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

(var x 1)
(loop [n :range-to [1 5]]
  (*= x n))
x # => 120
*=quexxonPlayground
(map tuple ["a" "b" "c" "d"] [1 2 3 4] "abcd")

# => @[("a" 1 97) ("b" 2 98) ("c" 3 99) ("d" 4 100)]
mapfelixrPlayground
# in struct 
(index-of 2 {:a 1 :b 2 :c 3 :d 2} )
# => :b

# in table 
(index-of 2 @{:a 1 :b 2 :c 3 :d 2})
# => :b

# in array 
(index-of 6 @[4 5 6 7 8 9] )
# => 2

# in tuple 
(index-of 2 [1 2 3 4])
# => 1
index-ofleobmPlayground
(get @"A"                      0)  # => 65 (0b01000001)
(get (buffer/bit-clear @"A" 0) 0)  # => 64 (0b01000000)
(get (buffer/bit-clear @"A" 6) 0)  # =>  1 (0b00000001)
buffer/bit-clearcellularmitosisPlayground
(last :hello)
# => 111
lastsogaiuPlayground
(in "yo" 0)
# => 121
insogaiuPlayground
(string/join @["1" "2" "3"]) # => "123"
# The esp argument is optional, and defaults to empty string
string/joinyumaikasPlayground
(def person-ids {"Alice" 42 "Bob" 23})

(keep person-ids ["Carl" "Bob" "Alice"])   # -> @[23 42]

(filter person-ids ["Carl" "Bob" "Alice"]) # -> @["Bob" "Alice"]
(map person-ids ["Carl" "Bob" "Alice"])    # -> @[nil 23 42]
keepfelixrPlayground
# janet 1.10.1

# note that os/cd does not appear to update PWD in the shell's environment.
(os/cwd)           # => "/Users/cell/tmp"
(os/getenv "PWD")  # => "/Users/cell/tmp"
(os/cd "/tmp")     # => nil
(os/cwd)           # => "/private/tmp"  (on Apple, /tmp is actually /private/tmp)
(os/getenv "PWD")  # => "/Users/cell/tmp"
os/cdcellularmitosisPlayground
(assert :dude :what?) # => :dude

(assert :dude :dude) # => :dude

(assert (= :dude :what?) "Where's my car?")
# => error: Where's my car?
# =>  in _thunk [repl] (tailcall) on line 84, column 1

(assert (= :dude :dude) "Where's my car?") # => true

assertjgartePlayground
(def a @[1 2])
(def b @[1 2])
(= a b)  # => false

(def a @[1 2])
(def b (array/concat a 3))
a        # => @[1 2 3]
b        # => @[1 2 3]
(= a b)  # => true
array/concatcellularmitosisPlayground
(let [p (parser/new)
      src ``
          (defn x
            [y]
            (+ 3 (* 4
                    (- 2 3)
          ``]
  (parser/consume p src)
  ((parser/state p) :delimiters))
# => "((("
parser/statesogaiuPlayground
(sort-by
  (fn [x] (get x :b))
   @[{:a 1 :b 100} {:a 100 :b 1} {:a -1 :b 50}])

# -> @[{:a 100 :b 1} {:a -1 :b 50} {:a 1 :b 100}]
sort-byfelixrPlayground
@[1 2 3]                 # -> @[1 2 3]
(array 1 2 3)            # -> @[1 2 3]
(array (splice [1 2 3])  # -> @[1 2 3]
(array ;[1 2 3])         # -> @[1 2 3]
arraycellularmitosisPlayground
(var enabled false)
(toggle enabled)
(print enabled)
# => true
toggleFuriouZzPlayground