frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Open in hackernews

Show HN: Kent Dybvig's Scheme Machine in 400 Lines of C (Heap-Memory Model)

https://gist.github.com/swatson555/8cc36d8d022d7e5cc44a5edb2c4f7d0b
226•swatson741•4mo ago

Comments

lambdaone•4mo ago
Amazing, and you could see how this could be translated into perhaps a couple of thousand lines of assembly code to boostrap Scheme almost from the bare metal, similar to the early IBM 709 LISP.

A thought: I wonder if an LLM would be up to the job of writing the assembly code from this?

nostrademons•4mo ago
You could just use a C compiler to write the assembly code from this, and it'd be far less buggy.

Before there were LLMs, there were about 65 years of other program-writing-programs to save labor.

f1shy•4mo ago
As simple as

gcc -S heap-lisp.c

kazinator•4mo ago
Generally speaking, program-writing-programs (when they are not either buggy, or being updated to a new version) predictably write the same thing from the same specification according to rules.

LLMs do not replace program-writing-programs; they should be used to work with program-writing-programs, not as a replacement.

E.g. I wouldn't use an LLM to convert a grammar to LR parsing tables, but perhaps to get help with the grammar file.

listeria•4mo ago
> I wonder if an LLM would be up to the job of writing the assembly code from this?

I could see a compiler doing that.

lambdaone•4mo ago
I'm quite aware of the existence of compilers, having worked on bootstrapping a production LISP compiler in the past. My point being that this would be an interesting experiment to do this "naïvely", given how close C is to (for example) PDP-11 assembly code.
tgv•4mo ago
If it's speed you're after, much more analysis (and thus code) is needed. See V8.
swatson741•4mo ago
A C compiler can output fairly readable code if you turn off optimizations, and it's definitely not going to take thousands of lines to do this in modern assembly. It may be only just barely a thousand lines to do this in aarch64, and the LLM can probably do it.

From what I've seen the LLM do it can definitely enhance these programs if you know what to ask, and it can explain how any piece this code works. It may even be able to add garbage collection to the evaluator since the root registers are explicit, and the evaluator only acts on static memory.

dannyobrien•4mo ago
This is the path that the GNU Mes and Guix folks are taking: https://guix.gnu.org/en/blog/2023/the-full-source-bootstrap-...

