Hi, everyone! Is there some debugging trick/lib to get evaluation output on each step of a threading macro?
You can inspect any particular step in (-> ...) with (doto prn) or something like that. And with (#(doto % prn)) in (->> ...).
And if you want to inspect every single step, there are multiple libraries with suitable functionality, e.g. https://github.com/philoskim/debux?tab=readme-ov-file#debugging-the-thread-macro-or.
Also, writing a macro that works like -> or ->> but adds a debugging tap>/`prn` line in between each step is very easy and a nice macros-writing exercise if you feel like it.
Aha, debux that's the one. Thank you!
Will follow your advice on macro exercise)
Just a tiny hint - I'd make that macro itself emit code that uses ->. No need to repeat work that -> already does for you.
@yaro there is also https://www.flow-storm.org/, which will allow you to see that and much more
I have been meaning to have a look at it for ages now, but I really hate to get out of nvim
I comment #_ out the expressions in the code that I don't want to include in the result
https://youtu.be/XM8ymzlHRdQ?si=AidR26wVgo4H3Cs1
Or Emacs cider debug tool will step through an expression, form by form, showing the current values.
Its a very good tool, especially for recursive code
https://www.youtube.com/live/pyIbP4BOGpQ?si=MnmfdYChxQp75bMd&t=1145
Hi everyone! I know that when we transform strings into symbols (for example (symbol "+")) the generated symbol is not bound to the + function of the core lib. However. If I ran the following, the result is 1, what is the reason for this behavior? I ran some tests, and looks like the call is always returning the last number in the function call.
((symbol "+") 1 1)
Symbols as objects are invokable and work in the same exact way as keywords - they look themselves up in an associative data structure.
user=> (def m {'a 1})
#'user/m
user=> ((symbol "a") m)
1
In your example, something like the [map key not-found] arity of get is used, so the first 1 is map, the symbol itself is key, and the second 1 is not-found.
1 is not associative, it can have no keys, so the not-found value is returned:
user=> ((symbol "+") 1 :not-found)
:not-found
So, in my snippet, it is "searching" for the symbol + inside the first 1, and since it is not found, it returns the second 1, am I correct?
Yep!
Thank you for the information!
Is there any map containing all functions of the core lib?
In case you're asking about the map of functions because you're trying to bind the symbol from a string to the actual function, take a look at resolve or ns-resolve
Oh, and in that case - requiring-resolve. Because ns-resolve won't work when the target ns isn't loaded.