ref: 5019c474f1124000e20065f3fcae200ab798e9f8
parent: 98c4ced1fc5d1eca1db3137124e805d988bb990f
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Mon Mar 17 16:30:35 EDT 2025
update documentation
--- a/boot/sl.boot
+++ b/boot/sl.boot
@@ -13,7 +13,8 @@
#fn("z0700}2:" #(aset!)) NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL #fn("n3012082>1|:" #(#fn("n1A061:" #())))
NIL NIL NIL NIL NIL NIL NIL NIL #fn("z0700}2:" #(aref)) NIL NIL NIL)
*properties* #table(*funvars* #table(identity ((x)) >= ((a . rest)) void? ((x)) length= ((lst
- n)) positive? ((x)) doc-for ((term (doc NIL))) car ((lst)) <= ((a . rest)) negative? ((x)) rand (NIL) void (rest) nan? ((x)) rand-double (NIL) 1- ((n)) cdr ((lst)) + ((num…)) > ((a . rest)) __finish ((status)) lz-unpack ((data
+ n)) positive? ((x)) doc-for ((term (doc NIL))) car ((lst)) <= ((a . rest)) remprop ((symbol
+ key)) negative? ((x)) rand (NIL) void (rest) nan? ((x)) rand-double (NIL) 1- ((n)) > ((a . rest)) cdr ((lst)) + ((num…)) __finish ((status)) lz-unpack ((data
:to destination)
(data :size decompressed-bytes)) defstruct ((name doc options… (slot-1 DEFAULT) slot-2 (slot-3
:read-only))
@@ -20,22 +21,23 @@
(name (:type vec) (:named T) (:constructor T) (:conc-name
NIL)
(:predicate NIL) . slots)) help ((term)) rand-u32 (NIL) = ((a . rest)) rand-u64 (NIL) add-exit-hook ((fun)) /= ((a . rest)) lz-pack ((data
- (level 0))) rand-float (NIL) *prompt* (NIL) cons? ((value)) vm-stats (NIL) * ((num…)) 1+ ((n)) zero? ((x))) *doc* #table(zero? "Return `T` if `x` is zero." >= "Return `T` if the arguments are in non-increasing order (previous\none is greater than or equal to the next one)." void? "Return `T` if `x` is `#<void>`, `NIL` otherwise." identity "Return `x`." length= "Perform a bounded length test.\n\nUse this instead of `(= (length lst) n)`, since it avoids unnecessary\nwork and always terminates." positive? "Return `T` if `x` is greater than zero." doc-for "Define documentation for a top level term.\n\nIf `term` is a function signature and `doc` is not specified, just\nthe signature will be included in the documentation, without\nreplacing any previously defined." car "Return the first element of a list or `NIL` if not available." *builtins* "VM instructions as closures." <= "Return `T` if the arguments are in non-decreasing order (previous\none is less than or equal to the next one)." negative? "Return `T` if `x` is negative." void "Return the constant `#<void>` while ignoring any arguments.\n\n`#<void>` is mainly used when a function has side effects but does not\nproduce any meaningful value to return, so even though `T` or `NIL` could\nbe returned instead, in case of `#<void>` alone, REPL will not print\nit." rand "Return a random non-negative fixnum on its maximum range." nan? "Return `T` if the argument is *NaN*, regardless of the sign." Instructions "VM instructions mapped to their encoded byte representation." rand-double "Return a random double on interval [0.0, 1.0]." 1- "Equivalent to `(- n 1)`." > "Return `T` if the arguments are in strictly decreasing order (previous\none is greater than the next one)." cdr "Return the tail of a list or `NIL` if not available." + "Return sum of the numbers or `0` with no arguments." T "A boolean \"true\".\n\n(not T) → NIL\n(if T 'yes 'no) → 'yes" lz-unpack "Return decompressed data previously compressed using lz-pack.\n\nEither destination for the decompressed data or the expected size of\nthe decompressed data must be specified. In the latter case a new\narray is allocated." __finish "A function called right before exit by the VM." help "Display documentation for the specified term, if available." defstruct "Defines a structure type with a specific name and slots.\n\nThe default underlying type is a \"named\" `vector`, where the\nfirst element is the name of the structure's type, the rest are the\nslot values. If the name as the first element isn't required,\n`:named NIL` should be used. A `list` can be used instead of a\n`vector` by adding `:type list` option.\n\nThe option `:conc-name` specifies the slot accessor prefix, which\ndefaults to `<name>-`.\n\nDefault predicate name (`<name>?`) can be changed:\n\n (defstruct blah :predicate blargh? a b c)" rand-u32 "Return a random integer on interval [0, 2³²-1]." = "Return `T` if the arguments are equal." rand-u64 "Return a random integer on interval [0, 2⁶⁴-1]." NIL "An empty list. Also used as the opposite of T.\n\n(not NIL) → T\n(if NIL 'yes 'no) → 'no\n(car NIL) → NIL\n(cdr NIL) → NIL" add-exit-hook "Puts an one-argument function on top of the list of exit hooks.\n\nOn shutdown each exit hook is called with the exit status as a\nsingle argument, which is (usually) `0` on success and any other\nnumber on error." /= "Return `T` if not all arguments are equal. Shorthand for `(not (= …))`." lz-pack "Return data compressed using Lempel-Ziv.\n\nThe data must be an array, returned value will have the same type.\nThe optional `level` is between `0` and `10`. With `level` set to\n`0` a simple LZSS using hashing will be performed. Levels between\n`1` and `9` offer a trade-off between time/space and ratio. Level\n`10` is optimal but very slow." arg-counts "VM instructions mapped to their expected arguments count." rand-float "Return a random float on [0.0, 1.0] interval." *prompt* "Function called by REPL to signal the user input is
\ No newline at end of file
+ (level 0))) rand-float (NIL) *prompt* (NIL) getprop ((symbol key (def NIL))) cons? ((value)) vm-stats (NIL) * ((num…)) putprop ((symbol
+ key val)) 1+ ((n)) zero? ((x))) *doc* #table(zero? "Return `T` if `x` is zero." >= "Return `T` if the arguments are in non-increasing order (previous\none is greater than or equal to the next one)." void? "Return `T` if `x` is `#<void>`, `NIL` otherwise." identity "Return `x`." length= "Perform a bounded length test.\n\nUse this instead of `(= (length lst) n)`, since it avoids unnecessary\nwork and always terminates." positive? "Return `T` if `x` is greater than zero." doc-for "Define documentation for a top level term.\n\nIf `term` is a function signature and `doc` is not specified, just\nthe signature will be included in the documentation, without\nreplacing any previously defined." car "Return the first element of a list or `NIL` if not available." *builtins* "VM instructions as closures." remprop "Remove a property value associated with a symbol." <= "Return `T` if the arguments are in non-decreasing order (previous\none is less than or equal to the next one)." negative? "Return `T` if `x` is negative." void "Return the constant `#<void>` while ignoring any arguments.\n\n`#<void>` is mainly used when a function has side effects but does not\nproduce any meaningful value to return, so even though `T` or `NIL` could\nbe returned instead, in case of `#<void>` alone, REPL will not print\nit." rand "Return a random non-negative fixnum on its maximum range." nan? "Return `T` if the argument is *NaN*, regardless of the sign." Instructions "VM instructions mapped to their encoded byte representation." rand-double "Return a random double on interval [0.0, 1.0]." 1- "Equivalent to `(- n 1)`." > "Return `T` if the arguments are in strictly decreasing order (previous\none is greater than the next one)." cdr "Return the tail of a list or `NIL` if not available." + "Return sum of the numbers or `0` with no arguments." T "A boolean \"true\".\n\n(not T) → NIL\n(if T 'yes 'no) → 'yes" lz-unpack "Return decompressed data previously compressed using lz-pack.\n\nEither destination for the decompressed data or the expected size of\nthe decompressed data must be specified. In the latter case a new\narray is allocated." __finish "A function called right before exit by the VM." help "Display documentation for the specified term, if available." defstruct "Defines a structure type with a specific name and slots.\n\nThe default underlying type is a \"named\" vector (`:type vec`),\nwhere the first element is the name of the structure's type, the\nrest are the slot values. If the name as the first element isn't\nrequired, `:named NIL` should be used. A list can be used instead\nof a vector by adding `:type list` option.\n\nAn example of a default constructor signature, based on structure\ndefinition:\n\n (defstruct blah a b c) →\n (make-blah (:a NIL) (:b NIL) (:c NIL))\n\nIt can be customized in several ways. For example:\n\n ; disable the constructor altogether\n (defstruct blah :constructor NIL a b c)\n ; only change its name\n (defstruct blah :constructor blargh a b c)\n ; rename AND avoid using keywords\n (defstruct blah :constructor (blah a b c) a b c)\n\nThe option `:conc-name` specifies the slot accessor prefix, which\ndefaults to `name-`.\n\nDefault predicate name (`name?`) can be changed:\n\n ; use \"blargh?\" instead of \"blah?\"\n (defstruct blah :predicate blargh? a b c)" rand-u32 "Return a random integer on interval [0, 2³²-1]." = "Return `T` if the arguments are equal." rand-u64 "Return a random integer on interval [0, 2⁶⁴-1]." NIL "An empty list. Also used as the opposite of T.\n\n(not NIL) → T\n(if NIL 'yes 'no) → 'no\n(car NIL) → NIL\n(cdr NIL) → NIL" add-exit-hook "Puts an one-argument function on top of the list of exit hooks.\n\nOn shutdown each exit hook is called with the exit status as a\nsingle argument, which is (usually) `0` on success and any other\nnumber on error." /= "Return `T` if not all arguments are equal. Shorthand for `(not (= …))`." lz-pack "Return data compressed using Lempel-Ziv.\n\
\ No newline at end of file
required.\n\nDefault function prints `#;> `." cons? "Return `T` if the value is a cons cell." vm-stats "Print various VM-related information, such as the number of GC\ncalls so far, heap and stack size, etc." * "Return product of the numbers or `1` with no arguments." 1+ "Equivalent to `(+ n 1)`." *properties* "All properties of symbols recorded with `putprop` are recorded in this table."))
*syntax-environment* #table(bcode:nconst #fn("n1200r2e3:" #(aref)) doc-for #fn("\x8710002000W1000J60q?140B86;35040<;J404086;35040=863H020212287e212288e2e4e2:20212287e21e3e2:" #(void
sym-set-doc quote)) with-input-from #fn("z12021e1220e2e1e12315163:" #(#fn(nconc) with-bindings
*io-in* #fn(copy-list))) unless #fn("z1200q211Pe4:" #(if
begin)) defmacro #fn("z170151863D0710<860=5341=?1@30q42223240<e22526e10=e12715153e3e2:" #(value-get-doc
-63:" #(#fn(nconc) with-bindings
+ with a symbol." * "Return product of the numbers or `1` with no arguments." vm-stats "Print various VM-related information, such as the number of GC\ncalls so far, heap and stack size, etc." cons? "Return `T` if the value is a cons cell." 1+ "Equivalent to `(+ n 1)`." *properties* "All properties of symbols recorded with `putprop` are recorded in this table."))
#fn("z1200q211Pe4:" #(if
begin)) defmacro #fn("z170151863D0710<860=5341=?1@30q42223240<e22526e10=e12715153e3e2:" #(value-get-doc
-340q:0<85<20Q;J80485<DQ3C085=J6085<:2185=P:85=J@02285<A<0=51e3:85T23C\x94074758551513c07675855151278685<e2e12886217975855151PA<0=51e4e3:272:85<e2e1282:7585512:e2A<0=51e4e3:2885<2185=PA<0=51e4:" #(else
+e21e3e2:" #(void
82:7585512:e2A<0=51e4e3:2885<2185=PA<0=51e4:" #(else
begin or => 1arg-lambda? caddr caadr let if cddr #:g20) cond-clauses->if))) do #fn("z21<2071052207205220230522425268827872829e12:1=51522829e12:82512825e18:52e153e4e3e2e12825e18952e3:" #(#fn(map)
car cadr #fn("n170051B38071061:0<:" #(cddr caddr)) letrec #:g348 λ if #fn(nconc) begin #fn(copy-list))) mark-label #fn("n22002122e21e4:" #(emit
quote label)) with-bindings #fn("z12071052207205220230522425e12076888653e12720288687535129242:e12715152242:e127202;8688535152e3e164:" #(#fn(map)
car cadr #fn("n12060:" #(#fn(gensym))) #fn(nconc) let list #fn(copy-list)
-tect begin #fn("n22001e3:" #(set!)))) let #fn("z1q0R3B00?641<?041=?1@30q42021e12223052e124151532225052863C0268687e2e186e3@408788P:" #(#fn(nconc)
+2185=PA<0=51e4:" #(else
1200r3e3:" #(aref)) > #fn("z12021e12273151510e163:" #(#fn(nconc)
< #fn(copy-list) reverse!)) when #fn("z1200211Pqe4:" #(if begin)) quasiquote #fn("n1700E62:" #(bq-process)) help #fn("n1700215285;3;042285235270024q5387;3>0487<B;350487863c07586<51486=3Q0262786=52478504883907850@30q@30q@30q4883e086=360q@;07850478504752951478504262:0>1885247850@30q486;J50488360q@>0752;0524785047<60:" #(getprop
*doc* #fn(str-split) "\n" *funvars* princ #fn(for-each)
@@ -51,7 +53,7 @@
"invalid slot name: " #fn(list*) #fn(sym) #\:))) tokw)
#fn(str?) #fn(length) #fn(map) #fn("n10B3500<:0:" #())
#fn(sym) #\? "make-" #fn(str) "-" #fn(nconc) begin def s and or not quote eq? aref = length when
-510M24e4e4e4:" #(list-ref
+1:" #(member
"n1200Ke3:" #(aref)) with-output-to #fn("z12021e1220e2e1e12315163:" #(#fn(nconc)
with-bindings *io-out* #fn(copy-list))) catch #fn("n22012122e123242522e2262722e22829e2e3262:22e20e3e42;22e22<22e2e4e3e3:" #(trycatch
λ #:g373 if and cons? eq? car quote thrown-value cadr caddr raise)) let* #fn("z10H3E02021e1qe12215153e1:2021e173051e1e1220=B3H02024e10=e12215153e1@301515375051e2:" #(#fn(nconc)
@@ -60,7 +62,7 @@
5153e2:" #(not #fn(nconc) = #fn(copy-list))) bcode:sp #fn("n1200r4e3:" #(aref)) bcode:stack #fn("n2200r421220e21e3e4:" #(aset!
+ bcode:sp)) assert #fn("n1200D2122230e2e2e2e4:" #(if raise quote assert-failed)) case #fn("z1Ib6208621_514225023870e2e12425e126278687>215252e3:" #(#0#
#fn("n2120C5020:1J40q:1R3=021072151e3:1H3=023072151e3:1=J>0230721<51e3:74751523=0260271e2e3:280271e2e3:" #(else
-R3=021072151e3:1H3=023072151e3:1=J>0230721<51e3:74751523=0260271e2e3:280271e2e3:" #(else
+e12215153e1:2021e173051e1e1220=B3H02024e10=e12215153e1@301515375051e2:" #(#fn(nconc)
alue eqv? every sym? memq quote memv) vals->cond)
#fn(gensym) let #fn(nconc) cond #fn(map) #fn("n1A<F0<520=P:" #()))) receive #fn("z22021q1e32221e10e123825153e3:" #(call-with-values
λ #fn(nconc) #fn(copy-list))) unwind-protect #fn("n2202122q1e3e2e1232402225e121e12625e2e4e321e1e3e3:" #(let
@@ -437,7 +439,7 @@
n12021q063:" #(#fn(table-foldl)
#fn("n3182P:" #())) table-values)
to-proper #fn("n10J400:0H3600e1:0<700=51P:" #(to-proper) to-proper)
- #fn("n0Aw0:" #(*io-out*))
+ #fn("n12021q063:" #(#fn(table-foldl)
#fn("n070A51471225061:" #(print-exception
print-stack-trace #fn(stacktrace))) #fn("n1A50420061:" #(#fn(raise)))) top-level-exception-handler)
trace #fn("n120051718551Jc02207324252627280e225e3e229e12:2885e225e3e55152@30q^147;60:" #(#fn(top-level-value)
--- a/src/system.lsp
+++ b/src/system.lsp
@@ -22,9 +22,12 @@
(unless (bound? '*syntax-environment*)
(def *syntax-environment* (table)))
-(def (set-syntax! s v) (put! *syntax-environment* s v))
-(def (get-syntax s) (get *syntax-environment* s nil))
+(def (set-syntax! s v)
+ (put! *syntax-environment* s v))
+(def (get-syntax s)
+ (get *syntax-environment* s nil))
+
(defmacro (defmacro form . body)
(let ((doc (value-get-doc body)))
(when doc
@@ -104,6 +107,7 @@
(def *properties* (table)))
(def (putprop symbol key val)
+ "Associate a property value with a symbol."
(let ((kt (get *properties* key nil)))
(unless kt
(let ((ta (table)))
@@ -113,10 +117,12 @@
val))
(def (getprop symbol key (def nil))
+ "Get a property value associated with a symbol or `def` if missing."
(let ((kt (get *properties* key nil)))
(or (and kt (get kt symbol def)) def)))
(def (remprop symbol key)
+ "Remove a property value associated with a symbol."
(let ((kt (get *properties* key nil)))
(and kt (has? kt symbol) (del! kt symbol))))
@@ -162,12 +168,14 @@
[fvs (and funvars (cons? (car funvars)) funvars)]}
(when lines
(princ (car lines))
- (when (cdr lines)
- (for-each (λ (line) (newline) (princ line))
- (cdr lines))
- (newline)
- (when fvs
- (newline))))
+ (if (cdr lines)
+ (begin (for-each (λ (line) (newline) (princ line))
+ (cdr lines))
+ (newline)
+ (when fvs
+ (newline))))
+ (unless fvs
+ (newline)))
(when fvs
(unless (cdr lines)
(newline)
@@ -192,6 +200,7 @@
(def (member item lst)
(cond ((equal? (car lst) item) lst)
(lst (member item (cdr lst)))))
+
(def (memv item lst)
(cond ((eqv? (car lst) item) lst)
(lst (memv item (cdr lst)))))
@@ -199,6 +208,7 @@
(def (assoc item lst)
(cond ((equal? (caar lst) item) (car lst))
(lst (assoc item (cdr lst)))))
+
(def (assv item lst)
(cond ((eqv? (caar lst) item) (car lst))
(lst (assv item (cdr lst)))))
@@ -921,17 +931,33 @@
. slots)
"Defines a structure type with a specific name and slots.
- The default underlying type is a \"named\" `vector`, where the
- first element is the name of the structure's type, the rest are the
- slot values. If the name as the first element isn't required,
- `:named NIL` should be used. A `list` can be used instead of a
- `vector` by adding `:type list` option.
+ The default underlying type is a \"named\" vector (`:type vec`),
+ where the first element is the name of the structure's type, the
+ rest are the slot values. If the name as the first element isn't
+ required, `:named NIL` should be used. A list can be used instead
+ of a vector by adding `:type list` option.
+ An example of a default constructor signature, based on structure
+ definition:
+
+ (defstruct blah a b c) →
+ (make-blah (:a NIL) (:b NIL) (:c NIL))
+
+ It can be customized in several ways. For example:
+
+ ; disable the constructor altogether
+ (defstruct blah :constructor NIL a b c)
+ ; only change its name
+ (defstruct blah :constructor blargh a b c)
+ ; rename AND avoid using keywords
+ (defstruct blah :constructor (blah a b c) a b c)
+
The option `:conc-name` specifies the slot accessor prefix, which
- defaults to `<name>-`.
+ defaults to `name-`.
- Default predicate name (`<name>?`) can be changed:
+ Default predicate name (`name?`) can be changed:
+ ; use \"blargh?\" instead of \"blah?\"
(defstruct blah :predicate blargh? a b c)"
(def (slot-opts slot)
; check whether slot options, if any, are valid