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

(filter (fn [x] (> x 2)) [1 2 3 4 5])  # @[3 4 5]
filterbtbytesPlayground
(peg/match ~{:main (capture (some :S))}
           "hello world")
# => @["hello"]
peg/matchsogaiuPlayground
(distinct [1 1 2 3])  # => @[1 2 3]

(distinct "hello")  # => @[104 101 108 111]
(string/from-bytes (splice (distinct "hello")))  # => "helo"
distinctcellularmitosisPlayground
# note, if running a server from the repl, you need to (quit) your repl.

# in a terminal:
# $ while true; do date | nc 0.0.0.0 1234 -w 1; sleep 1; done

# in a janet repl:
(net/server "0.0.0.0" 1234
  (fn [conn]
    (prin (net/read conn 4096))
    (net/close conn)))
# output doesn't actually start until you (quit) your repl's fiber:
(quit)
net/servercellularmitosisPlayground
(var x 12) # => 12

(/= x 2) # => 6
/=jgartePlayground
(int/u64 "18_446_744_073_709_551_615")
# => <core/u64 18446744073709551615>
int/u64sogaiuPlayground
(seq [i :range [0 3]
      j :range [0 3]
      :let [c (string/format "%c" (+ 97 i))]]
  [(keyword c) j])
# => '@[(:a 0) (:a 1) (:a 2) (:b 0) (:b 1) (:b 2) (:c 0) (:c 1) (:c 2)]
seqsogaiuPlayground
# see https://janet-lang.org/docs/abstract_machine.html

(def plus10
 (asm 
   '{
     :arity 1
     :bytecode @[(ldi 1 10)    # $1 = 10
                 (add 2 0 1)   # $2 = $0 + $1
                 (ret 2)]}))   # return $2

(plus10 1) # -> 11
asmfelixrPlayground
# in a terminal:
# $ while true; do date | nc 0.0.0.0 1234 -w 1; sleep 1; done

# in a janet repl:
(net/server "0.0.0.0" 1234
  (fn [conn]
    (prin (net/read conn 4096))
    (net/close conn)))
# note: output doesn't actually start until you (quit) your repl's fiber:
(quit)
net/readcellularmitosisPlayground
(last [1 1 2 3 5 8])
# => 8
lastsogaiuPlayground
(seq [v :in (coro
                (yield :hi)
                (yield :bye))]
    v)
# => @[:hi :bye]
coropepePlayground
(<)        # -> true
(< 1)      # -> true
(< 1 2)    # -> true
(< 2 1)    # -> false
(< 1 2 3)  # -> true
(< 1 3 2)  # -> false
<cellularmitosisPlayground
((juxt + - * /) ;[1 2 3])
# => '(6 -4 6 0.166667)
juxtsogaiuPlayground
(math/hypot 5 12)
# => 13
math/hypotsogaiuPlayground
(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