Skip to content

Commit

Permalink
WIP add destruct->
Browse files Browse the repository at this point in the history
TODO: document
  • Loading branch information
gilch committed Oct 23, 2024
1 parent e21047c commit c5f5a25
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/hissp/macros.lissp
Original file line number Diff line number Diff line change
Expand Up @@ -3621,6 +3621,24 @@ except ModuleNotFoundError: pass"
(,'my.__dict__.pop ".0" None)
,(ns.form scope)))))

(defmacro destruct-> (structure bindings : :* body)
my#(progn
names=(list)
$context=`$#context
walk=(lambda (bindings)
(let (pairs (X#(zip X X : strict True) (iter bindings)))
`(||
: ,@chain#(i#starmap XY#(if-else (H#is_node Y)
`(:* (let (,my.$context (-> ,my.$context ,X))
,(my.walk Y)))
(progn (.append my.names Y)
`(:? (-> ,my.$context ,X))))
pairs)
:? ||)))
values=`(let (,my.$context ,structure)
,(my.walk bindings))
`(let-from (,@my.names) ,my.values ,@body)))

(defmacro case (key default : :* pairs)
<#;Switch case macro.
;;
Expand Down

0 comments on commit c5f5a25

Please sign in to comment.