├── HISTORY ├── LICENSE ├── MASCOT.png ├── Makefile ├── PREHISTORY ├── README ├── README.md ├── README.s9core ├── TODO ├── _csums ├── attic ├── S9Book ├── S9Book-bw ├── catch.scm ├── find-help-path.scm ├── find-help.scm ├── procedures.scm ├── s9symbols.scm └── sys-plan9 │ ├── plan9-tools.scm │ ├── plan9.c │ ├── plan9.scm │ ├── s9-ffi.c │ ├── s9-ffi.h │ └── util.scm ├── config.scm ├── configure ├── contrib ├── bottles.scm ├── c2html.scm ├── ccode.css ├── draw-tree.scm ├── format-test.scm ├── format.scm ├── format.txt ├── help.scm ├── pretty-print.scm ├── prolog-test.scm ├── prolog.scm ├── queens.scm ├── s9sos.scm ├── s9sos.txt ├── scheme.css ├── scm2html.scm ├── string-locate.scm └── zebra.scm ├── ext ├── csv │ ├── csv.c │ └── csv.scm ├── curses │ ├── curses.c │ ├── curses.scm │ └── get-line.scm ├── sys-plan9 │ ├── plan9-tools.scm │ ├── plan9.c │ ├── plan9.scm │ ├── s9-ffi.c │ ├── s9-ffi.h │ └── util.scm └── sys-unix │ ├── append-to-output-file.scm │ ├── flush-output-port.scm │ ├── inet-server.scm │ ├── mode-to-string.scm │ ├── parse-optionsb.scm │ ├── runtime-stats.scm │ ├── search-path.scm │ ├── spawn-command.scm │ ├── spawn-shell-command.scm │ ├── standard-error.scm │ ├── time.scm │ ├── unix-tools.scm │ ├── unix.c │ └── unix.scm ├── help ├── INDEX ├── abs ├── adjoin ├── amb ├── and ├── and-letstar ├── append ├── appendb ├── apply ├── argv ├── assp ├── assq ├── basename ├── begin ├── bit-op ├── bit0 ├── bitwise-and ├── booleanp ├── bottles ├── c2html ├── caar ├── call-with-current-continuation ├── call-with-input-file ├── car ├── case ├── catch ├── catch-errors ├── cdf ├── cdr ├── char-alphabeticp ├── char-cieqp ├── char-plot ├── char-to-integer ├── char-upcase ├── chareqp ├── charp ├── choose ├── close-input-port ├── collect ├── combine ├── command-line ├── complement ├── cond ├── cond-expand ├── cons ├── count ├── csv │ ├── INDEX │ └── csv_read ├── current-error-port ├── current-input-port ├── curses │ ├── INDEX │ ├── curs_addch │ ├── curs_attroff │ ├── curs_cbreak │ ├── curs_clear │ ├── curs_color-set │ ├── curs_cursoff │ ├── curs_delch │ ├── curs_endwin │ ├── curs_flushinp │ └── get-line ├── data-structures ├── define ├── define-class ├── define-matcher ├── define-structure ├── define-syntax ├── delete-file ├── depth ├── dirname ├── disassemble ├── display ├── displaystar ├── do ├── draw-tree ├── dump-image ├── duplicates ├── environ ├── environment-variable ├── eof-objectp ├── eq ├── eqp ├── equal-cip ├── equalp ├── eqvp ├── erf ├── error ├── eval ├── exact-to-inexact ├── exactp ├── exists ├── exp ├── explode ├── exponent ├── expt ├── factor ├── factorial ├── file-existsp ├── filter ├── find-help-page ├── flatten ├── floor ├── fluid-let ├── fold-left ├── fold-right ├── for-all ├── for-each ├── force ├── format ├── format-time ├── gcd ├── gensym ├── get-line ├── get-prop ├── graph-tools ├── group ├── help ├── htmlify-char ├── hyper ├── id ├── if ├── ifstar ├── implode ├── input-portp ├── integer-sqrt ├── integer-to-binary-string ├── intersection ├── iota ├── keyword-value ├── lambda ├── leap-yearp ├── length ├── let ├── letrec ├── letrecstar ├── letslashcc ├── letstar ├── list ├── list-copy ├── list-ref ├── list-tail ├── list-to-set ├── listp ├── listq ├── load ├── load-from-library ├── locate-file ├── loutify-char ├── macro-expand ├── make-array ├── make-canvas ├── make-hash-table ├── make-help-index ├── make-partitions ├── make-queue ├── make-rbt ├── make-stream ├── make-string ├── make-vector ├── map ├── max ├── mean ├── median ├── memoize ├── memp ├── memq ├── merge ├── mergesort ├── minus ├── mode ├── module ├── name-to-file-name ├── ndf ├── newline ├── not ├── nullp ├── number-to-string ├── numberp ├── open-append-file ├── open-input-file ├── open-output-file ├── or ├── package ├── pairp ├── partition ├── peek-char ├── permute ├── plus ├── position ├── pretty-print ├── print ├── procedurep ├── programp ├── prolog ├── proper-timep ├── pushb ├── quartile ├── quasiquote ├── queens ├── queue ├── quicksort ├── quit ├── quote ├── quotient ├── r4rs-procedures ├── random ├── random-sort ├── range ├── re-comp ├── read ├── read-char ├── read-file ├── read-from-string ├── read-line ├── record ├── remove ├── replace ├── require-extension ├── reverse ├── reverseb ├── runstar ├── s9_bytecode ├── scan-help-pages ├── scm2html ├── set-carb ├── set-cdrb ├── set-difference ├── set-input-portb ├── setb ├── sieve ├── sort ├── split ├── split-url ├── sqrt ├── starstar ├── stat-tools ├── stats ├── stddev ├── string ├── string-append ├── string-copy ├── string-digest ├── string-expand ├── string-fillb ├── string-find ├── string-find-last ├── string-last-position ├── string-length ├── string-locate ├── string-map ├── string-parse ├── string-position ├── string-prefixeqp ├── string-ref ├── string-reverse ├── string-scan ├── string-setb ├── string-split ├── string-to-list ├── string-to-number ├── string-to-symbol ├── string-translate ├── string-unsplit ├── string-upcase ├── stringeqp ├── stringltp ├── stringp ├── sublist ├── subsetp ├── substitute ├── substring ├── subvector ├── sum ├── symbol-to-string ├── symbolp ├── symbols ├── syntax-extensions ├── syntax-rules ├── sys-plan9 │ ├── plan9-tools │ └── util ├── sys-unix │ ├── INDEX │ ├── append-to-output-file │ ├── char-readyp │ ├── flush-output-port │ ├── inet-server │ ├── mode-to-string │ ├── parse-optionsb │ ├── runtime-stats │ ├── search-path │ ├── spawn-command │ ├── spawn-shell-command │ ├── standard-error-port │ ├── sys_access │ ├── sys_catch-errors │ ├── sys_chdir │ ├── sys_chmod │ ├── sys_chown │ ├── sys_command-line │ ├── sys_dup │ ├── sys_errno │ ├── sys_execv │ ├── sys_exit │ ├── sys_fileno │ ├── sys_flush │ ├── sys_fork │ ├── sys_get-magic-value │ ├── sys_getcwd │ ├── sys_getenv │ ├── sys_getgrnam │ ├── sys_getpgid │ ├── sys_getpid │ ├── sys_getpwent │ ├── sys_getpwnam │ ├── sys_gettimeofday │ ├── sys_getuid │ ├── sys_group-name │ ├── sys_inet-connect │ ├── sys_inet-getpeername │ ├── sys_inet-listen │ ├── sys_kill │ ├── sys_link │ ├── sys_lock │ ├── sys_lseek │ ├── sys_make-input-port │ ├── sys_mkdir │ ├── sys_open │ ├── sys_pipe │ ├── sys_read │ ├── sys_readdir │ ├── sys_readlink │ ├── sys_rename │ ├── sys_rmdir │ ├── sys_select │ ├── sys_setuid │ ├── sys_stat │ ├── sys_stat-name │ ├── sys_stat-regularp │ ├── sys_strerror │ ├── sys_symlink │ ├── sys_system │ ├── sys_umask │ ├── sys_unlink │ ├── sys_unlock │ ├── sys_user-name │ ├── sys_usleep │ ├── sys_utimes │ ├── sys_wait │ ├── time │ └── unix-tools ├── system ├── system-command ├── t-sort ├── tagbody ├── take ├── thread-create ├── time-add ├── time-to-unix-time ├── transpose ├── tree-copy ├── tree-equalp ├── tree-map ├── troffify-char ├── type-case ├── union ├── unix-time-to-time ├── unsort ├── url-decode ├── variance ├── vector ├── vector-append ├── vector-copy ├── vector-fillb ├── vector-length ├── vector-map ├── vector-ref ├── vector-setb ├── vector-to-list ├── vectorp ├── void ├── when ├── while ├── with-input-from-file ├── write ├── write-char ├── write-to-string ├── zebra └── zerop ├── lib ├── _template ├── adjoin.scm ├── amb.scm ├── amk.scm ├── and-letstar.scm ├── appendb.scm ├── array.scm ├── assp.scm ├── basename.scm ├── bitops.scm ├── bitwise-ops.scm ├── cdf.scm ├── char-canvas.scm ├── char-plot.scm ├── choose.scm ├── collect.scm ├── combine.scm ├── cond-expand.scm ├── count.scm ├── data-structures.scm ├── define-structure.scm ├── depth.scm ├── dirname.scm ├── disassemble.scm ├── displaystar.scm ├── duplicates.scm ├── equal-cip.scm ├── erf.scm ├── exists.scm ├── explode.scm ├── factor.scm ├── factorial.scm ├── filter.scm ├── find-help-page.scm ├── flatten.scm ├── fluid-let-sr.scm ├── fluid-let.scm ├── for-all.scm ├── format-time.scm ├── get-prop.scm ├── graph-tools.scm ├── group.scm ├── hash-table.scm ├── hof.scm ├── htmlify-char.scm ├── hyper.scm ├── id.scm ├── implode.scm ├── integer-sqrt.scm ├── integer-to-binary-string.scm ├── intersection.scm ├── io-tools.scm ├── iota.scm ├── keyword-value.scm ├── leap-yearp.scm ├── letcc.scm ├── letrecstar.scm ├── list-copy.scm ├── list-to-set.scm ├── list-tools.scm ├── listq.scm ├── loutify-char.scm ├── make-help-index.scm ├── make-partitions.scm ├── matcher.scm ├── math-tools.scm ├── mean.scm ├── median.scm ├── memoize.scm ├── memp.scm ├── merge.scm ├── mergesort.scm ├── mode.scm ├── name-to-file-name.scm ├── ndf.scm ├── package.scm ├── partition.scm ├── permute.scm ├── position.scm ├── programp.scm ├── proper-timep.scm ├── quartile.scm ├── queue.scm ├── quicksort.scm ├── random-sort.scm ├── random.scm ├── range.scm ├── rb-tree.scm ├── read-file.scm ├── read-from-string.scm ├── read-line.scm ├── records.scm ├── regex.scm ├── remove.scm ├── replace.scm ├── scan-help-pages.scm ├── set-difference.scm ├── set-tools.scm ├── setters.scm ├── sieve.scm ├── simple-modules.scm ├── sort.scm ├── split-url.scm ├── split.scm ├── stat-tools.scm ├── stddev.scm ├── streams.scm ├── string-case.scm ├── string-digest.scm ├── string-expand.scm ├── string-find-last.scm ├── string-find.scm ├── string-last-position.scm ├── string-map.scm ├── string-parse.scm ├── string-position.scm ├── string-prefixeqp.scm ├── string-reverse.scm ├── string-scan.scm ├── string-split.scm ├── string-tools.scm ├── string-translate.scm ├── string-unsplit.scm ├── sublist.scm ├── subsetp.scm ├── substitute.scm ├── subvector.scm ├── sum.scm ├── symbols.scm ├── syntax-extensions.scm ├── syntax-rules.scm ├── t-sort.scm ├── tagbody.scm ├── take.scm ├── threads.scm ├── time-ops.scm ├── time-to-unix-time.scm ├── transpose.scm ├── tree-copy.scm ├── tree-equalp.scm ├── tree-map.scm ├── troffify-char.scm ├── type-case.scm ├── union.scm ├── unix-time-to-time.scm ├── unsort.scm ├── url-decode.scm ├── variance.scm ├── vector-map.scm ├── vector-tools.scm ├── when.scm ├── while.scm └── write-to-string.scm ├── mkfile ├── prog ├── adventure.adv ├── adventure.intro ├── advgen.scm ├── advgen.txt ├── c2html1.scm ├── cols.scm ├── dupes.scm ├── edoc.css ├── edoc.scm.edoc ├── edocbook.tr ├── htmlify.scm ├── rdb.scm ├── s9help.scm ├── s9hts.scm ├── s9resolve.scm ├── scm2html1.scm ├── scmpp.scm └── soccat.scm ├── s9.1 ├── s9.1.txt ├── s9.c ├── s9.scm ├── s9core.c ├── s9core.h ├── s9core.txt ├── s9ext.h ├── s9import.h └── util ├── blurb ├── book ├── categories.html ├── check-descr.scm ├── descriptions ├── dirhead ├── dirtail ├── libhead ├── libtail ├── libtest.scm ├── libtest.sh ├── make-cats.scm ├── make-docs ├── make-html ├── mktoc.sed ├── pagehead ├── pagetail ├── realtest.scm ├── rp_html ├── rpp.c ├── s9.rc ├── srtest.scm ├── stress-tests.tgz ├── systest.scm └── test.scm /MASCOT.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bakul/s9fes/57d9369595acabe89702e0196234dbe21900f6ce/MASCOT.png -------------------------------------------------------------------------------- /PREHISTORY: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bakul/s9fes/57d9369595acabe89702e0196234dbe21900f6ce/PREHISTORY -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This is a mirror of https://t3x.org/s9fes + plan9 related changes. 2 | See README in this directory for details on s9fes. The t3x.org 3 | branch tracks the latest sources from t3x.org/s9fes. 4 | 5 | If you have any changes to s9fes, please sense them directly 6 | to Nils M Holm. If you have plan9 related changes, you can 7 | send a pull request to this repo. 8 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | 2 | - clean up the library 3 | 4 | - review systest 5 | 6 | - EDOC: handle #| |# comments correctly 7 | handle white space in block comments properly 8 | 9 | -------------------------------------------------------------------------------- /attic/find-help-path.scm: -------------------------------------------------------------------------------- 1 | ; Scheme 9 from Empty Space, Unix Function Library 2 | ; By Nils M Holm, 2010, 2018 3 | ; In the public domain 4 | ; 5 | ; (find-help-path) ==> string | #f 6 | ; 7 | ; Returns the directory in which the online help pages are stored 8 | ; of #F when the pages cannot be located. 9 | ; 10 | ; (Example): (find-help-path) ==> "/usr/local/share/s9fes/help" 11 | 12 | (require-extension sys-unix) 13 | 14 | (define (find-help-path) 15 | (let loop ((dirs *library-path*)) 16 | (if (null? dirs) 17 | #f 18 | (let ((path (string-append (car dirs) "/help"))) 19 | (if (and (file-exists? path) 20 | (sys:stat-directory? path)) 21 | path 22 | (loop (cdr dirs))))))) 23 | -------------------------------------------------------------------------------- /attic/sys-plan9/plan9-tools.scm: -------------------------------------------------------------------------------- 1 | ; Scheme 9 from Empty Space, Function Library 2 | ; By Nils M Holm, 2010,2015 3 | ; Placed in the Public Domain 4 | ; 5 | ; Convenience file to load the Plan 9 programming procedures. 6 | 7 | ; (load-from-library "append-to-output-file.scm") 8 | (load-from-library "basename.scm") 9 | (load-from-library "dirname.scm") 10 | ; (load-from-library "find-help-path.scm") 11 | ; (load-from-library "flush-output-port.scm") 12 | (load-from-library "format-time.scm") 13 | (load-from-library "leap-yearp.scm") 14 | ; (load-from-library "mode-to-string.scm") 15 | ; (load-from-library "parse-optionsb.scm") 16 | (load-from-library "proper-timep.scm") 17 | ; (load-from-library "search-path.scm") 18 | ; (load-from-library "spawn-command.scm") 19 | ; (load-from-library "spawn-shell-command.scm") 20 | ; (load-from-library "standard-error.scm") 21 | (load-from-library "time-to-unix-time.scm") 22 | (load-from-library "unix-time-to-time.scm") 23 | -------------------------------------------------------------------------------- /attic/sys-plan9/s9-ffi.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FFI: conversion functions between bignums and various C int types 3 | */ 4 | cell make_ulong_integer(unsigned long long i); 5 | cell make_long_integer(long long i); 6 | long int32_value(char *src, cell x); 7 | unsigned long uint32_value(char *src, cell x); 8 | long long int64_value(char *src, cell x); 9 | unsigned long long uint64_value(char *src, cell x); 10 | -------------------------------------------------------------------------------- /attic/sys-plan9/util.scm: -------------------------------------------------------------------------------- 1 | ; 2 | (require-extension sys-plan9) 3 | 4 | (define (pwd) 5 | (let* ((fd (sys:open "." 0)) (cwd (sys:fd->path fd))) 6 | (sys:close fd) 7 | cwd)) 8 | 9 | (define (! x) 10 | (let ((a (string-split #\space x))) 11 | (if (not (eq? #\/ (string-ref (car a) 0))) 12 | (set-car! a (string-append "/bin/" (car a)))) 13 | (let ((pid (sys:fork))) 14 | (cond ((zero? pid) (sys:exec (car a) (cdr a))) 15 | ((> pid 0) (sys:await)))))) 16 | 17 | (define (getenv x) 18 | (if (symbol? x) (set! x (symbol->string x))) 19 | (let* ((fd (sys:open (string-append "/env/" x) 0)) 20 | (val (sys:read fd 1000))) 21 | (sys:close fd) 22 | val)) 23 | 24 | ; 25 | ; Useful during developing 26 | ; 27 | (define (remake) 28 | (and (! "mk all") (sys:exec "./s9" '()))) 29 | -------------------------------------------------------------------------------- /config.scm: -------------------------------------------------------------------------------- 1 | ; Configuration file for the S9 default heap image. 2 | ; Choose your extras or add your own stuff. 3 | 4 | (load-from-library "help.scm") 5 | (load-from-library "pretty-print.scm") 6 | (load-from-library "draw-tree.scm") 7 | 8 | (load-from-library "hash-table.scm") 9 | (load-from-library "keyword-value.scm") 10 | 11 | (load-from-library "graph-tools.scm") 12 | (load-from-library "io-tools.scm") 13 | (load-from-library "list-tools.scm") 14 | (load-from-library "math-tools.scm") 15 | (load-from-library "set-tools.scm") 16 | (load-from-library "stat-tools.scm") 17 | (load-from-library "string-tools.scm") 18 | (load-from-library "syntax-extensions.scm") 19 | (load-from-library "vector-tools.scm") 20 | -------------------------------------------------------------------------------- /configure: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | cat <path fd))) 6 | (sys:close fd) 7 | cwd)) 8 | 9 | (define (! x) 10 | (let ((a (string-split #\space x))) 11 | (if (not (eq? #\/ (string-ref (car a) 0))) 12 | (set-car! a (string-append "/bin/" (car a)))) 13 | (let ((pid (sys:fork))) 14 | (cond ((zero? pid) (sys:exec (car a) (cdr a))) 15 | ((> pid 0) (sys:await)))))) 16 | 17 | (define (getenv x) 18 | (if (symbol? x) (set! x (symbol->string x))) 19 | (let* ((fd (sys:open (string-append "/env/" x) 0)) 20 | (val (sys:read fd 1000))) 21 | (sys:close fd) 22 | val)) 23 | 24 | ; 25 | ; Useful during developing 26 | ; 27 | (define (remake) 28 | (and (! "mk all") (sys:exec "./s9" '()))) 29 | -------------------------------------------------------------------------------- /ext/sys-unix/flush-output-port.scm: -------------------------------------------------------------------------------- 1 | ; Scheme 9 from Empty Space, Unix Function Library 2 | ; By Nils M Holm, 2010 3 | ; Placed in the Public Domain 4 | ; 5 | ; (flush-output-port output-port) ==> unspecific 6 | ; (flush-output-port) ==> unspecific 7 | ; 8 | ; Flush the given output port by writing all pending output to 9 | ; the associated file descriptor. When no port is specified, 10 | ; flush (current-output-port). 11 | ; 12 | ; (Example): (flush-output-port) ==> unspecific 13 | 14 | (require-extension sys-unix) 15 | 16 | (define (flush-output-port . port) 17 | (if (null? port) 18 | (sys:flush (current-output-port)) 19 | (sys:flush (car port)))) 20 | -------------------------------------------------------------------------------- /ext/sys-unix/unix-tools.scm: -------------------------------------------------------------------------------- 1 | ; Scheme 9 from Empty Space, Unix Function Library 2 | ; By Nils M Holm, 2010 3 | ; Placed in the Public Domain 4 | ; 5 | ; Convenience file to load the Unix programming procedures. 6 | 7 | (load-from-library "append-to-output-file.scm") 8 | (load-from-library "basename.scm") 9 | (load-from-library "dirname.scm") 10 | (load-from-library "flush-output-port.scm") 11 | (load-from-library "format-time.scm") 12 | (load-from-library "leap-yearp.scm") 13 | (load-from-library "mode-to-string.scm") 14 | (load-from-library "parse-optionsb.scm") 15 | (load-from-library "proper-timep.scm") 16 | (load-from-library "search-path.scm") 17 | (load-from-library "spawn-command.scm") 18 | (load-from-library "spawn-shell-command.scm") 19 | (load-from-library "standard-error.scm") 20 | (load-from-library "time-to-unix-time.scm") 21 | (load-from-library "unix-time-to-time.scm") 22 | -------------------------------------------------------------------------------- /help/abs: -------------------------------------------------------------------------------- 1 | R4RS 6.5.5 (abs number) ==> number 2 | 3 | ABS returns the magnitude of its argument. 4 | 5 | (abs -7) ==> 7 6 | -------------------------------------------------------------------------------- /help/adjoin: -------------------------------------------------------------------------------- 1 | S9 LIB (adjoin object list) ==> list 2 | 3 | Add an element to a set. 4 | 5 | (adjoin 'x '(a b c)) ==> (x a b c) 6 | (adjoin 'c '(a b c)) ==> (a b c) 7 | -------------------------------------------------------------------------------- /help/and: -------------------------------------------------------------------------------- 1 | R4RS 4.2.1 (and ...) ==> object 2 | 3 | The s are evaluated from left to right, and the value 4 | of the first expression that evaluates to a false value is returned. 5 | Any remaining expressions are not evaluated. If all the expressions 6 | evaluate to true values, the value of the last expression is returned. 7 | If there are no expressions then #T is returned. 8 | 9 | (and (= 2 2) (> 2 1)) ==> #t 10 | (and (= 2 2) (< 2 1)) ==> #f 11 | (and 1 2 'c '(f g)) ==> (f g) 12 | (and) ==> #t 13 | -------------------------------------------------------------------------------- /help/append: -------------------------------------------------------------------------------- 1 | R4RS 6.3 (append list ...) ==> list 2 | (append list ... object) ==> object 3 | 4 | Returns a list consisting of the elements of the first list followed 5 | by the elements of the other lists. 6 | 7 | (append '(x) '(y)) ==> (x y) 8 | (append '(a) '(b c d)) ==> (a b c d) 9 | (append '(a (b)) '((c))) ==> (a (b) (c)) 10 | 11 | The resulting list is always newly allocated, except that it shares 12 | structure with the last list argument. The last argument may actually 13 | be any object; an improper list results if the last argument is not 14 | a proper list. 15 | 16 | (append '(a b) '(c . d)) ==> (a b c . d) 17 | (append '() 'a) ==> a 18 | -------------------------------------------------------------------------------- /help/appendb: -------------------------------------------------------------------------------- 1 | S9 LIB (append! list ...) ==> unspecific 2 | (append! list ... object) ==> unspecific 3 | 4 | APPEND! is like APPEND, but appends the LISTs destructively. 5 | It destroys all but the last object passed to it and returns 6 | an unspecific value. The append!ed list will be stored in the 7 | first LIST, which should be bound to a symbol or it will not 8 | be accessible after the operation. The first LIST may not be 9 | '(). 10 | 11 | (let ((a (list 1 2 3))) 12 | (append! a (list 4 5 6) 'end) 13 | a) ==> (1 2 3 4 5 6 . end) 14 | -------------------------------------------------------------------------------- /help/apply: -------------------------------------------------------------------------------- 1 | R4RS 6.8 (apply procedure list) ==> object 2 | (apply procedure object ... list) ==> object 3 | 4 | The first form calls PROCEDURE with the elements of LIST as 5 | the actual arguments. The second form is a generalization of 6 | the first that calls PROCEDURE with the elements of the list 7 | (append (list object ...) LIST) as the actual arguments. 8 | 9 | (apply + (list 3 4)) ==> 7 10 | 11 | (define (compose f g) 12 | (lambda args (f (apply g args))))) 13 | ((compose - *) 5 7) ==> -35 14 | -------------------------------------------------------------------------------- /help/argv: -------------------------------------------------------------------------------- 1 | S9fES (argv integer) ==> string | #f 2 | 3 | Return the value of the command line argument at the given position. 4 | If the there are less than INTEGER+1 arguments, return #F. The first 5 | argument is at position 0. 6 | 7 | This procedure is deprecated. Use COMMAND-LINE instead. 8 | 9 | (argv 0) ==> "first-argument" 10 | -------------------------------------------------------------------------------- /help/assp: -------------------------------------------------------------------------------- 1 | S9 LIB (assp procedure^2 object alist) ==> object | #f 2 | 3 | Find the first member X of an alist for which 4 | 5 | (procedure^2 object (car X)) 6 | 7 | holds. When no such member exists, return #F. 8 | 9 | (assp char=? #\b '((#\a . 1) (#\b . 2))) ==> (#\b . 2) 10 | -------------------------------------------------------------------------------- /help/basename: -------------------------------------------------------------------------------- 1 | S9 LIB (basename string) ==> string 2 | (basename string string2) ==> string 3 | 4 | Return the rightmost component of the Unix path name given in 5 | STRING. When STRING2 is given also remove a STRING2 suffix 6 | (if any) from STRING. 7 | 8 | (basename "/foo/bar/baz") ==> "baz" 9 | (basename "/goo/bar.Z" ".Z") ==> "bar" 10 | -------------------------------------------------------------------------------- /help/begin: -------------------------------------------------------------------------------- 1 | R4RS 4.2.3 (begin ...) ==> object 2 | 3 | The s are evaluated sequentially from left to right, 4 | and the value of the last expression is returned. This expression 5 | type is used to sequence side effects such as input and output. 6 | 7 | (define x 0) 8 | 9 | (begin (set! x 5) 10 | (+ x 1)) ==> 6 11 | 12 | (begin (display "4 plus 1 equals ") 13 | (display (+ 4 1))) ==> unspecific 14 | ; side effect: print 4 plus 1 equals 5 15 | 16 | S9fES allows BEGIN to take zero arguments, returning an unspecific 17 | value. 18 | -------------------------------------------------------------------------------- /help/booleanp: -------------------------------------------------------------------------------- 1 | R4RS 6.1 (boolean? object) ==> boolean 2 | 3 | BOOLEAN? returns #T if OBJECT is either #T or #F and returns #F 4 | otherwise. 5 | 6 | (boolean? #f) ==> #t 7 | (boolean? 0) ==> #f 8 | (boolean? '()) ==> #f 9 | -------------------------------------------------------------------------------- /help/bottles: -------------------------------------------------------------------------------- 1 | S9 LIB (bottles) ==> list 2 | (bottles tens ones) ==> list 3 | 4 | Generate the lyrics of the "99 bottles of beer" song using only 5 | DEFINE-SYNTAX/SYNTAX-RULES (and a little bit of arithmetics). 6 | 7 | (bottles) ==> ((99 bottles of beer on the wall) 8 | (99 bottles of beer) 9 | (take one down and pass it around) 10 | (98 bottles of beer on the wall) 11 | ... 12 | (0 bottles of beer on the wall) 13 | (0 bottles of beer) 14 | (go to the store buy some more) 15 | (99 bottles of beer on the wall)) 16 | -------------------------------------------------------------------------------- /help/caar: -------------------------------------------------------------------------------- 1 | R4RS 6.3 (caar pair) ==> object 2 | (cadr pair) ==> object 3 | ... 4 | (cdddar pair) ==> object 5 | (cddddr pair) ==> object 6 | 7 | These procedures are compositions of car and cdr, where for example 8 | caddr could be defined by 9 | 10 | (define (caddr x) (car (cdr (cdr x)))). 11 | 12 | Arbitrary compositions, up to four deep, are provided. There are 13 | twenty-eight of these procedures in all. 14 | -------------------------------------------------------------------------------- /help/car: -------------------------------------------------------------------------------- 1 | R4RS 6.3 (car pair) ==> object 2 | 3 | Returns the contents of the car field of PAIR. Note that it is an 4 | error to take the car of the empty list. 5 | 6 | (car '(a b c)) ==> a 7 | (car '((a) b c d)) ==> (a) 8 | (car '(1 . 2)) ==> 1 9 | (car '()) ==> error 10 | -------------------------------------------------------------------------------- /help/cdf: -------------------------------------------------------------------------------- 1 | S9 LIB (cdf real) ==> real 2 | 3 | (load-from-library "cdf.scm") 4 | 5 | Compute the quantile of the given standard deviation (cumulative 6 | distribution function). Results will get flaky beyond 5th standard 7 | deviation; see ERF for details. 8 | 9 | (cdf 0) ==> 0.5 10 | -------------------------------------------------------------------------------- /help/cdr: -------------------------------------------------------------------------------- 1 | R4RS 6.3 (cdr pair) ==> object 2 | 3 | Returns the contents of the cdr field of PAIR. Note that it is an 4 | error to take the cdr of the empty list. 5 | 6 | (cdr '((a) b c d)) ==> (b c d) 7 | (cdr '(1 . 2)) ==> 2 8 | (cdr '()) ==> error 9 | -------------------------------------------------------------------------------- /help/char-alphabeticp: -------------------------------------------------------------------------------- 1 | R4RS 6.6 (char-alphabetic? char) ==> boolean 2 | (char-numeric? char) ==> boolean 3 | (char-whitespace? char) ==> boolean 4 | (char-upper-case? char) ==> boolean 5 | (char-lower-case? char) ==> boolean 6 | 7 | These procedures return #T if their arguments are alphabetic, 8 | numeric, whitespace, upper case, or lower case characters, respectively, 9 | otherwise they return #F. The following remarks, which are specific 10 | to the ASCII character set, are intended only as a guide: The 11 | alphabetic characters are the 52 upper and lower case letters. The 12 | numeric characters are the ten decimal digits. The whitespace 13 | characters are space, tab, line feed, form feed, and carriage return. 14 | -------------------------------------------------------------------------------- /help/char-cieqp: -------------------------------------------------------------------------------- 1 | R4RS 6.6 (char-ci=? char1 char2) ==> boolean 2 | (char-ci boolean 3 | (char-ci>? char1 char2) ==> boolean 4 | (char-ci<=? char1 char2) ==> boolean 5 | (char-ci>=? char1 char2) ==> boolean 6 | 7 | These procedures are similar to CHAR=? et cetera, but they treat 8 | upper case and lower case letters as the same. For example, 9 | 10 | (char-ci=? #\A #\a) ==> #t. 11 | 12 | Some implementations may generalize these procedures to take more 13 | than two arguments, as with the corresponding numerical predicates. 14 | 15 | The S9fES versions of these procedures do accept more than two 16 | arguments. 17 | -------------------------------------------------------------------------------- /help/char-to-integer: -------------------------------------------------------------------------------- 1 | R4RS 6.6 (char->integer char) ==> integer 2 | (integer->char integer) ==> char 3 | 4 | Given a character, CHAR->INTEGER returns an integer representation 5 | of the character. Given an integer that is the image of a character 6 | under CHAR->INTEGER, INTEGER->CHAR returns that character. These 7 | procedures implement injective order isomorphisms between the set 8 | of characters under the CHAR<=? ordering and some subset of the 9 | integers under the <= ordering. That is, if 10 | 11 | (char<=? a b) ==> #t 12 | and (<= x y) ==> #t 13 | 14 | and X and Y are in the domain of INTEGER->CHAR, then 15 | 16 | (<= (char->integer a) 17 | (char->integer b)) ==> #t 18 | and (char<=? (integer->char x) 19 | (integer->char y)) ==> #t. 20 | -------------------------------------------------------------------------------- /help/char-upcase: -------------------------------------------------------------------------------- 1 | R4RS 6.6 (char-upcase char) ==> char 2 | (char-downcase char) ==> char 3 | 4 | These procedures return a character CHAR2 such that 5 | 6 | (char-ci=? char char2) ==> #t. 7 | 8 | In addition, if CHAR is alphabetic, then the result of CHAR-UPCASE 9 | is upper case and the result of CHAR-DOWNCASE is lower case. 10 | -------------------------------------------------------------------------------- /help/charp: -------------------------------------------------------------------------------- 1 | R4RS 6.6 (char? object) ==> boolean 2 | 3 | Returns #T if OBJECT is a character, otherwise returns #F. 4 | -------------------------------------------------------------------------------- /help/choose: -------------------------------------------------------------------------------- 1 | S9 LIB (choose integer1 integer2) ==> integer 2 | 3 | Return the binomial coefficient ("n choose k") of INTEGER1 (n) 4 | and INTEGER2 (k), i.e. the number of unique k-tuples that can be 5 | choosen without repetition from a set of n elements. INTEGER2 (k) 6 | must be positive. 7 | 8 | (choose 23 1) ==> 23 9 | (choose 23 2) ==> 253 10 | (choose 23 3) ==> 1771 11 | -------------------------------------------------------------------------------- /help/close-input-port: -------------------------------------------------------------------------------- 1 | R4RS 6.10 (close-input-port input-port) ==> unspecific 2 | (close-output-port output-port) ==> unspecific 3 | 4 | Closes the file associated with INPUT-PORT or OUTPUT-PORT respectively, 5 | rendering the port incapable of delivering or accepting characters. 6 | 7 | These routines have no effect if the file has already been closed. 8 | The value returned is unspecified. 9 | -------------------------------------------------------------------------------- /help/collect: -------------------------------------------------------------------------------- 1 | S9 LIB (collect procedure list) ==> list 2 | 3 | Collect elements from LIST as long as two subsequent elements 4 | E1 and E2 satisfy the predicate (PROCEDURE E1 E2). When two 5 | subsequent elements do not satisfy the predicate, start a new 6 | output list. Concatenate all output lists in the result. 7 | 8 | (collect eq? '(a a a b c c)) ==> ((a a a) (b) (c c)) 9 | (collect < '(1 2 3 3 4 5 4)) ==> ((1 2 3) (3 4 5) (4)) 10 | -------------------------------------------------------------------------------- /help/combine: -------------------------------------------------------------------------------- 1 | S9 LIB (combine integer list) ==> list 2 | (combine* integer list) ==> list 3 | 4 | (load-from-library "combine.scm") 5 | 6 | Create k-combinations of the elements of the given list. K (the 7 | size of the combinations) is specified in the integer argument. 8 | COMBINE creates combinations without repetition, and COMBINE* 9 | creates combinations with repetition. 10 | 11 | (combine 2 '(a b c)) ==> ((a b) (a c) (b c)) 12 | (combine* 2 '(a b c)) ==> ((a a) (a b) (a c) 13 | (b b) (b c) (c c)) 14 | -------------------------------------------------------------------------------- /help/command-line: -------------------------------------------------------------------------------- 1 | S9fES (command-line) ==> list 2 | 3 | Return the command line arguments passed to a Scheme program 4 | or to the S9 interpeter after an "--" argument. Each argument 5 | will be packaged in a separate string. 6 | 7 | (command-line) ==> () ; s9 8 | (command-line) ==> ("a" "b" "c") ; s9 -- a b c 9 | ; or s9 program a b c 10 | -------------------------------------------------------------------------------- /help/cond-expand: -------------------------------------------------------------------------------- 1 | S9 LIB (cond-expand (symbol expression ...)) ==> object 2 | 3 | This is a subset of SRFI-0 COND-EXPAND. Each argument of COND-EXPAND 4 | is a clause consisting of a leading "feature ID" (a symbol) and any 5 | number of trailing expressions (a body). It evaluates to the body of 6 | the first clause having a feature ID of SCHEME-9-FROM-EMPTY-SPACE, 7 | S9FES, or ELSE. The body is then evaluated by S9fES. When none 8 | of the above feature IDs is found, an error is reported. 9 | 10 | The new Scheme 9 (Reimagined) also defines the S9FES-REIMAGINED and 11 | SCHEME-9-FROM-EMPTY-SPACE-REIMAGNED identifiers. When testing for 12 | Reimagined, the test should come before the generic S9fES test, 13 | because the new S9 also defines the old identifiers. 14 | 15 | (cond-expand (s9fes (cons 1 2))) ==> (1 . 2) 16 | (cond-expand (foo (cons 1 2)) (else (+ 1 2))) ==> 3 17 | -------------------------------------------------------------------------------- /help/cons: -------------------------------------------------------------------------------- 1 | R4RS 6.3 (cons object1 object2) ==> pair 2 | 3 | Returns a newly allocated pair whose car is OBJECT1 and whose cdr 4 | is OBJECT2. The pair is guaranteed to be different (in the sense 5 | of EQV?) from every existing object. 6 | 7 | (cons 'a '()) ==> (a) 8 | (cons '(a) '(b c d)) ==> ((a) b c d) 9 | (cons "a" '(b c)) ==> ("a" b c) 10 | (cons 'a 3) ==> (a . 3) 11 | (cons '(a b) 'c) ==> ((a b) . c) 12 | -------------------------------------------------------------------------------- /help/count: -------------------------------------------------------------------------------- 1 | S9 LIB (count pair) ==> integer 2 | 3 | Count atomic members of a pair. 4 | 5 | (count '(a (b (c)) d . e)) ==> 5 6 | -------------------------------------------------------------------------------- /help/csv/INDEX: -------------------------------------------------------------------------------- 1 | ((csv:read csv:write)) 2 | -------------------------------------------------------------------------------- /help/current-error-port: -------------------------------------------------------------------------------- 1 | S9fES (current-error-port) ==> output-port 2 | 3 | Return a port connected to the Unix stderr file descriptor (2). 4 | -------------------------------------------------------------------------------- /help/current-input-port: -------------------------------------------------------------------------------- 1 | R4RS 6.10 (current-input-port) ==> input-port 2 | (current-output-port) ==> output-port 3 | 4 | Returns the current default input or output port. 5 | -------------------------------------------------------------------------------- /help/curses/INDEX: -------------------------------------------------------------------------------- 1 | ((curs:addch curs:addstr curs:beep curs:flash curs:move curs:mvaddch 2 | curs:mvaddstr curs:refresh curs:scroll) 3 | (curs:attroff curs:attron curs:attrset curs:standend curs:standout) 4 | (curs:cbreak curs:clearok curs:echo curs:get-magic-value curs:idlok 5 | curs:keypad curs:nl curs:nocbreak curs:nodelay curs:noecho curs:nonl 6 | curs:noraw curs:raw curs:resetty curs:savetty curs:scrollok) 7 | (curs:clear curs:clrtobot curs:clrtoeol) 8 | (curs:color-set curs:has-colors) 9 | (curs:cursoff curs:curson curs:mvcur) 10 | (curs:delch curs:mvdelch curs:deleteln curs:insch curs:insertln 11 | curs:mvinsch) 12 | (curs:endwin curs:initscr) 13 | (curs:flushinp curs:cols curs:getch curs:getyx curs:inch curs:lines 14 | curs:mvgetch curs:mvinch curs:unctrl curs:ungetch) 15 | (get-line)) 16 | -------------------------------------------------------------------------------- /help/curses/curs_clear: -------------------------------------------------------------------------------- 1 | S9 EXT (curs:clear) ==> unspecific 2 | (curs:clrtobot) ==> unspecific 3 | (curs:clrtoeol) ==> unspecific 4 | 5 | Curses routines for clearing the screen. This is only a rough 6 | summary. See the curses(3) manual page or a curses tutorial of 7 | your choice for further information. 8 | 9 | These routines do not cause any effect before CURS:REFRESH (q.v.) 10 | is called. 11 | 12 | CURS:CLEAR clears the entire virtual screen. 13 | 14 | CURS:CLRTOBOT clears the current line from the current column 15 | of the virtual cursor to the end of the line as well as all 16 | lines below the virtual cursor. 17 | 18 | CURS:CLRTOEOL clears the current line from the current column 19 | of the virtual cursor to the end of the line. 20 | -------------------------------------------------------------------------------- /help/curses/curs_color-set: -------------------------------------------------------------------------------- 1 | S9 EXT (curs:color-set integer_f integer_b) ==> unspecific 2 | (curs:has-colors) ==> boolean 3 | 4 | CURS:COLOR-SET sets the foreground color of the screen to 5 | INTEGER_F and the background color to INTEGER_B. The following 6 | constants can be used in the places of the integers: 7 | 8 | CURS:COLOR-BLACK CURS:COLOR-CYAN CURS:COLOR-YELLOW 9 | CURS:COLOR-BLUE CURS:COLOR-RED CURS:COLOR-GRAY 10 | CURS:COLOR-GREEN CURS:COLOR-MAGENTA 11 | 12 | Note that the pair black/black may be reserved for the terminal's 13 | default colors. 14 | 15 | CURS:HAS-COLORS returns #T when color support is available and 16 | otherwise #F. Color support is only available, if it has been 17 | compiled into Scheme 9 and the connected terminal offers color 18 | support. 19 | -------------------------------------------------------------------------------- /help/curses/curs_cursoff: -------------------------------------------------------------------------------- 1 | S9 EXT (curs:cursoff) ==> unspecific 2 | (curs:curson) ==> unspecific 3 | (curs:mvcur int_oy int_ox int_y int_x) ==> unspecific 4 | 5 | Curses routines for manipulating the hardware cursor. This is only 6 | a rough summary. See the curses(3) manual page or a curses tutorial 7 | of your choice for further information. 8 | 9 | CURS:CURSOFF makes the hardware cursor invisible. 10 | 11 | CURS:CURSOFF makes the hardware cursor visible. 12 | 13 | CURS:MVCUR moves the hardware cursor from position (INT_OY,INT_OX) 14 | to position (INT_Y,INT_X). 15 | -------------------------------------------------------------------------------- /help/curses/curs_endwin: -------------------------------------------------------------------------------- 1 | S9 EXT (curs:endwin) ==> unspecific 2 | (curs:initscr) ==> unspecific 3 | 4 | Routines for initializing and shutting down curses. This is only 5 | a rough summary. See the curses(3) manual page or a curses tutorial 6 | of your choice for further information. 7 | 8 | CURS:ENDWIN restores the terminal state that was in effect before 9 | initializing curses. No curses routines may be called after running 10 | CURS:ENDWIN. (Exception: CURS:GET-MAGI-VALUE.) 11 | 12 | CURS:INITSCR initializes the curses interface. No curses routines may 13 | be called prior to running CURS:INITSCR. 14 | (Exception: CURS:GET-MAGI-VALUE.) 15 | 16 | Typical curses-based programs will use the following setup: 17 | 18 | (curs:initscr) 19 | (curs:cbreak) ; or (curs:raw) 20 | (curs:noecho) 21 | (curs:nonl) 22 | (curs:keypad #t) 23 | -------------------------------------------------------------------------------- /help/data-structures: -------------------------------------------------------------------------------- 1 | S9 LIB Convenience file to load additional high-level data structures. 2 | 3 | (load-from-library "array.scm") 4 | (load-from-library "define-structure.scm") 5 | (load-from-library "hash-table.scm") 6 | (load-from-library "queue.scm") 7 | (load-from-library "rb-tree.scm") 8 | 9 | -------------------------------------------------------------------------------- /help/delete-file: -------------------------------------------------------------------------------- 1 | S9fES (delete-file string) ==> unspecific 2 | 3 | Delete the file specifed in the STRING argument. If the file does 4 | not exist or cannot be deleted, report an error. 5 | -------------------------------------------------------------------------------- /help/depth: -------------------------------------------------------------------------------- 1 | S9 LIB (depth list) ==> integer 2 | 3 | Compute the depth of a list. 4 | 5 | (depth '(a (b (c d (e))))) ==> 4 6 | -------------------------------------------------------------------------------- /help/dirname: -------------------------------------------------------------------------------- 1 | S9 LIB (dirname string) ==> string 2 | 3 | Return the directory part of the Unix path name in STRING. Note 4 | that DIRNAME performs merely a syntaxical operation without any 5 | regard to the actual file system structure, i.e. 6 | 7 | (dirname "/foo/bar") ==> "/foo" 8 | 9 | even if "bar" is also a directory. DIRNAME also takes care of 10 | trailing slashes and recognizes some special cases (see examples). 11 | 12 | (dirname "/foo/bar/baz") ==> "/foo/bar" 13 | (dirname "foo/bar") ==> "foo" 14 | (dirname "foo/bar/") ==> "foo" 15 | (dirname "/foo") ==> "/" 16 | (dirname "/") ==> "/" 17 | (dirname "foo") ==> "." 18 | -------------------------------------------------------------------------------- /help/display: -------------------------------------------------------------------------------- 1 | R4RS 6.10.3 (display object) ==> unspecific 2 | (display object output-port) ==> unspecific 3 | 4 | Writes a representation of OBJECT to the given OUTPUT-PORT. Strings 5 | that appear in the written representation are not enclosed in 6 | double quotes, and no characters are escaped within those strings. 7 | Character objects appear in the representation as if written by 8 | write-char instead of by write. DISPLAY returns an unspecified 9 | value. The OUTPUT-PORT argument may be omitted, in which case it 10 | defaults to the value returned by CURRENT-OUTPUT-PORT. 11 | 12 | Rationale: WRITE is intended for producing machine-readable output 13 | and DISPLAY is for producing human-readable output. Implementations 14 | that allow "slashification" within symbols will probably want WRITE 15 | but not DISPLAY to slashify funny characters in symbols. 16 | -------------------------------------------------------------------------------- /help/displaystar: -------------------------------------------------------------------------------- 1 | S9 LIB (display* object ...) ==> unspecific 2 | (display* output-port object ...) ==> unspecific 3 | 4 | (load-from-library "displaystar.scm") 5 | 6 | Display each OBJECT in the same way as DISPLAY. When the first 7 | argument of DISPLAY* is an output port, write all output to 8 | that port. 9 | 10 | (display* "foo" #\= 17 #\newline) ==> unspecific 11 | ; output: foo = 17 12 | -------------------------------------------------------------------------------- /help/draw-tree: -------------------------------------------------------------------------------- 1 | S9 LIB (draw-tree object) ==> unspecific 2 | (dt) ==> unspecific 3 | 4 | Print a tree structure resembling a Scheme datum. Each cons 5 | cell is represented by [o|o] with lines leading to their car 6 | and cdr parts. Conses with a cdr value of () are represented 7 | by [o|/]. 8 | 9 | DT is an abbrevation for DRAW-TREE. 10 | 11 | (draw-tree '((a) (b . c) (d e))) ==> unspecific 12 | 13 | Output: [o|o]---[o|o]---[o|/] 14 | | | | 15 | [o|/] | [o|o]---[o|/] 16 | | | | | 17 | a | d e 18 | | 19 | [o|o]--- c 20 | | 21 | b 22 | -------------------------------------------------------------------------------- /help/dump-image: -------------------------------------------------------------------------------- 1 | S9fES (dump-image "string") ==> unspecific 2 | 3 | Write a heap image to the file specified in STRING. The heap 4 | image can be loaded when starting the S9 interpreter by using 5 | the "-i" command line option. Heap images load much faster 6 | than Scheme source code. 7 | 8 | (dump-image "my-setup.image") ==> unspecific 9 | -------------------------------------------------------------------------------- /help/duplicates: -------------------------------------------------------------------------------- 1 | S9 LIB (duplicates list) ==> list 2 | (dupp procedure^2 list) ==> list 3 | (dupq list) ==> list 4 | (dupv list) ==> list 5 | 6 | Return a list of duplicates contained in LIST. 7 | 8 | DUPP uses the predicate PROCEDURE^2 to check if two members of 9 | LIST are duplicates. 10 | 11 | (Duplicates x) is equal to (dupp equal? x) 12 | (Dupv x) is equal to (dupp eqv? x) 13 | (Dupq x) is equal to (dupp eq? x) 14 | 15 | When a duplicate occurs multiple times in a given list, it will 16 | be contained only once in the results of these procedures. 17 | 18 | (dupp = '(1 2 3 1 2)) ==> (1 2) 19 | (duplicates '((1) (2) (1))) ==> ((1)) 20 | (dupv '(#\a #\b #\a #\c)) ==> (#\a) 21 | (dupq '(a b c d a c e f c)) ==> (a c) 22 | -------------------------------------------------------------------------------- /help/environ: -------------------------------------------------------------------------------- 1 | S9fES (environ string) ==> string | #f 2 | 3 | Return the value of the environment variable STRING. If 4 | the variable is undefined, return #F. 5 | 6 | This procedure is deprecated; use ENVIRONMENT-VARIABLE 7 | instead. 8 | 9 | (environ "HOME") ==> "/u/home/nmh" 10 | (environ "nonexistent") ==> #f 11 | -------------------------------------------------------------------------------- /help/environment-variable: -------------------------------------------------------------------------------- 1 | S9fES (environment-variable string) ==> string | #f 2 | 3 | Return the value of the environment variable STRING. If 4 | the variable is undefined, return #F. 5 | 6 | (environment-variable "HOME") ==> "/u/home/nmh" 7 | (environment-variable "nonexistent") ==> #f 8 | -------------------------------------------------------------------------------- /help/eof-objectp: -------------------------------------------------------------------------------- 1 | R4RS 6.10.2 (eof-object? object) ==> boolean 2 | 3 | Returns #T if OBJECT is an end of file object, otherwise returns #F. 4 | The precise set of end of file objects will vary among implementations, 5 | but in any case no end of file object will ever be an object that 6 | can be read in using read. 7 | -------------------------------------------------------------------------------- /help/eq: -------------------------------------------------------------------------------- 1 | R4RS 6.5.5 (= number1 number2 ...) ==> boolean 2 | (< number1 number2 ...) ==> boolean 3 | (> number1 number2 ...) ==> boolean 4 | (<= number1 number2 ...) ==> boolean 5 | (>= number1 number2 ...) ==> boolean 6 | 7 | These procedures return #T if their arguments are (respectively): 8 | equal, monotonically increasing, monotonically decreasing, monotonically 9 | nondecreasing, or monotonically non-increasing. 10 | 11 | These predicates are required to be transitive. 12 | 13 | Note: The traditional implementations of these predicates in Lisp-like 14 | languages are not transitive. 15 | 16 | Note: While it is not an error to compare inexact numbers using 17 | these predicates, the results may be unreliable because a small 18 | inaccuracy may affect the result; this is especially true of = and 19 | ZERO?. When in doubt, consult a numerical analyst. 20 | -------------------------------------------------------------------------------- /help/equal-cip: -------------------------------------------------------------------------------- 1 | S9 LIB (equal-ci? object1 object2) ==> boolean 2 | 3 | EQUAL-CI? is like EQUAL?, but compares strings and characters 4 | using case-insensitive predicates whereas EQUAL? distinguishes 5 | case. 6 | 7 | (equal-ci? '(#\A ("b")) '(#\a ("B"))) ==> #t 8 | -------------------------------------------------------------------------------- /help/equalp: -------------------------------------------------------------------------------- 1 | R4RS 6.2 (equal? object1 object2) ==> boolean 2 | 3 | EQUAL? recursively compares the contents of pairs, vectors, and 4 | strings, applying eqv? on other objects such as numbers and symbols. 5 | A rule of thumb is that objects are generally EQUAL? if they print 6 | the same. EQUAL? may fail to terminate if its arguments are circular 7 | data structures. 8 | 9 | (equal? 'a 'a) ==> #t 10 | (equal? '(a) '(a)) ==> #t 11 | (equal? '(a (b) c) 12 | '(a (b) c)) ==> #t 13 | (equal? "abc" "abc") ==> #t 14 | (equal? 2 2) ==> #t 15 | (equal? (make-vector 5 'a) 16 | (make-vector 5 'a)) ==> #t 17 | (equal? (lambda (x) x) 18 | (lambda (y) y)) ==> unspecified 19 | -------------------------------------------------------------------------------- /help/erf: -------------------------------------------------------------------------------- 1 | S9 LIB (erf real) ==> real 2 | 3 | (load-from-library "erf.scm") 4 | 5 | Gauss error function. Used to compute the integral of the normal 6 | distribution function (NDF). 7 | 8 | Using an Abramowitz-Stegun approximation with a maximum error of 9 | 3 * 10^-7, i.e. results will start to get flaky beyond the 5th 10 | standard deviation. 11 | 12 | (erf 0) ==> 0.0 13 | -------------------------------------------------------------------------------- /help/error: -------------------------------------------------------------------------------- 1 | S9fES (error string) ==> undefined 2 | (error string object) ==> undefined 3 | 4 | Display the message in STRING. If OBJECT is given, display a colon, 5 | a space character, and the external representation of OBJECT after 6 | the message. After printing the message, abort evaluation. No result 7 | is returned. 8 | 9 | Rationale: ERROR is used by S9fES programs to signal errors. 10 | -------------------------------------------------------------------------------- /help/exact-to-inexact: -------------------------------------------------------------------------------- 1 | R4RS 6.5.5 (exact->inexact number) ==> number 2 | (inexact->exact number) ==> number 3 | 4 | EXACT->INEXACT returns an inexact representation of NUMBER. The 5 | value returned is the inexact number that is numerically closest 6 | to the argument. 7 | 8 | INEXACT->EXACT returns an exact representation of NUMBER. The 9 | value returned is the exact number that is numerically closest 10 | to the argument. 11 | -------------------------------------------------------------------------------- /help/exactp: -------------------------------------------------------------------------------- 1 | R4RS 6.5.5 (exact? number) ==> boolean 2 | (inexact? number) ==> boolean 3 | 4 | These numerical predicates provide tests for the exactness of a 5 | quantity. For any Scheme number, precisely one of these predicates 6 | is true. 7 | -------------------------------------------------------------------------------- /help/exists: -------------------------------------------------------------------------------- 1 | S9 LIB (exists procedure list ...) ==> boolean 2 | 3 | Test whether a given property exists in a sequence of N lists. 4 | The property is expressed using the N-ary predicate P, which 5 | is given in the procedure argument. P is first applied to a 6 | list consisting of the first member of each given list. If P 7 | returns truth, EXISTS returns #T immediately. Otherwise it is 8 | applied to a list consisting of the second members of the given 9 | lists, etc. If P returns falsity for all sets of members, EXISTS 10 | returns #F. 11 | 12 | (exists < '(9 1) '(8 2) '(7 3)) ==> #t 13 | ; because (< 1 2 3) 14 | -------------------------------------------------------------------------------- /help/exp: -------------------------------------------------------------------------------- 1 | R4RS 6.5.5 (exp number) ==> number 2 | (log number) ==> number 3 | (sin number) ==> number 4 | (cos number) ==> number 5 | (tan number) ==> number 6 | (asin number) ==> number 7 | (acos number) ==> number 8 | (atan number) ==> number 9 | 10 | These procedures compute the usual transcendental functions. 11 | LOG computes the natural logarithm of NUMBER (not the base ten 12 | logarithm). ASIN, ACOS, and ATAN compute arcsine (sin^-1), 13 | arccosine (cos^-1), and arctangent (tan^-1), respectively. 14 | -------------------------------------------------------------------------------- /help/explode: -------------------------------------------------------------------------------- 1 | S9 LIB (explode symbol) ==> list 2 | 3 | Explode a symbol into a list of single-character symbols. 4 | 5 | (explode 'supernova) ==> (s u p e r n o v a) 6 | -------------------------------------------------------------------------------- /help/exponent: -------------------------------------------------------------------------------- 1 | S9fES (exponent number) ==> integer 2 | (mantissa number) ==> integer 3 | 4 | EXPONENT returns the exponent of a real number and MANTISSA 5 | returns its mantissa: 6 | 7 | real = (* mantissa (expt 10 exponent)) 8 | 9 | S9fES stores real numbers in such a format that the mantissa 10 | is always in integer and no trailing (yet significant) zeros 11 | are kept in the mantissa, e.g. 1000.0 would have a mantissa 12 | of 1 and an exponent of 3. This differs from the external 13 | form of real numbers, where the exponent is scaled to make 14 | numbers more friendly to human perception. 15 | 16 | Integers have an exponent of zero and a mantissa that is 17 | equal to their value. 18 | 19 | (exponent 12300.0) ==> 2 20 | (mantissa 12300.0) ==> 123 21 | 22 | (exponent 123.456) ==> -3 23 | (mantissa 123.456) ==> 123456 24 | 25 | (exponent 123) ==> 0 26 | (mantissa 123) ==> 123 27 | -------------------------------------------------------------------------------- /help/expt: -------------------------------------------------------------------------------- 1 | R4RS 6.5.5 (expt number1 number2) ==> number 2 | 3 | Returns NUMBER1 raised to the power NUMBER2. 4 | 5 | (Expt 0 0) is defined to be equal to 1. 6 | -------------------------------------------------------------------------------- /help/factor: -------------------------------------------------------------------------------- 1 | S9 LIB (factor integer) ==> list 2 | 3 | Factor an integer down to its constituent primes. 4 | The resulting list has the form ((base exponent) ...) 5 | 6 | (factor 24) ==> ((3 1) (2 3)) 7 | -------------------------------------------------------------------------------- /help/factorial: -------------------------------------------------------------------------------- 1 | S9 LIB (factorial integer) ==> integer 2 | 3 | Compute the factorial of a number. 4 | 5 | (factorial 30) ==> 265252859812191058636308480000000 6 | -------------------------------------------------------------------------------- /help/file-existsp: -------------------------------------------------------------------------------- 1 | S9fES (file-exists? string) ==> boolean 2 | 3 | Return #T if the file specifed in the STRING argument exists 4 | (and is readable by the Scheme process) and otherwise return #F. 5 | -------------------------------------------------------------------------------- /help/filter: -------------------------------------------------------------------------------- 1 | S9 LIB (filter procecure^1 list) ==> list 2 | 3 | Extract elements from a list. PROCEDURE describes the property 4 | of the elements to be extracted. It must be a procedure of one 5 | argument. 6 | 7 | (filter number? '(a 1 b 2 c 3)) ==> (1 2 3) 8 | -------------------------------------------------------------------------------- /help/find-help-page: -------------------------------------------------------------------------------- 1 | S9 LIB (find-help-page string) ==> string | #f 2 | 3 | Search the online help database for a file explaining the 4 | given topic. STRING may contain a Scheme 9 keyword, a 5 | procedure name, or the name of a special variable. When 6 | a file describing the desired topic exists, its full path 7 | will be returned. When no such file exists, the procedure 8 | returns #F. 9 | 10 | (find-help-page "help") ==> "path to help-page" 11 | -------------------------------------------------------------------------------- /help/flatten: -------------------------------------------------------------------------------- 1 | S9 LIB (flatten pair) ==> list 2 | 3 | Convert tree to flat list. 4 | 5 | (flatten '(a (b ((c) d . e)))) ==> (a b c d e) 6 | -------------------------------------------------------------------------------- /help/fluid-let: -------------------------------------------------------------------------------- 1 | S9 LIB (fluid-let ((variable expression) ...) expression ...) ==> object 2 | 3 | Bind variables dynamically, i.e. assign a dynamic (rather than 4 | a lexical/static) value to each given variable. The variables 5 | must be defined outside of FLUID-LET. The difference between 6 | LET and FLUID-LET is as follows: 7 | 8 | (let ((a 0)) (let ((a 0)) 9 | (let ((f (lambda () a))) (let ((f (lambda () a))) 10 | (let ((a 1)) (fluid-let ((a 1)) 11 | (f)))) ==> 0 (f)))) ==> 1 12 | 13 | (let ((a 0)) 14 | (let ((f (lambda () a))) 15 | (fluid-let ((a 1)) 16 | (f)))) ==> 1 17 | -------------------------------------------------------------------------------- /help/for-all: -------------------------------------------------------------------------------- 1 | S9 LIB (for-all procedure list ...) ==> object 2 | 3 | Test whether all members of a sequence of N lists have a given 4 | property. The property is expressed using an N-ary predicate P, 5 | which is given in the procedure argument. P is applied to a list 6 | consisting of the first member of each given list. If P returns 7 | truth, it is applied to a list consisting of the second member of 8 | each given list, etc. If P returns falsity for any set of members, 9 | FOR-ALL returns #F. If only one set of members is left to check, 10 | FOR-ALL returns the value of P applied to this final set. 11 | When the LISTs are empty, FOR-ALL returns #T. 12 | 13 | (for-all < '(1 7) '(2 8) '(3 9)) ==> #t 14 | ; because (< 1 2 3) and (< 7 8 9) 15 | -------------------------------------------------------------------------------- /help/for-each: -------------------------------------------------------------------------------- 1 | R4RS 6.9 (for-each procedure list1 list2 ...) ==> unspecific 2 | 3 | The arguments to FOR-EACH are like the arguments to MAP, but FOR-EACH 4 | calls PROCEDURE for its side effects rather than for its values. 5 | Unlike MAP, FOR-EACH is guaranteed to call PROCEDURE on the elements 6 | of the lists in order from the first element to the last, and the 7 | value returned by FOR-EACH is unspecified. 8 | 9 | (let ((v (make-vector 5))) 10 | (for-each (lambda (i) 11 | (vector-set! v i (* i i))) 12 | '(0 1 2 3 4)) 13 | v) ==> #(0 1 4 9 16) 14 | -------------------------------------------------------------------------------- /help/gcd: -------------------------------------------------------------------------------- 1 | R4RS 6.5.5 (gcd integer ...) ==> integer 2 | (lcm integer ...) ==> integer 3 | 4 | These procedures return the greatest common divisor or least common 5 | multiple of their arguments. The result is always non-negative. 6 | 7 | (gcd 32 -36) ==> 4 8 | (gcd) ==> 0 9 | (lcm 32 -36) ==> 288 10 | (lcm) ==> 1 11 | -------------------------------------------------------------------------------- /help/gensym: -------------------------------------------------------------------------------- 1 | S9fES (gensym) ==> symbol 2 | 3 | Return a fresh symbol that is guaranteed to be unique. 4 | 5 | (gensym) ==> G56 6 | 7 | (let* ((a (gensym)) 8 | (b (gensym)) 9 | (c (gensym))) 10 | (list a b c)) ==> (G61 G62 G63) 11 | -------------------------------------------------------------------------------- /help/graph-tools: -------------------------------------------------------------------------------- 1 | S9 LIB Convenience file to load additional tree/DAG-processing procedures. 2 | 3 | (load-from-library "t-sort.scm") 4 | (load-from-library "tree-copy.scm") 5 | 6 | -------------------------------------------------------------------------------- /help/group: -------------------------------------------------------------------------------- 1 | S9 LIB (group list integer) ==> list 2 | 3 | Group the elements of LIST in tuples of INTEGER elements 4 | each (except for the last tuple, which may contain fewer 5 | elements). Return a list of the resulting tuples. The 6 | elements appear in the output list in the same order as 7 | in the input list. 8 | 9 | INTEGER must be positive. 10 | 11 | (group '(1 2 3 4 5) 2) ==> ((1 2) (3 4) (5)) 12 | (group '(1 2 3 4 5) 5) ==> ((1 2 3 4 5)) 13 | -------------------------------------------------------------------------------- /help/htmlify-char: -------------------------------------------------------------------------------- 1 | S9 LIB (htmlify-char char) ==> string 2 | (htmlify-string string) ==> string 3 | 4 | HTMLIFY-CHAR converts a char to a string that is save for 5 | inclusion in an HTML document. HTMLIFY-STRING does the 6 | same for a string. 7 | 8 | (htmlify-char #\<) ==> "<" 9 | (htmlify-string "<&>") ==> "<&>" 10 | -------------------------------------------------------------------------------- /help/hyper: -------------------------------------------------------------------------------- 1 | S9 LIB (hyper integer1 integer2 integer3) ==> integer 2 | 3 | Compute A hyper(N) B, where N=INTEGER1, A=INTEGER2, and B=INTEGER3. 4 | 5 | (hyper 4 3 3) ==> 7625597484987 6 | -------------------------------------------------------------------------------- /help/id: -------------------------------------------------------------------------------- 1 | S9 LIB (false object ...) ==> #f 2 | (id object) ==> object 3 | (true object ...) ==> #t 4 | 5 | (load-from-library "id.scm") 6 | 7 | ID returns the object passed to it. 8 | 9 | FALSE returns always #F and TRUE returns always #T, no matter which 10 | values are passed to them. 11 | 12 | (true) ==> #t 13 | (false 1 2 3) ==> #f 14 | (id 'whatever) ==> whatever 15 | -------------------------------------------------------------------------------- /help/if: -------------------------------------------------------------------------------- 1 | R4RS 4.1.5 (if ) ==> object 2 | (if ) ==> object 3 | 4 | Syntax: , , and may be arbitrary 5 | expressions. 6 | 7 | Semantics: An IF expression is evaluated as follows: first, 8 | is evaluated. If it yields a true value (see section see section 9 | 6.1 Booleans), then is evaluated and its value is 10 | returned. Otherwise is evaluated and its value is 11 | returned. If yields a false value and no is 12 | specified, then the result of the expression is unspecified. 13 | 14 | (if (> 3 2) 'yes 'no) ==> yes 15 | (if (> 2 3) 'yes 'no) ==> no 16 | (if (> 3 2) 17 | (- 3 2) 18 | (+ 3 2)) ==> 1 19 | -------------------------------------------------------------------------------- /help/ifstar: -------------------------------------------------------------------------------- 1 | S9FES (if* ) ==> object 2 | 3 | Syntax: and may be arbitrary expressions. 4 | 5 | Semantics: An IF* expression is evaluated as follows: first, 6 | is evaluated. If it yields a true value, then this 7 | value is returned. Otherwise is evaluated and its 8 | value is returned. 9 | 10 | Formally, 11 | 12 | (if* ) 13 | 14 | if equal to 15 | 16 | (let ((t )) (if t t )). 17 | 18 | (if* (> 3 2) 'no) ==> #t 19 | (if* (> 2 3) 'no) ==> no 20 | (if* 'foo (/ 0)) ==> foo 21 | -------------------------------------------------------------------------------- /help/implode: -------------------------------------------------------------------------------- 1 | S9 LIB (implode list) ==> symbol 2 | 3 | Implode a list of single-character symbols into a symbol. 4 | 5 | (implode '(b l a c k h o l e)) ==> blackhole 6 | -------------------------------------------------------------------------------- /help/input-portp: -------------------------------------------------------------------------------- 1 | R4RS 6.10 (input-port? object) ==> boolean 2 | (output-port? object) ==> boolean 3 | 4 | Returns #T if OBJECT is an input port or output port respectively, 5 | otherwise returns #F. 6 | -------------------------------------------------------------------------------- /help/integer-sqrt: -------------------------------------------------------------------------------- 1 | S9 LIB (integer-sqrt integer) ==> integer 2 | 3 | Compute the largest integer value that is not greater than the 4 | square root of INTEGER. 5 | 6 | (integer-sqrt 10) ==> 3 7 | -------------------------------------------------------------------------------- /help/intersection: -------------------------------------------------------------------------------- 1 | S9 LIB (intersection list ...) ==> list 2 | 3 | Compute the intersection of a number of sets. 4 | 5 | (intersection '(v w x) '(w x y) '(x y z)) ==> (x) 6 | -------------------------------------------------------------------------------- /help/iota: -------------------------------------------------------------------------------- 1 | S9 LIB (iota integer) ==> list 2 | (iota integer1 integer2) ==> list 3 | (iota* integer1 integer2) ==> list 4 | 5 | (load-from-library "iota.scm") 6 | 7 | IOTA creates a sequence of integers starting at 1 and ending 8 | at INTEGER (including both). When a second argument is passed 9 | to IOTA, the sequence returned by it will start at INTEGER1 10 | and ; end at INTEGER2 (again, including both). 11 | 12 | IOTA* differs from IOTA in two ways: it always takes two 13 | arguments and excludes INTEGER2 from the generated sequence. 14 | 15 | (iota 7) ==> (1 2 3 4 5 6 7) 16 | (iota 17 21) ==> (17 18 19 20 21) 17 | (iota* 17 21) ==> (17 18 19 20) 18 | (iota* 1 1) ==> () 19 | -------------------------------------------------------------------------------- /help/leap-yearp: -------------------------------------------------------------------------------- 1 | S9 LIB (leap-year? integer) ==> boolean 2 | 3 | Return #T if INTEGER represents a leap year and otherwise return #F. 4 | 5 | (leap-year? 2000) ==> #t 6 | (leap-year? 2003) ==> #f 7 | -------------------------------------------------------------------------------- /help/length: -------------------------------------------------------------------------------- 1 | R4RS 6.3 (length list) ==> integer 2 | 3 | Returns the length of list. 4 | 5 | (length '(a b c)) ==> 3 6 | (length '(a (b) (c d e))) ==> 3 7 | (length '()) ==> 0 8 | -------------------------------------------------------------------------------- /help/letslashcc: -------------------------------------------------------------------------------- 1 | S9 LIB (let/cc . ) ==> object 2 | 3 | (load-from-library "letcc.scm") 4 | 5 | Bind the current continuation to and evaluate with 6 | that binding in effect. 7 | 8 | (let/cc exit 9 | (letrec 10 | ((f (lambda (x) 11 | (cond ((null? x) 0) 12 | ((pair? x) (+ 1 (f (cdr x)))) 13 | (else (exit 'foo)))))) 14 | (f '(1 2 3 . 4)))) ==> foo 15 | -------------------------------------------------------------------------------- /help/letstar: -------------------------------------------------------------------------------- 1 | R4RS 4.2.2 (let* ) ==> object 2 | 3 | Syntax: should have the form 4 | 5 | (( ) ...), 6 | 7 | and should be a sequence of one or more expressions. 8 | 9 | Semantics: LET* is similar to LET, but the bindings are performed 10 | sequentially from left to right, and the region of a binding indicated 11 | by `( )' is that part of the LET* expression to the 12 | right of the binding. Thus the second binding is done in an environment 13 | in which the first binding is visible, and so on. 14 | 15 | (let ((x 2) (y 3)) 16 | (let* ((x 7) 17 | (z (+ x y))) 18 | (* z x))) ==> 70 19 | -------------------------------------------------------------------------------- /help/list: -------------------------------------------------------------------------------- 1 | R4RS 6.3 (list object ...) ==> list 2 | 3 | Returns a newly allocated list of its arguments. 4 | 5 | (list 'a (+ 3 4) 'c) ==> (a 7 c) 6 | (list) ==> () 7 | -------------------------------------------------------------------------------- /help/list-copy: -------------------------------------------------------------------------------- 1 | S9 LIB (list-copy list) ==> list 2 | 3 | Copy the spine of a proper list, creating a fresh list with the 4 | same elements as the original list. 5 | 6 | (list-copy '(foo bar baz)) ==> (foo bar baz) 7 | -------------------------------------------------------------------------------- /help/list-ref: -------------------------------------------------------------------------------- 1 | R4RS 6.3 (list-ref list integer) ==> obj 2 | 3 | Returns the INTEGER'th element of list. (This is the same as the 4 | car of (list-tail list INTEGER).) 5 | 6 | (list-ref '(a b c d) 2) ==> c 7 | -------------------------------------------------------------------------------- /help/list-tail: -------------------------------------------------------------------------------- 1 | R4RS 6.3 (list-tail list integer) ==> list 2 | 3 | Returns the sublist of LIST obtained by omitting the first INTEGER 4 | elements. LIST-TAIL could be defined by 5 | 6 | (define (list-tail x k) 7 | (if (zero? k) 8 | x 9 | (list-tail (cdr x) (- k 1)))) 10 | -------------------------------------------------------------------------------- /help/list-to-set: -------------------------------------------------------------------------------- 1 | S9 LIB (list->set list) ==> list 2 | 3 | (load-from-library "list-to-set.scm") 4 | 5 | Convert list to set. A set is a list containing unique members. 6 | 7 | (list->set '(a b c b c)) ==> (a b c) 8 | -------------------------------------------------------------------------------- /help/listp: -------------------------------------------------------------------------------- 1 | R4RS 6.3 (list? object) ==> boolean 2 | 3 | Returns #T if OBJECT is a list, otherwise returns #F. By definition, 4 | all lists have finite length and are terminated by the empty list. 5 | 6 | (list? '(a b c)) ==> #t 7 | (list? '()) ==> #t 8 | (list? '(a . b)) ==> #f 9 | (let ((x (list 'a))) 10 | (set-cdr! x x) 11 | (list? x)) ==> #f 12 | -------------------------------------------------------------------------------- /help/listq: -------------------------------------------------------------------------------- 1 | S9 LIB (listq object ...) ==> list 2 | 3 | LISTQ is like LIST, but quotes each OBJECT passed to it. 4 | Rationale: (list a b c) evaluates a, b, and c 5 | '(a b c) makes the list immutable 6 | `(a b c) may be inefficient 7 | (list 'a 'b 'c) is awkward 8 | 9 | (listq a (b c) d) ==> (a (b c) d) 10 | -------------------------------------------------------------------------------- /help/load: -------------------------------------------------------------------------------- 1 | R4RS 6.10.4 (load string) ==> unspecific 2 | 3 | STRING should be a file name naming an existing file containing 4 | Scheme source code. The LOAD procedure reads expressions and 5 | definitions from the file and evaluates them sequentially. It is 6 | unspecified whether the results of the expressions are printed. 7 | The LOAD procedure does not affect the values returned by 8 | CURRENT-INPUT-PORT and CURRENT-OUTPUT-PORT. LOAD returns an 9 | unspecified value. 10 | 11 | Rationale: For portability, LOAD must operate on source files. Its 12 | operation on other kinds of files necessarily varies among 13 | implementations. 14 | -------------------------------------------------------------------------------- /help/load-from-library: -------------------------------------------------------------------------------- 1 | S9fES (load-from-library string) ==> unspecific 2 | 3 | Locate the Scheme source file whose name is specified in STRING and 4 | load it. It is an error to specify a file that cannot be located. 5 | LOAD-FROM-LIBRARY uses LOCATE-FILE to locate a file and LOAD to 6 | load it. It is intended to load files from extension libraries that 7 | may be stored in a set of pre-defined locations. 8 | -------------------------------------------------------------------------------- /help/loutify-char: -------------------------------------------------------------------------------- 1 | S9 LIB (loutify-char char) ==> string 2 | (loutify-string string) ==> string 3 | 4 | LOUTIFY-CHAR converts a char to a string that is save for 5 | inclusion in an Lout document. LOUTIFY-STRING does the 6 | same for a string. 7 | 8 | (loutify-char #\") ==> "\"\\\"\"" 9 | (loutify-string "\"x\"") ==> "\"\\\"x\\\"\"" 10 | -------------------------------------------------------------------------------- /help/make-help-index: -------------------------------------------------------------------------------- 1 | S9 LIB (make-help-index) ==> list 2 | 3 | Return a comprehensive list of topics found in the online help 4 | database. Topics include procedures (like CAR and +), syntactic 5 | keywords (like IF and DEFINE) as well as special variables (such 6 | as *LIBRARY-PATH*). The returned list will be lexicographically 7 | sorted and free of duplicates. 8 | 9 | (make-help-index) ==> (list of procedures and keywords) 10 | -------------------------------------------------------------------------------- /help/make-partitions: -------------------------------------------------------------------------------- 1 | S9 LIB (make-partitions integer) ==> list 2 | 3 | Create all partitions of a positive integer. A (number-theoretical) 4 | partition of a positive integer N is a set of integers whose sum is 5 | equal to N. E.g., the partitions of 3 are 3, 2+1, and 1+1+1. 6 | 7 | (make-partitions 4) ==> ((4) (3 1) (2 2) (2 1 1) (1 1 1 1)) 8 | -------------------------------------------------------------------------------- /help/make-string: -------------------------------------------------------------------------------- 1 | R4RS 6.7 (make-string integer) ==> string 2 | (make-string integer char) ==> string 3 | 4 | MAKE-STRING returns a newly allocated string of length INTEGER. 5 | If CHAR is given, then all elements of the string are initialized 6 | to CHAR, otherwise the contents of the string are unspecified. 7 | -------------------------------------------------------------------------------- /help/make-vector: -------------------------------------------------------------------------------- 1 | R4RS 6.8 (make-vector integer) ==> vector 2 | (make-vector integer object) ==> vector 3 | 4 | Returns a newly allocated vector of INTEGER elements. If a second 5 | argument is given, then each element is initialized to fill. 6 | Otherwise the initial content of each element is unspecified. 7 | -------------------------------------------------------------------------------- /help/map: -------------------------------------------------------------------------------- 1 | R4RS 6.9 (map procedure list1 list2 ...) ==> list 2 | 3 | The LISTs must be lists, and PROCEDURE must be a procedure taking 4 | as many arguments as there are lists. If more than one list is 5 | given, then they must all be the same length. Map applies PROCEDURE 6 | element-wise to the elements of the lists and returns a list of the 7 | results, in order from left to right. The dynamic order in which 8 | PROCEDURE is applied to the elements of the lists is unspecified. 9 | 10 | (map cadr '((a b) (d e) (g h))) ==> (b e h) 11 | (map (lambda (n) (expt n n)) '(1 2 3 4 5)) ==> (1 4 27 256 3125) 12 | (map + '(1 2 3) '(4 5 6)) ==> (5 7 9) 13 | 14 | (let ((count 0)) 15 | (map (lambda (ignored) 16 | (set! count (+ count 1)) 17 | count) 18 | '(a b c))) ==> unspecified 19 | -------------------------------------------------------------------------------- /help/max: -------------------------------------------------------------------------------- 1 | R4RS 6.5.5 (max number ...) ==> number 2 | (min number ...) ==> number 3 | 4 | These procedures return the maximum or minimum of their arguments. 5 | 6 | (max 3 4) ==> 4 ; exact 7 | (min 3 4.1) ==> 3.0 ; inexact 8 | 9 | Note: If any argument is inexact, then the result will also be 10 | inexact. 11 | -------------------------------------------------------------------------------- /help/mean: -------------------------------------------------------------------------------- 1 | S9 LIB (mean list) ==> real 2 | 3 | (load-from-library "mean.scm") 4 | 5 | Mean (average) function, returns the arithmetic mean value of a 6 | list of reals. 7 | 8 | (mean '(1 2 3 4 5 6)) ==> 3.5 9 | -------------------------------------------------------------------------------- /help/median: -------------------------------------------------------------------------------- 1 | S9 LIB (median list) ==> real 2 | 3 | (load-from-library "median.scm") 4 | 5 | Median (middle value) function, returns the value in the middle of 6 | a sorted list of values. The input list does not have to be sorted. 7 | 8 | (mean '(1 2 3 4 5 6)) ==> 3.5 9 | -------------------------------------------------------------------------------- /help/memp: -------------------------------------------------------------------------------- 1 | S9 LIB (memp procedure^2 object list) ==> list | #f 2 | 3 | Find the first tail X of LIST for which 4 | 5 | (procedure^2 object (car X)) 6 | 7 | holds. When no such tail exists, return #F. 8 | 9 | (memp char=? #\b '(#\a #\b #\c)) ==> (#\b #\c) 10 | -------------------------------------------------------------------------------- /help/memq: -------------------------------------------------------------------------------- 1 | R4RS 6.3 (memq object list) ==> list | #f 2 | (memv object list) ==> list | #f 3 | (member object list) ==> list | #f 4 | 5 | These procedures return the first sublist of LIST whose car is 6 | OBJECT, where the sublists of LIST are the non-empty lists returned 7 | by (list-tail list k) for K less than the length of LIST. If OBJECT 8 | does not occur in LIST, then #F (not the empty list) is returned. 9 | MEMQ uses EQ? to compare OBJECT with the elements of LIST, while 10 | MEMV uses EQV? and MEMBER uses EQUAL?. 11 | 12 | (memq 'a '(a b c)) ==> (a b c) 13 | (memq 'b '(a b c)) ==> (b c) 14 | (memq 'a '(b c d)) ==> #f 15 | (memq (list 'a) '(b (a) c)) ==> #f 16 | (member (list 'a) '(b (a) c)) ==> ((a) c) 17 | (memq 101 '(100 101 102)) ==> unspecified 18 | (memv 101 '(100 101 102)) ==> (101 102) 19 | -------------------------------------------------------------------------------- /help/merge: -------------------------------------------------------------------------------- 1 | S9 LIB (merge procedure^2 list1 list2) ==> list 2 | 3 | Merge the members of two lists into one. The next member to be 4 | pushed to the output list will always be the one satisfying 5 | 6 | (procedure^2 (car list1) (car list2)) 7 | 8 | The list moved to the output is removed from the input list. 9 | When one list is empty, input will be taken from the other 10 | one. 11 | 12 | When both LIST1 and LIST2 are sorted under PROCEDURE^2, so 13 | will be the output. When a single-element list is merged with 14 | a sorted list, the single element will be inserted at such a 15 | position that the order of the other list is preserved. 16 | 17 | (merge < '(1 3 5) '(2 4 6)) ==> (1 2 3 4 5 6) 18 | (merge < '(1 5 3) '(2 4 6)) ==> (1 2 5 3 4 6) 19 | (merge < '(3) '(1 2 4 5)) ==> (1 2 3 4 5) 20 | -------------------------------------------------------------------------------- /help/mergesort: -------------------------------------------------------------------------------- 1 | S9 LIB (mergesort procedure^2 list) ==> list 2 | 3 | Sort lists using the mergesort algorithm. PROCEDURE^2 is a 4 | binary predicate that describes the desired order. The original 5 | list is not changed. 6 | 7 | (mergesort <= '(5 3 7 9 1)) ==> (1 3 5 7 9) 8 | -------------------------------------------------------------------------------- /help/minus: -------------------------------------------------------------------------------- 1 | R4RS 6.5.5 (- number ...) ==> number 2 | (/ number ...) ==> number 3 | 4 | With two or more arguments, these procedures return the difference 5 | or quotient of their arguments, associating to the left. With one 6 | argument, however, they return the additive or multiplicative inverse 7 | of their argument. 8 | 9 | (- 3 4) ==> -1 10 | (- 3 4 5) ==> -6 11 | (- 3) ==> -3 12 | (/ 3 4 5) ==> 0.15 13 | (/ 4) ==> 0.25 14 | 15 | -------------------------------------------------------------------------------- /help/mode: -------------------------------------------------------------------------------- 1 | S9 LIB (mode list) ==> list 2 | 3 | (load-from-library "mode.scm") 4 | 5 | Return the mode(s) of a list of values. The mode of a set of samples 6 | is the value that occurs most frequently. A set may be multi-modal, 7 | i.e. have multiples modes. 8 | 9 | (mode '(1 2 3 3 4 5 5 6)) ==> (3 5) 10 | -------------------------------------------------------------------------------- /help/module: -------------------------------------------------------------------------------- 1 | S9 LIB (module ...) ==> unspecific 2 | (using ( ...) ...) ==> object 3 | 4 | (load-from-library "simple-modules.scm") 5 | 6 | Simple modules. Inside of a MODULE expression, DEFINE defines 7 | a local object and DEFINE* defines a public object. names 8 | the module itself. 9 | 10 | Expressions inside of USING may use all 's that are 11 | being imported from the module . 12 | 13 | (module math 14 | (define* (fact x) 15 | (if (= 0 x) 1 (* x (fact (- x 1)))))) 16 | 17 | (using math (fact) 18 | (fact 5)) ==> 120 19 | -------------------------------------------------------------------------------- /help/ndf: -------------------------------------------------------------------------------- 1 | S9 LIB (ndf real) ==> real 2 | (ndf* real) ==> real 3 | 4 | (load-from-library "ndf.scm") 5 | 6 | Compute the probability density at the given standard deviation 7 | (normal distribution function). Assuming a standard normal 8 | distribution. 9 | 10 | (ndf 0) ==> 0.4 11 | -------------------------------------------------------------------------------- /help/newline: -------------------------------------------------------------------------------- 1 | R4RS 6.10.3 (newline) ==> unspecific 2 | (newline output-port) ==> unspecific 3 | 4 | Writes an end of line to OUTPUT-PORT. Exactly how this is done 5 | differs from one operating system to another. Returns an unspecified 6 | value. The OUTPUT-PORT argument may be omitted, in which case it 7 | defaults to the value returned by CURRENT-OUTPUT-PORT. 8 | -------------------------------------------------------------------------------- /help/not: -------------------------------------------------------------------------------- 1 | R4RS 6.1 (not object) ==> boolean 2 | 3 | NOT returns #T if OBJECT is false, and returns #F otherwise. 4 | 5 | (not #t) ==> #f 6 | (not 3) ==> #f 7 | (not (list 3)) ==> #f 8 | (not #f) ==> #t 9 | (not '()) ==> #f 10 | (not (list)) ==> #f 11 | (not 'nil) ==> #f 12 | -------------------------------------------------------------------------------- /help/nullp: -------------------------------------------------------------------------------- 1 | R4RS 6.3 (null? object) ==> boolean 2 | 3 | Returns #T if OBJECT is the empty list, otherwise returns #F. 4 | -------------------------------------------------------------------------------- /help/numberp: -------------------------------------------------------------------------------- 1 | R4RS 6.5.5 (integer? object) ==> boolean 2 | (number? object) ==> boolean 3 | (real? object) ==> boolean 4 | 5 | These numerical type predicates can be applied to any kind of 6 | argument, including non-numbers. They return #t if the object is 7 | of the named type, and otherwise they return #f. In general, if a 8 | type predicate is true of a number then all higher type predicates 9 | are also true of that number. Consequently, if a type predicate is 10 | false of a number, then all lower type predicates are also false 11 | of that number. 12 | 13 | (real? 3) ==> #t 14 | (real? -2.5) ==> #t 15 | (real? #e1e10) ==> #t 16 | (integer? 3) ==> #t 17 | (integer? 3.0) ==> #t 18 | 19 | Note: The behavior of these type predicates on inexact numbers is 20 | unreliable, since any inaccuracy may affect the result. 21 | -------------------------------------------------------------------------------- /help/open-append-file: -------------------------------------------------------------------------------- 1 | S9fES (open-append-file string) ==> output-port 2 | 3 | Take a string naming an output file and return an output port 4 | capable of writing characters to the that file. Characters 5 | written to the port will be appended to the file. When the 6 | file does not exist when this procedure is called, it will 7 | be created. If the file cannot be opened, an error is signalled. 8 | -------------------------------------------------------------------------------- /help/open-input-file: -------------------------------------------------------------------------------- 1 | R4RS 6.10 (open-input-file filename) ==> input-port 2 | 3 | Takes a string naming an existing file and returns an input port 4 | capable of delivering characters from the file. If the file cannot 5 | be opened, an error is signalled. 6 | -------------------------------------------------------------------------------- /help/open-output-file: -------------------------------------------------------------------------------- 1 | R4RS 6.10 (open-output-file filename) ==> output-port 2 | 3 | Takes a string naming an output file to be created and returns an 4 | output port capable of writing characters to a new file by that 5 | name. If the file cannot be opened, an error is signalled. If a 6 | file with the given name already exists, the effect is unspecified. 7 | 8 | S9fES silently overwrites the existing file when the file specified 9 | in STRING already exists. 10 | -------------------------------------------------------------------------------- /help/or: -------------------------------------------------------------------------------- 1 | R4RS 4.2.1 (or ...) ==> obj 2 | 3 | The s are evaluated from left to right, and the value 4 | of the first expression that evaluates to a true value (see section 5 | see section 6.1 Booleans) is returned. Any remaining expressions 6 | are not evaluated. If all expressions evaluate to false values, the 7 | value of the last expression is returned. If there are no expressions 8 | then #F is returned. 9 | 10 | (or (= 2 2) (> 2 1)) ==> #t 11 | (or (= 2 2) (< 2 1)) ==> #t 12 | (or #f #f #f) ==> #f 13 | (or (memq 'b '(a b c)) 14 | (quotient 3 0)) ==> (b c) 15 | -------------------------------------------------------------------------------- /help/pairp: -------------------------------------------------------------------------------- 1 | R4RS 6.3 (pair? object) ==> boolean 2 | 3 | PAIR? returns #T if OBJECT is a pair, and otherwise returns #F. 4 | 5 | (pair? '(a . b)) ==> #t 6 | (pair? '(a b c)) ==> #t 7 | (pair? '()) ==> #f 8 | (pair? '#(a b)) ==> #f 9 | -------------------------------------------------------------------------------- /help/partition: -------------------------------------------------------------------------------- 1 | S9 LIB (partition proceduce^1 list) ==> (list_1 list_2) 2 | 3 | Partition a list into elements with and without a given property. 4 | The unary predicate P, which is given in the procedure argument, 5 | specifies the property. The returned value contains two lists, 6 | where the first one holds the elements satisfying the property 7 | and the second one the elements not satisfying the property. 8 | 9 | (partition even? '(1 2 3 4 5)) ==> ((2 4) (1 3 5)) 10 | -------------------------------------------------------------------------------- /help/peek-char: -------------------------------------------------------------------------------- 1 | R4RS 6.10.2 (peek-char) ==> char | eof-object 2 | (peek-char input-port) ==> char | eof-object 3 | 4 | Returns the next character available from the input port, without 5 | updating the port to point to the following character. If no more 6 | characters are available, an end of file object is returned. 7 | INPUT-PORT may be omitted, in which case it defaults to the value 8 | returned by CURRENT-INPUT-PORT. 9 | 10 | Note: The value returned by a call to PEEK-CHAR is the same as the 11 | value that would have been returned by a call to READ-CHAR with the 12 | same port. The only difference is that the very next call to READ-CHAR 13 | or PEEK-CHAR on that port will return the value returned by the 14 | preceding call to PEEK-CHAR. In particular, a call to PEEK-CHAR on 15 | an interactive port will hang waiting for input whenever a call to 16 | READ-CHAR would have hung. 17 | -------------------------------------------------------------------------------- /help/permute: -------------------------------------------------------------------------------- 1 | S9 LIB (permute integer list) ==> list 2 | (permute* integer list) ==> list 3 | 4 | (load-from-library "permute.scm") 5 | 6 | Create k-permutations of the elements of the given list. K (the 7 | size of the permutations) is specified in the integer argument. 8 | PERMUTE creates permutations without repetition and PERMUTE* 9 | creates permutations with repetition. 10 | 11 | (permute 2 '(a b c)) ==> ((a b) (b a) (a c) 12 | (c a) (b c) (c b)) 13 | 14 | (permute* 2 '(a b c)) ==> ((a a) (a b) (a c) 15 | (b a) (b b) (b c) 16 | (c a) (c b) (c c)) 17 | -------------------------------------------------------------------------------- /help/plus: -------------------------------------------------------------------------------- 1 | R4RS 6.5.5 (+ number1 ...) ==> number 2 | (+) ==> number 3 | (* number1 ...) ==> number 4 | (*) ==> number 5 | 6 | These procedures return the sum or product of their arguments. 7 | 8 | (+ 3 4) ==> 7 9 | (+ 3) ==> 3 10 | (+) ==> 0 11 | (* 4) ==> 4 12 | (*) ==> 1 13 | -------------------------------------------------------------------------------- /help/position: -------------------------------------------------------------------------------- 1 | S9 LIB (position object list) ==> integer | #f 2 | (posv object list) ==> integer | #f 3 | (posq object list) ==> integer | #f 4 | (posp procedure object list) ==> integer | #f 5 | 6 | Find the position of an object in a list. When LIST contains OBJECT, 7 | return the position of OBJECT (where the first object is as position 8 | zero) and otherwise return #F. 9 | 10 | POSP uses PROCEDURE as a predicate to compare OBJECT to each member 11 | of list. 12 | 13 | (Position a b) equals (posp equal? a b) 14 | (Posv a b) equals (posp eqv? a b) 15 | (Posq a b) equals (posp eq? a b) 16 | 17 | (position '(bar) '((foo) (bar) (baz))) ==> 1 18 | (posv 4 '(0 1 2 3 4 5 6)) ==> 4 19 | (posq 'foo '(foo bar baz)) ==> 0 20 | (posp (lambda (x y) (= x (car y))) 21 | 2 22 | '((0 . a) (1 . b) (2 . c))) ==> 2 23 | -------------------------------------------------------------------------------- /help/print: -------------------------------------------------------------------------------- 1 | S9fES (print object ...) ==> unspecific 2 | 3 | Write the external representation of each given OBJECT to the port 4 | returned by CURRENT-OUTPUT-PORT. Use WRITE to write each external 5 | representation. Display one space character between adjacent objects. 6 | Display a newline sequence after the last object. PRINT with no 7 | arguments is equal to (NEWLINE). 8 | -------------------------------------------------------------------------------- /help/procedurep: -------------------------------------------------------------------------------- 1 | R4RS 6.9 (procedure? object) ==> boolean 2 | 3 | Returns #T if OBJECT is a procedure, otherwise returns #F. 4 | 5 | (procedure? car) ==> #t 6 | (procedure? 'car) ==> #f 7 | (procedure? (lambda (x) (* x x))) ==> #t 8 | (procedure? '(lambda (x) (* x x))) ==> #f 9 | -------------------------------------------------------------------------------- /help/programp: -------------------------------------------------------------------------------- 1 | S9 LIB (program? object) ==> boolean 2 | 3 | (load-from-library "programp.scm") 4 | 5 | Return #T, if OBJECT is a syntactically correct Scheme program. 6 | This program does not implement all of R4RS. Caveat utilitor. 7 | 8 | (program? '(let ((x 1)) (cons x x))) ==> #t 9 | -------------------------------------------------------------------------------- /help/proper-timep: -------------------------------------------------------------------------------- 1 | S9 LIB (proper-time? time-list) ==> boolean 2 | 3 | Return #T if the given TIME-LIST is a proper TIME-LIST as defined 4 | by the UNIX-TIME->TIME procedure. Otherwise return #F. 5 | 6 | (proper-time? '(3 1970 1 1 0 0 0)) ==> #t 7 | -------------------------------------------------------------------------------- /help/quartile: -------------------------------------------------------------------------------- 1 | S9 LIB (quartile list) ==> list 2 | 3 | (load-from-library "quartile.scm") 4 | 5 | Return a list (L M H), where L is the value that is greater than or 6 | equal to 25% of the values in LIST, M is >= 50% of the list, and H is 7 | >= 75% of the list. 8 | 9 | (quartile '(1 2 3 4 5 6 7 )) ==> (2 4 6) 10 | -------------------------------------------------------------------------------- /help/queens: -------------------------------------------------------------------------------- 1 | S9 LIB (queens n) ==> list 2 | 3 | Solve the N-Queens puzzle using AMK. All solutions for the 4 | given board size will be returned, where the offset in each 5 | list is an X position on the board and the value at that 6 | offset is the corresponding Y position. E.g., the board 7 | (2 0 3 1) would look like this: 8 | 9 | . . & . 3 10 | & . . . 2 11 | . . . & 1 12 | . & . . 0 13 | 0 1 2 3 14 | 15 | (queens 4) ==> ((2 0 3 1) (1 3 0 2)) 16 | -------------------------------------------------------------------------------- /help/quicksort: -------------------------------------------------------------------------------- 1 | S9 LIB (quicksort procecure^2 list) ==> list 2 | 3 | Sort lists using the Quicksort algorithm. PROCEDURE^2 is a 4 | binary procedure describing the desired order. The original 5 | list is not changed. 6 | 7 | (quicksort <= '(5 3 7 9 1)) ==> (1 3 5 7 9) 8 | -------------------------------------------------------------------------------- /help/quit: -------------------------------------------------------------------------------- 1 | S9fES (quit) ==> undefined 2 | 3 | Exit from S9 and return control to the invoking process. 4 | 5 | QUIT never returns any value. 6 | 7 | (quit) ==> undefined 8 | -------------------------------------------------------------------------------- /help/r4rs-procedures: -------------------------------------------------------------------------------- 1 | S9 LIB (r4rs-syntax-objects) ==> list 2 | (s9fes-syntax-objects) ==> list 3 | (r4rs-procedures) ==> list 4 | (s9fes-procedures) ==> list 5 | (s9fes-symbols) ==> list 6 | (s9fes-extension-procedures) ==> list 7 | (s9fes-extension-symbols) ==> list 8 | 9 | (load-from-library "symbols.scm") 10 | 11 | Return lists of symbols bound the corresponding type of object. 12 | Note: only the R4RS symbols defined in S9fES are included here. 13 | Caveat Utilitor. 14 | 15 | (s9fes-syntax-objects) ==> (if*) 16 | -------------------------------------------------------------------------------- /help/random: -------------------------------------------------------------------------------- 1 | S9 LIB (random integer) ==> integer 2 | (random-state integer) ==> procedure 3 | 4 | (load-from-library "random.scm") 5 | 6 | RANDOM returns a random number in the range [0;INTEGER], where 7 | INTEGER may not be any larger than 2**19 = 524288. 8 | 9 | RANDOM-STATE returns a procedure that resembles RANDOM but uses 10 | a user-supplied seed instead of a default one. RANDOM can be passed 11 | a different seed by running: 12 | 13 | (set! random (random-state SEED)) 14 | 15 | RANDOM-STATE uses a 19-bit linear feedback shift register. Hence 16 | its limited range. 17 | 18 | (let* ((a (random 100)) 19 | (b (random 100)) 20 | (c (random 100))) 21 | (list a b c)) ==> (5 47 68) 22 | -------------------------------------------------------------------------------- /help/random-sort: -------------------------------------------------------------------------------- 1 | S9 LIB (random-sort list) ==> list 2 | (random-sort list integer) ==> list 3 | 4 | Create a random permutation of LIST and return it. When INTEGER 5 | is specified, use it to initialize a random state (see RANDOM). 6 | When no seed or the same seed is specified, RANDOM-SORT will 7 | always deliver the same permutation. 8 | 9 | (random-sort '(1 2 3 4 5)) ==> (2 5 1 4 3) 10 | -------------------------------------------------------------------------------- /help/range: -------------------------------------------------------------------------------- 1 | S9 LIB (range list) ==> list 2 | 3 | (load-from-library "range.scm") 4 | 5 | Return a list containing the minimal and maximal value of a set. 6 | (- (cadr (range set)) (car (range set))) is the statistical range 7 | of a set of samples. 8 | 9 | (range '(1 2 3 4 5)) ==> (1 5) 10 | -------------------------------------------------------------------------------- /help/read-char: -------------------------------------------------------------------------------- 1 | R4RS 6.10.2 (read-char) ==> char | eof-object 2 | (read-char input-port) ==> char | eof-object 3 | 4 | Returns the next character available from the input port, updating 5 | the port to point to the following character. If no more characters 6 | are available, an end of file object is returned. INPUT-PORT may 7 | be omitted, in which case it defaults to the value returned by 8 | CURRENT-INPUT-PORT. 9 | -------------------------------------------------------------------------------- /help/read-file: -------------------------------------------------------------------------------- 1 | S9 LIB (read-file) ==> list 2 | (read-file input-port) ==> list 3 | 4 | Read a text file from an input port, return a list containing 5 | one string for each line read. When no INPUT-PORT is specified, 6 | read the current input port. 7 | 8 | (with-input-from-file "lib/read-file.scm" read-file) 9 | ==> [lots of lines] 10 | -------------------------------------------------------------------------------- /help/read-line: -------------------------------------------------------------------------------- 1 | S9 LIB (read-line) ==> string 2 | (read-line input-port) ==> string 3 | 4 | Read a line from an input port. When no INPUT-PORT is specified, 5 | read the current input port. 6 | 7 | (with-input-from-file "lib/read-line.scm" read-line) 8 | ==> "; Scheme 9 from Empty Space, Function Library" 9 | -------------------------------------------------------------------------------- /help/remove: -------------------------------------------------------------------------------- 1 | S9 LIB (remove obj list) ==> list 2 | (remp procedure^1 list) ==> list 3 | (remq obj list) ==> list 4 | (remv obj list) ==> list 5 | 6 | (load-from-library "remove.scm") 7 | 8 | Remove elements from a list. REMP uses the unary predicate 9 | PROCEDURE^1 to describe the property of the elements to be 10 | removed. REMOVE uses EQUAL?, REMV uses EQV?, and REMQ uses 11 | EQ? to compare each element of LIST to OBJ. 12 | 13 | (remp number? '(a 1 b 2 c 3)) ==> (a b c) 14 | (remove '(b) '(a (b) (c) (b))) ==> (a (c)) 15 | (remq 'b '(a b c b d)) ==> (a c d) 16 | (remv 3 '(3 1 2 3 1)) ==> (1 2 1) 17 | -------------------------------------------------------------------------------- /help/replace: -------------------------------------------------------------------------------- 1 | S9 LIB (replace object-old object-new pair) ==> pair 2 | 3 | Replace elements of a pair. OBJECT-OLD is the object to be 4 | replaced and OBJECT-NEW is the new object. 5 | 6 | (replace '(x) '(y) '(lambda (x) y)) ==> (lambda (y) y) 7 | -------------------------------------------------------------------------------- /help/require-extension: -------------------------------------------------------------------------------- 1 | S9fES (require-extension ...) ==> unspecific 2 | 3 | When the given s have been compiled into the interpreter 4 | expanding this form, the form evaluates to an unspecific value. When 5 | at least one of the given s is absent, an error is 6 | signalled. 7 | 8 | Each extension may be either a symbol or a list of the form 9 | 10 | (or ...) 11 | 12 | where each names an extension. For the REQUIRE-EXTENSIONS form 13 | to succeed, it is sufficient if one of the extensions named in (or ...) 14 | is present. For example: 15 | 16 | (require-extension curses) 17 | 18 | requires the CURSES extension to be compiled-in, and 19 | 20 | (require-extension (or sys-unix sys-plan9)) 21 | 22 | requires either the SYS-UNIX or the SYS-PLAN9 extension to be present. 23 | (In the unlikely case that both the SYS-UNIX and SYS-PLAN9 extensions 24 | would be detected, the form would still succeed). 25 | -------------------------------------------------------------------------------- /help/reverse: -------------------------------------------------------------------------------- 1 | R4RS 6.3 (reverse list) ==> list 2 | 3 | Returns a newly allocated list consisting of the elements of LIST 4 | in reverse order. 5 | 6 | (reverse '(a b c)) ==> (c b a) 7 | (reverse '(a (b c) d (e (f)))) ==> ((e (f)) d (b c) a) 8 | -------------------------------------------------------------------------------- /help/reverseb: -------------------------------------------------------------------------------- 1 | S9fES (reverse! list) ==> list 2 | 3 | Reverse LIST in situ, thereby destroying the original list. 4 | Return the reversed list. REVERSE! is much more efficient 5 | than REVERSE, but does not preserve the original list. When 6 | porting S9fES programs, REVERSE! can be replaced by REVERSE. 7 | 8 | NOTE: When reversing a list that is bound to a symbol, the 9 | symbol will thereafter no longer be bound to the list. Hence 10 | the expression 11 | 12 | (set! x (reverse! x)) 13 | 14 | should be used to reverse the list bound to X. 15 | 16 | (reverse! (list 1 2 3 4 5)) ==> (5 4 3 2 1) 17 | -------------------------------------------------------------------------------- /help/runstar: -------------------------------------------------------------------------------- 1 | S9 LIB (run* (variable) query) ==> list 2 | (run* () query) ==> list 3 | 4 | (load-from-library "amk.scm") 5 | 6 | Run the given AMK (Another Micro Kanren) query and return its 7 | result, if any. See the book "Logic Programming in Scheme"[1] 8 | for an introduction to AMK. If a variable is given, return all 9 | values for that variable that satisfy the query. 10 | 11 | [1] http://www.lulu.com/shop/nils-m-holm/logic-programming-in-scheme/\ 12 | paperback/product-18693432.html 13 | 14 | (run* (q) (fresh (h t) 15 | (== q (list h t)) 16 | (appendo h t '(1 2 3)))) 17 | ==> ((() (1 2 3)) ((1) (2 3)) ((1 2) (3)) ((1 2 3) ())) 18 | -------------------------------------------------------------------------------- /help/s9_bytecode: -------------------------------------------------------------------------------- 1 | S9fES (s9:bytecode procedure) ==> vector 2 | 3 | Return a vector containing the bytecode of the given PROCEDURE. 4 | The resulting vector will contain the entire compilation unit 5 | in which the given procedure was defined, including details such 6 | as the assignment to the environment slot of its symbol. When 7 | multiple procedures are defined inside of a BEGIN block, the 8 | compilation block will contain all definitions of that block. 9 | 10 | The bytecode instructions contained in the vector are subject 11 | to change without notice. 12 | 13 | Rationale: 14 | 15 | The S9:BYTECODE procedure is intended to support procedures that 16 | are internal to the S9 interpreter, such as a disassembler. No 17 | user code would normally want to apply this procedure. 18 | -------------------------------------------------------------------------------- /help/set-carb: -------------------------------------------------------------------------------- 1 | R4RS 6.3 (set-car! pair object) ==> unspecific 2 | 3 | Stores OBJECT in the car field of PAIR. The value returned by 4 | SET-CAR! is unspecified. 5 | 6 | (define (f) (list 'not-a-constant-list)) 7 | (define (g) '(constant-list)) 8 | 9 | (set-car! (f) 3) ==> unspecified 10 | (set-car! (g) 3) ==> error 11 | -------------------------------------------------------------------------------- /help/set-cdrb: -------------------------------------------------------------------------------- 1 | R4RS 6.3 (set-cdr! pair object) ==> unspecific 2 | 3 | Stores OBJECT in the cdr field of PAIR. The value returned by 4 | SET-CDR! is unspecified. 5 | 6 | (define (f) (list 'not-a-constant-list)) 7 | (define (g) '(constant-list)) 8 | 9 | (set-cdr! (f) 3) ==> unspecified 10 | (set-cdr! (g) 3) ==> error 11 | -------------------------------------------------------------------------------- /help/set-difference: -------------------------------------------------------------------------------- 1 | S9 LIB (set-difference list ...) ==> list 2 | 3 | Compute the difference of a number of sets. 4 | 5 | (set-difference '(a b c d e f) '(b d) '(a f)) ==> (c e) 6 | -------------------------------------------------------------------------------- /help/set-input-portb: -------------------------------------------------------------------------------- 1 | S9fES (set-input-port! input-port) ==> unspecific 2 | (set-output-port! output-port) ==> unspecific 3 | 4 | Change the default input and output ports by mutating the values 5 | returned by CURRENT-INPUT-PORT and CURRENT-OUTPUT-PORT respectively. 6 | -------------------------------------------------------------------------------- /help/setb: -------------------------------------------------------------------------------- 1 | R4RS 4.1.6 (set! ) ==> unspecific 2 | 3 | is evaluated, and the resulting value is stored in the 4 | location to which is bound. must be bound 5 | either in some region enclosing the SET! expression or at top level. 6 | The result of the SET! expression is unspecified. 7 | 8 | (define x 2) 9 | (+ x 1) ==> 3 10 | (set! x 4) ==> unspecified 11 | (+ x 1) ==> 5 12 | -------------------------------------------------------------------------------- /help/sieve: -------------------------------------------------------------------------------- 1 | S9 LIB (sieve integer) ==> list 2 | 3 | Given an INTEGER N, generate a list of all prime numbers less 4 | than N. INTEGER must be positive. 5 | 6 | (sieve 20) ==> (2 3 5 7 11 13 17 19) 7 | -------------------------------------------------------------------------------- /help/sort: -------------------------------------------------------------------------------- 1 | S9 LIB (sort procedure^2 list) ==> list 2 | 3 | Sort lists. PROCEDURE^2 is a binary predicate that describes the 4 | desired order. The original list is not changed. 5 | 6 | (sort <= '(5 3 7 9 1)) ==> (1 3 5 7 9) 7 | -------------------------------------------------------------------------------- /help/split: -------------------------------------------------------------------------------- 1 | S9 LIB (split list) ==> list 2 | 3 | Split a list into two, where the first one contains the leftmost 4 | members of the list and the second one its rightmost members. When 5 | the list has an odd number of members, the first list will hold 6 | the extra member. Return a list of two lists: 7 | 8 | (leftmost-members rightmost-members) 9 | 10 | (split '(1 2 3 4)) ==> ((1 2) (3 4)) 11 | (split '(1 2 3 4 5)) ==> ((1 2 3) (4 5)) 12 | (split '()) ==> (() ()) 13 | -------------------------------------------------------------------------------- /help/sqrt: -------------------------------------------------------------------------------- 1 | R4RS 6.5.5 (sqrt number) ==> number 2 | 3 | Returns the principal square root of NUMBER. 4 | 5 | (sqrt 2) ==> 1.41421356237309504 6 | -------------------------------------------------------------------------------- /help/stat-tools: -------------------------------------------------------------------------------- 1 | S9 LIB Convenience file to load statistics procedures. 2 | 3 | (load-from-library "cdf.scm") 4 | (load-from-library "erf.scm") 5 | (load-from-library "mean.scm") 6 | (load-from-library "median.scm") 7 | (load-from-library "mode.scm") 8 | (load-from-library "ndf.scm") 9 | (load-from-library "quartile.scm") 10 | (load-from-library "range.scm") 11 | (load-from-library "stddev.scm") 12 | 13 | -------------------------------------------------------------------------------- /help/stats: -------------------------------------------------------------------------------- 1 | S9fES (stats form) ==> list 2 | 3 | Evaluate the given FORM and return a list containing its 4 | normal form plus the resources used to compute that normal 5 | form: 6 | 7 | - total nodes allocated 8 | - conses allocated 9 | - vector cells allocated 10 | - garbage collections performed 11 | 12 | Each resource count will be returned as a group of integers 13 | representing ones, thousands, millions, etc. Note that FORM 14 | must be quoted or it will be evaluated before passing it to 15 | STATS. 16 | 17 | (stats '(reverse '(1 2 3))) ==> ((3 2 1) 18 | (0 0 0 0 3) ; nodes 19 | (0 0 0 0 3) ; conses 20 | (0 0 0 0 0) ; vcells 21 | (0 0 0 0 0)) ; GCs 22 | -------------------------------------------------------------------------------- /help/stddev: -------------------------------------------------------------------------------- 1 | S9 LIB (stddev list) ==> real 2 | 3 | (load-from-library "stddev.scm") 4 | 5 | Return the standard deviation of the given list of values. 6 | 7 | (stddev '(1 1 2 1 1)) ==> 0.4 8 | -------------------------------------------------------------------------------- /help/string: -------------------------------------------------------------------------------- 1 | R4RS 6.7 (string char ...) ==> string 2 | 3 | Returns a newly allocated string composed of the arguments. 4 | -------------------------------------------------------------------------------- /help/string-append: -------------------------------------------------------------------------------- 1 | R4RS 6.7 (string-append string ...) ==> string 2 | 3 | Returns a newly allocated string whose characters form the 4 | concatenation of the given strings. 5 | -------------------------------------------------------------------------------- /help/string-copy: -------------------------------------------------------------------------------- 1 | R4RS 6.7 (string-copy string) ==> string 2 | 3 | Returns a newly allocated copy of the given string. 4 | -------------------------------------------------------------------------------- /help/string-digest: -------------------------------------------------------------------------------- 1 | S9 LIB (string-digest string) ==> integer 2 | (string-digest string integer) ==> integer 3 | 4 | Create a digest of the given string and return it. If specified, 5 | INTEGER determines the maximum size of the digest (2^INTEGER). 6 | 7 | CAVEAT: This procedures uses a simple non-cryptographic BSD 8 | sum-style algorithm. It should be replaced with a function 9 | generating more unique digests. 10 | 11 | The maximum digest size defaults to 2^32. 12 | 13 | (string-digest "hello") ==> 2107915172 14 | -------------------------------------------------------------------------------- /help/string-expand: -------------------------------------------------------------------------------- 1 | S9 LIB (string-expand string) ==> string 2 | (string-expand string integer) ==> string 3 | 4 | Expand horizontal tabulation (HT, ASCII 9, aka "TAB") characters 5 | in STRING to spaces. Return a new string. When INTEGER is specified, 6 | expand each TAB to INTEGER spaces at maximum (default = 8). 7 | 8 | (let ((tab (integer->char 9))) 9 | (string-expand (string #\x tab #\y))) ==> "x y" 10 | -------------------------------------------------------------------------------- /help/string-fillb: -------------------------------------------------------------------------------- 1 | R4RS 6.7 (string-fill! string char) ==> unspecific 2 | 3 | Stores CHAR in every element of the given STRING and returns an 4 | unspecified value. 5 | -------------------------------------------------------------------------------- /help/string-length: -------------------------------------------------------------------------------- 1 | R4RS 6.7 (string-length string) ==> integer 2 | 3 | Returns the number of characters in the given string. 4 | -------------------------------------------------------------------------------- /help/string-locate: -------------------------------------------------------------------------------- 1 | S9 LIB (string-locate string1 string2) ==> offset | #f 2 | (string-ci-locate string1 string2) ==> offset | #f 3 | 4 | (load-from-library "string-locate.scm") 5 | 6 | Attempt to locate the pattern STRING1 in the text STRING2. Return 7 | the offset of the first occurrence of STRING1 in STRING2 or #F, 8 | if STRING2 does not contain STRING1. 9 | 10 | This program is based on "A Very Fast Substring Search Algorithm", 11 | Daniel M. Sunday, CACM v33, #8, August 1990 and the 12 | SUBSTRING-SEARCH-MAKER procedure by Ken Dickey (1990). 13 | 14 | (string-locate "test" "This is a test string") ==> 10 15 | (string-locate "TEST" "This is a test string") ==> #f 16 | -------------------------------------------------------------------------------- /help/string-map: -------------------------------------------------------------------------------- 1 | S9 LIB (string-map procedure^1 string ...) ==> string 2 | (string-map! procedure^1 string ...) ==> unspecific 3 | 4 | (load-from-library "string-map.scm") 5 | 6 | Map a procedure over a string, giving a new string 7 | 8 | (string (f (string-ref s i)) ...) 9 | 10 | where F is the given PROCEDURE and S is the string to map. 11 | STRING-MAP is to strings what MAP is to lists. 12 | 13 | STRING-MAP! does not create a fresh string, but changes the 14 | given one in situ. 15 | 16 | (string-map char-downcase "HELLO") ==> "hello" 17 | (let ((s (string-copy "HELLO!"))) 18 | (string-map! char-downcase s) 19 | s) ==> "hello!" 20 | -------------------------------------------------------------------------------- /help/string-parse: -------------------------------------------------------------------------------- 1 | S9 LIB (string-parse string1 string2) ==> list 2 | 3 | Split a string into substrings. STRING1 is a set of separators. 4 | Return a list containing all coherent sequences of non-separating 5 | characters contained in the given string. 6 | 7 | (string-parse " ?" " to be or not to be? ") 8 | ==> ("to" "be" "or" "not" "to" "be") 9 | -------------------------------------------------------------------------------- /help/string-prefixeqp: -------------------------------------------------------------------------------- 1 | S9 LIB (string-prefix=? string1 string2) ==> boolean 2 | (string-prefix-ci=? string1 string2) ==> boolean 3 | 4 | Return #T when STRING2 has a prefix of STRING1 and otherwise 5 | return #F. STRING-PREFIX-CI=? performs the same operation, but 6 | ignores the case of the strings. 7 | 8 | (string-prefix=? "foo" "foobar") ==> #t 9 | (string-prefix=? "foo" "fubar") ==> #f 10 | -------------------------------------------------------------------------------- /help/string-ref: -------------------------------------------------------------------------------- 1 | R4RS 6.7 (string-ref string integer) ==> char 2 | 3 | INTEGER must be a valid index of STRING. STRING-REF returns character 4 | at the INTEGER'th position of STRING using zero-origin indexing. 5 | -------------------------------------------------------------------------------- /help/string-reverse: -------------------------------------------------------------------------------- 1 | S9 LIB (string-reverse string) ==> string 2 | (string-reverse! string) ==> unspecific 3 | 4 | Create a fresh string and fill it with the characters of 5 | STRING, but in reverse order. STRING-REVERSE! reverses the 6 | characters of STRING in situ, overwriting the original 7 | string. 8 | 9 | (string-reverse "rats live on no evil star") 10 | ==> "rats live on no evil star" 11 | -------------------------------------------------------------------------------- /help/string-scan: -------------------------------------------------------------------------------- 1 | S9 LIB (string-scan char string) ==> integer | #f 2 | (string-ci-scan char string) ==> integer | #f 3 | 4 | (load-from-library "string-scan.scm") 5 | 6 | Scan STRING for CHAR. When STRING contains CHAR, return its position, 7 | otherwise return #F. STRING-CI-SCAN does the same but ignores case. 8 | 9 | (string-scan #\y "xyz") ==> 1 10 | -------------------------------------------------------------------------------- /help/string-setb: -------------------------------------------------------------------------------- 1 | R4RS 6.7 (string-set! string integer char) ==> unspecific 2 | 3 | INTEGER must be a valid index of STRING. STRING-SET! stores CHAR 4 | in the element at the INTEGER'th position of STRING and returns an 5 | unspecified value. 6 | 7 | (define (f) (make-string 3 #\*)) 8 | (define (g) "***") 9 | (string-set! (f) 0 #\?) ==> unspecified 10 | (string-set! (g) 0 #\?) ==> error 11 | (string-set! (symbol->string 'immutable) 0 #\?) ==> error 12 | -------------------------------------------------------------------------------- /help/string-split: -------------------------------------------------------------------------------- 1 | S9 LIB (string-split char string) ==> list 2 | 3 | Split a string into substrings. CHAR is interpreted as a separator. 4 | Return a list containing all coherent sequences of non-separating 5 | characters contained in the given string. When multiple subsequent 6 | separators are found, empty strings will be generated. 7 | 8 | (string-split #\: "a::b:c:") ==> ("a" "" "b" "c" "") 9 | -------------------------------------------------------------------------------- /help/string-to-list: -------------------------------------------------------------------------------- 1 | R4RS 6.7 (string->list string) ==> list 2 | (list->string chars) ==> string 3 | 4 | STRING->LIST returns a newly allocated list of the characters that 5 | make up the given string. LIST->STRING returns a newly allocated 6 | string formed from the characters in the list CHARS. STRING->LIST 7 | and LIST->STRING are inverses so far as EQUAL? is concerned. 8 | -------------------------------------------------------------------------------- /help/string-to-symbol: -------------------------------------------------------------------------------- 1 | R4RS 6.4 (string->symbol string) ==> symbol 2 | 3 | Returns the symbol whose name is STRING. This procedure can create 4 | symbols with names containing special characters or letters in the 5 | non-standard case, but it is usually a bad idea to create such 6 | symbols because in some implementations of Scheme they cannot be 7 | read as themselves. See SYMBOL->STRING. 8 | 9 | The following examples assume that the implementation's standard 10 | case is lower case: 11 | 12 | (eq? 'mISSISSIppi 'mississippi) ==> #t 13 | (string->symbol "mISSISSIppi") ==> the symbol with 14 | name "mISSISSIppi" 15 | (eq? 'bitBlt (string->symbol "bitBlt")) ==> #f 16 | (eq? 'JollyWog 17 | (string->symbol (symbol->string 'JollyWog))) ==> #t 18 | 19 | (string=? (symbol->string (string->symbol "K. Harper, M.D.")) 20 | "K. Harper, M.D." ==> #t 21 | -------------------------------------------------------------------------------- /help/string-translate: -------------------------------------------------------------------------------- 1 | S9 LIB (string-translate string1 string2 string3) ==> string 2 | 3 | Translate STRING1 by replacing each instance of a character 4 | that occurs in STRING2 by the character at the corresponding 5 | position in STRING3. STRING-TRANSLATE does not alter STRING1 6 | but returns a fresh string. 7 | 8 | (string-translate "a:b:c" ":" "-") ==> "a-b-c" 9 | 10 | (string-translate 11 | "hello, world!" 12 | "abcdefghijklmnopqrstuvwxyz" 13 | "nopqrstuvwxyzabcdefghijklm") ==> "uryyb, jbeyq!" 14 | -------------------------------------------------------------------------------- /help/string-unsplit: -------------------------------------------------------------------------------- 1 | S9 LIB (string-unsplit char list) ==> string 2 | 3 | Unsplit a list of strings, giving a new string. CHAR is placed between 4 | each two elements of LIST. 5 | 6 | (string-unsplit #\: '("" "a" "b" "" "c")) ==> ":a:b::c" 7 | -------------------------------------------------------------------------------- /help/string-upcase: -------------------------------------------------------------------------------- 1 | S9 LIB (string-upcase string) ==> string 2 | (string-downcase string) ==> string 3 | 4 | (load-from-library "string-case.scm") 5 | 6 | Return a fresh string containing the characters of STRING, but 7 | with the case of alphabetic characters converted. STRING-UPCASE 8 | converts characters to upper case, STRING-DOWNCASE to lower case. 9 | 10 | (string-upcase "Hello, World!") ==> "HELLO, WORLD!" 11 | (string-downcase "Hello, World!") ==> "hello, world!" 12 | -------------------------------------------------------------------------------- /help/stringeqp: -------------------------------------------------------------------------------- 1 | R4RS 6.7 (string=? string1 string2) ==> boolean 2 | (string-ci=? string1 string2) ==> boolean 3 | 4 | Returns #T if the two strings are the same length and contain the 5 | same characters in the same positions, otherwise returns #F. 6 | STRING-CI=? treats upper and lower case letters as though they were 7 | the same character, but STRING=? treats upper and lower case as 8 | distinct characters. 9 | -------------------------------------------------------------------------------- /help/stringp: -------------------------------------------------------------------------------- 1 | R4RS 6.7 (string? object) ==> boolean 2 | 3 | Returns #T if OBJECT is a string, otherwise returns #F. 4 | -------------------------------------------------------------------------------- /help/sublist: -------------------------------------------------------------------------------- 1 | S9 LIB (sublist list integer1 integer2) ==> list 2 | 3 | Return a fresh list formed from the members of LIST beginning with 4 | index INTEGER1 (inclusive) and ending with index INTEGER2 (exclusive). 5 | 6 | (sublist '(a b c d e) 2 4) ==> (c d) 7 | (sublist '(a b c d e) 2 2) ==> () 8 | -------------------------------------------------------------------------------- /help/subsetp: -------------------------------------------------------------------------------- 1 | S9 LIB (subset? list1 list2 ...) ==> list 2 | 3 | (load-from-library "subsetp.scm") 4 | 5 | Check whether each of a sequence of sets is a subset of the subsequent 6 | set in the list. The test succeeds even if a set is an improper subset 7 | of (i.e. the same sets) the subsequent one. 8 | 9 | (subset? '(a) '(a b) '(a b) '(a b c d)) ==> #t 10 | (subset? '(a b c)) ==> #t 11 | -------------------------------------------------------------------------------- /help/substitute: -------------------------------------------------------------------------------- 1 | S9 LIB (substitute pair alist) ==> pair 2 | 3 | Substitute objects in a given PAIR. The association list 4 | ALIST contains the objects to be substituted as keys and 5 | the corresponding substitutes as values. 6 | 7 | (substitute '(* (+ 5 7) 9) '(((+ 5 7) . 12))) ==> (* 12 9) 8 | -------------------------------------------------------------------------------- /help/substring: -------------------------------------------------------------------------------- 1 | R4RS 6.7 (substring string INTEGER-0 INTEGER-N) ==> string 2 | 3 | STRING must be a string, and INTEGER-0 and INTEGER-N must satisfy 4 | 5 | 0 <= INTEGER-0 <= INTEGER-N <= (string-length string). 6 | 7 | SUBSTRING returns a newly allocated string formed from the characters 8 | of STRING beginning with index INTEGER-0 (inclusive) and ending with 9 | index INTEGER-N (exclusive). 10 | -------------------------------------------------------------------------------- /help/subvector: -------------------------------------------------------------------------------- 1 | S9 LIB (subvector vector integer1 integer2) ==> vector 2 | 3 | SUBVECTOR returns a fresh vector formed from the members of VECTOR 4 | beginning with index INTEGER1 (inclusive) and ending with index 5 | INTEGER2 (exclusive). 6 | 7 | (subvector '#(a b c d e) 2 4) ==> #(c d) 8 | (subvector '#(a b c d e) 2 2) ==> #() 9 | -------------------------------------------------------------------------------- /help/sum: -------------------------------------------------------------------------------- 1 | S9 LIB (sum integer1 integer2) ==> integer 2 | 3 | Compute the sum of a range of integers. 4 | 5 | (sum 2 5) ==> 14 6 | -------------------------------------------------------------------------------- /help/symbolp: -------------------------------------------------------------------------------- 1 | R4RS 6.4 (symbol? object) ==> boolean 2 | 3 | Returns #T if OBJECT is a symbol, otherwise returns #F. 4 | 5 | (symbol? 'foo) ==> #t 6 | (symbol? (car '(a b))) ==> #t 7 | (symbol? "bar") ==> #f 8 | (symbol? 'nil) ==> #t 9 | (symbol? '()) ==> #f 10 | (symbol? #f) ==> #f 11 | -------------------------------------------------------------------------------- /help/symbols: -------------------------------------------------------------------------------- 1 | S9fES (symbols) ==> list 2 | 3 | Return a list of all symbols known to the system. 4 | -------------------------------------------------------------------------------- /help/syntax-extensions: -------------------------------------------------------------------------------- 1 | S9 LIB Convenience file to load extended syntax constructs. 2 | 3 | (load-from-library "amb.scm") 4 | (load-from-library "and-letstar.scm") 5 | (load-from-library "cond-expand.scm") 6 | (load-from-library "define-structure.scm") 7 | (load-from-library "fluid-let.scm") 8 | (load-from-library "hof.scm") 9 | (load-from-library "letcc.scm") 10 | (load-from-library "letrecstar.scm") 11 | (load-from-library "listq.scm") 12 | (load-from-library "setters.scm") 13 | (load-from-library "syntax-rules.scm") 14 | (load-from-library "type-case.scm") 15 | (load-from-library "when.scm") 16 | 17 | -------------------------------------------------------------------------------- /help/sys-plan9/plan9-tools: -------------------------------------------------------------------------------- 1 | S9 LIB Convenience file to load the Plan 9 programming procedures. 2 | 3 | (load-from-library "append-to-output-file.scm") 4 | (load-from-library "basename.scm") 5 | (load-from-library "dirname.scm") 6 | (load-from-library "find-help-path.scm") 7 | (load-from-library "flush-output-port.scm") 8 | (load-from-library "format-time.scm") 9 | (load-from-library "leap-yearp.scm") 10 | (load-from-library "mode-to-string.scm") 11 | (load-from-library "parse-optionsb.scm") 12 | (load-from-library "proper-timep.scm") 13 | (load-from-library "search-path.scm") 14 | (load-from-library "spawn-command.scm") 15 | (load-from-library "spawn-shell-command.scm") 16 | (load-from-library "standard-error.scm") 17 | (load-from-library "time-to-unix-time.scm") 18 | 19 | -------------------------------------------------------------------------------- /help/sys-plan9/util: -------------------------------------------------------------------------------- 1 | S9 LIB Useful during developing 2 | 3 | (define (remake) 4 | -------------------------------------------------------------------------------- /help/sys-unix/append-to-output-file: -------------------------------------------------------------------------------- 1 | S9 LIB (append-to-output-file string) ==> output-port 2 | 3 | Take a string naming an output file and return an output port 4 | capable of writing characters to the that file. Characters 5 | written to the port will be appended to the file. When the 6 | file does not exist when this procedure is called, it will 7 | be created. If the file cannot be opened, an error is signalled. 8 | 9 | This function has been superseded by the OPEN-APPEND-FILE 10 | primitive procedure in S9fES Reimagined. 11 | 12 | (append-to-output-file "logfile") ==> # 13 | -------------------------------------------------------------------------------- /help/sys-unix/flush-output-port: -------------------------------------------------------------------------------- 1 | S9 LIB (flush-output-port output-port) ==> unspecific 2 | (flush-output-port) ==> unspecific 3 | 4 | Flush the given output port by writing all pending output to 5 | the associated file descriptor. When no port is specified, 6 | flush (current-output-port). 7 | 8 | (flush-output-port) ==> unspecific 9 | -------------------------------------------------------------------------------- /help/sys-unix/mode-to-string: -------------------------------------------------------------------------------- 1 | S9 LIB (mode->string integer) ==> string 2 | 3 | Return a symbolic representation of the access mode specified in 4 | INTEGER. The resulting string is in the same format as used by 5 | the ls(1) Unix command. 6 | 7 | (mode->string #o5751) ==> "rwsr-x--t" 8 | -------------------------------------------------------------------------------- /help/sys-unix/search-path: -------------------------------------------------------------------------------- 1 | S9 LIB (search-path string1 string2) ==> string | #f 2 | 3 | Search the Unix search path STRING2 for the executable STRING1. Return 4 | the full path of the first executable found or #F if not executable 5 | named STRING1 can be found in the given path. 6 | STRING2 is a colon-separated list of paths, e.g.: 7 | 8 | "/bin:/usr/bin:/usr/local/bin" 9 | 10 | SEARCH-PATH uses ACCESS with mode ACCESS-X-OK to check whether a 11 | file is executable. 12 | 13 | (search-path "vi" "/bin:/usr/bin") ==> "/usr/bin/vi" 14 | -------------------------------------------------------------------------------- /help/sys-unix/spawn-shell-command: -------------------------------------------------------------------------------- 1 | S9 LIB (spawn-shell-command string) ==> list 2 | (spawn-shell-command/fd string) ==> list 3 | 4 | (load-from-library "spawn-shell-command.scm") 5 | 6 | Spawn a child process running the shell command STRING. Return 7 | a list of two I/O-ports and the PID of the child process: 8 | 9 | (input-port output-port integer) 10 | 11 | The input-port can be used to read the output of the command and 12 | the output-port to send input to the command. The command will be 13 | executed by running the equivalent of: 14 | 15 | execl("/bin/sh", "/bin/sh", "-c", STRING, NULL); 16 | 17 | Error output of the child will be redirected to its standard output. 18 | 19 | SPAWN-SHELL-COMMAND/FD is like SPAWN-SHELL-COMMAND, but delivers raw 20 | Unix file descriptors instead of input/output ports. 21 | 22 | (spawn-shell-command "ls -l /bin") 23 | ==> (# # 707) 24 | -------------------------------------------------------------------------------- /help/sys-unix/sys_access: -------------------------------------------------------------------------------- 1 | S9 EXT (sys:access string integer) ==> boolean 2 | 3 | Test whether the file named in STRING can be accessed in the 4 | way encoded in INTEGER. INTEGER may have one of these values: 5 | 6 | sys:access-f-ok test if the file exists 7 | sys:access-r-ok test if the file can be read 8 | sys:access-w-ok test if the file can be written 9 | sys:access-x-ok test if the file can be executed 10 | 11 | (sys:access "." sys:access-f-ok) ==> true 12 | -------------------------------------------------------------------------------- /help/sys-unix/sys_catch-errors: -------------------------------------------------------------------------------- 1 | S9 EXT (sys:catch-errors boolean) ==> unspecific 2 | 3 | When a SYS-UNIX extension procedure called by an S9 program fails, 4 | the interpreter will normally generate an error condition and 5 | abort program execution. When #T is passed to SYS:CATCH-ERRORS, 6 | though, procedures will return #F instead of aborting program 7 | execution and procedures that normally succeed silently will 8 | return #T in case of success. E.g.: 9 | 10 | (sys:rmdir "non-existent-directory") ==> undefined 11 | (sys:strerror (sys:errno)) ==> "No such file or directory" 12 | (sys:catch-errors #t) 13 | (sys:errno) ==> 0 14 | (sys:rmdir "non-existent-directory") ==> #f 15 | (sys:strerror (sys:errno)) ==> "No such file or directory" 16 | 17 | SYS:CATCH-ERRORS will also reset SYS:ERRNO when applied to #T. 18 | 19 | (sys:catch-errors #t) ==> unspecific 20 | -------------------------------------------------------------------------------- /help/sys-unix/sys_chdir: -------------------------------------------------------------------------------- 1 | S9 EXT (sys:chdir string) ==> unspecific 2 | 3 | Change the current working directory to STRING. 4 | 5 | (sys:chdir "directory") ==> unspecific 6 | -------------------------------------------------------------------------------- /help/sys-unix/sys_chown: -------------------------------------------------------------------------------- 1 | S9 EXT (sys:chown string integer1|string2|#f int2|str3|#f) ==> unspecific 2 | 3 | Change the ownership for the file STRING to user ID INTEGER1 4 | and the group ID INT2. 5 | 6 | When a symbolic user or group name is supplied the place of 7 | a numeric user/group ID, the name will be looked up in the user 8 | database and converted to numeric ID. When the placeholder #F 9 | is given in the place of an ID, the corresponding ID will be 10 | left unchanged. 11 | 12 | (sys:chown "file" 0 0) ==> unspecific 13 | (sys:chown "file" "root" #f) ==> unspecific 14 | (sys:chown "file" #f #f) ==> unspecific ; null operation 15 | -------------------------------------------------------------------------------- /help/sys-unix/sys_command-line: -------------------------------------------------------------------------------- 1 | S9 EXT (sys:command-line) ==> list 2 | 3 | Return the command line arguments passed to the S9 interpeter 4 | after the "--" argument. Each argument will be packaged in a 5 | separate string. 6 | 7 | You may prefer to use the COMMAND-LINE procedure that is built 8 | into the core interpreter. 9 | 10 | (sys:command-line) ==> () ; s9 11 | (sys:command-line) ==> ("a" "b" "c") ; s9 -- a b c 12 | ; or s9 program a b c 13 | -------------------------------------------------------------------------------- /help/sys-unix/sys_dup: -------------------------------------------------------------------------------- 1 | S9 EXT (sys:dup integer) ==> integer 2 | (sys:dup2 integer1 integer2) ==> integer 3 | 4 | SYS:DUP duplicates an existing file descriptor INTEGER and returns 5 | the new descriptor. Both desciptors can then be used to manipulate 6 | the same file. All operations affecting one of them also affects 7 | the other. 8 | 9 | In calls to SYS:DUP2, the new descriptor can be specified explicitly 10 | in the INTEGER2 argument. 11 | 12 | (define (redirect-to-file file) 13 | (sys:dup2 (sys:creat "transcript-file") 1)) 14 | -------------------------------------------------------------------------------- /help/sys-unix/sys_errno: -------------------------------------------------------------------------------- 1 | S9 EXT (sys:errno) ==> integer 2 | 3 | Return the error code set by the most recently called Unix extension 4 | procedure and reset the error code. Calling SYS:ERRNO repeatedly will 5 | deliver 0. 6 | 7 | (begin (sys:errno) 8 | (sys:errno)) ==> 0 9 | -------------------------------------------------------------------------------- /help/sys-unix/sys_execv: -------------------------------------------------------------------------------- 1 | S9 EXT (sys:execv string list) ==> undefined 2 | 3 | Replace the calling process with a process loaded from the 4 | executable file named in STRING. LIST must be a list of strings. 5 | The strings contained in LIST will be passed as arguments to the 6 | new process. SYS:EXECV does not return. 7 | 8 | (sys:execv "/bin/ls" '("-l")) 9 | -------------------------------------------------------------------------------- /help/sys-unix/sys_exit: -------------------------------------------------------------------------------- 1 | S9 EXT (sys:exit integer) ==> undefined 2 | (sys:exit) ==> undefined 3 | 4 | Terminate the S9 process and return INTEGER as an exit 5 | code to the calling process. When no explicit exit code 6 | is specified, return zero. 7 | 8 | SYS:EXIT never returns any value. 9 | 10 | (sys:exit 1) ==> undefined 11 | -------------------------------------------------------------------------------- /help/sys-unix/sys_fileno: -------------------------------------------------------------------------------- 1 | S9 EXT (sys:fileno port) ==> integer 2 | 3 | Return the Unix file descriptor associated with the given input 4 | or output port. 5 | 6 | (sys:fileno (current-input-port)) ==> 0 7 | -------------------------------------------------------------------------------- /help/sys-unix/sys_flush: -------------------------------------------------------------------------------- 1 | S9 EXT (sys:flush output-port) ==> unspecific 2 | 3 | Flush the given output port. 4 | 5 | (sys:flush (current-output-port)) ==> unspecific 6 | -------------------------------------------------------------------------------- /help/sys-unix/sys_fork: -------------------------------------------------------------------------------- 1 | S9 EXT (sys:fork) ==> integer 2 | 3 | Create a copy of the calling process, return the process ID of the 4 | calling process (the parent process) to the parent process and zero 5 | to the new process (the child process). 6 | 7 | (sys:fork) ==> 0 ; now there are two S9 interpreters running 8 | -------------------------------------------------------------------------------- /help/sys-unix/sys_get-magic-value: -------------------------------------------------------------------------------- 1 | S9 EXT (sys:get-magic-value string) ==> integer 2 | 3 | Retrieve a magic constant from the system. When the requested 4 | constant could not be delivered, signal an error and terminate 5 | the calling program. 6 | 7 | (sys:get-magic-value "O_RDONLY") ==> 0 8 | (sys:get-magic-value "SIGTERM") ==> 15 9 | -------------------------------------------------------------------------------- /help/sys-unix/sys_getcwd: -------------------------------------------------------------------------------- 1 | S9 EXT (sys:getcwd) ==> string 2 | 3 | Return the current working directory. 4 | 5 | (sys:getcwd) ==> "/u/home/nmh/src/s9" 6 | -------------------------------------------------------------------------------- /help/sys-unix/sys_getenv: -------------------------------------------------------------------------------- 1 | S9 EXT (sys:getenv string) ==> string | #f 2 | 3 | Return the value of the environment variable STRING. If 4 | the variable is undefined, return #F. 5 | 6 | You may prefer to use the ENVIRONMENT-VARIABLE procedure 7 | instead, which is built into the core S9 interpreter. 8 | 9 | (sys:getenv "HOME") ==> "/u/home/nmh" 10 | (sys:getenv "nonexistent") ==> #f 11 | -------------------------------------------------------------------------------- /help/sys-unix/sys_getgrnam: -------------------------------------------------------------------------------- 1 | S9 EXT (sys:getgrnam string) ==> alist 2 | (sys:getgrgid integer) ==> alist 3 | 4 | Return the group record for the group name STRING or the group ID 5 | INTEGER. The returned association list has the following members: 6 | 7 | ((name . string) ; group name 8 | (gid . integer)) ; group ID 9 | 10 | (sys:getgrnam "staff") ==> ((name . "staff") (gid . 20)) 11 | (sys:getgrgid 0) ==> ((name . "wheel") (gid . 0)) 12 | -------------------------------------------------------------------------------- /help/sys-unix/sys_getpgid: -------------------------------------------------------------------------------- 1 | S9 EXT (sys:getpgid integer) ==> integer 2 | (sys:setpgid integer) ==> unspecific 3 | 4 | SYS:GETPGRP returns the process group ID of the S9 process and 5 | SYS:SETPGRP changes the process group ID of the process. 6 | 7 | (sys:setpgrp (sys:getpgrp)) ==> unspecific 8 | -------------------------------------------------------------------------------- /help/sys-unix/sys_getpid: -------------------------------------------------------------------------------- 1 | S9 EXT (sys:getpid) ==> integer 2 | 3 | Return the process ID of the S9 process. 4 | 5 | (sys:getpid) ==> 8450 6 | -------------------------------------------------------------------------------- /help/sys-unix/sys_getpwent: -------------------------------------------------------------------------------- 1 | S9 EXT (sys:getpwent) ==> list 2 | 3 | Return a list of strings containing all user names contained 4 | in the system user database. 5 | 6 | (sys:getpwent) ==> ("root" "toor" "daemon" "operator" "bin" "tty" 7 | "kmem" "games" "news" "man" "uucp" "nobody" 8 | "nmh") 9 | -------------------------------------------------------------------------------- /help/sys-unix/sys_getpwnam: -------------------------------------------------------------------------------- 1 | S9 EXT (sys:getpwnam string) ==> alist | #f 2 | (sys:getpwuid integer) ==> alist | #f 3 | 4 | Return the password record for the user name STRING or the user 5 | ID INTEGER. The returned association list has the following members: 6 | 7 | ((name . string) ; user name 8 | (uid . integer) ; user ID 9 | (gid . integer) ; group ID 10 | (gecos . string) ; real name 11 | (home . string) ; home directory 12 | (shell . string)) ; default shell 13 | 14 | When an invalid user name or UID is passed to these procedures, #F 15 | is returned. 16 | 17 | (sys:getpwnam "nmh") ==> ((name . "nmh") 18 | (uid . 1001) 19 | (gid . 1001) 20 | (gecos . "Nils M Holm") 21 | (home . "/u/home/nmh") 22 | (shell . "/bin/ksh")) 23 | -------------------------------------------------------------------------------- /help/sys-unix/sys_gettimeofday: -------------------------------------------------------------------------------- 1 | S9 EXT (sys:gettimeofday) ==> list 2 | (sys:time) ==> integer 3 | 4 | SYS:GETTIMEOFDAY returns a list of the form 5 | 6 | (seconds microseconds) 7 | 8 | where SECONDS is the number of seconds since the Unix Epoch 9 | (1970-01-01T00:00:00) and microseconds the number of 10 | microseconds since the beginning of the current second. 11 | 12 | SYS:TIME returns the car part of the above list. 13 | 14 | (sys:gettimeofday ) ==> (1272263214 409904) 15 | (sys:time) ==> 1272263214 16 | -------------------------------------------------------------------------------- /help/sys-unix/sys_getuid: -------------------------------------------------------------------------------- 1 | S9 EXT (sys:getgid) ==> integer 2 | (sys:getuid) ==> integer 3 | 4 | Return the group ID (user ID) of the S9 process. 5 | 6 | (sys:getgid) ==> 1001 7 | (sys:getuid) ==> 1001 8 | -------------------------------------------------------------------------------- /help/sys-unix/sys_group-name: -------------------------------------------------------------------------------- 1 | S9 EXT (sys:group-name string|integer) ==> string 2 | (sys:group-gid string|integer) ==> integer 3 | 4 | Return the group name or GID associated with the group name 5 | STRING or the GID INTEGER. (Yes, getting the group name of a 6 | group name or the GID of a GID is an identity operation.) 7 | 8 | (sys:group-name 0) ==> "wheel" 9 | (sys:group-gid "wheel") ==> 0 10 | -------------------------------------------------------------------------------- /help/sys-unix/sys_inet-connect: -------------------------------------------------------------------------------- 1 | S9 EXT (sys:inet-connect string1 string2) ==> integer 2 | 3 | Create a fresh client socket and connect it to host STRING1, 4 | service STRING2. Return a file descriptor for accessing the 5 | new socket. 6 | 7 | ; Fetch HTML page "url" from HTTP server "host", port "port" 8 | ; 9 | (define (http-fetch host url port) 10 | (let* ((s (sys:inet-connect host port)) 11 | (in (sys:make-input-port s)) 12 | (out (sys:make-output-port s))) 13 | (display* out "GET http://" host "/" url " HTTP/1.0" #\newline #\newline) 14 | (sys:flush out) 15 | (let in-loop ((line (read-line in)) 16 | (page '())) 17 | (cond ((eof-object? line) 18 | (close-input-port in) 19 | (close-output-port out) 20 | (reverse page)) 21 | (else 22 | (in-loop (read-line in) 23 | (cons line page))))))) 24 | -------------------------------------------------------------------------------- /help/sys-unix/sys_inet-getpeername: -------------------------------------------------------------------------------- 1 | S9 EXT (sys:inet-getpeername integer) ==> list 2 | 3 | Find out the peer name (IP address and port) of the remote host 4 | connected through the socket described by the file descriptor 5 | INTEGER (this descriptor is typically returned by SYS:INET-ACCEPT). 6 | Return a list of the form 7 | 8 | (ip-address port) 9 | 10 | where IP-ADDRESS is a string and PORT is an integer. When no 11 | peer name could be associated with INTEGER, return #F. 12 | -------------------------------------------------------------------------------- /help/sys-unix/sys_kill: -------------------------------------------------------------------------------- 1 | S9 EXT (sys:kill integer1 integer2) ==> unspecific 2 | (sys:kill integer) ==> unspecific 3 | (sys:notify integer1 integer2) ==> unspecific 4 | (sys:notify integer) ==> unspecific 5 | 6 | Send signal INTEGER2 to process INTEGER1. When no signal is 7 | specified SYS:SIGTERM is sent. SYS:NOTIFY is a more nonviolent 8 | alias for this procedure. 9 | 10 | The following symbolic signal names may be used in the place of 11 | INTEGER2: sys:sighup, sys:sigint, sys:sigquit, sys:sigill, 12 | sys:sigtrap, sys:sigabrt, sys:sigemt, sys:sigfpe, sys:sigkill, 13 | sys:sigbus, sys:sigsegv, sys:sigsys, sys:sigpipe, sys:sigalrm, 14 | sys:sigterm. 15 | 16 | When a signal is sent to the S9 process, the result of these 17 | procedures is undefined. 18 | 19 | (sys:notify (sys:getpid) sys:sigterm) ==> undefined 20 | -------------------------------------------------------------------------------- /help/sys-unix/sys_link: -------------------------------------------------------------------------------- 1 | S9 EXT (sys:link string1 string2) ==> unspecific 2 | 3 | Create a (hard) link STRING2 that refers to the same file as 4 | STRING1. 5 | 6 | (sys:link "file" "new-name") ==> unspecific 7 | -------------------------------------------------------------------------------- /help/sys-unix/sys_lock: -------------------------------------------------------------------------------- 1 | S9 EXT (sys:lock string) ==> boolean 2 | 3 | Create a lock file named (string-append STRING ".lock"). If 4 | the file already exists when the function is called, return 5 | #F, indicating that the requested resource is already locked. 6 | Otherwise return #T. SYS:LOCK uses mkdir() to create the 7 | lock file, which is atomic on virtually all systems. 8 | 9 | (sys:unlock "foo") 10 | (list (sys:lock "foo") 11 | (sys:lock "foo")) ==> (#t #f) 12 | -------------------------------------------------------------------------------- /help/sys-unix/sys_lseek: -------------------------------------------------------------------------------- 1 | S9 EXT (sys:lseek integer1 integer2 integer3) ==> integer 2 | 3 | Move the file pointer of the file descriptor INTEGER1 to the 4 | position INTEGER2 from the origin INTEGER3. Valid origin values 5 | include: 6 | 7 | sys:seek-set (0) = seek from the beginning of the file 8 | sys:seek-cur (1) = seek from the current position 9 | sys:seek-end (2) = seek from the end of the file 10 | 11 | SYS:LSEEK returns the current file position after performing the 12 | seek operation. 13 | 14 | (sys:lseek fd 0 sys:seek-end) will position the file pointer at the 15 | end of the file and return the size of the file. Data subsequently 16 | written to FD will hence be appended to the corresponding file. 17 | 18 | (let ((fd (sys:creat "tmpfile"))) 19 | (sys:write fd "test") 20 | (sys:lseek fd 0 sys:seek-end)) ==> 4 21 | -------------------------------------------------------------------------------- /help/sys-unix/sys_make-input-port: -------------------------------------------------------------------------------- 1 | S9 EXT (sys:make-input-port integer) ==> input-port 2 | (sys:make-output-port integer) ==> output-port 3 | 4 | Create a new input or output port and assign it to the Unix file 5 | descriptor specified in the INTEGER argument. The file descriptor 6 | must be open and match the type of the port to be created, i.e. 7 | a file descriptor passed to SYS:MAKE-INPUT-PORT must be open for 8 | reading and a descriptor passed to SYS:MAKE-OUTPUT-PORT must be 9 | open for writing. 10 | 11 | (sys:make-input-port 0) ==> # 12 | (sys:make-output-port 2) ==> # 13 | -------------------------------------------------------------------------------- /help/sys-unix/sys_mkdir: -------------------------------------------------------------------------------- 1 | S9 EXT (sys:mkdir string integer) ==> unspecific 2 | (sys:mkdir string) ==> unspecific 3 | 4 | Create directory STRING with mode INTEGER. When no mode is 5 | passed to SYS:MKDIR, it defaults to #o755 (rwx-r-xr-x). 6 | 7 | (sys:mkdir "new-directory") ==> unspecific 8 | -------------------------------------------------------------------------------- /help/sys-unix/sys_pipe: -------------------------------------------------------------------------------- 1 | S9 EXT (sys:pipe) ==> list 2 | 3 | Create a Unix pipe (a FIFO structure) and return a list containing 4 | two file descriptors (integers) for accessing it: 5 | 6 | (read-descriptor write-descriptor) 7 | 8 | All data written to the write-descriptor will subsequently 9 | appear on the read-descriptor. Use the SYS:MAKE-INPUT-PORT and 10 | SYS:MAKE-OUTPUT-PORT procedures to turn file descriptors into 11 | I/O ports. 12 | 13 | (let* ((p (sys:pipe)) 14 | (in (sys:make-input-port (car p))) 15 | (out (sys:make-output-port (cadr p)))) 16 | (display "foo" out) 17 | (newline out) 18 | (sys:flush out) 19 | (read in)) ==> foo 20 | -------------------------------------------------------------------------------- /help/sys-unix/sys_readdir: -------------------------------------------------------------------------------- 1 | S9 EXT (sys:readdir string) ==> list 2 | 3 | Return a list of all file names contained in the directory STRING. 4 | SYS:READDIR never includes the special files "." and ".." in the 5 | resulting list. 6 | 7 | (sys:readdir "empty-directory") ==> () 8 | -------------------------------------------------------------------------------- /help/sys-unix/sys_readlink: -------------------------------------------------------------------------------- 1 | S9 EXT (sys:readlink string) ==> string 2 | 3 | Return the path of the file referred to by the symbolic link STRING. 4 | 5 | (sys:symlink "foo" "bar") 6 | (sys:readlink "bar") ==> "foo" 7 | -------------------------------------------------------------------------------- /help/sys-unix/sys_rename: -------------------------------------------------------------------------------- 1 | S9 EXT (sys:rename string1 string2) ==> unspecific 2 | 3 | Change the name of directory entry STRING1 to STRING2. 4 | 5 | (sys:rename "old-name" "new-name") ==> unspecific 6 | -------------------------------------------------------------------------------- /help/sys-unix/sys_rmdir: -------------------------------------------------------------------------------- 1 | S9 EXT (sys:rmdir string) ==> unspecific 2 | 3 | Remove directory STRING. The directory must be empty. 4 | 5 | (sys:rmdir "empty-directory") ==> unspecific 6 | -------------------------------------------------------------------------------- /help/sys-unix/sys_select: -------------------------------------------------------------------------------- 1 | S9 EXT (sys:select list1 list2 list3) ==> integer | #f 2 | 3 | Check whether any of the input file descriptors listed in LIST2 4 | or output file descriptors listed in LIST3 are ready for reading 5 | or writing respectively. Return the total number of file descriptors 6 | that are ready. When no descriptors are ready at all, return #F. 7 | 8 | LIST1 specifies the maximum time to wait for the file descriptors to 9 | become ready. It is a two-element list with the following members: 10 | 11 | (seconds microseconds) 12 | 13 | When '() is passed in the place of LIST1, SYS:SELECT will wait 14 | indefinitely. When '(0 0) is passed to it, it will return immediately, 15 | effectively implementing polling. 16 | 17 | (sys:select '(0 0) '() '()) ==> #f 18 | -------------------------------------------------------------------------------- /help/sys-unix/sys_setuid: -------------------------------------------------------------------------------- 1 | S9 EXT (sys:setgid integer) ==> unspecific 2 | (sys:setuid integer) ==> unspecific 3 | 4 | Change the group ID (user ID) of the S9 process to the given 5 | INTEGER. Only the superuser may change the UID/GID of a process 6 | to a value other than the current UID/GID. 7 | 8 | (sys:setgid (sys:getgid)) ==> unspecific 9 | (sys:setuid (sys:getuid)) ==> unspecific 10 | -------------------------------------------------------------------------------- /help/sys-unix/sys_strerror: -------------------------------------------------------------------------------- 1 | S9 EXT (sys:strerror integer) ==> string 2 | 3 | Create a fresh string explaining the Unix error condition encoded 4 | in INTEGER. Valid condition codes are delivered by the SYS:ERRNO 5 | procedure. 6 | 7 | (sys:strerror 2) ==> "No such file or directory" 8 | -------------------------------------------------------------------------------- /help/sys-unix/sys_symlink: -------------------------------------------------------------------------------- 1 | S9 EXT (sys:symlink string1 string2) ==> unspecific 2 | 3 | Create a symbolic link STRING2 that points to the path of 4 | STRING1. 5 | 6 | (sys:symlink "foo" "bar") ==> unspecific 7 | -------------------------------------------------------------------------------- /help/sys-unix/sys_system: -------------------------------------------------------------------------------- 1 | S9 EXT (sys:system string) ==> integer 2 | 3 | Run the command STRING and return its exit status. 4 | 5 | You may prefer to use the SYSTEM-COMMAND procedure 6 | instead, which is built into the core S9 interpreter. 7 | 8 | (sys:system "ls") ==> 0 9 | (sys:system "ls nonexistent") ==> 127 10 | -------------------------------------------------------------------------------- /help/sys-unix/sys_umask: -------------------------------------------------------------------------------- 1 | S9 EXT (sys:umask integer) ==> integer 2 | (sys:umask) ==> integer 3 | 4 | When applied to a single integer argument, the SYS:UMASK procedure 5 | sets the file creation mode mask of the S9 process and returns the 6 | old umask value. When called without any argument, it simply returns 7 | the current umask value. 8 | 9 | The new file creation mode mask will be the lower nine bits of INTEGER, 10 | corresponding to the following file access permission bits: 11 | 12 | User Group Other 13 | r w x r w x r w x 14 | 8 7 6 5 4 3 2 1 0 15 | 16 | When creating a file with the SYS:CREAT procedure or the 17 | OPEN-OUTPUT-FILE function, the bits set in the file creation 18 | mask will be zeroed in the permission bits of the new file. 19 | E.g., the default mask of #o022 will never allow the group 20 | or others to write to the new file. 21 | 22 | (begin (sys:umask #o22) (sys:umask)) ==> 18 23 | -------------------------------------------------------------------------------- /help/sys-unix/sys_unlink: -------------------------------------------------------------------------------- 1 | S9 EXT (sys:unlink string) ==> unspecific 2 | 3 | Remove the file name (directory entry) STRING. 4 | 5 | (sys:link "foo" "bar") 6 | (sys:unlink "bar") ==> unspecific 7 | -------------------------------------------------------------------------------- /help/sys-unix/sys_unlock: -------------------------------------------------------------------------------- 1 | S9 EXT (sys:unlock string) ==> unspecific 2 | 3 | Remove the lock file (string-append STRING ".lock"). If the 4 | file does not exist, do nothing. 5 | 6 | (sys:unlock "foo") ==> unspecific 7 | -------------------------------------------------------------------------------- /help/sys-unix/sys_user-name: -------------------------------------------------------------------------------- 1 | S9 EXT (sys:user-name integer|string) ==> string 2 | (sys:user-uid integer|string) ==> integer 3 | (sys:user-gid integer|string) ==> integer 4 | (sys:user-gecos integer|string) ==> string 5 | (sys:user-home integer|string) ==> string 6 | (sys:user-shell integer|string) ==> string 7 | 8 | Return a specific member of the user database entry for the 9 | given user. A user may be indicated by its user name (STRING) 10 | or UID (INTEGER). See SYS:GETPWNAM for details. Basically 11 | (sys:user-MEMBER user) is short for: 12 | 13 | (let ((u (if (string? user) 14 | (sys:getpwnam user) 15 | (sys:getpwuid user)))) 16 | (if u 17 | (cdr (assq 'MEMBER u)) 18 | (error "no such name or UID"))) 19 | 20 | (sys:user-gecos "man") ==> "Mr. Man Pages" 21 | -------------------------------------------------------------------------------- /help/sys-unix/sys_usleep: -------------------------------------------------------------------------------- 1 | S9 EXT (sys:sleep integer) ==> unspecific 2 | (sys:usleep integer) ==> unspecific 3 | 4 | Suspend process execution for the given number of seconds (SYS:SLEEP) 5 | or microseconds (SYS:USLEEP). 6 | 7 | (sys:sleep 3) ==> unspecific 8 | -------------------------------------------------------------------------------- /help/sys-unix/sys_utimes: -------------------------------------------------------------------------------- 1 | S9 EXT (sys:utimes string) ==> unspecific 2 | 3 | Set the access and modification time of the file STRING to 4 | the current time. 5 | 6 | (sys:utimes "file") ==> unspecific 7 | -------------------------------------------------------------------------------- /help/sys-unix/sys_wait: -------------------------------------------------------------------------------- 1 | S9 EXT (sys:wait) ==> list 2 | (sys:waitpid integer) ==> integer | #f 3 | 4 | Wait for a child process to terminate and return the exit information 5 | and of the terminated process. SYS:WAIT returns a list containing the 6 | exit code and PID of any exited child process: 7 | 8 | (exit-code PID) 9 | 10 | When no exit information could be obtained it returns #F. The SYS:WAITPID 11 | procedure checks whether a process with a specific PID of INTEGER has 12 | exited and if so, it returns its exit code. When the process exists but 13 | has not yet exited, it returns #F. When there are no child processes to 14 | wait for, it signals an error. SYS:WAITPID, unlike SYS:WAIT, does not 15 | block the calling process. 16 | -------------------------------------------------------------------------------- /help/sys-unix/time: -------------------------------------------------------------------------------- 1 | S9 LIB (time* expression) ==> object 2 | (time form) ==> object 3 | 4 | The TIME* procedures evaluates EXPRESSION, measuring the number 5 | of allocations and garbage collections with the STATS procedure. 6 | It also measures the time spent reducing FORM. When finished, it 7 | prints some interesting data and returns the normal form of FORM. 8 | The FORM must be quoted or it will be reduced *before* running 9 | TIME*. 10 | 11 | The TIME special form is like TIME*, but does not require its 12 | argument to be quoted. 13 | 14 | (time (begin (expt 2 10000) #t)) ==> #t 15 | ; 0.4086 seconds 16 | ; 8,334,993 total nodes allocated 17 | ; 8,334,993 conses allocated 18 | ; 3,456 vector cells allocated 19 | ; 22 garbage collections 20 | -------------------------------------------------------------------------------- /help/sys-unix/unix-tools: -------------------------------------------------------------------------------- 1 | S9 LIB Convenience file to load the Unix programming procedures. 2 | 3 | (load-from-library "append-to-output-file.scm") 4 | (load-from-library "basename.scm") 5 | (load-from-library "dirname.scm") 6 | (load-from-library "flush-output-port.scm") 7 | (load-from-library "format-time.scm") 8 | (load-from-library "leap-yearp.scm") 9 | (load-from-library "mode-to-string.scm") 10 | (load-from-library "parse-optionsb.scm") 11 | (load-from-library "proper-timep.scm") 12 | (load-from-library "search-path.scm") 13 | (load-from-library "spawn-command.scm") 14 | (load-from-library "spawn-shell-command.scm") 15 | (load-from-library "standard-error.scm") 16 | (load-from-library "time-to-unix-time.scm") 17 | 18 | -------------------------------------------------------------------------------- /help/system: -------------------------------------------------------------------------------- 1 | S9fES (system string) ==> integer 2 | 3 | Run the command STRING and return its exit status. 4 | 5 | This procedure is deprecated; use SYSTEM-COMMAND instead. 6 | 7 | (system "ls") ==> 0 8 | (system "ls nonexistent") ==> 127 9 | -------------------------------------------------------------------------------- /help/system-command: -------------------------------------------------------------------------------- 1 | S9fES (system-command string) ==> integer 2 | 3 | Pass the given STRING to the operating system for execution and 4 | return the exit code returned by the system. On Unix this typically 5 | means passing the command to /bin/sh and on Plan 9 commands will 6 | be passed to /bin/rc. 7 | 8 | An exit code of zero indicates success and a non-zero exit code 9 | signals failure. 10 | 11 | (system-command "ls") ==> 0 12 | (system-command "ls nonexistent") ==> 127 13 | -------------------------------------------------------------------------------- /help/take: -------------------------------------------------------------------------------- 1 | S9 LIB (take list integer) ==> list 2 | 3 | Copy the first INTEGER conses of a proper list, creating a fresh 4 | that has the same elements as the original list in the first 5 | INTEGER positions. 6 | 7 | INTEGER may not be larger than the length of LIST. 8 | 9 | (take '(foo bar baz) 0) ==> () 10 | (take '(foo bar baz) 1) ==> (foo) 11 | (take '(foo bar baz) 3) ==> (foo bar baz) 12 | -------------------------------------------------------------------------------- /help/time-to-unix-time: -------------------------------------------------------------------------------- 1 | S9 LIB (time->unix-time time-list) ==> integer | #f 2 | 3 | TIME->UNIX-TIME converts TIME-LIST (see UNIX-TIME->TIME) to the 4 | number of seconds since the Unix epoch (1970-01-01). It returns 5 | #F if TIME-LIST is not a proper time list. 6 | 7 | (time->unix-time '(6 2010 4 25 7 1 19)) ==> 1272178879 8 | -------------------------------------------------------------------------------- /help/transpose: -------------------------------------------------------------------------------- 1 | S9 LIB (transpose list) ==> list 2 | 3 | Transpose a matrix. A matrix is represented by a nested list, 4 | where each inner list is a column of the matrix. 5 | 6 | (transpose '((1 2 3) (4 5 6))) ==> ((1 4) (2 5) (3 6)) 7 | -------------------------------------------------------------------------------- /help/tree-copy: -------------------------------------------------------------------------------- 1 | S9 LIB (tree-copy pair) ==> pair 2 | (tree-copy pair 'with-atoms) ==> pair 3 | 4 | Create an exact copy of an arbitrary non-cyclic cons structure. 5 | When a second argument is passed to TREE-COPY and that argument 6 | is not #F, then TREE-COPY will copy modifiable leaves of the tree, 7 | too. 8 | 9 | (tree-copy '(((a . b) (c . d)) (e . f))) 10 | ==> (((a . b) (c . d)) (e . f)) 11 | 12 | (let* ((tree (list (string #\A))) 13 | (tree2 (tree-copy tree)) 14 | (tree3 (tree-copy tree 'with-atoms))) 15 | (string-set! (car tree) 0 #\X) 16 | (list tree2 tree3)) ==> (("X") ("A")) 17 | -------------------------------------------------------------------------------- /help/tree-equalp: -------------------------------------------------------------------------------- 1 | S9 LIB (tree-equal? procedure pair1 pair2) ==> boolean 2 | 3 | Compare the leaves of two trees PAIR1 and PAIR2 using the predicate 4 | PROCEDURE. TREE-EQUAL? returns #T if the trees have the same structure 5 | and (procedure x1 x2) holds for their pairwise leaves. 6 | 7 | (tree-equal? (lambda (x y) #t) 8 | '(((a . b) (c . d)) (e . f)) 9 | '(((1 . 2) (3 . 4)) (5 . 6))) ==> #t 10 | 11 | (tree-equal? eqv? 12 | '((1 . 2) (3 . 4)) 13 | '((1 . 2) (3 4))) ==> #f 14 | -------------------------------------------------------------------------------- /help/tree-map: -------------------------------------------------------------------------------- 1 | S9 LIB (tree-map procedure1 procedure2 pair) ==> pair 2 | 3 | Apply PROCEDURE2 to each node of the tree rooted at PAIR 4 | to which the predicate PROCEDURE1 applies. Return a fresh 5 | tree. 6 | 7 | (tree-map number? list '((a . 1) (b . 2))) 8 | ==> ((a . (1)) (b . (2))) 9 | (tree-map (lambda (x) (and (pair? x) 10 | (string? (car x)) 11 | (string? (cdr x)))) 12 | (lambda (x) (string-append (car x) (cdr x))) 13 | '(("foo" . "bar") ("bar" . "baz"))) 14 | ==> ("foobar" "barbaz") 15 | -------------------------------------------------------------------------------- /help/troffify-char: -------------------------------------------------------------------------------- 1 | S9 LIB (troffify-char char) ==> string 2 | (troffify-string string) ==> string 3 | 4 | TROFFIFY-CHAR converts a char to a string that is save for 5 | inclusion in a TROFF document. TROFFIFY-STRING does the 6 | same for a string. 7 | 8 | Note: the conversion "$" -> "$dollar$" is a local idiosyncrasy. 9 | 10 | (troffify-char #\$) ==> "$dollar$" 11 | (troffify-string "\"a\\b\"") ==> "\"a\\\\b\"" 12 | -------------------------------------------------------------------------------- /help/type-case: -------------------------------------------------------------------------------- 1 | S9 LIB (type-case object ...) ==> object 2 | (type-of object) ==> symbol 3 | 4 | (load-from-library "type-case.scm") 5 | 6 | TYPE-OF returns a symbol describing the type of the given OBJECT. 7 | The following symbols may be returned by the procedure: 8 | 9 | boolean char eof-object input-port integer output-port 10 | pair procedure real string symbol syntax unknown-object 11 | vector 12 | 13 | (Type-case obj ...) is shorthand for (case (type-of obj) ...) 14 | 15 | (type-of type-of) ==> procedure 16 | 17 | (let ((x '#(1 2 3)) 18 | (i 0)) 19 | (type-case x 20 | ((string) (string-ref x i)) 21 | ((vector) (vector-ref x i)) 22 | (else x))) ==> 1 23 | -------------------------------------------------------------------------------- /help/union: -------------------------------------------------------------------------------- 1 | S9 LIB (union list ...) ==> list 2 | 3 | Compute the union of a series of sets. 4 | 5 | (union '(v w x) '(w x y) '(x y z)) ==> (v w x y z) 6 | -------------------------------------------------------------------------------- /help/unix-time-to-time: -------------------------------------------------------------------------------- 1 | S9 LIB (unix-time->time integer) ==> time-list 2 | 3 | UNIX-TIME->TIME converts the number of seconds since the Unix 4 | epoch (1970-01-01) specified in INTEGER to a time list, which 5 | has the following members: 6 | 7 | (weekday ; 0..6, where 0 = Monday 8 | year ; 1970..2038 9 | month ; 1..12 10 | day ; 1..31, depends on month 11 | hour ; 0..23 12 | minute ; 0..59 13 | second) ; 0..59 14 | 15 | (unix-time->time 1272178879) ==> (6 2010 4 25 7 1 19) 16 | -------------------------------------------------------------------------------- /help/unsort: -------------------------------------------------------------------------------- 1 | S9 LIB (unsort list seed) ==> list 2 | 3 | Unsort a list of integers. SEED must be a number in the range 4 | 0..(- (length LIST) 1). The original list is not changed. 5 | 6 | (unsort '(1 2 3 4 5) 1) ==> (1 3 5 4 2) 7 | -------------------------------------------------------------------------------- /help/url-decode: -------------------------------------------------------------------------------- 1 | S9 LIB (url-decode string) ==> string 2 | 3 | Decode an URL-encoded string. In an URL-encoded string, each subsequence 4 | of the form %NN represents a character with the ASCII code NN, where NN 5 | is a two-digit hexa-decimal number. URL-DECODE creates a fresh string 6 | where each %NN sequence has been replaced by the corresponding character. 7 | When STRING contains invalid %NN sequences, URL-DECODE returns #F. 8 | 9 | (url-decode "%46%4F%4FBAR") ==> "FOOBAR" 10 | -------------------------------------------------------------------------------- /help/variance: -------------------------------------------------------------------------------- 1 | S9 LIB (variance list) ==> real 2 | 3 | (load-from-library "variance.scm") 4 | 5 | Return the variance of the given list of values. 6 | 7 | (variance '(1 1 2 1 1)) ==> 0.16 8 | -------------------------------------------------------------------------------- /help/vector: -------------------------------------------------------------------------------- 1 | R4RS 6.8 (vector object ...) ==> vector 2 | 3 | Returns a newly allocated vector whose elements contain the given 4 | arguments. Analogous to LIST. 5 | 6 | (vector 'a 'b 'c) ==> #(a b c) 7 | -------------------------------------------------------------------------------- /help/vector-append: -------------------------------------------------------------------------------- 1 | S9 LIB (vector-append vector ...) ==> vector 2 | 3 | Returns a fresh vector consisting of the elements of the first vector 4 | followed by the elements of the other vectors in the given order. 5 | 6 | (vector-append '#(x) '#(y)) ==> #(x y) 7 | (vector-append '#(a) '#(b c d)) ==> #(a b c d) 8 | (vector-append '#(a (b)) '#((c))) ==> #(a (b) (c)) 9 | -------------------------------------------------------------------------------- /help/vector-fillb: -------------------------------------------------------------------------------- 1 | R4RS 6.8 (vector-fill! vector object) ==> unspecific 2 | 3 | Stores OBJECT in every element of VECTOR. The value returned by 4 | VECTOR-FILL! is unspecified. 5 | -------------------------------------------------------------------------------- /help/vector-length: -------------------------------------------------------------------------------- 1 | R4RS 6.8 (vector-length vector) ==> integer 2 | 3 | Returns the number of elements in VECTOR. 4 | -------------------------------------------------------------------------------- /help/vector-map: -------------------------------------------------------------------------------- 1 | S9 LIB (vector-map procedure vector ...) ==> vector 2 | (vector-map! procedure vector ...) ==> unspecific 3 | 4 | (load-from-library "vector-map.scm") 5 | 6 | Map a procedure over a set of vectors, giving a new vector 7 | 8 | (vector (f (vector-ref v0 i) ... ) ...) 9 | 10 | where F is the given PROCEDURE, V0 is the first and VN is the last 11 | VECTOR specified. The arity of PROCEDURE must match the number of 12 | vectors passed to these procedures. VECTOR-MAP is to vectors what 13 | MAP is to lists. 14 | 15 | VECTOR-MAP! does not create a fresh vector, but changes the members 16 | of the *first* vector in situ. 17 | 18 | (vector-map + '#(1 2 3) '#(4 5 6)) ==> #(5 7 9) 19 | (let ((v (vector 1 2 3))) 20 | (vector-map! - v) 21 | v) ==> #(-1 -2 -3) 22 | -------------------------------------------------------------------------------- /help/vector-ref: -------------------------------------------------------------------------------- 1 | R4RS 6.8 (vector-ref vector integer) ==> object 2 | 3 | INTEGER must be a valid index of VECTOR. VECTOR-REF returns the 4 | contents of the element at the INTEGER'th position of VECTOR. 5 | 6 | (vector-ref '#(1 1 2 3 5 8 13 21) 5) ==> 8 7 | -------------------------------------------------------------------------------- /help/vector-setb: -------------------------------------------------------------------------------- 1 | R4RS 6.8 (vector-set! vector integer object) ==> unspecific 2 | 3 | INTEGER must be a valid index of VECTOR. VECTOR-SET! stores OBJECT 4 | in the element at the INTEGER'th position of VECTOR. The value 5 | returned by VECTOR-SET! is unspecified. 6 | 7 | (let ((vec (vector 0 '(2 2 2 2) "Anna"))) 8 | (vector-set! vec 1 '("Sue" "Sue")) 9 | vec) ==> #(0 ("Sue" "Sue") "Anna") 10 | (vector-set! '#(0 1 2) 1 "doe") ==> error ; constant vector 11 | -------------------------------------------------------------------------------- /help/vector-to-list: -------------------------------------------------------------------------------- 1 | R4RS 6.8 (vector->list vector) ==> list 2 | (list->vector list) ==> vector 3 | 4 | VECTOR->LIST returns a newly allocated list of the objects 5 | contained in the elements of VECTOR. LIST->VECTOR returns a 6 | newly created vector initialized to the elements of the list 7 | LIST. 8 | 9 | (vector->list '#(dah dah didah)) ==> (dah dah didah) 10 | (list->vector '(dididit dah)) ==> #(dididit dah) 11 | -------------------------------------------------------------------------------- /help/vectorp: -------------------------------------------------------------------------------- 1 | R4RS 6.8 (vector? object) ==> boolean 2 | 3 | Returns #T if OBJECT is a vector, otherwise returns #F. 4 | -------------------------------------------------------------------------------- /help/void: -------------------------------------------------------------------------------- 1 | S9fES (void) ==> # 2 | 3 | Return an unspecific value. 4 | -------------------------------------------------------------------------------- /help/when: -------------------------------------------------------------------------------- 1 | S9 LIB (unless ) ==> object 2 | (when ) ==> object 3 | 4 | (load-from-library "when.scm") 5 | 6 | The WHEN syntax first evaluates . When it evaluates 7 | to a true value, it also evaluates , which is a sequence of 8 | expressions. The expressions will be evaluated in order and the value 9 | of the last expression will be returned. When 10 | evaluates to #f, WHEN does not evaluate its and returns an 11 | unspecific value. 12 | 13 | UNLESS is evaluates its body only if evaluates to #F. 14 | It evaluates its exactly if WHEN would not evaluate it and vice 15 | versa. 16 | 17 | (when (= 1 1) 'foo 'bar 'baz) ==> baz 18 | (unless (= 1 2) 'foo 'bar 'baz) ==> baz 19 | -------------------------------------------------------------------------------- /help/while: -------------------------------------------------------------------------------- 1 | S9 LIB (until ) ==> unspecific 2 | (while ) ==> unspecific 3 | 4 | (load-from-library "while.scm") 5 | 6 | The WHILE form first evaluates . When it evaluates 7 | to a true value, it also evaluates , which is a sequence of 8 | expressions. The expressions will be evaluated in order and then the 9 | WHILE form will be re-entered by evaluating once 10 | again. Then WHILE form terminates only if the test expression returns 11 | #F. The value of he form is unspecific. 12 | 13 | UNTIL is like WHILE, but evaluates its until 14 | evaluates to truth. 15 | 16 | (let ((x 0) 17 | (y 1)) 18 | (while (< x 10) 19 | (set! y (* 2 y)) 20 | (set! x (+ 1 x))) 21 | y) ==> 1024 22 | -------------------------------------------------------------------------------- /help/with-input-from-file: -------------------------------------------------------------------------------- 1 | R4RS 6.10 (with-input-from-file string procedure^0) ==> object 2 | (with-output-to-file string procedure^0) ==> object 3 | 4 | PROCEDURE^0 must be a procedure of no arguments, and STRING must 5 | be a string naming a file. For WITH-INPUT-FROM-FILE, the file must 6 | already exist; for WITH-OUTPUT-TO-FILE, the effect is unspecified 7 | if the file already exists. The file is opened for input or output, 8 | an input or output port connected to it is made the default value 9 | returned by CURRENT-INPUT-PORT or CURRENT-OUTPUT-PORT, and the thunk 10 | is called with no arguments. When the thunk returns, the port is 11 | closed and the previous default is restored. WITH-INPUT-FROM-FILE 12 | and WITH-OUTPUT-TO-FILE return the value yielded by PROCEDURE^0. 13 | 14 | S9fES silently overwrites the existing file when the file specified 15 | with WITH-OUTPUT-TO-FILE already exists. 16 | -------------------------------------------------------------------------------- /help/write: -------------------------------------------------------------------------------- 1 | R4RS 6.10.3 (write object) ==> unspecific 2 | (write object output-port) ==> unspecific 3 | 4 | Writes a written representation of OBJECT to the given port. Strings 5 | that appear in the written representation are enclosed in double quotes, 6 | and within those strings backslash and double quote characters are 7 | escaped by backslashes. WRITE returns an unspecified value. The 8 | OUTPUT-PORT argument may be omitted, in which case it defaults to 9 | the value returned by CURRENT-OUTPUT-PORT. 10 | -------------------------------------------------------------------------------- /help/write-char: -------------------------------------------------------------------------------- 1 | R4RS 6.10.3 (write-char char) ==> unspecific 2 | (write-char char output-port) ==> unspecific 3 | 4 | Writes the character CHAR (not an external representation of the 5 | character) to the given port and returns an unspecified value. The 6 | OUTPUT-PORT argument may be omitted, in which case it defaults to 7 | the value returned by CURRENT-OUTPUT-PORT. 8 | -------------------------------------------------------------------------------- /help/write-to-string: -------------------------------------------------------------------------------- 1 | S9 LIB (write-to-string object) ==> string 2 | (display-to-string object) ==> string 3 | 4 | (load-from-library "write-to-string.scm") 5 | 6 | Write the external representation of the given OBJECT to a fresh 7 | string. WRITE-TO-STRING is like WRITE but writes its output to a 8 | string instead of an output port. DISPLAY-TO-STRING is like 9 | DISPLAY but writes its output to a string. 10 | 11 | (write-to-string '(a 1 #\c #(v) #t "str" "\"s\"" (a . d))) 12 | ==> "(a 1 #\\c #(v) #t \"str\" \"\\\"s\\\"\" (a . d))" 13 | 14 | (display-to-string '(a 1 #\c #(v) #t "str" "\"s\"" (a . d))) 15 | ==> "(a 1 c #(v) #t str \"s\" (a . d))" 16 | -------------------------------------------------------------------------------- /help/zebra: -------------------------------------------------------------------------------- 1 | S9 LIB (zebra) ==> list 2 | 3 | Solve the zebra puzzle using AMK. 4 | 5 | (zebra) ==> (((norwegian kools _.0 fox yellow) 6 | (ukrainian chesterfields tea horse blue) 7 | (englishman oldgolds milk snails red) 8 | (spaniard luckystrikes orangejuice dog ivory) 9 | (japanese parliaments coffee zebra green))) 10 | -------------------------------------------------------------------------------- /help/zerop: -------------------------------------------------------------------------------- 1 | R4RS 6.5.5 (zero? number) ==> boolean 2 | (positive? number) ==> boolean 3 | (negative? number) ==> boolean 4 | (odd? integer) ==> boolean 5 | (even? integer) ==> boolean 6 | 7 | These numerical predicates test a number for a particular property, 8 | returning #T or #F. 9 | 10 | See also: note 2 in description of =. 11 | -------------------------------------------------------------------------------- /lib/_template: -------------------------------------------------------------------------------- 1 | ; Scheme 9 from Empty Space, Function Library 2 | ; By Nils M Holm, 2013 3 | ; Placed in the Public Domain 4 | ; 5 | ; (name argument ...) ==> type 6 | ; 7 | ; A template for new library procedures. 8 | ; 9 | ; Example: (name value ...) ==> object 10 | ; ... 11 | 12 | ; code 13 | -------------------------------------------------------------------------------- /lib/adjoin.scm: -------------------------------------------------------------------------------- 1 | ; Scheme 9 from Empty Space, Function Library 2 | ; By Nils M Holm, 2010 3 | ; Placed in the Public Domain 4 | ; 5 | ; (adjoin object list) ==> list 6 | ; 7 | ; Add an element to a set. 8 | ; 9 | ; Example: (adjoin 'x '(a b c)) ==> (x a b c) 10 | ; (adjoin 'c '(a b c)) ==> (a b c) 11 | 12 | (define (adjoin x a) 13 | (if (member x a) 14 | a 15 | (cons x a))) 16 | -------------------------------------------------------------------------------- /lib/assp.scm: -------------------------------------------------------------------------------- 1 | ; Scheme 9 from Empty Space, Function Library 2 | ; By Nils M Holm, 2009 3 | ; Placed in the Public Domain 4 | ; 5 | ; (assp procedure^2 object alist) ==> object | #f 6 | ; 7 | ; Find the first member X of an alist for which 8 | ; 9 | ; (procedure^2 object (car X)) 10 | ; 11 | ; holds. When no such member exists, return #F. 12 | ; 13 | ; Example: (assp char=? #\b '((#\a . 1) (#\b . 2))) ==> (#\b . 2) 14 | 15 | (define (assp p x a) 16 | (cond ((null? a) 17 | #f) 18 | ((p x (caar a)) 19 | (car a)) 20 | (else 21 | (assp p x (cdr a))))) 22 | -------------------------------------------------------------------------------- /lib/cdf.scm: -------------------------------------------------------------------------------- 1 | ; Scheme 9 from Empty Space, Function Library 2 | ; By Nils M Holm, 2015 3 | ; Placed in the Public Domain 4 | ; 5 | ; (cdf real) ==> real 6 | ; 7 | ; (load-from-library "cdf.scm") 8 | ; 9 | ; Compute the quantile of the given standard deviation (cumulative 10 | ; distribution function). Results will get flaky beyond 5th standard 11 | ; deviation; see ERF for details. 12 | ; 13 | ; Example: (cdf 0) ==> 0.5 14 | 15 | (load-from-library "erf.scm") 16 | 17 | (define (cdf x) 18 | (+ 0.5 (* 0.5 (erf (/ x (sqrt 2)))))) 19 | -------------------------------------------------------------------------------- /lib/choose.scm: -------------------------------------------------------------------------------- 1 | ; Scheme 9 from Empty Space, Function Library 2 | ; By Nils M Holm, 2012 3 | ; Placed in the Public Domain 4 | ; 5 | ; (choose integer1 integer2) ==> integer 6 | ; 7 | ; Return the binomial coefficient ("n choose k") of INTEGER1 (n) 8 | ; and INTEGER2 (k), i.e. the number of unique k-tuples that can be 9 | ; choosen without repetition from a set of n elements. INTEGER2 (k) 10 | ; must be positive. 11 | ; 12 | ; Example: (choose 23 1) ==> 23 13 | ; (choose 23 2) ==> 253 14 | ; (choose 23 3) ==> 1771 15 | 16 | (define (choose x y) 17 | (define (product x y) 18 | (if (= x y) 19 | x 20 | (* x (product (+ x 1) y)))) 21 | (quotient (product (+ 1 (- x y)) x) 22 | (product 1 y))) 23 | -------------------------------------------------------------------------------- /lib/count.scm: -------------------------------------------------------------------------------- 1 | ; Scheme 9 from Empty Space, Function Library 2 | ; By Nils M Holm, 2009,2010 3 | ; Placed in the Public Domain 4 | ; 5 | ; (count pair) ==> integer 6 | ; 7 | ; Count atomic members of a pair. 8 | ; 9 | ; Example: (count '(a (b (c)) d . e)) ==> 5 10 | 11 | (define (count x) 12 | (cond ((null? x) 0) 13 | ((pair? x) 14 | (+ (count (car x)) 15 | (count (cdr x)))) 16 | (else 1))) 17 | -------------------------------------------------------------------------------- /lib/data-structures.scm: -------------------------------------------------------------------------------- 1 | ; Scheme 9 from Empty Space, Function Library 2 | ; By Nils M Holm, 2010 3 | ; Placed in the Public Domain 4 | ; 5 | ; Convenience file to load additional high-level data structures. 6 | 7 | (load-from-library "array.scm") 8 | (load-from-library "define-structure.scm") 9 | (load-from-library "hash-table.scm") 10 | (load-from-library "queue.scm") 11 | (load-from-library "rb-tree.scm") 12 | (load-from-library "records.scm") 13 | -------------------------------------------------------------------------------- /lib/depth.scm: -------------------------------------------------------------------------------- 1 | ; Scheme 9 from Empty Space, Function Library 2 | ; By Nils M Holm, 2009 3 | ; Placed in the Public Domain 4 | ; 5 | ; (depth list) ==> integer 6 | ; 7 | ; Compute the depth of a list. 8 | ; 9 | ; Example: (depth '(a (b (c d (e))))) ==> 4 10 | 11 | (define (depth a) 12 | (if (pair? a) 13 | (+ 1 (apply max (map depth a))) 14 | 0)) 15 | -------------------------------------------------------------------------------- /lib/displaystar.scm: -------------------------------------------------------------------------------- 1 | ; Scheme 9 from Empty Space, Function Library 2 | ; By Nils M Holm, 2009 3 | ; Placed in the Public Domain 4 | ; 5 | ; (display* object ...) ==> unspecific 6 | ; (display* output-port object ...) ==> unspecific 7 | ; 8 | ; (load-from-library "displaystar.scm") 9 | ; 10 | ; Display each OBJECT in the same way as DISPLAY. When the first 11 | ; argument of DISPLAY* is an output port, write all output to 12 | ; that port. 13 | ; 14 | ; (Example): (display* "foo" #\= 17 #\newline) ==> unspecific 15 | ; ; output: foo = 17 16 | 17 | (define (display* . x) 18 | (if (not (null? x)) 19 | (let* ((args (if (output-port? (car x)) 20 | (list (car x) (cdr x)) 21 | (list (current-output-port) x))) 22 | (port (car args)) 23 | (args (cadr args))) 24 | (for-each (lambda (x) 25 | (display x port)) 26 | args)))) 27 | -------------------------------------------------------------------------------- /lib/erf.scm: -------------------------------------------------------------------------------- 1 | ; Scheme 9 from Empty Space, Function Library 2 | ; By Nils M Holm, 2015 3 | ; Placed in the Public Domain 4 | ; 5 | ; (erf real) ==> real 6 | ; 7 | ; (load-from-library "erf.scm") 8 | ; 9 | ; Gauss error function. Used to compute the integral of the normal 10 | ; distribution function (NDF). 11 | ; 12 | ; Using an Abramowitz-Stegun approximation with a maximum error of 13 | ; 3 * 10^-7, i.e. results will start to get flaky beyond the 5th 14 | ; standard deviation. 15 | ; 16 | ; Example: (erf 0) ==> 0.0 17 | 18 | (define (erf x) 19 | (if (< x 0) 20 | (- (erf (- x))) 21 | (- 1 (/ (expt (+ 1 (* 0.0705230784 x) 22 | (* 0.0422820123 x x) 23 | (* 0.0092705272 x x x) 24 | (* 0.0001520143 x x x x) 25 | (* 0.0002765672 x x x x x) 26 | (* 0.0000430638 x x x x x x)) 27 | 16))))) 28 | 29 | -------------------------------------------------------------------------------- /lib/explode.scm: -------------------------------------------------------------------------------- 1 | ; Scheme 9 from Empty Space, Function Library 2 | ; By Nils M Holm, 2009 3 | ; Placed in the Public Domain 4 | ; 5 | ; (explode symbol) ==> list 6 | ; 7 | ; Explode a symbol into a list of single-character symbols. 8 | ; 9 | ; Example: (explode 'supernova) ==> (s u p e r n o v a) 10 | 11 | (define (explode x) 12 | (map (lambda (x) 13 | (string->symbol (string x))) 14 | (string->list (symbol->string x)))) 15 | -------------------------------------------------------------------------------- /lib/factorial.scm: -------------------------------------------------------------------------------- 1 | ; Scheme 9 from Empty Space, Function Library 2 | ; By Nils M Holm, 2009 3 | ; Placed in the Public Domain 4 | ; 5 | ; (factorial integer) ==> integer 6 | ; 7 | ; Compute the factorial of a number. 8 | ; 9 | ; Example: (factorial 30) ==> 265252859812191058636308480000000 10 | 11 | (define (factorial n) 12 | (letrec 13 | ((r* (lambda (n m) 14 | (if (< m 2) 15 | n 16 | (let ((k (quotient m 2))) 17 | (* (r* n k) 18 | (r* (+ n k) (- m k)))))))) 19 | (cond ((negative? n) 20 | (error "factorial: negative operand" n)) 21 | (else 22 | (r* 1 n))))) 23 | -------------------------------------------------------------------------------- /lib/filter.scm: -------------------------------------------------------------------------------- 1 | ; Scheme 9 from Empty Space, Function Library 2 | ; By Nils M Holm, 2009 3 | ; Placed in the Public Domain 4 | ; 5 | ; (filter procecure^1 list) ==> list 6 | ; 7 | ; Extract elements from a list. PROCEDURE describes the property 8 | ; of the elements to be extracted. It must be a procedure of one 9 | ; argument. 10 | ; 11 | ; Example: (filter number? '(a 1 b 2 c 3)) ==> (1 2 3) 12 | 13 | (define (filter p a) 14 | (letrec 15 | ((filter2 16 | (lambda (a r) 17 | (cond ((null? a) 18 | (reverse! r)) 19 | ((p (car a)) 20 | (filter2 (cdr a) (cons (car a) r))) 21 | (else 22 | (filter2 (cdr a) r)))))) 23 | (filter2 a '()))) 24 | -------------------------------------------------------------------------------- /lib/flatten.scm: -------------------------------------------------------------------------------- 1 | ; Scheme 9 from Empty Space, Function Library 2 | ; By Nils M Holm, 2009 3 | ; Placed in the Public Domain 4 | ; 5 | ; (flatten pair) ==> list 6 | ; 7 | ; Convert tree to flat list. 8 | ; 9 | ; Example: (flatten '(a (b ((c) d . e)))) ==> (a b c d e) 10 | 11 | (define (flatten x) 12 | (letrec 13 | ((f (lambda (x r) 14 | (cond ((null? x) 15 | r) 16 | ((pair? x) 17 | (f (car x) 18 | (f (cdr x) r))) 19 | (else 20 | (cons x r)))))) 21 | (f x '()))) 22 | -------------------------------------------------------------------------------- /lib/graph-tools.scm: -------------------------------------------------------------------------------- 1 | ; Scheme 9 from Empty Space, Function Library 2 | ; By Nils M Holm, 2010 3 | ; Placed in the Public Domain 4 | ; 5 | ; Convenience file to load additional tree/DAG-processing procedures. 6 | 7 | (load-from-library "t-sort.scm") 8 | (load-from-library "tree-copy.scm") 9 | (load-from-library "tree-equalp.scm") 10 | -------------------------------------------------------------------------------- /lib/group.scm: -------------------------------------------------------------------------------- 1 | ; Scheme 9 from Empty Space, Function Library 2 | ; By Nils M Holm, 2010,2012 3 | ; Placed in the Public Domain 4 | ; 5 | ; (group list integer) ==> list 6 | ; 7 | ; Group the elements of LIST in tuples of INTEGER elements 8 | ; each (except for the last tuple, which may contain fewer 9 | ; elements). Return a list of the resulting tuples. The 10 | ; elements appear in the output list in the same order as 11 | ; in the input list. 12 | ; 13 | ; INTEGER must be positive. 14 | ; 15 | ; Example: (group '(1 2 3 4 5) 2) ==> ((1 2) (3 4) (5)) 16 | ; (group '(1 2 3 4 5) 5) ==> ((1 2 3 4 5)) 17 | 18 | (load-from-library "take.scm") 19 | 20 | (define (group a n) 21 | (let group ((a a) 22 | (k (length a)) 23 | (r '())) 24 | (if (< n k) 25 | (group (list-tail a n) 26 | (- k n) 27 | (cons (take a n) r)) 28 | (reverse! (cons a r))))) 29 | -------------------------------------------------------------------------------- /lib/htmlify-char.scm: -------------------------------------------------------------------------------- 1 | ; Scheme 9 from Empty Space, Function Library 2 | ; By Nils M Holm, 2010 3 | ; Placed in the Public Domain 4 | ; 5 | ; (htmlify-char char) ==> string 6 | ; (htmlify-string string) ==> string 7 | ; 8 | ; HTMLIFY-CHAR converts a char to a string that is save for 9 | ; inclusion in an HTML document. HTMLIFY-STRING does the 10 | ; same for a string. 11 | ; 12 | ; Example: (htmlify-char #\<) ==> "<" 13 | ; (htmlify-string "<&>") ==> "<&>" 14 | 15 | (define (htmlify-char c) 16 | (cond ((char=? c #\<) "<") 17 | ((char=? c #\>) ">") 18 | ((char=? c #\&) "&") 19 | (else (string c)))) 20 | 21 | (define (htmlify-string s) 22 | (apply string-append 23 | (map htmlify-char (string->list s)))) 24 | -------------------------------------------------------------------------------- /lib/hyper.scm: -------------------------------------------------------------------------------- 1 | ; Scheme 9 from Empty Space, Function Library 2 | ; By Nils M Holm, 2009 3 | ; Placed in the Public Domain 4 | ; 5 | ; (hyper integer1 integer2 integer3) ==> integer 6 | ; 7 | ; Compute A hyper(N) B, where N=INTEGER1, A=INTEGER2, and B=INTEGER3. 8 | ; 9 | ; Example: (hyper 4 3 3) ==> 7625597484987 10 | 11 | (define (hyper n a b) 12 | (cond ((= n 0) (+ 1 b)) 13 | ((= n 1) (+ a b)) 14 | ((= b 1) a) 15 | ((= n 2) (* a b)) 16 | ((= n 3) (expt a b)) 17 | ((= n 4) (expt a (hyper n a (- b 1)))) 18 | ((> n 4) (hyper (- n 1) a (hyper n a (- b 1)))))) 19 | -------------------------------------------------------------------------------- /lib/id.scm: -------------------------------------------------------------------------------- 1 | ; Scheme 9 from Empty Space, Function Library 2 | ; By Nils M Holm, 2010 3 | ; Placed in the Public Domain 4 | ; 5 | ; (false object ...) ==> #f 6 | ; (id object) ==> object 7 | ; (true object ...) ==> #t 8 | ; 9 | ; (load-from-library "id.scm") 10 | ; 11 | ; ID returns the object passed to it. 12 | ; 13 | ; FALSE returns always #F and TRUE returns always #T, no matter which 14 | ; values are passed to them. 15 | ; 16 | ; Example: (true) ==> #t 17 | ; (false 1 2 3) ==> #f 18 | ; (id 'whatever) ==> whatever 19 | 20 | (define (id x) x) 21 | (define (true . x) #t) 22 | (define (false . x) #f) 23 | -------------------------------------------------------------------------------- /lib/implode.scm: -------------------------------------------------------------------------------- 1 | ; Scheme 9 from Empty Space, Function Library 2 | ; By Nils M Holm, 2009 3 | ; Placed in the Public Domain 4 | ; 5 | ; (implode list) ==> symbol 6 | ; 7 | ; Implode a list of single-character symbols into a symbol. 8 | ; 9 | ; Example: (implode '(b l a c k h o l e)) ==> blackhole 10 | 11 | (define (implode x) 12 | (letrec 13 | ((sym->char 14 | (lambda (x) 15 | (let ((str (symbol->string x))) 16 | (if (= (string-length str) 1) 17 | (string-ref str 0) 18 | (error "bad symbol in implode" x)))))) 19 | (string->symbol 20 | (list->string (map sym->char x))))) 21 | -------------------------------------------------------------------------------- /lib/integer-sqrt.scm: -------------------------------------------------------------------------------- 1 | ; Scheme 9 from Empty Space, Function Library 2 | ; By Nils M Holm, 2009 3 | ; Placed in the Public Domain 4 | ; 5 | ; (integer-sqrt integer) ==> integer 6 | ; 7 | ; Compute the largest integer value that is not greater than the 8 | ; square root of INTEGER. 9 | ; 10 | ; Example: (integer-sqrt 10) ==> 3 11 | 12 | (define (integer-sqrt square) 13 | (letrec 14 | ((sqrt2 (lambda (x last) 15 | (cond ((= last x) 16 | x) 17 | ((= last (+ 1 x)) 18 | (if (> (* x x) square) (- x 1) x)) 19 | (else 20 | (sqrt2 (quotient 21 | (+ x (quotient square x)) 22 | 2) 23 | x)))))) 24 | (if (negative? square) 25 | (error "integer-sqrt: negative argument" square) 26 | (sqrt2 square 0)))) 27 | -------------------------------------------------------------------------------- /lib/intersection.scm: -------------------------------------------------------------------------------- 1 | ; Scheme 9 from Empty Space, Function Library 2 | ; By Nils M Holm, 2009 3 | ; Placed in the Public Domain 4 | ; 5 | ; (intersection list ...) ==> list 6 | ; 7 | ; Compute the intersection of a number of sets. 8 | ; 9 | ; Example: (intersection '(v w x) '(w x y) '(x y z)) ==> (x) 10 | 11 | (define (intersection . a*) 12 | (letrec 13 | ((intersection3 (lambda (a b r) 14 | (cond ((null? a) 15 | (reverse! r)) 16 | ((member (car a) b) 17 | (intersection3 (cdr a) b (cons (car a) r))) 18 | (else 19 | (intersection3 (cdr a) b r)))))) 20 | (if (null? a*) 21 | a* 22 | (fold-left (lambda (a b) 23 | (intersection3 a b '())) 24 | (car a*) 25 | (cdr a*))))) 26 | -------------------------------------------------------------------------------- /lib/io-tools.scm: -------------------------------------------------------------------------------- 1 | ; Scheme 9 from Empty Space, Function Library 2 | ; By Nils M Holm, 2010 3 | ; Placed in the Public Domain 4 | ; 5 | ; Convenience file to load additional I/O procedures. 6 | 7 | (load-from-library "displaystar.scm") 8 | (load-from-library "read-file.scm") 9 | (load-from-library "read-from-string.scm") 10 | (load-from-library "read-line.scm") 11 | (load-from-library "format.scm") 12 | (load-from-library "write-to-string.scm") 13 | -------------------------------------------------------------------------------- /lib/leap-yearp.scm: -------------------------------------------------------------------------------- 1 | ; Scheme 9 from Empty Space, Function Library 2 | ; By Nils M Holm, 2009 3 | ; Placed in the Public Domain 4 | ; 5 | ; (leap-year? integer) ==> boolean 6 | ; 7 | ; Return #T if INTEGER represents a leap year and otherwise return #F. 8 | ; 9 | ; Example: (leap-year? 2000) ==> #t 10 | ; (leap-year? 2003) ==> #f 11 | 12 | (define (leap-year? x) 13 | (or (zero? (remainder x 400)) 14 | (and (zero? (remainder x 4)) 15 | (not (zero? (remainder x 100)))))) 16 | -------------------------------------------------------------------------------- /lib/letcc.scm: -------------------------------------------------------------------------------- 1 | ; Scheme 9 from Empty Space, Function Library 2 | ; By Nils M Holm, 2010 3 | ; Placed in the Public Domain 4 | ; 5 | ; (let/cc . ) ==> object 6 | ; 7 | ; (load-from-library "letcc.scm") 8 | ; 9 | ; Bind the current continuation to and evaluate with 10 | ; that binding in effect. 11 | ; 12 | ; Example: (let/cc exit 13 | ; (letrec 14 | ; ((f (lambda (x) 15 | ; (cond ((null? x) 0) 16 | ; ((pair? x) (+ 1 (f (cdr x)))) 17 | ; (else (exit 'foo)))))) 18 | ; (f '(1 2 3 . 4)))) ==> foo 19 | 20 | (define-syntax (let/cc name . body) 21 | `(call/cc 22 | (lambda (,name) 23 | ,@body))) 24 | -------------------------------------------------------------------------------- /lib/list-copy.scm: -------------------------------------------------------------------------------- 1 | ; Scheme 9 from Empty Space, Function Library 2 | ; By Nils M Holm, 2012 3 | ; Placed in the Public Domain 4 | ; 5 | ; (list-copy list) ==> list 6 | ; 7 | ; Copy the spine of a proper list, creating a fresh list with the 8 | ; same elements as the original list. 9 | ; 10 | ; Example: (list-copy '(foo bar baz)) ==> (foo bar baz) 11 | 12 | (define (list-copy a) 13 | (let copy ((a a) 14 | (r '())) 15 | (if (pair? a) 16 | (copy (cdr a) 17 | (cons (car a) r)) 18 | (reverse! r)))) 19 | -------------------------------------------------------------------------------- /lib/listq.scm: -------------------------------------------------------------------------------- 1 | ; Scheme 9 from Empty Space, Function Library 2 | ; By Nils M Holm, 2010 3 | ; Placed in the Public Domain 4 | ; 5 | ; (listq object ...) ==> list 6 | ; 7 | ; LISTQ is like LIST, but quotes each OBJECT passed to it. 8 | ; Rationale: (list a b c) evaluates a, b, and c 9 | ; '(a b c) makes the list immutable 10 | ; `(a b c) may be inefficient 11 | ; (list 'a 'b 'c) is awkward 12 | ; 13 | ; Example: (listq a (b c) d) ==> (a (b c) d) 14 | 15 | (load-from-library "syntax-rules.scm") 16 | 17 | (define-syntax listq 18 | (syntax-rules () 19 | ((_ x ...) 20 | (list 'x ...)))) 21 | -------------------------------------------------------------------------------- /lib/math-tools.scm: -------------------------------------------------------------------------------- 1 | ; Scheme 9 from Empty Space, Function Library 2 | ; By Nils M Holm, 2010 3 | ; Placed in the Public Domain 4 | ; 5 | ; Convenience file to load additional math procedures. 6 | 7 | (load-from-library "bitops.scm") 8 | (load-from-library "bitwise-ops.scm") 9 | (load-from-library "choose.scm") 10 | (load-from-library "factor.scm") 11 | (load-from-library "factorial.scm") 12 | (load-from-library "hyper.scm") 13 | (load-from-library "integer-sqrt.scm") 14 | (load-from-library "make-partitions.scm") 15 | (load-from-library "random.scm") 16 | (load-from-library "sieve.scm") 17 | (load-from-library "sum.scm") 18 | -------------------------------------------------------------------------------- /lib/mean.scm: -------------------------------------------------------------------------------- 1 | ; Scheme 9 from Empty Space, Function Library 2 | ; By Nils M Holm, 2015 3 | ; Placed in the Public Domain 4 | ; 5 | ; (mean list) ==> real 6 | ; 7 | ; (load-from-library "mean.scm") 8 | ; 9 | ; Mean (average) function, returns the arithmetic mean value of a 10 | ; list of reals. 11 | ; 12 | ; Example: (mean '(1 2 3 4 5 6)) ==> 3.5 13 | 14 | (define (mean set) 15 | (/ (apply + set) (length set))) 16 | -------------------------------------------------------------------------------- /lib/median.scm: -------------------------------------------------------------------------------- 1 | ; Scheme 9 from Empty Space, Function Library 2 | ; By Nils M Holm, 2015 3 | ; Placed in the Public Domain 4 | ; 5 | ; (median list) ==> real 6 | ; 7 | ; (load-from-library "median.scm") 8 | ; 9 | ; Median (middle value) function, returns the value in the middle of 10 | ; a sorted list of values. The input list does not have to be sorted. 11 | ; 12 | ; Example: (mean '(1 2 3 4 5 6)) ==> 3.5 13 | 14 | (load-from-library "mergesort") 15 | 16 | (define (median set) 17 | (let* ((vs (mergesort <= set)) 18 | (k (length set)) 19 | (i (quotient k 2))) 20 | (if (even? k) 21 | (/ (+ (list-ref vs i) (list-ref vs (- i 1))) 2) 22 | (list-ref vs i)))) 23 | -------------------------------------------------------------------------------- /lib/memp.scm: -------------------------------------------------------------------------------- 1 | ; Scheme 9 from Empty Space, Function Library 2 | ; By Nils M Holm, 2009 3 | ; Placed in the Public Domain 4 | ; 5 | ; (memp procedure^2 object list) ==> list | #f 6 | ; 7 | ; Find the first tail X of LIST for which 8 | ; 9 | ; (procedure^2 object (car X)) 10 | ; 11 | ; holds. When no such tail exists, return #F. 12 | ; 13 | ; Example: (memp char=? #\b '(#\a #\b #\c)) ==> (#\b #\c) 14 | 15 | (define (memp p x a) 16 | (cond ((null? a) 17 | #f) 18 | ((p x (car a)) 19 | a) 20 | (else 21 | (memp p x (cdr a))))) 22 | -------------------------------------------------------------------------------- /lib/mergesort.scm: -------------------------------------------------------------------------------- 1 | ; Scheme 9 from Empty Space, Function Library 2 | ; By Nils M Holm, 2009 3 | ; Placed in the Public Domain 4 | ; 5 | ; (mergesort procedure^2 list) ==> list 6 | ; 7 | ; Sort lists using the mergesort algorithm. PROCEDURE^2 is a 8 | ; binary predicate that describes the desired order. The original 9 | ; list is not changed. 10 | ; 11 | ; Example: (mergesort <= '(5 3 7 9 1)) ==> (1 3 5 7 9) 12 | 13 | (load-from-library "split.scm") 14 | (load-from-library "merge.scm") 15 | 16 | (define (mergesort p a) 17 | (letrec 18 | ((sort 19 | (lambda (a) 20 | (if (or (null? a) 21 | (null? (cdr a))) 22 | a 23 | (let ((p* (split a))) 24 | (merge p (sort (car p*)) 25 | (sort (cadr p*)))))))) 26 | (sort a))) 27 | -------------------------------------------------------------------------------- /lib/ndf.scm: -------------------------------------------------------------------------------- 1 | ; Scheme 9 from Empty Space, Function Library 2 | ; By Nils M Holm, 2015 3 | ; Placed in the Public Domain 4 | ; 5 | ; (ndf real) ==> real 6 | ; (ndf* real) ==> real 7 | ; 8 | ; (load-from-library "ndf.scm") 9 | ; 10 | ; Compute the probability density at the given standard deviation 11 | ; (normal distribution function). Assuming a standard normal 12 | ; distribution. 13 | ; 14 | ; (Example:) (ndf 0) ==> 0.4 15 | 16 | (define (ndf x) 17 | (* (/ (sqrt (* 2 pi))) 18 | (expt 2.71828182845904523536028747135266249775724709369995 19 | (/ (- (* x x)) 2)))) 20 | 21 | (define (ndf* x mu sigma) 22 | (* (/ (* sigma (sqrt (* 2 pi)))) 23 | (expt 2.71828182845904523536028747135266249775724709369995 24 | (- (/ (* (- x mu) (- x mu)) (* 2 (* sigma sigma))))))) 25 | -------------------------------------------------------------------------------- /lib/quicksort.scm: -------------------------------------------------------------------------------- 1 | ; Scheme 9 from Empty Space, Function Library 2 | ; By Nils M Holm, 2009 3 | ; Placed in the Public Domain 4 | ; 5 | ; (quicksort procecure^2 list) ==> list 6 | ; 7 | ; Sort lists using the Quicksort algorithm. PROCEDURE^2 is a 8 | ; binary procedure describing the desired order. The original 9 | ; list is not changed. 10 | ; 11 | ; Example: (quicksort <= '(5 3 7 9 1)) ==> (1 3 5 7 9) 12 | 13 | (load-from-library "partition.scm") 14 | 15 | (define (quicksort p a) 16 | (letrec 17 | ((sort 18 | (lambda (a) 19 | (if (or (null? a) 20 | (null? (cdr a))) 21 | a 22 | (let ((p* (partition (lambda (x) (p (car a) x)) 23 | (cdr a)))) 24 | (append (sort (cadr p*)) 25 | (list (car a)) 26 | (sort (car p*)))))))) 27 | (sort a))) 28 | -------------------------------------------------------------------------------- /lib/random-sort.scm: -------------------------------------------------------------------------------- 1 | ; Scheme 9 from Empty Space, Function Library 2 | ; By Nils M Holm, 2010 3 | ; Placed in the Public Domain 4 | ; 5 | ; (random-sort list) ==> list 6 | ; (random-sort list integer) ==> list 7 | ; 8 | ; Create a random permutation of LIST and return it. When INTEGER 9 | ; is specified, use it to initialize a random state (see RANDOM). 10 | ; When no seed or the same seed is specified, RANDOM-SORT will 11 | ; always deliver the same permutation. 12 | ; 13 | ; Example: (random-sort '(1 2 3 4 5)) ==> (2 5 1 4 3) 14 | 15 | (load-from-library "hof.scm") 16 | (load-from-library "random.scm") 17 | (load-from-library "sort.scm") 18 | 19 | (define (random-sort a . seed) 20 | (let ((r (apply random-state seed))) 21 | (sort (const (= 0 (r 2))) a))) 22 | -------------------------------------------------------------------------------- /lib/range.scm: -------------------------------------------------------------------------------- 1 | ; Scheme 9 from Empty Space, Function Library 2 | ; By Nils M Holm, 2015 3 | ; Placed in the Public Domain 4 | ; 5 | ; (range list) ==> list 6 | ; 7 | ; (load-from-library "range.scm") 8 | ; 9 | ; Return a list containing the minimal and maximal value of a set. 10 | ; (- (cadr (range set)) (car (range set))) is the statistical range 11 | ; of a set of samples. 12 | ; 13 | ; Example: (range '(1 2 3 4 5)) ==> (1 5) 14 | 15 | (load-from-library "mergesort") 16 | 17 | (define (range set) 18 | (let* ((vs (mergesort <= set)) 19 | (min (car vs)) 20 | (max (car (reverse! vs)))) 21 | (list min max))) 22 | -------------------------------------------------------------------------------- /lib/read-file.scm: -------------------------------------------------------------------------------- 1 | ; Scheme 9 from Empty Space, Function Library 2 | ; By Nils M Holm, 2009 3 | ; Placed in the Public Domain 4 | ; 5 | ; (read-file) ==> list 6 | ; (read-file input-port) ==> list 7 | ; 8 | ; Read a text file from an input port, return a list containing 9 | ; one string for each line read. When no INPUT-PORT is specified, 10 | ; read the current input port. 11 | ; 12 | ; (Example): (with-input-from-file "lib/read-file.scm" read-file) 13 | ; ==> [lots of lines] 14 | 15 | (load-from-library "read-line.scm") 16 | 17 | (define (read-file . port) 18 | (letrec 19 | ((collect-lines 20 | (lambda (ln lines) 21 | (cond ((eof-object? ln) 22 | (reverse! lines)) 23 | (else 24 | (collect-lines (apply read-line port) 25 | (cons ln lines))))))) 26 | (collect-lines (apply read-line port) '()))) 27 | -------------------------------------------------------------------------------- /lib/replace.scm: -------------------------------------------------------------------------------- 1 | ; Scheme 9 from Empty Space, Function Library 2 | ; By Nils M Holm, 2009 3 | ; Placed in the Public Domain 4 | ; 5 | ; (replace object-old object-new pair) ==> pair 6 | ; 7 | ; Replace elements of a pair. OBJECT-OLD is the object to be 8 | ; replaced and OBJECT-NEW is the new object. 9 | ; 10 | ; Example: (replace '(x) '(y) '(lambda (x) y)) ==> (lambda (y) y) 11 | 12 | (define (replace old new obj) 13 | (cond ((equal? obj old) 14 | new) 15 | ((pair? obj) 16 | (cons (replace old new (car obj)) 17 | (replace old new (cdr obj)))) 18 | (else 19 | obj))) 20 | -------------------------------------------------------------------------------- /lib/set-difference.scm: -------------------------------------------------------------------------------- 1 | ; Scheme 9 from Empty Space, Function Library 2 | ; By Nils M Holm, 2010 3 | ; Placed in the Public Domain 4 | ; 5 | ; (set-difference list ...) ==> list 6 | ; 7 | ; Compute the difference of a number of sets. 8 | ; 9 | ; Example: (set-difference '(a b c d e f) '(b d) '(a f)) ==> (c e) 10 | 11 | (define (set-difference . a*) 12 | (letrec 13 | ((set-difference-3 (lambda (a b r) 14 | (cond ((null? a) 15 | (reverse! r)) 16 | ((member (car a) b) 17 | (set-difference-3 (cdr a) b r)) 18 | (else 19 | (set-difference-3 (cdr a) b (cons (car a) r))))))) 20 | (if (null? a*) 21 | a* 22 | (fold-left (lambda (a b) 23 | (set-difference-3 a b '())) 24 | (car a*) 25 | (cdr a*))))) 26 | -------------------------------------------------------------------------------- /lib/set-tools.scm: -------------------------------------------------------------------------------- 1 | ; Scheme 9 from Empty Space, Function Library 2 | ; By Nils M Holm, 2010 3 | ; Placed in the Public Domain 4 | ; 5 | ; Convenience file to load additional set-processing procedures. 6 | 7 | (load-from-library "adjoin.scm") 8 | (load-from-library "bitwise-ops.scm") 9 | (load-from-library "combine.scm") 10 | (load-from-library "exists.scm") 11 | (load-from-library "for-all.scm") 12 | (load-from-library "intersection.scm") 13 | (load-from-library "list-to-set.scm") 14 | (load-from-library "permute.scm") 15 | (load-from-library "set-difference.scm") 16 | (load-from-library "subsetp.scm") 17 | (load-from-library "union.scm") 18 | -------------------------------------------------------------------------------- /lib/sieve.scm: -------------------------------------------------------------------------------- 1 | ; Scheme 9 from Empty Space, Function Library 2 | ; By Nils M Holm, 2010 3 | ; Placed in the Public Domain 4 | ; 5 | ; (sieve integer) ==> list 6 | ; 7 | ; Given an INTEGER N, generate a list of all prime numbers less 8 | ; than N. INTEGER must be positive. 9 | ; 10 | ; Example: (sieve 20) ==> (2 3 5 7 11 13 17 19) 11 | 12 | (define (sieve n) 13 | (letrec 14 | ((sieve2 15 | (lambda (n primes) 16 | (let loop ((p (reverse primes))) 17 | (cond ((or (null? p) 18 | (> (* (car p) (car p)) n)) 19 | (cons n primes)) 20 | ((zero? (remainder n (car p))) 21 | primes) 22 | (else 23 | (loop (cdr p)))))))) 24 | (let loop ((i 3) 25 | (primes (list 2))) 26 | (if (> i n) 27 | (reverse! primes) 28 | (loop (+ 2 i) (sieve2 i primes)))))) 29 | -------------------------------------------------------------------------------- /lib/sort.scm: -------------------------------------------------------------------------------- 1 | ; Scheme 9 from Empty Space, Function Library 2 | ; By Nils M Holm, 2010 3 | ; Placed in the Public Domain 4 | ; 5 | ; (sort procedure^2 list) ==> list 6 | ; 7 | ; Sort lists. PROCEDURE^2 is a binary predicate that describes the 8 | ; desired order. The original list is not changed. 9 | ; 10 | ; Example: (sort <= '(5 3 7 9 1)) ==> (1 3 5 7 9) 11 | 12 | (load-from-library "mergesort.scm") 13 | 14 | (define sort mergesort) 15 | -------------------------------------------------------------------------------- /lib/stat-tools.scm: -------------------------------------------------------------------------------- 1 | ; Scheme 9 from Empty Space, Function Library 2 | ; By Nils M Holm, 2015 3 | ; Placed in the Public Domain 4 | ; 5 | ; Convenience file to load statistics procedures. 6 | 7 | (load-from-library "cdf.scm") 8 | (load-from-library "erf.scm") 9 | (load-from-library "mean.scm") 10 | (load-from-library "median.scm") 11 | (load-from-library "mode.scm") 12 | (load-from-library "ndf.scm") 13 | (load-from-library "quartile.scm") 14 | (load-from-library "range.scm") 15 | (load-from-library "stddev.scm") 16 | (load-from-library "variance.scm") 17 | -------------------------------------------------------------------------------- /lib/stddev.scm: -------------------------------------------------------------------------------- 1 | ; Scheme 9 from Empty Space, Function Library 2 | ; By Nils M Holm, 2015 3 | ; Placed in the Public Domain 4 | ; 5 | ; (stddev list) ==> real 6 | ; 7 | ; (load-from-library "stddev.scm") 8 | ; 9 | ; Return the standard deviation of the given list of values. 10 | ; 11 | ; Example: (stddev '(1 1 2 1 1)) ==> 0.4 12 | 13 | (load-from-library "variance.scm") 14 | 15 | (define (stddev set) 16 | (sqrt (variance set))) 17 | -------------------------------------------------------------------------------- /lib/string-case.scm: -------------------------------------------------------------------------------- 1 | ; Scheme 9 from Empty Space, Function Library 2 | ; By Nils M Holm, 2009,2010 3 | ; Placed in the Public Domain 4 | ; 5 | ; (string-upcase string) ==> string 6 | ; (string-downcase string) ==> string 7 | ; 8 | ; (load-from-library "string-case.scm") 9 | ; 10 | ; Return a fresh string containing the characters of STRING, but 11 | ; with the case of alphabetic characters converted. STRING-UPCASE 12 | ; converts characters to upper case, STRING-DOWNCASE to lower case. 13 | ; 14 | ; Example: (string-upcase "Hello, World!") ==> "HELLO, WORLD!" 15 | ; (string-downcase "Hello, World!") ==> "hello, world!" 16 | 17 | (load-from-library "string-map.scm") 18 | 19 | (define (string-downcase s) 20 | (string-map char-downcase s)) 21 | 22 | (define (string-upcase s) 23 | (string-map char-upcase s)) 24 | -------------------------------------------------------------------------------- /lib/string-prefixeqp.scm: -------------------------------------------------------------------------------- 1 | ; Scheme 9 from Empty Space, Function Library 2 | ; By Nils M Holm, 2010 3 | ; Placed in the Public Domain 4 | ; 5 | ; (string-prefix=? string1 string2) ==> boolean 6 | ; (string-prefix-ci=? string1 string2) ==> boolean 7 | ; 8 | ; Return #T when STRING2 has a prefix of STRING1 and otherwise 9 | ; return #F. STRING-PREFIX-CI=? performs the same operation, but 10 | ; ignores the case of the strings. 11 | ; 12 | ; Example: (string-prefix=? "foo" "foobar") ==> #t 13 | ; (string-prefix=? "foo" "fubar") ==> #f 14 | 15 | (define (make-s-p=? op) 16 | (lambda (p s) 17 | (let ((k (string-length p))) 18 | (and (>= (string-length s) k) 19 | (op p (substring s 0 k)))))) 20 | 21 | (define string-prefix=? (make-s-p=? string=?)) 22 | (define string-prefix-ci=? (make-s-p=? string-ci=?)) 23 | -------------------------------------------------------------------------------- /lib/string-reverse.scm: -------------------------------------------------------------------------------- 1 | ; Scheme 9 from Empty Space, Function Library 2 | ; By Nils M Holm, 2010 3 | ; Placed in the Public Domain 4 | ; 5 | ; (string-reverse string) ==> string 6 | ; (string-reverse! string) ==> unspecific 7 | ; 8 | ; Create a fresh string and fill it with the characters of 9 | ; STRING, but in reverse order. STRING-REVERSE! reverses the 10 | ; characters of STRING in situ, overwriting the original 11 | ; string. 12 | ; 13 | ; Example: (string-reverse "rats live on no evil star") 14 | ; ==> "rats live on no evil star" 15 | 16 | (define (string-reverse! s) 17 | (let* ((k (string-length s)) 18 | (m (quotient k 2))) 19 | (do ((i 0 (+ 1 i)) 20 | (j (- k 1) (- j 1))) 21 | ((= i m)) 22 | (let ((c (string-ref s i))) 23 | (string-set! s i (string-ref s j)) 24 | (string-set! s j c))))) 25 | 26 | (define (string-reverse s) 27 | (let ((n (string-copy s))) 28 | (string-reverse! n) 29 | n)) 30 | -------------------------------------------------------------------------------- /lib/string-scan.scm: -------------------------------------------------------------------------------- 1 | ; Scheme 9 from Empty Space, Function Library 2 | ; By Nils M Holm, 2010 3 | ; Placed in the Public Domain 4 | ; 5 | ; (string-scan char string) ==> integer | #f 6 | ; (string-ci-scan char string) ==> integer | #f 7 | ; 8 | ; (load-from-library "string-scan.scm") 9 | ; 10 | ; Scan STRING for CHAR. When STRING contains CHAR, return its position, 11 | ; otherwise return #F. STRING-CI-SCAN does the same but ignores case. 12 | ; 13 | ; Example: (string-scan #\y "xyz") ==> 1 14 | 15 | (define (make-string-scan c=?) 16 | (lambda (c s) 17 | (let ((k (string-length s))) 18 | (let loop ((i 0)) 19 | (cond ((>= i k) 20 | #f) 21 | ((c=? c (string-ref s i)) 22 | i) 23 | (else 24 | (loop (+ 1 i)))))))) 25 | 26 | (define string-scan (make-string-scan char=?)) 27 | (define string-ci-scan (make-string-scan char-ci=?)) 28 | -------------------------------------------------------------------------------- /lib/string-tools.scm: -------------------------------------------------------------------------------- 1 | ; Scheme 9 from Empty Space, Function Library 2 | ; By Nils M Holm, 2010 3 | ; Placed in the Public Domain 4 | ; 5 | ; Convenience file to load additional string procedures. 6 | 7 | (load-from-library "format.scm") 8 | (load-from-library "read-from-string.scm") 9 | (load-from-library "string-case.scm") 10 | (load-from-library "string-digest.scm") 11 | (load-from-library "string-expand.scm") 12 | (load-from-library "string-find.scm") 13 | (load-from-library "string-find-last.scm") 14 | (load-from-library "string-last-position.scm") 15 | (load-from-library "string-locate.scm") 16 | (load-from-library "string-map.scm") 17 | (load-from-library "string-parse.scm") 18 | (load-from-library "string-position.scm") 19 | (load-from-library "string-scan.scm") 20 | (load-from-library "string-split.scm") 21 | (load-from-library "string-translate.scm") 22 | (load-from-library "string-unsplit.scm") 23 | (load-from-library "write-to-string.scm") 24 | -------------------------------------------------------------------------------- /lib/string-unsplit.scm: -------------------------------------------------------------------------------- 1 | ; Scheme 9 from Empty Space, Function Library 2 | ; By Nils M Holm, 2010 3 | ; Placed in the Public Domain 4 | ; 5 | ; (string-unsplit char list) ==> string 6 | ; 7 | ; Unsplit a list of strings, giving a new string. CHAR is placed between 8 | ; each two elements of LIST. 9 | ; 10 | ; Example: (string-unsplit #\: '("" "a" "b" "" "c")) ==> ":a:b::c" 11 | 12 | (define (string-unsplit c s*) 13 | (let loop ((s* s*) 14 | (r '()) 15 | (s0 #t)) 16 | (cond ((null? s*) 17 | (apply string-append (reverse! r))) 18 | (s0 19 | (loop (cdr s*) 20 | (cons (car s*) r) 21 | #f)) 22 | (else 23 | (loop (cdr s*) 24 | (cons (car s*) (cons (string c) r)) 25 | #f))))) 26 | -------------------------------------------------------------------------------- /lib/sublist.scm: -------------------------------------------------------------------------------- 1 | ; Scheme 9 from Empty Space, Function Library 2 | ; By Nils M Holm, 2010 3 | ; Placed in the Public Domain 4 | ; 5 | ; (sublist list integer1 integer2) ==> list 6 | ; 7 | ; Return a fresh list formed from the members of LIST beginning with 8 | ; index INTEGER1 (inclusive) and ending with index INTEGER2 (exclusive). 9 | ; 10 | ; Example: (sublist '(a b c d e) 2 4) ==> (c d) 11 | ; (sublist '(a b c d e) 2 2) ==> () 12 | 13 | (define (sublist x p0 pn) 14 | (let ((k (length x))) 15 | (cond ((<= 0 p0 pn k) 16 | (do ((i p0 (+ 1 i)) 17 | (in (list-tail x p0) (cdr in)) 18 | (out '() (cons (car in) out))) 19 | ((= i pn) 20 | (reverse! out)))) 21 | (else 22 | (error "sublist: bad range" (list p0 pn)))))) 23 | -------------------------------------------------------------------------------- /lib/substitute.scm: -------------------------------------------------------------------------------- 1 | ; Scheme 9 from Empty Space, Function Library 2 | ; By Nils M Holm, 2009 3 | ; Placed in the Public Domain 4 | ; 5 | ; (substitute pair alist) ==> pair 6 | ; 7 | ; Substitute objects in a given PAIR. The association list 8 | ; ALIST contains the objects to be substituted as keys and 9 | ; the corresponding substitutes as values. 10 | ; 11 | ; Example: (substitute '(* (+ 5 7) 9) '(((+ 5 7) . 12))) ==> (* 12 9) 12 | 13 | (define (substitute x a) 14 | (cond ((assoc x a) => cdr) 15 | ((pair? x) (cons (substitute (car x) a) 16 | (substitute (cdr x) a))) 17 | (else x))) 18 | -------------------------------------------------------------------------------- /lib/subvector.scm: -------------------------------------------------------------------------------- 1 | ; Scheme 9 from Empty Space, Function Library 2 | ; By Nils M Holm, 2010 3 | ; Placed in the Public Domain 4 | ; 5 | ; (subvector vector integer1 integer2) ==> vector 6 | ; 7 | ; SUBVECTOR returns a fresh vector formed from the members of VECTOR 8 | ; beginning with index INTEGER1 (inclusive) and ending with index 9 | ; INTEGER2 (exclusive). 10 | ; 11 | ; Example: (subvector '#(a b c d e) 2 4) ==> #(c d) 12 | ; (subvector '#(a b c d e) 2 2) ==> #() 13 | 14 | (define (subvector v p0 pn) 15 | (let ((k (vector-length v))) 16 | (cond ((<= 0 p0 pn k) 17 | (vector-copy v p0 pn)) 18 | (else 19 | (error "subvector: bad range" (list p0 pn)))))) 20 | -------------------------------------------------------------------------------- /lib/sum.scm: -------------------------------------------------------------------------------- 1 | ; Scheme 9 from Empty Space, Function Library 2 | ; By Nils M Holm, 2009 3 | ; Placed in the Public Domain 4 | ; 5 | ; (sum integer1 integer2) ==> integer 6 | ; 7 | ; Compute the sum of a range of integers. 8 | ; 9 | ; Example: (sum 2 5) ==> 14 10 | 11 | (define (sum n m) 12 | (let ((x (+ 1 (- m n)))) 13 | (+ (quotient (+ x (* x x)) 14 | 2) 15 | (* x (- n 1))))) 16 | -------------------------------------------------------------------------------- /lib/syntax-extensions.scm: -------------------------------------------------------------------------------- 1 | ; Scheme 9 from Empty Space, Function Library 2 | ; By Nils M Holm, 2010 3 | ; Placed in the Public Domain 4 | ; 5 | ; Convenience file to load extended syntax constructs. 6 | 7 | (load-from-library "amb.scm") 8 | (load-from-library "and-letstar.scm") 9 | (load-from-library "cond-expand.scm") 10 | (load-from-library "define-structure.scm") 11 | (load-from-library "fluid-let.scm") 12 | (load-from-library "hof.scm") 13 | (load-from-library "letcc.scm") 14 | (load-from-library "letrecstar.scm") 15 | (load-from-library "listq.scm") 16 | (load-from-library "setters.scm") 17 | (load-from-library "syntax-rules.scm") 18 | (load-from-library "type-case.scm") 19 | (load-from-library "when.scm") 20 | (load-from-library "while.scm") 21 | -------------------------------------------------------------------------------- /lib/take.scm: -------------------------------------------------------------------------------- 1 | ; Scheme 9 from Empty Space, Function Library 2 | ; By Nils M Holm, 2012 3 | ; Placed in the Public Domain 4 | ; 5 | ; (take list integer) ==> list 6 | ; 7 | ; Copy the first INTEGER conses of a proper list, creating a fresh 8 | ; that has the same elements as the original list in the first 9 | ; INTEGER positions. 10 | ; 11 | ; INTEGER may not be larger than the length of LIST. 12 | ; 13 | ; Example: (take '(foo bar baz) 0) ==> () 14 | ; (take '(foo bar baz) 1) ==> (foo) 15 | ; (take '(foo bar baz) 3) ==> (foo bar baz) 16 | 17 | (define (take a n) 18 | (let copy ((a a) 19 | (n n) 20 | (r '())) 21 | (if (or (not (pair? a)) 22 | (zero? n)) 23 | (reverse! r) 24 | (copy (cdr a) 25 | (- n 1) 26 | (cons (car a) r))))) 27 | -------------------------------------------------------------------------------- /lib/transpose.scm: -------------------------------------------------------------------------------- 1 | ; Scheme 9 from Empty Space, Function Library 2 | ; By Nils M Holm, 2009 3 | ; Placed in the Public Domain 4 | ; 5 | ; (transpose list) ==> list 6 | ; 7 | ; Transpose a matrix. A matrix is represented by a nested list, 8 | ; where each inner list is a column of the matrix. 9 | ; 10 | ; Example: (transpose '((1 2 3) (4 5 6))) ==> ((1 4) (2 5) (3 6)) 11 | 12 | (define (transpose x) 13 | (apply map list x)) 14 | -------------------------------------------------------------------------------- /lib/tree-equalp.scm: -------------------------------------------------------------------------------- 1 | ; Scheme 9 from Empty Space, Function Library 2 | ; By Nils M Holm, 2010 3 | ; Placed in the Public Domain 4 | ; 5 | ; (tree-equal? procedure pair1 pair2) ==> boolean 6 | ; 7 | ; Compare the leaves of two trees PAIR1 and PAIR2 using the predicate 8 | ; PROCEDURE. TREE-EQUAL? returns #T if the trees have the same structure 9 | ; and (procedure x1 x2) holds for their pairwise leaves. 10 | ; 11 | ; Example: (tree-equal? (lambda (x y) #t) 12 | ; '(((a . b) (c . d)) (e . f)) 13 | ; '(((1 . 2) (3 . 4)) (5 . 6))) ==> #t 14 | ; 15 | ; (tree-equal? eqv? 16 | ; '((1 . 2) (3 . 4)) 17 | ; '((1 . 2) (3 4))) ==> #f 18 | 19 | (define (tree-equal? p t1 t2) 20 | (if (pair? t1) 21 | (and (pair? t2) 22 | (tree-equal? p (car t1) (car t2)) 23 | (tree-equal? p (cdr t1) (cdr t2))) 24 | (p t1 t2))) 25 | -------------------------------------------------------------------------------- /lib/troffify-char.scm: -------------------------------------------------------------------------------- 1 | ; Scheme 9 from Empty Space, Function Library 2 | ; By Nils M Holm, 2018 3 | ; In the public domain 4 | ; 5 | ; (troffify-char char) ==> string 6 | ; (troffify-string string) ==> string 7 | ; 8 | ; TROFFIFY-CHAR converts a char to a string that is save for 9 | ; inclusion in a TROFF document. TROFFIFY-STRING does the 10 | ; same for a string. 11 | ; 12 | ; Note: the conversion "$" -> "$dollar$" is a local idiosyncrasy. 13 | ; 14 | ; Example: (troffify-char #\$) ==> "$dollar$" 15 | ; (troffify-string "\"a\\b\"") ==> "\"a\\\\b\"" 16 | 17 | (define (troffify-char c) 18 | (cond ((char=? c #\\) "\\\\") 19 | ((char=? c #\$) "$dollar$") 20 | (else (string c)))) 21 | 22 | (define (troffify-string s) 23 | (apply string-append 24 | (map troffify-char (string->list s)))) 25 | -------------------------------------------------------------------------------- /lib/union.scm: -------------------------------------------------------------------------------- 1 | ; Scheme 9 from Empty Space, Function Library 2 | ; By Nils M Holm, 2009 3 | ; Placed in the Public Domain 4 | ; 5 | ; (union list ...) ==> list 6 | ; 7 | ; Compute the union of a series of sets. 8 | ; 9 | ; Example: (union '(v w x) '(w x y) '(x y z)) ==> (v w x y z) 10 | 11 | (load-from-library "list-to-set.scm") 12 | 13 | (define (union . a*) 14 | (list->set (apply append a*))) 15 | -------------------------------------------------------------------------------- /lib/variance.scm: -------------------------------------------------------------------------------- 1 | ; Scheme 9 from Empty Space, Function Library 2 | ; By Nils M Holm, 2015 3 | ; Placed in the Public Domain 4 | ; 5 | ; (variance list) ==> real 6 | ; 7 | ; (load-from-library "variance.scm") 8 | ; 9 | ; Return the variance of the given list of values. 10 | ; 11 | ; Example: (variance '(1 1 2 1 1)) ==> 0.16 12 | 13 | (load-from-library "mean.scm") 14 | 15 | (define (variance set) 16 | (- (/ (apply + (map (lambda (x) (* x x)) set)) 17 | (length set)) 18 | ((lambda (x) (* x x)) (mean set)))) 19 | -------------------------------------------------------------------------------- /lib/vector-tools.scm: -------------------------------------------------------------------------------- 1 | ; Scheme 9 from Empty Space, Function Library 2 | ; By Nils M Holm, 2010 3 | ; Placed in the Public Domain 4 | ; 5 | ; Convenience file to load additional string procedures. 6 | 7 | (load-from-library "subvector.scm") 8 | (load-from-library "vector-map.scm") 9 | -------------------------------------------------------------------------------- /prog/adventure.intro: -------------------------------------------------------------------------------- 1 | Scheme 9 Mascot 2 | 3 |

