git.s-ol.nu alive / 40d9549
move array and struct constructor into builtins s-ol 1 year, 8 months ago
3 changed file(s) with 42 addition(s) and 49 deletion(s). Raw diff Collapse all Expand all
44 -- documentation.
55 --
66 -- @module builtin
7 import Builtin, Op, T, FnDef, Input, const, val, evt from require 'alv.base'
7 import Builtin, Op, PureOp, T, FnDef, Input, const, val, evt, Struct, Array
8 from require 'alv.base'
89 import Constant from require 'alv.result'
910 import Error from require 'alv.error'
1011 import RTNode from require 'alv.rtnode'
399400 tick: =>
400401 @out\set @inputs.sig!
401402
403 array = Constant.meta
404 meta:
405 name: 'array'
406 summary: "Construct an array."
407 examples: { '(array a b c…)' }
408 description: "Produces an array of values."
409
410 value: do
411 any = val! / evt!
412
413 class extends PureOp
414 pattern: any!*0
415 type: (args) => Array #args, args[1]\type!
416
417 tick: =>
418 args = @unwrap_all!
419 @out\set args
420
421 struct = Constant.meta
422 meta:
423 name: 'struct'
424 summary: "Construct an struct."
425 examples: { '(struct key1 val1 [key2 val2…])' }
426 description: "Produces an struct of values."
427
428 value: do
429 key = const.str / const.sym
430 val = val! / evt!
431 pair = (key + val)\named 'key', 'val'
432
433 class extends PureOp
434 pattern: pair*0
435 type: (pairs) =>
436 Struct {key.result!, val\type! for {:key, :val} in *pairs}
437
438 tick: =>
439 pairs = @unwrap_all!
440 @out\set {key, val for {:key, :val} in *pairs}
441
402442 get = Constant.meta
403443 meta:
404444 name: 'get'
445485 '~': to_sig
446486 '!': to_evt
447487
448 :get
488 :array, :struct, :get
449489
450490 true: Constant.meta
451491 meta:
+0
-22
alv-lib/array.moon less more
0 import PureOp, Constant, T, Array, val, evt from require 'alv.base'
1
2 any = val! / evt!
3
4 array = Constant.meta
5 meta:
6 name: 'array'
7 summary: "Construct an array."
8 examples: { '(array a b c…)' }
9 description: "Produces an array of values."
10
11 value: class extends PureOp
12 pattern: any!*0
13 type: (args) => Array #args, args[1]\type!
14
15 tick: =>
16 args = @unwrap_all!
17 @out\set args
18
19 {
20 :array
21 }
+0
-25
alv-lib/struct.moon less more
0 import PureOp, Constant, T, Struct, const, val, evt from require 'alv.base'
1
2 key = const.str / const.sym
3 val = val! / evt!
4 pair = (key + val)\named 'key', 'val'
5
6 struct = Constant.meta
7 meta:
8 name: 'struct'
9 summary: "Construct an struct."
10 examples: { '(struct key1 val1 [key2 val2…])' }
11 description: "Produces an struct of values."
12
13 value: class extends PureOp
14 pattern: pair*0
15 type: (pairs) =>
16 Struct {key.result!, val\type! for {:key, :val} in *pairs}
17
18 tick: =>
19 pairs = @unwrap_all!
20 @out\set {key, val for {:key, :val} in *pairs}
21
22 {
23 :struct
24 }