Merge pull request #1773 from Kodiologist/gensymplify

Simplify gensym format
This commit is contained in:
Kodi Arfer 2019-05-05 11:15:43 -04:00 committed by GitHub
commit 819e2121dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 19 additions and 16 deletions

View File

@ -15,6 +15,9 @@ New Features
* Added a special form `setx` to create Python 3.8 assignment expressions.
* New list? function.
* New tuple? function.
* Gensyms now have a simpler format that's more concise when
mangled (e.g., `_hyx_XsemicolonXfooXvertical_lineX1235` is now
`_hyx_fooXUffffX1`).
Bug Fixes
------------------------------

View File

@ -968,10 +968,10 @@ written without accidental variable name clashes.
.. code-block:: clj
=> (gensym)
u':G_1235'
HySymbol('_G\uffff1')
=> (gensym "x")
u':x_1236'
HySymbol('_x\uffff2')
.. seealso::

View File

@ -214,7 +214,7 @@ Return series of accumulated sums (or other binary function results)."
(instance? HySymbol s))
(import [threading [Lock]])
(setv _gensym_counter 1234)
(setv _gensym_counter 0)
(setv _gensym_lock (Lock))
(defn gensym [&optional [g "G"]]
@ -224,7 +224,7 @@ Return series of accumulated sums (or other binary function results)."
(global _gensym_lock)
(.acquire _gensym_lock)
(try (do (setv _gensym_counter (inc _gensym_counter))
(setv new_symbol (HySymbol (.format "_;{0}|{1}" g _gensym_counter))))
(setv new_symbol (HySymbol (.format "_{}\uffff{}" g _gensym_counter))))
(finally (.release _gensym_lock)))
new_symbol)

View File

@ -282,12 +282,12 @@ result['y in globals'] = 'y' in globals()")
(import [hy.models [HySymbol]])
(setv s1 (gensym))
(assert (isinstance s1 HySymbol))
(assert (= 0 (.find s1 "_;G|")))
(assert (= 0 (.find s1 "_G\uffff")))
(setv s2 (gensym "xx"))
(setv s3 (gensym "xx"))
(assert (= 0 (.find s2 "_;xx|")))
(assert (= 0 (.find s2 "_xx\uffff")))
(assert (not (= s2 s3)))
(assert (not (= (str s2) (str s3)))))
(assert (not (= (string s2) (string s3)))))
(defn test-identity []
"NATIVE: testing the identity function"

View File

@ -166,9 +166,9 @@
(setv _ast2 (hy-compile (hy-parse macro1) __name__))
(setv s1 (to_source _ast1))
(setv s2 (to_source _ast2))
;; and make sure there is something new that starts with _;G|
(assert (in (mangle "_;G|") s1))
(assert (in (mangle "_;G|") s2))
;; and make sure there is something new that starts with _G\uffff
(assert (in (mangle "_G\uffff") s1))
(assert (in (mangle "_G\uffff") s2))
;; but make sure the two don't match each other
(assert (not (= s1 s2))))
@ -193,8 +193,8 @@
(setv _ast2 (hy-compile (hy-parse macro1) __name__))
(setv s1 (to_source _ast1))
(setv s2 (to_source _ast2))
(assert (in (mangle "_;a|") s1))
(assert (in (mangle "_;a|") s2))
(assert (in (mangle "_a\uffff") s1))
(assert (in (mangle "_a\uffff") s2))
(assert (not (= s1 s2))))
(defn test-defmacro/g! []
@ -217,8 +217,8 @@
(setv _ast2 (hy-compile (hy-parse macro1) __name__))
(setv s1 (to_source _ast1))
(setv s2 (to_source _ast2))
(assert (in (mangle "_;res|") s1))
(assert (in (mangle "_;res|") s2))
(assert (in (mangle "_res\uffff") s1))
(assert (in (mangle "_res\uffff") s2))
(assert (not (= s1 s2)))
;; defmacro/g! didn't like numbers initially because they
@ -247,8 +247,8 @@
(setv _ast2 (hy-compile (hy-parse macro1) __name__))
(setv s1 (to_source _ast1))
(setv s2 (to_source _ast2))
(assert (in (mangle "_;res|") s1))
(assert (in (mangle "_;res|") s2))
(assert (in (mangle "_res\uffff") s1))
(assert (in (mangle "_res\uffff") s2))
(assert (not (= s1 s2)))
;; defmacro/g! didn't like numbers initially because they