mirror of
https://github.com/janet-lang/janet
synced 2024-09-29 07:20:41 +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;
|
const DstKV *kv = NULL;
|
||||||
while ((kv = dstc_next(left, kv))) {
|
while ((kv = dstc_next(left, kv))) {
|
||||||
DstSlot newright;
|
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;
|
Dst subval = kv->value;
|
||||||
localright = dstc_preread(c, ast, 0xFF, 1, right);
|
localright = dstc_preread(c, ast, 0xFF, 1, right);
|
||||||
localsub = dstc_lslotn(c, 0xFF, 3);
|
localsub = dstc_lslotn(c, 0xFF, 3);
|
||||||
|
@ -127,6 +127,19 @@
|
|||||||
(assert (= (string.find "123" "abc123def") 3) "string.find positive")
|
(assert (= (string.find "123" "abc123def") 3) "string.find positive")
|
||||||
(assert (= (string.find "1234" "abc123def") nil) "string.find negative")
|
(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
|
# Marshal
|
||||||
|
|
||||||
(defn testmarsh [x msg]
|
(defn testmarsh [x msg]
|
||||||
|
Loading…
Reference in New Issue
Block a user