4 ms·
I know python, and last semester I took a class that briefly touched (lightly kissed?) LISP for a few weeks. I have a passing familiarity and I really loved the
by chuckdries 9y ago
I know python, and last semester I took a class that briefly touched (lightly kissed?) LISP for a few weeks. I have a passing familiarity and I really loved the very small amount that I saw. I'd like to learn more, can you go into more detail on the usage of let and how one would go without it?
- hood_syntax 9y ago> lightly kissed How romantic!
- flavio81 9y ago> I'd like to learn more, can you go into more detail on the usage of let and how one would go without it? Welcome to the wonderful world of Lisp. I'd recommend to you to install Portacle (the Portable Common Lisp Environment), this allows you to code in Lisp straight away. As for tutorials, "Practical Common Lisp" (free online book) is fun, modern, and excellent for introducing you to most CL concepts, including of course use of let, let*, etc.
- flavio81 9y agoand to directly answer your question, there a are many things you can do with let. Let binds a "form" to a symbol. (let ((pi 3.14)) ... code goes here ... ) So within the "code" part, that is, within that lexical environment, the symbol "pi" exists and is bound to float number 3.14 (Alternatively, you don't need to set a initial value.) One of the interesting uses of let is that it can also redefine dynamic variables (aka special variables, think of them as "global variables). So for example let's assume i define timeout to 300, so within my whole package, this special variable has the value of 300. Let's suppose this variable is going to be read by function "my-function", and others. So i create this special variable: (defparameter *timeout* 300) Now, despite the above, let's suppose i want to call "my-function" but with a timeout of 1000. I can just do this in my code: (let ((*timeout* 1000)) (my-function)) So, inside this "let", when "my-function" gets executed, the timeout will be 1000. Outside of this, it will still be 300. Let, thus, allows you easy use of lexical environments. Another use is creating closures by using the combination of "let" with "lambda."