(mac awhen (expr . body)
`(let it ,expr (if it (do ,@body))))
This basically add a new syntax to the language. How often did you do in python: some_value = my_function()
if some_value:
call_something_with(some_value)
With the small macro defined earlier, we can do: (awhen (my_function)
(call_something_with it))
Basically, binding (my_function) to the variable named "it".It's amazing to be able to add new syntax/features to the language without having to wait for a new version. Imagine if you could add any features you want to javascript or python without having to wait 5 years for the spec to be approved and implemented..
It's possible because the code is written in the same data structure that you use to manipulate normal values. I.e.:
(let x 1
(prn x))
Is the code of the program but also simply a list of 4 elements. And since the code itself is a data structure that you can manipulate with normal functions, there's something called "Macro" in Lisp (not to confuse with C++ macros), which essentially are functions that receive code and returns code, instead of receiving values and returning values.So: (some_macro (prn 1)). some_macro would receive a list of two elements (prn and 1) and could do some operation to it and returns some new code.. such as (prn 2), which will then get evaluated to print 2. Whereas (some_fn (prn 1)) would evaluate (prn 1) (which returns nil), and pass nil to some_fn.
That's why it's so hard to impress a lisp programmer with any other languages because if a feature doesn't exist, they can add it with a macro. I.e. Actors or OO, or whatever really.