我用AI在4天内构建了一个Scheme编译器。
I Built a Scheme Compiler with AI in 4 Days

原始链接: https://matthewphillips.info/programming/posts/i-built-a-scheme-compiler-with-ai/

受最近快速开发工具的进步启发,作者在几天内构建了“Puppy Scheme”,一个针对WebAssembly (WASM) 的Scheme编译器。利用AI辅助(Claude)显著提升了性能——将编译时间从3.5分钟减少到11秒。 尽管仍处于alpha阶段,Puppy Scheme已经拥有令人印象深刻的功能,包括支持73%的R5RS/R7RS Scheme标准,WASI 2 & 组件模型,WASM GC,以及有效的死代码消除,从而产生小型二进制文件。值得注意的是,它是自托管的,可以编译自己的代码,并包含一个wasmtime包装器用于原生二进制文件。 作者还开发了一个基本组件模型和一个托管在Cloudflare Workers上的网站,所有这些都在Puppy WASM上运行。虽然仍然存在bug并且主要供个人使用,但该项目展示了新工具在短时间内取得显著成果的力量。更多信息请访问puppy-scheme.org。

马修·菲利普斯在Hacker News上分享说,他用AI在短短四天内构建了一个Scheme编译器。虽然承认它目前由于持续存在的bug还不能用于生产环境,但他对在短时间内达到的深度印象深刻。 这一讨论引发了兴趣,一位评论员指出这与菲利普斯之前使用Astro和AI辅助开发的工作有关。其他人也分享了使用AI(特别是Claude)修复自己代码生成器中bug的类似经历,并质疑AI是否能够真正收敛到可靠的解决方案,或者是否需要仔细的人工监督。 有人提出了编译器范围的问题,并将其与成熟的“48小时内编写自己的Scheme”项目进行了比较。最后,一条评论触及了关于AI原创性的争论,认为它可能是在现有训练数据的基础上构建,但也能够创建真正新的代码。
相关文章

原文

Inspired seeing others quickly built near-production level things that would normally take months or years, I decided to do something that only I would care about: build a Scheme compiler to WASM. I call it Puppy Scheme.

And it happened way faster than I expected. This is a side project so I’m not exactly sure the total number of hours I spent; it was most of last weekend plus an hour or two a couple of weekday nights, but that’s really it.

One night before I went to bed I told Claude to “grind on performance” and when I woke up it had taken compilation time from 3½ minutes down to 11 seconds. Just incredible stuff.

The compiler is definitely still alpha quality but the number of features is impressive for how little time I spent on it. It has:

  • Support for 73% of R5RS and R7RS
  • Support for WASI 2 and the Component Model
  • Uses WASM GC
  • Pretty good dead-code elimination, creating small binaries
  • Self-hosting - Puppy compiles its own source code to puppyc.wasm
  • A wasmtime wrapper to create native binaries
  • A website I built that runs on Puppy wasm in Cloudflare Workers. See the code.

I also started working on a little component model that looks a little like this:

(define count 0)

(define (counter-view)
  (html (div (@ (class "counter"))
          (button (@ (on "click" "on_decrement")) "-")
          (span (@ (class "count")) ,(number->string count))
          (button (@ (on "click" "on_increment")) "+"))))

(define (handle-event handler)
  (cond ((equal? handler "on_decrement")
         (if (> count 0)
             (set! count (- count 1))))
        ((equal? handler "on_increment")
         (set! count (+ count 1)))))

There’s probably more I built that I have already forgotten about. I run into bugs all the time so it’s probably not ready for anyone other than me to use, but I’ve managed to go pretty deep (if not wide) in just a few days of work. We’ve definitely entered a new world.

This is a side-project so I can’t promise too much and am not sure where I’ll take it from here, but if you’re interesting, puppy-scheme.org is where you can check it out.

联系我们 contact @ memedata.com