JanetDocsPlaygroundI'm feeling luckyGitHub sign in

JanetDocs is a community documentation site for the Janet programming language

Loading...

Recent examples

(net/address "0.0.0.0" 80) # => <core/socket-address 0x55CABA438E90>

(net/address "0.0.0.0" 8989) # => <core/socket-address 0x55CABA439980>

net/addressjgartePlayground
(peg/find-all ':d "Battery temperature: 40 °C")

# => @[21 22] indices containing digits

# :d (range "09")

# peg grammars are contained in a table @{} (mutable) located in boot.janet source file.

peg/find-alljgartePlayground
(peg/find ':a "Battery temperature: 40 °C")

# => 0 index of the first upper/lower case character

# :a (range "az" "AZ")
peg/findjgartePlayground
(peg/find ':s "Battery temperature: 40 °C")

# => 7 index of the first whitespace character

# :s (set " \t\r\n\0\f\v")

peg/findjgartePlayground
(loop [i :range [0 12]]
  (print i))

# => 0
# => 1
# => 2
# => 3
# => 4
# => 5
# => 6
# => 7
# => 8
# => 9
# => 10
# => 11
# => nil

loopjgartePlayground
(unmarshal @"hello world!") # => 104
unmarshaljgartePlayground
(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
(flatten-into @[1 2 3] @[[4 5 6] @[7 8 9] @[10 11 12]]) # => @[1 2 3 4 5 6 7 8 9 10 11 12]
flatten-intojgartePlayground
(forv i 0 10
 (print "hello"))

# => hello
# => hello
# => hello
# => hello
# => hello
# => hello
# => hello
# => hello
# => hello
# => hello
# => nil
forvjgartePlayground
(one? :dude) # => false
one?jgartePlayground
(defmacro- =dude
 "sets any symbolic expression to the atom :what?"
 [a]
 ~(var a :what?)) # => <function =dude>

(=dude 2) # => :what?

(=dude :2) # => :what?

(=dude 2) # => :what?

(=dude "2") # => :what?

(=dude @"2") # => :what?

(=dude @[2]) # => :what?

(=dude (2)) # => :what?

(=dude @(2)) # => :what?

(=dude @{2 3}) # => :what?


(doc =dude)


# =>    macro
# =>    repl on line 59, column 1
# =>
# =>    (=dude a)


# => nil


# Macro expanding the =dude macro:

(macex (=dude 2)) # => :what?

(macex1 (=dude 2)) # => :what?

# Macros have to be quoted in order to expand

(macex ~(=dude 2)) # => (var a :what?)

(macex1 ~(=dude 2)) # => (var a :what?)

(macex ~(=dude @{2 3})) # => (var a :what?)
defmacro-jgartePlayground
(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
math/int32-max # => 2147483647
math/int32-maxjgartePlayground
(buffer "dude, " "where's " "my " "car?") # => @"dude, where's my car?"
bufferjgartePlayground
(buffer/bit-set @"hahaha" 3) # => @"hahaha"

(buffer/bit-set @"what" 3) # => @"\x7Fhat"

buffer/bit-setjgartePlayground
(buffer/bit-toggle @"dude" 3) # => @"lude"

(buffer/bit-toggle @"hahaha" 3) # => @"`ahaha"
buffer/bit-togglejgartePlayground
(sorted-by > @[1 2 3 4 5 6 7 8 9 10 11 12]) # => @[8 7 9 11 10 12 2 1 3 5 4 6]

(sorted-by < @[1 2 3 4 5 6 7 8 9 10 11 12]) # => @[8 7 9 11 10 12 2 1 3 5 4 6]

(sorted-by = @[1 2 3 4 5 6 7 8 9 10 11 12]) # => @[8 7 9 11 10 12 2 1 3 5 4 6]


sorted-byjgartePlayground
(janet/version 0) # => 49

(janet/version 1) # => 46

(janet/version 2) # => 49

(janet/version 3) # => 55

(janet/version 4) # => 46

(janet/version 5) # => 50
janet/versionjgartePlayground
(> 12 11 10 9 8 7 6 5 4 3 2 1) # => true

(> 12 11 10 9 8 7 6 5 4 3 2 9) # => false
>jgartePlayground
(os/realpath ".") # => "/home/jgarte"

(os/realpath "Downloads") # => "/home/jgarte/Downloads"
os/realpathjgartePlayground
(forever 
 (print "and then?") 
 (ev/sleep 1) 
 (print "no and then!")) 

# => and then? 
# sleeps for one second
# => no and then!
# => and then?
# sleeps for one second
# => no and then!
# ...
foreverjgartePlayground
(take-while number? @[1 2 3 "4" 5 6 7 8 9 "10" 11 "12"]) # => (1 2 3)
take-whilejgartePlayground
(var x 12) # => 12

(/= x 2) # => 6
/=jgartePlayground
(array/pop @[]) # => nil
array/popjgartePlayground
(array/pop (range 12)) # => 11
array/popjgartePlayground
(reduce string "ha" ["ha" "ha" "ha" "ha"]) # => "hahahahaha"

(accumulate string "ha" ["ha" "ha" "ha" "ha"]) # => @["haha" "hahaha" "hahahaha" "hahahahaha"]
accumulatejgartePlayground
(repeat 12 (-> 12 os/cryptorand pp))

# => @"\xA7li[ \xED\xD2\xF7O\xD6\x15="
# => @">\"-w+\x04\x1C\xC1KG\x9C\xE4"
# => @"\x06b\f\xBD\x12\x19\xB6\x1A\xCA\xB9[\x85"
# => @"\xBE`R\t\x13\x81\xED\x9D#\xD0\x11!"
# => @"\xE2\xC1\xD8\x7F\\\xA7\x84\xC0\v\x8B'\x98"
# => @"\xD6\x0Fz\x86\xE2\xB2\x1D}\xC6'{\xB5"
# => @"\x9D\x97\xA1\x07i\x9FW\x83h4n2"
# => @"d\x8E\xB8\xBA \xA6\x9C\f\xC6\xAD{g"
# => @"\r\xB5\xF84#\xB8c~V\xD7d>"
# => @"\xBB\x19\xB2\xDC\x8B\xD9\x7F\xDC\xBE\f\x88\xE3"
# => @"w\xB50\xF9\xFD\xEB\x1D\xFF:j]\xB8"
# => @"\x8F$\xEBKL~\xFD\t\xA8\xD1\x8C\xC5"
# => nil
repeatjgartePlayground
(os/shell "seq 12 | head -n 1") # => 1
os/shelljgartePlayground
(range 12) # => @[0 1 2 3 4 5 6 7 8 9 10 11]

(range 0 12) # => @[0 1 2 3 4 5 6 7 8 9 10 11]

(range 0 12 1) # => @[0 1 2 3 4 5 6 7 8 9 10 11]

(range 0 12 2) # => @[0 2 4 6 8 10]

(range 0 12 3) # => @[0 3 6 9]

(range 0 12 4) # => @[0 4 8]

(range 0 12 6) # => @[0 6]
rangejgartePlayground
(let [sweet "what does mine say?"]
 (let [dude sweet]
  (let [what-does-mine-say? dude]
   what-does-mine-say?))) # => "what does mine say?"
letjgartePlayground