Welcome, I'm happy to see you here! Feel free to pick a function and add a happy example, the more the merrier!
(string/split "\n" @"works\nfor\nbuffers\ntoo" )
# => @["works" "for" "buffers" "too"] (import joy )
# given a handler
(defn handle-func [request ]
(joy/text/plain (string "Hi " ((request :params ) :name ))))
# joy/defroutes will prepare routes
(joy/defroutes r [:get "/hi/:name" :handle-func ])
# which you can pass to joy/app
(joy/server (joy/app {:routes r }) 9002 )
# visit localhost:9002/hi/bob # Due to: https://github.com/swlkr/janetdocs/issues/50
(defn parse-date
"Parses YYYY-MM-DD date format to time"
[date ]
(let [[year month day ] (map scan-number (string/split "-" date ))]
(os/mktime {:year year :month (dec month ) :month-day (dec day )})))
(print (parse-date "2021-01-01" )) # 1609459200
(print (os/strftime "%c" (parse-date "2021-01-01" ))) # Fri Jan 1 00:00:00 2021 (print
(prompt :a
(for i 0 1000000000000
(print (string "i=" i ))
(if (= i 2 )
(return :a 10 )))))
# output:
# i=0
# i=1
# i=2
# 10 (def f (fiber/new (fn [] (yield 2 ) 3 )))
(pp (resume f )) # => 2
(resume f )
(pp (fiber/last-value f )) # => 3
(os/sleep 1 ) # => nil
(os/sleep 0.1 ) # => nil
(os/sleep 0 ) # => nil
# can execute query from a file like:
(db/query (slurp "db/sql/random.sql" ))
# In context:
(defn show [request ]
(when-let [[name ] (request :wildcard )
name (uri/unescape name ) # escaping is important for = and especially %
name (string/replace "_q" "?" name )
binding (first (db/query (slurp "db/sql/search.sql" ) [name ]))]
[:vstack {:spacing "m" }
(binding-header binding )
(examples/index (merge request {:binding binding }))]))
# From https://codeberg.org/veqq/janetdocs/src/commit/ac1dc9e3e82f17e8e9ac047297b00803b68034d0/routes/examples.janet#L217 (map math/abs [-2.9 -2.1 2.1 2.9 ]) # => @[ 2.9 2.1 2.1 2.9 ]
(map math/floor [-2.9 -2.1 2.1 2.9 ]) # => @[ -3 -3 2 2 ]
(map math/ceil [-2.9 -2.1 2.1 2.9 ]) # => @[ -2 -2 3 3 ]
(map math/round [-2.9 -2.1 2.1 2.9 ]) # => @[ -3 -2 2 3 ]
(map math/trunc [-2.9 -2.1 2.1 2.9 ]) # => @[ -2 -2 2 2 ]
(last [1 1 2 3 5 8 ])
# => 8
# './foo.janet' is a file with contents '(def bar 42)'.
(use foo )
bar # => 42 (-> 1 (< 2 )) # -> true
(->> 1 (< 2 )) # -> false (map |(+ $0 $1 ) [1 2 3 ] [4 5 6 ]) # @[5 7 9] - uses the fn shorthand (let [a 1 b 2 c 3 ] (+ a b c )) # => 6
(let
[a 1
b (+ a 1 )
c (+ b 1 )]
(+ a b c )) # => 6
(type (fiber/new (fn [])))
# =>
:fiber (nat? 1 ) # => true
(nat? 3.14159 ) # => false