Skip to content

Commit

Permalink
Added w/lisp1.
Browse files Browse the repository at this point in the history
It is a macro that makes code act like it was evaluated in a Lisp-1.
  • Loading branch information
malisper committed Jan 2, 2015
1 parent d973eb3 commit 930889b
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions clamp-experimental.asd
Expand Up @@ -15,4 +15,5 @@
(:file "ssyntax" :depends-on ("package" "destructuring"))
(:file "ssyntax-defs" :depends-on ("ssyntax"))
(:file "coerce" :depends-on ("package"))
(:file "lisp1" :depends-on ("package"))
(:file "def" :depends-on ("ssyntax" "destructuring"))))))
3 changes: 2 additions & 1 deletion clamp-tests.asd
Expand Up @@ -24,4 +24,5 @@
(:file "clamp-experimental-suite")
(:file "destructuring-suite")
(:file "coerce-suite")
(:file "ssyntax-suite")))))
(:file "ssyntax-suite")
(:file "lisp1-suite")))))
18 changes: 18 additions & 0 deletions experimental/lisp1.lisp
@@ -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))
3 changes: 3 additions & 0 deletions experimental/package.lisp
Expand Up @@ -12,6 +12,9 @@
;; From coerce.
:coerce :defcoerce

;; From lisp1.
:w/lisp1

;; From def.
:def :defmemo :mac))

Expand Down
8 changes: 8 additions & 0 deletions tests/lisp1-suite.lisp
@@ -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))))))

0 comments on commit 930889b

Please sign in to comment.