more-magic.net

more-magic.net · Personal blog · on HN since 2013

Peter Bex writes about Scheme programming, Chicken Scheme internals, Clojure, web standards, and software security.

What HN saysHN commenters recommend his Chicken Scheme garbage collector article as one of the best introductions to generational GC and Cheney on the MTA.
35HN people shared it
18linked it in comments
31stories submitted
949story points
9 months agolast shared
2013people per year2026

Most-shared posts

  1. 1
    Chicken Scheme internals: the garbage collector
    16 people · 281 points · first shared 2014 · 25 comments on HN
  2. 2
    Clojure from a Schemer's perspective (2021)
    6 people · 334 points · first shared 2021 · 85 comments on HN
  3. 3
    What to Expect from Chicken 6
    3 people · 11 points · first shared 2024 · 1 comments on HN
  4. 4
    An Appeal to the Whatwg (2018)
    3 people · 7 points · first shared 2018 · 3 comments on HN
  5. 5
    Structurally fixing injection bugs (2012)
    3 people · 2 points · first shared 2013 · discussion on HN
  6. 6
    Chicken Scheme Internals: Data Representation
    2 people · 58 points · first shared 2015 · discussion on HN
  7. 7
    FOSS for Digital Sovereignty in the EU
    2 people · 3 points · first shared 2026 · discussion on HN
  8. 8
    Scheme c integration
    2 people · first shared 2021
  9. 9
    Crunch – a Scheme compiler with a minimal runtime
    1 people · 190 points · first shared 2024 · 71 comments on HN
  10. 10
    Let's add a statistical profiler to Chicken Scheme
    1 people · 50 points · first shared 2016 · 3 comments on HN
  11. 11
    CHICKEN's numeric tower: part 1
    1 people · 3 points · first shared 2016 · discussion on HN
  12. 12
  13. 13
    CHICKEN's numeric tower
    1 people · 3 points · first shared 2017 · discussion on HN
  14. 14
    Trustworthy software through non-profits?
    1 people · 2 points · first shared 2025 · discussion on HN
  15. 15
    Adding Weak References to Chicken
    1 people · 2 points · first shared 2023 · discussion on HN

What HN people wrote when they linked it

