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

(math/acos 0.3)
1.2661036727795
math/acosbtbytesPlayground
(var x 5)
(%= x 3)
(pp x) # 2
%=skuzzymigletPlayground
(forv i 0 10
 (print "hello"))

# => hello
# => hello
# => hello
# => hello
# => hello
# => hello
# => hello
# => hello
# => hello
# => hello
# => nil
forvjgartePlayground
(buffer/bit (buffer/new-filled 1 48) 4)
# => true
buffer/bitsogaiuPlayground
(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
# repeat is about _side-effects_, since it returns nil.
# You'll need to use a mutable collection if you want to
# use repeat to add repeated items to a collection:
(var coll @["Y" "Z"]) #=> @["Y" "Z"]
(repeat 3 (array/push coll "A")) #=> nil
coll
# Returns:
@["Y" "Z" "A" "A" "A"]

# You can use map if the whole collection consists
# of these repetitions:
(map (fn [_] "A") (range 3))
# Returns:
@["A" "A" "A"]
repeatsemperosPlayground
(def a @[11 12])              # => @[11 12]
(array/insert a 0 10)         # => @[10 11 12]
(array/insert a 3 13)         # => @[10 11 12 13]
(array/insert a -1 14)        # => @[10 11 12 13 14]
(array/insert a -1 15 16 17)  # => @[10 11 12 13 14 15 16 17]
array/insertcellularmitosisPlayground
# Contrived examples returning the variadic arguments passed in.
(defn example-function [& args] args)
(defmacro example-macro [& args] ~(tuple ,;args))

(macex '(example-macro 1 2 3))

(assert (= (example-function 1 2 3)
           (example-macro 1 2 3)))

(def args [1 2 3])

# `apply` is for functions, but there's always `eval`.
(assert (= (apply example-function args)
           (eval ~(example-macro ,;args))))

# Same return for both.
# => (1 2 3)
apply4kbytePlayground
(def f (file/temp))
(file/write f "ok stuff")
(file/seek f :set 0)
(file/read f :all)

# N.b. file/temp's file is not accessible outside of the process
file/tempveqqqPlayground
(protect
  (if (> (math/random) 0.42)
    (error "Good luck")
    "Bad luck"))
# => randomly returns:
# (false "Good luck")
# or
# (true "Bad luck")
protectpepePlayground
(print (doc-format "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat." 30))

    Lorem ipsum dolor
    sit amet, consectetur
    adipiscing elit, sed
    do eiusmod tempor
    incididunt ut labore
    et dolore magna
    aliqua. Ut enim ad
    minim veniam, quis
    nostrud exercitation
    ullamco laboris nisi
    ut aliquip ex ea
    commodo consequat.
doc-formatbtbytesPlayground
(let [x 10]
  (unless (= x 10)
    (print "x is not 10!")
  )
)

# => nil

(let [x 5]
  (unless (= x 10)
    (print "x is not 10!")
  )
)

# => "x is not 10!"
unlessHoangTuan110Playground
(map false? [ false nil   true  0     1     42    'a    :a    "a"   [97]  {:a 42} (fn []) ])
# =>       @[ true  false false false false false false false false false false   false   ]
false?cellularmitosisPlayground
(math/log (* math/e math/e))  # => 2
(math/log2 256)               # => 8
(math/log10 1000)             # => 3
math/log2cellularmitosisPlayground
(- 1)
# => -1
-sogaiuPlayground