Welcome, I'm happy to see you here! Feel free to pick a function and add a happy example, the more the merrier!
(in :yo 0 )
# => 121
(def buf-bytes 12 )
(var new-buffer (buffer/new buf-bytes )) #--> @""
(buffer/push new-buffer "hello, world" ) #--> @"hello, world" (reduce2 + [1 2 3 ]) # -> 6
(accumulate2 + [1 2 3 ]) # -> @[1 3 6] (try
(error :fun )
([e ]
(= e :fun )))
# => true
(interleave [:a :b :c ]
[1 2 3 ]
["x" "y" "z" ])
# => @[:a 1 "x" :b 2 "y" :c 3 "z"] (- 1 )
# => -1 (seq [i :range [0 10 ] :when (odd? i )] (math/pow 2 i ))
# => @[2 8 32 128 512]
# array with 2 to the power of all odd numbers smaller than 10
(let [tbl @{:a 1 }]
(merge-into tbl {:b 2 })
tbl )
# => @{:a 1 :b 2}
# real-world example: https://git.sr.ht/~subsetpark/bagatto/tree/19aea03fe23fe5486890912df7dc4a936ce617a3/item/main.janet#L23
# Walk from the API is defined using a case
(defn walk
`Iterate over the values in ast and apply f
to them. Collect the results in a data structure. If ast is not a
table, struct, array, or tuple,
returns form.`
[f form ]
(case (type form )
:table (walk-dict f form )
:struct (table/to-struct (walk-dict f form ))
:array (walk-ind f form )
:tuple (let [x (walk-ind f form )]
(if (= :parens (tuple/type form ))
(tuple/slice x )
(tuple/brackets ;x )))
form ))(peg/find-all ~(capture :d )
"hi 0 bye 1" )
# => @[3 9] (def ast '(print novar ))
(def es (compile ast ))
# => @{:column 11 :line 12 :error "unknown symbol novar"} returns struct with error on invalid ast (def a @[1 2 3 ])
(def b (array/slice a ))
#=> good way to clone array, a and b are different arrays (map |(+ $0 $1 ) [1 2 3 ] [4 5 6 ]) # @[5 7 9] - uses the fn shorthand (string/repeat "moshi" 2 ) # => "moshimoshi" (def chan (ev/chan ))
(def f (ev/go (coro (ev/give-supervisor :msg "Hello" )) nil chan ))
(pp (ev/take chan )) # => (:msg "Hello")