source: project/chicken/trunk/manual/Unit library @ 10513

Last change on this file since 10513 was 10513, checked in by Ivan Raikov, 11 years ago

Version increased to 3.1.6

File size: 28.9 KB
Line 
1[[tags: manual]]
2[[toc:]]
3
4== Unit library
5
6This unit contains basic Scheme definitions. This unit is used by default,
7unless the program is compiled with the {{-explicit-use}} option.
8
9=== Arithmetic
10
11
12==== add1/sub1
13
14; [procedure] (add1 N)
15; [procedure] (sub1 N)
16
17Adds/subtracts 1 from {{N}}.
18
19==== Binary integer operations
20
21Binary integer operations. {{arithmetic-shift}} shifts the argument {{N1}} by
22{{N2}} bits to the left. If {{N2}} is negative, than {{N1}} is shifted to the
23right. These operations only accept exact integers or inexact integers in word
24range (32 bit signed on 32-bit platforms, or 64 bit signed on 64-bit
25platforms).
26
27; [procedure] (bitwise-and N1 ...)
28; [procedure] (bitwise-ior N1 ...)
29; [procedure] (bitwise-xor N1 ...)
30; [procedure] (bitwise-not N)
31; [procedure] (arithmetic-shift N1 N2)
32
33==== bit-set?
34
35 [procedure] (bit-set? N INDEX)
36
37Returns {{#t}} if the bit at the position {{INDEX}} in the integer {{N}} is
38set, or {{#f}} otherwise. The rightmost/least-significant bit is bit 0.
39
40
41==== fixnum?
42
43 [procedure] (fixnum? X)
44
45Returns {{#t}} if {{X}} is a fixnum, or {{#f}} otherwise.
46
47==== Arithmetic fixnum operations
48
49These procedures do not check their arguments, so non-fixnum parameters will
50result in incorrect results. {{fxneg}} negates its argument.
51
52On division by zero, {{fx/}} and {{fxmod}} signal a condition of kind
53{{(exn arithmetic)}}.
54
55{{fxshl}} and {{fxshr}} perform arithmetic shift left and right,
56respectively.
57
58; [procedure] (fx+ N1 N2)
59; [procedure] (fx- N1 N2)
60; [procedure] (fx* N1 N2)
61; [procedure] (fx/ N1 N2)
62; [procedure] (fxmod N1 N2)
63; [procedure] (fxneg N)
64; [procedure] (fxmin N1 N2)
65; [procedure] (fxmax N1 N2)
66; [procedure] (fx= N1 N2)
67; [procedure] (fx> N1 N2)
68; [procedure] (fx< N1 N2)
69; [procedure] (fx>= N1 N2)
70; [procedure] (fx<= N1 N2)
71; [procedure] (fxand N1 N2)
72; [procedure] (fxior N1 N2)
73; [procedure] (fxxor N1 N2)
74; [procedure] (fxnot N)
75; [procedure] (fxshl N1 N2)
76; [procedure] (fxshr N1 N2)
77
78
79==== Arithmetic floating-point operations
80
81In safe mode, these procedures throw a type error with non-float
82arguments (except {{flonum?}}, which returns {{#f}}). In unsafe mode,
83these procedures do not check their arguments. A non-flonum argument
84in unsafe mode can crash the system.
85
86; [procedure] (flonum? X)
87; [procedure] (fp+ X Y)
88; [procedure] (fp- X Y)
89; [procedure] (fp* X Y)
90; [procedure] (fp/ X Y)
91; [procedure] (fpneg X)
92; [procedure] (fpmin X Y)
93; [procedure] (fpmax X Y)
94; [procedure] (fp= X Y)
95; [procedure] (fp> X Y)
96; [procedure] (fp< X Y)
97; [procedure] (fp>= X Y)
98; [procedure] (fp<= X Y)
99
100==== signum
101
102 [procedure] (signum N)
103
104Returns {{1}} if {{N}} is positive, {{-1}} if {{N}}
105is negative or {{0}} if {{N}} is zero. {{signum}} is exactness preserving.
106
107
108==== finite?
109
110 [procedure] (finite? N)
111
112Returns {{#f}} if {{N}} is negative or positive infinity, and {{#t}} otherwise.
113
114
115
116=== File Input/Output
117
118==== current-output-port
119
120 [procedure] (current-output-port [PORT])
121
122Returns default output port. If {{PORT}} is given, then that port is selected
123as the new current output port.
124
125Note that the default output port is not buffered. Use [[Unit posix#Setting the
126file buffering mode|{{set-buffering-mode!}}]] if you need a different behavior.
127
128==== current-error-port
129
130 [procedure] (current-error-port [PORT])
131
132Returns default error output port. If {{PORT}} is given, then that port is
133selected as the new current error output port.
134
135Note that the default error output port is not buffered. Use [[Unit
136posix#Setting the file buffering mode|{{set-buffering-mode!}}]] if you need a
137different behavior.
138
139==== flush-output
140
141 [procedure] (flush-output [PORT])
142
143Write buffered output to the given output-port. {{PORT}} defaults
144to the value of {{(current-output-port)}}.
145
146
147==== port-name
148
149 [procedure] (port-name [PORT])
150
151Fetch filename from {{PORT}}. This returns the filename that was used to open
152this file. Returns a special tag string, enclosed into parentheses for
153non-file ports. {{PORT}} defaults to the value of {{(current-input-port)}}.
154
155
156==== port-position
157
158 [procedure] (port-position [PORT])
159
160Returns the current position of {{PORT}} as two values: row and column number.
161If the port does not support such an operation an error is signaled. This
162procedure is currently only available for input ports. {{PORT}} defaults to the
163value of {{(current-input-port)}}.
164
165
166==== set-port-name!
167
168 [procedure] (set-port-name! PORT STRING)
169
170Sets the name of {{PORT}} to {{STRING}}.
171
172
173
174=== Files
175
176==== delete-file
177
178 [procedure] (delete-file STRING)
179
180Deletes the file with the pathname {{STRING}}. If the file does
181not exist, an error is signaled.
182
183
184==== file-exists?
185
186 [procedure] (file-exists? STRING)
187
188Returns {{STRING}} if a file with the given pathname exists, or
189{{#f}} otherwise.
190
191
192==== rename-file
193
194 [procedure] (rename-file OLD NEW)
195
196Renames the file or directory with the pathname {{OLD}} to
197{{NEW}}. If the operation does not succeed, an error is signaled.
198
199
200=== String ports
201
202==== get-output-string
203
204 [procedure] (get-output-string PORT)
205
206Returns accumulated output of a port created with
207{{(open-output-string)}}.
208
209
210==== open-input-string
211
212 [procedure] (open-input-string STRING)
213
214Returns a port for reading from {{STRING}}.
215
216
217==== open-output-string
218
219 [procedure] (open-output-string)
220
221Returns a port for accumulating output in a string.
222
223
224
225
226
227=== Feature identifiers
228
229
230CHICKEN maintains a global list of ''features'' naming functionality available
231in the current system. Additionally the {{cond-expand}} form accesses this
232feature list to infer what features are provided. Predefined features are
233{{chicken}}, and the SRFIs (Scheme Request For Implementation) provided by the
234base system: {{srfi-23, srfi-30, srfi-39}}. If the {{eval}} unit
235is used (the default), the features {{srfi-0, srfi-2, srfi-6, srfi-8, srfi-9}}
236and {{srfi-10}} are defined. When compiling code (during compile-time) the
237feature {{compiling}} is registered. When evaluating code in the interpreter
238(csi), the feature {{csi}} is registered.
239
240
241==== features
242
243 [procedure] (features)
244
245Returns a list of all registered features that will be accepted as valid
246feature-identifiers by {{cond-expand}}.
247
248
249==== feature?
250
251 [procedure] (feature? ID ...)
252
253Returns {{#t}} if all features with the given feature-identifiers {{ID ...}}
254are registered.
255
256
257==== register-feature!
258
259 [procedure] (register-feature! FEATURE ...)
260
261Register one or more features that will be accepted as valid
262feature-identifiers by {{cond-expand}}. {{FEATURE ...}} may
263be a keyword, string or symbol.
264
265
266==== unregister-feature!
267
268 [procedure] (unregister-feature! FEATURE ...)
269
270Unregisters the specified feature-identifiers. {{FEATURE ...}}
271may be a keyword, string or symbol.
272
273
274
275
276
277=== Keywords
278
279Keywords are special symbols prefixed with {{#:}} that evaluate
280to themselves. Procedures can use keywords to accept optional named
281parameters in addition to normal required parameters. Assignment to
282and bindings of keyword symbols is not allowed.
283The parameter {{keyword-style}} and the compiler/interpreter option
284{{-keyword-style}} can be used to allow an additional keyword
285syntax, either compatible to Common LISP, or to DSSSL.
286
287
288
289==== get-keyword
290
291 [procedure] (get-keyword KEYWORD ARGLIST [THUNK])
292
293Returns the argument from {{ARGLIST}} specified under the keyword
294{{KEYWORD}}. If the keyword is not found, then the zero-argument
295procedure {{THUNK}} is invoked and the result value is returned. If
296{{THUNK}} is not given, {{#f}} is returned.
297
298<enscript highlight=scheme>
299(define (increase x . args)
300  (+ x (get-keyword #:amount args (lambda () 1))) )
301(increase 123)                                      ==> 124
302(increase 123 #:amount 10)                          ==> 133
303</enscript>
304
305Note: the {{KEYWORD}} may actually be any kind of object.
306
307
308==== keyword?
309
310 [procedure] (keyword? X)
311
312Returns {{#t}} if {{X}} is a keyword symbol, or {{#f}}
313otherwise.
314
315
316==== keyword->string
317
318 [procedure] (keyword->string KEYWORD)
319
320Transforms {{KEYWORD}} into a string.
321
322
323==== string->keyword
324
325 [procedure] (string->keyword STRING)
326
327Returns a keyword with the name {{STRING}}.
328
329
330
331
332
333=== Exceptions
334
335
336CHICKEN implements the (currently withdrawn)
337[[http://srfi.schemers.org/srfi-12/srfi-12.html|SRFI-12]] exception system. For
338more information, see the
339[[http://srfi.schemers.org/srfi-12/srfi-12.html|SRFI-12]] document.
340
341
342
343==== condition-case
344
345 [syntax] (condition-case EXPRESSION CLAUSE ...)
346
347Evaluates {{EXPRESSION}} and handles any exceptions that are covered by
348{{CLAUSE ...}}, where {{CLAUSE}} should be of the following form:
349
350<enscript highlight=scheme>
351CLAUSE = ([VARIABLE] (KIND ...) BODY ...)
352</enscript>
353
354If provided, {{VARIABLE}} will be bound to the signaled exception
355object. {{BODY ...}} is executed when the exception is a property-
356or composite condition with the kinds given {{KIND ...}} (unevaluated).
357If no clause applies, the exception is re-signaled in the same dynamic
358context as the {{condition-case}} form.
359
360<enscript highlight=scheme>
361(define (check thunk)
362  (condition-case (thunk)
363    [(exn file) (print "file error")]
364    [(exn) (print "other error")]
365    [var () (print "something else")] ) )
366
367(check (lambda () (open-input-file "")))   ; -> "file error"
368(check (lambda () some-unbound-variable))  ; -> "othererror"
369(check (lambda () (signal 99)))            ; -> "something else"
370
371(condition-case some-unbound-variable
372  [(exn file) (print "ignored")] )      ; -> signals error
373
374</enscript>
375
376
377==== breakpoint
378
379 [procedure] (breakpoint [NAME])
380
381Programmatically triggers a breakpoint (similar to the {{,br}} top-level csi
382command).
383
384All error-conditions signaled by the system are of kind {{exn}}.
385The following composite conditions are additionally defined:
386
387<table>
388
389<tr><td> (exn arity)
390
391Signaled when a procedure is called with the wrong number of arguments.
392
393</td></tr><tr><td> (exn type)
394
395Signaled on type-mismatch errors, for example when an argument of the wrong
396type is passed to a built-in procedure.
397
398</td></tr><tr><td> (exn arithmetic)
399
400Signaled on arithmetic errors, like division by zero.
401
402</td></tr><tr><td> (exn i/o)
403
404Signaled on input/output errors.
405
406</td></tr><tr><td> (exn i/o file)
407
408Signaled on file-related errors.
409
410</td></tr><tr><td> (exn i/o net)
411
412Signaled on network errors.
413
414</td></tr><tr><td> (exn bounds)
415
416Signaled on errors caused by accessing non-existent elements of a collection.
417
418</td></tr><tr><td> (exn runtime)
419
420Signaled on low-level runtime-system error-situations.
421
422</td></tr><tr><td> (exn runtime limit)
423
424Signaled when an internal limit is exceeded (like running out of memory).
425
426</td></tr><tr><td> (exn match)
427
428Signaled on errors raised by failed matches (see the section on {{match}}).
429
430</td></tr><tr><td> (exn syntax)
431
432Signaled on syntax errors.
433
434</td></tr><tr><td> (exn breakpoint)
435
436Signaled when a breakpoint is reached.
437
438</td></tr>
439
440</table>
441
442Notes:
443
444* All error-exceptions (of the kind {{exn}}) are non-continuable.
445
446* Error-exceptions of the {{exn}} kind have additional {{arguments}} and
447{{location}} properties that contain the arguments passed to the
448exception-handler and the name of the procedure where the error occurred (if
449available).
450
451* When the {{posix}} unit is available and used, then a user-interrupt
452({{signal/int}}) signals an exception of the kind {{user-interrupt}}.
453
454* the procedure {{condition-property-accessor}} accepts an optional third
455argument. If the condition does not have a value for the desired property and
456if the optional argument is given, no error is signaled and the accessor
457returns the third argument.
458
459* In composite conditions all properties are currently collected in a single
460property-list, so in the case that to conditions have the same named property,
461only one will be visible.
462
463
464
465=== Environment information and system interface
466
467
468
469==== argv
470
471 [procedure] (argv)
472
473Return a list of all supplied command-line arguments. The first item in
474the list is a string containing the name of the executing program. The
475other items are the arguments passed to the application. This list is
476freshly created on every invocation of {{(argv)}}. It depends on
477the host-shell whether arguments are expanded ('globbed') or not.
478
479
480==== exit
481
482 [procedure] (exit [CODE])
483
484Exit the running process and return exit-code, which defaults to 0
485(Invokes {{exit-handler}}).
486
487Note that pending {{dynamic-wind}} thunks are ''not'' invoked when exiting your program in this way.
488==== build-platform
489
490 [procedure] (build-platform)
491
492Returns a symbol specifying the toolset which has been used for
493building the executing system, which is one of the following:
494
495 cygwin
496 mingw32
497 gnu
498 intel
499 unknown
500
501
502==== chicken-version
503
504 [procedure] (chicken-version [FULL])
505
506Returns a string containing the version number of the CHICKEN runtime
507system. If the optional argument {{FULL}} is given and true, then
508a full version string is returned.
509
510
511==== errno
512
513 [procedure] (errno)
514
515Returns the error code of the last system call.
516
517
518==== getenv
519
520 [procedure] (getenv STRING)
521
522Returns the value of the environment variable {{STRING}} or
523{{#f}} if that variable is not defined.
524
525
526
527==== machine-byte-order
528
529 [procedure] (machine-byte-order)
530
531Returns the symbol {{little-endian}} or {{big-endian}}, depending on the
532machine's byte-order.
533
534
535==== machine-type
536
537 [procedure] (machine-type)
538
539Returns a symbol specifying the processor on which this process is
540currently running, which is one of the following:
541
542 alpha
543 mips
544 hppa
545 ultrasparc
546 sparc
547 ppc
548 ppc64
549 ia64
550 x86
551 x86-64
552 unknown
553
554
555==== on-exit
556
557 [procedure] (on-exit THUNK)
558
559Schedules the zero-argument procedures {{THUNK}} to be executed before
560the process exits, either explicitly via {{exit}} or implicitly after execution
561of the last top-level form. Note that finalizers for unreferenced finalized
562data are run before exit procedures.
563
564
565==== software-type
566
567 [procedure] (software-type)
568
569Returns a symbol specifying the operating system on which this process
570is currently running, which is one of the following:
571
572 windows
573 unix
574 macos
575 ecos
576 unknown
577
578
579==== software-version
580
581 [procedure] (software-version)
582
583Returns a symbol specifying the operating system version on which this
584process is currently running, which is one of the following:
585
586 linux
587 freebsd
588 netbsd
589 openbsd
590 macosx
591 hpux
592 solaris
593 sunos
594 unknown
595
596
597
598==== c-runtime
599
600 [procedure] (c-runtime)
601
602Returns a symbol that designates what kind of C runtime library has been linked
603with this version of the Chicken libraries. Possible return values are
604{{static}}, {{dynamic}} or {{unknown}}. On systems not compiled with the
605Microsoft C compiler, {{c-runtime}} always returns {{unknown}}.
606
607
608==== system
609
610 [procedure] (system STRING)
611
612Execute shell command. The functionality offered by this procedure
613depends on the capabilities of the host shell. If the forking of a subprocess
614failed, an exception is raised. Otherwise the return status of the
615subprocess is returned unaltered.
616
617
618
619
620=== Execution time
621
622
623
624==== cpu-time
625
626 [procedure] (cpu-time)
627
628Returns the used CPU time of the current process in milliseconds as
629two values: the time spent in user code, and the time spent in system
630code. On platforms where user and system time can not be differentiated,
631system time will be always be 0.
632
633
634==== current-milliseconds
635
636 [procedure] (current-milliseconds)
637
638Returns the number of milliseconds since process- or machine startup.
639
640
641==== current-seconds
642
643 [procedure] (current-seconds)
644
645Returns the number of seconds since midnight, Jan. 1, 1970.
646
647
648==== current-gc-milliseconds
649
650 [procedure] (current-gc-milliseconds)
651
652Returns the number of milliseconds spent in major garbage collections since
653the last call of {{current-gc-milliseconds}} and returns an exact
654integer.
655
656
657
658=== Interrupts and error-handling
659
660
661
662==== enable-warnings
663
664 [procedure] (enable-warnings [BOOL])
665
666Enables or disables warnings, depending on wether {{BOOL}} is true or false.
667If called with no arguments, this procedure returns {{#t}} if warnings are
668currently enabled, or {{#f}} otherwise. Note that this is not a parameter.
669The current state (whether warnings are enabled or disabled) is global and not
670thread-local.
671
672
673==== error
674
675 [procedure] (error [LOCATION] [STRING] EXP ...)
676
677Prints error message, writes all extra arguments to the
678value of {{(current-error-port)}} and invokes the
679current exception-handler. This conforms to
680[[http://srfi.schemers.org/srfi-23/srfi-23.html|SRFI-23]].
681If {{LOCATION}} is given and a symbol, it specifies the ''location'' (the name
682of the procedure) where the error occurred.
683
684
685
686==== get-call-chain
687
688 [procedure] (get-call-chain [START [THREAD]])
689
690Returns a list with the call history. Backtrace information
691is only generated in code compiled without {{-no-trace}} and evaluated code.
692If the optional argument {{START}} is given, the backtrace starts
693at this offset, i.e. when {{START}} is 1, the next to last trace-entry
694is printed, and so on. If the optional argument {{THREAD}} is given, then
695the call-chain will only be constructed for calls performed by this thread.
696
697
698
699==== print-call-chain
700
701 [procedure] (print-call-chain [PORT [START [THREAD]]])
702
703Prints a backtrace of the procedure call history to {{PORT}},
704which defaults to {{(current-output-port)}}.
705
706
707==== print-error-message
708
709 [procedure] (print-error-message EXN [PORT [STRING]])
710
711Prints an appropriate error message to {{PORT}} (which defaults to the
712value of {{(current-output-port)}} for the object {{EXN}}.
713{{EXN}} may be a condition, a string or any other object.
714If the optional argument {{STRING}} is given, it is printed before the
715error-message. {{STRING}} defaults to {{"Error:"}}.
716
717
718
719==== procedure-information
720
721 [procedure] (procedure-information PROC)
722
723Returns an s-expression with debug information for the procedure {{PROC}}, or
724{{#f}}, if {{PROC}} has no associated debug information.
725
726
727==== reset
728
729 [procedure] (reset)
730
731Reset program (Invokes {{reset-handler}}).
732
733
734==== warning
735
736 [procedure] (warning STRING EXP ...)
737
738Displays a warning message (if warnings are enabled with {{enable-warnings}}) and
739continues execution.
740
741
742==== singlestep
743
744 [procedure] (singlestep THUNK)
745
746Executes the code in the zero-procedure {{THUNK}} in single-stepping mode.
747
748
749
750=== Garbage collection
751
752
753
754==== gc
755
756 [procedure] (gc [FLAG])
757
758Invokes a garbage-collection and returns the number of free bytes in the heap.
759The flag specifies whether a minor ({{#f}}) or major ({{#t}}) GC is to be
760triggered. If no argument is given, {{#t}} is assumed. An explicit {{#t}}
761argument will cause all pending finalizers to be executed.
762
763==== memory-statistics
764
765 [procedure] (memory-statistics)
766
767Performs a major garbage collection and returns a three element vector
768containing the total heap size in bytes, the number of bytes currently
769used and the size of the nursery (the first heap generation). Note
770that the actual heap is actually twice the size given in the heap size,
771because CHICKEN uses a copying semi-space collector.
772
773
774==== set-finalizer!
775
776 [procedure] (set-finalizer! X PROC)
777
778Registers a procedure of one argument {{PROC}}, that will be
779called as soon as the non-immediate data object {{X}} is about to
780be garbage-collected (with that object as its argument). Note that
781the finalizer will '''not''' be called while interrupts are disabled.
782This procedure returns {{X}}.
783
784
785==== set-gc-report!
786
787 [procedure] (set-gc-report! FLAG)
788
789Print statistics after every GC, depending on {{FLAG}}. A value of
790{{#t}} shows statistics after every major GC. A true value different
791from {{#t}} shows statistics after every minor GC. {{#f}}
792switches statistics off.
793
794
795
796
797
798=== Other control structures
799
800
801
802==== promise?
803
804 [procedure] (promise? X)
805
806Returns {{#t}} if {{X}} is a promise returned by {{delay}}, or
807{{#f}} otherwise.
808
809
810
811=== String utilities
812
813
814==== reverse-list->string
815
816 [procedure] (reverse-list->string LIST)
817
818Returns a string with the characters in {{LIST}} in reverse order. This is
819equivalent to {{(list->string (reverse LIST))}}, but much more efficient.
820
821
822
823=== Generating uninterned symbols
824
825==== gensym
826
827 [procedure] (gensym [STRING-OR-SYMBOL])
828
829Returns a newly created uninterned symbol. If an argument is provided,
830the new symbol is prefixed with that argument.
831
832
833==== string->uninterned-symbol
834
835 [procedure] (string->uninterned-symbol STRING)
836
837Returns a newly created, unique symbol with the name {{STRING}}.
838
839
840
841=== Standard Input/Output
842
843==== port?
844
845 [procedure] (port? X)
846
847Returns {{#t}} if {{X}} is a port object or {{#f}}
848otherwise.
849
850
851==== print
852
853 [procedure] (print [EXP1 ...])
854
855Outputs the optional arguments {{EXP1 ...}} using {{display}} and
856writes a newline character to the port that is the value of
857{{(current-output-port)}}. Returns {{(void)}}.
858
859
860==== print*
861
862 [procedure] (print* [EXP1 ...])
863
864Similar to {{print}}, but does not output a terminating newline
865character and performs a {{flush-output}} after writing its arguments.
866
867
868
869
870=== User-defined named characters
871
872==== char-name
873
874 [procedure] (char-name SYMBOL-OR-CHAR [CHAR])
875
876This procedure can be used to inquire about character names or to
877define new ones. With a single argument the behavior is as follows:
878If {{SYMBOL-OR-CHAR}} is a symbol, then {{char-name}} returns
879the character with this name, or {{#f}} if no character is defined
880under this name. If {{SYMBOL-OR-CHAR}} is a character, then the
881name of the character is returned as a symbol, or {{#f}} if the
882character has no associated name.
883
884If the optional argument {{CHAR}} is provided, then
885{{SYMBOL-OR-CHAR}} should be a symbol that will be the new name of
886the given character. If multiple names designate the same character,
887then the {{write}} will use the character name that was defined last.
888
889<enscript highlight=scheme>
890(char-name 'space)                  ==> #\space
891(char-name #\space)                 ==> space
892(char-name 'bell)                   ==> #f
893(char-name (integer->char 7))       ==> #f
894(char-name 'bell (integer->char 7))
895(char-name 'bell)                   ==> #\bell
896(char->integer (char-name 'bell))   ==> 7
897</enscript>
898
899
900
901=== Blobs
902
903"blobs" are collections of unstructured bytes. You can't do much
904with them, but allow conversion to and from SRFI-4 number vectors.
905
906==== make-blob
907
908 [procedure] (make-blob SIZE)
909
910Returns a blob object of {{SIZE}} bytes, aligned on an 8-byte boundary,
911uninitialized.
912
913==== blob?
914
915 [procedure] (blob? X)
916
917Returns {{#t}} if {{X}} is a blob object, or
918{{#f}} otherwise.
919
920==== blob-size
921
922 [procedure] (blob-size BLOB)
923
924Returns the number of bytes in {{BLOB}}.
925
926==== blob->string
927
928 [procedure] (blob->string BLOB)
929
930Returns a string with the contents of {{BLOB}}.
931
932==== string->blob
933
934 [procedure] (string->blob STRING)
935
936Returns a blob with the contents of {{STRING}}.
937
938==== blob=?
939
940 [procedure] (blob=? BLOB1 BLOB2)
941
942Returns {{#t}} if the two argument blobs are of the same
943size and have the same content.
944
945
946
947=== Vectors
948
949==== vector-copy!
950
951 [procedure] (vector-copy! VECTOR1 VECTOR2 [COUNT])
952
953Copies contents of {{VECTOR1}} into {{VECTOR2}}. If the
954argument {{COUNT}} is given, it specifies the maximal number of
955elements to be copied. If not given, the minimum of the lengths of the
956argument vectors is copied.
957
958Exceptions: {{(exn bounds)}}
959
960
961==== vector-resize
962
963 [procedure] (vector-resize VECTOR N [INIT])
964
965Creates and returns a new vector with the contents of {{VECTOR}} and length
966{{N}}. If {{N}} is greater than the original length of {{VECTOR}}, then all
967additional items are initialized to {{INIT}}. If {{INIT}} is not specified, the
968contents are initialized to some unspecified value.
969
970
971
972=== The unspecified value
973
974==== void
975
976 [procedure] (void)
977
978Returns an unspecified value.
979
980
981
982=== Continuations
983
984==== call/cc
985
986 [procedure] (call/cc PROCEDURE)
987
988An alias for {{call-with-current-continuation}}.
989
990
991==== continuation-capture
992
993 [procedure] (continuation-capture PROCEDURE)
994
995Creates a continuation object representing the current continuation and
996tail-calls {{PROCEDURE}} with this continuation as the single argument.
997
998More information about this continuation API can be found in the paper
999[[http://repository.readscheme.org/ftp/papers/sw2001/feeley.pdf]] ''A Better
1000API for first class Continuations'' by Marc Feeley.
1001
1002
1003==== continuation?
1004
1005 [procedure] (continuation? X)
1006
1007Returns {{#t}} if {{X}} is a continuation object, or {{#f}} otherwise. Please
1008note that this applies only to continuations created by the Continuation API,
1009but not by call/cc, i.e.: {{(call-with-current-continuation continuation?)}}
1010returns {{#f}}, whereas {{(continuation-capture continuation?)}} returns
1011{{#t}}.
1012
1013
1014==== continuation-graft
1015
1016 [procedure] (continuation-graft CONT THUNK)
1017
1018Calls the procedure {{THUNK}} with no arguments and the implicit continuation
1019{{CONT}}.
1020
1021
1022==== continuation-return
1023
1024 [procedure] (continuation-return CONT VALUE ...)
1025
1026Returns the value(s) to the continuation {{CONT}}. {{continuation-return}} could
1027be implemented like this:
1028
1029<enscript highlight=scheme>
1030(define (continuation-return k . vals)
1031  (continuation-graft
1032    k
1033    (lambda () (apply values vals)) ) )
1034</enscript>
1035
1036
1037
1038=== Setters
1039
1040SRFI-17 is fully implemented. For more information see:
1041[[http://srfi.schemers.org/srfi-17/srfi-17.html|SRFI-17]].
1042
1043==== setter
1044
1045 [procedure] (setter PROCEDURE)
1046
1047Returns the setter-procedure of {{PROCEDURE}}, or signals an error if
1048{{PROCEDURE}} has no associated setter-procedure.
1049
1050Note that {{(set! (setter PROC) ...)}} for a procedure that has no associated
1051setter procedure yet is a very slow operation (the old procedure is replaced by
1052a modified copy, which involves a garbage collection).
1053
1054
1055==== getter-with-setter
1056
1057 [procedure] (getter-with-setter GETTER SETTER)
1058
1059Returns a copy of the procedure {{GETTER}} with the associated setter procedure
1060{{SETTER}}. Contrary to the SRFI specification, the setter of the returned
1061procedure may be changed.
1062
1063
1064
1065=== Reader extensions
1066
1067==== define-reader-ctor
1068
1069 [procedure] (define-reader-ctor SYMBOL PROC)
1070
1071Define new read-time constructor for {{#,}} read syntax. For further information, see
1072the documentation for [[http://srfi.schemers.org/srfi-10/srfi-10.html|SRFI-10]].
1073
1074
1075==== set-read-syntax!
1076
1077 [procedure] (set-read-syntax! CHAR-OR-SYMBOL PROC)
1078
1079When the reader encounters the non-whitespace character {{CHAR}} while reading
1080an expression from a given port, then the procedure {{PROC}} will be called with
1081that port as its argument. The procedure should return a value that will be returned
1082to the reader:
1083
1084<enscript highlight=scheme>
1085 ; A simple RGB color syntax:
1086
1087 (set-read-syntax! #\%
1088   (lambda (port)
1089     (apply vector
1090       (map (cut string->number <> 16)
1091            (string-chop (read-string 6 port) 2) ) ) ) )
1092
1093 (with-input-from-string "(1 2 %f0f0f0 3)" read)
1094 ; ==> (1 2 #(240 240 240) 3)
1095</enscript>
1096
1097If {{CHAR-OR-SYMBOL}} is a symbol, then a so-called ''read-mark'' handler is defined.
1098In that case the handler procedure will be called when a character-sequence of the
1099form
1100
1101 #!SYMBOL
1102
1103is encountered.
1104
1105You can undo special handling of read-syntax by passing {{#f}} as the second argument
1106(if the syntax was previously defined via {{set-read-syntax!}}).
1107
1108Note that all of CHICKEN's special non-standard read-syntax is handled directly by the reader.
1109To disable built-in read-syntax, define a handler that triggers an error (for example).
1110
1111
1112==== set-sharp-read-syntax!
1113
1114 [procedure] (set-sharp-read-syntax! CHAR-OR-SYMBOL PROC)
1115
1116Similar to {{set-read-syntax!}}, but allows defining new {{#<CHAR> ...}} reader syntax.
1117If the first argument is a symbol, then this procedure is equivalent to {{set-read-syntax!}}.
1118
1119
1120==== set-parameterized-read-syntax!
1121
1122 [procedure] (set-parameterized-read-syntax! CHAR-OR-SYMBOL PROC)
1123
1124Similar to {{set-sharp-read-syntax!}}, but intended for defining reader syntax of the
1125form {{#<NUMBER><CHAR> ...}}. The handler procedure {{PROC}} will be called with two
1126arguments: the input port and the number preceding
1127the dispatching character.
1128If the first argument is a symbol, then this procedure is equivalent to {{set-read-syntax!}}.
1129
1130
1131==== copy-read-table
1132
1133 [procedure] (copy-read-table READ-TABLE)
1134
1135Returns a copy of the given read-table. You can access the currently active read-table
1136with {{(current-read-table)}}.
1137
1138
1139=== Property lists
1140
1141As in other Lisp dialects, CHICKEN supports "property lists" associated with symbols.
1142Properties are accessible via a key that can be any kind of value but which will
1143be compared using {{eq?}}.
1144
1145==== get
1146
1147  [procedure] (get SYMBOL PROPERTY [DEFAULT])
1148
1149Returns the value stored under the key {{PROPERTY}} in the property
1150list of {{SYMBOL}}. If no such property is stored, returns
1151{{DEFAULT}}. The {{DEFAULT}} is optional and defaults to {{#f}}.
1152
1153==== put!
1154
1155  [procedure] (put! SYMBOL PROPERTY VALUE)
1156  [setter] (set! (get SYMBOL PROPERTY) VALUE)
1157
1158Stores {{VALUE}} under the key {{PROPERTY}} in the property list of
1159{{SYMBOL}} replacing any previously stored value.
1160
1161==== remprop!
1162
1163  [procedure] (remprop! SYMBOL PROPERTY)
1164
1165Deletes the first property matching the key {{PROPERTY}} in the property list
1166of {{SYMBOL}}. Returns {{#t}} when a deletion performed, and {{#f}} otherwise.
1167
1168==== symbol-plist
1169
1170  [procedure] (symbol-plist SYMBOL)
1171  [setter] (set! (symbol-plist SYMBOL) LST)
1172
1173Returns the property list of {{SYMBOL}} or sets it.
1174
1175==== get-properties
1176
1177  [procedure] (get-properties SYMBOL PROPERTIES)
1178
1179Searches the property list of {{SYMBOL}} for the first property with a key in
1180the list {{PROPERTIES}}. Returns 3 values: the matching property key, value,
1181and the tail of property list after the matching property. When no match found
1182all values are {{#f}}.
1183
1184{{PROPERTIES}} may also be an atom, in which case it is treated as a list of
1185one element.
1186
1187
1188Previous: [[Parameters]]
1189
1190Next: [[Unit eval]]
Note: See TracBrowser for help on using the repository browser.