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.

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.

The newest Instagram “exploit” is the goofiest I've seen

https://www.0xsid.com/blog/meta-account-takeover-fiasco
1098•ssiddharth•6h ago•259 comments

Debug Project

https://debug.com/
79•Eridanus2•1h ago•34 comments

AI Agent Guidelines for CS336 at Stanford

https://github.com/stanford-cs336/assignment1-basics/blob/main/CLAUDE.md
256•prakashqwerty•5h ago•103 comments

Should you normalize RGB values by 255 or 256?

https://30fps.net/pages/255-vs-256-division/
143•pplanu•4h ago•57 comments

CS336: Language Modeling from Scratch

https://cs336.stanford.edu/
300•kristianpaul•8h ago•39 comments

What appear to be biochemical processes may be a natural feature of geology

https://www.quantamagazine.org/the-dirt-that-refused-to-die-20260601/
164•speckx•7h ago•47 comments

Florida sues OpenAI and Sam Altman over AI risks

https://www.politico.com/news/2026/06/01/openai-hit-with-florida-lawsuit-00944215
151•cyunker•6h ago•117 comments

GrapheneOS Speech Services version 2 released

https://discuss.grapheneos.org/d/36001-grapheneos-speech-services-version-2-released
57•pretext•3h ago•8 comments

Stealing from Biologists to Compile Haskell Faster

https://www.iankduncan.com/engineering/2026-05-30-stealing-from-biologists-to-compile-haskell-fas...
68•mooreds•2d ago•4 comments

I made my phone slow on purpose

https://vinewallapp.com/notes/i-made-my-phone-slow-on-purpose/
145•gcampos•4d ago•132 comments

A 10 year old Xeon is all you need

https://point.free/blog/gemma-4-on-a-2016-xeon/
652•cafkafk•15h ago•265 comments

Ask HN: Who is hiring? (June 2026)

131•whoishiring•7h ago•200 comments

Nvidia RTX Spark

https://www.nvidia.com/en-us/products/rtx-spark/
269•shenli3514•17h ago•229 comments

Microsoft builds MacBook Pro rival with NVIDIA-powered Surface Laptop Ultra

https://www.windowslatest.com/2026/06/01/microsoft-builds-its-ultimate-macbook-pro-rival-with-the...
96•jbk•10h ago•264 comments

GitHub and the crime against software

https://eblog.fly.dev/githubbad.html
162•pplanu•3h ago•61 comments

Anthropic confidentially submits draft S-1 to the SEC

https://www.anthropic.com/news/confidential-draft-s1-sec
395•surprisetalk•6h ago•314 comments

Windows GOG DOS Games on M-Series Macs

https://f055.net/technology/windows-gog-dos-games-on-m-series-macs/
122•f055•9h ago•75 comments

Only 17% of all 64-bit Integers are products of two 32-bit integers

https://lemire.me/blog/2026/05/22/only-17-of-all-64-bit-integers-are-products-of-two-32-bit-integ...
178•sebg•4d ago•86 comments

I missed Network integrated tools on Windows so I built a Linux equivalent

https://github.com/thongor77/nmlinux
12•magetriste•2d ago•2 comments

Flipper Zero Zig Template

https://github.com/NishantJoshi00/flipper-template
114•Nars088•9h ago•7 comments

Building a custom mount for a telescoping webcam

https://john.mercouris.online/webcam-mount.html
7•jmercouris•1d ago•2 comments

Launch HN: Expanse (YC P26) – Unlock Wasted GPU Capacity

62•ismaeel_bashir•9h ago•14 comments

Ask HN: Who wants to be hired? (June 2026)

70•whoishiring•7h ago•234 comments

Malicious npm packages detected across Red Hat Cloud Services

https://github.com/RedHatInsights/javascript-clients/issues/492
701•kurmiashish•9h ago•390 comments

The Pirate Bay Remains Resilient, 20 Years After the Raid

https://torrentfreak.com/the-pirate-bay-remains-resilient-20-years-after-the-raid/
448•speckx•8h ago•227 comments

Superintelligence: The Idea That Eats Smart People (2016)

https://idlewords.com/talks/superintelligence.htm
100•thoughtpeddler•4h ago•111 comments

Sysadmining Like It's 2009

https://lambdacreate.com/posts/sysadmining-like-its-2009
82•yacin•8h ago•32 comments

Linux Basics for Hackers (2019)

https://github.com/ahegazy0/linux-basics-for-hackers-notes
118•ibobev•9h ago•21 comments

Handmade Hawaiian Islands Map

https://www.notesfromtheroad.com/roam/hawaiian-islands-map.html
42•bovermyer•2d ago•16 comments

Show HN: Textile – A desktop app for weaving together bits of text

https://www.gettextile.app
19•stack_framer•3h ago•7 comments