bakpakin on master
Update Janet version. (compare)
bakpakin on master
Fix meson.build for older versi… (compare)
bakpakin on v1.22.0
bakpakin on v1.22.0
bakpakin on master
Fix version bump. (compare)
bakpakin on v1.22.0
bakpakin on master
Prepare for 1.22.0 release. (compare)
bakpakin on master
Add `module/value` function to … (compare)
bakpakin on master
Remove file/popen - address #974 (compare)
bakpakin on master
Use janet_getnat when non-negat… (compare)
bakpakin on master
Fix #975 - null ptr dereference… Merge pull request #976 from ri… (compare)
``
(defn map
Map a function over every value in a data structure anddofile
with an absolute path, I get the absolute path :) that makes sense
jpm build
runs with relative path on windows, and full path on linux/macos
(dyn :current-file)
seems to always use /
as the separator, even on windows
if
, where you have to explicitly specify the then-case and the else-case. I don't know much about macros yet so if I'm doing something weird let me know!(defmacro ifte
``
ifte = if-then-else
Works just like `if`, but you have to supply `:then` and `:else` keywords for
extra verboseness. This can be helpful when the then-expression of
else-expression is huge and it becomes hard to keep track of things. In
general, you should probably consider creating variables to mitigate that
problem, but sometimes you're better off using `ifte`.
Usage: (ifte true :then true :else false)
``
[if-condition then-keyword then-expression else-keyword else-expression]
(with-syms [$if-condition
$then-keyword
$then-expression
$else-keyword
$else-expression]
~(let [,$if-condition ,if-condition
,$then-keyword ,then-keyword
,$then-expression (when ,$if-condition ,then-expression)
,$else-keyword ,else-keyword
,$else-expression (unless ,$if-condition ,else-expression)]
(assert
(= :then ,$then-keyword)
"The second argument of `ifte` should always be the :then keyword.")
(assert
(= :else ,$else-keyword)
"The fourth argument of `ifte` should always be the :else keyword.")
(if ,$if-condition
,$then-expression
,$else-expression))))
match
, with literal keywords in the appropriate positions in the matching pattern)
(defmacro ifte
[if-condition then-keyword then-expression else-keyword else-expression]
(assert
(= :then then-keyword)
"The second argument of `ifte` should always be the :then keyword.")
(assert
(= :else else-keyword)
"The fourth argument of `ifte` should always be the :else keyword.")
(with-syms [$if-condition
$then-expression
$else-expression]
~(let [,$if-condition ,if-condition
,$then-expression (when ,$if-condition ,then-expression)
,$else-expression (unless ,$if-condition ,else-expression)]
(if ,$if-condition
,$then-expression
,$else-expression))))
(defmacro ifte
[if-condition then-keyword then-expression else-keyword else-expression]
(assert
(= :then then-keyword)
"The second argument of `ifte` should always be the :then keyword.")
(assert
(= :else else-keyword)
"The fourth argument of `ifte` should always be the :else keyword.")
(with-syms [$then-expression
$else-expression]
~(let [,$then-expression (when ,if-condition ,then-expression)
,$else-expression (unless ,if-condition ,else-expression)]
(if ,if-condition
,$then-expression
,$else-expression))))
repl:1:> (defmacro ifte
repl:2:(> ""
repl:3:(> [& args]
repl:4:(> (match args
repl:5:((> @[if-cond :then then-exp :else else-exp] ~(if ,if-cond ,then-exp ,else-exp)
repl:6:((> (error "Expected (ifte <if> :then <then> :else <else>")))
<function ifte>
repl:7:> (ifte true :then (print "ok") :else (/ 0 0))
ok
nil
repl:8:> (ifte false :then (print "ok") :else (/ 0 0))
-nan
repl:9:> (ifte true (print "ok") :else (/ 0 0))
repl:9:1: compile error: error: (macro) Expected (ifte <if> :then <then> :else <else>
in ifte [repl] on line 6, column 2
repl:10:>
if
is also a macro (or a special form, don't remember). So you can feel free sticking whatever you like in the then and else positions of a normal if
form, and they won't be automatically evaluated
if
, those don't get evaluated
repl:10:> (if false (error "oh nooooo!"))
nil
repl:11:> (ifte true :then (print "ok") :else (error "oh noooo!"))
ok
nil