commit 8cef078a1936124e7724fd018fad15d8a31f4007
parent 8e5278c3eed890555a0f93fe03d634da4639e02f
Author: Andres Navarro <canavarro82@gmail.com>
Date: Tue, 27 Dec 2011 01:57:09 -0300
Bugfixes: re-added deleted ground bindings (display, newline, flush-output-port), completed system module in the manual. Refactor: renamed some system combiners to be verbs instead of nouns. Changed behaviour of get-environment-variable to throw an error and added defined-environment-variable? predicate to check for this.
Diffstat:
15 files changed, 284 insertions(+), 88 deletions(-)
diff --git a/TODO b/TODO
@@ -6,7 +6,6 @@
- bytevector
- module/library
- error
-- system
** Test
*** Windows
- build
diff --git a/doc/html/Alphabetical-Index.html b/doc/html/Alphabetical-Index.html
@@ -5,7 +5,7 @@
<meta name="description" content="klisp Reference Manual">
<meta name="generator" content="makeinfo 4.13">
<link title="Top" rel="start" href="index.html#Top">
-<link rel="prev" href="Ports.html#Ports" title="Ports">
+<link rel="prev" href="System.html#System" title="System">
<link rel="next" href="../index.html#dir" title="(dir)">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<meta http-equiv="Content-Style-Type" content="text/css">
@@ -26,7 +26,7 @@
<a name="Alphabetical-Index"></a>
<p>
Next: <a rel="next" accesskey="n" href="../index.html#dir">(dir)</a>,
-Previous: <a rel="previous" accesskey="p" href="Ports.html#Ports">Ports</a>,
+Previous: <a rel="previous" accesskey="p" href="System.html#System">System</a>,
Up: <a rel="up" accesskey="u" href="index.html#Top">Top</a>
<hr>
</div>
@@ -166,6 +166,8 @@ Up: <a rel="up" accesskey="u" href="index.html#Top">Top</a>
<li><a href="Pairs-and-lists.html#index-copy_002des_002dimmutable_0021-50"><code>copy-es-immutable!</code></a>: <a href="Pairs-and-lists.html#Pairs-and-lists">Pairs and lists</a></li>
<li><a href="Numbers.html#index-cos-225"><code>cos</code></a>: <a href="Numbers.html#Numbers">Numbers</a></li>
<li><a href="Pairs-and-lists.html#index-countable_002dlist_003f-98"><code>countable-list?</code></a>: <a href="Pairs-and-lists.html#Pairs-and-lists">Pairs and lists</a></li>
+<li><a href="System.html#index-defined_002denvironment_002dvariable_003f-358"><code>defined-environment-variable?</code></a>: <a href="System.html#System">System</a></li>
+<li><a href="System.html#index-delete_002dfile-354"><code>delete-file</code></a>: <a href="System.html#System">System</a></li>
<li><a href="Numbers.html#index-denominator-213"><code>denominator</code></a>: <a href="Numbers.html#Numbers">Numbers</a></li>
<li><a href="Format-of-Descriptions.html#index-description-format-7">description format</a>: <a href="Format-of-Descriptions.html#Format-of-Descriptions">Format of Descriptions</a></li>
<li><a href="Characters.html#index-digit_002d_003echar-292"><code>digit->char</code></a>: <a href="Characters.html#Characters">Characters</a></li>
@@ -196,6 +198,7 @@ Up: <a rel="up" accesskey="u" href="index.html#Top">Top</a>
<li><a href="Numbers.html#index-exp-222"><code>exp</code></a>: <a href="Numbers.html#Numbers">Numbers</a></li>
<li><a href="Numbers.html#index-expt-221"><code>expt</code></a>: <a href="Numbers.html#Numbers">Numbers</a></li>
<li><a href="Continuations.html#index-extend_002dcontinuation-144"><code>extend-continuation</code></a>: <a href="Continuations.html#Continuations">Continuations</a></li>
+<li><a href="System.html#index-file_002dexists-353"><code>file-exists</code></a>: <a href="System.html#System">System</a></li>
<li><a href="Ports.html#index-file_002dport_003f-299"><code>file-port?</code></a>: <a href="Ports.html#Ports">Ports</a></li>
<li><a href="Pairs-and-lists.html#index-filter-94"><code>filter</code></a>: <a href="Pairs-and-lists.html#Pairs-and-lists">Pairs and lists</a></li>
<li><a href="Ports.html#index-find_002drequired_002dfilename-347"><code>find-required-filename</code></a>: <a href="Ports.html#Ports">Ports</a></li>
@@ -211,7 +214,13 @@ Up: <a rel="up" accesskey="u" href="index.html#Top">Top</a>
<li><a href="Environments.html#index-get_002dcurrent_002denvironment-113"><code>get-current-environment</code></a>: <a href="Environments.html#Environments">Environments</a></li>
<li><a href="Ports.html#index-get_002dcurrent_002derror_002dport-308"><code>get-current-error-port</code></a>: <a href="Ports.html#Ports">Ports</a></li>
<li><a href="Ports.html#index-get_002dcurrent_002dinput_002dport-306"><code>get-current-input-port</code></a>: <a href="Ports.html#Ports">Ports</a></li>
+<li><a href="System.html#index-get_002dcurrent_002djiffies-351"><code>get-current-jiffies</code></a>: <a href="System.html#System">System</a></li>
<li><a href="Ports.html#index-get_002dcurrent_002doutput_002dport-307"><code>get-current-output-port</code></a>: <a href="Ports.html#Ports">Ports</a></li>
+<li><a href="System.html#index-get_002dcurrent_002dsecond-350"><code>get-current-second</code></a>: <a href="System.html#System">System</a></li>
+<li><a href="System.html#index-get_002denvironment_002dvariable-359"><code>get-environment-variable</code></a>: <a href="System.html#System">System</a></li>
+<li><a href="System.html#index-get_002denvironment_002dvariables-360"><code>get-environment-variables</code></a>: <a href="System.html#System">System</a></li>
+<li><a href="System.html#index-get_002dinterpreter_002darguments-357"><code>get-interpreter-arguments</code></a>: <a href="System.html#System">System</a></li>
+<li><a href="System.html#index-get_002djiffies_002dper_002dsecond-352"><code>get-jiffies-per-second</code></a>: <a href="System.html#System">System</a></li>
<li><a href="Pairs-and-lists.html#index-get_002dlist_002dmetrics-86"><code>get-list-metrics</code></a>: <a href="Pairs-and-lists.html#Pairs-and-lists">Pairs and lists</a></li>
<li><a href="Ports.html#index-get_002dmodule-348"><code>get-module</code></a>: <a href="Ports.html#Ports">Ports</a></li>
<li><a href="Ports.html#index-get_002doutput_002dbytevector-323"><code>get-output-bytevector</code></a>: <a href="Ports.html#Ports">Ports</a></li>
@@ -220,6 +229,7 @@ Up: <a rel="up" accesskey="u" href="index.html#Top">Top</a>
<li><a href="Numbers.html#index-get_002dreal_002dexact_002dprimary-205"><code>get-real-exact-primary</code></a>: <a href="Numbers.html#Numbers">Numbers</a></li>
<li><a href="Numbers.html#index-get_002dreal_002dinternal_002dbounds-202"><code>get-real-internal-bounds</code></a>: <a href="Numbers.html#Numbers">Numbers</a></li>
<li><a href="Numbers.html#index-get_002dreal_002dinternal_002dprimary-204"><code>get-real-internal-primary</code></a>: <a href="Numbers.html#Numbers">Numbers</a></li>
+<li><a href="System.html#index-get_002dscript_002darguments-356"><code>get-script-arguments</code></a>: <a href="System.html#System">System</a></li>
<li><a href="Numbers.html#index-get_002dstring_002darithmetic-210"><code>get-string-arithmetic</code></a>: <a href="Numbers.html#Numbers">Numbers</a></li>
<li><a href="Continuations.html#index-guard_002dcontinuation-145"><code>guard-continuation</code></a>: <a href="Continuations.html#Continuations">Continuations</a></li>
<li><a href="Continuations.html#index-guard_002ddynamic_002dextent-151"><code>guard-dynamic-extent</code></a>: <a href="Continuations.html#Continuations">Continuations</a></li>
@@ -316,6 +326,7 @@ Up: <a rel="up" accesskey="u" href="index.html#Top">Top</a>
<li><a href="Pairs-and-lists.html#index-reduce-99"><code>reduce</code></a>: <a href="Pairs-and-lists.html#Pairs-and-lists">Pairs and lists</a></li>
<li><a href="Ports.html#index-register_002drequirement_0021-345"><code>register-requirement!</code></a>: <a href="Ports.html#Ports">Ports</a></li>
<li><a href="Ports.html#index-registered_002drequirement_003f-344"><code>registered-requirement?</code></a>: <a href="Ports.html#Ports">Ports</a></li>
+<li><a href="System.html#index-rename_002dfile-355"><code>rename-file</code></a>: <a href="System.html#System">System</a></li>
<li><a href="Ports.html#index-require-343"><code>require</code></a>: <a href="Ports.html#Ports">Ports</a></li>
<li><a href="Pairs-and-lists.html#index-reverse-85"><code>reverse</code></a>: <a href="Pairs-and-lists.html#Pairs-and-lists">Pairs and lists</a></li>
<li><a href="Numbers.html#index-robust_003f-176"><code>robust?</code></a>: <a href="Numbers.html#Numbers">Numbers</a></li>
@@ -362,6 +373,7 @@ Up: <a rel="up" accesskey="u" href="index.html#Top">Top</a>
<li><a href="Symbols.html#index-symbol_002d_003estring-25"><code>symbol->string</code></a>: <a href="Symbols.html#Symbols">Symbols</a></li>
<li><a href="Symbols.html#index-symbol_003f-24"><code>symbol?</code></a>: <a href="Symbols.html#Symbols">Symbols</a></li>
<li><a href="Symbols.html#index-symbols-23">symbols</a>: <a href="Symbols.html#Symbols">Symbols</a></li>
+<li><a href="System.html#index-system-349">system</a>: <a href="System.html#System">System</a></li>
<li><a href="Numbers.html#index-tan-226"><code>tan</code></a>: <a href="Numbers.html#Numbers">Numbers</a></li>
<li><a href="Ports.html#index-textual_002dport_003f-297"><code>textual-port?</code></a>: <a href="Ports.html#Ports">Ports</a></li>
<li><a href="Numbers.html#index-truncate-216"><code>truncate</code></a>: <a href="Numbers.html#Numbers">Numbers</a></li>
@@ -406,6 +418,7 @@ Up: <a rel="up" accesskey="u" href="index.html#Top">Top</a>
<li><a href="Alphabetical-Index.html#toc_Strings">15 Strings</a></li>
<li><a href="Alphabetical-Index.html#toc_Characters">16 Characters</a></li>
<li><a href="Alphabetical-Index.html#toc_Ports">17 Ports</a></li>
+<li><a href="Alphabetical-Index.html#toc_System">18 System</a></li>
<li><a href="Alphabetical-Index.html#toc_Alphabetical-Index">Index</a></li>
</ul>
</div>
@@ -458,6 +471,7 @@ Up: <a rel="up" accesskey="u" href="index.html#Top">Top</a>
<li><a name="toc_Strings" href="Strings.html#Strings">15 Strings</a>
<li><a name="toc_Characters" href="Characters.html#Characters">16 Characters</a>
<li><a name="toc_Ports" href="Ports.html#Ports">17 Ports</a>
+<li><a name="toc_System" href="System.html#System">18 System</a>
<li><a name="toc_Alphabetical-Index" href="Alphabetical-Index.html#Alphabetical-Index">Index</a>
</li></ul>
</div>
diff --git a/doc/html/Ports.html b/doc/html/Ports.html
@@ -6,7 +6,7 @@
<meta name="generator" content="makeinfo 4.13">
<link title="Top" rel="start" href="index.html#Top">
<link rel="prev" href="Characters.html#Characters" title="Characters">
-<link rel="next" href="Alphabetical-Index.html#Alphabetical-Index" title="Alphabetical Index">
+<link rel="next" href="System.html#System" title="System">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
@@ -25,7 +25,7 @@
<div class="node">
<a name="Ports"></a>
<p>
-Next: <a rel="next" accesskey="n" href="Alphabetical-Index.html#Alphabetical-Index">Alphabetical Index</a>,
+Next: <a rel="next" accesskey="n" href="System.html#System">System</a>,
Previous: <a rel="previous" accesskey="p" href="Characters.html#Characters">Characters</a>,
Up: <a rel="up" accesskey="u" href="index.html#Top">Top</a>
<hr>
@@ -600,9 +600,6 @@ prior to evaluating read expressions, by binding symbol
<code>module-parameters</code> to the <code>environment</code> argument.
</p></blockquote></div>
-<!-- appendices -->
-<!-- TODO -->
<!-- *-texinfo-*- -->
-<!-- TODO correct prev node -->
</body></html>
diff --git a/doc/html/index.html b/doc/html/index.html
@@ -53,6 +53,7 @@ Up: <a rel="up" accesskey="u" href="../index.html#dir">(dir)</a>
<li><a href="Strings.html#Strings">Strings</a>: Strings module features.
<li><a href="Characters.html#Characters">Characters</a>: Characters module features.
<li><a href="Ports.html#Ports">Ports</a>: Ports module features.
+<li><a href="System.html#System">System</a>: System module features.
<!-- TODO add error objs to both klisp and the manual -->
<li><a href="Alphabetical-Index.html#Alphabetical-Index">Alphabetical Index</a>: Index including concepts, functions, variables,
and other terms.
diff --git a/doc/klisp.info b/doc/klisp.info
@@ -56,6 +56,7 @@ the header "Permission to copy this report", that reads:
* Strings:: Strings module features.
* Characters:: Characters module features.
* Ports:: Ports module features.
+* System:: System module features.
* Alphabetical Index:: Index including concepts, functions, variables,
and other terms.
@@ -2518,7 +2519,7 @@ features defined here were taken mostly from r7rs.
base argument.
-File: klisp.info, Node: Ports, Next: Alphabetical Index, Prev: Characters, Up: Top
+File: klisp.info, Node: Ports, Next: System, Prev: Characters, Up: Top
17 Ports
********
@@ -3015,7 +3016,87 @@ klisp and was taken from r7rs.
binding symbol `module-parameters' to the `environment' argument.
-File: klisp.info, Node: Alphabetical Index, Next: (dir), Prev: Ports, Up: Top
+File: klisp.info, Node: System, Next: Alphabetical Index, Prev: Ports, Up: Top
+
+18 System
+*********
+
+Module System contains some useful features for interacting with the
+host environment.
+
+ SOURCE NOTE: most of these come from r7rs.
+
+ -- Applicative: get-current-second (get-current-second)
+ Applicative `get-current-second' returns the number of seconds
+ elapsed since the UNIX/POSIX epoch (that is midnight January 1st,
+ 1970, UTC).
+
+ NOTE: r7rs specifies TAI seconds, but for now we are sticking to
+ POSIX here.
+
+ -- Applicative: get-current-jiffies (get-current-jiffies)
+ Applicative `get-current-jiffies' returns the number of jiffies
+ (fractions of a second) elapsed since an arbitrary epoch that may
+ change in each run of the klisp interpreter. Applicative
+ `get-jiffies-per-second' can be used to determine which fraction
+ of a second a jiffy represents.
+
+ -- Applicative: get-jiffies-per-second (get-jiffies-per-second)
+ Applicative `get-jiffies-per-second' returns a constant
+ representing the number of jiffies that correspond to one second.
+
+ -- Applicative: file-exists (file-exists string)
+ Predicate `file-exists?' checks to see if a file named `string'
+ exists.
+
+ -- Applicative: delete-file (delete-file string)
+ `string' should be the name/path for an existing file.
+
+ Applicative `delete-file' deletes the file named `string'. If it
+ doesn't exists or can't be deleted, an error is signaled. The
+ result returned by `delete-file' is inert.
+
+ -- Applicative: rename-file (rename-file string1 string2)
+ `string1' should be the name/path for an existing file, `string2'
+ should be the name/path for a non existing file.
+
+ Applicative `rename-file' renames the file named `string1' to
+ `string2'. If the file doesn't exists or can't be renamed for any
+ reason, an error is signaled. The result returned by `rename-file'
+ is inert.
+
+ SOURCE NOTE: this is missing from r7rs, it is taken from C, being
+ quite similar to `delete-file'.
+
+ -- Applicative: get-script-arguments (get-script-arguments)
+ -- Applicative: get-interpreter-arguments (get-interpreter-arguments)
+ These applicatives return respectively the script and interpreter
+ arguments. The script arguments are a list of the arguments
+ passed to the klisp interpreter starting from (and including) the
+ script name. The interpreter arguments are the complete list of
+ arguments passed to the klisp interpreter (including the name of
+ the interpreter as the first item in the list, the interpreter
+ flag arguments and the script name and arguments.
+
+ -- Applicative: defined-environment-variable?
+ (defined-environment-variable? string)
+ Predicate `defined-environment-variable?' returns true iff
+ `string' represents a defined envrionment variable.
+
+ -- Applicative: get-environment-variable (get-environment-variable
+ string)
+ Applicative `get-environment-variable' returns the value of the
+ environment variable represented by `string'. If `string' doesn't
+ represent a defined environment variable an error is signaled.
+
+ -- Applicative: get-environment-variables (get-environment-variables)
+ Applicative `get-environment-variable' returns an alist
+ representing the defined environment variables and their values.
+ The alist is a list of `(variable . value)' entries, where both
+ `variable' and `value' are strings.
+
+
+File: klisp.info, Node: Alphabetical Index, Next: (dir), Prev: System, Up: Top
Index
*****
@@ -3155,6 +3236,8 @@ Index
* copy-es-immutable!: Pairs and lists. (line 59)
* cos: Numbers. (line 405)
* countable-list?: Pairs and lists. (line 307)
+* defined-environment-variable?: System. (line 65)
+* delete-file: System. (line 35)
* denominator: Numbers. (line 330)
* description format: Format of Descriptions.
(line 6)
@@ -3186,6 +3269,7 @@ Index
* exp: Numbers. (line 402)
* expt: Numbers. (line 397)
* extend-continuation: Continuations. (line 50)
+* file-exists: System. (line 31)
* file-port?: Ports. (line 54)
* filter: Pairs and lists. (line 277)
* find-required-filename: Ports. (line 457)
@@ -3202,7 +3286,13 @@ Index
* get-current-environment: Environments. (line 114)
* get-current-error-port: Ports. (line 91)
* get-current-input-port: Ports. (line 89)
+* get-current-jiffies: System. (line 20)
* get-current-output-port: Ports. (line 90)
+* get-current-second: System. (line 12)
+* get-environment-variable: System. (line 70)
+* get-environment-variables: System. (line 75)
+* get-interpreter-arguments: System. (line 55)
+* get-jiffies-per-second: System. (line 27)
* get-list-metrics: Pairs and lists. (line 161)
* get-module: Ports. (line 488)
* get-output-bytevector: Ports. (line 195)
@@ -3211,6 +3301,7 @@ Index
* get-real-exact-primary: Numbers. (line 267)
* get-real-internal-bounds: Numbers. (line 247)
* get-real-internal-primary: Numbers. (line 266)
+* get-script-arguments: System. (line 54)
* get-string-arithmetic: Numbers. (line 314)
* guard-continuation: Continuations. (line 63)
* guard-dynamic-extent: Continuations. (line 156)
@@ -3309,6 +3400,7 @@ Index
* reduce: Pairs and lists. (line 312)
* register-requirement!: Ports. (line 454)
* registered-requirement?: Ports. (line 453)
+* rename-file: System. (line 42)
* require: Ports. (line 430)
* reverse: Pairs and lists. (line 150)
* robust?: Numbers. (line 102)
@@ -3355,6 +3447,7 @@ Index
* symbol->string: Symbols. (line 22)
* symbol?: Symbols. (line 18)
* symbols: Symbols. (line 6)
+* system: System. (line 6)
* tan: Numbers. (line 406)
* textual-port?: Ports. (line 42)
* truncate: Numbers. (line 341)
@@ -3381,36 +3474,37 @@ Index
Tag Table:
Node: Top703
-Node: License2663
-Node: Introduction4345
-Node: Caveats7278
-Node: Kernel History8064
-Node: Conventions9509
-Node: Some Terms10180
-Node: Evaluation Notation10851
-Node: Printing Notation11872
-Node: Error Messages12348
-Node: Format of Descriptions12996
-Node: A Sample Applicative Description13560
-Node: Acknowledgements15323
-Node: Interpreter15709
-Ref: Command Line Options18009
-Ref: Interpreter Exit Status18943
-Node: Booleans20171
-Node: Equivalence22848
-Node: Symbols23641
-Node: Control25271
-Node: Pairs and lists29362
-Node: Environments48242
-Node: Combiners58915
-Node: Continuations65569
-Node: Encapsulations74112
-Node: Promises75565
-Node: Keyed Variables79720
-Node: Numbers82491
-Node: Strings104945
-Node: Characters112206
-Node: Ports116852
-Node: Alphabetical Index140004
+Node: License2715
+Node: Introduction4397
+Node: Caveats7330
+Node: Kernel History8116
+Node: Conventions9561
+Node: Some Terms10232
+Node: Evaluation Notation10903
+Node: Printing Notation11924
+Node: Error Messages12400
+Node: Format of Descriptions13048
+Node: A Sample Applicative Description13612
+Node: Acknowledgements15375
+Node: Interpreter15761
+Ref: Command Line Options18061
+Ref: Interpreter Exit Status18995
+Node: Booleans20223
+Node: Equivalence22900
+Node: Symbols23693
+Node: Control25323
+Node: Pairs and lists29414
+Node: Environments48294
+Node: Combiners58967
+Node: Continuations65621
+Node: Encapsulations74164
+Node: Promises75617
+Node: Keyed Variables79772
+Node: Numbers82543
+Node: Strings104997
+Node: Characters112258
+Node: Ports116904
+Node: System140044
+Node: Alphabetical Index143538
End Tag Table
diff --git a/doc/src/Makefile b/doc/src/Makefile
@@ -9,7 +9,8 @@ srcs = klisp.texi index.texi \
continuations.texi encapsulations.texi \
promises.texi keyed_vars.texi \
numbers.texi strings.texi \
- characters.texi ports.texi
+ characters.texi ports.texi \
+ system.texi
#TODO add dvi/pdf output
#TODO check what happens with xrefs
diff --git a/doc/src/index.texi b/doc/src/index.texi
@@ -2,7 +2,7 @@
@setfilename ../src/index
@c TODO correct prev node
-@node Alphabetical Index, (dir), Ports, Top
+@node Alphabetical Index, (dir), System, Top
@c this is from the elisp manual... Should read a little about this.
@unnumbered Index
diff --git a/doc/src/klisp.texi b/doc/src/klisp.texi
@@ -110,6 +110,7 @@ permission is granted to copy it in whole or in part without fee.
* Strings:: Strings module features.
* Characters:: Characters module features.
* Ports:: Ports module features.
+* System:: System module features.
@c TODO add error objs to both klisp and the manual
* Alphabetical Index:: Index including concepts, functions, variables,
and other terms.
@@ -137,6 +138,7 @@ permission is granted to copy it in whole or in part without fee.
@include strings.texi
@include characters.texi
@include ports.texi
+@include system.texi
@c appendices
@c TODO
diff --git a/doc/src/ports.texi b/doc/src/ports.texi
@@ -1,7 +1,7 @@
@c -*-texinfo-*-
@setfilename ../src/ports
-@node Ports, Alphabetical Index, Characters, Top
+@node Ports, System, Characters, Top
@comment node-name, next, previous, up
@chapter Ports
diff --git a/doc/src/system.texi b/doc/src/system.texi
@@ -1,31 +1,91 @@
-@deffn Applicative file-exists? (file-exists? string)
- @code{string} should be the name/path for a file.
+@c -*-texinfo-*-
+@setfilename ../src/system
- Predicate @code{file-exists?} checks to see if a file named
-@code{string} exists.
+@node System, Alphabetical Index, Ports, Top
+@comment node-name, next, previous, up
+
+@chapter System
+@cindex system
+
+Module System contains some useful features for interacting with the
+host environment.
- SOURCE NOTE: this is missing from Kernel, it is taken from r7rs Scheme.
+SOURCE NOTE: most of these come from r7rs.
+
+@deffn Applicative get-current-second (get-current-second)
+Applicative @code{get-current-second} returns the number of seconds
+elapsed since the UNIX/POSIX epoch (that is midnight January 1st,
+1970, UTC).
+
+NOTE: r7rs specifies TAI seconds, but for now we are sticking to POSIX
+here.
+@end deffn
+
+@deffn Applicative get-current-jiffies (get-current-jiffies)
+Applicative @code{get-current-jiffies} returns the number of jiffies
+(fractions of a second) elapsed since an arbitrary epoch that may
+change in each run of the klisp interpreter. Applicative
+@code{get-jiffies-per-second} can be used to determine which fraction
+of a second a jiffy represents.
+@end deffn
+
+@deffn Applicative get-jiffies-per-second (get-jiffies-per-second)
+Applicative @code{get-jiffies-per-second} returns a constant
+representing the number of jiffies that correspond to one second.
+@end deffn
+
+@deffn Applicative file-exists (file-exists string)
+Predicate @code{file-exists?} checks to see if a file named
+@code{string} exists.
@end deffn
@deffn Applicative delete-file (delete-file string)
- @code{string} should be the name/path for an existing file.
+@code{string} should be the name/path for an existing file.
- Applicative @code{delete-file} deletes the file named @code{string}.
+Applicative @code{delete-file} deletes the file named @code{string}.
If it doesn't exists or can't be deleted, an error is signaled. The
-result returned by @code{delete-file} is inert.
-
- SOURCE NOTE: this is missing from Kernel, it is taken from r7rs Scheme.
+result returned by @code{delete-file} is inert.
@end deffn
@deffn Applicative rename-file (rename-file string1 string2)
- @code{string1} should be the name/path for an existing file,
+@code{string1} should be the name/path for an existing file,
@code{string2} should be the name/path for a non existing file.
- Applicative @code{rename-file} renames the file named @code{string1}
+Applicative @code{rename-file} renames the file named @code{string1}
to @code{string2}. If the file doesn't exists or can't be renamed for
any reason, an error is signaled. The result returned by
-@code{rename-file} is inert.
+@code{rename-file} is inert.
+
+SOURCE NOTE: this is missing from r7rs, it is taken from C, being
+quite similar to @code{delete-file}.
+@end deffn
+
+@deffn Applicative get-script-arguments (get-script-arguments)
+@deffnx Applicative get-interpreter-arguments (get-interpreter-arguments)
+These applicatives return respectively the script and interpreter
+arguments. The script arguments are a list of the arguments passed to
+the klisp interpreter starting from (and including) the script name.
+The interpreter arguments are the complete list of arguments passed to
+the klisp interpreter (including the name of the interpreter as the
+first item in the list, the interpreter flag arguments and the script
+name and arguments.
+@end deffn
+
+@deffn Applicative defined-environment-variable? (defined-environment-variable? string)
+Predicate @code{defined-environment-variable?} returns true iff
+@code{string} represents a defined envrionment variable.
+@end deffn
+
+@deffn Applicative get-environment-variable (get-environment-variable string)
+Applicative @code{get-environment-variable} returns the value of the
+environment variable represented by @code{string}. If @code{string}
+doesn't represent a defined environment variable an error is signaled.
+@end deffn
- SOURCE NOTE: this is missing from Kernel AND Scheme, it is taken
-from C, being quite similar to @code{delete-file}.
+@deffn Applicative get-environment-variables (get-environment-variables)
+@c TODO xref to alist
+Applicative @code{get-environment-variable} returns an alist
+representing the defined environment variables and their values. The
+alist is a list of @code{(variable . value)} entries, where both
+@code{variable} and @code{value} are strings.
@end deffn
diff --git a/src/kgports.c b/src/kgports.c
@@ -1309,6 +1309,13 @@ void kinit_ports_ground_env(klisp_State *K)
i2tv(K_TEOF));
/* 15.1.? newline */
add_applicative(K, ground_env, "newline", newline, 0);
+ /* 15.1.? display */
+ add_applicative(K, ground_env, "display", display, 0);
+ /* 15.1.? read-line */
+ add_applicative(K, ground_env, "read-line", read_line, 0);
+ /* 15.1.? flush-output-port */
+ add_applicative(K, ground_env, "flush-output-port", flush, 0);
+
/* 15.1.? write-char */
add_applicative(K, ground_env, "write-char", write_char, 0);
/* 15.1.? read-char */
diff --git a/src/kgsystem.c b/src/kgsystem.c
@@ -29,7 +29,7 @@
/* XXX current revision of the r7rs draft asks for tai seconds,
I am sticking with UTC seconds for now, at least till the report is
ratified */
-void current_second(klisp_State *K)
+void get_current_second(klisp_State *K)
{
TValue *xparams = K->next_xparams;
TValue ptree = K->next_value;
@@ -50,7 +50,7 @@ void current_second(klisp_State *K)
}
/* ??.?.? current-jiffy */
-void current_jiffy(klisp_State *K)
+void get_current_jiffy(klisp_State *K)
{
TValue ptree = K->next_value;
check_0p(K, ptree);
@@ -58,7 +58,7 @@ void current_jiffy(klisp_State *K)
}
/* ??.?.? jiffies-per-second */
-void jiffies_per_second(klisp_State *K)
+void get_jiffies_per_second(klisp_State *K)
{
TValue ptree = K->next_value;
check_0p(K, ptree);
@@ -156,7 +156,24 @@ void get_arguments(klisp_State *K)
kapply_cc(K, res);
}
-/* ?.? get-environment-variable, get-environment-variables */
+/* ?.? defined-environment-variable?, get-environment-variable,
+ get-environment-variables */
+void defined_environment_variableP(klisp_State *K)
+{
+ TValue ptree = K->next_value;
+ TValue *xparams = K->next_xparams;
+ TValue denv = K->next_env;
+ klisp_assert(ttisenvironment(K->next_env));
+ UNUSED(xparams);
+ UNUSED(denv);
+
+ bind_1tp(K, ptree, "string", ttisstring, name);
+ char *str = getenv(kstring_buf(name));
+
+ TValue res = (str == NULL)? KFALSE : KTRUE;
+ kapply_cc(K, res);
+}
+
void get_environment_variable(klisp_State *K)
{
TValue ptree = K->next_value;
@@ -168,10 +185,11 @@ void get_environment_variable(klisp_State *K)
bind_1tp(K, ptree, "string", ttisstring, name);
char *str = getenv(kstring_buf(name));
- /* I follow r7rs here, but should probably throw error */
+
TValue res;
if (str == NULL) {
- res = KFALSE;
+ klispE_throw_simple_with_irritants(K, "undefined env var", 1, name);
+ return;
} else {
res = kstring_new_b_imm(K, str);
}
@@ -236,12 +254,12 @@ void kinit_system_ground_env(klisp_State *K)
TValue ground_env = K->ground_env;
TValue symbol, value;
- /* ??.?.? current-second */
- add_applicative(K, ground_env, "current-second", current_second, 0);
- /* ??.?.? current-jiffy */
- add_applicative(K, ground_env, "current-jiffy", current_jiffy, 0);
- /* ??.?.? jiffies-per-second */
- add_applicative(K, ground_env, "jiffies-per-second", jiffies_per_second,
+ /* ??.?.? get-current-second */
+ add_applicative(K, ground_env, "get-current-second", get_current_second, 0);
+ /* ??.?.? get-current-jiffy */
+ add_applicative(K, ground_env, "get-current-jiffy", get_current_jiffy, 0);
+ /* ??.?.? get-jiffies-per-second */
+ add_applicative(K, ground_env, "get-jiffies-per-second", get_jiffies_per_second,
0);
/* ?.? file-exists? */
add_applicative(K, ground_env, "file-exists?", file_existsp, 0);
@@ -256,7 +274,10 @@ void kinit_system_ground_env(klisp_State *K)
1, KNIL);
add_applicative(K, ground_env, "get-interpreter-arguments", get_arguments,
1, KNIL);
- /* ?.? get-environment-variable, get-environment-variables */
+ /* ?.? defined-environment-variable?, get-environment-variable,
+ get-environment-variables */
+ add_applicative(K, ground_env, "defined-environment-variable?",
+ defined_environment_variableP, 0);
add_applicative(K, ground_env, "get-environment-variable",
get_environment_variable, 0);
add_applicative(K, ground_env, "get-environment-variables",
diff --git a/src/tests/environments.k b/src/tests/environments.k
@@ -230,7 +230,6 @@
get-module))
;; Additional symbols defined in klisp.
-
($check-predicate
($binds? (make-kernel-standard-environment)
;; symbols
@@ -246,6 +245,7 @@
;; TODO
;; ports
textual-port? binary-port?
+ flush-output-port
with-error-to-file
get-current-error-port
open-binary-input-file open-binary-output-file
@@ -255,10 +255,9 @@
newline
display
read-u8 peek-u8 u8-ready? write-u8
- flush-output-port
- file-exists? delete-file rename-file
;; system functions
- current-second current-jiffy jiffies-per-second
+ get-current-second get-current-jiffy get-jiffies-per-second
+ file-exists? delete-file rename-file
;; bytevectors
bytevector?
;; error handling
diff --git a/src/tests/system.k b/src/tests/system.k
@@ -3,25 +3,25 @@
;; Tests of system features.
;;
-;; (R7RS 3rd draft, section 6.7.4) current-second
+;; (R7RS 3rd draft, section 6.7.4) get-current-second
-($check-predicate (applicative? current-second))
-($check-predicate (number? (current-second)))
+($check-predicate (applicative? get-current-second))
+($check-predicate (number? (get-current-second)))
;; TODO: Update before the year 2031....
($let ((T-2011-01-01 1293836400) (T-2031-01-01 1924988400))
- ($check-predicate (<? T-2011-01-01 (current-second)))
- ($check-predicate (>? T-2031-01-01 (current-second))))
+ ($check-predicate (<? T-2011-01-01 (get-current-second)))
+ ($check-predicate (>? T-2031-01-01 (get-current-second))))
-;; (R7RS 3rd draft, section 6.7.4) current-jiffy jiffies-per-second
+;; (R7RS 3rd draft, section 6.7.4) get-current-jiffy get-jiffies-per-second
-($check-predicate (applicative? current-jiffy jiffies-per-second))
-($check-predicate (exact-integer? (current-jiffy) (jiffies-per-second)))
-($check-predicate (positive? (current-jiffy) (jiffies-per-second)))
+($check-predicate (applicative? get-current-jiffy get-jiffies-per-second))
+($check-predicate (exact-integer? (get-current-jiffy) (get-jiffies-per-second)))
+($check-predicate (positive? (get-current-jiffy) (get-jiffies-per-second)))
-($let* ((jiffy1 (current-jiffy)) (jiffy2 (current-jiffy)))
+($let* ((jiffy1 (get-current-jiffy)) (jiffy2 (get-current-jiffy)))
($check-predicate (<=? jiffy1 jiffy2)))
-($let* ((jps1 (jiffies-per-second)) (jps2 (jiffies-per-second)))
+($let* ((jps1 (get-jiffies-per-second)) (jps2 (get-jiffies-per-second)))
($check-predicate (=? jps1 jps2)))
diff --git a/src/tests/test-interpreter.sh b/src/tests/test-interpreter.sh
@@ -290,7 +290,8 @@ unset KLISP_PATH
export KLISPTEST1=pqr
check_o '"pqr"' $KLISP '-e (write (get-environment-variable "KLISPTEST1"))'
-check_o '#f' $KLISP '-e (write (get-environment-variable "KLISPTEST2"))'
+check_o '#t' $KLISP '-e (write (defined-environment-variable? "KLISPTEST1"))'
+check_o '#f' $KLISP '-e (write (defined-environment-variable? "KLISPTEST2"))'
# script arguments