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

(interpose 0 [1 2 3])
# -> @[1 0 2 0 3]
interposeKrasjetPlayground
(map type [nil true 42 [] @[] {} @{} "a" @"b" 'c :d identity (fn [])])
# => @[:nil :boolean :number :tuple :array :struct :table :string :buffer :symbol :keyword :function :function]
typecellularmitosisPlayground
janet:2:> (all true? [true true false])
false
janet:3:> (all even? [2 4 6 7])
false
janet:5:> (all even? [2 4 6])
true
allswlkrPlayground
(defn capitalize [str]
  (string (string/ascii-upper (string/slice str 0 1)) (string/slice str 1)))
string/ascii-upperveqqqPlayground
(os/time)  # => 1593837535
os/timecellularmitosisPlayground
(all-dynamics)
# => @[:args :err-color :executable :peg-grammar :pretty-format :syspath]

(setdyn :fixed true)
(all-dynamics)
# => @[:args :err-color :executable :fixed :peg-grammar :pretty-format :syspath]
all-dynamicspepePlayground
(os/shell "seq 12 | head -n 1") # => 1
os/shelljgartePlayground
(empty? :)
# => true
empty?sogaiuPlayground
(spit "/tmp/hello.sh" "#!/bin/bash\necho 'Hello from Bash!'\n")
(os/chmod "/tmp/hello.sh" "rwx------")
(os/setenv "PATH" (string (os/getenv "PATH") ":/tmp"))
(os/shell "hello.sh")
os/chmodcellularmitosisPlayground
You can see janet datastructure values by typing:

(string/format "%q" {:a 1 :b 2}) # => {:a 1 :b 2} 
string/formatswlkrPlayground
(bxor 3 6)  # => 5

#     011  (3)
# xor 110  (6)
# -------
#     101  (5)
bxorcellularmitosisPlayground
(string/join @["alice" "bob" "eve"] "\t")
# => "alice\tbob\teve"
string/joinsogaiuPlayground
(math/log (* math/e math/e))  # => 2
(math/log2 256)               # => 8
(math/log10 1000)             # => 3
math/logcellularmitosisPlayground
(map  |($ {:a 7 :b 8} )   [  keys      values    kvs             pairs                 ])
# =>                     @[  @[:a :b]  @[7 8]    @[:a 7 :b 8]    @[(:a 7) (:b 8)]      ]

(map  |($ [4 5 6] )       [  keys      values    kvs             pairs                 ])
# =>                     @[  @[0 1 2]  @[4 5 6]  @[0 4 1 5 2 6]  @[(0 4) (1 5) (2 6)]  ]

(map  |($ 'ab )           [  keys      values    kvs             pairs                 ])
# =>                     @[  @[0 1]    @[97 98]  @[0 97 1 98]    @[(0 97) (1 98)]      ]

(map  |($ :ab )           [  keys      values    kvs             pairs                 ])
# =>                     @[  @[0 1]    @[97 98]  @[0 97 1 98]    @[(0 97) (1 98)]      ]

(map  |($ "ab" )          [  keys      values    kvs             pairs                 ])
# =>                     @[  @[0 1]    @[97 98]  @[0 97 1 98]    @[(0 97) (1 98)]      ]
pairscellularmitosisPlayground
(map length  [  'a  :a  "a"  [97]  @[97]  {0 97}  @{0 97}  ])
# =>        @[  1   1   1    1     1      1       1        ]
lengthcellularmitosisPlayground