7 ms·
> To anticipate a common question: why couldn't my-unless be a function? Function arguments are evaluated eagerly, before the function ever sees them. Interest
by meken 1mo ago
> To anticipate a common question: why couldn't my-unless be a function? Function arguments are evaluated eagerly, before the function ever sees them.
Interesting, so if you’re using a lazy language then you don’t need a macro here and could write my-unless as a function.
- wk_end 1mo agoIndeed: https://hackage-content.haskell.org/package/base-4.22.0.0/docs/Control-Monad.html#v:unless https://hackage-content.haskell.org/package/base-4.22.0.0/do...
- brabel 1mo agoYes, the D language has that as a feature in function arguments! https://dlang.org/articles/lazy-evaluation.html https://dlang.org/articles/lazy-evaluation.html It makes it hard to know when things run. In Lisp you also have that problem everywhere, of course. As the post shows this allows you to do stuff that looks like extending the syntax of the language. I can’t decide if I love it or hate it!
- carlosneves 1mo agoProps to D for having such a simple implementation of fexprs[1]. The downside compared to macros I think is that, as argument expressions become lambdas, it becomes harder to manipulate them. Check the cond example which needs two fexprs, whereas one macro could do it. Not sure about D, but if it were lisp, even lambdas could be manipulated as lists. Macro args not having the lambda wrapping just seems simpler. [1] https://en.wikipedia.org/wiki/Fexpr https://en.wikipedia.org/wiki/Fexpr
- brabel 1mo agoWalter Bright is against adding macros to D but D already has really advanced metaprogramming in other shapes: https://dlang.org/spec/template-mixin.html https://dlang.org/spec/template-mixin.html https://dlang.org/spec/traits.html https://dlang.org/spec/traits.html
- phyzix5761 1mo agoYou could do that as well with lisp by passing around lambdas to functions but that adds unnecessary syntax.
- floxy 1mo agoOr you could wrap arguments in lambdas (anonymous functions) for eagerly-evaluted languages. Lisp unfortunately has a bulky syntax for lambdas, compared to something like Smalltalk. Of course, you can fix this with reader macros in Common Lisp (but no one does). Clojure has a shorter syntax I believe as well: #().
- BoingBoomTschak 1mo agoUnless laziness is pervasive (I guess, no knowledge about GHC internals), you basically have an FEXPR (https://en.wikipedia.org/wiki/Fexpr https://en.wikipedia.org/wiki/Fexpr) which was replaced by macros for good reasons.