History

if: make the else a list of forms with implicit begin

Sigrid Solveig Haflínudóttir committed 1 year ago

Commit 235b9081 parent 69965463 files · +128 −129Browse files

Unified · Split

3 files
  1. boot/sl.boot +12 −11
  2. src/compiler.sl +88 −91
  3. src/system.sl +28 −27
boot/sl.boot+12−11
@@ -27,7 +27,7 @@ doc)) cdaaar ((lst)) bounds-error ((seq index . msg)) even? ((n)) zero? ((n) · 26 unmodified lines
2727 new-name)) random ((max)) reverse! ((lst)) eval ((x)) cdaadr ((lst)) u32 (((n 0))) cons ((first
2828 second)) filter ((pred lst)) assq ((key lst)) del! ((table key)) when ((cond . body)) vec? ((v)) min ((v . rest)) cddaar ((lst)) num->str ((n
2929 (:base 10))) io? ((term)) eof-object? ((v)) help ((topic (:print-header help-print-header) . rest)) mod ((a
30−n)) if ((cond then else)) p32 (((n 0))) io-read-lines ((io)) io-line ((io)) sym-set-doc ((symbol
30+n)) if ((cond then . else)) p32 (((n 0))) io-read-lines ((io)) io-line ((io)) sym-set-doc ((symbol
3131 doc-seq . formals-list)) macrocall? ((e)) trycatch ((try catch)) iterate ((fn zero n)) table-values ((ta)) macroexpand ((e)) caadr ((lst)) type-of ((v)) top-level-value ((sym)) defstruct ((name
3232 docs… options… (slot-1 DEFAULT) slot-2 slot-3)
3333 (name (:type vec) (:named T) (:constructor T) (:conc-name T) (:predicate T) . slots)) caadar ((lst)) foldl1 ((fn
@@ -73,8 +73,8 @@ sigs (:kind NIL) (:lpad ""))) sleep ((sec)) s16 (((n 0))) rune? ((v)) os-set · 39 unmodified lines
7373 group error) "Errors and exception handling." io-eof? "Return `T` if `io` is currently in the \"end of file\" state, `NIL`\notherwise." path-exists? "Return `T` if `path` exists on the filesystem, `NIL` otherwise." cadddr "Shorthand for (car (cdr (cdr (cdr lst))))." (doc
7474 group string) "Strings and runes." sort "Return a copy of the list sorted by comparing elements with the\ntwo-argument function `less-than?`.\n\nAn optional keyworded argument `:key` is used to provide a function to\nretrieve terms (the _key_) from the list items in order to perform\ncomparison. By default the terms compared are the list elements\nthemselves.\n\nExamples:\n\n ; simple sort (note: symbols > numbers)\n (sort '(1a 1 0 2b e 3) <)\n ; ↳ (0 1 3 1a 2b e)\n\n ; sort in lexicographical order (as strings)\n (sort '(1a 1 0 2b e 3) < :key str)\n ; ↳ (0 1 1a 2b 3 e)\n\n ; sort by type (note how the numbers stayed in the same order)\n (sort '(3 \"a\" 1 a #\\a 2)\n (λ (a b) (< (type-of a) (type-of b))))\n ; ↳ (3 1 2 #\\a \"a\" a)" fixnum? "Return `T` if `v` is of a fixnum type, `NIL` otherwise." exit "Terminate the process with the specified status. Does not return.\nThe status is expected to be a string in case of an error.\n\nExamples:\n\n (exit) ; exit with status 0 (nil on Plan 9)\n (exit \"error\") ; exit with status 1 (\"error\" on Plan 9)" __finish "A function called right before exit by the VM.\n\nThe exit `status` is either `NIL` or a string referring to an error\ncondition." caaar "Shorthand for (car (car (car lst)))." s32 "Construct a 32-bit signed number." u8 "Construct a 8-bit unsigned number." any "Return `T` if the predicate is true for _any_ element of the list,\n`NIL` otherwise.\n\nExample:\n\n ; is there any even number?\n (any even? '(1 3 5 7))\n ; ↳ NIL\n\n ; is there any string longer than one rune?\n (any (λ (s) (length> s 1))\n '(\"ab\" \"cd\" \"e\"))\n ; ↳ T" nthcdr "Return the reminder of the list after at most `n` elements, or `NIL`\nif the list is shorter.\n\nExamples:\n\n (def l '(a b c))\n (nthcdr l 1)\n ; ↳ (b c)\n (nthcdr l 2)\n ; ↳ (c)\n (nthcdr l 10)\n ; ↳ NIL" os-getenv "Return the value of the environment variable `name` or `NIL` if it's\nnot set." s8 "Construct a 8-bit signed number." io-close "Close the IO object.\n\nNo further operations on the IO object are possible, those will throw\nan exception if attempted. The only exception is `(io-filename io)`,\nwhich might be useful in some cases for debugging purposes.\n\nExamples:\n\n (def f (file \"/dev/random\"))\n (io-read f 'u8)\n ; ↳ #u8(123)\n (io-close f)\n (io-read f 'u8)\n ; ‼ I/O error: closed file" io-line! "Change the current line number of the IO object." num? "Return `T` if `v` is of a numerical type, `NIL` otherwise.\n\nNumerical types include floating point, fixnum, bignum, etc.\nNote: ironically, a NaN value is considered a number by this function\nsince it's only testing the _type_ of the value." assert "Throw an exception if `expr` evaluates to `NIL`. Return `T` in any\nother case.\n\nExamples:\n\n (def s \"abc\")\n (assert (= (length s) 3))\n ; ↳ T\n (assert (eq? (str-rune s 0) #\\x))\n ; ‼ assertion failed: ..." vec->list "Return the vector converted to a list.\n\nExamples:\n\n (vec->list #(1 2 a))\n ; ↳ (1 2 a)" 1+ "Equivalent to `(+ n 1)` - increment by one." throw "Raise an exception consisting of a tag and a value.\n\nThis exception can be caught by `catch`." positive? "Return `T` if `n` is greater than zero. Shorthand for `(> n 0)`." atan "Return the arc tangent of `y/x` in radians." *builtins* "VM instructions as closures." remprop "Remove a property value associated with the symbol." io-copy-until "Copy bytes from the source IO object to the destination until\nencountering the delimiting rune `r` and return the number of bytes\ncopied. The copied bytes include the delimiter." (doc
7575 group list) "Working with lists." delete-file "Delete the file from the filesystem.\n\nThrows an IO error if file does not exist or it failed to be deleted." (doc
76−group compare) "Comparison operators." cdddar "Shorthand for (cdr (cdr (cdr (car lst))))." set-cdr! "Modify a cons cell (a list) in-place by putting `new-second` as its\nsecond element (tail of the list). Return the modified cons\ncell (list).\n\nExamples:\n\n (def q '(1 2 3 4 5))\n (set-cdr! q '(6 7))\n ; ↳ (1 6 7)\n q\n ; ↳ (1 6 7)" stacktrace "Return the current stack trace." eq? "Return `T` if `a` and `b` are the same object, `NIL` otherwise.\n\nExamples:\n\n (eq? 0.0 0)\n ; ↳ NIL\n\n (eq? 0 0)\n ; ↳ T\n\n (def a \"1\")\n (def b \"1\")\n (eq? a b)\n ; ↳ NIL\n\n (def a '(1))\n (def b '(1))\n (eq? a b)\n ; ↳ NIL" io->str "Return the data of the in-memory `io` buffer as a string." bound? "Return `T` if `sym` has a value associated with it, `NIL` otherwise.\n\nExamples:\n\n (bound? 'bound?)\n ; ↳ T\n\n (bound? 'doesnotcompute)\n ; ↳ NIL" list->vec "Return the list converted to a vector.\n\nExamples:\n\n (list->vec '(1 2 a))\n ; ↳ #(1 2 a)" odd? "Return `T` if `n` is an odd integer, `NIL` otherwise." def "Assign the function (first form) or the result of the expression\n(second form) to the identifier.\n\nDocumentation for the definition may also be supplied after `form` in\nthe same manner as with `defdoc`.\n\nFunction definitions themselves may contain other definitions internal\nto the function.\n\nExamples:\n\n ; a function with documentation (first form)\n (def (f x)\n \"Return the square of doubled `x`.\n\n Examples:\n\n (f 3)\n ; ↳ 36\"\n :doc-group cool-funcs ; documentation group for (help groups)\n :doc-see g ; reference another function in the documentation\n (def (g y) ; an internal function\n (+ y y))\n (* (g x) (g x)))\n (f 2)\n ; ↳ 16\n\n ; a variable (second form)\n (def x (length \"hello\"))\n x\n ; ↳ 5" list? "Return `T` if the value is either `NIL` or a cons cell, `NIL`\notherwise." *os-version* "The \"version\" of the operating system this StreetLISP VM executable\nwas built for.\n\nThe availability of the constant and its value depends on the\noperating system and is only provided for the user to see. No logic\nshould depend on it.\n\nExamples:\n\n *os-version*\n ; ↳ \"6.14.5-0-edge\" ; Alpine Linux kernel version" str-rep "Return the concatenation of the term formatted as a string, repeated\n`k` times.\n\nExamples:\n\n (str-rep \"oi\" 3)\n ; ↳ \"oioioi\"\n\n (str-rep #\\ы 5)\n ; ↳ \"ыыыыы\"\n\n (str-rep 'a 3)\n ; ↳ \"aaa\"\n\n (str-rep 1 5)\n ; ↳ \"11111\"" time "Display the elapsed time of evaluating `expr` to `*io-out*`, return\nthe result of the evaluated expression.\n\nExamples:\n\n (time (begin (sleep 0.1) 12345))\n ; ‼ Elapsed time: 0.10013356 seconds\n ; ↳ 12345" size-of "Return the size of the value in bytes, if applicable.\n\nWorks only with C integer types, arrays, strings and in-memory\nbuffers.\n\nExamples:\n\n (size-of \"hello\")\n ; ↳ 5\n\n (size-of (arr 'u32 1 2 3))\n ; ↳ 12\n\n (def b (buffer))\n (io-write b \"hello\")\n (size-of b)\n ; ↳ 5" sym "Return a symbol with the name being the concatenation of terms\nformatted as strings.\n\nThis is equivalent to `(sym (str …))`.\n\nExamples:\n\n (sym \"a\" 'b 1)\n ; ↳ ab1" tanh "Return the hyperbolic tangent of `x`." for "Call the function `f` with a single integer argument, starting from\n`min` and ending with `max`.\n\nExamples:\n\n (for 0 2 (λ (i) (print (- 2 i))))\n ; ‼ 210" begin "Evaluate the expressions in order and return the result of the last\nexpression.\n\nExamples:\n\n (if 1\n (begin (print 1)\n (newline)\n 'ignored\n 'done)\n (begin (print 0)\n (newline)\n 'else))\n ; ‼ 1\n ; ↳ done" const? "Return `T` if the term refers to a constant, `NIL` otherwise.\n\nConstants cannot be modified with `set!`. Trying to do so will result\nin an exception.\n\nExamples:\n\n (const? 12345) ; a number\n ; ↳ T\n\n (const? 'const?) ; a function\n ; ↳ NIL\n\n (const? 'pi) ; a mathematical constant\n ; ↳ T" str-trim "Return the portion of the string with all leading runes satisfying\n`lead-pred` (and trailing runes satisfying `trail-pred`) removed.\n\nWithout predicates explicitly specified, `str-trim` will remove\nwhitespace from both sides of the string.\n\nPass `NIL` as the predicate to disable trimming on either side.\n\nExamples:\n\n (str-trim \" \\nhello\\t\\v\")\n ; ↳ \"hello\"\n\n (str-trim \" \\nhello\\t\\v\"\n (λ (r) (str-find \" \\v\" r)))\n ; ↳ \"\\nhello\\t\"\n\n (str-trim \"123abc!456def\"\n rune-numeric?\n rune-alphabetic?)\n ; ↳ \"abc!456\"" io-pos! "Change the current absolute position within the IO object in bytes,\nreturn the resulting position.\n\nExamples:\n\n (def f (buffer))\n (io-write f \"hello, world!\")\n (io-pos! f 64)\n ; ↳ 13\n (io-pos! f 7)\n ; ↳ 7\n (read f)\n ; ↳ world!" return "Return from the function with the specified value as the result.\n\nExamples:\n\n (def (f x) (when (not x)\n (return 0))\n (princ \"hi\")\n (newline)\n 1)\n (f 'a)\n ; ‼ hi\n ; ↳ 1\n (f NIL)\n ; ↳ 0" *stderr* "Standard error output IO stream." tan "Return the tangent of `r`, where `r` is given in radians." table "Construct a table from keys from the arguments.\n\nEvery two arguments are expected to be a key and a value associated\nwith that key.\n\nExamples:\n\n (table)\n ; ↳ #table()\n\n (table 'a 1 'b 2)\n ; ↳ #table(a 1 b 2)" __rcscript "Execute, if exists, the user's \"run commands\" file.\n\nThe file path is predefined and depends on the OS:\n\n * `$home/lib/slrc` on Plan 9\n * `$HOME/.slrc` on other operating systems\n\nIt is automatically loaded by StreetLISP when running in interactive\nmode. The user may wish to use this file to change the look of the\nprompt, load additional functionality they want to use without having\nto do the process manually each time, and so on." doc-group "Define documentation for a group." cdaaar "Shorthand for (cdr (car (car (car lst))))." bounds-error "Raise a bounds error exception." even? "Return `T` if `n` is an even integer, `NIL` otherwise." *properties* "All properties of symbols recorded with `putprop` are recorded in this\ntable." zero? "Return `T` if `n` is zero. Shorthand for `(= n 0)`." proper-list? "Return `T` is the value is a proper list. That is, a non-circular\nlist with the last element being `NIL`, as opposed to a dotted list.\n\nExamples:\n\n ; empty list\n (proper-list? NIL)\n ; ↳ T\n\n ; a list with one element\n (proper-list? '(1))\n ; ↳ T\n\n ; a pair, cdr of the cell is 2\n (proper-list? '(1 . 2))\n ; ↳ NIL\n\n ; on a circular list\n (def l '(1))\n (set-cdr! l l)\n ; ↳ #0=(1 . #0#)\n (length l)\n ; ↳ +inf.0\n (proper-list? l)\n ; ↳ NIL" io-filename! "Change the filename of the IO object, return the new filename.\n\nChanging the filename does not cause any side effects. The filename\nis purely informative and does not necessarily reflect the actual\npath.\n\nExamples:\n\n (def f (buffer))\n (io-filename b)\n ; ↳ \"\"\n (io-filename! b \"new name\") ; change the filename\n ; ↳ \"new name\"\n (io-filename b)\n ; ↳ \"new name\"" random "Return a random number in the range `[0, max]` (inclusive).\n\nThe result is either an integer or a floating point number, depending\non the type of the `max` argument.\n\nExamples:\n\n (random 1)\n ; ↳ 1\n\n (random 1.0)\n ; ↳ 0.69517" *directory-separator* "OS-specific path separator.\n\nIt is preferred over hardcoded `\"/\"`, for portability." reverse! "Return the list with its elements in reverse order.\n\nThe original list may be modified by this function since it's a\ndestructive operation.\n\nExamples:\n\n (def a '(1 2 3))\n (reverse! a)\n ; ↳ (3 2 1)\n a\n ; ↳ (1) ; original list has been modified in-place" eval "Evaluate expression.\n\nExamples:\n\n (eval '(begin (set! x 1 y 2) (+ x y)))\n ; ↳ 3\n x\n ; ↳ 1\n y\n ; ↳ 2" cdaadr "Shorthand for (cdr (car (car (cdr lst))))." u32 "Construct a 32-bit unsigned number." cons "Return a cons cell containing two arguments.\n\nExamples:\n\n (cons 1 2)\n ; ↳ (1 . 2)\n\n (cons 1 '(2))\n ; ↳ (1 2)\n\n (cons 1 (cons 2 (cons 3 NIL)))\n ; ↳ (1 2 3)" filter "Return a copy of the list with only the elements of the original\nthat satisfy the predicate.\n\nExamples:\n\n (filter odd? '(0 1 2 3 4))\n ; ↳ (1 3)" assq "Return a pair of a matching key and the associated value, or `NIL` if\nnone matched. Keys are compared using `eq?`." most-positive-fixnum "A constant integer closest to positive infinity that can be\nrepresented by fixnum type on this particular platform." del! "Remove any existing mapping for `key` and return the table.\n\nExamples:\n\n (def t #table(a 1 b 2))\n (del! t 'c)\n ; ↳ #table(b 2 a 1)\n (del! t 'b)\n ; ↳ #table(a 1)\n t\n ; ↳ #table(a 1)" when "Shorthand for `(if cond body NIL)`.\n\nExamples:\n\n (when (eq? cmd 'exit)\n (princ \"exiting!\")\n (newline)\n (exit))" vec? "Return `T` if `v` is a vector, `NIL` otherwise." min "Return the smallest among the arguments.\n\nExamples:\n\n (min 3 1 9 4)\n ; ↳ 1\n\n (min 'c 'h 'z 'a)\n ; ↳ a\n\n (min \"t\" \"g\" \"a\")\n ; ↳ \"a\"" cddaar "Shorthand for (cdr (cdr (car (car lst))))." num->str "Return the number formatted as a string.\n\nFloating point numbers can only be formatted in base 10. Bignums are\nsupported with bases 2, 4, 8, 10, 16 and 32. The rest of the\nnumerical types are valid for any base from 2 to 36.\n\nNote: unlike other LISP dialects, StreetLISP's base-32 encoding is\ndone according to RFC 4648.\n\nExamples:\n\n (num->str 65535 :base 16)\n ; ↳ \"FFFF\"\n\n (num->str (s8 -7))\n ; ↳ \"-7\"" io? "Return `T` if `term` is of `io` type, `NIL` otherwise." eof-object? "Return `T` if the argument is `#<eof>`, `NIL` otherwise.\n\nThis object is returned by I/O functions to signal end of file,\nwhere applicable." help "Display documentation for a specific term or group of terms, if\navailable.\n\nAn optional symbol `group` is used to query for documentation on a\ngroup instead of a single term. All available documentation groups\ncan be displayed with `(help groups)`.\n\nAsterisk can be added to the beginning and/or end of the term in order\nto list the matching terms defined in the current environment. This\ncan be useful to recall a function's name.\n\nExamples:\n\n (help str?) ; show documentation for str?\n (help groups) ; show documentation groups\n (help type group) ; list items for dealing with types\n (help group type) ; same as ^\n (help str->*) ; find functions converting from strings\n (help *->str) ; find functions converting to strings\n (help *num*) ; find anything related to numbers" (doc
77−group array) "Arrays and vectors." mod "Return the remainder of the Euclidean division `a/n`.\n\nExamples:\n\n (mod 10 3)\n ; ↳ 1\n\n (mod -10 3)\n ; ↳ 2\n\n (mod -10 -3)\n ; ↳ 2\n\n (mod 10 -3)\n ; ↳ 1" if "Return the result of `then` if `cond` evaluated as \"true\", `else`\notherwise.\n\nThe `else` is not optional unlike in many other LISP implementations.\nPrimary purpose is to spot errors involving wrong parenthesis\nplacement. Another reason is to force a certain coding style.\n\nExamples:\n\n (def x '(1))\n (if x 'yes 0)\n ; ↳ yes\n (if (str? x) 1 'no)\n ; ↳ no" p32 "Construct a 32-bit abstract pointer value." io-read-lines "Return a list of lines read from the IO object until it ran out of\ndata.\n\nThe file is split into lines by `#\\linefeed`. Each string will have\nthe character, except the last line if EOF has been reached\nbeforehand.\n\nExamples:\n\n ; read current process' segments on Plan 9\n (def seg (file (str \"/proc/\" (getpid) \"/segment\")))\n (io-read-lines seg)\n ; ↳ (\"Stack 1feff0000 1ffff0000 1\\n\"\n \"Text R 10000 70000 1\\n\"\n \"Data 70000 d0000 1\\n\"\n \"Bss d0000 1a0000 1\\n\"\n \"Bss 1fcff0000 1feff0000 1\\n\"\n \"Bss 1faff0000 1fcff0000 1\\n\")" io-line "Return the current line number of the IO object.\n\nLine number is purely informative and is only being automatically\nupdated with the files opened for reading. If the cursor position is\nchanged via `io-skip` or `io-pos!`, the behavior is undefined." sym-set-doc "Set the documentation for the symbol." macrocall? "Return the macro application function if `e` refers to a macro call,\n`NIL` otherwise.\n\nExamples:\n\n (macrocall? '(car NIL))\n ; ↳ NIL\n\n (macrocall? '(let ((x 1)) 2))\n ; ↳ #fn(...)" trycatch "Return the result of evaluation of the expression `try` or, if an\nexception has been thrown, the one-argument function `catch`.\n\nExamples:\n\n (trycatch (+ 1 2) (λ (e) e))\n ; ↳ 3\n (trycatch (+ 1 NIL) (λ (e) e))\n ; ↳ (type-error num NIL)" (doc
76+group compare) "Comparison operators." cdddar "Shorthand for (cdr (cdr (cdr (car lst))))." set-cdr! "Modify a cons cell (a list) in-place by putting `new-second` as its\nsecond element (tail of the list). Return the modified cons\ncell (list).\n\nExamples:\n\n (def q '(1 2 3 4 5))\n (set-cdr! q '(6 7))\n ; ↳ (1 6 7)\n q\n ; ↳ (1 6 7)" stacktrace "Return the current stack trace." eq? "Return `T` if `a` and `b` are the same object, `NIL` otherwise.\n\nExamples:\n\n (eq? 0.0 0)\n ; ↳ NIL\n\n (eq? 0 0)\n ; ↳ T\n\n (def a \"1\")\n (def b \"1\")\n (eq? a b)\n ; ↳ NIL\n\n (def a '(1))\n (def b '(1))\n (eq? a b)\n ; ↳ NIL" io->str "Return the data of the in-memory `io` buffer as a string." bound? "Return `T` if `sym` has a value associated with it, `NIL` otherwise.\n\nExamples:\n\n (bound? 'bound?)\n ; ↳ T\n\n (bound? 'doesnotcompute)\n ; ↳ NIL" list->vec "Return the list converted to a vector.\n\nExamples:\n\n (list->vec '(1 2 a))\n ; ↳ #(1 2 a)" odd? "Return `T` if `n` is an odd integer, `NIL` otherwise." def "Assign the function (first form) or the result of the expression\n(second form) to the identifier.\n\nDocumentation for the definition may also be supplied after `form` in\nthe same manner as with `defdoc`.\n\nFunction definitions themselves may contain other definitions internal\nto the function.\n\nExamples:\n\n ; a function with documentation (first form)\n (def (f x)\n \"Return the square of doubled `x`.\n\n Examples:\n\n (f 3)\n ; ↳ 36\"\n :doc-group cool-funcs ; documentation group for (help groups)\n :doc-see g ; reference another function in the documentation\n (def (g y) ; an internal function\n (+ y y))\n (* (g x) (g x)))\n (f 2)\n ; ↳ 16\n\n ; a variable (second form)\n (def x (length \"hello\"))\n x\n ; ↳ 5" list? "Return `T` if the value is either `NIL` or a cons cell, `NIL`\notherwise." *os-version* "The \"version\" of the operating system this StreetLISP VM executable\nwas built for.\n\nThe availability of the constant and its value depends on the\noperating system and is only provided for the user to see. No logic\nshould depend on it.\n\nExamples:\n\n *os-version*\n ; ↳ \"6.14.5-0-edge\" ; Alpine Linux kernel version" str-rep "Return the concatenation of the term formatted as a string, repeated\n`k` times.\n\nExamples:\n\n (str-rep \"oi\" 3)\n ; ↳ \"oioioi\"\n\n (str-rep #\\ы 5)\n ; ↳ \"ыыыыы\"\n\n (str-rep 'a 3)\n ; ↳ \"aaa\"\n\n (str-rep 1 5)\n ; ↳ \"11111\"" time "Display the elapsed time of evaluating `expr` to `*io-out*`, return\nthe result of the evaluated expression.\n\nExamples:\n\n (time (begin (sleep 0.1) 12345))\n ; ‼ Elapsed time: 0.10013356 seconds\n ; ↳ 12345" size-of "Return the size of the value in bytes, if applicable.\n\nWorks only with C integer types, arrays, strings and in-memory\nbuffers.\n\nExamples:\n\n (size-of \"hello\")\n ; ↳ 5\n\n (size-of (arr 'u32 1 2 3))\n ; ↳ 12\n\n (def b (buffer))\n (io-write b \"hello\")\n (size-of b)\n ; ↳ 5" sym "Return a symbol with the name being the concatenation of terms\nformatted as strings.\n\nThis is equivalent to `(sym (str …))`.\n\nExamples:\n\n (sym \"a\" 'b 1)\n ; ↳ ab1" tanh "Return the hyperbolic tangent of `x`." for "Call the function `f` with a single integer argument, starting from\n`min` and ending with `max`.\n\nExamples:\n\n (for 0 2 (λ (i) (print (- 2 i))))\n ; ‼ 210" begin "Evaluate the expressions in order and return the result of the last\nexpression.\n\nExamples:\n\n (if 1\n (begin (print 1)\n (newline)\n 'ignored\n 'done)\n (print 0)\n (newline)\n 'else)\n ; ‼ 1\n ; ↳ done" const? "Return `T` if the term refers to a constant, `NIL` otherwise.\n\nConstants cannot be modified with `set!`. Trying to do so will result\nin an exception.\n\nExamples:\n\n (const? 12345) ; a number\n ; ↳ T\n\n (const? 'const?) ; a function\n ; ↳ NIL\n\n (const? 'pi) ; a mathematical constant\n ; ↳ T" str-trim "Return the portion of the string with all leading runes satisfying\n`lead-pred` (and trailing runes satisfying `trail-pred`) removed.\n\nWithout predicates explicitly specified, `str-trim` will remove\nwhitespace from both sides of the string.\n\nPass `NIL` as the predicate to disable trimming on either side.\n\nExamples:\n\n (str-trim \" \\nhello\\t\\v\")\n ; ↳ \"hello\"\n\n (str-trim \" \\nhello\\t\\v\"\n (λ (r) (str-find \" \\v\" r)))\n ; ↳ \"\\nhello\\t\"\n\n (str-trim \"123abc!456def\"\n rune-numeric?\n rune-alphabetic?)\n ; ↳ \"abc!456\"" io-pos! "Change the current absolute position within the IO object in bytes,\nreturn the resulting position.\n\nExamples:\n\n (def f (buffer))\n (io-write f \"hello, world!\")\n (io-pos! f 64)\n ; ↳ 13\n (io-pos! f 7)\n ; ↳ 7\n (read f)\n ; ↳ world!" return "Return from the function with the specified value as the result.\n\nExamples:\n\n (def (f x) (when (not x)\n (return 0))\n (princ \"hi\")\n (newline)\n 1)\n (f 'a)\n ; ‼ hi\n ; ↳ 1\n (f NIL)\n ; ↳ 0" *stderr* "Standard error output IO stream." tan "Return the tangent of `r`, where `r` is given in radians." table "Construct a table from keys from the arguments.\n\nEvery two arguments are expected to be a key and a value associated\nwith that key.\n\nExamples:\n\n (table)\n ; ↳ #table()\n\n (table 'a 1 'b 2)\n ; ↳ #table(a 1 b 2)" __rcscript "Execute, if exists, the user's \"run commands\" file.\n\nThe file path is predefined and depends on the OS:\n\n * `$home/lib/slrc` on Plan 9\n * `$HOME/.slrc` on other operating systems\n\nIt is automatically loaded by StreetLISP when running in interactive\nmode. The user may wish to use this file to change the look of the\nprompt, load additional functionality they want to use without having\nto do the process manually each time, and so on." doc-group "Define documentation for a group." cdaaar "Shorthand for (cdr (car (car (car lst))))." bounds-error "Raise a bounds error exception." even? "Return `T` if `n` is an even integer, `NIL` otherwise." *properties* "All properties of symbols recorded with `putprop` are recorded in this\ntable." zero? "Return `T` if `n` is zero. Shorthand for `(= n 0)`." proper-list? "Return `T` is the value is a proper list. That is, a non-circular\nlist with the last element being `NIL`, as opposed to a dotted list.\n\nExamples:\n\n ; empty list\n (proper-list? NIL)\n ; ↳ T\n\n ; a list with one element\n (proper-list? '(1))\n ; ↳ T\n\n ; a pair, cdr of the cell is 2\n (proper-list? '(1 . 2))\n ; ↳ NIL\n\n ; on a circular list\n (def l '(1))\n (set-cdr! l l)\n ; ↳ #0=(1 . #0#)\n (length l)\n ; ↳ +inf.0\n (proper-list? l)\n ; ↳ NIL" io-filename! "Change the filename of the IO object, return the new filename.\n\nChanging the filename does not cause any side effects. The filename\nis purely informative and does not necessarily reflect the actual\npath.\n\nExamples:\n\n (def f (buffer))\n (io-filename b)\n ; ↳ \"\"\n (io-filename! b \"new name\") ; change the filename\n ; ↳ \"new name\"\n (io-filename b)\n ; ↳ \"new name\"" random "Return a random number in the range `[0, max]` (inclusive).\n\nThe result is either an integer or a floating point number, depending\non the type of the `max` argument.\n\nExamples:\n\n (random 1)\n ; ↳ 1\n\n (random 1.0)\n ; ↳ 0.69517" *directory-separator* "OS-specific path separator.\n\nIt is preferred over hardcoded `\"/\"`, for portability." reverse! "Return the list with its elements in reverse order.\n\nThe original list may be modified by this function since it's a\ndestructive operation.\n\nExamples:\n\n (def a '(1 2 3))\n (reverse! a)\n ; ↳ (3 2 1)\n a\n ; ↳ (1) ; original list has been modified in-place" eval "Evaluate expression.\n\nExamples:\n\n (eval '(begin (set! x 1 y 2) (+ x y)))\n ; ↳ 3\n x\n ; ↳ 1\n y\n ; ↳ 2" cdaadr "Shorthand for (cdr (car (car (cdr lst))))." u32 "Construct a 32-bit unsigned number." cons "Return a cons cell containing two arguments.\n\nExamples:\n\n (cons 1 2)\n ; ↳ (1 . 2)\n\n (cons 1 '(2))\n ; ↳ (1 2)\n\n (cons 1 (cons 2 (cons 3 NIL)))\n ; ↳ (1 2 3)" filter "Return a copy of the list with only the elements of the original\nthat satisfy the predicate.\n\nExamples:\n\n (filter odd? '(0 1 2 3 4))\n ; ↳ (1 3)" assq "Return a pair of a matching key and the associated value, or `NIL` if\nnone matched. Keys are compared using `eq?`." most-positive-fixnum "A constant integer closest to positive infinity that can be\nrepresented by fixnum type on this particular platform." del! "Remove any existing mapping for `key` and return the table.\n\nExamples:\n\n (def t #table(a 1 b 2))\n (del! t 'c)\n ; ↳ #table(b 2 a 1)\n (del! t 'b)\n ; ↳ #table(a 1)\n t\n ; ↳ #table(a 1)" when "Shorthand for `(if cond body NIL)`.\n\nExamples:\n\n (when (eq? cmd 'exit)\n (princ \"exiting!\")\n (newline)\n (exit))" vec? "Return `T` if `v` is a vector, `NIL` otherwise." min "Return the smallest among the arguments.\n\nExamples:\n\n (min 3 1 9 4)\n ; ↳ 1\n\n (min 'c 'h 'z 'a)\n ; ↳ a\n\n (min \"t\" \"g\" \"a\")\n ; ↳ \"a\"" cddaar "Shorthand for (cdr (cdr (car (car lst))))." num->str "Return the number formatted as a string.\n\nFloating point numbers can only be formatted in base 10. Bignums are\nsupported with bases 2, 4, 8, 10, 16 and 32. The rest of the\nnumerical types are valid for any base from 2 to 36.\n\nNote: unlike other LISP dialects, StreetLISP's base-32 encoding is\ndone according to RFC 4648.\n\nExamples:\n\n (num->str 65535 :base 16)\n ; ↳ \"FFFF\"\n\n (num->str (s8 -7))\n ; ↳ \"-7\"" io? "Return `T` if `term` is of `io` type, `NIL` otherwise." eof-object? "Return `T` if the argument is `#<eof>`, `NIL` otherwise.\n\nThis object is returned by I/O functions to signal end of file,\nwhere applicable." help "Display documentation for a specific term or group of terms, if\navailable.\n\nAn optional symbol `group` is used to query for documentation on a\ngroup instead of a single term. All available documentation groups\ncan be displayed with `(help groups)`.\n\nAsterisk can be added to the beginning and/or end of the term in order\nto list the matching terms defined in the current environment. This\ncan be useful to recall a function's name.\n\nExamples:\n\n (help str?) ; show documentation for str?\n (help groups) ; show documentation groups\n (help type group) ; list items for dealing with types\n (help group type) ; same as ^\n (help str->*) ; find functions converting from strings\n (help *->str) ; find functions converting to strings\n (help *num*) ; find anything related to numbers" (doc
77+group array) "Arrays and vectors." mod "Return the remainder of the Euclidean division `a/n`.\n\nExamples:\n\n (mod 10 3)\n ; ↳ 1\n\n (mod -10 3)\n ; ↳ 2\n\n (mod -10 -3)\n ; ↳ 2\n\n (mod 10 -3)\n ; ↳ 1" if "Return the result of `then` if `cond` evaluated as \"true\", `else`\notherwise.\n\nThe `else` is not optional unlike in many other LISP implementations.\nPrimary purpose is to spot errors involving wrong parenthesis\nplacement. Another reason is to force a certain coding style.\n\nExamples:\n\n (def x '(1))\n (if x (begin (print \"yep!\") (newline) 'yes) 0)\n ; ‼ yep!\n ; ↳ yes\n (if (str? x) 1 (print \"nope!\") (newline) 'no)\n ; ‼ nope!\n ; ↳ no" p32 "Construct a 32-bit abstract pointer value." io-read-lines "Return a list of lines read from the IO object until it ran out of\ndata.\n\nThe file is split into lines by `#\\linefeed`. Each string will have\nthe character, except the last line if EOF has been reached\nbeforehand.\n\nExamples:\n\n ; read current process' segments on Plan 9\n (def seg (file (str \"/proc/\" (getpid) \"/segment\")))\n (io-read-lines seg)\n ; ↳ (\"Stack 1feff0000 1ffff0000 1\\n\"\n \"Text R 10000 70000 1\\n\"\n \"Data 70000 d0000 1\\n\"\n \"Bss d0000 1a0000 1\\n\"\n \"Bss 1fcff0000 1feff0000 1\\n\"\n \"Bss 1faff0000 1fcff0000 1\\n\")" io-line "Return the current line number of the IO object.\n\nLine number is purely informative and is only being automatically\nupdated with the files opened for reading. If the cursor position is\nchanged via `io-skip` or `io-pos!`, the behavior is undefined." sym-set-doc "Set the documentation for the symbol." macrocall? "Return the macro application function if `e` refers to a macro call,\n`NIL` otherwise.\n\nExamples:\n\n (macrocall? '(car NIL))\n ; ↳ NIL\n\n (macrocall? '(let ((x 1)) 2))\n ; ↳ #fn(...)" trycatch "Return the result of evaluation of the expression `try` or, if an\nexception has been thrown, the one-argument function `catch`.\n\nExamples:\n\n (trycatch (+ 1 2) (λ (e) e))\n ; ↳ 3\n (trycatch (+ 1 NIL) (λ (e) e))\n ; ↳ (type-error num NIL)" (doc
7878 group builtin) "Built-in operators." iterate "Return the list of length `n` containing results of applying function\n`fn` to `zero`, 0 through `n` times.\n\nThe result is of form\n\n [zero (fn zero) (fn (fn zero)) (fn (fn (fn zero))) …]\n\nExamples:\n\n (iterate 1+ 5 3)\n ; ↳ (5 6 7)\n\n (iterate (λ (x) (* x x)) 2 5)\n ; ↳ (2 4 16 256 65536)\n\n (iterate (λ (s) (str-sub s 1)) \"hello\" 5)\n ; ↳ (\"hello\" \"ello\" \"llo\" \"lo\" \"o\")" *syntax-environment* "Table containing macro definitions.\n\nThe keys are macro names, the values are their application functions." table-values "Return the list of all values of the table.\n\nExamples:\n\n (def t #table(a 1 b 2 c 1))\n (table-values t)\n ; ↳ (1 2 1)" macroexpand "Return a fully macro-expanded expression.\n\nExpansion will continue until no more macro calls are left.\n\nExamples:\n\n (let ((a 3) (b 4) (c 5))\n (macroexpand `(let* {[x ,a] [y ,b]} (+ x y ,c))))\n ; ↳ ((λ (x)\n ((λ (y)\n (+ x y 5))\n 4))\n 3)" caadr "Shorthand for (car (car (cdr lst)))." type-of "Return the underlying type of the value.\n\nExamples:\n\n (type-of 1)\n ; ↳ fixnum\n\n (type-of NIL)\n ; ↳ null\n\n (type-of T)\n ; ↳ bool\n\n (type-of \"hello\")\n ; ↳ str\n\n (type-of (arr 'u32 0 1 2))\n ; ↳ (arr u32)" top-level-value "Return the value bound to the symbol in the top level (global)\nenvironment.\n\nExamples:\n\n (def abc 1)\n (let {[abc 2]}\n (cons abc (top-level-value 'abc)))\n ; ↳ (2 . 1)\n abc\n ; ↳ 1" defstruct "Declare a new structure type with the specified name and slots.\n\nThe default underlying type is a \"named\" vector (`:type vec`), where\nthe first element is the name of the structure's type, the rest are\nthe keyworded slot values. A list with slot values alone can be used\ninstead by adding `:type list` option. The list will not contain the\nname of the struct by default, which can be enabled with `:named T`\noption.\n\nAs an example, the following declaration generates the default\nconstructor for a structure of three slots, with one of them (`c`)\nhaving a non-`NIL` default value and marked as read-only:\n\n (defstruct blah \"Return stuff.\" :doc-group stuff a b (c 1 :read-only T))\n ; (make-blah (:a NIL) (:b NIL) (:c 1))\n ; (blah-a s)\n ; (blah-b s)\n ; (blah-c s)\n ; (blah-a! s new-a)\n ; (blah-b! s new-b)\n\nSlot's options, if any, should be specified after its default value.\nSupported options are:\n\n ; mark the slot as read-only\n ; its value can be read, but trying to modify it will throw an error\n … :read-only T\n\nThe constructor can be changed in several ways:\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/setter prefix,\nwhich defaults to `structname-`. Prefix can be disabled entirely with\n`:conc-name NIL`.\n\nSlot setters are generated for writable slots by appending `!`\n(exclamation mark) to the accessor's name.\n\nDefault predicate can be disabled or its name, which defaults to\n`structname?`, changed:\n\n ; use \"blargh?\" instead of \"blah?\"\n (defstruct blah :predicate blargh? a b c)\n ; without predicate\n (defstruct blah :predicate NIL a b c)" caadar "Shorthand for (car (car (cdr (car lst))))." foldl1 "Same as `foldl` but using the first element of the list as the\ninitial accumulator.\n\nExamples:\n\n (foldl1 * (iota 6 1))\n ; ↳ 720" buffer "Return an in-memory buffer for I/O, of `io` type.\n\nA buffer can be used for both reading and writing at the same\ntime." assoc-list "Construct an association list from the arguments.\n\nEvery two arguments are expected to be a key and a value associated\nwith that key.\n\nExamples:\n\n (assoc-list 'a 0 'b 1)\n ; ↳ ((a . 0) (b . 1))" builtin? "Return `T` if `v` is a built-in function implemented in C, `NIL`\notherwise.\n\nExamples:\n\n (builtin? map)\n ; ↳ T\n\n (builtin? macroexpand)\n ; ↳ NIL" str-map "Return the concatenation of the values produced by `fn` when applying\nto each rune of the string `s`.\n\nFunction `fn` may return a value of any type suitable for `io-write` -\na rune, string, array of C primitives. If `fn` returns `NIL`, the\nrune is ignored.\n\nExamples:\n\n (str-map rune-upcase\n \"hello, world!\")\n ; ↳ \"HELLO, WORLD!\"\n\n (str-map (λ (r) (str r r))\n \"hello\")\n ; ↳ \"hheelllloo\"\n\n (str-map (λ (r) (and (not (rune-whitespace? r)) r))\n \"! this is great !\")\n ; ↳ \"!thisisgreat!\"" macroexpand-1 "Return a macro-expanded expression.\n\nIf the expression is not a macro call, it is returned unchanged.\nOnly a single level of expansion is performed.\n\nExamples:\n\n (let ((a 3) (b 4) (c 5))\n (macroexpand-1 `(let* {[x ,a] [y ,b]} (+ x y ,c))))\n ; ↳ ((λ (x) ; note how the inner let* expression isn't expanded\n (let* ((y 4)) (+ x y 5)))\n 3)" str "Return concatenation of terms formatted as strings.\n\nThis is equivalent to `(princ terms…)`, except the string is\n_returned_, rather than printed.\n\nExamples:\n\n (str \"a\" 'b 1 #(0))\n ; ↳ \"ab1#(0)\"" negative? "Return `T` if `n` is a negative number. Shorthand for `(< n 0)`." 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." assert-fail "Throw an \"assertion failed\" exception if evaluating `expr` itself does\nnot result in an exception thrown. Return `T` otherwise.\n\nTo test for a specific exception type, an optional `what` argument can\nbe used.\n\nExamples:\n\n (def s \"abc\")\n (assert-fail (= (length s) 3))\n ; ‼ assertion failed: ...\n (assert-fail (= s 1) type-error)\n ; ↳ T" io-read-line "Return a single line of input read from `io`.\n\nReading stops at either a `#\\linefeed` character or upon reaching EOF.\nThe line feed character is included in the returned value unless EOF\nhas been reached beforehand.\n\nEOF (`#<eof-object>`) is returned if the IO object had no data.\n\nExamples:\n\n ; read one line from the kernel messages file\n (io-read-line (file \"/dev/kmesg\"))\n ; ↳ \"127 holes free\\n\"\n\n ; /dev/null has no data - EOF is returned\n (eof-object? (io-read-line (file \"/dev/null\")))\n ; ↳ T" and "Return `NIL` and stop evaluating the arguments if one of them\nevaluated to `NIL`. Return the last value otherwise.\n\nExamples:\n\n (and)\n ; ↳ T\n\n (and 1 2 (print 'yes) 3)\n ; ‼ yes\n ; ↳ 3\n\n (and 1 NIL (print 'yes) 3)\n ; ↳ NIL" 1- "Equivalent to `(- n 1)` - decrement by one." that "The result of the last expression evaluated in the REPL.\n\nExamples:\n\n (map rune-upcase \"hello, world!\")\n ; ↳ \"HELLO, WORLD!\"\n (str-sub that 0 5)\n ; ↳ \"HELLO\"\n (map rune-downcase that)\n ; ↳ \"hello\"" (doc
7979 group prop) "Dealing with properties of symbols." (doc group vm) "VM-related functions." equal? "Return `T` if both `a` and `b` are of the same value. For non-leaf\ntypes (cons cell and vector), the equality test is performed\nthroughout the whole structure of the values.\n\nExamples:\n\n (equal? 0.0 0)\n ; ↳ NIL\n\n (equal? 0 0)\n ; ↳ T\n\n (def a \"1\")\n (def b \"1\")\n (equal? a b)\n ; ↳ T\n\n (def a '(1))\n (def b '(1))\n (equal? a b)\n ; ↳ T" cddar "Shorthand for (cdr (cdr (car lst)))." *interactive* "Variable indicating whether VM is running in \"interactive\" mode (`T`,\nREPL is active) or not (`NIL`, REPL is not active).\n\nInteractive mode can be forced by adding `-i` as the first command\nline argument." unquote "Evaluate the expression, which is a part of a quasiquoted expression\nitself.\n\nShorthand for `(unquote expr)`.\n\nExamples:\n\n `(0 1 ,(+ 2 3)) ; same as (quasiquote (0 1 (unquote (+ 2 3))))\n ; ↳ (0 1 5)" or "Return the first evaluated argument that is not `NIL` and stop\nevaluating the rest of the arguments. Return `NIL` otherwise.\n\nExamples:\n\n (or)\n ; ↳ NIL\n\n (or 1 2 (print 'first) (print 'second) 3)\n ; ↳ 1\n\n (or NIL NIL (print 'first) (print 'second) 3)\n ; ‼ first" = "Numerical equality test. Return `T` if all numbers are equal,\n`NIL` otherwise." fn? "Return `T` if `v` is a function, `NIL` otherwise.\n\nExamples:\n\n (fn? (void))\n ; ↳ NIL\n\n (fn? map)\n ; ↳ T\n\n (fn? macroexpand)\n ; ↳ T" (doc
8080 group type) "Dealing with types." caaadr "Shorthand for (car (car (car (cdr lst))))." make-system-image "Build and store a \"system image\" of the runtime environment to a file." subseq "Return a bounded part of a sequence.\n\nThe returned value is always a copy of the subsequence of the\noriginal. It is an error if either `start` or `end` (if specified)\nare out of bounds.\n\nExamples:\n\n (subseq \"hello\" 1 2)\n ; ↳ \"e\"\n\n (subseq '(1 2 3) 0 2)\n ; ↳ (1 2)\n\n (subseq #(a b c) 2)\n ; ↳ #(c)" set! "Evaluate the expression, assign the result to the identifier and\nreturn the value.\n\nThe identifier must already be bound in the same environment,\notherwise this results in a compilation error.\n\nMultiple identifiers and expressions may be specified in pairs. The\nreturned value will be the result of the last expression.\n\nExamples:\n\n (def a NIL)\n (def b NIL)\n (def c NIL)\n (set! a 1 b 2 c (+ a b))\n ; ↳ 3\n a\n ; ↳ 1\n b\n ; ↳ 2\n c\n ; ↳ 3" vm-stats "Print various VM-related information, such as the number of GC\ncalls so far, heap and stack size, etc." ptr "Construct an abstract pointer value. The bit width is either 32-bit\nor 64-bit, depending on the platform the code is executing on.\n\nNote: certain arithmetic operations on pointers, such as division and\nmultiplication, will throw an error. This is done on purpose since\ndoing that on pointers rarely makes sense." caddar "Shorthand for (car (cdr (cdr (car lst))))." print-stack-trace "Print the stacktrace." *stdin* "Standard input IO stream." cosh "Return the hyperbolic cosine of `x`." < "Return `T` if the arguments are in strictly increasing order (next\none is greater than the previous one). With a single argument\nthe result is always `T`." (doc
@@ -259,12 +259,12 @@ group number) "Operations on numbers, mathematical constants." cdaddr "Shorthan · 178 unmodified lines
259259 *syntax-environment* #table(while #fn("z12001PP:" #($while) 7) trycatch #fn("n22001e3:" #($trycatch) 7) def #fn("z2200182PPP:" #($def) 8) prog1 #fn("z12001PP:" #($prog1) 7) bcode:nconst #fn("n1200r2e3:" #(aref) 7) bcode:spmax #fn("n1200r5e3:" #(aref) 7) with-input-from #fn("z12021e1220e2e1e17315163:" #(#fn(nconc)
260260 with-bindings *io-in* copy-list) 9) defmacro #fn("z17015186<86=873?0710<870=53@30q42223240<e22526e10=e177885153e3Ie3:" #(separate-doc-from-body
261261 sym-set-doc begin set-syntax! quote #fn(nconc) λ copy-list) 15) unless #fn("z1200q211Pe4:" #(if
262−begin) 9) time #fn("n1202122e1e2e123024252622e121e32728e5e3e3:" #(let #:g557 time-now prog1
262+begin) 9) time #fn("n1202122e1e2e123024252622e121e32728e5e3e3:" #(let #:g560 time-now prog1
263263 princ "Elapsed time: " - " seconds"
264264 *linefeed*) 13) cond #fn("z0Ib5852085>1_485<061:" #(#fn("n10H340q: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
265−begin or => 1arg-lambda? caddr caadr let if cddr #:g486) cond-clauses->if 14)) 7) do #fn("z21<2071052207205220230522425268827872829e17:1=51522829e17:82512825e18:52e153e4e3e2e12825e18952e3:" #(#fn(map)
266−car cadr #fn("n170051B38071061:0<:" #(cddr caddr) 6) letrec #:g505 λ if #fn(nconc) begin
267−copy-list) 21) assert-fail #fn("z12021220qe32324e113E0252624e2271<e2e3@30De3e3e2:" #(assert
265+begin or => 1arg-lambda? caddr caadr let if cddr #:g489) cond-clauses->if 14)) 7) do #fn("z21<207105220720522023052242526882728e187e12729e17:1=5152e17:82512725e18:52e155e3e2e12725e18952e3:" #(#fn(map)
266+car cadr #fn("n170051B38071061:0<:" #(cddr caddr) 6) letrec #:g508 λ #fn(nconc) if begin
267+copy-list) 20) assert-fail #fn("z12021220qe32324e113E0252624e2271<e2e3@30De3e3e2:" #(assert
268268 trycatch
269269 begin λ e
270270 eq? car
@@ -312,8 +312,9 @@ copy-list) 8) defstruct #fn("z0700=5185<85=0<I218887>2?94863H0728873862489Pe152 · 41 unmodified lines
312312 "\n\n" #fn(str-sub) "" #fn(str-split) print-to-str #fn(list*) defstruct "\n" #fn(str) "\n\n "
313313 str-join "\n ") fmt 14) sym-set-doc append :doc-fmt #fn(nconc) %defstruct% copy-list) 15) with-output-to #fn("z12021e1220e2e1e17315163:" #(#fn(nconc)
314314 with-bindings *io-out* copy-list) 9) bcode:ctable #fn("n1200Ke3:" #(aref) 7) catch #fn("n22012122e123242522e2262722e22829e2e3262:22e20e3e42;22e22<22e2e4e3e3:" #(trycatch
315−λ #:g549 if and cons? eq? car quote thrown-value cadr caddr raise) 15) let* #fn("z10H3E02021e1qe17215153e1:2021e173051e1e1720=B3H02024e10=e17215153e1@301515375051e2:" #(#fn(nconc)
316−λ copy-list caar let* cadar) 13) return #fn("|00001000W0000J907050?04210e2:" #(void $return) 6) if #fn("n3200182e4:" #($if) 8) letrec #fn("z1202021e12273052e122240527515154e1227605262:" #(#fn(nconc)
315+λ #:g552 if and cons? eq? car quote thrown-value cadr caddr raise) 15) let* #fn("z10H3E02021e1qe17215153e1:2021e173051e1e1720=B3H02024e10=e17215153e1@301515375051e2:" #(#fn(nconc)
316+λ copy-list caar let* cadar) 13) return #fn("|00001000W0000J907050?04210e2:" #(void $return) 6) if #fn("z282360q@80702151422012382Pe4:" #(arg-error
317+"if without an else branch" $if begin) 9) letrec #fn("z1202021e12273052e122240527515154e1227605262:" #(#fn(nconc)
317318 λ #fn(map) car #fn("n12021e17205162:" #(#fn(nconc) set! copy-list) 8) copy-list void) 11) bcode:sp #fn("n1200r4e3:" #(aref) 7) defdoc #fn("z10B86;35040<;J404086;35040=70711225251<863I0232487e22489e22488e2e4:232487e22489e2e3:" #(separate-doc-from-body
318319 append (NIL) sym-set-doc quote) 13) assert #fn("n1200D2122230e2e2e2e4:" #(if raise quote
319320 assert-failed) 11) case #fn("z1IIb6b78620_4872186>1_4225023880e2e12425e126278788>215252e3:" #(#fn("n1700513400:210e2:" #(self-evaluating?
@@ -326,7 +327,7 @@ $set! cddr) 8)) 9) receive #fn("z22021q1e32221e10e173825153e3:" #(call-with-val · 6 unmodified lines
326327 #fn(length) foldl #fn("n22021AF0~52C7022@40231e1P:" #(#\a #fn(str-rune) car cdr) 9) lst iota def
327328 "Shorthand for " "." :doc-group list) 13) dotimes #fn("z10<0T20E2187Ke32223e186e1e17415153e4:" #(for
328329 - #fn(nconc) λ copy-list) 14) unwind-protect #fn("n2202122q1e3e2e1232402225e121e12625e2e4e321e1e3e3:" #(let
329−#:g550 λ prog1 trycatch #:g551 raise) 14) throw #fn("n220212223e201e4e2:" #(raise list quote
330+#:g553 λ prog1 trycatch #:g554 raise) 14) throw #fn("n220212223e201e4e2:" #(raise list quote
330331 thrown-value) 9) doc-group #fn("n22021222324e22325e2230e2e41e3e2:" #(begin
331332 sym-set-doc list quote doc group) 11))
332333 1+ #fn("n10KM:" #() 1+ 6) 1-
@@ -731,7 +732,7 @@ top-level-exception-handler #fn("n17071w042285>1230>12486>1{86504:" #(*io-out* * · 398 unmodified lines
731732 #fn("n070A51471225061:" #(print-exception
732733 print-stack-trace #fn(stacktrace)) 6) #fn("n1A50420061:" #(#fn(raise)) 6)) top-level-exception-handler 8)
733734 trace #fn("n120051718551Jc02207324252627280e225e3e229e12:2885e225e3e55152@30q^14I:" #(#fn(top-level-value)
734−traced? #fn(set-top-level-value!) eval λ #:g552 write cons quote newline apply) trace 15)
735+traced? #fn(set-top-level-value!) eval λ #:g555 write cons quote newline apply) trace 15)
735736 traced? #fn("n12071051;3?0422051228551d:" #(#fn("z020210P51472504230}2:" #(#fn(write)
736737 x newline #.apply) 7)
737738 closure? #fn(fn-code)) traced? 8)
src/compiler.sl+88−91
@@ -23,9 +23,9 @@ · 22 unmodified lines
2323 (nconst (bcode:nconst b)))
2424 (if (has? const-to-idx v)
2525 (get const-to-idx v)
26− (begin (put! const-to-idx v nconst)
27− (prog1 nconst
28− (aset! b 2 (+ nconst 1)))))))
26+ (put! const-to-idx v nconst)
27+ (prog1 nconst
28+ (aset! b 2 (+ nconst 1))))))
2929
3030 (def (emit e inst . args)
3131 (def (load? i)
@@ -39,37 +39,36 @@ · 7 unmodified lines
3939 (aset! e 0 (cdr bc)))
4040 (else
4141 (aset! e 0 (cons inst bc)))))
42− (begin
43− (when (memq inst '(loadv loadg setg))
44− (set! args (list (bcode:indexfor e (car args)))))
45− (let ((longform
46− (assq inst '((loadv loadv.l) (loadg loadg.l) (setg setg.l)
47− (loada loada.l) (seta seta.l) (box box.l)))))
48− (when (and longform (> (car args) 255))
49− (set! inst (cadr longform))))
50− (let ((longform
51− (assq inst '((loadc loadc.l)))))
52− (when (and longform (> (car args) 255))
53− (set! inst (cadr longform))))
54− (if (eq? inst 'loada)
42+ (when (memq inst '(loadv loadg setg))
43+ (set! args (list (bcode:indexfor e (car args)))))
44+ (let ((longform
45+ (assq inst '((loadv loadv.l) (loadg loadg.l) (setg setg.l)
46+ (loada loada.l) (seta seta.l) (box box.l)))))
47+ (when (and longform (> (car args) 255))
48+ (set! inst (cadr longform))))
49+ (let ((longform
50+ (assq inst '((loadc loadc.l)))))
51+ (when (and longform (> (car args) 255))
52+ (set! inst (cadr longform))))
53+ (if (eq? inst 'loada)
54+ (cond ((equal? args '(0))
55+ (set! inst 'loada0 args NIL))
56+ ((equal? args '(1))
57+ (set! inst 'loada1 args NIL)))
58+ (when (eq? inst 'loadc)
5559 (cond ((equal? args '(0))
56− (set! inst 'loada0 args NIL))
60+ (set! inst 'loadc0 args NIL))
5761 ((equal? args '(1))
58− (set! inst 'loada1 args NIL)))
59− (when (eq? inst 'loadc)
60− (cond ((equal? args '(0))
61− (set! inst 'loadc0 args NIL))
62− ((equal? args '(1))
63− (set! inst 'loadc1 args NIL)))))
64− (let ((lasti (car bc)))
65− (cond ((and (eq? inst 'brn)
66− (cond ((eq? lasti 'not)
67− (aset! e 0 (cons (car args) (cons 'brnn (cdr bc)))))
68− ((eq? lasti 'eq?)
69− (aset! e 0 (cons (car args) (cons 'brne (cdr bc)))))
70− (else NIL))))
71− (else
72− (aset! e 0 (nreconc (cons inst args) bc)))))))
62+ (set! inst 'loadc1 args NIL)))))
63+ (let ((lasti (car bc)))
64+ (cond ((and (eq? inst 'brn)
65+ (cond ((eq? lasti 'not)
66+ (aset! e 0 (cons (car args) (cons 'brnn (cdr bc)))))
67+ ((eq? lasti 'eq?)
68+ (aset! e 0 (cons (car args) (cons 'brne (cdr bc)))))
69+ (else NIL))))
70+ (else
71+ (aset! e 0 (nreconc (cons inst args) bc))))))
7372 e))
7473
7574 (defmacro (make-label e) `(gensym))
@@ -97,47 +96,46 @@ · 21 unmodified lines
9796 (if (eq? vi 'label)
9897 (begin (put! label-to-loc (aref v (+ i 1)) (size-of bcode))
9998 (set! i (+ i 2)))
100− (begin
101− (io-write bcode
102− (get Instructions
103− (if long?
104− (case vi
105− (jmp 'jmp.l)
106− (brne 'brne.l)
107− (brnn 'brnn.l)
108− (brn 'brn.l)
109− (else vi))
110− vi)))
111− (set! i (+ i 1)
112− nxt (and (< i n) (aref v i)))
113− (cond ((memq vi '(jmp brne brnn brn))
114− (put! fixup-to-label (size-of bcode) nxt)
115− (io-write bcode ((if long? s32 s16) 0))
116− (set! i (+ i 1)))
117− ((eq? vi 'bounda)
118− (io-write bcode (s32 nxt) :little-endian)
119− (set! i (+ i 1)))
120− ((num? nxt)
121− (case vi
122− ((loadv.l loadg.l setg.l loada.l seta.l
123− argc.l vargc.l call.l tcall.l loadc.l box.l)
124− (io-write bcode (s32 nxt) :little-endian)
125− (set! i (+ i 1)))
126−
127− ((optargs keyargs) ; 2 s32 args
128− (io-write bcode (s32 nxt) :little-endian)
129− (set! i (+ i 1))
99+ (io-write bcode
100+ (get Instructions
101+ (if long?
102+ (case vi
103+ (jmp 'jmp.l)
104+ (brne 'brne.l)
105+ (brnn 'brnn.l)
106+ (brn 'brn.l)
107+ (else vi))
108+ vi)))
109+ (set! i (+ i 1)
110+ nxt (and (< i n) (aref v i)))
111+ (cond ((memq vi '(jmp brne brnn brn))
112+ (put! fixup-to-label (size-of bcode) nxt)
113+ (io-write bcode ((if long? s32 s16) 0))
114+ (set! i (+ i 1)))
115+ ((eq? vi 'bounda)
116+ (io-write bcode (s32 nxt) :little-endian)
117+ (set! i (+ i 1)))
118+ ((num? nxt)
119+ (case vi
120+ ((loadv.l loadg.l setg.l loada.l seta.l
121+ argc.l vargc.l call.l tcall.l loadc.l box.l)
122+ (io-write bcode (s32 nxt) :little-endian)
123+ (set! i (+ i 1)))
124+
125+ ((optargs keyargs) ; 2 s32 args
126+ (io-write bcode (s32 nxt) :little-endian)
127+ (set! i (+ i 1))
128+ (io-write bcode (s32 (aref v i)) :little-endian)
129+ (set! i (+ i 1))
130+ (when (eq? vi 'keyargs)
130131 (io-write bcode (s32 (aref v i)) :little-endian)
131− (set! i (+ i 1))
132− (when (eq? vi 'keyargs)
133− (io-write bcode (s32 (aref v i)) :little-endian)
134− (set! i (+ i 1))))
132+ (set! i (+ i 1))))
135133
136− (else
137− ; other number arguments are always u8
138− (io-write bcode (u8 nxt))
139− (set! i (+ i 1)))))
140− (else NIL)))))
134+ (else
135+ ; other number arguments are always u8
136+ (io-write bcode (u8 nxt))
137+ (set! i (+ i 1)))))
138+ (else NIL))))
141139
142140 (for-each
143141 (λ (addr labl)
@@ -242,9 +240,9 @@ · 98 unmodified lines
242240 (compile-in g env NIL rhs)
243241 (bcode:stack g -1)
244242 (emit g 'set-car!))
245− (begin (compile-in g env NIL rhs)
246− (unless arg? (error (str "internal error: misallocated var " s)))
247− (emit g 'seta idx)))))))
243+ (compile-in g env NIL rhs)
244+ (unless arg? (error (str "internal error: misallocated var " s)))
245+ (emit g 'seta idx))))))
248246
249247 (def (box-vars g env)
250248 (let loop ((e env))
@@ -457,19 +455,19 @@ · 206 unmodified lines
457455 (begin (let {[nargs (compile-arglist g env (cdr x))]}
458456 (bcode:stack g (- nargs))
459457 (compile-builtin-call g env tail? x head b nargs)))
460− (begin (compile-in g env NIL head)
461− (bcode:stack g 1)
462− (let* {[nargs (compile-arglist g env (cdr x))]
463− [loc (and (sym? head) (lookup-sym head env 0))]
464− [fn (and (eq? loc 'global) (bound? head) (top-level-value head))]
465− [code (and (closure? fn) (fn-code fn))]
466− [argc? (and code (= (aref code 0) (get Instructions 'argc)))]
467− [argc (and argc? (aref code 1))]}
468− (unless (or (not argc) (= argc nargs))
469− (compile-error "arity error: expected " argc ", got " nargs))
470− (bcode:stack g (- nargs))
471− (bcode:stack g -1)
472− (emit g (if tail? 'tcall 'call) nargs))))))))
458+ (compile-in g env NIL head)
459+ (bcode:stack g 1)
460+ (let* {[nargs (compile-arglist g env (cdr x))]
461+ [loc (and (sym? head) (lookup-sym head env 0))]
462+ [fn (and (eq? loc 'global) (bound? head) (top-level-value head))]
463+ [code (and (closure? fn) (fn-code fn))]
464+ [argc? (and code (= (aref code 0) (get Instructions 'argc)))]
465+ [argc (and argc? (aref code 1))]}
466+ (unless (or (not argc) (= argc nargs))
467+ (compile-error "arity error: expected " argc ", got " nargs))
468+ (bcode:stack g (- nargs))
469+ (bcode:stack g -1)
470+ (emit g (if tail? 'tcall 'call) nargs)))))))
473471
474472 ;; lambda, main compilation loop
475473
@@ -738,10 +736,9 @@ · 262 unmodified lines
738736 (if (not kwa)
739737 (emit g 'optargs nreq
740738 (if atail (- nargs) nargs))
741− (begin
742− (bcode:indexfor g (map 'vec car kwa))
743− (emit g 'keyargs nreq nkwa
744− (if atail (- nargs) nargs)))))
739+ (bcode:indexfor g (map 'vec car kwa))
740+ (emit g 'keyargs nreq nkwa
741+ (if atail (- nargs) nargs))))
745742
746743 (cond ((> nargs 255) (emit g (if atail 'vargc.l 'argc.l) nargs))
747744 (atail (emit g 'vargc nargs))
src/system.sl+28−27
@@ -170,14 +170,13 @@ · 169 unmodified lines
170170 (print-type term)
171171 (newline))
172172 sigs)
173− (begin
174− (princ lpad)
175− (if kind
176− (begin (princ (caddr term))
177− (print-type "doc group"))
178− (begin (print term)
179− (print-type term)))
180− (newline)))
173+ (princ lpad)
174+ (if kind
175+ (begin (princ (caddr term))
176+ (print-type "doc group"))
177+ (print term)
178+ (print-type term))
179+ (newline))
181180 (newline))
182181
183182 (defmacro (help topic (:print-header help-print-header) . rest)
@@ -234,9 +233,9 @@ · 50 unmodified lines
234233 (princ lpad)
235234 (princ (cons term sig)))
236235 sigs)
237− (begin (newline)
238− (princ lpad)
239− (princ term))))
236+ (newline)
237+ (princ lpad)
238+ (princ term)))
240239 (def (first-line s)
241240 (str-sub s 0 (str-find s "\n")))
242241 (def (doc-group? k)
@@ -1325,9 +1324,8 @@ · 1082 unmodified lines
13251324 (reverse! acc)
13261325 (if (has? ta (car l))
13271326 (loop (cdr l) acc)
1328− (begin
1329− (put! ta (car l) T)
1330− (loop (cdr l) (cons (car l) acc))))))))
1327+ (put! ta (car l) T)
1328+ (loop (cdr l) (cons (car l) acc)))))))
13311329
13321330 (def (find-if pred lst (:key identity)
13331331 (:start 0)
@@ -1793,16 +1791,16 @@ · 459 unmodified lines
17931791 (newline)
17941792 'ignored
17951793 'done)
1796− (begin (print 0)
1797− (newline)
1798− 'else))
1794+ (print 0)
1795+ (newline)
1796+ 'else)
17991797 ; ‼ 1
18001798 ; ↳ done»
18011799 :doc-group syntax
18021800 :doc-see prog1
18031801 (cons '$begin body))
18041802
1805−(defmacro (if cond then else)
1803+(defmacro (if cond then . else)
18061804 «Return the result of `then` if `cond` evaluated as "true", `else`
18071805 otherwise.
18081806
@@ -1813,14 +1811,18 @@ · 4 unmodified lines
18131811 Examples:
18141812
18151813 (def x '(1))
1816− (if x 'yes 0)
1814+ (if x (begin (print "yep!") (newline) 'yes) 0)
1815+ ; ‼ yep!
18171816 ; ↳ yes
1818− (if (str? x) 1 'no)
1817+ (if (str? x) 1 (print "nope!") (newline) 'no)
1818+ ; ‼ nope!
18191819 ; ↳ no»
18201820 :doc-group syntax
18211821 :doc-see when
18221822 :doc-see unless
1823− (list '$if cond then else))
1823+ (unless else
1824+ (arg-error "if without an else branch"))
1825+ (list '$if cond then (cons 'begin else)))
18241826
18251827 (defmacro (when cond . body)
18261828 «Shorthand for `(if cond body NIL)`.
@@ -2010,9 +2012,8 @@ · 183 unmodified lines
20102012 (if ,test-expr
20112013 (begin
20122014 ,@(cdr test-spec))
2013− (begin
2014− ,@commands
2015− (loop# ,.steps))))))
2015+ ,@commands
2016+ (loop# ,.steps)))))
20162017 (loop# ,.inits))))
20172018
20182019 ; SRFI 8
@@ -3073,9 +3074,9 @@ · 1054 unmodified lines
30733074 (when (void? v)
30743075 (*prompt*)
30753076 (io-flush *io-out*))
3076− (begin (print V)
3077− (set! that V)
3078− (newline)))
3077+ (print V)
3078+ (set! that V)
3079+ (newline))
30793080 #.(void)))))
30803081 (def (reploop)
30813082 (when (trycatch (prompt)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t