(sans LLMs -- I believe they have a Scheme (GNU Mes) that can be compiled from their 357 byte bootloader, and that Scheme can run a C compiler that can compile tinycc, and I think there's a path from tinycc to compiling gcc. I'm not sure how far it can get after that -- this blog post[1] implies that you still need a binary of guile to run Gash, which is a POSIX shell written in Scheme. I'm guessing the plan is to either simplify Gash or complexify Mes to be able to remove Guile as a dependency.

[1] https://guix.gnu.org/en/blog/2023/the-full-source-bootstrap-...

anthomtb•4mo ago
> I wonder if an LLM would be up to the job of writing the assembly code from this

Why ask a cluster of GPU's to do something any single CPU from the last 30 years can accomplish?

CobrastanJorji•4mo ago
I ask this question every day, and I think the answer is the same as the answer to the question "why are you doing this with blockchain?"
tensility•4mo ago
If your Scheme were a native compiler rather than an interpreter (i.e. like Chez) and written in (a constrained subset of) Scheme, then you could use an itty-bitty Scheme interpreter written like this to bootstrap the core of your native Scheme compiler so that the interpreted version of it could compile itself to native binary.

Given that this was the path that one of Dr. Dybvig's post-doc acolytes, Dr. Michael Ashley, taught us in his Scheme-based compiler class, I must guess that this was also Kent's path and that that was the intent for this little interpreter. I suppose I should (finally) take the time to read his dissertation.

glouwbug•4mo ago
I believe MIT Scheme compiled directly to C by intermingling switch statements and gotos to emulate its call stack. Problem was, as programs grew, compile times weren't linear. I gave it a shot once, it was a somewhat spiritual experience:

https://github.com/glouw/switch

kkylin•4mo ago
Thanks! Do you mean MIT Scheme's C backend? I've used MIT Scheme on and off for a long time and have never touched the C backend & have no idea how it works, so this is interesting.

(MIT Scheme also has a native code compiler for Intel CPUs, which seems to be what most users of MIT Scheme (an admittedly small community) actually use.)

glouwbug•4mo ago
If you'd like to define the backend like this, it's the easiest way to compile to C; we're just repurposing C as a general-purpose assembler: https://glouw.com/2023/11/07/Switch.html

I believe MIT-scheme took it a step further with gnu extensions which allowed you to take the address of a label like &&label, which allowed for function pointers: https://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html

f1shy•4mo ago
I think a very rudimentary implementation (which is easy to understand) is in the SICP book
soegaard•4mo ago
Even MIT Scheme was used with SICP, the Scheme implementation in the book is different from MIT Scheme.

MIT Scheme was for a long period one of the leading Scheme implementations. It lacks support for Apple Silicon, so it is not as popular now, as it once was.

https://www.gnu.org/software/mit-scheme/

f1shy•4mo ago
Yes. In Apple the memory can be writable XOR executable. MIT scheme needs to write on pages that will execute, so it will trigger the MMU..
anthk•4mo ago
Install chicken scheme. Then:

       sudo chicken-install srfi-203

       sudo chicken-install srfi-216
At ~/.csirc put:

    (import scheme)
    (import (srfi 203))
    (import (srfi 216))
Now you can do nearly all the execises.
shawn_w•4mo ago
I don't see anything in the manual about MIT scheme compiling to C, just to its own native code object files and some portable bytecode...

https://www.gnu.org/software/mit-scheme/documentation/stable...

aag•4mo ago
It's there, but the documentation is weak.

The release notes from long ago when that back end was released are here, and give some detail:

https://share.google/xmUnDhC7lndujD7TI

fanf2•4mo ago
Instead of representing atoms as string literals, you can represent them as global variables, eg

    const char conti[] = "conti";
Then you can use pointer comparison instead of strcmp().
swatson741•4mo ago
You'll still probably need the `strcmp` because the pointers won't be the same unless you check for them and make them the same.

You may be thinking about how `eq?` (reference equality) works in scheme. That's usually done by hashing the identifier string. Which is the more general solution to this equality problem.

fanf2•4mo ago
The atoms strcmp()ed by the interpreter are all created by the compiler so you can ensure the pointers are equal by construction.
swatson741•4mo ago
You're right `virtmach` only works on things that are output from `compile` and maintaining the invariant that virtmach lisp uses those pointers isn't difficult to do in with how the evaluator is presented.

It gives virtmach lisp and scheme different ontology, but I can't think of any practical reason why that would matter other than it makes things a little bit more complicated. But, then again if I'm thinking practically scheme should be using hashed identifiers, and then there's no reason for them to have different ontology and conceptually we're right back where we started with virtmach lisp and scheme using identifiers as objects.

ashton314•4mo ago
Kent Dybvig also wrote Chez Scheme [1] which on most benchmarks is far-and-away the fastest [2] Scheme implementation.

Racket recently got rewritten to be based off of Chez [3] and I have it from the maintainer of Racket himself that it’s paid off well: better performance and a smaller, more maintainable codebase.

1: https://github.com/cisco/ChezScheme (also, pronounced “Shay Scheme”)

2: https://ecraven.github.io/r7rs-benchmarks/

3: https://m.youtube.com/watch?v=s3Q3M2wZ7rI&pp=0gcJCRsBo7VqN5t...

qhwudbebd•4mo ago
Reading and hacking on the Chez Scheme codebase is always a treat and rather inspiring, especially compared with more mainstream compilers and code generators. As well as Kent Dybvig, Andy Keep's contribution (nanopass) is super-impressive. The whole thing is so cleanly designed and beautifully expressed.
saltcured•4mo ago
Since these seems to be turning into an opportunity to shout out for other Scheme implementations...

I was a happy use of VSCM by Matthias Blume, doing a bunch of my university assignments with it on my Linux PC in the early 90s.

kfarr•4mo ago
Shout out to Mr. Dybvig who taught our intro to CS course at IU Bloomington 20+ years ago! It was my first intro to recursion (of course the class was all scheme based) and gave me much more confidence in software development coming from a self taught background.
smrq•4mo ago
I had the great pleasure of studying compilers, and then optimizing compilers, with Dybvig at IU in the late 2000s. He was a phenomenal professor; obviously deeply knowledgeable (that's a given), but also uncommonly gifted at imparting that knowledge.
keith_analog•4mo ago
I had the good fortune to be in Dybvig’s compilers class in the mid 2000s. The way it was presented really brought the concepts to life and made it enjoyable.
Vivtek•4mo ago
One of the funniest moments I remember from that class is he suddenly noticed the parens didn't match in the snippet he'd written on the board - so he counted through the trailing ))))) and inserted a close paren at the right place.
Vivtek•4mo ago
I took his Compilers class about 30 years ago. I really wish I still had those notes.
miga•4mo ago
How much faster or slower than 400 lines compiler? https://news.ycombinator.com/item?id=26191243
djmips•4mo ago
Have you tested this? Does it work?
swatson741•4mo ago
It works but it can’t do much other than demonstrate semantics. The evaluator won’t even be able to add numbers for example.
spyrja•4mo ago
I couldn't get it to do much. Also noticed a subtle bug here:

  next = compile(read(buffer), cons("halt", NULL));
C doesn't guarantee the order in which arguments to a function are processed. Since 'cons' relies on 'read' being called first, the result is undefined behavior. (In fact I had to fix that before it would even "run" on my system.)
iberator•4mo ago
Do Forth bootstrapping now
rogerallen•4mo ago
Can someone give more info on the relevance of this particular code?
apgwoz•4mo ago
This is an implementation of an interpreter from his dissertation. https://www.cs.unc.edu/xcms/wpfiles/dissertations/dybvig.pdf
dented42•4mo ago
What an utterly delightful itty bitty scheme. <3
matheusmoreira•4mo ago
> note! repl implies there's a top-level but there isn't...

