by shrimpx · 3y ago · 0 comments
[
// define some_fun(x) => let y=2;let z=y*3;return x+z
{"some_fun": [["x"], [
{"y": 2,
"z": ["*", "y", 3]},
["+", "x", "z"]
]},
// call it
["some_fun", 100]
]
Here I'm using JSON dictionaries to bind variables, and lists for everything else (instruction sequences, argument lists, etc.). Now I can quote stuff to define JSON data, or otherwise define programs.I'm not a lisper but it seems what's special about lisp is it defines its programs in a generic data format.
The most obvious thing lacking from the point of view of interpreting in a Lisp-like way is an ergonomic syntax for symbols.
People have experimented with computation in JSON, pretty much like how you have it; but it's lame to work with. Nobody wants to write quotes around basic identifiers like "+". And it is inefficient, to boot.
Interning of symbols is a key advantage of Lisp, and it was there in 1958 already; so by using JSON this way, you're regressing before that.
Lisp converts symbols into small values, which are atoms. Two or more occurrences of the same symbol are the same atom. An atom is a small word-sized quantity. Often a pointer, but not necessarily so; it could be a numeric index into a table of objects. Anyway, it is very efficient to test whether two atoms are the same object.
One of the things that still makes Lisp special. It makes metaprogramming "easy" in contrast to metaprogramming in almost every other language out there.
The other big thing is its high degree of interactivity and dynamic capabilities.