3 ms·
The first step is to overcome the syntax. It's useful to think in terms of Python syntax at first. f(x) (f x) ["f", "x"] (print (< 10 20)) ["print",
by matheusmoreira 1y ago
The first step is to overcome the syntax. It's useful to think in terms of Python syntax at first.
f(x)
(f x)
["f", "x"]
(print (< 10 20))
["print", ["<", 10, 20]]
Lisp code is just list data which gets evaluated by an interpreter function. Like this:
code = ["print", ["<", 10, 20]]
def eval(code):
# magic
eval(code) # True
Filling out that eval function is a great way to learn. I only truly understood lisp when I implemented my own.
These articles are very good and accessible:
https://www.norvig.com/lispy.html https://www.norvig.com/lispy.html
https://norvig.com/lispy2.html https://norvig.com/lispy2.html
- jasomill 1y agoFunny you mention this, as I've written quite a bit of Python code that works just like this, typically in the form of an evaluator for some random proprietary language I've parsed into an AST in the form of a Python list or tuple.