I'm a little confused. How could it not have a top-level environment? There are environments which are extended on function application by consing lists of variables and their values onto the old environment.

  void* extend(void* env, void* vars, void* vals) {
    return cons(cons(vars, vals), env);
  }
This implies a root environment whose cdr is nil.
lynx97•4mo ago
No matter what I try, I always get:

heap-lisp: heap-lisp.c:99: cons: Assertion `istext(textptr)' failed.

I wonder if the ptr comparison in istext is actually UB?

shawn_w•4mo ago
If textptr is not an element of the text array, then it's undefined.

Study confirms experience beats youthful enthusiasm

https://www.theregister.com/2026/02/07/boomers_vs_zoomers_workplace/
1•Willingham•6m ago•0 comments

The Big Hunger by Walter J Miller, Jr. (1952)

https://lauriepenny.substack.com/p/the-big-hunger
1•shervinafshar•8m ago•0 comments

The Genus Amanita

https://www.mushroomexpert.com/amanita.html
1•rolph•12m ago•0 comments

We have broken SHA-1 in practice

https://shattered.io/
1•mooreds•13m ago•1 comments

Ask HN: Was my first management job bad, or is this what management is like?

1•Buttons840•14m ago•0 comments

Ask HN: How to Reduce Time Spent Crimping?

1•pinkmuffinere•16m ago•0 comments

KV Cache Transform Coding for Compact Storage in LLM Inference

https://arxiv.org/abs/2511.01815
1•walterbell•20m ago•0 comments

A quantitative, multimodal wearable bioelectronic device for stress assessment

https://www.nature.com/articles/s41467-025-67747-9
1•PaulHoule•22m ago•0 comments

Why Big Tech Is Throwing Cash into India in Quest for AI Supremacy

https://www.wsj.com/world/india/why-big-tech-is-throwing-cash-into-india-in-quest-for-ai-supremac...
1•saikatsg•22m ago•0 comments

How to shoot yourself in the foot – 2026 edition

https://github.com/aweussom/HowToShootYourselfInTheFoot
1•aweussom•22m ago•0 comments

Eight More Months of Agents

https://crawshaw.io/blog/eight-more-months-of-agents
3•archb•24m ago•0 comments

From Human Thought to Machine Coordination

https://www.psychologytoday.com/us/blog/the-digital-self/202602/from-human-thought-to-machine-coo...
1•walterbell•25m ago•0 comments

The new X API pricing must be a joke

https://developer.x.com/
1•danver0•26m ago•0 comments

Show HN: RMA Dashboard fast SAST results for monorepos (SARIF and triage)

https://rma-dashboard.bukhari-kibuka7.workers.dev/
1•bumahkib7•26m ago•0 comments

Show HN: Source code graphRAG for Java/Kotlin development based on jQAssistant

https://github.com/2015xli/jqassistant-graph-rag
1•artigent•31m ago•0 comments

Python Only Has One Real Competitor

https://mccue.dev/pages/2-6-26-python-competitor
3•dragandj•33m ago•0 comments

Tmux to Zellij (and Back)

https://www.mauriciopoppe.com/notes/tmux-to-zellij/
1•maurizzzio•33m ago•1 comments

Ask HN: How are you using specialized agents to accelerate your work?

1•otterley•35m ago•0 comments

Passing user_id through 6 services? OTel Baggage fixes this

https://signoz.io/blog/otel-baggage/
1•pranay01•35m ago•0 comments

DavMail Pop/IMAP/SMTP/Caldav/Carddav/LDAP Exchange Gateway

https://davmail.sourceforge.net/
1•todsacerdoti•36m ago•0 comments

Visual data modelling in the browser (open source)

https://github.com/sqlmodel/sqlmodel
1•Sean766•38m ago•0 comments

Show HN: Tharos – CLI to find and autofix security bugs using local LLMs

https://github.com/chinonsochikelue/tharos
1•fluantix•39m ago•0 comments

Oddly Simple GUI Programs

https://simonsafar.com/2024/win32_lights/
1•MaximilianEmel•39m ago•0 comments

The New Playbook for Leaders [pdf]

https://www.ibli.com/IBLI%20OnePagers%20The%20Plays%20Summarized.pdf
1•mooreds•39m ago•1 comments

Interactive Unboxing of J Dilla's Donuts

https://donuts20.vercel.app
1•sngahane•41m ago•0 comments

OneCourt helps blind and low-vision fans to track Super Bowl live

https://www.dezeen.com/2026/02/06/onecourt-tactile-device-super-bowl-blind-low-vision-fans/
1•gaws•42m ago•0 comments

Rudolf Vrba

https://en.wikipedia.org/wiki/Rudolf_Vrba
1•mooreds•43m ago•0 comments

Autism Incidence in Girls and Boys May Be Nearly Equal, Study Suggests

https://www.medpagetoday.com/neurology/autism/119747
1•paulpauper•44m ago•0 comments

Wellness Hotels Discovery Application

https://aurio.place/
1•cherrylinedev•45m ago•1 comments

NASA delays moon rocket launch by a month after fuel leaks during test

https://www.theguardian.com/science/2026/feb/03/nasa-delays-moon-rocket-launch-month-fuel-leaks-a...
2•mooreds•45m ago•0 comments