Login
7 branches 0 tags
Ben (X13/Arch) The stdlib is now completely bytecoded 5e5e056 3 years ago 615 Commits
nujel / stdlib / core / closures.nuj
;; Nujel - Copyright (C) 2020-2021 - Benjamin Vincent Schulenburg
;; This project uses the MIT license, a copy should be included under /LICENSE
;;
;; Mostly macros for all kinds of let varieties

[defn let/arg [arg]
  [when arg
    [when [or [not [pair? arg]]
              [not [symbol? [car arg]]]]
      [throw [list :invalid-let-form "Please fix the structure of the let form" arg]]]
    `[def ~[car arg] ~[cadr arg]]]]

[defn let/args [args]
  [if-not args #nil
          [cons [let/arg [car args]]
                [let/args [cdr args]]]]]
[defmacro let [bindings . body]
  "Evalutes to BODY if PRED is true"
  `[let* [do ~@[let/args bindings] ~@body]]]

[defmacro if-let [binding then else]
  `[let* [def ~[car binding] ~[cadr binding]]
     [if ~[car binding] ~then ~else]]]

[defmacro when-let [binding . body]
  `[if-let ~binding ~[cons 'do body] #nil]]