Questions tagged [s-expression]

S-expressions are a notation for nested list or tree-structured data, popularized by the Lisp programming language.

In computing, s-expressions, sexprs or sexps (for "symbolic expression") are a notation for nested list (tree-structured) data, invented for and popularized by the programming language which uses them for source code as well as data.

Source: Wikipedia

138 questions
2
votes
3 answers

What is the disadvantage of list as a universal data type representation?

Lisp programmers tend to use lists to represent all other data types. However, I have heard that lists are not a good universal representation for data types. What are the disadvantage of lists being used in this manner, in contrast to using…
day
  • 2,292
  • 1
  • 20
  • 23
2
votes
3 answers

How to build AST by S-expression in Ruby?

I have no idea how to build S-exp. I want to do it, because I need to build AST for my langauge. At the beginning I used RubyParser to parse it to sexp then code gen. But it must be ruby's subset I think.I cant define the language what I want. Now I…
user997948
  • 157
  • 1
  • 7
2
votes
1 answer

Is it possible to implement a simple typed lisp in the TypeScript type system?

I'm attempting to implement a simple typed lisp in the TypeScript type system, drawing inspiration from JSON Logic, but with types. Here is an example of what that looks like: /** * Given a context object C, this type will allow you to construct *…
wvandaal
  • 4,265
  • 2
  • 16
  • 27
2
votes
2 answers

How to convert a list to code/lambda in scheme?

Let's say I have a list, for example: (define a '(+ (* p p) (* x x))). How can I define a procedure with an expression given by a, for example here: (define (H x p) (+ (* p p) (* x x)))) ? I tried to do something like: (define (H x p) (eval a)) but…
Syrocco
  • 179
  • 1
  • 5
2
votes
1 answer

How to parse an XML to S-Expression for lisp using C#?

I want to be able to load any xml file and convert it into s-expression for lisp. Does anyone have an idea how this could be done using c#? I have no prior experience in working either with lisp or s-expression and my main problem is that I can't…
Oskar
  • 37
  • 1
  • 3
2
votes
1 answer

Bug in s-expr printing function

To practice my Haskell skills, I'm following the Write Yourself a Scheme tutorial. I've implemented a parser for s-expressions, but I'm having trouble with the printing function. When I run the following program main :: IO () main = do args <-…
Fred Foo
  • 355,277
  • 75
  • 744
  • 836
2
votes
2 answers

Calculating the depth of a tree data structure - clojure

I'm trying to implement an algorithm to find the depth of a sequence expression through Clojure Zippers. (zip/seq-zip (+ 1 (* 2 3))) This is the way I'm interpreting a sequence to be converted into a tree data structure. Is there a direct method to…
Coding active
  • 1,620
  • 3
  • 23
  • 40
2
votes
2 answers

jq or xsltproc alternative for s-expressions?

I have a project which contains a bunch of small programs tied together using bash scripts, as per the Unix philosophy. Their exchange format originally looked like this: meta1a:meta1b:meta1c AST1 meta2a:meta2b:meta2c AST2 Where the :-separated…
Warbo
  • 2,611
  • 1
  • 29
  • 23
2
votes
1 answer

reading deeply nested tree causes stack overflow

I'm trying to read a massive sexp from file into memory, and it seems to be working out fine for smaller inputs, but on more deeply nested ones sbcl conks out with stack exhaustion. There seems to be a hard recursion limit (at 1000 functions deep)…
2
votes
1 answer

Neighborhood of a mathematical expression using Haskell

I'm trying to implement with Haskell an algorithm to manipulate mathematical expressions. I have this data type : data Exp = Var String | IVal Int | Add Exp Exp This will be enough for my question. Given a set of expression transformations, for…
2
votes
1 answer

An elegant way to parse sexp

sexp is like this: type sexp = Atom of string | List of sexp list, e.g., "((a b) ((c d) e) f)". I have written a parser to parse a sexp string to the type: let of_string s = let len = String.length s in let empty_buf () = Buffer.create 16 in …
Jackson Tale
  • 25,428
  • 34
  • 149
  • 271
2
votes
4 answers

Emacs: how to evaluate the smallest s-expression the cursor is in, or the following s-expression

What is a good way to evaluate the (+ 100 (+ 100 100)) part in (+ (+ 1 2) (+ 100 (+ 100 100))) ? For now, I do it by C-x C-e, which means I need to locate the ending parenthesis, which is difficult in most cases. Options > Paren Matching…
Yoo
  • 17,526
  • 6
  • 41
  • 47
2
votes
2 answers

Destructively reverse every cons node in an s-expression

Any ideas how to go about this? I am trying to not create any new nodes.
jblade
2
votes
2 answers

Clojure Application Data Exchange

I would like to move data back and fourth between clojure applications. Application settings and some state information. I can not decide between using xml or s-expressions, what do you think pros and cons of each approach?
Hamza Yerlikaya
  • 49,047
  • 44
  • 147
  • 241
2
votes
1 answer

Lisp S-Expressions and Lists Length/Size

I am trying to write a function using Common Lisp functions only that will count how many s-expressions are in an s-expression. For example: ((x = y)(z = 1)) ;; returns 2 and ((x - y)) ;; returns 1 Nested expressions are possible so: ((if x then…
darksky
  • 20,411
  • 61
  • 165
  • 254