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.

YuE2 · Frontier Music with Symbolic Planning

https://map-yue2.github.io/
44•sexy_seedbox•1h ago•39 comments

Shopify is moving from React Native back to Swift and Kotlin

https://shopify.engineering/back-to-native
801•fnthawar2•12h ago•539 comments

More questions about whether researchers can trust OpenAI with unpublished math

https://mathstodon.xyz/@andreasthom/117240535270608201
689•pred_•19h ago•636 comments

OpenAI Agents API

https://developers.openai.com/api/docs/guides/agents-api/overview
140•aquir•6h ago•89 comments

Google will buy half the electricity of a nuclear power plant

https://www.bbc.com/news/articles/c8r6y4me2g6o
83•lukaspetersson•1h ago•60 comments

The Deathray: A simple way for an untrusted site to freeze a Mac

https://auberon.xyz/blog/posts/deathray/
91•auberonedu•6h ago•57 comments

Don't let anyone take away your big box of cables

https://blog.jim-nielsen.com/2026/hands-off-my-cables/
336•Brajeshwar•10h ago•259 comments

Cognition launches new SWE-2 model, Rivaling Fable 5.1 and GPT-Astra

https://cognition.com/blog/swe-2
358•seelos•10h ago•150 comments

Thelio Mira AI Linux Workstation: 192 GB GPU Memory

https://system76.com/workstations/thelio-mira-ai
33•jonifico•3h ago•26 comments

Technique for Manipulating Satellite Photos Now Reveals Ancient Images (2025)

https://spinoff.nasa.gov/Manipulating_Satellite_Photos_Now_Reveals_Ancient_Images
277•gumby•10h ago•42 comments

NTSB issues investigative update on B-767 runway excursion accident in Miami

https://www.ntsb.gov:443/news/press-releases/Pages/NR20260909.aspx
62•mckn1ght•4h ago•94 comments

Mexican student creates an acoustic fire extinguisher to put out fire in seconds

https://www.upsocl.com/en/16-year-old-mexican-student-creates-an-acoustic-fire-extinguisher-that-...
11•rguiscard•1h ago•0 comments

Customizing my Compaq MX-11800 keyboard

https://blog.webb.page/WM-102
14•NetOpWibby•3d ago•2 comments

Music Theory for the 21st-Century Classroom

https://musictheory.pugetsound.edu/mt21c/MusicTheory.html
167•aanet•9h ago•80 comments

Neki – Sharded Postgres

https://planetscale.com/blog/introducing-neki
203•simon_weber•10h ago•113 comments

Setting up OpenCode with Ollama and sbx on Mac

https://tensorsandtokens.com/posts/opencode-ollama/
7•etoxin•1h ago•4 comments

Forgejo <=16.0.3 Critical RCE

https://codeberg.org/forgejo/forgejo/src/branch/forgejo/release-notes-published/16.0.4.md
154•weierstass•10h ago•57 comments

Recursion into madness

https://blog.coredump.cx/p/recursion-into-madness
40•surprisetalk•3d ago•9 comments

Rust is tier-1 language at Microsoft

https://rustfoundation.org/media/guest-post-rust-is-tier-1-language-at-microsoft/
609•mmastrac•12h ago•350 comments

Hitachi launches CO2 heat pump water heaters with solar-friendly tariff controls

https://www.pv-magazine.com/2026/09/07/hitachi-launches-co2-heat-pump-water-heaters-with-solar-fr...
287•thelastgallon•1d ago•230 comments

What happens when a GPU writes memory

https://blog.doubleword.ai/what-happens-when-a-gpu-writes-memory
49•ibobev•2d ago•1 comments

iPhone Duo

https://www.apple.com/iphone-duo/
1415•thecosmicfrog•1d ago•2442 comments

JEP 544: Ahead-of-Time Code Compilation

https://openjdk.org/jeps/544
79•Skinney•8h ago•26 comments

Douglas Hofstadter: Analogy as the Core of Cognition [video]

https://www.youtube.com/watch?v=n8m7lFQ3njk
148•tosh•4d ago•74 comments

Detecting and countering misuse of AI: September 2026

https://www.anthropic.com/threat-intelligence-report-september-2026
86•garo-pro•8h ago•159 comments

Embedding a bitmap font in your HyperCard stack

https://www.leadedsolder.com/2026/09/08/hypercard-custom-fonts-in-resources.html
20•zdw•2d ago•1 comments

OpenAI’s Navier-Stokes release included a Lean 4 formal proof

https://www.johndcook.com/blog/2026/09/09/formal-method-revolution/
140•ibobev•4h ago•139 comments

Proof of Capture: Apple Reference Image, but open source and using steganography

https://merybenavente.me/blog/proof-of-capture
70•merybenavente•6h ago•51 comments

Show HN: Vertumnus – printable posters of farmers' market produce seasonality

https://vertumnus.fyi
28•perspectivezoom•3d ago•14 comments

Silicon Valley is transforming the military-industrial complex? (2024)

https://costsofwar.watson.brown.edu/paper/how-big-tech-and-silicon-valley-are-transforming-milita...
153•paimapi•10h ago•307 comments