TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Julia Macros for Beginners

127 pointsby IlyaOrsonover 3 years ago

7 comments

phoe-krkover 3 years ago
As always, I&#x27;m very glad to see that structural, Common Lisp-style macro systems with the whole language available for macro construction, have been successfully adopted in other languages to the point where it&#x27;s possible to explain them without a single mention of Lisp in the article, or even better - where a mention of Lisp anywhere else except for the very beginning would make the article <i>worse</i> by making a unnecessary detour.<p>pg&#x27;s article on the topic, &quot;What Made Lisp Different&quot;, [0] has aged poorly, and points 8 and 9 it makes (a notation for code using trees of symbols and the whole language always available) are no longer Lisp-specific. The final point, about &quot;inventing a new dialect of Lisp&quot;, doesn&#x27;t hold true either - as seen here, Julia is doing just fine not claiming to be another dialect of Lisp, even though many sources mention directly that it&#x27;s Lisp-inspired.<p>Congrats to Julia people for the macro system and to the author for the article!<p>[0] <a href="http:&#x2F;&#x2F;www.paulgraham.com&#x2F;diff.html" rel="nofollow">http:&#x2F;&#x2F;www.paulgraham.com&#x2F;diff.html</a>
评论 #30083618 未加载
tombertover 3 years ago
Macros were part of the &quot;holy shit&quot; moment for me for Lisp, in particular the Common Lisp Object System. I hadn&#x27;t fully realized that it was possible to add a whole new <i>paradigm</i> to a language as a <i>library</i> [1], and moreover a particularly nice implementation of that paradigm.<p>After that, I realized that macros aren&#x27;t <i>always</i> something that needs to be avoided; in the right hands they&#x27;re immensely powerful.<p>I&#x27;ve only played a little with Julia macros, but it seems like they learned a lot of Lisps lessons, so I support it wholly.<p>[1] I wasn&#x27;t aware of how Objective C was built at the time.
dan-robertsonover 3 years ago
The frustration of Julia macros for me was never knowing what AST would be produced for a given expression. This is a bit more manageable if you have a typed AST (e.g. OCaml but ppxes have other issues) or an obvious one (e.g. lisp). I like the way rust handles it where the macros operate on a tree of non-delimiter leaves and [delimiter, subtree list, delimiter] nodes which can allow for figuring out what the input to a macro will be more easily and for more varied macro syntax. Other languages that want a full AST before macros force the macro input to be a bit more AST-like, e.g. the Julia parser picks operator precedence and OCaml won’t let you use _ as an identifier.<p>Maybe it is better now but when I looked at macros ~5 years ago some language update changed the ast produced by the parser and I basically gave up.<p>I like that Julia offers some macro-like techniques that replace a lot of the cases where one might use a macro for performance reasons.
评论 #30090643 未加载
评论 #30088379 未加载
leephillipsover 3 years ago
This is an excellent, clear introduction to a topic that’s not easy to explain to beginners.
tlinker123over 3 years ago
Julia macros are pretty legit. Right up there with Rust macros.
Kalanosover 3 years ago
never understood why this was better&#x2F; how it was different from regular functions. just seems like bugs&#x2F;vulns waiting to happen
评论 #30086792 未加载
评论 #30086719 未加载
评论 #30087244 未加载
评论 #30086016 未加载
xiaodaiover 3 years ago
There are R meta programming techniques called non standard evaluation. It has many similarities to the macro system in Julia
评论 #30085693 未加载