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

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

applied cygwin patch for DLLSINPATH [Thanks to Nathan Thern]

File size: 29.0 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
784Finalizers are invoked asynchronously, in the thread that happens
785to be currently running.
786
787
788==== set-gc-report!
789
790 [procedure] (set-gc-report! FLAG)
791
792Print statistics after every GC, depending on {{FLAG}}. A value of
793{{#t}} shows statistics after every major GC. A true value different
794from {{#t}} shows statistics after every minor GC. {{#f}}
795switches statistics off.
796
797
798
799
800
801=== Other control structures
802
803
804
805==== promise?
806
807 [procedure] (promise? X)
808
809Returns {{#t}} if {{X}} is a promise returned by {{delay}}, or
810{{#f}} otherwise.
811
812
813
814=== String utilities
815
816
817==== reverse-list->string
818
819 [procedure] (reverse-list->string LIST)
820
821Returns a string with the characters in {{LIST}} in reverse order. This is
822equivalent to {{(list->string (reverse LIST))}}, but much more efficient.
823
824
825
826=== Generating uninterned symbols
827
828==== gensym
829
830 [procedure] (gensym [STRING-OR-SYMBOL])
831
832Returns a newly created uninterned symbol. If an argument is provided,
833the new symbol is prefixed with that argument.
834
835
836==== string->uninterned-symbol
837
838 [procedure] (string->uninterned-symbol STRING)
839
840Returns a newly created, unique symbol with the name {{STRING}}.
841
842
843
844=== Standard Input/Output
845
846==== port?
847
848 [procedure] (port? X)
849
850Returns {{#t}} if {{X}} is a port object or {{#f}}
851otherwise.
852
853
854==== print
855
856 [procedure] (print [EXP1 ...])
857
858Outputs the optional arguments {{EXP1 ...}} using {{display}} and
859writes a newline character to the port that is the value of
860{{(current-output-port)}}. Returns {{(void)}}.
861
862
863==== print*
864
865 [procedure] (print* [EXP1 ...])
866
867Similar to {{print}}, but does not output a terminating newline
868character and performs a {{flush-output}} after writing its arguments.
869
870
871
872
873=== User-defined named characters
874
875==== char-name
876
877 [procedure] (char-name SYMBOL-OR-CHAR [CHAR])
878
879This procedure can be used to inquire about character names or to
880define new ones. With a single argument the behavior is as follows:
881If {{SYMBOL-OR-CHAR}} is a symbol, then {{char-name}} returns
882the character with this name, or {{#f}} if no character is defined
883under this name. If {{SYMBOL-OR-CHAR}} is a character, then the
884name of the character is returned as a symbol, or {{#f}} if the
885character has no associated name.
886
887If the optional argument {{CHAR}} is provided, then
888{{SYMBOL-OR-CHAR}} should be a symbol that will be the new name of
889the given character. If multiple names designate the same character,
890then the {{write}} will use the character name that was defined last.
891
892<enscript highlight=scheme>
893(char-name 'space)                  ==> #\space
894(char-name #\space)                 ==> space
895(char-name 'bell)                   ==> #f
896(char-name (integer->char 7))       ==> #f
897(char-name 'bell (integer->char 7))
898(char-name 'bell)                   ==> #\bell
899(char->integer (char-name 'bell))   ==> 7
900</enscript>
901
902
903
904=== Blobs
905
906"blobs" are collections of unstructured bytes. You can't do much
907with them, but allow conversion to and from SRFI-4 number vectors.
908
909==== make-blob
910
911 [procedure] (make-blob SIZE)
912
913Returns a blob object of {{SIZE}} bytes, aligned on an 8-byte boundary,
914uninitialized.
915
916==== blob?
917
918 [procedure] (blob? X)
919
920Returns {{#t}} if {{X}} is a blob object, or
921{{#f}} otherwise.
922
923==== blob-size
924
925 [procedure] (blob-size BLOB)
926
927Returns the number of bytes in {{BLOB}}.
928
929==== blob->string
930
931 [procedure] (blob->string BLOB)
932
933Returns a string with the contents of {{BLOB}}.
934
935==== string->blob
936
937 [procedure] (string->blob STRING)
938
939Returns a blob with the contents of {{STRING}}.
940
941==== blob=?
942
943 [procedure] (blob=? BLOB1 BLOB2)
944
945Returns {{#t}} if the two argument blobs are of the same
946size and have the same content.
947
948
949
950=== Vectors
951
952==== vector-copy!
953
954 [procedure] (vector-copy! VECTOR1 VECTOR2 [COUNT])
955
956Copies contents of {{VECTOR1}} into {{VECTOR2}}. If the
957argument {{COUNT}} is given, it specifies the maximal number of
958elements to be copied. If not given, the minimum of the lengths of the
959argument vectors is copied.
960
961Exceptions: {{(exn bounds)}}
962
963
964==== vector-resize
965
966 [procedure] (vector-resize VECTOR N [INIT])
967
968Creates and returns a new vector with the contents of {{VECTOR}} and length
969{{N}}. If {{N}} is greater than the original length of {{VECTOR}}, then all
970additional items are initialized to {{INIT}}. If {{INIT}} is not specified, the
971contents are initialized to some unspecified value.
972
973
974
975=== The unspecified value
976
977==== void
978
979 [procedure] (void)
980
981Returns an unspecified value.
982
983
984
985=== Continuations
986
987==== call/cc
988
989 [procedure] (call/cc PROCEDURE)
990
991An alias for {{call-with-current-continuation}}.
992
993
994==== continuation-capture
995
996 [procedure] (continuation-capture PROCEDURE)
997
998Creates a continuation object representing the current continuation and
999tail-calls {{PROCEDURE}} with this continuation as the single argument.
1000
1001More information about this continuation API can be found in the paper
1002[[http://repository.readscheme.org/ftp/papers/sw2001/feeley.pdf]] ''A Better
1003API for first class Continuations'' by Marc Feeley.
1004
1005
1006==== continuation?
1007
1008 [procedure] (continuation? X)
1009
1010Returns {{#t}} if {{X}} is a continuation object, or {{#f}} otherwise. Please
1011note that this applies only to continuations created by the Continuation API,
1012but not by call/cc, i.e.: {{(call-with-current-continuation continuation?)}}
1013returns {{#f}}, whereas {{(continuation-capture continuation?)}} returns
1014{{#t}}.
1015
1016
1017==== continuation-graft
1018
1019 [procedure] (continuation-graft CONT THUNK)
1020
1021Calls the procedure {{THUNK}} with no arguments and the implicit continuation
1022{{CONT}}.
1023
1024
1025==== continuation-return
1026
1027 [procedure] (continuation-return CONT VALUE ...)
1028
1029Returns the value(s) to the continuation {{CONT}}. {{continuation-return}} could
1030be implemented like this:
1031
1032<enscript highlight=scheme>
1033(define (continuation-return k . vals)
1034  (continuation-graft
1035    k
1036    (lambda () (apply values vals)) ) )
1037</enscript>
1038
1039
1040
1041=== Setters
1042
1043SRFI-17 is fully implemented. For more information see:
1044[[http://srfi.schemers.org/srfi-17/srfi-17.html|SRFI-17]].
1045
1046==== setter
1047
1048 [procedure] (setter PROCEDURE)
1049
1050Returns the setter-procedure of {{PROCEDURE}}, or signals an error if
1051{{PROCEDURE}} has no associated setter-procedure.
1052
1053Note that {{(set! (setter PROC) ...)}} for a procedure that has no associated
1054setter procedure yet is a very slow operation (the old procedure is replaced by
1055a modified copy, which involves a garbage collection).
1056
1057
1058==== getter-with-setter
1059
1060 [procedure] (getter-with-setter GETTER SETTER)
1061
1062Returns a copy of the procedure {{GETTER}} with the associated setter procedure
1063{{SETTER}}. Contrary to the SRFI specification, the setter of the returned
1064procedure may be changed.
1065
1066
1067
1068=== Reader extensions
1069
1070==== define-reader-ctor
1071
1072 [procedure] (define-reader-ctor SYMBOL PROC)
1073
1074Define new read-time constructor for {{#,}} read syntax. For further information, see
1075the documentation for [[http://srfi.schemers.org/srfi-10/srfi-10.html|SRFI-10]].
1076
1077
1078==== set-read-syntax!
1079
1080 [procedure] (set-read-syntax! CHAR-OR-SYMBOL PROC)
1081
1082When the reader encounters the non-whitespace character {{CHAR}} while reading
1083an expression from a given port, then the procedure {{PROC}} will be called with
1084that port as its argument. The procedure should return a value that will be returned
1085to the reader:
1086
1087<enscript highlight=scheme>
1088 ; A simple RGB color syntax:
1089
1090 (set-read-syntax! #\%
1091   (lambda (port)
1092     (apply vector
1093       (map (cut string->number <> 16)
1094            (string-chop (read-string 6 port) 2) ) ) ) )
1095
1096 (with-input-from-string "(1 2 %f0f0f0 3)" read)
1097 ; ==> (1 2 #(240 240 240) 3)
1098</enscript>
1099
1100If {{CHAR-OR-SYMBOL}} is a symbol, then a so-called ''read-mark'' handler is defined.
1101In that case the handler procedure will be called when a character-sequence of the
1102form
1103
1104 #!SYMBOL
1105
1106is encountered.
1107
1108You can undo special handling of read-syntax by passing {{#f}} as the second argument
1109(if the syntax was previously defined via {{set-read-syntax!}}).
1110
1111Note that all of CHICKEN's special non-standard read-syntax is handled directly by the reader.
1112To disable built-in read-syntax, define a handler that triggers an error (for example).
1113
1114
1115==== set-sharp-read-syntax!
1116
1117 [procedure] (set-sharp-read-syntax! CHAR-OR-SYMBOL PROC)
1118
1119Similar to {{set-read-syntax!}}, but allows defining new {{#<CHAR> ...}} reader syntax.
1120If the first argument is a symbol, then this procedure is equivalent to {{set-read-syntax!}}.
1121
1122
1123==== set-parameterized-read-syntax!
1124
1125 [procedure] (set-parameterized-read-syntax! CHAR-OR-SYMBOL PROC)
1126
1127Similar to {{set-sharp-read-syntax!}}, but intended for defining reader syntax of the
1128form {{#<NUMBER><CHAR> ...}}. The handler procedure {{PROC}} will be called with two
1129arguments: the input port and the number preceding
1130the dispatching character.
1131If the first argument is a symbol, then this procedure is equivalent to {{set-read-syntax!}}.
1132
1133
1134==== copy-read-table
1135
1136 [procedure] (copy-read-table READ-TABLE)
1137
1138Returns a copy of the given read-table. You can access the currently active read-table
1139with {{(current-read-table)}}.
1140
1141
1142=== Property lists
1143
1144As in other Lisp dialects, CHICKEN supports "property lists" associated with symbols.
1145Properties are accessible via a key that can be any kind of value but which will
1146be compared using {{eq?}}.
1147
1148==== get
1149
1150  [procedure] (get SYMBOL PROPERTY [DEFAULT])
1151
1152Returns the value stored under the key {{PROPERTY}} in the property
1153list of {{SYMBOL}}. If no such property is stored, returns
1154{{DEFAULT}}. The {{DEFAULT}} is optional and defaults to {{#f}}.
1155
1156==== put!
1157
1158  [procedure] (put! SYMBOL PROPERTY VALUE)
1159  [setter] (set! (get SYMBOL PROPERTY) VALUE)
1160
1161Stores {{VALUE}} under the key {{PROPERTY}} in the property list of
1162{{SYMBOL}} replacing any previously stored value.
1163
1164==== remprop!
1165
1166  [procedure] (remprop! SYMBOL PROPERTY)
1167
1168Deletes the first property matching the key {{PROPERTY}} in the property list
1169of {{SYMBOL}}. Returns {{#t}} when a deletion performed, and {{#f}} otherwise.
1170
1171==== symbol-plist
1172
1173  [procedure] (symbol-plist SYMBOL)
1174  [setter] (set! (symbol-plist SYMBOL) LST)
1175
1176Returns the property list of {{SYMBOL}} or sets it.
1177
1178==== get-properties
1179
1180  [procedure] (get-properties SYMBOL PROPERTIES)
1181
1182Searches the property list of {{SYMBOL}} for the first property with a key in
1183the list {{PROPERTIES}}. Returns 3 values: the matching property key, value,
1184and the tail of property list after the matching property. When no match found
1185all values are {{#f}}.
1186
1187{{PROPERTIES}} may also be an atom, in which case it is treated as a list of
1188one element.
1189
1190
1191Previous: [[Parameters]]
1192
1193Next: [[Unit eval]]
Note: See TracBrowser for help on using the repository browser.