Welcome, I'm happy to see you here! Feel free to pick a function and add a happy example, the more the merrier!
## Quadratic Formula
(defn qform
"Use the quadratic formula to solve for x. Returns all real solutions."
[a b c ]
(def det (- (* b b ) (* 4 a c )))
(def factor (/ 0.5 a ))
(cond
(neg? det ) []
(zero? det ) [(* factor (- b ))]
(let [root-det (math/sqrt det )]
[(* factor (- (- b ) root-det )) (* factor (+ (- b ) root-det ))])))
(qform 1 4 3 ) # -> (-3 -1)
(some odd? [2 4 6 8 10 ])
# =>
nil
(do
(def coll @[])
(forv i 0 9
(array/push coll i )
(+= i 2 ))
coll )
# => @[0 3 6]
(os/sleep 1 ) # => nil
(os/sleep 0.1 ) # => nil
(os/sleep 0 ) # => nil
Example usage
janet:1:> (def buf @"ABCDE" )
@"ABCDE"
janet:2:> (buffer/slice 0 )
error: bad slot #0, expected string|symbol|keyword|buffer, got 0
in buffer/slice
in _thunk [repl ] (tailcall ) on line 2 , column 1
janet:3:> (buffer/slice buf 0 )
@"ABCDE"
janet:4:> (buffer/slice buf 0 1 )
@"A"
janet:5:> (buffer/slice buf 0 -1 )
@"ABCDE"
janet:6:> (buffer/slice buf 1 3 )
@"BC"
(def b @"" )
(xprin b "HOHOHO" )
# => nil
b
# => "HOHOHO" (doc doc ) # works
(doc* doc ) # symbol <function doc> not found
(doc* "doc" ) # same as (doc doc) (defn read-from-file [file-path ]
(let [f (file/open file-path :r )
content (file/read f :all )]
(file/close f )
content ))
### USAGE
(read-from-file "/path/to/file-read-example.janet" )
# => @"(defn read-from-file [file-path]\n (let [f (file/open file-path :r)\n content (file/read f :all)]\n (file/close f)\n content))\n" (filter identity [1 true 2 3 nil 4 false ])
# => @[1 true 2 3 4] (string/split "," "bruce,scott,tiger,woods" )
# => @["bruce" "scott" "tiger" "woods"] (filter (partial string/has-prefix? "z" ) (all-bindings )) # => @[zero? zipcoll] (net/address "0.0.0.0" 80 ) # => <core/socket-address 0x55CABA438E90>
(net/address "0.0.0.0" 8989 ) # => <core/socket-address 0x55CABA439980>
(def time (os/time )) # => 1593838001
(os/date t )
# => {:month 6 :dst false :year-day 185 :seconds 41 :minutes 46 :week-day 6 :year 2020 :hours 4 :month-day 3}
(os/date t false )
# => {:month 6 :dst false :year-day 185 :seconds 41 :minutes 46 :week-day 6 :year 2020 :hours 4 :month-day 3}
(os/date t true )
# => {:month 6 :dst true :year-day 184 :seconds 41 :minutes 46 :week-day 5 :year 2020 :hours 23 :month-day 2}
(os/date t :local )
# => {:month 6 :dst true :year-day 184 :seconds 41 :minutes 46 :week-day 5 :year 2020 :hours 23 :month-day 2}
(var abc 123 )
(= 356 (with-vars [abc 456 ] (- abc 100 )))(flatten [1 [2 3 [4 ]] 5 ]) # => @[1 2 3 4 5]