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

# on a Core i5-4590:
(os/arch)  # => :x64

# on an Intel Atom N270:
(os/arch)  # => :x86

# on a raspberry pi:
(os/arch)  # => :arm
os/archcellularmitosisPlayground
(def a @[])
(array/insert a  1 :a)  # error: index out of range
(array/insert a -2 :a)  # error: index out of range
array/insertcellularmitosisPlayground
(seq [v :in (coro
                (yield :hi)
                (yield :bye))]
    v)
# => @[:hi :bye]
coropepePlayground
(net/address "0.0.0.0" 80) # => <core/socket-address 0x55CABA438E90>

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

net/addressjgartePlayground
(symbol "foo")  # => foo

(def a "foo")
(symbol a)         # => foo
(symbol a 42 nil)  # => foo42nil
symbolcellularmitosisPlayground
(bxor 2r011 2r110)
# => 5
bxorsogaiuPlayground
# note that 'not' works as an implementation of 'falsey?'
(map not     [ nil   false true  0     1     'a    :a    "a"   []    {}    (fn []) ])
# =>        @[ true  true  false false false false false false false false false   ]

(map truthy? [ nil   false true  0     1     'a    :a    "a"   []    {}    (fn []) ])
# =>        @[ false false true  true  true  true  true  true  true  true  true    ]
notcellularmitosisPlayground
(math/rng-uniform (math/rng 0))
# => 0.487181
math/rng-uniformsogaiuPlayground
(->  1 (< 2))   # -> true
(->> 1 (< 2))   # -> false
->>cellularmitosisPlayground
(string/check-set "0123456789abcdef" "deadbeef") # => true
string/check-setsogaiuPlayground
(defmacro timeit [& body]
    # generate unique symbols to use in the macro so they can't conflict with anything used in `body`
    (with-syms [$t0 $t1]
        ~(do
            (def $t0 (os/clock :monotonic :double))
            (do ,;body)
            (def $t1 (os/clock :monotonic :double))
            (- $t1 $t0))))

(def time-taken (timeit (os/sleep 0.5)))
(printf "Took %.3f seconds" time-taken)
with-symsAndriamanitraPlayground
(update @{:a 1} :a inc)
# => @{:a 2}
updatesogaiuPlayground
(map truthy? [ nil   false true  0     1     'a    :a    "a"   []    {}    (fn []) ])
# =>        @[ false false true  true  true  true  true  true  true  true  true    ]

# note that 'not' works as an implementation of 'falsey?'
(map not     [ nil   false true  0     1     'a    :a    "a"   []    {}    (fn []) ])
# =>        @[ true  true  false false false false false false false false false   ]
truthy?cellularmitosisPlayground
(not=        [1 1]   [1 1])  # => false
(not=        [1 1]   [2 3])  # => true
(not=        [1 1]  @[1 1])  # => true
(not=        [1 1]  @[2 3])  # => true
(not=       @[1 1]  @[1 1])  # => true
(not=       @[1 1]  @[2 3])  # => true

(deep-not=   [1 1]   [1 1])  # => nil
(deep-not=   [1 1]   [2 3])  # => true
(deep-not=   [1 1]  @[1 1])  # => true
(deep-not=   [1 1]  @[2 3])  # => true
(deep-not=  @[1 1]  @[1 1])  # => nil
(deep-not=  @[1 1]  @[2 3])  # => true
deep-not=cellularmitosisPlayground
(def b @"")
(xprin b "HOHOHO")
# => nil
b
# => "HOHOHO"
xprinpepePlayground