list
map
number
string
set
syntax
macro
native
Lisp
CirruText
Cirru
All/WIP
Found 212 entries.
#{}
hashset. it' based on Nim's hashset, might be slower
(#{} 1 2 3 4)
&
argument spread operator, used in function creating or calling
(defn f (x0 & xs) (echo xs))
(f x0 & xs)
&*
native add function which multiples 2 numbers
(&* 2 3)
&+
native add function which adds 2 numbers
(&+ 1 2)
&-
native add function which substracts one number from another
(&+ 2 1)
&/
native add function which divide one number by another
(&/ 10 2)
&<
native < function for 2 numbers
(&< 2 3)
&<=
native implemention of <=, of 2 arguments
(<= 1 2)
&=
native = function for 2 numbers
(&= 2 (+ 1 1))
&>
native > function for 2 numbers
(&> 3 2)
&>=
native implemention of >=, of 2 arguments
(>= 2 1)
&E
get value of e, natural log
(echo &E)
&PI
get value of PI, the ratio of a circle's circumference to its diameter
(echo &PI)
&and
native and function for 2 booleans
(&and true true)
&case
internal helper for case
&concat
native list concatenation of 2 lists
(&concat ([] 1 2) ([] 3 4))
&difference
difference of two hashsets
(&difference (#{} 1 2 3 4) (#{} 1 2))
&exclude
exclude an item out of a hashset
(&exclude (#{} 1 2 3 4) 4)
&include
include an item into a hashset
(&include (#{} 1 2 3) 4)
&intersection
intersection of two hashsets
(&intersection (#{} 1 2) (#{} 2 3))
&let
internal operator for let, which only binds 1 variable per expression
(&let (a 1) (+ a 1))
&max
native implemention of max, takes 2 arguments
(&max 1 2)
&min
native implemention of min, takes 2 arguments
(&min 1 2)
&newline
just
(echo &newline)
&or
native or function for 2 booleans
(&or false true)
&reset-gensym-index!
debugging function for gensym
&str
turn a single item into string
(&str 1)
(= |keyword (&str :keyword))
&str-concat
concat 2 strings
(&str-concat |a |b)
&tab
just
(echo &tab)
&union
union of two hashsets
(&union (#{} 1 2) (#{} 3 4))
&{}
internal function for {}, creating with arrays
(&{} ([] :a 1) ([] :b 2))
=>
({} (:a 1) (:b 2))
*
multiply numbers
(* 1 2 3)
+
add multiple numbers
(+ 1 2)
(+ 1 2 3)
-
substract numbers from a number
(- 2 1)
(- 10 1 2 3)
->
thread macro for nested functions, argument at head
(-> a (b) (c d))
->>
thread macro for nested functions, argument at tail
(->> a (b) (c d))
/
division of multiple numbers
(/ 12 3 4)
/=
compare 2 numbers
(/= 1 2)
;
adds comments
(; "this will not be evaludated" "more comments")
<
compare multiple numbers
(< 1 2 3 4)
<=
compare multiple numbers
(<= 2 3 4)
=
compare multiple numbers
(= 1 (- 2 1) (- 4 3))
>
compare multiple numbers
(> 4 3 2 1)
>=
compare multiple numbers
(>= 4 3 2)
[,]
macro for creating lists, , children are removed
([,] 1 , 2 , 3)
[]
operator for creating lists, internally it's ternary tree list
([] 1 2 3 4 (+ 1 2))
[][]
defining 2-dimensional list with fewer []s
([][] (2 3) (4 5) (6 7))
=>
([] ([] 2 3) ([] 4 5) ([] 6 7))
This is a macro
\
alias for an anounymous function, use % and %2 for arguments
(map (\ + x 1) (range 10))
(map-indexed (\ [] % %2) (range 10))
add-watch
add a watch function to an atom by keyword
(add-watch *a :log (\ echo |changed %))
and
varadic and operator, false for empty arguments
(either nil 1)
=>
(do 1)
(and)
=>
(do false)
(and true true false)
=>
(do false)
(and true false true)
=>
(do false)
(and true true true)
=>
(do true)
any?
detects if any item in list satisfies function
(any? (fn (x) (> x 1)) ([] 1 2 3 4))
append
returns new list, with new item at tail
(append ([] 1 2 3) 4)
apply
apply a list of arguments to a function
(apply f ([] 1 2 3 4))
assert
like Clojure assert, but string is placed first
(assert "|x > 0" (> x 0))
assert=
debugging macro for comparing a value
(assert= 2 (+ x 1))
assoc
returns a list with new item or key/value associated
(assoc ([] 1 2 3) 1 :a)
(assoc ({} (:a 1) (:b 2)) :c 10)
assoc-after
returns a list with new item associated after specified index
(assoc-after ([] 1 2 3) 1 10)
assoc-before
returns a list with new item associated before specified index
(assoc-before ([] 1 2 3) 1 10)
assoc-in
assoc a field deep inside
(assoc-in data ([] :a :b :c) 10)
(assoc-in data ([] :a 1 2) 10)
(assoc-in nil ([] :a :b) 10)
=>
({} (:a ({} (:b 10))))
assoc data even when operand is nil
bool?
detects a bool
(bool? true)
butlast
slice list without last item, return empty list if nil
(butlast ([] 1 2 3 4))
case
like Clojure case, but using value itself for else case
(case a (:a |a) (:b |b) (a |else))
(macroexpand-all (quote (case (+ 1 2) (1 |one) (2 |two) (3 |three))))
=>
(quote (&let (v__1 (+ 1 2)) (if (&= v__1 1) |one (if (&= v__1 2) |two (if (&= v__1 3) |three nil)))))
ceil
ceil of a float
(ceil 1.1)
concat
concat mutiple lists
(concat ([] 1 2) ([] 3 4) ([] 5 6))
cond
like Clojure cond, but using true for else case
(cond ((> a 10) |>10) ((> a 1) |>1) (true |false))
contains-symbol?
a function for detecting symbol existence in code
(contains-symbol? (quote (+ a b)) 'a)
contains?
check if key is contained in map, should work for sets as well
(contains? ({} (:a 1) (:b 2)) :a)
(contains? |abc |b)
cos
cos of a number
(cos 0.1)
count
just count
(count ([]))
(count ({}))
(count (|abc))
def
def is a macro, just discard the name return the value
(def x 1)
=>
(do 1)
name is totally useless in runtime
(macroexpand (quote (def a b)))
=>
(quote (b))
defatom
creating an atom of states. it requires a name, and currently not atomic, just states
(defatom *a 1)
defmacro
defines macros
(defmacro m1 (a b) (quote-replace (+ (~ a) (~ b))))
defn
create functions on namespaces
(defn (a b) (+ a b))
(defn (a (xs)) echo a xs)
deref
grab data from atom
(deref *a)
difference
return a difference hashset of 2 hashsets
(difference (#{} 1 2 3 4) (#{} 1 2) (#{} 3))
dissoc
returns a list with a key dissociated
(dissoc ({} (:a 1) (:b 2)) :a)
dissoc-in
dissociate data deep in a structure
(dissoc-in data ([] :a 1))
dissoc-in
dissoc a field deep inside
(dissoc-in data ([] :a :b :c))
(dissoc-in data ([] :a 1 2))
do
add multiple numbers
(do (echo 1) (echo 2))
draw-canvas
draw with json-paint shapes
(draw-canvas ({} (:type :polyline) (:from ([] 40 40)) (:stops ([] ([] 100 60) ([] 200 200) ([] 600 60) ([] 500 400))) (:stroke-color ({} (:r 90) (:g 10) (:b 10)))))
drop
take items of a list except for first n items
(drop 2 ([] 1 2 3 4 5))
dual-balanced-ternary
create a dual balanced ternary value from 2 numbers
(dual-balanced-ternary 1.1 1.1)
each
take a list and a function and call each item with function
(each ([] 1 2 3 4) (fn (x) (echo x)))
echo
alias for println
(echo 1 2 3)
either
if x is nil, then return y, else y is never evaludated. or only takes booleans.
(either nil 1)
=>
(do 1)
(either 2 1)
=>
(do 2)
empty?
detects empty list or map, returns true for nil
(empty? nil)
(empty? ([]))
(empty? ({}))
ends-with?
detects if string ends with item
(ends-with? |abc |c)
escape
string escaping
(escape "|a b")
every?
detects if every item in list satisfies function
(every? (fn (x) (> x 1)) ([] 1 2 3 4))
exclude
exclude multiple items from hashset
(exclude (#{} 1 2 3 4) 1 2)
filter
filter a list with a function
(filter (fn (x) (> n 5)) (range 10))
filter-not
filter a list with a function with false return
(filter-not (fn (x) (> n 5)) (range 10))
find
find first item from list that matches the function
(find ([] 1 2 3 4) (fn (x) (> x 2)))
find-index
find index of first item that matches the function, returns -1 when not found
(find-index ([] 1 2 3 4) (fn (x) (> x 2)))
first
return first item of list
(first ([] 1 2 3 4))
floor
floor of a float
(floor 1.1)
fn
create anounymous functions
(fn (a b) (+ a b))
(macroexpand (quote (fn (a (xs)) (echo a xs))))
=>
(quote (defn generated-fn (a (xs)) (echo a xs)))
expands to function
fn?
detects a function or a proc
(fn? (fn () 1))
(fn? &=)
foldl
Haskell's foldl function, implemented i Nim for performance
(foldl + acc 0)
foldl-compare
internal function for generation comparing functions
(foldl-compare &< ([] 2 3 4) 1)
format-number
format a float with specified precision
(format-number 1.2345 2)
=>
(do 1.23)
format-ternary-tree
disply string form of internal ternary tree structure
(format-ternary-tree ([] 1 2 3 4 5 6))
(format-ternary-tree ({} (:a 1) (:b 2) (:c 3)))
format-time
format time with syntax defined in Nim times module
(format-time 1602295800 "|yyyy-MM-dd HH:mm")
=>
(do "|2020-10-10 10:10")
template syntax of Nim `times` module
frequencies
count frequencies of items in list, returns a map
(frequencies ([] 1 1 1 2 2 3))
=>
({} (3 1) (2 2) (1 3))
generate-id!
id generator, currently using nanoid
(generate-id!)
(generate-id! 10)
(generate-id! 10 abcd)
gensym
gensym, generates an unique symbol like Clojure
(gensym)
=>
(G__101)
(gensym |a)
=>
(a__102)
(gensym 'b)
=>
(b__103)
get
like Clojure get
(get ([] 1 2 3) 1)
(get ({} (:a 1) (:b 2)) :a)
get-env
read from environment variable
(get-env |HOME)
get-in
like Clojure get-in function, read property recursively
(get-in data ([] :a 1))
group-by
take a list, return grouped result with a map
(group-by (fn (x) (mod x 3)) (range 10))
has-index?
detects if a list has item on a index
(has-index? (range 10) 4)
identical?
detects if items share the same pointer, mainly for lists and maps
(identical? a b)
identity
takes an item and just return it
(map identity (range 10))
if
if syntax, when ELSE branch is omitted, it will be nil
(if (> a 1) |true |false)
(if (> a 1) |just-true)
inc
add 1 to a number
(inc 10)
include
include multiple items to hashset
(include (#{} 1 2) 3 4)
index-of
native implemention of indexOf function, returns -1 when not found
(index-of ([] 1 2 3 4) 1)
init-canvas
load window of Cairo, see json-paint
(init-canvas ({} (:title "\"DEMO") (:width 800) (:height 600)))
interleave
interleave of two lists, like Clojure
(interleave ([] :a :b :c) ([] 1 2 3 4))
=>
([] :a 1 :b 2 :c 3)
intersection
return a intersection hasset of multiple hashsets
(intersection (#{} 1 2 3) (#{} 2 3 4) (#{} 3 4 5))
join
join list of items with a separator
(join 10 ([] 1 2 3 4))
=>
([] 1 10 2 10 3 10 4)
join-str
join segments into a string
(join-str |- ([] 1 2 3 4))
=>
(do |1-2-3-4)
keys
returns a list of keys of a map
(keys ({} (:a 1) (:b 2)))
keyword?
detects a keyword
(keyword? :key)
last
return last item of list
(last ([] 1 2 3 4))
let
local variable bindings, using Clojure syntax
(let ((a 1) (b (+ a 1))) (+ a b))
let->
syntax sugar on top of &let for reducing nesting
(let-> (let a 1) (let b 2) (+ a b))
list?
detects a list
(list? ([] 1 2 3 4))
loop
like Clojure loop, use tail recursion to loop inside expressions
(loop ((idx 0) (acc ([]))) (if (< idx 10) (recur (+ idx 1) (append acc idx)) acc))
(loop () (echo "|never ends") (recur))
(macroexpand (quote (loop ((acc 0) (x 0)) (if (> x 10) acc (recur (+ acc x) (inc x))))))
=>
(apply (defn generated-loop (acc x) (if (> x 10) acc (recur (+ acc x) (inc x)))) (&[] 0 0))
macro?
detects a macro
(fn? cond)
macroexpand
expand quoted code for debugging purpose, notice that quote is required
(macroexpand (quote (when true 1 2 3)))
=>
(quote (if true (do 1 2 3)))
macroexpand-all
expand quoted code recursively, notice that quote is required
(macroexpand-all (quote (when true 1 2 3)))
=>
(quote (if true (do 1 2 3)))
(macroexpand-all (quote (case (+ 1 2) (1 |one) (2 |two) (3 |three))))
=>
(quote (&let (v__1 (+ 1 2)) (if (&= v__1 1) |one (if (&= v__1 2) |two (if (&= v__1 3) |three nil)))))
map
map items of list into a new list
(map ([] 1 2 3 4) (fn (x) (+ x 1)))
map-indexed
map with index parameter
(map-indexed (fn (idx x) idx) (range 10))
map-kv
map key and value for a map
(map-kv (fn (k v) ([] k (+ v 1))) ({} (:a 1) (:b 2)))
=>
([][] (:a 2) (:b 3))
map?
detects a map
(map? ({} (:a 1) (:b 2)))
mapcat
map item to list and then concat, or just flatmap
(mapcat (fn (x) ([] x (+ x 10))) ([] 1 2 3 4))
max
max function that takes a list of arguments
(max ([] 1 2 3 4))
merge
merge multiple lists
(merge ({} (:a 1)) ({} (:b 2)))
min
max function that takes a list of arguments
(min ([] 1 2 3 4))
mod
function for get a reminder value
(mod 5 3)
=>
(do 2)
nil?
detects a nil
(nil? nil)
not
just not
(not true)
now!
get current time, stored as a float
number?
detects a number
(number? 1)
or
varadic or operator, false for empty arguments
()
(or)
=>
(do false)
(or false false false)
=>
(do false)
(or false true false)
=>
(do true)
(or false false true)
=>
(do true)
pairs-map
create a map from a list of pairs
(pairs-map ([] ([] :a 1) ([] :b 2)))
=>
({} (:a 1) (:b 2))
parse-cirru-edn
parse data from Cirru EDN format
(parse-cirru-edn "{} (:a 1)")
parse-float
get float number from string
(parse-float |1.1)
parse-json
parse JSON string into Cirru data, notice that ":a" will be parsed as keyword
(parse-json "|{\"a\": [1, 2]}")
parse-time
currently time is represented in float in calcit runner
(parse-time |2020-10-10)
=>
(do 1602259200)
default parsing template is yyyy-MM-dd
(parse-time "|2020-10-10 10:10" "|yyyy-MM-dd HH:mm")
=>
(do 1602295800)
template syntax of Nim `times` module
pow
power of a number
(pow 2 2)
pr-str
return string value with more details, string being escaped
(pr-str "|demo with space")
=>
(do "\"|demo with space\"")
(pr-str 1 2 3 4)
=>
(do "|1 2 3 4")
prepend
returns new list, with new item at first
(prepend ([] 1 2 3) 0)
print
write string values to stdout
(print 1 2 3)
println
displays values with newline at end
(println 1 2 3)
quit
call Nim's quit function
(quit 1)
quote
return quoted data, mainly lists that are not evaludated
(quote ([] + 1 2 3))
quote-replace
used in defmacro, togather with ~ for replacing in quoted data
(quote-replace (+ 1 2 3 (~ a)))
=>
(quote (+ 1 2 3 a))
raise
raise exception with a message
(raise "|xs has error")
rand
generates a random float number in a area, defaults to 100 when not specified
(rand)
(rand 10)
(rand -10 10)
rand-int
generates a random round number in a area, defaults to 100 when not specified
(rand-int)
(rand-int 10)
(rand-int -10 10)
rand-nth
takes a random item from a list, returns nil for empty list
(rand-nth)
(rand-nth 10)
(rand-nth -10 10)
range
return a list of ranged numbers
(range 10)
(range 1 10)
(range 1 10 2)
read-file
read string from a relative file path
(read-file |demo.md)
recur
operator for tail recursion, can be used in a function or a loop
(defn f (acc n) (if (< n 10) (recur (+ acc n) (+ n 1)) acc))
remove-watch
remove a watch function from an atom by keyword
(remove-watch *a :log)
repeat
repeat an item n times
(repeat 5 :a)
=>
([] :a :a :a :a :a)
replace
replace segments in a string
(replace "|looks good" |good |bad)
reset!
update data from atom
(reset! *a 2)
rest
slice list without first item, return empty list if nil
(rest ([] 1 2 3 4))
reverse
return a list with order reversed
(reverse ([] 1 2 3 4))
round
round a float number, also works for a ternary value
(round 1.1)
(round &1.1)
section-by
turn list into a list of lists of n sizes, remaining items also in a list
(section-by 3 (range 5))
=>
([] ([] 0 1 2) ([] 3 4))
set-trace-fn!
set a ns/def for debug tracing, arguments and results will be printed. unstable
(set-trace-fn! |app.main |f1)
sin
sin of a number
(sin 0.1)
slice
return a slice of list, item at last index is not included
(slice ([] 1 2 3 4) 1 2)
some?
detects something not nil
(some? 1)
sort
sort list with given comparator function
(sort (fn (x y) (&- x y)) ([] 1 3 4 2))
=>
([] 1 2 3 4)
value returned from comparator function should be a number
split
split string into a list of segments
(split |1,2,3,4 |,)
split-lines
split lines(currently with \n)
(split-lines "|a\nb\nc")
sqrt
square root of number
(sqrt 9)
starts-with?
detects if string starts with item
(starts-with? |abc |a)
str
string concatenation
(str |a 1 :k)
str-find
find index of item in a string
(str-find |abcd |a)
string?
detects a string
(string? |demo)
stringify-json
stringify Cirru data into JSON string
(stringify-json ({} (:a ([] 1 2))))
(stringify-json ({} (:a ([] 1 2))) true)
substr
get sub string by indexes
(substr |abcd 1)
(substr |abcd 1 3)
swap!
update data from atom with a function, syntax from Clojure
(swap! *a inc)
symbol?
detects a symbol
(symbol? 'a)
take
take n items from list
(take 2 ([] 1 2 3 4 5))
ternary->point
return a list of 2 numbers from a dual balanced ternary value
(ternary->point &4)
=>
([] 1 -1)
to-pairs
returns pairs of a map as a list of lists
(to-pairs ({} (:a 1) (:b 2)))
=>
([] ([] :a 1) ([] :b 2))
trim
trim spaces or characters from string
(trim "| a ")
(trim |__a__ |_)
turn-keyword
turn something into a keyword
(turn-keyword |k)
(turn-keyword 'k)
turn-str
turn something into a string
(turn-str :key)
(turn-str 'key)
(turn-str 1)
turn-symbol
turn something into a symbol
(turn-symbol |a)
(turn-symbol :a)
type-of
gets type of a value, returns in a keyword
(type-of a)
union
return a union hashset of 2 hashsets
(union (#{} 1 2) (#{} 3 4) (#{} 5 6))
unless
if-not syntax
(unless false |false |true)
(unless false |false)
update
update map or list
(update ({} (:a 1)) :a (\ + % 1))
(update (range 4) 1 (\ + % 1))
update-in
update data deep in a structure
(update-in data ([] :a 1) (fn (x) (x + 1)))
update-in
update a field deep inside
(update-in data ([] :a :b :c))
(update-in data ([] :a 1 2))
vals
returns a list of values of a map
(vals ({} (:a 1) (:b 2)))
when
if with no false branch
(when true (echo 1) (echo 2))
(macroexpand (quote (when true 1 2 3)))
=>
(quote (if true (do 1 2 3)))
with-log
for debug purpose, add log to an expression
(macroexpand (quote (with-log (+ 1 2))))
=>
(&let (v__1 (+ 1 2)) (echo (quote (+ 1 2)) |=> v__1) v__1)
write-file
write string content to a relative file path
(write-file |demo.md "|some content")
zipmap
create a map with two lists, one for keys and one for values
(zipmap ([] :a :b :c :d) ([] 1 2 3 4))
=>
({} (:a 1) (:b 2) (:c 3) (:d 4))
{,}
quicker way for creating literal maps, seperated with comma
(macroexpand (quote ({,} :a 1 , :b 2 , :c 3)))
=>
(pairs-map (section-by 2 ([] :a 1 :b 2 :c 3)))
commas are just removed after macro expansion
({,} :a 1 , :b 2 , :c 3)
=>
({} (:a 1) (:b 2) (:c 3))
{}
operator for creating maps based on &{}, internally it's ternary tree map
({} (:a 1) (:b (+ 2 3)))
(macroexpand (quote ({} (:a 1) (:b (+ 2 3)))))
=>
(quote (&{} ([] :a 1) ([] :b (+ 2 3))))
expands to &{}, which creates a map
~
replaces variables in quoted data
(quote-replace (+ 1 2 (~ a)))
=>
(quote (+ 1 2 a))
~@
like ~ but turns a list into multiple symbols beforing inserting
(quote-replace (+ 1 2 (~@ xs)))
(quote-replace (+ 1 2 (~@ (quote ([] a b)))))
=>
(quote (+ 1 2 a b))