/
Parameters
178 lines (106 loc) · 5.09 KB
/
Parameters
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
[[tags: manual]]
[[toc:]]
== Parameters
Parameters are Chicken's form of dynamic variables, except that they are
procedures rather than actual variables. A parameter is a procedure of
zero or one arguments. To retrieve the value of a parameter call the
parameter-procedure with zero arguments. To change the setting of the
parameter, call the parameter-procedure with the new value as argument:
<enscript highlight=scheme>
(define foo (make-parameter 123))
(foo) ==> 123
(foo 99)
(foo) ==> 99
</enscript>
Parameters are fully thread-local, each thread of execution
owns a local copy of a parameters' value.
CHICKEN implements [[http://srfi.schemers.org/srfi-39/srfi-39.html|SRFI-39]].
=== make-parameter
<procedure>(make-parameter VALUE [GUARD])</procedure>
Returns a procedure that accepts zero or one argument. Invoking the
procedure with zero arguments returns {{VALUE}}. Invoking the
procedure with one argument changes its value to the value of that
argument (subsequent invocations with zero parameters return the new
value). {{GUARD}} should be a procedure of a single argument. Any
new values of the parameter (even the initial value) are passed to this
procedure. The guard procedure should check the value and/or convert it
to an appropriate form.
== Built-in parameters
Certain behavior of the interpreter and compiled programs can be
customized via the following built-in parameters:
=== case-sensitive
<parameter>(case-sensitive)</parameter>
If true, then {{read}} reads symbols and identifiers in
case-sensitive mode and uppercase characters in symbols are printed
escaped. Defaults to {{#t}}.
=== dynamic-load-libraries
<parameter>(dynamic-load-libraries)</parameter>
A list of strings containing shared libraries that should be checked
for explicitly loaded library units (this facility is not available on
all platforms). See {{load-library}}.
=== command-line-arguments
<parameter>(command-line-arguments)</parameter>
Contains the list of arguments passed to this program, with the name of
the program and any runtime options (all options starting with {{-:}})
removed.
=== current-read-table
<parameter>(current-read-table)</parameter>
A read-table object that holds read-procedures for special non-standard
read-syntax (see {{set-read-syntax!}} for more information).
=== exit-handler
<parameter>(exit-handler)</parameter>
A procedure of a single optional argument. When {{exit}} is called,
then this procedure will be invoked with the exit-code as argument. The
default behavior is to terminate the program.
=== eval-handler
<parameter>(eval-handler)</parameter>
A procedure of one or two arguments. When {{eval}} is invoked, it
calls the value of this parameter with the same arguments. The default
behavior is to evaluate the argument expression and to ignore the
second parameter.
=== force-finalizers
<parameter>(force-finalizers)</parameter>
If true, force and execute all pending finalizers before exiting the
program (either explicitly by {{exit}} or implicitly when the last
toplevel expression has been executed). Default is {{#t}}.
=== implicit-exit-handler
<parameter>(implicit-exit-handler)</parameter>
A procedure of no arguments. When the last toplevel expression of the
program has executed, then the value of this parameter is called. The
default behaviour is to invoke all pending finalizers.
=== keyword-style
<parameter>(keyword-style)</parameter>
Enables alternative keyword syntax, where {{STYLE}} may be either
{{#:prefix}} (as in Common Lisp), which recognizes symbols beginning
with a colon as keywords, or {{#:suffix}} (as in DSSSL), which recognizes
symbols ending with a colon as keywords.
Any other value disables the alternative syntaxes. In the interpreter
the default is {{#:suffix}}.
=== parenthesis-synonyms
<parameter>(parenthesis-synonyms)</parameter>
If true, then the list delimiter synonyms {{#\[}} {{#\]}} and {{#\{}} {{#\}}} are enabled. Defaults to {{#t}}.
=== symbol-escape
<parameter>(symbol-escape)</parameter>
If true, then the symbol escape {{#\|}} {{#\|}} is enabled. Defaults to {{#t}}.
=== load-verbose
<parameter>(load-verbose)</parameter>
A boolean indicating whether loading of source files, compiled code
(if available) and compiled libraries should display a message.
=== program-name
<parameter>(program-name)</parameter>
The name of the currently executing program. This is equivalent to
{{(car (argv))}} for compiled programs or the filename following the
{{-script}} option in interpreted scripts.
=== repl-prompt
<parameter>(repl-prompt)</parameter>
A procedure that should evaluate to a string that will be printed before reading
interactive input from the user in a read-eval-print loop. Defaults to
{{(lambda () "#;N> ")}}.
=== reset-handler
<parameter>(reset-handler)</parameter>
A procedure of zero arguments that is called via {{reset}}. The
default behavior in compiled code is to invoke the value of
{{(exit-handler)}}. The default behavior in the interpreter is to
abort the current computation and to restart the read-eval-print loop.
----
Previous: [[Declarations]] Next: [[Exceptions]]