src.elv.sh@v0.21.0-dev.0.20240515223629-06979efb9a2a/pkg/eval/closure_test.elvts (about) 1 /////////// 2 # closure # 3 /////////// 4 5 ## value operations ## 6 ~> kind-of { } 7 ▶ fn 8 ~> eq { } { } 9 ▶ $false 10 ~> var x = { }; put [&$x= foo][$x] 11 ▶ foo 12 13 ## arity check ## 14 ~> {|x| } a b 15 Exception: arity mismatch: arguments must be 1 value, but is 2 values 16 [tty]:1:1-10: {|x| } a b 17 ~> {|x y| } a 18 Exception: arity mismatch: arguments must be 2 values, but is 1 value 19 [tty]:1:1-10: {|x y| } a 20 ~> {|x y @rest| } a 21 Exception: arity mismatch: arguments must be 2 or more values, but is 1 value 22 [tty]:1:1-16: {|x y @rest| } a 23 24 ## unsupported option ## 25 ~> {|&valid=1| } &bad=1 26 Exception: unsupported option: bad 27 [tty]:1:1-20: {|&valid=1| } &bad=1 28 ~> {|&valid1=1 &valid2=2| } &bad1=1 &bad2=2 29 Exception: unsupported options: bad1, bad2 30 [tty]:1:1-40: {|&valid1=1 &valid2=2| } &bad1=1 &bad2=2 31 32 ## introspection ## 33 ~> put {|a b| }[arg-names] 34 ▶ [a b] 35 ~> put {|@r| }[rest-arg] 36 ▶ 0 37 ~> put {|&opt=def| }[opt-names] 38 ▶ [opt] 39 ~> put {|&opt=def| }[opt-defaults] 40 ▶ [def] 41 ~> put { body }[body] 42 ▶ 'body ' 43 ~> put {|x @y| body }[def] 44 ▶ '{|x @y| body }' 45 ~> put { body }[src][code] 46 ▶ 'put { body }[src][code]' 47 48 ## body of fn-defined function ## 49 // Regression test for https://b.elv.sh/1126. 50 ~> fn f { body }; put $f~[body] 51 ▶ 'body '