Title here
Summary here
(macro -> (arg fn1 ...fns) (...))
Chain calls on a given value, for a nicer syntax
arg
: value to transform...fns
: series of functions to apply one by one to arg
(import std.Macros)
(-> "f0" f1) # equivalent to (f1 "f0")
(-> "f0" f1 f2 f3) # equivalent to (f3 (f2 (f1 "f0")))
(-> "f0" f1 (apply _ f2) (apply _ f3)) # equivalent to (apply (apply (f1 "f0") f2) f3)
(macro partial (func ...defargs) (...))
Create a partial function with prefilled arguments
func
: function to make partial...defargs
: predefined arguments(import std.Macros)
(let test_func (fun (a b c) (* a b c)))
(let test_func1 (partial test_func 1))
(let test_func2 (partial test_func1 2))
(print (test_func1 2 3)) # 6
(print (test_func2 3)) # 6
(macro partial2 (call ...args) (...))
Create a partial function with prefilled arguments, allowing some arguments to be skipped
call
: function to make partial...args
: predefined arguments(import std.Macros)
(let test_func (fun (a b c) (* a b c)))
(let test_func3 (partial2 test_func 1 _ 3))
(print (test_func3 2)) # 6
(macro unless (cond ...body) (...))
Create a reversed condition
cond
: conditionbody
: then node (or then/else nodes)(import std.Macros)
(unless (canCall? dog)
(print "dog can't call")
(print "dog can actually call us!"))
(unless false
(print "this will always be executed"))
(macro until (cond body) (...))
Iterate until the condition is truthy
cond
: conditionbody
: loop body(import std.Macros)
(mut data [0])
(until (= 10 (len data))
(append! data (+ 1 (@ data -1))))
(print data) # [0 1 2 3 4 5 6 7 8 9]