Welcome, I'm happy to see you here! Feel free to pick a function and add a happy example, the more the merrier!
(filter (fn [x ] (> x 2 )) [1 2 3 4 5 ]) # @[3 4 5] (peg/match ~{:main (capture (some :S ))}
"hello world" )
# => @["hello"] (distinct [1 1 2 3 ]) # => @[1 2 3]
(distinct "hello" ) # => @[104 101 108 111]
(string/from-bytes (splice (distinct "hello" ))) # => "helo"
# 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 )
(var x 12 ) # => 12
(/= x 2 ) # => 6 (int/u64 "18_446_744_073_709_551_615" )
# => <core/u64 18446744073709551615>
(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)] # 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 # 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 )
(last [1 1 2 3 5 8 ])
# => 8
(seq [v :in (coro
(yield :hi )
(yield :bye ))]
v )
# => @[:hi :bye] (< ) # -> true
(< 1 ) # -> true
(< 1 2 ) # -> true
(< 2 1 ) # -> false
(< 1 2 3 ) # -> true
(< 1 3 2 ) # -> false
((juxt + - * / ) ;[1 2 3 ])
# => '(6 -4 6 0.166667) (math/hypot 5 12 )
# => 13 (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.