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

building s-expression with boost::proto

I'm trying to build s-expression objects using boost::proto with the following terminals: typedef proto::terminal< const char* >::type string_term_t; typedef proto::terminal< uint32_t >::type uint32_term_t; typedef…
lurscher
  • 25,930
  • 29
  • 122
  • 185
1
vote
1 answer

Non-intrusive extension of Rcpp with Rcpp::traits::Exporter

I am writing an Rcpp package with classes containing base Rcpp objects that are non-intrusively exported to C++ types (see Extending Rcpp by Eddelbuettel and Francois, and this helpful vignette by coatless). What this means is that if I have a class…
zdebruine
  • 3,687
  • 6
  • 31
  • 50
1
vote
0 answers

`Rcpp::wrap` and `Rcpp::as` for external classes that use Rcpp namespace classes

How can Rcpp::wrap and Rcpp::as methods be written for classes that contain an Rcpp class? For example, the following .cpp file compiles using sourceCpp(): #include namespace Rcpp { class myVector { public: NumericVector data; …
zdebruine
  • 3,687
  • 6
  • 31
  • 50
1
vote
2 answers

Why does my Prolog S-expression tokenizer fail on its base case?

To learn some Prolog (I'm using GNU Prolog) and grok its parsing abilities, I am starting by writing a Lisp (or S-expression, if I'm being exact) tokenizer, which given a set of tokens like ['(', 'f', 'o', 'o', ')'] should produce ['(', 'foo', ')'].…
Caspian Ahlberg
  • 934
  • 10
  • 19
1
vote
1 answer

What's causing my OCaml S-expression parser to fail?

I am working on making a Lisp interpreter in OCaml. I naturally started with the front-end. So far I have an S-expression parsing algorithm that works most of the time. For both simple S-expressions like (a b) and ((a b) (c d)) my function,…
Caspian Ahlberg
  • 934
  • 10
  • 19
1
vote
1 answer

How to select successive words backwards with `C-M-SPC` (`mark-sexp`)?

I tried to select three successive words using C-M-SPC SPC SPC. The quick brown fox jumps over the lazy dog Repeating SPC selects additional words in a forward direction. How can I do the same thing in a backward direction, e.g. starting after lazy…
AbstProcDo
  • 19,953
  • 19
  • 81
  • 138
1
vote
1 answer

Why doesn't this clojure code using go blocks work?

(defn ff [t] (let [ch (chan 5)] (map (fn [i] (println i)) t) (go (>! ch 0)))) (ff [1 2 3 4 5]) The mapping function body isn't being executed. If I remove the go block in the last line, it works as expected. This function gives…
saga
  • 1,933
  • 2
  • 17
  • 44
1
vote
1 answer

turn lisp command to nested lists in python

I am building a lisp parser in python 3.7. Imagine I have this list program as a string "(begin (define r 10) (* pi (* r r)))" which I tokenize using: def tokenize(string): return string.replace('(', ' ( ').replace(')', ' )…
Tytire Recubans
  • 967
  • 10
  • 27
1
vote
1 answer

Declare s-expressions types in TypeScript

TypeScript client communicates with server using s-expressions, encoded as JSON. For simplicity let's assume that expression alphabet consist of one terminator function 'rx' which accepts string as parameter and functions 'and', 'or' which accept…
1
vote
1 answer

How to highlight region enclosed by parentheses in vim?

Is there a way to automatically highlight the region enclosed by parentheses when the cursor goes over that region? Take the following text as an example: (define (example x) (cond ((string? x) (display x)) (else (error "Bad"…
Flux
  • 9,805
  • 5
  • 46
  • 92
1
vote
1 answer

How do I use Jane Street's Sexplib's pretty-printer functions?

I'm a new OCaml-learner, and I'm trying to print some S-expressions, using Jane Street's Sexplib (included with Core): let rec print_source ?(channel = stdout) sexps = let formatter = Format.formatter_of_out_channel channel in Sexp.pp_hum…
ELLIOTTCABLE
  • 17,185
  • 12
  • 62
  • 78
1
vote
1 answer

Parse lists which can contain parentheses with ANTLR4

Lets say I want to create a grammar that is similar to Lisp where all expressions are between open and close parentheses. For example: (+ 1 2) I also want the grammar to be able to parse the string ('(def foo)) to a parse tree which is similar to…
tymm
  • 543
  • 1
  • 6
  • 18
1
vote
2 answers

How to represent a simple document as an s-exp?

I'm trying to understand how to express a simple document in an s-expression. Here's what I mean. Let's say I have this simple html structure:

Document Title

Paragraph with some text.

Paragraph with some bold

fraxture
  • 5,113
  • 4
  • 43
  • 83
1
vote
1 answer

emacs: Evaluate buffer contents as an s-expression?

Suppose I have an emacs buffer which contains the following text: '(1 2 3) I would like to evaluate the contents of this buffer as a lisp exprerssion (an s-expression). If I invoke (eval (buffer-string)), the result simply gets evaluated as the…
HippoMan
  • 2,119
  • 2
  • 25
  • 48
1
vote
2 answers

How to Match Parenthesis to Parse a S-Expression?

I am trying to create a function that does the following: Assuming that the code input is "(a 1 2 (b 3 4 5 (c 6) |7) 8 9)" where the pipe | symbol is the position of the cursor, the function returns: a String "b 3 4 5 (c 6) 7" representing the code…
euwbah
  • 363
  • 1
  • 13