sjamaan · 2026-01-15
My blog is at https://www.more-magic.net, mostly about programming (with a focus on Scheme) or adjacent stuff.
Reisen · 2018-11-08
One of the best intros to generational garbage collection is on chicken internals[1]. If you've ever wondered about GCs I thoroughly recommend giving the article a read, it's full of interesting asides as well. I think I would use chicken more but usually when reaching for scheme it seems to be because I want something embeddable. Even so, extremely excited about this release! [1]: https://www.more-magic.net/posts/internals-gc.html
MichaelBurge · 2016-03-31
"High level" is in the eye of the beholder, but I don't know that C is the best example to pick on: Before LLVM it was pretty common to target C as your portable assembly language. Just to give an example, I think GHC targets C-- as one of the steps in its transformations, and still outputs C when you're porting it to a new platform or building a cross-compiler. I don't know that it's useful to say that GHC ceases to be a compiler when you use it to target weird platforms. And the Chicken Scheme compiler outputs C code[1] that doesn't look like a human wrote it: The C code uses a trampoline to organize function calls, and it periodically garbage-collects your stack cleaning up old frames as you call functions. [1] http://www.more-magic.net/posts/internals-gc.html
nostrademons · 2021-09-03
Note that Chicken has a very interesting garbage-collection algorithm called "Cheney on the MTA". Basically, the stack is the heap, and no function ever returns. The compiler converts every program to continuation-passing style, where instead of a function returning, it tail-calls a continuation. When the stack exhausts its limit, the runtime longjmps back to a trampoline. Variables captured by the current continuation form the roots of a copying generational GC - the runtime traces every pointer from them and copies the live objects to the heap. The stack then unwinds, with every uncopied object being garbage that gets re-used the next time the stack grows. It's pretty amazing that it works, particularly in relatively portable C. Also gets fairly decent performance, too: as Schemes go Chicken is one of the faster ones. https://www.more-magic.net/posts/internals-gc.html https://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.54.7143
qwertyuiop924 · 2016-10-24
right. Brace yourself, you're in for a long ride. If you want to get in-depth on Cheney on the MTA, I'd reccomend Peter Bex's article on the Chicken GC (http://www.more-magic.net/posts/internals-gc.html), and the original paper, "CONS should not CONS its arguments, part II: Cheney on the MTA". But I'll do my best to sum it up here. Cheney on the MTA is a really neat hack that allows for cheap continuations, realtively efficient C compilation of Scheme code, and an effective garbage collection scheme. Effectively, with CMTA, you have a generational GC, but the first generation is stack allocated. When the stack allocations run out of space, all the data is copied out to the heap, into the second generation of GC. This is super effective because most data is only allocated for a short time, so it never goes out to heap, and your accesses are closer together, and also on the stack, so there's less chance of a cache miss. But it gets better: In Scheme, a program's continuation (think basically its instruction pointer and stack state) can be reified as an actual data structure. However, since you're GCing the stack already, this doesn't causr any overheard, or at least not nearly as much as it does in, say, Guile, which has to copy the stack every single time a continuation is created. The reason it's called Cheney on the MTA is because it uses Cheney's algorithm for GC, and because it's using the stack to hold data, popping the stack would invalidate program state, so it…
PaulHoule · 2025-04-21
Only highly abstract languages like Brainfuck https://esolangs.org/wiki/Brainfuck which are too simple to have WTFs, although you might say the whole thing is a WTF. I think AVR-8 assembler is WTF free, but I'd like a more powerful macro assembler which would probably introduce a WTF. Common Lisp is full of WTFs, I went through many stages of grief reading Graham's On Lisp but most notable was "if he was using Clojure he wouldn't be fighting with nconc". People have problems with Clojure too https://www.more-magic.net/posts/thoughts-on-clojure.html
soegaard · 2024-12-17
I would call the code CHICKEN generates for "direct style" not "natural". (I know - it is a cop-out to use "natural" in quotes) Regardless of what we call the style, it isn't simple any more. For people interested in the internals of Chicken Scheme (I suspect sctb already knows): https://www.more-magic.net/posts/internals-gc.html
thesuperbigfrog · 2023-06-05
>> My understanding is that Clojure is meant to be Scheme like, but it is not fully compliant to a Scheme spec, my only guess is due to JVM specific nuances, but I could be wrong. Clojure's syntax and semantics are quite different from Scheme and Common Lisp: https://clojure.org/reference/lisps https://www.more-magic.net/posts/thoughts-on-clojure.html Most differences are due to design choices, not merely JVM nuances. A few differences are due to JVM limitations at the time that Clojure was designed. I don't think any attempt was made to comply with a Scheme spec.
outworlder · 2022-04-15
Chicken Scheme is embedded in C programs with one line. https://wiki.call-cc.org/embedding I've even embedded it in Objective-C programs running in iOS (could make OpenGLES calls in the repl and everything). Full API spec: https://wiki.call-cc.org/man/5/Embedding FFI example: https://wiki.call-cc.org/An%20extended%20FFI%20example https://www.more-magic.net/posts/scheme-c-integration.html
mshroyer · 2021-09-03
It was a configuration manager for what was basically a Linux-based wireless router. The Chicken compiler actually compiles down to C, which has the nice side-effect that you can easily include literal C code. Here's an example: https://www.more-magic.net/posts/scheme-c-integration.html
Joker_vD · 2020-11-09
See also [0], which talks about how Chicken SCHEME (which compiles to portable C) does it. [0] https://www.more-magic.net/posts/internals-gc.html#managing-data-on-th…
divs1210 · 2020-07-02
Cheney on the MTA and its various implementations (like Chicken Scheme [0]) have been allocating objects on the stack for ages. Would like to know how this compares. [0] https://www.more-magic.net/posts/internals-gc.html
davexunit · 2017-02-14
Another day, another string-based template engine that will lead to invalid output and injection attacks. You don't need a new language specifically for templates, you need to use a real programming language with real data structures that represent the HTML/XML nodes. http://www.more-magic.net/posts/structurally-fixing-injection-bugs.htm…
thecombjelly · 2014-10-30
Here is an article discussing the utilization of this technique specifically for CHICKEN scheme. http://www.more-magic.net/posts/internals-gc.html
demetrius · 2013-05-13
I think a blog post by Peter Bex, "Structurally fixing injection bugs", is a better description the problems associated with strings: http://www.more-magic.net/posts/structurally-fixing-injection-bugs.htm… Quoting it: "In other words, you're performing string surgery on the serialized representation of a tree structure. Just stop and think how insane that really sounds!"
hajile · 2019-12-09
CPS is a very bad idea in JS at present. CPS in scheme works because proper tail call optimization exists, so your call stack doesn't explode. In current JS, the only way to make that work is performing a nextTick or setTimeout on every single function which trashes performance of simple things due to exiting your code back to the event loop all the time. <stands on soapbox> There's a special place in hell reserved for companies that deviate from standards because of petty disagreements. Proper tail calls have been a part of the JS spec for 5 versions now. They are implemented in Safari and in popular embedded engines like duktape. MS and Firefox refused to implement. They were in v8 behind a flag, but were removed. v8 devs pitched a fit about stack traces disappearing (even though they disappear across the event loop anyway). The webkit team showed that Chicken scheme's shadow stack works just fine and it's been in production for a long time now (without any issues I'd add). Instead, they insisted that they wanted to revise the standard to require marking tail-recursive functions. They also talked about decreased performance, but JSC team seems to have implemented it with a minimal performance impact, so it's definitely possible. More importantly, JS is a language to make development easy -- we have wasm in development for when speed becomes an issue and it's faster anyway (the label proposal would have also solved the issue by giving devs a choice). They then dropped…

Keyboard shortcuts

/Search
j kNext / previous blog
EnterOpen selected blog
vVisit the blog site
fFollow / unfollow
lSwitch grid / list view
dSwitch dark mode
g hHome
g pTop posts
g tTopics
g fFollowing
g lLiked
g yHistory
g qFAQ
EscBack / close