619 | 619 |
table.insert children, node
|
620 | 620 |
super RTNode :children, result: node.result
|
621 | 621 |
|
|
622 |
mk_thread = (name, thread_first) ->
|
|
623 |
class extends Builtin
|
|
624 |
eval: (scope, tail) =>
|
|
625 |
L\trace "evaling #{@}"
|
|
626 |
assert #tail > 1, "'#{name}' requires at least 2 arguments"
|
|
627 |
|
|
628 |
last_result = tail[1]
|
|
629 |
|
|
630 |
for cell in *tail[2,]
|
|
631 |
assert cell.__class == Cell, "'#{name}'s arguments have to be expressions"
|
|
632 |
|
|
633 |
children = [c for c in *cell.children]
|
|
634 |
if thread_first
|
|
635 |
table.insert children, 2, last_result
|
|
636 |
else
|
|
637 |
table.insert children, last_result
|
|
638 |
|
|
639 |
last_result = Cell cell.tag, children
|
|
640 |
|
|
641 |
super last_result\eval scope, tail
|
|
642 |
|
|
643 |
thread_first = Constant.meta
|
|
644 |
meta:
|
|
645 |
name: '->'
|
|
646 |
summary: "Thread first macro."
|
|
647 |
examples: { '(-> initial [expr1 expr2…])' }
|
|
648 |
description: "
|
|
649 |
Evaluate expressions `expr1`, `expr2`, … while passing the result of the
|
|
650 |
previous expression to the following one, starting with `initial`. The value
|
|
651 |
is always inserted as the first argument."
|
|
652 |
|
|
653 |
value: mk_thread '->', true
|
|
654 |
|
|
655 |
thread_last = Constant.meta
|
|
656 |
meta:
|
|
657 |
name: '->>'
|
|
658 |
summary: "Thread last macro."
|
|
659 |
examples: { '(->> initial [expr1 expr2…])' }
|
|
660 |
description: "
|
|
661 |
Evaluate expressions `expr1`, `expr2`, … while passing the result of the
|
|
662 |
previous expression to the following one, starting with `initial`. The value
|
|
663 |
is always inserted as the last argument."
|
|
664 |
|
|
665 |
value: mk_thread '->>', false
|
622 | 666 |
|
623 | 667 |
Constant.meta
|
624 | 668 |
meta:
|
|
645 | 689 |
'~': to_sig
|
646 | 690 |
'!': to_evt
|
647 | 691 |
|
|
692 |
'->': thread_first
|
|
693 |
'->>': thread_last
|
|
694 |
|
648 | 695 |
:array, :struct
|
649 | 696 |
|
650 | 697 |
:loop, :recur
|