Defmacro Clojure Tutorial - Code that writes code

preview_player
Показать описание
Defmacro in Clojure allows you to write code that outputs code 🤯

This is a video on how to create and expand macros

00:00 intro
00:10 what are macros?
00:45 create a function that delays the return
01:55 create a function that records the time taken
04:05 Syntax Quoting
05:24 Convert time-taken function to macro
07:10 Cater for multiple expressions to be passed through to time-taken
09:50 Begging for subs
Рекомендации по теме
Комментарии
Автор

Fun facts:
1. Macro can have varied amount of arguments (like functions do)
2. Inside macro you can get env bindings by inspecting &env variable (there is also &form var, but it is boring)
3. You can define function and macro under the same name (symbol). It is useful for the cases when you want to run the macro(actually the function) with apply.
4. Macro can be used for performance sake. For example, you might want to move some of a heavy calculation to the compile time. For this you can implement a macro that does the work and inlines the result.

eugenej.
Автор

Well done ! Enjoyed the interactive style of coding..

streamcityvideo
Автор

Love the intro ! And excellent content !

Bbduyg
Автор

Awesome! one of the reasons why I wanted to learn Clojure.

street.programmer
Автор

Very nice explanation.. Looking forward to the next video. Cheers

dionysiuswilson
Автор

I really love the way you explain things. Not found a need for macros in my work, but it was good to see one built up. Thanks. It would be good to have a video about handling complex nested structures, may be including specter?

staringout
Автор

Wow!
1. you can comment the entire function with #_
2. # with ` instead of gensym
Thanks

Frodohack
Автор

Great example and explanation of Clojure macros!
You could look at transient data structures at some point. Just a suggestion))

romanostash
Автор

Very nice and useful video! Thanks
Notice that "println" (unlike str) already surround args with space, so you can rid of spaces in your srings.

TneDeaf
Автор

Who's up for macros in Overtone with self writing music in artificial intelligence?

fredconcklin
join shbcf.ru