Welcome, I'm happy to see you here! Feel free to pick a function and add a happy example, the more the merrier!
(math/abs -42 ) # => 42
(map math/abs [-1 0 1 ]) # => @[1 0 1] (bxor 3 6 ) # => 5
# 011 (3)
# xor 110 (6)
# -------
# 101 (5)
(def a @[1 6 ]) # => @[1 6]
(array/insert a 1 (splice [2 3 ])) # => @[1 2 3 6]
(array/insert a 3 ;[4 5 ]) # => @[1 2 3 4 5 6]
(math/log (* math/e math/e )) # => 2
(math/log2 256 ) # => 8
(math/log10 1000 ) # => 3
(array/slice @[1 2 3 ] 0 0 ) # => @[]
(array/slice @[1 2 3 ] 0 1 ) # => @[1]
(array/slice @[1 2 3 ] 0 2 ) # => @[1 2]
(array/slice @[1 2 3 ] 0 3 ) # => @[1 2 3]
(array/slice @[1 2 3 ] 0 4 ) # error: index out of range
(array/slice @[1 2 3 ] 1 1 ) # => @[]
(array/slice @[1 2 3 ] 1 2 ) # => @[2]
(array/slice @[1 2 3 ] 0 -1 ) # => @[1 2 3]
(array/slice @[1 2 3 ] 0 -2 ) # => @[1 2]
(array/slice @[1 2 3 ] 0 -3 ) # => @[1]
(array/slice @[1 2 3 ] 0 -4 ) # => @[]
(array/slice @[1 2 3 ] 0 -5 ) # error: index out of range
(def s (symbol/slice :hello 2 4 ))
(print (type s )) # symbol
(print s ) # ll
# many terminals will truncate long data, use this if you need to see/copypaste it:
(defn full-print `Print a large DS without truncation` [ds ] (print (string/format "%m" ds )))(string/trim " foo " ) # => "foo"
(string/trim "_!_foo_!_" "_!" ) # => "foo" (defn spit-lines [path lines ]
(spit path (string/join lines "\n" )))(from-pairs [[:hello "world" ] [:foo "bar" ]])
# => @{:foo "bar" :hello "world"} trampoline should work at some callback method which will match these code. most provide callback should be like these!
```c
// liba.so
void call_mul_at_callback(int i, void (*on_complete) (void*,void*), void* user_data) {
// user_data = ctx
// work_code
int v = i * i + i* i * i << 12 - 5 *i;
printf("from janet ffi\n");
on_complete(&i, user_data);
printf("FFI CALLBACK COMPLETE\n");
}
```
```janet
(ffi/context "liba.so")
(ffi/defbind call-mul-at-callback :void (i :int callback :ptr data :ptr))
(def cb (delay (ffi/trampoline :default)))
(call-mul-at-callback 15
(cb)
(fn[ptr]
(let [args (ffi/read (ffi/struct :int) ptr)]
(print (string/format "got value %d from ffi"
(first args))))))
``` (min 1 2 3 ) # => 1
(min (splice [1 2 3 ])) # => 1
(min ;[1 2 3 ]) # => 1
(apply min [1 2 3 ]) # => 1 # Get a new and different random number each time you run your program.
(math/seedrandom (os/cryptorand 8 ))
(math/random )(math/exp 1 ) # => 2.71828
math/e # => 2.71828 (flatten [1 [2 3 [4 ]] 5 ]) # => @[1 2 3 4 5]