Skip to content

Commit 9fb22d0

Browse files
committed
chapter A: self-hosting (wip)
1 parent 5d15bac commit 9fb22d0

File tree

4 files changed

+75
-78
lines changed

4 files changed

+75
-78
lines changed

interp.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"fmt"
55
)
66

7-
const disableTcoFuncs = false // caution: if `true`, cannot def `macro`s; this bool is just for quick temporary via-REPL trouble-shootings to see if TCO got somehow broken (or to enable call tracing for trouble-shooting)
7+
const disableTcoFuncs = true // caution: if `true`, cannot def `macro`s; this bool is just for quick temporary via-REPL trouble-shootings to see if TCO got somehow broken (or to enable call tracing for trouble-shooting)
88
const disableTracing = true || !disableTcoFuncs
99

1010
// to confirm TCO still works, uncomment the 2 commented lines in `evalAndApply` below that are referring to `id`.

mal_compat.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ var malCompat = (os.Getenv("MAL_COMPAT") != "")
1010
func makeCompatibleWithMAL() {
1111
// simple aliases: special-forms
1212
for mals, ours := range map[ExprIdent]ExprIdent{
13-
"def!": "def",
14-
"fn*": "fn",
15-
"try*": "try",
13+
"def!": "def",
14+
"fn*": "fn",
15+
"try*": "try",
16+
"quasiquote": "quasiQuote",
1617
} {
1718
it := specialForms[ours]
1819
if specialForms[mals] = it; it == nil {

self-hosted-mal/tests/step7_quote.mal

Lines changed: 69 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -278,72 +278,72 @@ a
278278
`[splice-unquote 0]
279279
;=>[splice-unquote 0]
280280

281-
;; Debugging quasiquote
282-
(quasiquoteexpand nil)
283-
;=>nil
284-
(quasiquoteexpand 7)
285-
;=>7
286-
(quasiquoteexpand a)
287-
;=>(quote a)
288-
(quasiquoteexpand {"a" b})
289-
;=>(quote {"a" b})
290-
(quasiquoteexpand ())
291-
;=>()
292-
(quasiquoteexpand (1 2 3))
293-
;=>(cons 1 (cons 2 (cons 3 ())))
294-
(quasiquoteexpand (a))
295-
;=>(cons (quote a) ())
296-
(quasiquoteexpand (1 2 (3 4)))
297-
;=>(cons 1 (cons 2 (cons (cons 3 (cons 4 ())) ())))
298-
(quasiquoteexpand (nil))
299-
;=>(cons nil ())
300-
(quasiquoteexpand (1 ()))
301-
;=>(cons 1 (cons () ()))
302-
(quasiquoteexpand (() 1))
303-
;=>(cons () (cons 1 ()))
304-
(quasiquoteexpand (1 () 2))
305-
;=>(cons 1 (cons () (cons 2 ())))
306-
(quasiquoteexpand (()))
307-
;=>(cons () ())
308-
(quasiquoteexpand (f () g (h) i (j k) l))
309-
;=>(cons (quote f) (cons () (cons (quote g) (cons (cons (quote h) ()) (cons (quote i) (cons (cons (quote j) (cons (quote k) ())) (cons (quote l) ())))))))
310-
(quasiquoteexpand (unquote 7))
311-
;=>7
312-
(quasiquoteexpand a)
313-
;=>(quote a)
314-
(quasiquoteexpand (unquote a))
315-
;=>a
316-
(quasiquoteexpand (1 a 3))
317-
;=>(cons 1 (cons (quote a) (cons 3 ())))
318-
(quasiquoteexpand (1 (unquote a) 3))
319-
;=>(cons 1 (cons a (cons 3 ())))
320-
(quasiquoteexpand (1 b 3))
321-
;=>(cons 1 (cons (quote b) (cons 3 ())))
322-
(quasiquoteexpand (1 (unquote b) 3))
323-
;=>(cons 1 (cons b (cons 3 ())))
324-
(quasiquoteexpand ((unquote 1) (unquote 2)))
325-
;=>(cons 1 (cons 2 ()))
326-
(quasiquoteexpand (a (splice-unquote (b c)) d))
327-
;=>(cons (quote a) (concat (b c) (cons (quote d) ())))
328-
(quasiquoteexpand (1 c 3))
329-
;=>(cons 1 (cons (quote c) (cons 3 ())))
330-
(quasiquoteexpand (1 (splice-unquote c) 3))
331-
;=>(cons 1 (concat c (cons 3 ())))
332-
(quasiquoteexpand (1 (splice-unquote c)))
333-
;=>(cons 1 (concat c ()))
334-
(quasiquoteexpand ((splice-unquote c) 2))
335-
;=>(concat c (cons 2 ()))
336-
(quasiquoteexpand ((splice-unquote c) (splice-unquote c)))
337-
;=>(concat c (concat c ()))
338-
(quasiquoteexpand [])
339-
;=>(vec ())
340-
(quasiquoteexpand [[]])
341-
;=>(vec (cons (vec ()) ()))
342-
(quasiquoteexpand [()])
343-
;=>(vec (cons () ()))
344-
(quasiquoteexpand ([]))
345-
;=>(cons (vec ()) ())
346-
(quasiquoteexpand [1 a 3])
347-
;=>(vec (cons 1 (cons (quote a) (cons 3 ()))))
348-
(quasiquoteexpand [a [] b [c] d [e f] g])
349-
;=>(vec (cons (quote a) (cons (vec ()) (cons (quote b) (cons (vec (cons (quote c) ())) (cons (quote d) (cons (vec (cons (quote e) (cons (quote f) ()))) (cons (quote g) ()))))))))
281+
;; ;; Debugging quasiquote
282+
;; (quasiquoteexpand nil)
283+
;; ;=>nil
284+
;; (quasiquoteexpand 7)
285+
;; ;=>7
286+
;; (quasiquoteexpand a)
287+
;; ;=>(quote a)
288+
;; (quasiquoteexpand {"a" b})
289+
;; ;=>(quote {"a" b})
290+
;; (quasiquoteexpand ())
291+
;; ;=>()
292+
;; (quasiquoteexpand (1 2 3))
293+
;; ;=>(cons 1 (cons 2 (cons 3 ())))
294+
;; (quasiquoteexpand (a))
295+
;; ;=>(cons (quote a) ())
296+
;; (quasiquoteexpand (1 2 (3 4)))
297+
;; ;=>(cons 1 (cons 2 (cons (cons 3 (cons 4 ())) ())))
298+
;; (quasiquoteexpand (nil))
299+
;; ;=>(cons nil ())
300+
;; (quasiquoteexpand (1 ()))
301+
;; ;=>(cons 1 (cons () ()))
302+
;; (quasiquoteexpand (() 1))
303+
;; ;=>(cons () (cons 1 ()))
304+
;; (quasiquoteexpand (1 () 2))
305+
;; ;=>(cons 1 (cons () (cons 2 ())))
306+
;; (quasiquoteexpand (()))
307+
;; ;=>(cons () ())
308+
;; (quasiquoteexpand (f () g (h) i (j k) l))
309+
;; ;=>(cons (quote f) (cons () (cons (quote g) (cons (cons (quote h) ()) (cons (quote i) (cons (cons (quote j) (cons (quote k) ())) (cons (quote l) ())))))))
310+
;; (quasiquoteexpand (unquote 7))
311+
;; ;=>7
312+
;; (quasiquoteexpand a)
313+
;; ;=>(quote a)
314+
;; (quasiquoteexpand (unquote a))
315+
;; ;=>a
316+
;; (quasiquoteexpand (1 a 3))
317+
;; ;=>(cons 1 (cons (quote a) (cons 3 ())))
318+
;; (quasiquoteexpand (1 (unquote a) 3))
319+
;; ;=>(cons 1 (cons a (cons 3 ())))
320+
;; (quasiquoteexpand (1 b 3))
321+
;; ;=>(cons 1 (cons (quote b) (cons 3 ())))
322+
;; (quasiquoteexpand (1 (unquote b) 3))
323+
;; ;=>(cons 1 (cons b (cons 3 ())))
324+
;; (quasiquoteexpand ((unquote 1) (unquote 2)))
325+
;; ;=>(cons 1 (cons 2 ()))
326+
;; (quasiquoteexpand (a (splice-unquote (b c)) d))
327+
;; ;=>(cons (quote a) (concat (b c) (cons (quote d) ())))
328+
;; (quasiquoteexpand (1 c 3))
329+
;; ;=>(cons 1 (cons (quote c) (cons 3 ())))
330+
;; (quasiquoteexpand (1 (splice-unquote c) 3))
331+
;; ;=>(cons 1 (concat c (cons 3 ())))
332+
;; (quasiquoteexpand (1 (splice-unquote c)))
333+
;; ;=>(cons 1 (concat c ()))
334+
;; (quasiquoteexpand ((splice-unquote c) 2))
335+
;; ;=>(concat c (cons 2 ()))
336+
;; (quasiquoteexpand ((splice-unquote c) (splice-unquote c)))
337+
;; ;=>(concat c (concat c ()))
338+
;; (quasiquoteexpand [])
339+
;; ;=>(vec ())
340+
;; (quasiquoteexpand [[]])
341+
;; ;=>(vec (cons (vec ()) ()))
342+
;; (quasiquoteexpand [()])
343+
;; ;=>(vec (cons () ()))
344+
;; (quasiquoteexpand ([]))
345+
;; ;=>(cons (vec ()) ())
346+
;; (quasiquoteexpand [1 a 3])
347+
;; ;=>(vec (cons 1 (cons (quote a) (cons 3 ()))))
348+
;; (quasiquoteexpand [a [] b [c] d [e f] g])
349+
;; ;=>(vec (cons (quote a) (cons (vec ()) (cons (quote b) (cons (vec (cons (quote c) ())) (cons (quote d) (cons (vec (cons (quote e) (cons (quote f) ()))) (cons (quote g) ()))))))))

special_forms.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,7 @@ func stdQuasiQuote(env *Env, args []Expr) (*Env, Expr, error) {
213213
if unquote, ok, err := isListStartingWithIdent(args[0], exprIdentUnquote, 2); err != nil {
214214
return nil, nil, err
215215
} else if ok {
216-
if unquoted, err := evalAndApply(env, unquote[1]); err != nil {
217-
return nil, nil, err
218-
} else {
219-
return nil, unquoted, nil
220-
}
216+
return env, unquote[1], nil
221217
}
222218

223219
expr := make(ExprList, 0, len(list))

0 commit comments

Comments
 (0)