S9fES is a mature, portable, and comprehensible public-domain 4 | interpreter for R4RS Scheme offering

5 | 6 |
    7 |
  • support for low-level Unix programming
  • 8 |
  • cursor addressing with Curses
  • 9 |
  • decimal-based real number arithmetics
  • 10 |
  • basic networking procedures
  • 11 |
  • loads of useful library functions
  • 12 |
13 | 14 |

So you want to get access to the latest S9fES source code?

15 | 16 |

Your mission is to get access to the terminal room of a 17 | cold, faceless concrete blockwellspring 18 | of creativity (a.k.a. college) and steal the code! 19 |

20 | -------------------------------------------------------------------------------- /s9ext.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Scheme 9 from Empty Space, Refactored 3 | * By Nils M Holm, 2007-2019 4 | * In the public domain 5 | * 6 | * Interface for extension procedures. 7 | */ 8 | 9 | extern cell Rts; 10 | extern int Sp; 11 | 12 | #define parg(n) car(vector(*GC_stack)[*GC_stkptr-(n)]) 13 | #define narg() fixval(vector(*GC_stack)[*GC_stkptr]) 14 | 15 | #define BOL T_BOOLEAN 16 | #define CHR T_CHAR 17 | #define INP T_INPUT_PORT 18 | #define INT T_INTEGER 19 | #define LST T_LIST 20 | #define OUP T_OUTPUT_PORT 21 | #define PAI T_PAIR 22 | #define FUN T_FUNCTION 23 | #define REA T_REAL 24 | #define STR T_STRING 25 | #define SYM T_SYMBOL 26 | #define VEC T_VECTOR 27 | #define ___ T_ANY 28 | 29 | void add_primitives(char *name, S9_PRIM *p); 30 | void error(char *msg, cell expr); 31 | cell integer_value(char *src, cell x); 32 | -------------------------------------------------------------------------------- /util/dirhead: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | @DESC@ : S9fES : T3X.ORG 5 | 6 | 7 | 8 | 9 | 10 |
http://t3x.org/s9fes/@BASE@
11 | 12 |
13 | 14 |

