mirror of
https://github.com/janet-lang/janet
synced 2025-04-13 14:23:11 +00:00
Allow expressions as keys in destructuring.
This commit is contained in:
parent
5e9d1d07b9
commit
23dcfb986e
@ -107,7 +107,7 @@ static void destructure(DstCompiler *c, Dst left, DstSlot right,
|
||||
const DstKV *kv = NULL;
|
||||
while ((kv = dstc_next(left, kv))) {
|
||||
DstSlot newright;
|
||||
DstSlot kslot = dstc_cslot(dst_ast_unwrap(kv->key));
|
||||
DstSlot kslot = dstc_value(dstc_fopts_default(c), kv->key);
|
||||
Dst subval = kv->value;
|
||||
localright = dstc_preread(c, ast, 0xFF, 1, right);
|
||||
localsub = dstc_lslotn(c, 0xFF, 3);
|
||||
|
@ -127,6 +127,19 @@
|
||||
(assert (= (string.find "123" "abc123def") 3) "string.find positive")
|
||||
(assert (= (string.find "1234" "abc123def") nil) "string.find negative")
|
||||
|
||||
# Test destructuring
|
||||
(do
|
||||
(def test-tab @{:a 1 :b 2})
|
||||
(def {:a a :b b} test-tab)
|
||||
(assert (= a 1) "dictionary destructuring 1")
|
||||
(assert (= b 2) "dictionary destructuring 2"))
|
||||
(do
|
||||
(def test-tab @{'a 1 'b 2 3 4})
|
||||
(def {'a a 'b b (+ 1 2) c} test-tab)
|
||||
(assert (= a 1) "dictionary destructuring 3")
|
||||
(assert (= b 2) "dictionary destructuring 4")
|
||||
(assert (= c 4) "dictionary destructuring 5 - expression as key"))
|
||||
|
||||
# Marshal
|
||||
|
||||
(defn testmarsh [x msg]
|
||||
|
Loading…
x
Reference in New Issue
Block a user