展示HN:用Rust/WASM编写的AutoLISP解释器 – 33年前发明的CAD工作流程
Show HN: AutoLISP interpreter in Rust/WASM – a CAD workflow invented 33 yrs ago

原始链接: https://acadlisp.de/noscript.html

## acadlisp.de:浏览器中的AutoLISP acadlisp.de 是一个基于 Rust 的 AutoLISP 解释器,编译为 WebAssembly,允许 AutoLISP 代码直接在 Web 浏览器中运行——无需 AutoCAD。它源于 1991 年的一个项目,该项目的创建者使用 AutoLISP、CSV 文件和模板自动生成电气原理图,形成了一种独特高效的工作流程。 出于怀旧和保存这种知识的愿望,该项目在线复活了这种自动化能力。AutoLISP 诞生于 1958 年,以其“同像性”(代码即数据)、自修改能力和符号处理而闻名——这些特性在原始原理图生成器中被利用,代码动态地创建更多代码。 该解释器目前支持核心 AutoLISP 函数,如 `defun`、`setq` 以及数学/列表操作,并以 SVG 和 DXF 格式输出图形。一个简单的例子展示了通过单个函数调用绘制矩形。你可以在网站上探索一个交互式演示。

## Rust/WASM AutoLISP 解释器:一份怀旧的保存 一位开发者“holg”创建了一个Rust/WASM AutoLISP解释器,AutoLISP是AutoCAD自90年代初以来使用的Lisp方言。该项目源于开发者数十年前建立的个人工作流程——使用电子表格定义组件,并通过AutoLISP模板自动生成技术图纸。holg意识到这种方法在很大程度上被遗忘,因此他构建了这个解释器,一部分是为了怀旧,另一部分是为了在知识消失之前进行保存。 该项目包含原始的AutoLISP文件和重现,可以直接在网页浏览器中运行。许多评论者分享了使用AutoLISP进行各种应用的类似经历,包括电气原理图、PCB布局、广播设施设计,甚至大型基础设施项目,如光纤网络勘测和立法选区划分。 许多人强调了AutoLISP的强大和效率,尤其是在自动化重复绘图任务方面。讨论揭示了一个共同的主题:AutoLISP赋予了用户*无需*专门的编程专业知识就能显著改善工作流程的能力。虽然现在有现代工具,但该项目是对一个强大但经常被忽视的CAD自动化时代的致敬。代码可在GitHub上找到:[https://github.com/holg/acadlisp/](https://github.com/holg/acadlisp/)。
相关文章

原文
AutoLISP Interpreter in Rust/WASM - acadlisp.de

Try the Interactive Demo

What is acadlisp?

acadlisp is an AutoLISP interpreter written in Rust and compiled to WebAssembly. It runs AutoLISP code directly in the browser - no AutoCAD installation required.

The Story: Schematic Generator 1991

In 1991, a small electrical company in Bavaria, Germany faced a challenge: every machine installation required custom electrical schematics - a time-consuming manual process.

The solution: AutoLISP, the programming language built into AutoCAD. I invented a workflow using CSV files, templates, and LISP code to automate schematic generation. Define components in spreadsheets, feed them through templates, generate complete technical drawings automatically.

I've never met anyone else who used this approach. Now I've built an interpreter in Rust/WASM so this workflow can live on in the browser - partly nostalgia, partly preservation before this knowledge disappears entirely.

LISP as Early AI

LISP (List Processing) was developed in 1958 by John McCarthy and was for decades the language of Artificial Intelligence research. What makes LISP special?

  • Homoiconicity: Code and data share the same structure (lists)
  • Self-modification: Programs can write and modify themselves
  • Symbolic processing: Manipulation of symbols, not just numbers

In the 1991 schematic generator, the code actually wrote itself: inserting a component could trigger more components, templates generated templates.

Technical Details

  • Language: Rust
  • Target: WebAssembly (WASM)
  • Output formats: SVG, DXF (AutoCAD R12/AC1009)
  • Supported AutoLISP functions: defun, setq, if, while, cond, +, -, *, /, sin, cos, sqrt, car, cdr, list, nth, command, princ, and more

Example Code

; Draw a rectangle
(defun draw-box (x y w h)
  (command "LINE" (list x y) (list (+ x w) y) "")
  (command "LINE" (list (+ x w) y) (list (+ x w) (+ y h)) "")
  (command "LINE" (list (+ x w) (+ y h)) (list x (+ y h)) "")
  (command "LINE" (list x (+ y h)) (list x y) ""))

(draw-box 10 10 100 50)

Links

© 2024 acadlisp.de - AutoLISP Interpreter in Rust/WebAssembly

联系我们 contact @ memedata.com