source: project/chicken/trunk/manual/faq @ 13659

Last change on this file since 13659 was 13659, checked in by felix winkelmann, 11 years ago

small manual fixes; merged wiki changes (rev. 13647) into manual

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