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

(describe {:a 1}) # => "<struct 0x5564AF1BD6C0>"
describesogaiuPlayground
(let (x @["This" "is" "a"]     # Must be array.
      y @["test" "of"]       
      z  ["the" "emergency!"])  # Tuple OK for part.
  (pp (array/join x y z)))

# @["This" "is" "a" "test" "of" "the" "emergency!"]
array/joinoofoePlayground
(doc string)


# =>    cfunction
# =>    ../src/core/corelib.c on line 349, column 1
# =>
# =>    (string & xs)
# =>
# =>    Creates a string by concatenating the elements of xs together. If
# =>    an element is not a byte sequence, it is converted to bytes via
# =>    describe. Returns the new string.


# nil
docjgartePlayground
(odd? 2) # => false
(odd? nil) # throws an error
(odd? 1) # => true
(odd? "a") # => throws an error
odd?swlkrPlayground
(blshift 8 2)  # => 32
blshiftcellularmitosisPlayground
(def cc (ev/thread-chan 99))  # Sets up a message channel.
(def ww (filewatch/new cc))   # Creates the watcher.
(filewatch/add ww "ftest.janet" :all)  # File to watch.
(filewatch/listen ww)         # Start filewatcher listening for changes.

(ev/spawn-thread              # Spawn thread to catch change events.
 (print "Waiting...")
 (forever (pp (ev/take cc))))
filewatch/newoofoePlayground
(string "hello " "world") # => "hello world"
stringswlkrPlayground
(string "hello" nil true 42 :bar)  # => "helloniltrue42bar"
(string :a :b :c)  # => "abc"
stringcellularmitosisPlayground
(invert :yo)
# => @{111 1 121 0}
invertsogaiuPlayground
(def cc (ev/thread-chan 99))  # Sets up a message channel.
(def ww (filewatch/new cc))   # Creates the watcher.
(filewatch/add ww "ftest.janet" :all)     # Watch for all changes.
(filewatch/add ww "fadd.janet"  :modify)  # Only care if modified (Linux-specific flag).
(filewatch/listen ww)         # Start filewatcher listening for changes.

(pp (ev/take cc))             # Print info on first file to change.
(filewatch/unlisten ww)       # Stop caring about changes.
filewatch/addoofoePlayground
(os/shell "touch foo")
(os/stat "foo" :modified)  # => 1593836002
(os/touch "foo")
(os/stat "foo" :modified)  # => 1593836013
os/touchcellularmitosisPlayground
(sorted [1 -2 2 3 9 -10])  # @[-10 -2 1 2 3 9]
sortedbtbytesPlayground
# foo.txt is a file with contents "hello\nworld\n".
(slurp "foo.txt")  # => @"hello\nworld\n"
(string/split "\n" (slurp "foo.txt"))  # => @["hello" "world" ""]

(defn slurp-lines [path]
  (string/split "\n" (slurp path)))

(slurp-lines "foo.txt")  # => @["hello" "world" ""]

(string/join @["hello" "world" ""] "\n")  # => "hello\nworld\n"
(spit "foo2.txt" (string/join @["hello" "world" ""] "\n"))
# The contents of foo.txt and foo2.txt are now identical.

(defn spit-lines [path lines]
  (spit path (string/join lines "\n")))

(spit-lines "foo3.txt" (slurp-lines "foo.txt"))
# The contents of foo.txt and foo3.txt are now identical.
slurpcellularmitosisPlayground
(eval-string "(+ 1 2 3 4)") # -> 10
(eval-string ")") # -> parse error
(eval-string "(bloop)") # -> compile error
(eval-string "(+ nil nil)") # -> runtime error
eval-stringswlkrPlayground
(invert "yo")
# => @{111 1 121 0}
invertsogaiuPlayground