Some stuff that took me longer than it should to grok, figure out, look-up or otherwise non-intuitive or radically different from Clojure.
- namespace
-
Operates on symbols and keywords but has a implementation which is picky. Takes keywords and symbols as follows:
(namespace 'foo/bar),(namespace (keyword "foo" "bar"))or,(namespace (keyword :foo :bar))all return foo
This would really contain pretty much everything about. It’s just a really tough subject every now and then. But there are these little moments of extremely clarity and insight when you’ve just 'grokked' it thanks to someones super-easy explanation or that 1 golden example code which gave the 'aha' moment.
A few pointers here for and from myself:
-
Quote everything you want executed with a delay, everything you don’t will be evaluated. One way to think of this, is that the quotes get stripped off and when it doesn’t have quotes, they will be evaluated. So a quote acts as a buffer against immediate evaluation/invocation.
(defmacro foo [x] (namespace x)) ;=> void(0); (print (foo wisp/main)) ;=> error ; Add str (defmacro foo [x] (str (namespace x))) (print (foo wisp/main)) ;=> error ; Ok now properly quote then (defmacro foo [x] (list 'str (namespace x))) (print (foo wisp/main)) ;=> wisp
So one way to think of this toggling quotes, besides from the perspective of the variable (do I expand or not) we can ask ourselves where does it happen.
One way to get a hint is to do something like:
(defmacro foo [] (print *ns*))
It will print { id: 'wisp.backend.escodegen.generator', doc: undefined }.
Another thing which will expose something about the nature of macro’s (in wisp) is the following. Consider hacking in some variables, foo, bar and baz.
One could do something as: