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

Last change on this file since 13562 was 13562, checked in by Kon Lovett, 11 years ago

Added fixnum & flonum limit constants.

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