Welcome, I'm happy to see you here! Feel free to pick a function and add a happy example, the more the merrier!
(map math/abs [-2.9 -2.1 2.1 2.9 ]) # => @[ 2.9 2.1 2.1 2.9 ]
(map math/floor [-2.9 -2.1 2.1 2.9 ]) # => @[ -3 -3 2 2 ]
(map math/ceil [-2.9 -2.1 2.1 2.9 ]) # => @[ -2 -2 3 3 ]
(map math/round [-2.9 -2.1 2.1 2.9 ]) # => @[ -3 -2 2 3 ]
(map math/trunc [-2.9 -2.1 2.1 2.9 ]) # => @[ -2 -2 2 2 ]
(buffer/bit @"0" 4 )
# => true
(var a 1 )
a # => 1
(inc a ) # => 2
a # => 1
(++ a ) # => 2
a # => 2
# create a channel without buffer, default is 0
(def channel (ev/chan ))
(ev/spawn
(ev/sleep 5 )
(ev/give channel "Hard work is done!" ))
(print "do anything" )
(for i 0 5
(print i )
(ev/sleep 0.5 ))
(print (ev/take channel )) # blocks here, until there is a result in the channel
(print "done" )
(* 2 3 ) # -> 6
(* 2 3.3 ) # -> 6.6
(* 2.2 3.3 ) # -> 7.26
(def pi 3.14159 )
(* 2 pi ) # -> 6.28318
(* 2 ) # -> 2
(* ) # -> 1
(* 2 3 4 ) # -> 24
(apply * [2 3 4 ]) # -> 24
(* (splice [2 3 4 ])) # -> 24
(* ;[2 3 4 ]) # -> 24
(def a [2 3 4 ])
(* ;a ) # -> 24
(string/has-prefix? "project." "project.janet" ) # => true (map truthy? [ nil false true 0 1 'a :a "a" [] {} (fn []) ])
# => @[ false false true true true true true true true true true ]
# note that 'not' works as an implementation of 'falsey?'
(map not [ nil false true 0 1 'a :a "a" [] {} (fn []) ])
# => @[ true true false false false false false false false false false ]
(os/shell "seq 12 | head -n 1" ) # => 1 (partition-by even? [1 1 2 3 5 8 13 21 ])
# => @[@[1 1] @[2] @[3 5] @[8] @[13 21]]
(type (fiber/new (fn [])))
# =>
:fiber (-> "X"
(string "a" "b" )
(string "c" "d" )
(string "e" "f" )) # => "Xabcdef" # Contrived examples returning the variadic arguments passed in.
(defn example-function [& args ] args )
(defmacro example-macro [& args ] ~(tuple ,;args ))
(macex '(example-macro 1 2 3 ))
(assert (= (example-function 1 2 3 )
(example-macro 1 2 3 )))
(def args [1 2 3 ])
# `apply` is for functions, but there's always `eval`.
(assert (= (apply example-function args )
(eval ~(example-macro ,;args ))))
# Same return for both.
# => (1 2 3)
(peg/replace-all '(set "aiou" ) "e" "The quick brown fox jumps over the lazy dog" )
# returns The qeeck brewn fex jemps ever the lezy deg (def p (os/spawn ["ls" ] :p {:in :pipe :out :pipe })) # define core/process with selfpipe
(pp (:read (p :out ) :all )) # => prints the ls output
(pp (:wait p )) # => waits for the process to finish, prints 0 if succesful (take-while number? @[1 2 3 "4" 5 6 7 8 9 "10" 11 "12" ]) # => (1 2 3)