GNU Guile 比其他语言好 10 倍 (2021)
How GNU Guile is 10x better (2021)

原始链接: https://www.draketo.de/software/guile-10x

Wisp 是一种新语言,利用了 **同像性** 的力量——将代码视为数据,反之亦然的能力,这是基于 Lisp 的语言的关键优势。这使得优雅的代码操作和更简单的语言扩展成为可能,因为代码可以轻松地在不同的程序层之间传递。 开发者通过多次迭代改进 Wisp 代码来利用这一点:首先是初稿,然后是增量改进,最后是准备好用于规范的代码。这种方法在创建复杂功能时尤其有价值,例如为游戏 *dryads wake* 创建一个“提问”宏。 该宏使用同像性将选项表示为数据(问题),同时允许答案直接执行代码(例如,`,(load-game)`)。 `Ask` 宏和 `QuoteFirsts` 函数促进了这一点,从而实现了交互式游戏元素的动态且易于管理实现。

一个黑客新闻的讨论围绕着一个声称 GNU Guile “比其他语言好 10 倍” 的说法。评论者承认 Guile 具有有趣的特性和稳定的生态系统,但大多不同意这个说法的程度。 一个主要的批评集中在 Guile 的文档上,被描述为组织混乱,假定先验知识(RnRS/SFRIs),并遭受“专家诅咒”——对新手不清楚。一位用户建议举办黑客马拉松来改进基本的文档元素,例如定义缩略语。 其他人指出,与 Python 和 JavaScript 等现代替代方案相比,Guile 的优势不那么明显,其生产力优势更多地来自于生态系统的稳定性,而不是革命性的特性。提及 Crystal、Elixir 和 Gleam 等其他语言突出了替代偏好以及找到“正确”工具的挑战。 还有一个注释提到一个有用但未维护的库 `guile-pfds`。
相关文章

原文

Compared to non-lisp languages, the regularity of s-expressions and being able to treat code as data and the other way round (homoiconicity) is a big advantage.

thanks to pinoaffe for this point.

This is an essential elegance I want to conserve in wisp.

Wikipedia notes as advantage that

extending the language with new concepts typically becomes simpler, as data representing code can be passed between the meta and base layer of the program. — Homoiconicity: Uses and Advantages

and

It can be much easier to understand how to manipulate the code since it can be more easily understood as simple data (since the format of the language itself is a data format). — Homoiconicity: Uses and Advantages

For Wisp I use this a lot, because it allows me to do a first simple pass over the code, add incremental improvements and finally have the cleaned up code that I can pass to the language spec definition:

define : wisp-scheme-read-chunk port
         . "Read and parse one chunk of wisp-code"
     let : :  lines : wisp-scheme-read-chunk-lines port
          wisp-make-improper
            wisp-replace-empty-eof
              wisp-unescape-underscore-and-colon
                wisp-replace-paren-quotation-repr
                  wisp-propagate-source-properties
                    wisp-scheme-indentation-to-parens lines

Also this enables me to write a Question-Asking macro for dryads wake without going totally insane. Usage:

Choose
    : new game
      ,(first-encounter)
    : load game
      ,(load-game)
    : show prologue
      ,(prologue) ,(welcome-screen)
    : exit
      We hope you enjoyed our game!

Definition:

define-syntax-rule : Choose . choices
   . "Ask questions, apply consequences"
   begin 
     say-lines : ("") ;; newline before question
     let loop :
       ;; Get the response via the Ask macro 
       ;; to evaluate inline-code incrementally
       define resp : string->number : Ask choices
       or
         cond
           : equal? resp 1
             Respond1 choices
           : equal? resp 2
             Respond2 choices
           : equal? resp 3
             Respond3 choices
           : equal? resp 4
             Respond4 choices
           : equal? resp 5
             Respond5 choices
           : equal? resp 6
             Respond6 choices
           else
             . #f
         loop

define-syntax Ask
  lambda (x)
    syntax-case x ()
      : _ (choices ...)
        #` begin
           ask (QuoteFirsts (choices ...))


QuoteFirsts interprets the questions as data but leaves the answers as code which can e.g. use ,(load-game) to open the load game dialog.

联系我们 contact @ memedata.com