@DESC@

15 | 16 | -------------------------------------------------------------------------------- /util/dirtail: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 |

contact  |  5 | privacy 6 |

7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /util/libhead: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | @TITLE@ : S9fES : T3X.ORG 5 | 6 | 7 | 8 | 9 | 10 |
http://t3x.org/s9fes/@BASE@
11 | 12 |
13 | 14 |

@DESC@

15 | 16 | -------------------------------------------------------------------------------- /util/libtail: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 |

contact  |  5 | privacy 6 |

7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /util/mktoc.sed: -------------------------------------------------------------------------------- 1 | s/C;.*\...*\...*;\(.*\);\(..\)$/\\f[HI]\1 \2\\fP/p 2 | s/C;.*\...*\...*;\(.*\);\(.\)$/\\f[HI]\1 \\h'\\w'0'u'\2\\fP/p 3 | s/C;.*\...*;\(.*\);\(..\)$/\1 \2/p 4 | s/C;.*\...*;\(.*\);\(.\)$/\1 \\h'\\w'0'u'\2/p 5 | s/C;.*\.;\(.*\);\(..\)$/\\f[HB]\1 \2\\fP/p 6 | s/C;.*\.;\(.*\);\(.\)$/\\f[HB]\1 \\h'\\w'0'u'\2\\fP/p 7 | -------------------------------------------------------------------------------- /util/pagehead: -------------------------------------------------------------------------------- 1 | 2 |
3 | -------------------------------------------------------------------------------- /util/pagetail: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 |

