JanetDocsSourcePlaygroundTutorialsI'm Feeling luckyCommunityGitHub sign in

Community documentation for Janet

Supported Modules

Welcome, I'm happy to see you here! Feel free to pick a function and add a happy example, the more the merrier!

Loading...

Random Examples

(map |(+ $0 $1) [1 2 3] [4 5 6]) # @[5 7 9] - uses the fn shorthand
mapahungryPlayground
(->> 
  (string/split " " "this  is an  example yes, an example")
  (filter (complement empty?))
  (frequencies))
# -> @{"is" 1 "example" 2 "yes," 1 "an" 2 "this" 1}

# same as:
(frequencies
  (filter
    (complement empty?)
    (string/split " " "this  is an  example yes, an example")))
->>felixrPlayground
(chr "a")  # => 97
chrcellularmitosisPlayground
# repeat is about _side-effects_, since it returns nil.
# You'll need to use a mutable collection if you want to
# use repeat to add repeated items to a collection:
(var coll @["Y" "Z"]) #=> @["Y" "Z"]
(repeat 3 (array/push coll "A")) #=> nil
coll
# Returns:
@["Y" "Z" "A" "A" "A"]

# You can use map if the whole collection consists
# of these repetitions:
(map (fn [_] "A") (range 3))
# Returns:
@["A" "A" "A"]
repeatsemperosPlayground
(map boolean? [true false nil   0     1    ])
# =>         @[true true  false false false]
boolean?cellularmitosisPlayground
(get (os/environ) "HOME")  # => "/Users/cell"
(os/getenv "HOME")  # => "/Users/cell"
os/environcellularmitosisPlayground
(print "The build hash of your Janet executable is " janet/build ".")
janet/buildoofoePlayground
(let [a 1]
 (let [b a]
  b)) # => 1
letjgartePlayground
(->> ["small" "cuddly" "creature"]
     (interpose "-")
     splice
     keyword)
# => :small-cuddly-creature
keywordsogaiuPlayground
(string "hello" nil true 42 :bar)  # => "helloniltrue42bar"
(string :a :b :c)  # => "abc"
stringcellularmitosisPlayground
(zipcoll [:a :b :c] [1 2 3])  #=> @{:c 3 :a 1 :b 2}
zipcolluvtcPlayground
(get default-peg-grammar :h)
# => '(range "09" "af" "AF")
default-peg-grammarsogaiuPlayground
(get-in  [[4 5] [6 7]]  [0]    42)  # => (4 5)
(get-in  [[4 5] [6 7]]  [0 1]  42)  # => 5

(get-in  [[4 5] [6 7]]  [-1]     42)  # => 42
(get-in  [[4 5] [6 7]]  [9 9 9]  42)  # => 42
get-incellularmitosisPlayground
(map string/from-bytes "Hello, world!")  # => @["H" "e" "l" "l" "o" "," " " "w" "o" "r" "l" "d" "!"]
mapGrayJackPlayground
[1 2 3]                  # => (1 2 3)
(tuple 1 2 3)            # => (1 2 3)
(tuple (splice [1 2 3])  # => (1 2 3)
(tuple ;[1 2 3])         # => (1 2 3)
tuplecellularmitosisPlayground