Remove let

Yes, bizarrely, this does require editing the implementation of `defn` a little. Without the import, HyList isn't in scope. Defining `let` made it visible due to black magic regarding automatic import.
This commit is contained in:
Kodi Arfer 2017-02-04 09:54:39 -08:00
parent 31f3a55a26
commit 2a44928eb7
2 changed files with 5 additions and 13 deletions

2
NEWS
View File

@ -1,6 +1,8 @@
Changes from 0.12.1
[ Language Changes ]
* `let` has been removed. Python's scoping rules do not make a proper
implementation of it possible. Use `setv` instead.
* xor: If exactly one argument is true, return it
[ Bug Fixes ]

View File

@ -41,23 +41,13 @@
(defmacro defn [name lambda-list &rest body]
"define a function `name` with signature `lambda-list` and body `body`"
(if (not (= (type name) HySymbol))
(import hy)
(if (not (= (type name) hy.HySymbol))
(macro-error name "defn takes a name as first argument"))
(if (not (isinstance lambda-list HyList))
(if (not (isinstance lambda-list hy.HyList))
(macro-error name "defn takes a parameter list as second argument"))
`(setv ~name (fn ~lambda-list ~@body)))
(defmacro let [variables &rest body]
"Execute `body` in the lexical context of `variables`"
(if (not (isinstance variables HyList))
(macro-error variables "let lexical context must be a list"))
(if (= (len variables) 0)
`((fn []
~@body))
`((fn []
(setv ~@variables)
~@body))))
(defmacro if-python2 [python2-form python3-form]
"If running on python2, execute python2-form, else, execute python3-form"
(import sys)