frontpage.
newsnewestaskshowjobs

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.

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]
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.

Google SWE points 48 AI agents at NASA Lidar, finds unmapped Maya pyramid in 72h

https://pietromiotti.com/latest/maya-site/?maya
679•eyvindn•4h ago•257 comments

Pharo in the Browser with WebAssembly

https://massimo-nocentini.github.io/pharo-vm/world.html
76•xkriva11•2h ago•16 comments

Why aren't we shipping faster now?

https://cabird.com/talks/shipping-faster/
19•azhenley•23m ago•17 comments

Atuin Threads: All your agent sessions on every machine

https://blog.atuin.sh/threads-agent-sessions/
81•linsomniac•2h ago•33 comments

A false smoke alarm almost drowned Jane Street's only NYC datacenter

https://michael.bacarella.com/2026/11/10/false-smoke-alarm-jane-street-datacenter/
12•mbac32768•18m ago•0 comments

Can a Linear Program Do Weight-Space Programming?

https://nathan.rs/posts/weight-space-lp/
154•emschwartz•4h ago•25 comments

Hyper-Realistic Sand with WebGL2

https://av.github.io/safe-sand/
102•everlier•3h ago•17 comments

Using voltage glitching to unleash the A100 in my mining card

https://blog.kate.land/posts/using-voltage-glitching-to-unlock-the-a100/
160•lae•6h ago•60 comments

Show HN: Godbolt-in-a-floating-window for Neovim (C, C++, Rust)

https://github.com/0xdeadf1sh/AssemblyForNeovim
45•0xdeadf1sh•3h ago•4 comments

We need more goat sacrifices

https://www.experimental-history.com/p/we-need-more-goat-sacrifices
90•iamnothere•4h ago•51 comments

I asked every TV manufacturer 17 questions about how they spy on you

https://www.theverge.com/tech/1012372/tv-privacy-acr-questions
197•Brajeshwar•3h ago•97 comments

Protecting SSH Keys with macOS Secure Enclave

https://gatezh.com/posts/macos-secure-enclave-ssh-keys/
346•js2•12h ago•122 comments

Apple is killing its Support Community forum next week

https://www.theverge.com/tech/1031507/apple-community-support-forum-shutting-down
144•saikatsg•2h ago•80 comments

EventSourcingDB 1.3.0 Is Available

https://www.eventfoundation.io/resources/blog/eventsourcingdb-1-3-0-is-available
23•goloroden•3h ago•1 comments

Peer-to-peer WebRTC connections with built-in signaling and discovery

https://github.com/lukks/like-webrtc
40•LuKks•2d ago•12 comments

Tinfoil (YC P25) is hiring an applied AI security engineer in San Francisco

1•FrasiertheLion•4h ago

The hardest notes to find on the guitar fretboard

https://www.gitori.com/blog/articles/hardest-notes-on-the-guitar-fretboard
6•udit99•51m ago•3 comments

Show HN: Klad, a paint app your coding agent can drive (source-available)

https://github.com/klad-app/klad
7•ambewas•56m ago•0 comments

Attention to Mamba: A Recipe for Cross-Architecture Distillation

https://machinelearning.apple.com/research/attention-mamba-distillation
23•zerop•3h ago•1 comments

The Computer Graphics Book of Knowledge

https://www.cs.cmu.edu/~ph/nyit/masson/history.htm
7•num42•1h ago•0 comments

Next-Level Benchmarking Overfitting – Thomas Neumann

http://databasearchitects.blogspot.com/2026/11/next-level-benchmarking-overfitting.html
49•artrax•4h ago•9 comments

Apple has new Mac app coming to make running local AI models easy

https://9to5mac.com/2026/11/10/apple-has-new-mac-app-coming-to-make-running-local-ai-models-easy/
443•linolevan•19h ago•460 comments

Scion is back and is going to sell a kei truck in America

https://www.theautopian.com/scion-is-back-and-its-going-to-sell-a-freaking-kei-truck-in-america/
538•NaOH•21h ago•371 comments

In Defense of Giving a Shit

https://www.possibilityspace.org/blog/posts/in-defence-of-giving-a-shit/
81•mrkn1•4h ago•56 comments

Welcome to Ed and Sam's great adventure

https://www.hintz.org/trip/
6•mooreds•1d ago•1 comments

Open research, stronger privacy: Making Firefox users harder to fingerprint

https://blog.mozilla.org/security/2026/11/10/open-research-stronger-privacy-making-firefox-users-...
113•Vinnl•4h ago•25 comments

A Brain Teaser of an Obituary

https://www.nytimes.com/2026/11/10/obituaries/steve-selvin-dead.html
3•droidjj•1d ago•0 comments

Physically Controllable Relighting of Photographs

https://yaksoy.github.io/PhysicalRelighting/
47•summarity•5h ago•10 comments

Six Math Essentials

https://teorth.github.io/tao-web/six-math-essentials.html
317•digital55•19h ago•58 comments

Show HN: Black Ops II statically recompiled to native ARM64 macOS

https://github.com/adrbn/bo2-mac
112•adrbn•12h ago•47 comments