frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Open in hackernews

Extending a Language – Writing Powerful Macros in Scheme

https://mnieper.github.io/scheme-macros/README.html
92•textread•1y ago

Comments

neilv•1y ago
A few formatting changes might make this advanced example easier to understand:

    (define-syntax trace-let
      (syntax-rules ()
        [(trace-let name ([var expr] ...) body1 ... body2)
         (let f ([depth 0] [var expr] ...)
           (define name
             (lambda (var ...)
               (f (+ depth 1) var ...)))
           (indent depth)
           (display "(")
           (display 'name)
           (begin
             (display " ")
             (display var))
           ...
           (display ")")
           (newline)
           (call-with-values
               (lambda ()
                 body1 ... body2)
             (lambda val*
               (indent depth)
               (fold-left
                (lambda (sep val)
                  (display sep)
                  (display val)
                  " ")
                "" val*)
               (newline)
               (apply values val*))))]))
The biggest one is to make the rule template pattern variables all-uppercase. I also made a few other tweaks, including using indentation a little more, and naming the named-`let` variable as "loop" (I usually name it `loop` or prefix the name with `loop-` if there's more than one):

    (define-syntax trace-let
      (syntax-rules ()
        ((trace-let NAME ((VAR EXPR) ...) BODY1 ... BODY2)
         (let loop ((depth 0)
                    (VAR   EXPR) ...)
           (define NAME
             (lambda (VAR ...)
               (loop (+ depth 1) VAR ...)))
           (indent depth)
           (display "(")
           (display (quote NAME))
           (begin (display " ")
                  (display VAR)) ...
           (display ")")
           (newline)
           (call-with-values (lambda ()
                               BODY1 ... BODY2)
             (lambda val*
               (indent depth)
               (fold-left (lambda (sep val)
                            (display sep)
                            (display val)
                            " ")
                          ""
                          val*)
               (newline)
               (apply values val*)))))))
Incidentally, all-uppercase Scheme pattern variables is one of the all-time best uses of all-uppercase in any language. Second only to all-uppercase for the C preprocessor, where a preprocessor macro can introduce almost arbitrary text. Using all-uppercase for constants in some language that has constants, however, is an abomination.

(My suspicion of why Java did all-caps is that they were developing a language for embedded systems developers who were currently using C and C++, and they wanted to make it superficially look similar, even though it was an entirely different language. And then, ironically, the language ended up being used mostly by the analogue of a very different developer of the time: corporate internal information systems developers, who, as a field, didn't use anything like C. It's too late to save Java, but to all other language and API developers, please stop the insanity of all-caps constants, enum values, etc. It's not the most important thing that needs to jump out from the code above all other things.)

Y_Y•1y ago
FWIW, all-caps makes this look much worse to me. I understand that people like things like Hungarian notation, arrows over vector names, and shouting Common Lisp symbols. I understand the argument that it can make reading easier. I just can't appreciate that benefit, and it seems to me an ugly hack which obscures the abstract and general symbolic manipulation going on.

This is all highly subjective of course, de gustibus non disputandem.

neilv•1y ago
You mean aesthetically, in that interspersed all-caps makes the code visually less soothingly sensual?

I can sympathize, but let me make a non-aesthetic argument...

In large blocks of code, with all-caps, you can see at a glance where all the template substitutions are happening, and also instantly know as you're reading code what are variables and what are template substitutions?

I'm asking because one of my realizations in recent years is that not everyone reads or sees code the same way.

For example, maybe some people are stronger "visual" and some people are stronger "verbal".

For another example of a different in how people perceive and think, some people can visualize an object in their mind almost as if they're looking at it, but other people can only know and describe what it looks like without bringing a visual of it into their head.

With the benefit of the all-caps, I can glance at this and immediately see much of the structure of the template. Without all-caps, I'd have to work harder to find all the pattern variables, and the structure would be obscured.

For a bit kludgy practical matter, as I'm quickly looking at pieces of code in a template, with all-caps, I can look at a fragment of code in isolation and know what are and aren't pattern variables. Without that, I have to go read the top of the template clause (and read through any syntactic scopes of `let-syntax`) and get that in my head, until I get to the fragment of code I originally wanted to look at.

IDE support can make this unnecessary, with a hypothetical great IDE, with familiar syntax coloring. But still, if there is one thing that all-caps should be reserved for, it's something like this.

With all-caps, your code can be sensual, and the jolting all-caps bits are look out, potentially arbitrary code gets pasted into here.

Y_Y•1y ago
Since you asked, my objection is both aesthetic and semantic, though I was really referring to the semantic part above.

I think you've hit the nail on the head with this visual vs. verbal distinction.

I can add a few clarifying details. I don't use IDEs as much as basic text editors maybe with highlighting, and I try not to rely on any fancy features. It does worry me that the allcaps use you describe is (afaik) not known to the editor or interpreter, so if you make a mistake or the symbol gets out of sync with its meaning (re: pattern variables) you may have a false signal. Finally I'll say that in the end I can't suggest a good way to treat these special variables, and so maybe I don't get it, or tastes like mine would be better served by a different formalism for macros.

mnemenaut•1y ago
https://github.com/rogerturner/scheme-macros/blob/main/examp... shows stepwise development of a trace-let [the `(example: (fn arg) => result)` forms are tests - see check-examples library]

Googlebook

https://googlebook.google/
461•tambourine_man•4h ago•739 comments

How to make your text look futuristic (2016)

https://typesetinthefuture.com/2016/02/18/futuristic/
105•_vaporwave_•1h ago•10 comments

CERT is releasing six CVEs for serious security vulnerabilities in dnsmasq

https://lists.thekelleys.org.uk/pipermail/dnsmasq-discuss/2026q2/018471.html
167•chizhik-pyzhik•4h ago•74 comments

Show HN: Needle: We Distilled Gemini Tool Calling into a 26M Model

https://github.com/cactus-compute/needle
181•HenryNdubuaku•4h ago•59 comments

Why senior developers fail to communicate their expertise

https://www.nair.sh/guides-and-opinions/communicating-your-expertise/why-senior-developers-fail-t...
273•nilirl•7h ago•140 comments

Quack: The DuckDB Client-Server Protocol

https://duckdb.org/2026/05/12/quack-remote-protocol
119•aduffy•4h ago•27 comments

The Future of Obsidian Plugins

https://obsidian.md/blog/future-of-plugins/
255•xz18r•6h ago•101 comments

Rendering the Sky, Sunsets, and Planets

https://blog.maximeheckel.com/posts/on-rendering-the-sky-sunsets-and-planets/
368•ibobev•8h ago•34 comments

Reimagining the mouse pointer for the AI era

https://deepmind.google/blog/ai-pointer/
89•devhouse•4h ago•76 comments

Beyond Semantic Similarity

https://arxiv.org/abs/2605.05242
23•44za12•2h ago•2 comments

Learning Software Architecture

https://matklad.github.io/2026/05/12/software-architecture.html
493•surprisetalk•12h ago•100 comments

Is this why science advances one funeral at a time?

https://nautil.us/is-this-why-science-advances-one-funeral-at-a-time-1280650
14•Brajeshwar•4h ago•14 comments

Bambu Lab is abusing the open source social contract

https://www.jeffgeerling.com/blog/2026/bambu-lab-abusing-open-source-social-contract/
967•rubenbe•7h ago•329 comments

Launch HN: Voker (YC S24) – Analytics for AI Agents

https://voker.ai
33•ttpost•6h ago•19 comments

Dead.Letter (CVE-2026-45185) – How XBOW found an unauthenticated RCE on Exim

https://xbow.com/blog/dead-letter-cve-2026-45185-xbow-found-rce-exim
47•fedek_•4h ago•23 comments

Show HN: Statewright – Visual state machines that make AI agents reliable

https://github.com/statewright/statewright
47•azurewraith•7h ago•12 comments

Riding the D in Los Angeles: city hopes new subway stations will be game changer

https://www.theguardian.com/us-news/2026/may/09/los-angeles-subway-public-transportation
27•raybb•1d ago•7 comments

When life gives you lemons, write better error messages

https://wix-ux.com/when-life-gives-you-lemons-write-better-error-messages-46c5223e1a2f
88•luispa•4d ago•25 comments

Show HN: Agentic interface for mainframes and COBOL

https://www.hypercubic.ai/hopper
40•sai18•5h ago•19 comments

Canada’s Bill C-22 Is a Repackaged Version of Last Year’s Surveillance Nightmare

https://www.eff.org/deeplinks/2026/05/canadas-bill-c-22-repackaged-version-last-years-surveillanc...
190•Brajeshwar•4h ago•58 comments

We accidentally recreated old Facebook

https://amrshawky.com/posts/we-accidentally-recreated-fb/
37•amr_shawky•2d ago•23 comments

Meta employees protest against mouse tracking tech at US offices

https://www.reuters.com/sustainability/society-equity/meta-us-employees-organize-protest-against-...
40•delichon•1h ago•23 comments

Instructure pays ransom to Canvas hackers

https://www.insidehighered.com/news/tech-innovation/administrative-tech/2026/05/11/instructure-pa...
197•Cider9986•19h ago•189 comments

Show HN: Gigacatalyst – Extend your SaaS with an embedded AI builder

30•namanyayg•5h ago•8 comments

SQL: Incorrect by Construction

https://chreke.com/posts/sql-incorrect-by-construction
25•ingve•4h ago•22 comments

Text Blaze (YC W21) Is Hiring for a No-AI Summer Internship

https://www.ycombinator.com/companies/text-blaze/jobs/P4CCN62-the-blaze-no-ai-summer-internship
1•scottfr•10h ago

The Real Story of Troy

https://storica.club/blog/troy-was-real/
44•cemsakarya•2d ago•18 comments

The Surprisingly Long Life of the Vacuum Tube

https://www.construction-physics.com/p/the-surprisingly-long-life-of-the
56•surprisetalk•1d ago•36 comments

Snowflake Postgres, Lakebase, HorizonDB: Picking the Lock-In You Want

https://thebuild.com/blog/2026/05/12/snowflake-postgres-lakebase-horizondb-picking-the-lock-in-yo...
16•samaysharma•2h ago•4 comments

The Moth Story Map

https://themoth.org/dispatches/story-map
17•jxmorris12•3d ago•3 comments