Welcome, I'm happy to see you here! Feel free to pick a function and add a happy example, the more the merrier!
(- )
# => 0 # wrap short-fn / |
(->> 10
(|(/ $ 2 )))
# =>
5
# also wrap fn
(->> 10
((fn [n ] (/ n 2 ))))
# =>
5 (peg/find-all ~(capture ,(get default-peg-grammar :d ))
"hi 0 bye 1" )
# => [3 9] (reduce2 + [1 2 3 ]) # -> 6
(accumulate2 + [1 2 3 ]) # -> @[1 3 6] (invert {:a 1 :b 2 :c 3 })
# => @{3 :c 1 :a 2 :b} (var a false )
(defer (set a 42 )
(set a true )
(error "Oh no!" ))
# error: Oh no!
(pp a ) # => prints 42 (->> (range 10 ) (map (fn [arg ] (* arg arg ))))
# => @[0 1 4 9 16 25 36 49 64 81] (defn array-difference [array-1 array-2 ]
(filter |(not (has-value? array-2 $ )) array-1 ))
(array-difference [1 2 3 4 5 ] [2 3 4 ]) # => @[1 5] (/ 1 2 3 )
# => 0.166667
# removes a file in the current directory
(os/rm "hello.txt" )(defmacro- =dude
"sets any symbolic expression to the atom :what?"
[a ]
~(var a :what? )) # => <function =dude>
(=dude 2 ) # => :what?
(=dude :2 ) # => :what?
(=dude 2 ) # => :what?
(=dude "2" ) # => :what?
(=dude @"2" ) # => :what?
(=dude @[2 ]) # => :what?
(=dude (2 )) # => :what?
(=dude [2 ]) # => :what?
(=dude @{2 3 }) # => :what?
(doc =dude )
# => macro
# => repl on line 59, column 1
# =>
# => (=dude a)
# => nil
# Macro expanding the =dude macro:
(macex (=dude 2 )) # => :what?
(macex1 (=dude 2 )) # => :what?
# Macros have to be quoted in order to expand
(macex ~(=dude 2 )) # => (var a :what?)
(macex1 ~(=dude 2 )) # => (var a :what?)
(macex ~(=dude @{2 3 })) # => (var a :what?)
# demo of (@ <sym>) feature
(let [content "# => label" ]
(match [:comment @{} "# => label" ]
[:comment _ (@ content )]
:found
nil ))
# => :found (let [p @{:a 1 }
t @{:b 2 }]
(table/setproto t p )
[(get t :a ) (table/rawget t :a )])
# => '(1 nil) (get @"A" 0 ) # => 65 (0b01000001)
(get (buffer/bit-clear @"A" 0 ) 0 ) # => 64 (0b01000000)
(get (buffer/bit-clear @"A" 6 ) 0 ) # => 1 (0b00000001)
(var a 0 )
(assert (pos? a ) "A is definitely not positive" )
# error: A is definitely not positive
# in assert [boot.janet] on line 149, column 11
# in _thunk [repl] (tailcall) on line 3, column 1