Welcome, I'm happy to see you here! Feel free to pick a function and add a happy example, the more the merrier!
(buffer ;(interpose " " [:ant 'bee "cat" ``dog`` @`ewe` ]))
# => @"ant bee cat dog ewe" (= math/-inf (- math/-inf 1 ))
# =>
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 ]
(map truthy? [ nil false true 0 1 'a :a "a" [] {} (fn []) ])
# => @[ false false true true true true true true true true true ]
(doc-of file/read ) # => file/read docs are shown
(def tmpfile (file/temp ))
(doc-of (tmpfile :read )) # => also shows the file/read docs.
# Note that we didn't have to use the file/read symbol here to get docs. (buffer "dude, " "where's " "my " "car?" ) # => @"dude, where's my car?" (map bytes? [ 'ab :ab "ab" @"ab" [97 98 ] @[97 98 ] {0 97 1 98 } @{0 97 1 98 } ])
# => @[ true true true true false false false false ]
(map symbol? [ 'ab :ab "ab" @"ab" [97 98 ] @[97 98 ] {0 97 1 98 } @{0 97 1 98 } ])
# => @[ true false false false false false false false ]
(map keyword? [ 'ab :ab "ab" @"ab" [97 98 ] @[97 98 ] {0 97 1 98 } @{0 97 1 98 } ])
# => @[ false true false false false false false false ]
(map string? [ 'ab :ab "ab" @"ab" [97 98 ] @[97 98 ] {0 97 1 98 } @{0 97 1 98 } ])
# => @[ false false true false false false false false ]
(map buffer? [ 'ab :ab "ab" @"ab" [97 98 ] @[97 98 ] {0 97 1 98 } @{0 97 1 98 } ])
# => @[ false false false true false false false false ] # use (dyn :args) to get the value of dynamic binding *args*
(let [args (dyn :args )]
(if (= "-h" (get args 1 ))
(print "Usage: janet args.janet [-h] ARGS.." )
(printf "command line arguments:\n %q" args )))
# Find all bindings (in the current environment) with "push" in the name.
(doc "push" )
# Bindings:
#
# array/push buffer/push buffer/push-byte buffer/push-string
# buffer/push-word
#
# Dynamics:
#
#
#
# Use (doc sym) for more information on a binding. (os/dir "." ) # => @["foo" "bar"]
(os/rename "bar" "bar2" ) # => nil
(os/dir "." ) # => @["bar2" "foo"]
(reduce string "ha" ["ha" "ha" "ha" "ha" ]) # => "hahahahaha"
(accumulate string "ha" ["ha" "ha" "ha" "ha" ]) # => @["haha" "hahaha" "hahahaha" "hahahahaha"] # There is a list of formatters here: https://janet-lang.org/capi/writing-c-functions.html
(string/format "With terminal colors: %M" [:array {:key-in "struct" }]) # => "With terminal colors: (\e[33m:array\e[0m {\e[33m:key-in\e[0m \e[35m\"struct\"\e[0m})"
(defn greet-me [] (print "hey programmer!" ))
(defn greet-stranger [] (print "hey stranger!" ))
(varfn greet [] (greet-me ))
(greet ) # prints "hey programmer!"
(varfn greet [] (greet-stranger ))
(greet ) # prints "hey stranger!"
# kind of analogous to (def greet (fn [] (some-thunk))), but with built-in
# sugar to automatically update 'greet' if varfn is called with a name
# already bound
(int/u64 "18446744073709551615" )
# => <core/u64 18446744073709551615> (string/bytes "foo" ) # => (102 111 111)
(string/from-bytes 102 111 111 ) # => "foo"
(string/from-bytes (splice (string/bytes "foo" ))) # => "foo"
(map (fn [x ] x ) "foo" ) # => @[102 111 111]
(map string/from-bytes "foo" ) # => @["f" "o" "o"]
(defn string/explode [s ] (map string/from-bytes s ))
(string/explode "foo" ) # => @["f" "o" "o"]
(frequencies ["a" "a" "b" "c" "d" "d" ])
# => @{"c" 1 "d" 2 "a" 2 "b" 1}
(frequencies {:a "Bob"
:b "Joe"
:c "Mat"
:d "Bob" })
# => @{"Bob" 2 "Joe" 1 "Mat" 1}
(frequencies "Hallo World" )
# => @{108 3 114 1 100 1 87 1 97 1 32 1 111 2 72 1}