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.

Clojure macros continue to surprise me

138 pointsby jgrodziski10 months ago

8 comments

lloydatkinson10 months ago
I really enjoyed reading this, and I don&#x27;t know Clojure at all. This is a problem I&#x27;ve encountered several times while building design systems&#x2F;component libraries. It&#x27;s a very universal documentation problem, regardless of what platform it&#x27;s targeting.<p>I have done the same with React - but it gets messy. Something nice like in the post would be great for that.<p>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.<p>Instead of something meaningful like in the post, I see:<p><pre><code> () =&gt; &lt;TextInputStorybook &#x2F;&gt; </code></pre> As the only avaliable code. The point of the code blocks is so people can copy paste. When I see that, I know I&#x27;m in for a rough ride because the code quality inevitably isn&#x27;t any good either.<p>For reference, this is easily the best design system I know of: <a href="https:&#x2F;&#x2F;seek-oss.github.io&#x2F;braid-design-system&#x2F;components&#x2F;Text" rel="nofollow">https:&#x2F;&#x2F;seek-oss.github.io&#x2F;braid-design-system&#x2F;components&#x2F;Te...</a> I use this as a reference when I work on my own.
josefrichter10 months ago
In elixir you can run docs as (init) tests too. The doctest macro is generating the tests from the docs within the module. Maybe this might be interesting together with this article.
seancorfield10 months ago
The fifth time this has been posted in just over a week... it must be a REALLY good article! :)
评论 #41041430 未加载
kazinator10 months ago
&gt; <i>What if our macro read the source file?</i><p>&gt; <i>Like, actually went to the file system, opened a file, and read its content? We already have the file name conveniently stored in </i>file<i>, and luckily Clojure keeps sources around.</i><p>&gt; <i>So this is what I ended up with:</i><p>&gt; <i>(defn slurp-source [file key]</i><p>Looks like a function to me (which is good).
评论 #41043048 未加载
compacct2710 months ago
The real trick here is dodging ASTs, which, after trying to use in so many parse-the-code projects, really aren’t needed all the time but are put pretty highly on the pedestal
评论 #41046163 未加载
simply-typed10 months ago
<p><pre><code> sometimes a vector is just a vector, but sometimes it’s a UI component and shows the structure of the UI. </code></pre> Easily the worst aspect of Clojure. Everything is an untyped map or an untyped vector. Your editor can&#x27;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.
评论 #41084726 未加载
pjmlp10 months ago
Just wait for using full blown CL macros then.
评论 #41080828 未加载
kazinator10 months ago
TXR Lisp:<p><pre><code> $ 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 #&#x2F;\s*&#x2F;))) (dedent (mapcar (op drop indent) tail))) `@{dedent &quot;\n&quot;}\n`)) $ txr -i slurp-source.tl 1&gt; (put-string (slurp-source &quot;slurp-source.tl&quot; &quot;let*&quot;)) (match (member-if (op contains key) lines)) (tail (rest match)) (indent (find-min-key tail : (op match-regex @1 #&#x2F;\s*&#x2F;))) (dedent (mapcar (op drop indent) tail))) `@{dedent &quot;\n&quot;}\n`)) t</code></pre>
评论 #41053934 未加载