(defmacro (defdoc term . doc) «Define documentation for a top level term. If `term` is a function signature and `doc` is not specified, just the signature will be included in the documentation, without replacing any previously defined. First `doc` argument is supposed to be a string with the description of the term. The following arguments are expected to be optional tag pairings that provide grouping for multiple symbols and "see also" references. Useful in cases where setting the documentation for a term can't (or not preferred to) be done during the definition of said term. One of those reasons could be that the term is a built-in function implemented in C. Examples: (defdoc (func arg (arg2 0)) "Return something about the `arg` and `arg2`. This is a short description. This is the longer description, following the short one. Examples: (func 0) ; ↳ T (func 1 3) ; ↳ NIL" :doc-group stuff :doc-see func2) (defdoc (func arg (:another-variant NIL)))» :doc-group doc (let* {[call (cons? term)] [sym (or (and call (car term)) term)] [callvars (and call (cdr term))] [doc (car (separate-doc-from-body (append doc '(NIL))))]} (if call `(sym-set-doc ',sym ',doc ',callvars) `(sym-set-doc ',sym ',doc)))) (defmacro (doc-group group-name doc) "Define documentation for a group." :doc-group doc `(begin (sym-set-doc (list 'doc 'group ',group-name) ,doc))) (doc-group doc "Writing and reading documentation.") (doc-group prop "Dealing with properties of symbols.") (doc-group compress "Compression.") (defdoc (lz-pack data (level 0)) "Return data compressed using Lempel-Ziv. The data must be an array, returned value will have the same type. The optional `level` is between `0` and `10`. With `level` set to `0` a simple LZSS using hashing will be performed. Levels between `1` and `9` offer a trade-off between time/space and ratio. Level `10` is optimal but very slow." :doc-group compress) (defdoc (lz-unpack data :to destination))(defdoc (lz-unpack data :size decompressed-bytes) "Return decompressed data previously compressed using lz-pack. Either destination for the decompressed data or the expected size of the decompressed data must be specified. In the latter case a new array is allocated." :doc-group compress) (doc-group rand "Random numbers generation.") (defdoc (rand) "Return a random non-negative fixnum on its maximum range." :doc-group rand) (defdoc (rand-u64) "Return a random integer on interval [0, 2⁶⁴-1]." :doc-group rand) (defdoc (rand-u32) "Return a random integer on interval [0, 2³²-1]." :doc-group rand) (defdoc (rand-f64) "Return a random 64-bit floating point number on interval [0.0, 1.0]." :doc-group rand) (defdoc (rand-f32) "Return a random 32-bit floating pointer number on [0.0, 1.0] interval." :doc-group rand) (doc-group sys "OS-specific functions.") (defdoc +endianness+ "Endianess of the CPU the VM is running on, a constant. Set to either `:big-endian` or `:little-endian`." :doc-group sys) (defdoc *directory-separator* «OS-specific path separator. It is preferred over hardcoded `"/"`, for portability.» :doc-group sys :doc-see *linefeed*) (defdoc *linefeed* «OS-specific _line_ _feed_ value. It is preferred over hardcoded `"\n"`, for portability.» :doc-group sys :doc-see newline :doc-see *directory-separator*) (defdoc +os-name+ «The name of the operating system this StreetLISP VM executable was built for. It's set to a lowercase string and its value is considered "best effort" - it might not always be accurate. Possible values: `"unknown"`, `"plan9"`, `"linux"`, `"openbsd"`, `"netbsd"`, `"dragonflybsd"`, `"freebsd"`, `"haiku"`, `"macosx"`, `"macos"`, `"dos"`.» :doc-group sys :doc-see +os-version+) (defdoc +os-version+ «The "version" of the operating system this StreetLISP VM executable was built for. The availability of the constant and its value depends on the operating system and is only provided for the user to see. No logic should depend on it. Examples: +os-version+ ; ↳ "6.14.5-0-edge" ; Alpine Linux kernel version» :doc-group sys :doc-see +os-name+) (defdoc (os-getenv name) "Return the value of the environment variable `name` or `NIL` if it's not set." :doc-group sys :doc-see os-setenv) (defdoc (os-setenv name value) "Add or replace the value of the environment variable `name` to `value`. If `value` is `NIL`, the variable is deleted from the environment if it exists." :doc-group sys :doc-see os-getenv) (defdoc (exit (status NIL)) «Terminate the process with the specified status. Does not return. The status is expected to be a string in case of an error. Examples: (exit) ; exit with status 0 (nil on Plan 9) (exit "error") ; exit with status 1 ("error" on Plan 9)» :doc-group sys) (defdoc (getpid) "Return the process ID of the StreetLISP VM within the operating system it's running on." :doc-group sys) (doc-group io "Files and I/O functionality.") (defdoc (delete-file path) "Delete the file from the filesystem. Throws an IO error if file does not exist or it failed to be deleted." :doc-group io :doc-see file :doc-see path-exists?) (defdoc (path-exists? path) "Return `T` if `path` exists on the filesystem, `NIL` otherwise." :doc-group io :doc-see file :doc-see delete-file) (defdoc (path-cwd (to NIL)) "Return the full path to the current directory of the process, or change it to the path specified with `to` argument." :doc-group io :doc-see path-exists?) (defdoc (file path (mode #o644) (:read NIL) (:write NIL) (:create NIL) (:truncate NIL) (:append NIL)) "Open a file for I/O. An `io` object is returned. Without any modes specified the file must already exist and is opened in read-only mode. Files are created with the default mode bits #o644." :doc-group io) (defdoc (io? term) "Return `T` if `term` is of `io` type, `NIL` otherwise." :doc-group io :doc-group type) (defdoc (io->str io) "Return the data of the in-memory `io` buffer as a string." :doc-group io) (defdoc (io-eof? io) «Return `T` if `io` is currently in the "end of file" state, `NIL` otherwise.» :doc-group io) (defdoc (eof-object? v) "Return `T` if the argument is `#<eof>`, `NIL` otherwise. This object is returned by I/O functions to signal end of file, where applicable." :doc-group io :doc-group type) (defdoc (buffer) "Return an in-memory buffer for I/O, of `io` type. A buffer can be used for both reading and writing at the same time." :doc-group io) (defdoc (assq key lst) "Return a pair of a matching key and the associated value, or `NIL` if none matched. Keys are compared using `eq?`." :doc-group list :doc-see assoc :doc-see assv) (defdoc (memq item lst) "Return the tail of a list beginning with the item, or `NIL` otherwise. List elements are compared to the `item` using `eq?`." :doc-group list :doc-see member :doc-see memv) (defdoc NIL "An empty list. Can be used as the opposite of T in boolean expressions. Examples: (not NIL) ; ↳ T (if NIL 'yes 'no) ; ↳ no (car NIL) ; ↳ NIL (cdr NIL) ; ↳ NIL" :doc-see T) (defdoc T «A boolean "true". Examples: (not T) ; ↳ NIL (if T 'yes 'no) ; ↳ yes» :doc-see NIL) (doc-group string "Strings and runes.") (defdoc (str . terms) «Return concatenation of terms formatted as strings. This is equivalent to `(princ terms…)`, except the string is _returned_, rather than printed. Examples: (str "a" 'b 1 #(0)) ; ↳ "ab1#(0)"» :doc-group string) (defdoc (str-rune s n) «Return the nth rune of the string. Throws an exception if the index `n` is out of bounds. Examples: (str-rune "йцукен" 3) ; ↳ #\к» :doc-group string :doc-see str-sub) (defdoc (str-sub s start (end NIL)) «Return the portion of the string within the specified bounds. The `start` and `end` index by rune. Specifying any index out of bounds of the string will result in an exception thrown. If `end` isn't specified the portion is assumed to begin at `start` until the end of the original string. Examples: (str-sub "hello" 2) ; ↳ "llo" (str-sub "hello" 3 3) ; ↳ "" (str-sub "hello" 2 4) ; ↳ "ll"» :doc-group string :doc-see str-rune) (defdoc (str-utf8? s) «Return `T` if `s` is a valid UTF-8 string, `NIL` otherwise. Examples: (str-utf8? "привет") ; ↳ T (str-utf8? "при\xffвет") ; ↳ NIL» :doc-group string :doc-see str?) (defdoc (str->num s (base NIL)) «Return the number using the radix `base` in the string `s`. Returns `NIL` if the number could not be parsed or there were left-over trailing characters. Examples: (str->num "1.2") ; ↳ 1.2 (str->num "#x123") ; ↳ 291 (str->num "ffff" 16) ; ↳ 65535 (str->num "777" 8) ; ↳ 511» :doc-group string :doc-see num->str) (defdoc (sym term . rest) «Return a symbol with the name being the concatenation of terms formatted as strings. This is equivalent to `(sym (str …))`. Examples: (sym "a" 'b 1) ; ↳ ab1» :doc-group misc :doc-see sym?) (doc-group struct "Declaring and manipulating structures.") (defdoc (defstruct name docs… options… (slot-1 DEFAULT) slot-2 slot-3)) ',sym ',doc ',callvars (defdoc (defstruct name (:type vec) (:named T named-supplied) (:constructor T constructor-supplied) (:conc-name T conc-name-supplied) (:predicate T predicate-supplied) . slots) «Declare a new structure type with the specified name and slots. 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 keyworded slot values. A list with slot values alone can be used instead by adding `:type list` option. The list will not contain the name of the struct by default, which can be enabled with `:named T` option. As an example, the following declaration generates the default constructor for a structure of three slots, with one of them (`c`) having a non-`NIL` default value and marked as read-only: (defstruct blah "Return stuff." :doc-group stuff a b (c 1 :read-only T)) ; (make-blah (:a NIL) (:b NIL) (:c 1)) ; (blah-a s) ; (blah-b s) ; (blah-c s) ; (blah-a! s new-a) ; (blah-b! s new-b) Slot's options, if any, should be specified after its default value. Supported options are: ; mark the slot as read-only ; its value can be read, but trying to modify it will throw an error … :read-only T The constructor can be changed in several ways: ; 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/setter prefix, which defaults to `structname-`. Prefix can be disabled entirely with `:conc-name NIL`. Slot setters are generated for writable slots by appending `!` (exclamation mark) to the accessor's name. Default predicate can be disabled or its name, which defaults to `structname?`, changed: ; use "blargh?" instead of "blah?" (defstruct blah :predicate blargh? a b c) ; without predicate (defstruct blah :predicate NIL a b c)» :doc-group struct) (defdoc (const? term) "Return `T` if the term refers to a constant, `NIL` otherwise. Constants cannot be modified with `set!`. Trying to do so will result in an exception. Examples: (const? 12345) ; a number ; ↳ T (const? 'const?) ; a function ; ↳ NIL (const? 'pi) ; a mathematical constant ; ↳ T" :doc-group type) (defdoc (bignum? v) "Return `T` if the argument is a bignum, `NIL` otherwise." :doc-group type :doc-group number :doc-see bignum) (defdoc (int? v) "Return `T` if the argument is an integer, `NIL` otherwise." :doc-group type :doc-group number) (defdoc (str? v) "Return `T` if the argument is a string, `NIL` otherwise." :doc-group type :doc-see str :doc-see str-utf8?) (defdoc (gensym? v) "Return `T` if the argument is a gensym, `NIL` otherwise." :doc-group typeLines 1–500 of 1521. Load more
(defmacro (defdoc term . doc) «Define documentation for a top level term. If `term` is a function signature and `doc` is not specified, just the signature will be included in the documentation, without replacing any previously defined. First `doc` argument is supposed to be a string with the description of the term. The following arguments are expected to be optional tag pairings that provide grouping for multiple symbols and "see also" references. Useful in cases where setting the documentation for a term can't (or not preferred to) be done during the definition of said term. One of those reasons could be that the term is a built-in function implemented in C. Examples: (defdoc (func arg (arg2 0)) "Return something about the `arg` and `arg2`. This is a short description. This is the longer description, following the short one. Examples: (func 0) ; ↳ T (func 1 3) ; ↳ NIL" :doc-group stuff :doc-see func2) (defdoc (func arg (:another-variant NIL)))» :doc-group doc (let* {[call (cons? term)] [sym (or (and call (car term)) term)] [callvars (and call (cdr term))] [doc (car (separate-doc-from-body (append doc '(NIL))))]} (if call `(sym-set-doc ',sym ',doc ',callvars) `(sym-set-doc ',sym ',doc)))) (defmacro (doc-group group-name doc) "Define documentation for a group." :doc-group doc `(begin (sym-set-doc (list 'doc 'group ',group-name) ,doc))) (doc-group doc "Writing and reading documentation.") (doc-group prop "Dealing with properties of symbols.") (doc-group compress "Compression.") (defdoc (lz-pack data (level 0)) "Return data compressed using Lempel-Ziv. The data must be an array, returned value will have the same type. The optional `level` is between `0` and `10`. With `level` set to `0` a simple LZSS using hashing will be performed. Levels between `1` and `9` offer a trade-off between time/space and ratio. Level `10` is optimal but very slow." :doc-group compress) (defdoc (lz-unpack data :to destination)) (defdoc (lz-unpack data :size decompressed-bytes) "Return decompressed data previously compressed using lz-pack. Either destination for the decompressed data or the expected size of the decompressed data must be specified. In the latter case a new array is allocated." :doc-group compress) (doc-group rand "Random numbers generation.") (defdoc (rand) "Return a random non-negative fixnum on its maximum range." :doc-group rand) (defdoc (rand-u64) "Return a random integer on interval [0, 2⁶⁴-1]." :doc-group rand) (defdoc (rand-u32) "Return a random integer on interval [0, 2³²-1]." :doc-group rand) (defdoc (rand-f64) "Return a random 64-bit floating point number on interval [0.0, 1.0]." :doc-group rand) (defdoc (rand-f32) "Return a random 32-bit floating pointer number on [0.0, 1.0] interval." :doc-group rand) (doc-group sys "OS-specific functions.") (defdoc +endianness+ "Endianess of the CPU the VM is running on, a constant. Set to either `:big-endian` or `:little-endian`." :doc-group sys) (defdoc *directory-separator* «OS-specific path separator. It is preferred over hardcoded `"/"`, for portability.» :doc-group sys :doc-see *linefeed*) (defdoc *linefeed* «OS-specific _line_ _feed_ value. It is preferred over hardcoded `"\n"`, for portability.» :doc-group sys :doc-see newline :doc-see *directory-separator*) (defdoc +os-name+ «The name of the operating system this StreetLISP VM executable was built for. It's set to a lowercase string and its value is considered "best effort" - it might not always be accurate. Possible values: `"unknown"`, `"plan9"`, `"linux"`, `"openbsd"`, `"netbsd"`, `"dragonflybsd"`, `"freebsd"`, `"haiku"`, `"macosx"`, `"macos"`, `"dos"`.» :doc-group sys :doc-see +os-version+) (defdoc +os-version+ «The "version" of the operating system this StreetLISP VM executable was built for. The availability of the constant and its value depends on the operating system and is only provided for the user to see. No logic should depend on it. Examples: +os-version+ ; ↳ "6.14.5-0-edge" ; Alpine Linux kernel version» :doc-group sys :doc-see +os-name+) (defdoc (os-getenv name) "Return the value of the environment variable `name` or `NIL` if it's not set." :doc-group sys :doc-see os-setenv) (defdoc (os-setenv name value) "Add or replace the value of the environment variable `name` to `value`. If `value` is `NIL`, the variable is deleted from the environment if it exists." :doc-group sys :doc-see os-getenv) (defdoc (exit (status NIL)) «Terminate the process with the specified status. Does not return. The status is expected to be a string in case of an error. Examples: (exit) ; exit with status 0 (nil on Plan 9) (exit "error") ; exit with status 1 ("error" on Plan 9)» :doc-group sys) (defdoc (getpid) "Return the process ID of the StreetLISP VM within the operating system it's running on." :doc-group sys) (doc-group io "Files and I/O functionality.") (defdoc (delete-file path) "Delete the file from the filesystem. Throws an IO error if file does not exist or it failed to be deleted." :doc-group io :doc-see file :doc-see path-exists?) (defdoc (path-exists? path) "Return `T` if `path` exists on the filesystem, `NIL` otherwise." :doc-group io :doc-see file :doc-see delete-file) (defdoc (path-cwd (to NIL)) "Return the full path to the current directory of the process, or change it to the path specified with `to` argument." :doc-group io :doc-see path-exists?) (defdoc (file path (mode #o644) (:read NIL) (:write NIL) (:create NIL) (:truncate NIL) (:append NIL)) "Open a file for I/O. An `io` object is returned. Without any modes specified the file must already exist and is opened in read-only mode. Files are created with the default mode bits #o644." :doc-group io) (defdoc (io? term) "Return `T` if `term` is of `io` type, `NIL` otherwise." :doc-group io :doc-group type) (defdoc (io->str io) "Return the data of the in-memory `io` buffer as a string." :doc-group io) (defdoc (io-eof? io) «Return `T` if `io` is currently in the "end of file" state, `NIL` otherwise.» :doc-group io) (defdoc (eof-object? v) "Return `T` if the argument is `#<eof>`, `NIL` otherwise. This object is returned by I/O functions to signal end of file, where applicable." :doc-group io :doc-group type) (defdoc (buffer) "Return an in-memory buffer for I/O, of `io` type. A buffer can be used for both reading and writing at the same time." :doc-group io) (defdoc (assq key lst) "Return a pair of a matching key and the associated value, or `NIL` if none matched. Keys are compared using `eq?`." :doc-group list :doc-see assoc :doc-see assv) (defdoc (memq item lst) "Return the tail of a list beginning with the item, or `NIL` otherwise. List elements are compared to the `item` using `eq?`." :doc-group list :doc-see member :doc-see memv) (defdoc NIL "An empty list. Can be used as the opposite of T in boolean expressions. Examples: (not NIL) ; ↳ T (if NIL 'yes 'no) ; ↳ no (car NIL) ; ↳ NIL (cdr NIL) ; ↳ NIL" :doc-see T) (defdoc T «A boolean "true". Examples: (not T) ; ↳ NIL (if T 'yes 'no) ; ↳ yes» :doc-see NIL) (doc-group string "Strings and runes.") (defdoc (str . terms) «Return concatenation of terms formatted as strings. This is equivalent to `(princ terms…)`, except the string is _returned_, rather than printed. Examples: (str "a" 'b 1 #(0)) ; ↳ "ab1#(0)"» :doc-group string) (defdoc (str-rune s n) «Return the nth rune of the string. Throws an exception if the index `n` is out of bounds. Examples: (str-rune "йцукен" 3) ; ↳ #\к» :doc-group string :doc-see str-sub) (defdoc (str-sub s start (end NIL)) «Return the portion of the string within the specified bounds. The `start` and `end` index by rune. Specifying any index out of bounds of the string will result in an exception thrown. If `end` isn't specified the portion is assumed to begin at `start` until the end of the original string. Examples: (str-sub "hello" 2) ; ↳ "llo" (str-sub "hello" 3 3) ; ↳ "" (str-sub "hello" 2 4) ; ↳ "ll"» :doc-group string :doc-see str-rune) (defdoc (str-utf8? s) «Return `T` if `s` is a valid UTF-8 string, `NIL` otherwise. Examples: (str-utf8? "привет") ; ↳ T (str-utf8? "при\xffвет") ; ↳ NIL» :doc-group string :doc-see str?) (defdoc (str->num s (base NIL)) «Return the number using the radix `base` in the string `s`. Returns `NIL` if the number could not be parsed or there were left-over trailing characters. Examples: (str->num "1.2") ; ↳ 1.2 (str->num "#x123") ; ↳ 291 (str->num "ffff" 16) ; ↳ 65535 (str->num "777" 8) ; ↳ 511» :doc-group string :doc-see num->str) (defdoc (sym term . rest) «Return a symbol with the name being the concatenation of terms formatted as strings. This is equivalent to `(sym (str …))`. Examples: (sym "a" 'b 1) ; ↳ ab1» :doc-group misc :doc-see sym?) (doc-group struct "Declaring and manipulating structures.") (defdoc (defstruct name docs… options… (slot-1 DEFAULT) slot-2 slot-3)) ',sym ',doc ',callvars (defdoc (defstruct name (:type vec) (:named T named-supplied) (:constructor T constructor-supplied) (:conc-name T conc-name-supplied) (:predicate T predicate-supplied) . slots) «Declare a new structure type with the specified name and slots. 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 keyworded slot values. A list with slot values alone can be used instead by adding `:type list` option. The list will not contain the name of the struct by default, which can be enabled with `:named T` option. As an example, the following declaration generates the default constructor for a structure of three slots, with one of them (`c`) having a non-`NIL` default value and marked as read-only: (defstruct blah "Return stuff." :doc-group stuff a b (c 1 :read-only T)) ; (make-blah (:a NIL) (:b NIL) (:c 1)) ; (blah-a s) ; (blah-b s) ; (blah-c s) ; (blah-a! s new-a) ; (blah-b! s new-b) Slot's options, if any, should be specified after its default value. Supported options are: ; mark the slot as read-only ; its value can be read, but trying to modify it will throw an error … :read-only T The constructor can be changed in several ways: ; 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/setter prefix, which defaults to `structname-`. Prefix can be disabled entirely with `:conc-name NIL`. Slot setters are generated for writable slots by appending `!` (exclamation mark) to the accessor's name. Default predicate can be disabled or its name, which defaults to `structname?`, changed: ; use "blargh?" instead of "blah?" (defstruct blah :predicate blargh? a b c) ; without predicate (defstruct blah :predicate NIL a b c)» :doc-group struct) (defdoc (const? term) "Return `T` if the term refers to a constant, `NIL` otherwise. Constants cannot be modified with `set!`. Trying to do so will result in an exception. Examples: (const? 12345) ; a number ; ↳ T (const? 'const?) ; a function ; ↳ NIL (const? 'pi) ; a mathematical constant ; ↳ T" :doc-group type) (defdoc (bignum? v) "Return `T` if the argument is a bignum, `NIL` otherwise." :doc-group type :doc-group number :doc-see bignum) (defdoc (int? v) "Return `T` if the argument is an integer, `NIL` otherwise." :doc-group type :doc-group number) (defdoc (str? v) "Return `T` if the argument is a string, `NIL` otherwise." :doc-group type :doc-see str :doc-see str-utf8?) (defdoc (gensym? v) "Return `T` if the argument is a gensym, `NIL` otherwise." :doc-group type