summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2019-06-28 21:25:43 -0700
committerKaz Kylheku <kaz@kylheku.com>2019-06-28 21:25:43 -0700
commit1fb6f6691d5b6fb6b037bb14073694f651f2b9fc (patch)
treead4d2e030419290b52c87d9e1fe73e4b4e11c4bb /tests
parent43323e1431d5919b8e296b37c38affe1228c27d1 (diff)
downloadtxr-1fb6f6691d5b6fb6b037bb14073694f651f2b9fc.tar.gz
txr-1fb6f6691d5b6fb6b037bb14073694f651f2b9fc.tar.bz2
txr-1fb6f6691d5b6fb6b037bb14073694f651f2b9fc.zip
defset: bind new-val-sym to temporary variable.
Users of defset no longer have to ensure that in the store form, the symbol which gives the new value to be stored is inserted only once. * share/txr/stdlib/defset.tl (defset-expander): Transform the store form by inserting a temporary variable using alet. (sub-list, sub-vec, sub-str): These place forms no longer require a local gensym. * txr.1: Updated doc. * tests/012/defset.tl: The expected output for the inc case now incorporates a gensym that comes from the compiled defset macro. Since we can't control that by means of the gensym counter, we resort to extracting it from the expansion itself, then check the test case against a template which incorporates that gensym. We check that the extracted item really is a gensym: it's a symbol with no home package whose name starts with "g".
Diffstat (limited to 'tests')
-rw-r--r--tests/012/defset.tl14
1 files changed, 12 insertions, 2 deletions
diff --git a/tests/012/defset.tl b/tests/012/defset.tl
index 601be292..110f3c64 100644
--- a/tests/012/defset.tl
+++ b/tests/012/defset.tl
@@ -2,10 +2,20 @@
(defset foo (:key x y -- a b c (d 4)) n ^(bar ,x ,y, a, b, c ,d ,n))
+;; obtain identity of new-val gensym: this is baked into defset
+(defvarl %new-val-sym% (caar (last (cadr (expand '(inc (foo 1 2)))))))
+
+(test
+ (and (symbolp %new-val-sym%)
+ (null (symbol-package %new-val-sym%))
+ (starts-with "g" (symbol-name %new-val-sym%)))
+ t)
+
(test
(expand '(set (foo 1 2 :a 3 :b 4) 5))
(bar 1 2 3 4 nil 4 5))
-(test
+(vtest
(expand '(inc (foo 1 2 :a 3 :b 4) 5))
- (bar 1 2 3 4 nil 4 (+ (foo 1 2 :a 3 :b 4) 5)))
+ ^(let ((,%new-val-sym% (+ (foo 1 2 :a 3 :b 4) 5)))
+ (bar 1 2 3 4 () 4 ,%new-val-sym%)))