Welcome, I'm happy to see you here! Feel free to pick a function and add a happy example, the more the merrier!
(empty? [])
# => true
(odd? 2 ) # => false
(odd? nil ) # throws an error
(odd? 1 ) # => true
(odd? "a" ) # => throws an error # removes a file in the current directory
(os/rm "hello.txt" )# 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 (var x 5 )
(%= x 3 )
(pp x ) # 2 (freeze @{:a @[1 2 ]
:b @{:x @[8 9 ]
:y :smile }})
# => {:a (1 2) :b {:x (8 9) :y :smile}} (math/hypot 1 1 ) # => 1.41421
(math/sqrt 2 ) # => 1.41421
(array/pop (range 12 )) # => 11 (peg/find-all ~(capture :d )
"hi 0 bye 1" )
# => @[3 9] (buffer/bit-set @"hahaha" 3 ) # => @"hahaha"
(buffer/bit-set @"what" 3 ) # => @"\x7Fhat"
(string/reverse "hello" ) # => "olleh" (disasm (fn []) :bytecode )
# => @[(retn)]
# in the file ex.janet
(main [_ & args ]
(print "write something and I'll echo it" )
(def x (getline ))
(print x ))
# in the terminal:
# $ janet ex.janet
# write something and I'll echo it
# bla <- you wrote this
# bla (update @[3 4 5 ] 1 dec ) # => @[3 3 5]
(update (update @[3 4 5 ] 1 dec ) 2 inc ) # => @[3 3 6]
(put @{:a 4 :b 5 } :c 6 ) # => @{:a 4 :b 5 :c 6}
(put @{:a 4 :b 5 } :b nil ) # => @{:a 4}
(put @{:a 4 :b 5 } :z nil ) # => @{:a 4 :b 5}
(put @[:a :b :c ] 0 :z ) # => @[:z :b :c]
(put @[:a :b :c ] 1 nil ) # => @[:a nil :c]
(put @[:a :b :c ] 5 :d ) # => @[:a :b :c nil nil :d]
(put @"hello" 0 "z" ) # error: can only put integers in buffers
(defn ord [ch ] (first (string/bytes ch )))
(ord "z" ) # => 122
(put @"hello" 0 122 ) # => @"zello"
(put @"hello" 0 (ord "z" ) ) # => @"zello"
(put @"hello" 8 (ord "y" ) ) # => @"hello\0\0\0y"