source: project/wiki/man/4/faq @ 30951

Last change on this file since 30951 was 30951, checked in by sjamaan, 6 years ago

Update the online User's Manual for CHICKEN 4.9.0

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