Login
7 branches 0 tags
Ben (X13/Arch) Removed WW specific functionality 58c854b 3 years ago 779 Commits
nujel / stdlib / core / core.nuj
;; Nujel - Copyright (C) 2020-2021 - Benjamin Vincent Schulenburg
;; This project uses the MIT license, a copy should be included under /LICENSE
;;
;; Contains native nujel implementations of some
;; core language constructs and essential macros

[def otherwise #t]
[defmacro deftest l #nil] ; Tests should be skipped when compiling
[defmacro defqtest l #nil] ; Tests should be skipped when compiling

[defmacro comment body
          "Does nothing"
          #nil]

[defmacro += [val inc]
          `[set! ~val [+ ~val ~inc]]]

[defmacro cdr! [l]
          "[set! l [cdr l]]"
          `[set! ~l [cdr ~l]]]

[defn boolean [v] :inline
      "Coerce to boolean"
      [if v #t #f]]

[defn not [v] :inline
      "Return true if V is false"
      [if v #f #t]]

[defn identity [α] :inline
      "Returns its argument"
      α]

[defn list arguments
      "Return ARGUMENTS as a list"
      arguments]

[defn caar [p] :inline
      "[car [car p]]"
      [car [car p]]]

[defn cadr [p] :inline
      "[car [cdr p]]"
      [car [cdr p]]]

[defn cdar [p] :inline
      "[cdr [car p]]"
      [cdr [car p]]]

[defn cddr [p] :inline
      "[cdr [cdr p]]"
      [cdr [cdr p]]]

[defn cadar [p]
      "[cdr [car p]]"
      [car [cdr [car p]]]]

[defn caddr [p]
      "[car [cdr [cdr p]]]"
      [car [cdr [cdr p]]]]

[defn cdddr [p]
      "[cdr [cdr [cdr p]]]"
      [cdr [cdr [cdr p]]]]

[defn cadddr [p]
      "[car [cdr [cdr [cdr p]]]]"
      [car [cdr [cdr [cdr p]]]]]

[defn cddddr [p]
      "[car [cdr [cdr [cdr p]]]]"
      [cdr [cdr [cdr [cdr p]]]]]

[defn caddddr [p]
      "[car [cdr [cdr [cdr p]]]]"
      [car [cdr [cdr [cdr [cdr p]]]]]]

[defn cdddddr [p]
      "[cdr [cdr [cdr [cdr p]]]]"
      [cdr [cdr [cdr [cdr [cdr p]]]]]]

[defn keyword->string [α]
      [when-not [keyword? α] [throw [list :type-error "[keyword->string] can only be called on keywords" α [current-lambda]]]]
      [symbol->string [keyword->symbol α]]]

[defn string->keyword [α]
      [when-not [string? α] [throw [list :type-error "[string->keyword] can only be called on strings" α [current-lambda]]]]
      [symbol->keyword [string->symbol α]]]

[defmacro exception [type description value]
          `[throw [list ~type ~description ~value [current-lambda]]]]