Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

My blog/wiki engine is written in an older version of Hy:

https://github.com/rcarmo/sushy

I'm currently re-writing it in Python 3.6 because Hy has taken a hard stance in backwards compatibility and deprecated "let" (with a replacement macro, but still) and isn't tackling async (both for understandable, but sad reasons), so it doesn't really work for me anymore.

But while it did, I loved it to bits. Python with a LISP syntax is just wonderful, and if someone ever finds a way to add back the stuff I like, I'm more than willing to deal with the quirks.



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?


and 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."


> 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.


> lightly kissed

How romantic!


Thank you for sharing this. The last time I started trying to use Hy, I felt like I was basically writing Python but wrapped in parens -- I felt like I was doing something wrong, but couldn't place what it was, so it's nice to see a non-toy implementation that demonstrates what one can do with it.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: