source: project/wiki/man/5/faq @ 35323

Last change on this file since 35323 was 35323, checked in by felix winkelmann, 18 months ago

manual: more links changed, added R5RS page (or should it be R7RS?)

File size: 27.5 KB
Line 
1[[toc:]]
2[[tags:faq manual]]
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 extensible, 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
31Fill a ticket at [[http://bugs.call-cc.org|bugs.call-cc.org]] with
32some hints about the problem, like version/build of the compiler,
33platform, system configuration, code that causes the bug, etc.
34
35
36=== Specific
37
38==== Why are values defined with {{define-foreign-variable}} or {{define-constant}} or {{define-inline}} not seen outside of the containing source file?
39
40Accesses to foreign variables are translated directly into C constructs that access the variable,
41so the Scheme name given to that variable does only exist during compile-time.
42The same goes for constant- and inline-definitions: The name is only there to tell the compiler
43that this reference is to be replaced with the actual value.
44
45==== How does {{cond-expand}} know which features are registered in used units?
46
47Each unit used via {{(declare (uses ...))}} is registered as a feature and
48so a symbol with the unit-name can be tested by {{cond-expand}} during macro-expansion-time.
49Features registered using the {{register-feature!}} procedure are only
50available during run-time of the compiled file. You can use the {{eval-when}} form
51to register features at compile time.
52
53==== Why are constants defined by {{define-constant}} not honoured in {{case}} constructs?
54
55{{case}} expands into a cascaded {{if}} expression, where the first item in each arm
56is treated as a quoted list. So the {{case}} macro can not infer whether
57a symbol is to be treated as a constant-name (defined via {{define-constant}}) or
58a literal symbol.
59
60
61==== How can I enable case sensitive reading/writing in user code?
62
63To enable the {{read}} procedure to read symbols and identifiers case sensitive, you can set the
64parameter {{case-sensitivity}} to {{#t}}.
65
66
67==== Does CHICKEN support native threads?
68
69Native threads are not supported for two reasons. One, the runtime
70system is not reentrant.  Two, concurrency implemented properly would
71require mandatory locking of every object that could be potentially
72shared between two threads. The garbage-collection algorithm would
73then become much more complex and inefficient, since the location of
74every object has to be accessed via a thread synchronization
75protocol. Such a design would make native threads in CHICKEN
76essentially equivalent to Unix processes and shared memory.
77
78For a different approach to concurrency, please see the
79[[/egg/mpi|mpi]] or
80[[/egg/concurrent-native-callbacks|concurrent-native-callbacks]] egg.
81
82[[http://www.stylewarning.com/blog/about|Robert Smith]] has put
83[[http://www.stylewarning.com/blog/bounties|a bounty]] on a
84release-quality implementation of native threads.
85
86==== Does CHICKEN support Unicode strings?
87
88The system does not directly support Unicode, but there is an extension for UTF-8 strings: [[/egg/utf8|utf8]].
89
90=== Why are `dynamic-wind' thunks not executed when a thread signals an error?
91
92Here is what Marc Feeley, the author of [[http://srfi.schemers.org/srfi-18|SRFI-18]] has to
93say about this subject:
94
95    >No the default exception handler shouldn't invoke the after
96    > thunks of the current continuation.  That's because the
97    > exception handler doesn't "continue" at the initial
98    > continuation of that thread.  Here are the relevant words of
99    > SRFI 18:
100   
101    >
102    >  Moreover, in this dynamic environment the exception handler
103    >  is bound to the "initial exception handler" which is a unary
104    >  procedure which causes the (then) current thread to store in
105    >  its end-exception field an "uncaught exception" object whose
106    >  "reason" is the argument of the handler, abandon all mutexes
107    >  it owns, and finally terminate.
108    >
109   
110    >The rationale is that, when an uncaught exception occurs in a
111    >thread the thread is in bad shape and things have gone
112    >sufficiently wrong that there is no universally acceptable way to
113    >continue execution.  Executing after thunks could require a
114    >whole lot of processing that the thread is not in a shape to do.
115    >So the safe thing is to terminate the thread.  If the programmer
116    >knows how to recover from an exception, then he can capture the
117    >continuation early on, and install an exception handler which
118    >invokes the continuation.  When the continuation is invoked the
119    >after thunks will execute.
120
121
122=== Platform specific
123
124==== How do I generate a DLL under MS Windows (tm) ?
125
126Use {{csc}} in combination with the {{-dll}} option:
127
128{{C:\> csc foo.scm -dll}}
129
130==== How do I generate a GUI application under Windows(tm)?
131
132Invoke {{csc}} with the {{-gui}} option.  In GUI-mode, the runtime
133system displays error messages in a message box and does some
134rudimentary command-line parsing.
135
136==== Compiling very large files under Windows with the Microsoft C compiler fails with a message indicating insufficient heap space.
137
138It seems that the Microsoft C compiler can only handle files up to a certain size, and it doesn't utilize virtual memory as
139well as the GNU C compiler, for example. Try closing running applications. If that fails, try to break up the Scheme code
140into several library units.
141
142==== When I run {{csi}} inside an emacs buffer under Windows, nothing happens.
143
144Invoke {{csi}} with the {{-:c}} runtime option. Under Windows the interpreter thinks it
145is not running under control of a terminal and doesn't print the prompt and does not flush the output stream properly.
146
147==== On Windows, {{csc.exe}} seems to be doing something else entirely.
148
149The Windows development tools include a C# compiler with the same name. Either invoke {{csc.exe}} with a full
150pathname, or put the directory where you installed CHICKEN in front of the MS development tool path in the {{PATH}}
151environment variable.
152
153==== On Windows source and/or output filenames with embedded whitespace are not found.
154
155There is no current workaround. Do not use filenames with embedded whitespace for code. However, command
156names with embedded whitespace will work correctly.
157=== Customization
158
159
160==== How do I run custom startup code before the runtime-system is invoked?
161
162When you invoke the C compiler for your translated Scheme source program, add the C compiler option
163{{-DC_EMBEDDED}}, or pass {{-embedded}} to the {{csc}}
164driver program, so no entry-point function will be generated ({{main()}}).
165When your are finished with your startup processing, invoke:
166
167<enscript highlight=c>
168CHICKEN_main(argc, argv, C_toplevel);
169</enscript>
170
171where {{C_toplevel}} is the entry-point into the compiled Scheme code. You
172should add the following  declarations at the head of your code:
173
174<enscript highlight=c>
175#include "chicken.h"
176extern void C_toplevel(C_word,C_word,C_word) C_noret;
177</enscript>
178
179=== Macros
180
181==== Where is {{define-macro}}?
182
183In CHICKEN 4 and 5, the macro-expansion subsystem is now hygienic where old Lisp-style low-level macros
184are not available anymore. {{define-syntax}} can define hygienic macros using {{syntax-rules}}
185or low-level macros with user-controlled hygienic with ''explicit renaming'' macros. Translating
186old-style macros into ER-macros isn't that hard, see [[Macros]] for more information.
187
188==== Why are low-level macros defined with {{define-syntax}} complaining about unbound variables?
189
190Macro bodies that are defined and used in a compiled source-file are
191evaluated during compilation and so have no access to anything created with {{define}}. Use {{define-for-syntax}} instead.
192
193==== Why isn't {{load}} properly loading my library of macros?
194
195During 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.
196
197=== Warnings and errors
198
199==== Why does my program crash when I use callback functions (from Scheme to C and back to Scheme again)?
200
201There are two reasons why code involving callbacks can crash out of no apparent reason:
202
203# 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.
204
205# 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.
206
207==== Why does the linker complain about a missing function {{_C_..._toplevel}}?
208
209This message indicates that your program uses a library-unit, but that the
210object-file or library was not supplied to the linker. If you have the unit
211{{foo}}, which is contained in {{foo.o}} than you have to supply it to the
212linker like this (assuming a GCC environment):
213
214{{% csc program.scm foo.o -o program}}
215
216==== Why does the linker complain about a missing function {{_C_toplevel}}?
217
218This means you have compiled a library unit as an application. When a unit-declaration (as in {{(declare (unit ...))}})
219is given, then this file has a specially named toplevel entry procedure. Just remove the declaration,
220or compile this file to an object-module and link it to your application code.
221
222==== Why does my program crash when I compile a file with {{-unsafe}} or unsafe declarations?
223
224The compiler option {{-unsafe}} or the declaration {{(declare (unsafe))}} disable
225certain safety-checks to improve performance, so code that would normally
226trigger an error will work unexpectedly or even crash the running application.
227It is advisable to develop and debug a program in safe mode (without unsafe
228declarations) and use this feature only if the application works properly.
229
230==== Why don't toplevel-continuations captured in interpreted code work?
231
232Consider the following piece of code:
233
234<enscript highlight=scheme> 
235(define k (call-with-current-continuation (lambda (k) k)))
236(k k)
237</enscript>
238
239When compiled, this will loop endlessly. But when interpreted, {{(k k)}} will return
240to the read-eval-print loop! This happens because the continuation captured will eventually read the
241next toplevel expression from the standard-input (or an input-file if loading from a file). At the moment
242{{k}} was defined, the next expression was {{(k k)}}. But when {{k}}
243is invoked, the next expression will be whatever follows after {{(k k)}}.
244In other words, invoking a captured continuation will not rewind the file-position of the input source.
245A solution is to wrap the whole code into a {{(begin ...)}} expression, so all toplevel
246expressions will be loaded together.
247
248==== Why does {{define-reader-ctor}} not work in my compiled program?
249
250The following piece of code does not work as expected:
251
252<enscript highlight=scheme>
253 (define-reader-ctor 'integer->char integer->char)
254 (print #,(integer->char 33))
255</enscript>
256
257The problem is that the compiler reads the complete source-file before doing any processing on it,
258so the sharp-comma form is encountered before the reader-ctor is defined. A possible solution is to include
259the file containing the sharp-comma form, like this:
260
261<enscript highlight=scheme>
262 (define-reader-ctor 'integer->char integer->char)
263 (include "other-file")
264</enscript>
265
266<enscript highlight=scheme>
267 ;;; other-file.scm:
268 (print #,(integer->char 33))
269</enscript>
270
271==== Why do built-in units, such as srfi-4 and posix fail to load?
272
273When you try to {{import}} a built-in unit such as {{posix}} (which defines among other things, the {{(chicken posix)}} module), you may get the following error:
274
275<enscript highlight=scheme>
276 #;1> (import (chicken posix))
277 ; loading library posix ...
278 Error: (load-library) unable to load library
279 posix
280 "dlopen(libchicken.dylib, 9): image not found"                ;; on a Mac
281 "libchicken.so: cannot open shared object file: No such file or directory"  ;; Linux
282</enscript>
283
284Another symptom is that {{(require 'posix)}} will silently fail.
285
286This 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:
287
288 export DYLD_LIBRARY_PATH=~/scheme/chicken/lib:$DYLD_LIBRARY_PATH ;; Mac
289 export LD_LIBRARY_PATH=~/scheme/chicken/lib:$LD_LIBRARY_PATH    ;; Linux
290
291==== How can I increase the size of the trace shown when runtime errors are detected?
292
293When a runtime error is detected, CHICKEN will print the last entries from the trace of functions called
294(unless your executable was compiled with the {{-no-trace}} option.
295By default, only 16 entries will be shown.
296To increase this number pass the {{-:aN}} runtime option to your executable.
297
298
299=== Optimizations
300
301==== How can I obtain smaller executables?
302
303XXX still valid?
304
305If you don't need {{eval}} or the stuff in the {{extras}} library unit,
306you can just use the {{library}} unit:
307
308<enscript highlight=scheme>
309        (declare (uses library))
310        (display "Hello, world!\n")
311</enscript>
312
313(Don't forget to compile with the {{-explicit-use}} option)
314Compiled with Visual C++ this generates an executable of around 240 kilobytes.
315It is theoretically possible to compile something without the library, but
316a program would have to implement quite a lot of support code on its own.
317
318==== How can I obtain faster executables?
319
320There are a number of declaration specifiers that should be used to speed up
321compiled files: declaring {{(standard-bindings)}} is mandatory, since this enables
322most optimizations. Even if some standard procedures should be redefined, you can
323list untouched bindings in the declaration.
324Declaring {{(extended-bindings)}} lets the compiler choose faster versions of certain
325internal library functions. This might give another speedup. You can also use the
326the {{usual-integrations}} declaration, which is identical to declaring
327{{standard-bindings}} and {{extended-bindings}}
328(note that {{usual-integrations}} is set by default).
329Declaring {{(block)}} tells the compiler that global procedures are not changed
330outside the current compilation unit, this gives the compiler some more
331opportunities for optimization.
332If no floating point arithmetic is required, then declaring {{(number-type fixnum)}}
333can give a big performance improvement, because the compiler can now inline
334most arithmetic operations.
335Declaring {{(unsafe)}} will switch off most safety checks.
336If threads are not used, you can declare {{(disable-interrupts)}}.
337You should always use maximum optimizations settings for your C compiler.
338Good GCC compiler options on Pentium (and compatible) hardware are:
339{{-Os -fomit-frame-pointer -fno-strict-aliasing}}
340Some programs are very sensitive to the setting of the nursery (the first heap-generation). You
341should experiment with different nursery settings (either by compiling with the {{-nursery}}
342option or by using the {{-:s...}} runtime option).
343
344==== Which non-standard procedures are treated specially when the {{extended-bindings}} or {{usual-integrations}} declaration or compiler option is used?
345
346The following standard bindings are handled specially, depending on optimization options
347and compiler settings:
348
349{{*}}
350{{+}}
351{{-}}
352{{/}}
353{{<=}}
354{{<}}
355{{=}}
356{{>=}}
357{{>}}
358{{abs}}
359{{acos}}
360{{append}}
361{{apply}}
362{{asin}}
363{{assoc}}
364{{assv}}
365{{atan}}
366{{boolean?}}
367{{c...r}}
368{{call-with-current-continuation}}
369{{call-with-values}}
370{{ceiling}}
371{{char->integer}}
372{{char-alphabetic?}}
373{{char-downcase}}
374{{char-lower-case?}}
375{{char-numeric?}}
376{{char-upcae}}
377{{char-upper-case?}}
378{{char-whitespace?}}
379{{char<=?}}
380{{char<?}}
381{{char=?}}
382{{char>=?}}
383{{char>?}}
384{{char?}}
385{{complex?}}
386{{cons}}
387{{cos}}
388{{current-input-port}}
389{{current-output-port}}
390{{eof-object?}}
391{{eq?}}
392{{equal?}}
393{{eqv?}}
394{{even?}}
395{{exact->inexact}}
396{{exact?}}
397{{exp}}
398{{floor}}
399{{for-each}}
400{{gcd}}
401{{inexact->exact}}
402{{inexact?}}
403{{integer->char}}
404{{lcm}}
405{{length}}
406{{list-ref}}
407{{list-tail}}
408{{list?}}
409{{list}}
410{{log}}
411{{make-vector}}
412{{map}}
413{{member}}
414{{memq}}
415{{memv}}
416{{make-polar}}
417{{make-rectangular}}
418{{negative?}}
419{{not}}
420{{null?}}
421{{number->string}}
422{{number?}}
423{{odd?}}
424{{pair?}}
425{{positive?}}
426{{procedure?}}
427{{quotient}}
428{{rational?}}
429{{read-string}}
430{{real?}}
431{{remainder}}
432{{reverse}}
433{{round}}
434{{set-car!}}
435{{set-cdr!}}
436{{sin}}
437{{sqrt}}
438{{string->number}}
439{{string-append}}
440{{string-ci=?}}
441{{string-length}}
442{{string-ref}}
443{{string-set!}}
444{{string=?}}
445{{string?}}
446{{string}}
447{{substring}}
448{{symbol?}}
449{{tan}}
450{{truncate}}
451{{values}}
452{{vector-length}}
453{{vector-ref}}
454{{vector-set!}}
455{{vector?}}
456{{vector}}
457{{write-char}}
458{{zero?}}
459
460The following extended bindings are handled specially:
461
462{{add1}}
463{{any?}}
464{{arithmetic-shift}}
465{{atom?}}
466{{bignum?}}
467{{bit->boolean}}
468{{bitwise-and}}
469{{bitwise-ior}}
470{{bitwise-not}}
471{{bitwise-xor}}
472{{blob-size}}
473{{block-ref}}
474{{block-set!}}
475{{call/cc}}
476{{call-with-input-file}}
477{{call-with-output-file}}
478{{current-error-port}}
479{{current-thread}}
480{{error}}
481{{f32vector->blob/shared}}
482{{f32vector-length}}
483{{f32vector-ref}}
484{{f64vector->blob/shared}}
485{{f64vector-length}}
486{{f64vector-ref}}
487{{finite?}}
488{{fixnum?}}
489{{flonum?}}
490{{flush-output}}
491{{foldl}}
492{{foldr}}
493{{format}}
494{{fp*}}
495{{fp+}}
496{{fp-}}
497{{fp/}}
498{{fp<=}}
499{{fp<}}
500{{fp=}}
501{{fp>=}}
502{{fp>}}
503{{fpabs}}
504{{fpacos}}
505{{fpasin}}
506{{fpatan2}}
507{{fpatan}}
508{{fpceiling}}
509{{fpcos}}
510{{fpexpt}}
511{{fpexp}}
512{{fpfloor}}
513{{fpinteger?}}
514{{fplog}}
515{{fpmax}}
516{{fpmin}}
517{{fpneg}}
518{{fprintf}}
519{{fpround}}
520{{fpsin}}
521{{fpsqrt}}
522{{fptan}}
523{{fptruncate}}
524{{fx*?}}
525{{fx*}}
526{{fx+?}}
527{{fx+}}
528{{fx-?}}
529{{fx-}}
530{{fx/?}}
531{{fx/}}
532{{fx=}}
533{{fx>=}}
534{{fx>}}
535{{fxand}}
536{{fxeven?}}
537{{fxior}}
538{{fxmax}}
539{{fxmin}}
540{{fxmod}}
541{{fxneg}}
542{{fxnot}}
543{{fxodd?}}
544{{fxrem}}
545{{fxshl}}
546{{fxshr}}
547{{fxxor}}
548{{identity}}
549{{infinite?}}
550{{list->string}}
551{{list->vector}}
552{{locative->object}}
553{{locative-ref}}
554{{locative-set!}}
555{{locative?}}
556{{make-record-instance}}
557{{nan?}}
558{{number-of-slots}}
559{{o}}
560{{pointer+}}
561{{pointer->object}}
562{{pointer-f32-ref}}
563{{pointer-f32-set!}}
564{{pointer-f64-ref}}
565{{pointer-f64-set!}}
566{{pointer-s16-ref}}
567{{pointer-s16-set!}}
568{{pointer-s32-ref}}
569{{pointer-s32-set!}}
570{{pointer-s8-ref}}
571{{pointer-s8-set!}}
572{{pointer-u16-ref}}
573{{pointer-u16-set!}}
574{{pointer-u32-ref}}
575{{pointer-u32-set!}}
576{{pointer-u8-ref}}
577{{pointer-u8-set!}}
578{{pointer=?}}
579{{print*}}
580{{printf}}
581{{print}}
582{{s16vector->blob/shared}}
583{{s16vector-length}}
584{{s16vector-ref}}
585{{s16vector-set!}}
586{{s32vector->blob/shared}}
587{{s32vector-length}}
588{{s32vector-ref}}
589{{s32vector-set!}}
590{{s64vector->blob/shared}}
591{{s64vector-length}}
592{{s64vector-ref}}
593{{s64vector-set!}}
594{{s8vector->blob/shared}}
595{{s8vector-length}}
596{{s8vector-ref}}
597{{s8vector-set!}}
598{{signum}}
599{{sprintf}}
600{{string-append}}
601{{string->list}}
602{{sub1}}
603{{substring}}
604{{substring-ci=?}}
605{{substring-index-ci}}
606{{substring-index}}
607{{substring=?}}
608{{u16vector->blob/shared}}
609{{u16vector-length}}
610{{u16vector-ref}}
611{{u16vector-set!}}
612{{u32vector->blob/shared}}
613{{u32vector-length}}
614{{u32vector-ref}}
615{{u32vector-set!}}
616{{u64vector->blob/shared}}
617{{u64vector-length}}
618{{u64vector-ref}}
619{{u64vector-set!}}
620{{u8vector->blob/shared}}
621{{u8vector-length}}
622{{u8vector-ref}}
623{{u8vector-set!}}
624{{vector->list}}
625
626==== What's the difference betweem "block" and "local" mode?
627
628In {{block}} mode, the compiler assumes that definitions in the current file
629are not visible from outside of the current compilation unit, so unused
630definitions can be removed and calls can be inlined. In {{local}} mode,
631definitions are not hidden, but the compiler assumes that they are
632not modified from other compilation units (or code evaluated at runtime),
633and thus allows inlining of them.
634
635==== Can I load compiled code at runtime?
636
637Yes. You can load compiled at code at runtime with {{load}} just as
638well as you can load Scheme source code.  Compiled code will, of
639course, run faster.
640
641To do this, pass to {{load}} a path for a shared object.  Use a form
642such as {{(load "foo.so")}} and run {{csc -shared foo.scm}} to produce
643{{foo.so}} from {{foo.scm}} (at which point {{foo.scm}} will no longer
644be required).
645
646If you have compiled code that contains a {{module}} definition, then
647executing the code will "register" the module to allow importing the
648bindings provided by the module into a running Scheme process.
649The information required to use a module is in this case embedded in
650the compiled code. Compiling another program that uses this (compiled)
651module is more difficult: the used module will not necessarily be loaded
652into the compiler, so the registration will not be executed. In this
653case the information about what bindings the compiled module exports
654must be separated from the actual code that executes at runtime.
655To make this possible, compiling a module can be done in such a
656manner that an "import library" is created. This is a file that
657contains the binding information of the module and we can use it
658to compile a file that refers to that module. An example can perhaps
659make this clearer:
660
661  ;; my-module.scm
662 
663  (module my-module (...) ...)
664
665  ;; use-my-module.scm
666
667  (import my-module)
668  ...
669
670Compile the module and generate an import library for the "my-module" module:
671
672  % csc -s my-module.scm -emit-import-library my-module
673
674Compile the program that uses the module:
675
676  % csc use-my-module.scm
677
678==== Why is my program which uses regular expressions so slow?
679
680The regular expression engine has recently been replaced by [[/users/alex shinn|alex shinn]]'s excellent
681{{irregex}} library, which is fully implemented in Scheme. Precompiling regular
682expressions to internal forms is somewhat slower than with the old PCRE-based
683regex engine. It is advisable to use {{irregex}} to precompile regular expressions
684outside of time-critical loops and use them where performance matters.
685
686
687=== Garbage collection
688
689==== Why does a loop that doesn't {{cons}} still trigger garbage collections?
690
691Under CHICKEN's implementation policy, tail recursion is achieved simply by avoiding
692returns from function calls. Since the programs are CPS converted, a continuous
693sequence of nested procedure calls is performed. At some stage the stack-space has
694to run out and the current procedure and its parameters (including the current
695continuation) are stored somewhere in the runtime system. Now a minor garbage collection
696occurs and rescues all live
697data from the stack (the first heap generation) and moves it into the the second heap
698generation. Then the stack is cleared (using
699a {{longjmp}}) and execution can continue from the saved state.
700With this method arbitrary recursion (in tail- or non-tail position) can happen,
701provided the application doesn't run out of heap-space.
702(The difference between a tail- and a non-tail call is that the tail-call has no
703live data after it invokes its continuation - and so the amount of heap-space needed stays constant)
704
705==== Why do finalizers not seem to work in simple cases in the interpeter?
706
707Consider the following interaction in CSI:
708
709 #;1> (define x '(1 2 3))
710 #;2> (define (yammer x) (print x " is dead"))
711 #;3> (set-finalizer! x yammer)
712 (1 2 3)
713 #;4> (gc #t)
714 157812
715 #;5> (define x #f)
716 #;6> (gc #t)
717 157812
718 #;7>
719
720While you might expect objects to be reclaimed and "''(1 2 3) is dead''" printed, it won't happen:
721the literal list gets held in the interpreter history, because it is the
722result value of the set-finalizer! call.
723Running this in a normal program will work fine.
724
725When testing finalizers from the interpreter, you might want to define a trivial macro such as
726
727 (define-syntax v
728   (syntax-rules ()
729     ((_ x) (begin (print x) (void)))))
730
731and wrap calls to {{set-finalizer!}} in it.
732
733=== Interpreter
734
735==== Does CSI support history and autocompletion?
736
737CSI doesn't support it natively but it can be activated with one of the
738[[/egg/readline|readline]], [[/egg/linenoise|linenoise]] or
739[[/egg/parley|parley]] eggs. Out of these three, the parley egg is
740recommended. After installing parley, add the following to your
741{{~/.csirc}} or equivalent file:
742
743<enscript highlight=scheme>
744(import parley)
745(let ((old (current-input-port)))
746  (current-input-port (make-parley-port old)))
747</enscript>
748
749Users 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.
750
751==== Does code loaded with {{load}} run compiled or interpreted?
752
753If you compile a file with a call to {{load}}, the code will be loaded at
754runtime and, if the file loaded is a Scheme source code file
755(instead of a shared object), it will be
756interpreted (even if the caller program is compiled).
757
758==== How do I use extended (non-standard) syntax in evaluated code at run-time?
759
760Normally, only standard Scheme syntax is available to the evaluator. To
761use the extensions provided in the CHICKEN compiler and interpreter,
762add:
763
764<enscript highlight=scheme>
765(require-library chicken-syntax)
766</enscript>
767
768=== Extensions
769
770==== How can I install CHICKEN eggs to a non-default location?
771
772You can just set the {{CHICKEN_INSTALL_REPOSITORY}} and {{CHICKEN_REPOSITORY_PATH}}
773environment variables.
774They should contain the path where you want eggs to be installed:
775
776 $ export CHICKEN_INSTALL_REPOSITORY=~/eggs/lib/chicken/5
777 $ export CHICKEN_REPOSITORY_PATH=~/eggs/lib/chicken/5
778 $ chicken-install -init ~/eggs/lib/chicken/5
779 $ chicken-install -p ~/eggs/ extensionname
780
781In order to make programs (including csi) see these eggs, you should set {{CHICKEN_REPOSITORY_PATH}} when you run them. See the [[Extensions#Changing repository location|Extensions/Changing repository location]] section of the manual for more information on that.
782
783Alternatively, you can call the {{repository-path}} Scheme procedure before loading the eggs, as in:
784
785<enscript highlight=scheme>
786(repository-path "/home/azul/eggs")
787(import format-modular)
788</enscript>
789
790Note, 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.
791
792The repository needs to be initialized before use. See the documentation for the {{-init}} option
793to {{chicken-install}}, in [[Extensions]].
794
795==== Can I install chicken eggs as a non-root user?
796
797Yes, just install them in a directory you can write to by using {{CHICKEN_INSTALL_REPOSITORY}} (see above).
798
799==== Why does downloading an extension via {{chicken-install}} fail on Windows Vista?
800
801Possibly the Windows Firewall is active, which prevents {{chicken-install}} from opening a TCP
802connection to the egg repository. Try disabling the firewall temporarily.
803
804---
805Previous: [[Bugs and limitations]]
806
807Next: [[Acknowledgements]]
Note: See TracBrowser for help on using the repository browser.