source: project/chicken/branches/prerelease/manual/faq @ 9381

Last change on this file since 9381 was 9381, checked in by Ivan Raikov, 12 years ago

Merged trunk into prerelease

File size: 26.7 KB
Line 
1[[toc:]]
2[[tags:faq]]
3
4== FAQ
5
6This is the list of Frequently Asked Questions about Chicken Scheme.
7If you have a question not answered here, feel free to post to the chicken-users mailing list;
8if you consider your question general enough, feel free to add it to this list.
9
10=== General
11
12==== Why yet another Scheme implementation?
13
14Since Scheme is a relatively simple language, a large number of implementations exist and
15each has its specific advantages and disadvantages. Some are fast, some provide a rich
16programming environment. Some are free, others are tailored to specific domains, and so on. The reasons
17for the existence of CHICKEN are:
18
19* CHICKEN is portable because it generates C code that runs on a large number of platforms.
20
21* CHICKEN is extendable, since its code generation scheme and runtime system/garbage collector fits neatly into a C environment.
22
23* CHICKEN is free and can be freely distributed, including its source code.
24
25* CHICKEN offers better performance than nearly all interpreter based implementations, but still provides full Scheme semantics.
26
27* As far as we know, CHICKEN is the first implementation of Scheme that uses Henry Baker's [[http://home.pipeline.com/~hbaker1/CheneyMTA.html|Cheney on the M.T.A]] concept.
28
29==== What should I do if I find a bug?
30
31Send e-mail to chicken-janitors@nongnu.org (preferably using the {{chicken-bug(1)}} tool)
32with some hints about the problem, like
33version/build of the compiler, platform, system configuration, code that
34causes the bug, etc.
35
36==== Why are values defined with {{define-foreign-variable}} or {{define-constant}} or {{define-inline}} not seen outside of the containing source file?
37
38Accesses to foreign variables are translated directly into C constructs that access the variable,
39so the Scheme name given to that variable does only exist during compile-time.
40The same goes for constant- and inline-definitions: The name is only there to tell the compiler
41that this reference is to be replaced with the actual value.
42
43==== How does {{cond-expand}} know which features are registered in used units?
44
45Each unit used via {{(declare (uses ...))}} is registered as a feature and
46so a symbol with the unit-name can be tested by {{cond-expand}} during macro-expansion-time.
47Features registered using the {{register-feature!}} procedure are only
48available during run-time of the compiled file. You can use the {{eval-when}} form
49to register features at compile time.
50
51==== Why are constants defined by {{define-constant}} not honoured in {{case}} constructs?
52
53{{case}} expands into a cascaded {{if}} expression, where the first item in each arm
54is treated as a quoted list. So the {{case}} macro can not infer wether
55a symbol is to be treated as a constant-name (defined via {{define-constant}}) or
56a literal symbol.
57
58
59==== How can I enable case sensitive reading/writing in user code?
60
61To enable the {{read}} procedure to read symbols and identifiers case sensitive, you can set the
62parameter {{case-sensitivity}} to {{#t}}.
63
64
65==== How can I change {{match-error-control}} during compilation?
66
67Use {{eval-when}}, like this:
68
69<enscript highlight=scheme>
70(eval-when (compile)
71(match-error-control #:unspecified) )
72</enscript>
73
74
75==== Why doesn't CHICKEN support the full numeric tower by default?
76
77The short answer:
78
79<enscript highlight=scheme>
80% chicken-setup numbers
81% csi -q
82#;1> (use numbers)
83</enscript>
84
85The long answer:
86
87There are a number of reasons for this:
88
89- For most applications of Scheme fixnums (exact word-sized integers) and flonums (64-bit floating-point
90numbers) are more than sufficient;
91
92- Interfacing to C is simpler;
93
94- Dispatching of arithmetic operations is more efficient.
95
96There is an extension based on the GNU Multiprecision Package that implements most of the full
97numeric tower, see [[numbers]].
98
99
100==== How can I specialize a generic function method to match instances of every class?
101
102Specializing a method on {{<object>}} doesn't work on primitive data objects like
103numbers, strings, etc. so for example
104
105<enscript highlight=scheme>
106(define-method (foo (x <my-class>)) ...)
107(define-method (foo (x <object>)) ...)
108(foo 123)
109</enscript>
110
111will signal an error, because to applicable method can be found. To specialize a method for primitive
112objects, use {{<top>}}:
113
114<enscript highlight=scheme>
115(define-method (foo (x <top>)) ...)
116</enscript>
117
118
119==== Does CHICKEN support native threads?
120
121Currently native threads are not supported. The runtime system is not reentrant, and the garbage-collection
122algorithm would be made much more complicated, since the location of every object (whether it is allocated
123on the stack or on the heap or completely outside the GC-able data space) has to be checked - this would
124be rather complex and inefficient in a situation where multiple threads are involved.
125
126
127==== Does CHICKEN support Unicode strings?
128
129Yes, as an extension.
130
131By default all string and character functions operate bytewise, so that characters with an iteger value greater than 255 don't make much sense and multibyte UTF-8 characters are seen and manipulated as separate bytes, analogous to what a C program would see.
132
133You can enable UTF-8 support by placing the following two lines at the beginning of your source file (or in your ~/.csirc for interactive sessions) before any other code, including other use directives:
134
135<enscript highlight=scheme>
136(use iset syntax-case utf8)
137(import utf8)
138</enscript>
139
140This will replace all builtin string operators with UTF-8-aware versions, that will treat strings as sequences of multibyte UTF-8 characters, thus enabling you to represent and manipulate Unicode characters while remaining compatible with most C libraries and system interfaces.
141
142Most eggs should work correctly in utf8 mode, including the regex extension, but you still have the option of working around incompatibilities of specific eggs by loading them before the (import utf8) directive. Keep in mind that some operations, such as string-length, are much more expensive in utf8 (multibyte) mode, and should be used with care. See the [[http://www.call-with-current-continuation.org/eggs/utf8.html|utf8 egg documentation]] for details.
143
144
145==== Why do I get an "Error: invalid syntax: ..." using 'match' and 'syntax-case'?
146
147The built-in 'match' macro is incompatible with 'syntax-case'. Use the  [[http://www.call-with-current-continuation.org/eggs/matchable.html|matchable egg]] instead.
148
149
150=== Platform specific
151
152==== How do I generate a DLL under MS Windows (tm) ?
153
154Use {{csc}} in combination with the {{-dll}} option:
155
156{{C:\> csc foo.scm -dll}}
157
158==== How do I generate a GUI application under Windows(tm)?
159
160Invoke {{csc}} with the {{-windows}} option. Or pass the {{-DC_WINDOWS_GUI}}
161option to the C compiler and link with the GUI version of the runtime system (that's {{libchicken-gui[-static].lib}}.
162The GUI runtime displays error messages in a message box and does some rudimentary command-line
163parsing.
164
165==== Compiling very large files under Windows with the Microsoft C compiler fails with a message indicating insufficient heap space.
166
167It seems that the Microsoft C compiler can only handle files up to a certain size, and it doesn't utilize virtual memory as
168well as the GNU C compiler, for example. Try closing running applications. If that fails, try to break up the Scheme code
169into several library units.
170
171==== When I run {{csi}} inside an emacs buffer under Windows, nothing happens.
172
173Invoke {{csi}} with the {{-:c}} runtime option. Under Windows the interpreter thinks it
174is not running under control of a terminal and doesn't print the prompt and does not flush the output stream properly.
175
176==== I load compiled code dynamically in a Windows GUI application and it crashes.
177
178Code compiled into a DLL to be loaded dynamically must be linked with the same runtime system as the loading
179application. That means that all dynamically loaded entities (including extensions built and installed with
180{{chicken-setup}}) must be compiled with the {{-windows}} {{csc}} option.
181
182==== On Windows, {{csc.exe}} seems to be doing something wrong.
183
184The Windows development tools include a C# compiler with the same name. Either invoke {{csc.exe}} with a full
185pathname, or put the directory where you installed CHICKEN in front of the MS development tool path in the {{PATH}}
186environment variable.
187
188==== On Windows source and/or output filenames with embedded whitespace are not found.
189
190There is no current workaround. Do not use filenames with embedded whitespace for code. However, command
191names with embedded whitespace will work correctly.
192=== Customization
193
194
195==== How do I run custom startup code before the runtime-system is invoked?
196
197When you invoke the C compiler for your translated Scheme source program, add the C compiler option
198{{-DC_EMBEDDED}}, or pass {{-embedded}} to the {{csc}}
199driver program, so no entry-point function will be generated ({{main()}}).
200When your are finished with your startup processing, invoke:
201
202<enscript highlight=c>
203CHICKEN_main(argc, argv, C_toplevel);
204</enscript>
205
206where {{C_toplevel}} is the entry-point into the compiled Scheme code. You
207should add the following  declarations at the head of your code:
208
209<enscript highlight=c>
210#include "chicken.h"
211extern void C_toplevel(C_word,C_word,C_word) C_noret;
212</enscript>
213
214==== How can I add compiled user passes?
215
216To add a compiled user pass instead of an interpreted one, create a library unit and recompile
217the main unit of the compiler (in the file {{chicken.scm}}) with an additional {{uses}}
218declaration. Then link all compiler modules and your (compiled) extension to create a new version of
219the compiler, like this (assuming all sources are in the
220current directory):
221
222<enscript highlight=scheme>
223% cat userpass.scm
224;;;; userpass.scm - My very own compiler pass
225
226(declare (unit userpass))
227
228;; Perhaps more user passes/extensions are added:
229(let ([old (user-pass)])
230(user-pass
231(lambda (x)
232(let ([x2 (do-something-with x)])
233          (if old
234              (old x2)
235              x2) ) ) ) )
236</enscript>
237
238 % csc -c -x userpass.scm
239 % csc chicken.scm -c -o chicken-extended.o -uses userpass
240 % gcc chicken-extended.o support.o easyffi.o compiler.o optimizer.o batch-driver.o c-platform.o \
241 c-backend.o userpass.o `csc -ldflags -libs` -o chicken-extended
242
243On platforms that support it (Linux ELF, Solaris, Windows + VC++), compiled code can be loaded via {{-extend}}
244just like source files (see {{load}} in the User's Manual).
245
246
247=== Compiled macros
248
249==== Why is {{define-macro}} complaining about unbound variables?
250
251Macro bodies that are defined and used in a compiled source-file are
252evaluated during compilation and so have no access to anything created with {{define}}. Use {{define-for-syntax}} instead.
253
254==== Why isn't {{load}} properly loading my library of macros?
255
256During compile-time, macros are only available in the source file in which they are defined. Files included via {{include}} are considered part of the containing file.
257
258==== Why is {{include}} unable to load my hygienic macros?
259
260It is not sufficient for the included file to require the {{syntax-case}} extension. Call {{(require-extension syntax-case)}} ''before'' calling {{include}}.
261
262==== Why are macros not visible outside of the compilation unit in which they are defined?
263
264Macros are defined during compile time, so when a file has been compiled, the definitions are gone. An exception
265to this rule are macros defined with {{define-macro}}, which are also visible at run-time, i.e.
266in {{eval}}. To use macros defined in other files, use the {{include}} special
267form.
268
269=== Warnings and errors
270
271==== Why does my program crash when I use callback functions (from Scheme to C and back to Scheme again)?
272
273There are two reasons why code involving callbacks can crash out of no apparent reason:
274
275# It is important to use {{foreign-safe-lambda/foreign-safe-lambda*}} for the C code that is to call back into Scheme. If this is not done than sooner or later the available stack space will be exhausted.
276
277# If the C code uses a large amount of stack storage, or if Scheme-to-C-to-Scheme calls are nested deeply, then the available nursery space on the stack will run low. To avoid this it might be advisable to run the compiled code with a larger nursery setting, i.e. run the code with {{-:s...}} and a larger value than the default (for example {{-:s300k}}), or use the {{-nursery}} compiler option.  Note that this can decrease runtime performance on some platforms.
278
279==== Why does the linker complain about a missing function {{_C_..._toplevel}}?
280
281This message indicates that your program uses a library-unit, but that the
282object-file or library was not supplied to the linker. If you have the unit
283{{foo}}, which is contained in {{foo.o}} than you have to supply it to the
284linker like this (assuming a GCC environment):
285
286{{% csc program.scm foo.o -o program}}
287
288==== Why does the linker complain about a missing function {{_C_toplevel}}?
289
290This means you have compiled a library unit as an application. When a unit-declaration (as in {{(declare (unit ...))}})
291is given, then this file has a specially named toplevel entry procedure. Just remove the declaration,
292or compile this file to an object-module and link it to your application code.
293
294==== Why does my program crash when I compile a file with {{-unsafe}} or unsafe declarations?
295
296The compiler option {{-unsafe}} or the declaration {{(declare (unsafe))}} disable
297certain safety-checks to improve performance, so code that would normally
298trigger an error will work unexpectedly or even crash the running application.
299It is advisable to develop and debug a program in safe mode (without unsafe
300declarations) and use this feature only if the application works properly.
301
302==== Why do I get a warning when I define a global variable named {{match}}?
303
304Even when the {{match}} unit is not used, the macros from that package are visible in the compiler.
305The reason for this is that macros can not be accessed from library units (only when explicitly evaluated in running
306code). To speed up macro-expansion time, the compiler and the interpreter both already provide the compiled
307{{match-...}} macro definitions. Macros shadowed lexically are no problem, but global definitions
308of variables named identically to (global) macros are useless - the macro definition shadows the global
309variable.
310
311This problem can be solved using a different name or undefining the macro, like this:
312
313<enscript highlight=scheme>
314(eval-when (compile eval) (undefine-macro! 'match))
315</enscript>
316==== Why don't toplevel-continuations captured in interpreted code work?
317
318Consider the following piece of code:
319
320<enscript highlight=scheme> 
321(define k (call-with-current-continuation (lambda (k) k)))
322(k k)
323</enscript>
324
325When compiled, this will loop endlessly. But when interpreted, {{(k k)}} will return
326to the read-eval-print loop! This happens because the continuation captured will eventually read the
327next toplevel expression from the standard-input (or an input-file if loading from a file). At the moment
328{{k}} was defined, the next expression was {{(k k)}}. But when {{k}}
329is invoked, the next expression will be whatever follows after {{(k k)}}.
330In other words, invoking a captured continuation will not rewind the file-position of the input source.
331A solution is to wrap the whole code into a {{(begin ...)}} expression, so all toplevel
332expressions will be loaded together.
333
334==== Why does {{define-reader-ctor}} not work in my compiled program?
335
336The following piece of code does not work as expected:
337
338<enscript highlight=scheme>
339(eval-when (compile)
340(define-reader-ctor 'integer->char integer->char) )
341(print #,(integer->char 33))
342</enscript>
343
344The problem is that the compiler reads the complete source-file before doing any processing on it,
345so the sharp-comma form is encountered before the reader-ctor is defined. A possible solution is to include
346the file containing the sharp-comma form, like this:
347
348<enscript highlight=scheme>
349(eval-when (compile)
350(define-reader-ctor 'integer->char integer->char) )
351
352(include "other-file")
353</enscript>
354
355<enscript highlight=scheme>
356;;; other-file.scm:
357(print #,(integer->char 33))
358</enscript>
359
360==== Why do built-in units, such as srfi-1, srfi-18, and posix fail to load?
361
362When you try to {{use}} a built-in unit such as {{srfi-18}}, you may get the following error:
363
364<enscript highlight=scheme>
365#;1> (use srfi-18)
366; loading library srfi-18 ...
367Error: (load-library) unable to load library
368srfi-18
369"dlopen(libchicken.dylib, 9): image not found"                ;; on a Mac
370"libchicken.so: cannot open shared object file: No such file or directory"  ;; Linux
371</enscript>
372
373Another symptom is that {{(require 'srfi-18)}} will silently fail.
374
375This typically happens because the Chicken libraries have been installed in a non-standard location, such as your home directory.  The workaround is to explicitly tell the dynamic linker where to look for your libraries:
376
377 export DYLD_LIBRARY_PATH=~/scheme/chicken/lib:$DYLD_LIBRARY_PATH ;; Mac
378 export LD_LIBRARY_PATH=~/scheme/chicken/lib:$LD_LIBRARY_PATH    ;; Linux
379
380==== How can I increase the size of the trace shown when runtime errors are detected?
381
382When a runtime error is detected, Chicken will print the last entries from the trace of functions called
383(unless your executable was compiled with the {{-no-trace}} option.
384By default, only 16 entries will be shown.
385To increase this number pass the {{-:aN}} parameter to your executable.
386
387=== Optimizations
388
389==== How can I obtain smaller executables?
390
391If you don't need {{eval}} or the stuff in the {{extras}} library unit,
392you can just use the {{library}} unit:
393
394<enscript highlight=scheme>
395        (declare (uses library))
396        (display "Hello, world!\n")
397</enscript>
398
399(Don't forget to compile with the {{-explicit-use}} option)
400Compiled with Visual C++ this generates an executable of around 240 kilobytes.
401It is theoretically possible to compile something without the library, but
402a program would have to implement quite a lot of support code on its own.
403
404==== How can I obtain faster executables?
405
406There are a number of declaration specifiers that should be used to speed up
407compiled files: declaring {{(standard-bindings)}} is mandatory, since this enables
408most optimizations. Even if some standard procedures should be redefined, you can
409list untouched bindings in the declaration.
410Declaring {{(extended-bindings)}} lets the compiler choose faster versions of certain
411internal library functions. This might give another speedup. You can also use the
412the {{usual-integrations}} declaration, which is identical to declaring
413{{standard-bindings}} and {{extended-bindings}}
414(note that {{usual-integrations}} is set by default).
415Declaring {{(block)}} tells the compiler that global procedures are not changed
416outside the current compilation unit, this gives the compiler some more
417opportunities for optimization.
418If no floating point arithmetic is required, then declaring {{(number-type fixnum)}}
419can give a big performance improvement, because the compiler can now inline
420most arithmetic operations.
421Declaring {{(unsafe)}} will switch off most safety checks.
422If threads are not used, you can declare {{(disable-interrupts)}}.
423You should always use maximum optimizations settings for your C compiler.
424Good GCC compiler options on Pentium (and compatible) hardware are:
425{{-Os -fomit-frame-pointer -fno-strict-aliasing}}
426Some programs are very sensitive to the setting of the nursery (the first heap-generation). You
427should experiment with different nursery settings (either by compiling with the {{-nursery}}
428option or by using the {{-:s...}} runtime option).
429
430==== Which non-standard procedures are treated specially when the {{extended-bindings}} or {{usual-integrations}} declaration or compiler option is used?
431
432The following standard bindings are handled specially, depending on optimization options
433and compiler settings:
434
435 {{+}} {{*}} {{-}} {{/}} {{quotient}} {{eq?}} {{eqv?}} {{equal?}} {{apply}} {{c...r}} {{values}} {{call-with-values}}
436 {{list-ref}} {{null?}} {{length}} {{not}} {{char?}} {{string?}} {{symbol?}} {{vector?}} {{pair?}} {{procedure?}}
437 {{boolean?}} {{number?}} {{complex?}} {{rational?}} {{real?}} {{exact?}} {{inexact?}} {{list?}} {{eof-object?}}
438 {{string-ref}} {{string-set!}} {{vector-ref}} {{vector-set!}} {{char=?}} {{char<?}} {{char>?}} {{char<=?}} {{char>=?}}
439 {{char-numeric?}} {{char-alphabetic?}} {{char-whitespace?}} {{char-upper-case?}}
440 {{char-lower-case?}} {{char-upcae}} {{char-downcase}} {{list-tail}} {{assv}} {{memv}} {{memq}} {{assoc}}
441 {{member}} {{set-car!}} {{set-cdr!}} {{abs}} {{exp}} {{sin}} {{cos}} {{tan}} {{log}} {{asin}} {{acos}} {{atan}} {{sqrt}}
442 {{zero?}} {{positive?}} {{negative?}} {{vector-length}} {{string-length}} {{char->integer}}
443 {{integer->char}} {{inexact->exact}} {{=}} {{>}} {{<}} {{>=}} {{<=}} {{for-each}} {{map}} {{substring}}
444 {{string-append}} {{gcd}} {{lcm}} {{list}} {{exact->inexact}} {{string->number}} {{number->string}}
445 {{even?}} {{odd?}} {{remainder}} {{floor}} {{ceiling}} {{truncate}} {{round}} {{cons}} {{vector}} {{string}}
446 {{string=?}} {{string-ci=?}} {{make-vector}} {{call-with-current-continuation}}
447 {{write-char}} {{read-string}}
448
449The following extended bindings are handled specially:
450
451{{bitwise-and}} {{bitwise-ior}} {{bitwise-xor}} {{bitwise-not}}
452{{bit-set?}} {{add1}} {{sub1}}
453{{fx+}}
454{{fx-}} {{fx*}} {{fx/}} {{fxmod}}
455{{fx=}} {{fx>}} {{fx>=}} {{fixnum?}} {{fxneg}} {{fxmax}} {{fxmin}}
456{{fxand}} {{fxior}} {{fxxor}} {{fxnot}} {{fxshl}} {{fxshr}}
457{{flonum?}} {{fp+}}
458{{fp-}} {{fp*}} {{fp/}} {{atom?}}
459{{fp=}} {{fp>}} {{fp>=}} {{fpneg}} {{fpmax}} {{fpmin}}
460{{arithmetic-shift}} {{signum}} {{flush-output}} {{thread-specific}} {{thread-specific-set!}}
461{{not-pair?}} {{null-list?}} {{print}} {{print*}} {{u8vector->blob/shared}}
462{{s8vector->blob/shared}} {{u16vector->blob/shared}} {{s16vector->blob/shared}}
463{{u32vector->blob/shared}}
464{{s32vector->blob/shared}} {{f32vector->blob/shared}} {{f64vector->blob/shared}} {{block-ref}}
465{{blob-size}}
466{{u8vector-length}}
467{{s8vector-length}}
468{{u16vector-length}}
469{{s16vector-length}}
470{{u32vector-length}}
471{{s32vector-length}}
472{{f32vector-length}}
473{{f64vector-length}}
474{{u8vector-ref}}
475{{s8vector-ref}}
476{{u16vector-ref}}
477{{s16vector-ref}}
478{{u32vector-ref}}
479{{s32vector-ref}}
480{{f32vector-ref}}
481{{f64vector-ref}}
482{{u8vector-set!}}
483{{s8vector-set!}}
484{{u16vector-set!}}
485{{s16vector-set!}}
486{{u32vector-set!}}
487{{s32vector-set!}}
488{{hash-table-ref}}
489{{block-set!}} {{number-of-slots}}
490{{first}} {{second}} {{third}} {{fourth}} {{null-pointer?}} {{pointer->object}}
491{{make-record-instance}}
492{{locative-ref}} {{locative-set!}} {{locative?}} {{locative->object}} {{identity}}
493{{cpu-time}} {{error}} {{call/cc}} {{any?}}
494{{substring=?}} {{substring-ci=?}} {{substring-index}} {{substring-index-ci}}
495
496==== Can I load compiled code at runtime?
497
498Yes.
499You can load compiled at code at runtime with {{load}} just as
500well as you can load Scheme source code.
501Compiled code will, of course, run faster.
502
503To do this, pass to {{load}} a path for a shared object.
504Use a form such as {{(load "foo.so")}} and run
505{{csc -shared foo.scm}} to produce {{foo.so}} from {{foo.scm}} (at
506which point {{foo.scm}} will no longer be required).
507
508=== Garbage collection
509
510==== Why does a loop that doesn't {{cons}} still trigger garbage collections?
511
512Under CHICKENs implementation policy, tail recursion is achieved simply by avoiding
513to return from a function call. Since the programs are CPS converted, a continuous
514sequence of nested procedure calls is performed. At some stage the stack-space has
515to run out and the current procedure and its parameters (including the current
516continuation) are stored somewhere in the runtime system. Now a minor garbage collection
517occurs and rescues all live
518data from the stack (the first heap generation) and moves it into the the second heap
519generation. Then the stack is cleared (using
520a {{longjmp}}) and execution can continue from the saved state.
521With this method arbitrary recursion (in tail- or non-tail position) can happen,
522provided the application doesn't run out of heap-space.
523(The difference between a tail- and a non-tail call is that the tail-call has no
524live data after it invokes its continuation - and so the amount of heap-space needed stays constant)
525
526==== Why do finalizers not seem to work in simple cases in the interpeter?
527
528Consider the following interaction in CSI:
529
530 #;1> (define x '(1 2 3))
531 #;2> (define (yammer x) (print x " is dead"))
532 #;3> (set-finalizer! x yammer)
533 (1 2 3)
534 #;4> (gc #t)
535 157812
536 #;5> (define x #f)
537 #;6> (gc #t)
538 157812
539 #;7>
540
541While you might expect objects to be reclaimed and "''(1 2 3) is dead''" printed, it won't happen:
542the literal list gets held in the interpreter history, because it is the
543result value of the set-finalizer! call.
544Running this in a normal program will work fine.
545
546When testing finalizers from the interpreter, you might want to define a trivial macro such as
547
548 (define-macro (v x) `(begin (print ,x) (void)))
549
550and wrap calls to {{set-finalizer!}} in it.
551
552=== Interpreter
553
554==== Does CSI support history and autocompletion?
555
556CSI doesn't support it natively but it can be activated with the [[http://www.call-with-current-continuation.org/eggs/readline.html]] egg.
557After installing the egg, add the following to your {{~/.csirc}} or equivalent file:
558
559<enscript highlight=scheme>
560(require-extension readline)
561(current-input-port (make-gnu-readline-port))
562(gnu-history-install-file-manager (string-append (or (getenv "HOME") ".") "/.csi.history"))
563</enscript>
564
565Users of *nix-like systems (including Cygwin), may also want to check out [[http://utopia.knoware.nl/~hlub/rlwrap/|rlwrap]].  This program lets you "wrap" another process (e.g. {{rlwrap csi}}) with the readline library, giving you history, autocompletion, and the ability to set the keystroke set. Vi fans can get vi keystrokes by adding "set editing-mode vi" to their {{.inputrc}} file.
566
567==== Does code loaded with {{load}} run compiled or interpreted?
568
569If you compile a file with a call to {{load}}, the code will be loaded at
570runtime and, if the file loaded is a Scheme source code file
571(instead of a shared object), it will be
572interpreted (even if the caller program is compiled).
573
574=== Extensions
575
576==== How can I install Chicken eggs to a non-default location?
577
578You can just set the {{CHICKEN_REPOSITORY}} environment variable.
579It should contain the path where you want eggs to be installed:
580
581 $ export CHICKEN_REPOSITORY=~/chicken/
582 $ chicken-setup extensionname
583
584In order to make programs (including csi) see these eggs, you should set this variable when you run them.
585Alternatively, you can call the {{repository-path}} Scheme procedure before loading the eggs, as in:
586
587<enscript highlight=scheme>
588(repository-path "/home/azul/chicken")
589(use format-modular)
590</enscript>
591
592Note, however, that using {{repository-path}} as above hard-codes the location of your eggs in your source files.  While this might not be an issue in your case, it might be safe to keep this configuration outside of the source code (that is, specifying it as an environment variable) to make it easier to maintain.
593
594==== Can I install chicken eggs as a non-root user?
595
596Yes, just [[FAQ#Extensions#How can I install Chicken eggs to a non-default location?|install them in a directory you can write]].
597
598----
599
600Previous: [[Bugs and limitations]]
601
602Next: [[Acknowledgements]]
Note: See TracBrowser for help on using the repository browser.