News for hackers. Stuff that matters.
Re:A Year in Clojure by travisoneill1 on Sunday October 07, 2018 @11:27AM (#18161013)
I messed around with Clojure for a couple of days to see what a Lisp is like but never got into any of the advanced features. What could I build that would illustrate the capability you are talking about?
Re:A Year in Clojure by lvh on Sunday October 07, 2018 @11:42AM (#18161099)
It's hard for me to provide a good example without knowing some of the stuff you're in to but here's one of my favorite macros: https://github.com/lvh/caesium/blob/master/src/caesium/bindi...

It takes a symbol and figures out the name of a C function, how to most efficiently call it (with type hints for perf). If you screwed that up in one location it might have security consequences. But I _can't_ scre it up, because instead of copy pasting that code a gazillion times as I would have in Python, I just figured out what I want once and then use that functionality a gazillion times :)

Re:A Year in Clojure by eval on Sunday October 07, 2018 @01:12PM (#18161586)
As an exercise you could do on a REPL what a macro would do. Say you have a file containing “(1 + 1)”. Reading this (using slurp and read-str) would yield a list, eval-ing this list would however fail as it’s not valid Clojure. To make it eval-able you transform the list (all the operations of the language are at your disposal as you’re just handling data) to (+ 1 1). It’s this operating on data between read and eval that macros do.