masak / bel

An interpreter for Bel, Paul Graham's Lisp language
GNU General Public License v3.0
27 stars 1 forks source link

Include a fun test about a Lisp quine #416

Closed masak closed 9 months ago

masak commented 3 years ago

This cliki page has an example, apparently from Bawden's article about quasiquotation (go figure):

(let ((let '`(let ((let ',let))
               ,let)))
  `(let ((let ',let))
     ,let))

Apparently, in Common Lisp, this is a quine — that is, the expression evaluates to itself.

Include a Bel test that does the same thing. Naturally, since Bel's let macro has a syntax with slightly fewer parentheses, we need to make the corresponding modifications to the quine. I think this would do it:

(let let '`(let let ',let
         ,let)
  `(let let ',let
     ,let))

That is, we've kept the parentheses around the let combinations which are actually let declarations, but removed the two types in Common Lisp's special operator let which (a) group the declarations together in a group and (b) group individual var/init-form pairs together as units.

masak commented 3 years ago

Good news! I got it right, sort of:

> (let let '`(let let ',let ,let) `(let let ',let ,let))
(let let (quote #1=(bquote (let let (quote (comma let)) (comma let)))) #1)
> (= (let let '`(let let ',let ,let) `(let let ',let ,let)) '(let let (quote #1=(bquote (let let (quote (comma let)) (comma let)))) #1))
t
> (= (let let '`(let let ',let ,let) `(let let ',let ,let)) '(let let '`(let let ',let ,let) `(let let ',let ,let)))
t

Note the thing with the shared pair. But equality holds whether we take the sharing into account or not.