s-expression

What advantage does common lisp reader macros have that Clojure does not have?

*爱你&永不变心* 提交于 2020-01-29 02:51:05
问题 I have been using Clojure alot recently but I still don't understand what functionality I do not get that common lisp reader macros provide. Can explain explain this to me in simple terms? 回答1: In short, reader macros provide you with the ability to redefine the programming language's syntax within some delimited context. For example, you could implement regular expression literals (e.g. #"pattern" ) yourself given reader macros. Without them, you would be forced to properly escape regular

With clojure read/read-string function, how do i read in a .clj file to a list of objects

我的未来我决定 提交于 2019-12-23 16:43:48
问题 As titled, If I do (read-string (slurp "somefile")) This will only give me the first object in the file, meaning if "somefile" is as below: (a obj) (b obj) Then I only get (a obj) as the result. How do i get a list of all objects, like this? ((a obj) (b obj)) Thanks. 回答1: (defn read-all [input] (let [eof (Object.)] (take-while #(not= % eof) (repeatedly #(read input false eof))))) 回答2: I usually wrap stuff in a list, (read-string (str \( (slurp "somefile") \))) 来源: https://stackoverflow.com

running embedded R in C

倖福魔咒の 提交于 2019-12-23 10:54:57
问题 I have written up a piece of C code which declares a square matrix of size 4x4. Then it samples from a sampling function called rgig in package GeneralizedHyperbolic in R. It inverses the matrix using a gsl library from gnu and spits out the result. This is an exercise in calling R from C. #include <stdio.h> #include <stdio.h> #include <math.h> #include <stdlib.h> #include <stddef.h> // for gsl #include <gsl/gsl_machine.h> #include <gsl/gsl_rng.h> #include <gsl/gsl_randist.h> #include <gsl

Do you know of a language with Static Type checking where Code is Data? [closed]

丶灬走出姿态 提交于 2019-12-20 17:39:06
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 2 years ago . Can you name languages with static type checking (like Java) and where code is data (like in LISP)? I mean both things in one language. 回答1: Qi is a statically-typed Lisp dialect. Also, many other Lisp dialects have (optional) static typing. Java itself has very limited

Parse string with “read” and ignore package namespaces

≯℡__Kan透↙ 提交于 2019-12-13 03:50:36
问题 I am writing a program that opens a lisp file, calls "read" on the stream until the stream is empty, and does things with the lists it collects. This was working quite nicely until I discovered that "read" will perform package lookup, for instance if it encounters some-package:foo it will complain that Package SOME-PACKAGE does not exist. Here is an example showing what I mean: (read (make-string-input-stream "(list 'foo :foo some-package:foo)")) So I now I would like one of three things:

What are improper lists for?

元气小坏坏 提交于 2019-12-12 11:05:42
问题 This is a follow-up of my previous question: Why do we need nil? Clearly, proper lists are used most of the time. But what is the purpose of an improper list? 回答1: For no good reason. The only thing that improper lists are truly good for is as part of the syntax for association lists—and even there, a custom syntax for key-value pairs would be better. Any use you can think of for improper lists can be better implemented with record types—which, after all, subsume lists: you can define Lisp

Parsing and building S-Expressions using Sets and binary search tree

余生颓废 提交于 2019-12-12 09:27:04
问题 This is pseudo homework (it's extra credit). I've got a BST which is an index of words that point to the lines (stored somewhere else) that contain the words. I need to implement a way to search using s-expressions so I can combine and (&) and or (|). At the command prompt a user could type something like: QUERY ((((fire)&(forest))|((ocean)&(boat)))&(water)) Essentially that should return all lines that contain the words fire, forest and water as well as all lines that contain ocean, boat and

jq or xsltproc alternative for s-expressions?

给你一囗甜甜゛ 提交于 2019-12-12 09:01:23
问题 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 fields are metadata and the AST s are s-expressions which the scripts pass along as-is. This worked fine, as I could use cut -d ' ' to split the metadata from the ASTs, and cut -d ':' to dig into the metadata. However, I then needed to add a metadata

Common lisp: is there a less painful way to input math expressions?

房东的猫 提交于 2019-12-12 08:02:17
问题 I enjoy common lisp, but sometimes it is really painful to input simple math expressions like a(8b^2+1)+4bc(4b^2+1) (Sure I can convert this, but it is kind of slow, I write (+ () ()) first, and then in each bracket I put (* () ())...) I'm wondering if anyone here knows a better way to input this. I was thinking about writing a math macro, where (math “a(8b^2+1)+4bc(4b^2+1)”) expands to (+ (* a (1+ (* 8 b b))) (* 4 b c (1+ (* 4 b b)))) but parsing is a problem for variables whose names are

An elegant way to parse sexp

谁都会走 提交于 2019-12-11 00:54:39
问题 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 let rec parse_atom buf i = if i >= len then failwith "cannot parse" else match s.[i] with | '(' -> failwith "cannot parse" | ')' -> Atom (Buffer.contents buf), i-1 | ' ' -> Atom (Buffer.contents buf), i | c when i = len-1 -> (Buffer.add_char buf c; Atom