contact  |  5 | privacy 6 |

7 | 8 | -------------------------------------------------------------------------------- /util/rp_html: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # 3 | # rpp profile for 4 | # 5 | # HTML 6 | # 7 | init-string 8 | boldface-on 9 | boldface-off 10 | underline-on 11 | underline-off 12 | italics-on 13 | italics-off 14 | -------------------------------------------------------------------------------- /util/s9.rc: -------------------------------------------------------------------------------- 1 | #!/bin/rc 2 | 3 | # S9 startup script 4 | 5 | # based on a script in this article: 6 | # http://ninetimes.cat-v.org/tips/2009/07/19/0/ 7 | 8 | s9dir=$home/lib/s9fes 9 | 10 | mkdir -p $home/lib/s9fes 11 | 12 | for (i in . $objtype lib ext contrib) 13 | bind -a $s9dir/$i $home/lib/s9fes 14 | 15 | S9FES_LIBRARY_PATH=$home/lib/s9fes 16 | S9FES_IMAGE_DIR=$home/lib/s9fes/$objtype 17 | /$objtype/bin/s9fes $* 18 | 19 | unmount $home/lib/s9fes 20 | -------------------------------------------------------------------------------- /util/stress-tests.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bakul/s9fes/57d9369595acabe89702e0196234dbe21900f6ce/util/stress-tests.tgz --------------------------------------------------------------------------------