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:
parent
31f3a55a26
commit
2a44928eb7
2
NEWS
2
NEWS
@ -1,6 +1,8 @@
|
|||||||
Changes from 0.12.1
|
Changes from 0.12.1
|
||||||
|
|
||||||
[ Language Changes ]
|
[ 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
|
* xor: If exactly one argument is true, return it
|
||||||
|
|
||||||
[ Bug Fixes ]
|
[ Bug Fixes ]
|
||||||
|
@ -41,23 +41,13 @@
|
|||||||
|
|
||||||
(defmacro defn [name lambda-list &rest body]
|
(defmacro defn [name lambda-list &rest body]
|
||||||
"define a function `name` with signature `lambda-list` and body `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"))
|
(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"))
|
(macro-error name "defn takes a parameter list as second argument"))
|
||||||
`(setv ~name (fn ~lambda-list ~@body)))
|
`(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]
|
(defmacro if-python2 [python2-form python3-form]
|
||||||
"If running on python2, execute python2-form, else, execute python3-form"
|
"If running on python2, execute python2-form, else, execute python3-form"
|
||||||
(import sys)
|
(import sys)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user