Live data from Hacker News

Clojure macros continue to surprise me

tonsky.me

21–30 of 31 posts

Re: Clojure macros continue to surprise me

#21

TXR Lisp: $ cat slurp-source.tl (defun slurp-source (path key) (let* ((lines (file-get-lines path)) (match (member-if (op contains key) lines)) (tail (rest match)) (indent (find-min-key tail : (op match-regex @1 #/\s*/))) (dedent (mapcar (op drop indent) tail))) `@{dedent "\n"}\n`)) $ txr -i slurp-source.tl 1> (put-string (slurp-source "slurp-source.tl" "let*")) (match (member-if (op contains key) lines)) (tail (rest…

Wow!

Re: Clojure macros continue to surprise me

#22
I really enjoyed reading this, and I don't know Clojure at all. This is a problem I've encountered several times while building design systems/component libraries. It's a very universal documentation problem, regardless of what platform it's targeting.

I have done the same with React - but it gets messy. Something nice like in the post would be great for that.

Too often I see very poor Storybook sites in the wild (a web based design system visual explorer, somewhat like the screenshot in the post) where no thought was given to this exact problem.

Instead of something meaningful like in the post, I see:

    () => 
As the only avaliable code. The point of the code blocks is so people can copy paste. When I see that, I know I'm in for a rough ride because the code quality inevitably isn't any good either.

For reference, this is easily the best design system I know of: https://seek-oss.github.io/braid-design-system/components/Te... I use this as a reference when I work on my own.

Re: Clojure macros continue to surprise me

#25
post #17

Just wait for using full blown CL macros then.

CL macros are more or less the same as Clojure macros and neither hold a candle to modern Scheme or Racket macros :)

Eh? Pretty sure they're more powerful. And readable, unlike the Scheme ones that look as elegant and well integrated as a caravan being pulled by a Porsche =).

Re: Clojure macros continue to surprise me

#26

Earlier quoted context omitted.

CL macros are more or less the same as Clojure macros and neither hold a candle to modern Scheme or Racket macros :)

Eh? Pretty sure they're more powerful. And readable, unlike the Scheme ones that look as elegant and well integrated as a caravan being pulled by a Porsche =).

Used in the way the author of the article presents, or generally the way you could use them in Clojure, Racket and Scheme macros are pretty similar. However at least in Racket you have a lot more control over certain parts of the way compilation affects the macro (look up phases for example). I assume Scheme has similar constructs, as does CL.

Note this is ignoring anything about the reader, for which Racket has substantially more powerful functionality around than Clojure.

Re: Clojure macros continue to surprise me

#27

  sometimes a vector is just a vector, but sometimes it’s a UI component and shows the structure of the UI.
Easily the worst aspect of Clojure. Everything is an untyped map or an untyped vector. Your editor can't tell the difference between a vector of keywords and some DSL for a macro. Things like this make Clojure a nightmare to refactor and scale poorly relative to languages like TypeScript.

Re: Clojure macros continue to surprise me

#28

sometimes a vector is just a vector, but sometimes it’s a UI component and shows the structure of the UI. Easily the worst aspect of Clojure. Everything is an untyped map or an untyped vector. Your editor can't tell the difference between a vector of keywords and some DSL for a macro. Things like this make Clojure a nightmare to refactor and scale poorly relative to languages like TypeScript.

Thankfully this hiccup style seems less common in recent code. ie. where the index in the vector has a hidden meaning.. Now vectors are typically used for array of the same datatype. I think this makes more sense as basically if you see a vector, you can shove it in to map/filter/etc.

People now prefer using maps - even if it's a bit more verbose. Not sure why records fell out of fashion. You get the terseness of hiccup and the named keys of maps

Re: Clojure macros continue to surprise me

#29

Earlier quoted context omitted.

CL macros are more or less the same as Clojure macros and neither hold a candle to modern Scheme or Racket macros :)

Eh? Pretty sure they're more powerful. And readable, unlike the Scheme ones that look as elegant and well integrated as a caravan being pulled by a Porsche =).

Writing defmacro in syntax-case is simple. Writing syntax-case with defmacro is not.

Everybody seems to think scheme macros means syntax-rules. You can get something pretty cl-esque with implicit renaming macros, but with hygiene as opt-out instead of opt-in.

Re: Clojure macros continue to surprise me

#30
post #29

Earlier quoted context omitted.

Eh? Pretty sure they're more powerful. And readable, unlike the Scheme ones that look as elegant and well integrated as a caravan being pulled by a Porsche =).

Writing defmacro in syntax-case is simple. Writing syntax-case with defmacro is not. Everybody seems to think scheme macros means syntax-rules. You can get something pretty cl-esque with implicit renaming macros, but with hygiene as opt-out instead of opt-in.

Didn't R7RS drop syntax-case?
Post reply on HN