source: project/chicken/branches/hygienic/manual/faq @ 11149

Last change on this file since 11149 was 11149, checked in by felix winkelmann, 12 years ago

merged trunk rev. 11148; started with split up setup api modules

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