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
1
vote
3 answers

Idiomatic way to define s-expr in Scala

How does Scala "want" me to define s-expr? In English, we define s-expr recursively, like this: "An s-expr is either an atom or a list of s-exprs." How do you say that in Scala? I'm pretty sure this is wrong: // Scala 2.11.2 trait Sexpr case class…
Ben Kovitz
  • 4,920
  • 1
  • 22
  • 50
1
vote
4 answers

Lisp-family: Different evaluation of a symbol call and symbol as argument

Is there a way in lisp-family (EDIT: lisp-1) languages to differentiate symbol evaluation with regard to its position as as function or as an argument (i.e. override eval of this symbol in regard to when it is evaluated)? As an example (I don't need…
artemonster
  • 744
  • 4
  • 27
1
vote
2 answers

Can this image processing code be optimised to use less memory?

I have a python function that takes a string s-expression like "(add (sub 10 5) 5)", where "add" and "sub" are actually image processing functions, and evaluates and creates the image represented in the string. The image processing functions take…
1
vote
1 answer

Tokenizing an s-expression in C

I'm trying to create my own Lisp interpreter and have run into some issues with the parsing of s-expressions. My initial thought was to tokenize the expression and handle one bit at a time. I came across some code to do this after failing with my…
J. Doe
  • 13
  • 2
1
vote
1 answer

symbolic expression stream I/O

In Common Lisp, how can one read & write symbolic expressions from/to streams? For example, I might want to write an anonymous function to file and then read and funcall it: ;;; sexp-io.lisp ;;; Try writing a sexp to file and reading it back…
fpt
  • 358
  • 3
  • 11
1
vote
2 answers

Parsing S Expression

Given the following definitions that make up an S Expression from Prof. Yorgey's course: data Atom = N Integer | I Ident deriving Show and data SExpr = A Atom | Comb [SExpr] deriving Show What should the full data type be (in Haskell) for the…
Kevin Meredith
  • 41,036
  • 63
  • 209
  • 384
1
vote
2 answers

Little Schemer "S-expression" predicate

Is it true that this is an S-expression? xyz asks The Little Schemer. but how to test? syntactically, i get how to test other statements like > (atom? 'turkey) and > (list? '(atom)) not entirely sure how to test this... > (list? '(atom turkey)…
1
vote
1 answer

How to optimize a transitive closure?

I have the following code, which I would like to optimize. I'm particularly unhappy with nub : deep (Op o x) = [f (Op o x)] ++ map (\y->(Op o y)) (sf x) deep x = [x] sf [x] = [[f x]] sf (x:xs) = map (\y->(y:xs)) (deep x) ++ map (x:) (sf xs) eqlst…
1
vote
1 answer

Is trailing white space is forbidden in s-expression?

When I try sexplib, it tells me Sexp.of_string " a";; is correct. Sexp.of_string "a ";; is wrong. Is trailing white space is forbidden in sexp? Why?
Jackson Tale
  • 25,428
  • 34
  • 149
  • 271
1
vote
1 answer

Python -- special method arithmetic using existing class methods

This class takes a finite field polynomial string, parses it, operates (+-*/%), then outputs in the same format as the input. It works fine (so far). However, now I'm trying to implement special methods on the arithmetic operators, and I can't get…
1
vote
1 answer

How can I unserialize a s-exp then seralize it and avoid upper-casing?

I am supposed to read a complex s-expression tree, modify some nodes and save it somewhere. It appears that in process the 'read function is "modifying" the input. For instance in a simple example: CL-USER> (read-from-string "(seq_num…
yves Baumes
  • 8,836
  • 7
  • 45
  • 74
1
vote
2 answers

Lazy list s-expression matrix in smalltalk

So I have a class to create in smalltalk called LazyMatrix. The class only has 1 instance variable and cannot be a subclass of anything but Object. The instance variable of LazyMatrix is called block and must be a back. I initialize LazyMatrix like…
Wes Field
  • 3,291
  • 6
  • 23
  • 26
1
vote
1 answer

Usage of ruby_parser, AST in prior 1.8.7 and S-expression in ruby?

Recently I am converting the ror project that uses ParseTree in ruby 1.8.7 to ruby 1.9.3 Figured out that ParseTree cannot work with 1.9.3, Searched for it in bunch of googlers, still stuck with some code-migration Found various alternative like…
millisami
  • 9,931
  • 15
  • 70
  • 112
0
votes
1 answer

What is syntax expression?

I read in the book "Land of Lisp", the author mentions syntax expression. Does that mean the ability to express syntax as a form of data? Is this the same as S-expression (symbolic expression)?
Amumu
  • 17,924
  • 31
  • 84
  • 131
0
votes
0 answers

gpg-agent GENKEY via cli for simplest RSA , invalid length specifier in sexp returned, using documentation example

https://www.gnupg.org/documentation/manuals/gnupg/Agent-GENKEY.html When I execute gpg-agent --server for an interactive session, and enter the example from this site, I get the following error : "gpg-agent[14]: failed to convert keyparam: Invalid…