Welcome, I'm happy to see you here! Feel free to pick a function and add a happy example, the more the merrier!
(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 ]
(as-> [1 2 3 ] _
(map inc _ )
(sum _ )
(- _ 10 )
(< _ 0 ))
# -> true
# same as
(< (- (sum (map inc [1 2 3 ])) 10 ) 0 )(slice [:a :b :c :d ]) # => (:a :b :c :d)
(slice [:a :b :c :d ] 0 ) # => (:a :b :c :d)
(slice [:a :b :c :d ] 1 ) # => (:b :c :d)
(slice [:a :b :c :d ] 3 ) # => (:d)
(slice [:a :b :c :d ] 4 ) # => ()
(slice [:a :b :c :d ] 5 ) # error: index out of range
(slice [:a :b :c :d ] -1 ) # => ()
(slice [:a :b :c :d ] -2 ) # => (:d)
(slice [:a :b :c :d ] -4 ) # => (:b :c :d)
(slice [:a :b :c :d ] -5 ) # => (:a :b :c :d)
(slice [:a :b :c :d ] -6 ) # error: index out of range
(slice [:a :b :c :d ] 0 0 ) # => ()
(slice [:a :b :c :d ] 0 1 ) # => (:a)
(slice [:a :b :c :d ] 0 4 ) # => (:a :b :c :d)
(slice [:a :b :c :d ] -1 -1 ) # => ()
(slice [:a :b :c :d ] -2 -1 ) # => (:d)
(slice [:a :b :c :d ] -5 -1 ) # => (:a :b :c :d)
(slice [:a :b :c :d ] 1 0 ) # => ()
(slice [:a :b :c :d ] 4 0 ) # => ()
(slice [:a :b :c :d ] -1 -2 ) # => ()
(slice [:a :b :c :d ] -1 -5 ) # => ()
(peg/find-all ~(capture (range "09" ))
"hi 0 bye 1" )
# => @[3 9] # To resume an image's environment:
# With this example image:
# echo "(def a 1)" > test.janet
# janet -c test.janet test.jimage
# Now open the REPL:
# To enter an image, for continued development or exploration. N.b. this does not work as expected:
# See: https://janet.zulipchat.com/#narrow/channel/409517-help/topic/Image.20Based.20Development.3F/with/529177765
(defn restore-image [image ]
(loop [[k v ] :pairs image ]
(put (curenv ) k v )))
(restore-image (load-image (slurp "test.jimage" )))# note that os/touch does not create a file if it does not yet exist.
(os/touch "foo" )
error: No such file or directory
in os/touch
in _thunk [repl ] (tailcall ) on line 2 , column 1
(-> 1 (< 2 )) # -> true
(->> 1 (< 2 )) # -> false (/ 2 )
# => 0.5
(map |($ {:a 7 :b 8 } ) [ keys values kvs pairs ])
# => @[ @[:a :b] @[7 8] @[:a 7 :b 8] @[(:a 7) (:b 8)] ]
(map |($ [4 5 6 ] ) [ keys values kvs pairs ])
# => @[ @[0 1 2] @[4 5 6] @[0 4 1 5 2 6] @[(0 4) (1 5) (2 6)] ]
(map |($ 'ab ) [ keys values kvs pairs ])
# => @[ @[0 1] @[97 98] @[0 97 1 98] @[(0 97) (1 98)] ]
(map |($ :ab ) [ keys values kvs pairs ])
# => @[ @[0 1] @[97 98] @[0 97 1 98] @[(0 97) (1 98)] ]
(map |($ "ab" ) [ keys values kvs pairs ])
# => @[ @[0 1] @[97 98] @[0 97 1 98] @[(0 97) (1 98)] ]
(peg/match ~{:main (capture (some :S ))}
"hello world" )
# => @["hello"] (def conn-chan (ev/thread-chan 1000 ))
(defn producer [no ]
(forever
(ev/sleep 5 )
(print "Adding data from producer num:" no )
(ev/give conn-chan (math/random ))))
(defn consumer [no ]
(forever
(ev/sleep 0.5 )
(def num (ev/take conn-chan ))
(print num ": Printing from consumer:" no )))
(defn main [& args ]
(ev/spawn-thread (producer 1 ))
(ev/spawn-thread (consumer 1 ))
(ev/spawn-thread (consumer 2 ))
(ev/sleep 20 )
(print "exiting" ))(defn spit-lines [path lines ]
(spit path (string/join lines "\n" )))(-> "X"
(string "a" "b" )
(string "c" "d" )
(string "e" "f" )) # => "Xabcdef" (def chan (ev/chan ))
(def f (ev/go (coro (ev/give-supervisor :msg "Hello" )) nil chan ))
(pp (ev/take chan )) # => (:msg "Hello")
(import joy )
# given a handler
(defn handle-func [request ]
(joy/text/plain (string "Hi " ((request :params ) :name ))))
# joy/routes will make handlers
(def r (joy/routes [:get "/hi/:name" :handle-func ]))
# which you can pass to joy/app
(joy/server (joy/app {:routes r }) 9002 )
# visit at localhost:9002/hi/bob