source: project/wiki/man/4/Unit eval @ 27461

Last change on this file since 27461 was 27461, checked in by Ivan Raikov, 9 years ago

manual: synchronizing wiki manual with core manual

File size: 6.7 KB
Line 
1[[tags: manual]]
2[[toc:]]
3
4== Unit eval
5
6This unit has support for evaluation and macro-handling. This unit is used
7by default, unless the program is compiled with the {{-explicit-use}}
8option.
9
10=== Loading code
11
12==== load
13
14<procedure>(load FILE [EVALPROC])</procedure>
15
16Loads and evaluates expressions from the given source file, which may be either
17a string or an input port. Each expression read is passed to {{EVALPROC}}
18(which defaults to {{eval}}). On platforms that support it (currently BSD,
19Haiku, MacOS X, Linux, Solaris, and Windows), {{load}} can be used to load
20compiled programs:
21
22 % cat x.scm
23 (define (hello) (print "Hello!"))
24 % csc -s x.scm
25 % csi -q
26 #;1> (load "x.so")
27 ; loading x.so ...
28 #;2> (hello)
29 Hello!
30 #;3>
31
32The second argument to {{load}} is ignored when loading compiled
33code.
34If source code is loaded from a port, then that port is closed after
35all expressions have been read.
36
37A compiled file can only be loaded once. Subsequent attempts to load the
38same file have no effect.
39
40
41==== load-relative
42
43<procedure>(load-relative FILE [EVALPROC])</procedure>
44
45Similar to {{load}}, but loads {{FILE}} relative to the path
46of the currently loaded file.
47
48==== load-noisily
49
50<procedure>(load-noisily FILE #!key EVALUATOR TIME PRINTER)</procedure>
51
52As {{load}} but the result(s) of each evaluated toplevel-expression
53is written to standard output. If {{EVALUATOR}} is given and not {{#f}},
54then each expression is evaluated by calling this argument with the read
55expression as argument. If {{TIME}} is given and not false, then
56the execution time of each expression is shown (as with the {{time}} macro).
57If {{PRINTER}} is given and not false, then each expression is
58printed before evaluation by applying the expression to the value of this
59argument, which should be a one-argument procedure.
60
61See also the [[Parameters#load-verbose|load-verbose]] parameter.
62==== load-library
63
64<procedure>(load-library UNIT [LIBRARYFILE])</procedure>
65
66On platforms that support dynamic loading, {{load-library}} loads
67the compiled library unit {{UNIT}} (which should be a symbol). If the
68string {{LIBRARYFILE}} is given, then the given shared library will
69be loaded and the toplevel code of the contained unit will be executed.
70If no {{LIBRARYFILE}} argument is given, then the following libraries
71are checked for the required unit:
72
73* a file named ''{{<UNIT>.so}}''
74* the files given in the parameter {{dynamic-load-libraries}}
75
76If the unit is not found, an error is signaled. When the library unit
77can be successfully loaded, a feature-identifier named {{UNIT}}
78is registered. If the feature is already registered before loading,
79the {{load-library}} does nothing.
80
81==== set-dynamic-load-mode!
82
83<procedure>(set-dynamic-load-mode! MODELIST)</procedure>
84
85On systems that support dynamic loading of compiled code via the {{dlopen(3)}}
86interface (for example Linux and Solaris), some options can be specified to
87fine-tune the behaviour of the dynamic linker. {{MODE}} should be a list of
88symbols (or a single symbol) taken from the following set:
89
90; {{local}} : If {{local}} is given, then any C/C++ symbols defined in the dynamically loaded file are not available for subsequently loaded files and libraries. Use this if you have linked foreign code into your dynamically loadable file and if you don't want to export them (for example because you want to load another file that defines the same symbols).
91; {{global}} : The default is {{global}}, which means all C/C++ symbols are available to code loaded at a later stage.
92; {{now}} : If {{now}} is specified, all symbols are resolved immediately.
93; {{lazy}} : Unresolved symbols are resolved as code from the file is executed. This is the default.
94
95Note that this procedure does not control the way Scheme variables are handled -
96this facility is mainly of interest when accessing foreign code.
97
98
99=== Read-eval-print loop
100
101==== repl
102
103<procedure>(repl [EVALUATOR])</procedure>
104
105Start a new read-eval-print loop. Sets the {{reset-handler}} so that
106any invocation of {{reset}} restarts the read-eval-print loop. Also
107changes the current exception-handler to display a message, write
108any arguments to the value of {{(current-error-port)}} and reset.
109
110If {{EVALUATOR}} is given, it should be a procedure of one argument that
111is used in place of {{eval}} to evaluate each entered expression.
112
113You can use {{quit}} to terminate the current read-eval-print loop.
114
115
116=== Loading extension libraries
117
118This functionality is only available on platforms that support dynamic
119loading of compiled code. Currently Linux, BSD, Solaris, Windows (with Cygwin) and HP/UX are supported.
120
121==== repository-path
122
123<parameter>repository-path</parameter>
124
125Contains a string naming the path to the extension repository, which defaults to
126either the value of the environment variable {{CHICKEN_REPOSITORY}}
127or the default library path
128(usually {{/usr/local/lib/chicken}} on UNIX systems).
129
130==== extension-information
131
132<procedure>(extension-information ID)</procedure>
133
134If an extension with the name {{ID}} is installed and if it has a setup-information
135list registered in the extension repository, then the info-list is returned. Otherwise
136{{extension-information}} returns {{#f}}.
137
138==== provide
139
140<procedure>(provide ID ...)</procedure>
141
142Registers the extension IDs {{ID ...}} as loaded. This is mainly
143intended to provide aliases for certain extension identifiers.
144
145==== provided?
146
147<procedure>(provided? ID ...)</procedure>
148
149Returns {{#t}} if the extension with the IDs {{ID ...}}
150are currently loaded, or {{#f}} otherwise.
151
152==== require
153
154<procedure>(require ID ...)</procedure>
155
156If the extension library {{ID}} is not already loaded into the
157system, then {{require}} will lookup the location of the shared
158extension library and load it. If {{ID}} names a library-unit of
159the base system, then it is loaded via {{load-library}}. If no
160extension library is available for the given ID, then an attempt is
161made to load the file {{ID.so}} or {{ID.scm}} (in that order)
162from one of the following locations:
163
164* the current include path, which defaults to the pathnames given in {{CHICKEN_INCLUDE_PATH}}.
165* the current directory
166
167{{ID}} should be a string or a symbol.
168
169=== System information
170
171==== chicken-home
172
173<procedure>(chicken-home)</procedure>
174
175Returns a string which represents the installation directory (usually {{/usr/local/share/chicken}} on UNIX-like systems).
176As a last option,
177if the environment variable {{CHICKEN_PREFIX}} is set, then {{chicken-home}} will return
178{{$CHICKEN_PREFIX/share}}.
179
180
181=== Eval
182
183==== eval
184
185<procedure>(eval EXP [ENVIRONMENT])</procedure>
186
187Evaluates {{EXP}} and returns the result of the evaluation. The second argument is optional
188and defaults to the value of {{(interaction-environment)}}.
189
190---
191Previous: [[Unit library]]
192
193Next: [[Unit expand]]
Note: See TracBrowser for help on using the repository browser.