Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

lisp interpreter in python

I'm curious how a part of Peter Norvig's Lisp interpreter works. One can define functions in this Lisp interpreter...how does this work? I'm a beginner, and just would like a simple explanation.

There's one part that might be related where it says

elif x[0] == 'define':         # (define var exp)
        (_, var, exp) = x

http://norvig.com/lispy.html

like image 311
tekknolagi Avatar asked Jun 12 '26 23:06

tekknolagi


1 Answers

In this case, x[0] is define, x[1] is the variable name, and x[2] is the expression. So, in Python, _, var, exp = x is a "destructuring assignment", which destructures the array x into its constituent elements, and assigns them to the variables on the left-hand side.

like image 181
Chris Jester-Young Avatar answered Jun 15 '26 23:06

Chris Jester-Young



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!