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•10mo ago

Comments

neilv•10mo 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•10mo 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•10mo 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•10mo 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•10mo 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]

Make macOS consistently bad (unironically)

https://lr0.org/blog/p/macos/
303•speckx•6h ago•208 comments

Brave Browser unable to block certain ads due to Rust language limitations

https://github.com/brave/brave-browser/issues/43098
7•Onavo•6m ago•1 comments

Don't YOLO your file system

https://jai.scs.stanford.edu/
19•mazieres•1h ago•13 comments

Improving Composer through real-time RL

https://cursor.com/blog/real-time-rl-for-composer
51•ingve•1d ago•8 comments

Show HN: Twitch Roulette – Find live streamers who need views the most

https://twitchroulette.net/
46•ellg•3h ago•23 comments

Velxio 2.0 – Emulate Arduino, ESP32, and Raspberry Pi 3 in the Browser

https://github.com/davidmonterocrespo24/velxio
90•dmcrespo•5h ago•19 comments

LG's new 1Hz display is the secret behind a new laptop's battery life

https://www.pcworld.com/article/3096432/lgs-new-1hz-display-is-the-secret-behind-a-new-laptops-ba...
128•robotnikman•4d ago•65 comments

ISBN Visualization

https://annas-archive.gd/isbn-visualization?
96•Cider9986•5h ago•13 comments

Anatomy of the .claude/ folder

https://blog.dailydoseofds.com/p/anatomy-of-the-claude-folder
373•freedomben•11h ago•190 comments

Nashville library launches Memory Lab for digitizing home movies

https://www.axios.com/local/nashville/2026/03/16/nashville-library-digitize-home-movies
101•toomuchtodo•3d ago•26 comments

Telnyx package compromised on PyPI

https://telnyx.com/resources/telnyx-python-sdk-supply-chain-security-notice-march-2026
89•ramimac•16h ago•98 comments

DOJ confirms FBI Director Kash Patel's personal email was hacked

https://arstechnica.com/tech-policy/2026/03/doj-confirms-fbi-director-kash-patels-personal-email-...
177•sebastian_z•4h ago•98 comments

Installing a Let's Encrypt TLS certificate on a Brother printer with Certbot

https://owltec.ca/Other/Installing+a+Let%27s+Encrypt+TLS+certificate+on+a+Brother+printer+automat...
188•8organicbits•12h ago•48 comments

Colorado House passes bill to limit surveillance pricing and wage setting

https://coloradonewsline.com/briefs/surveillance-pricing-wage-setting/
28•jprs•5h ago•3 comments

Explore the Hidden World of Sand

https://magnifiedsand.com/
178•RAAx707•4d ago•35 comments

Meow.camera

https://meow.camera/#4258783365322591678
191•surprisetalk•11h ago•46 comments

The Future of SCIP

https://sourcegraph.com/blog/the-future-of-scip
35•jdorfman•10h ago•16 comments

Building FireStriker: Making Civic Tech Free

https://firestriker.org/blog/building-firestriker-why-im-making-civic-tech-free
90•noleary•1d ago•20 comments

‘Energy independence feels practical’: Europeans building mini solar farms

https://www.euronews.com/2026/03/26/suddenly-energy-independence-feels-practical-europeans-are-bu...
216•vrganj•16h ago•210 comments

Fets and Crosses: Tic-Tac-Toe built from 2458 discrete transistors

https://schilk.co/projects/fetsncrosses/
14•voxadam•3d ago•5 comments

Type Construction and Cycle Detection

https://go.dev/blog/type-construction-and-cycle-detection
5•commotionfever•3d ago•0 comments

Embracing Bayesian methods in clinical trials

https://jamanetwork.com/journals/jama/fullarticle/2847011
79•nextos•3d ago•8 comments

Capability-Based Security for Redox: Namespace and CWD as Capabilities

https://www.redox-os.org/news/nlnet-cap-nsmgr-cwd/
29•ejplatzer•6h ago•3 comments

People inside Microsoft are fighting to drop mandatory Microsoft Account

https://www.windowscentral.com/microsoft/windows-11/people-inside-microsoft-are-fighting-to-drop-...
509•breve•11h ago•402 comments

Desk for people who work at home with a cat

https://soranews24.com/2026/03/27/japan-now-has-a-special-desk-for-people-who-work-at-home-with-a...
329•zdw•10h ago•127 comments

Solving Semantle with the Wrong Embeddings

https://victoriaritvo.com/blog/robust-semantle-solver/
17•evakhoury•3d ago•0 comments

Slovenia becomes first EU country to introduce fuel rationing

https://www.bbc.com/news/articles/c77m4zx6zvmo
152•measurablefunc•4h ago•213 comments

Automatically generate all 3D print files for organizing a drawer

https://geniecrate.com/
24•woktalk•2d ago•14 comments

21,864 Yugoslavian .yu domains

https://jacobfilipp.com/yu/
78•freediver•2d ago•98 comments

Should QA exist?

https://www.rubick.com/should-qa-exist/
99•PretzelFisch•15h ago•132 comments