Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
It is a macro that makes code act like it was evaluated in a Lisp-1.
- Loading branch information
Showing
5 changed files
with
32 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
(in-package :experimental) | ||
|
||
;; The macro w/lisp1 works by defining every symbol within the body to | ||
;; expand into itself surrounded by a call to function. The symbol | ||
;; will not be expanded again since function is a special form. Due to | ||
;; the fact that symbol-macrolet is lexically scoped, it is still | ||
;; possible to define variables within the w/lisp1 form, although it | ||
;; is impossible to refer to symbols outside of it. You cannot use any | ||
;; symbol that is defined as a global variable within the w/lisp1, | ||
;; because it is an error to define a symbol-macrolet with the same | ||
;; name as a global variable. It is currently not possible to call | ||
;; variables as procedures. | ||
|
||
(defmacro w/lisp1 (&rest body) | ||
"Evaluate BODY as if in a lisp-1." | ||
`(symbol-macrolet ,(mapeach sym (redup (keep #'symbolp (flat body))) | ||
`(,sym #',sym)) | ||
,@body)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,9 @@ | |
;; From coerce. | ||
:coerce :defcoerce | ||
|
||
;; From lisp1. | ||
:w/lisp1 | ||
|
||
;; From def. | ||
:def :defmemo :mac)) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
(in-package :experimental-tests) | ||
|
||
(deftest lisp1 (clamp-experimental) | ||
(assert-equal '((1 4) (2 5) (3 6)) | ||
(w/lisp1 (map list '(1 2 3) '(4 5 6)))) | ||
(assert-equal '((1 4) (2 5) (3 6)) | ||
(w/lisp1 (let var list | ||
(map var '(1 2 3) '(4 5 6)))))) |