File: type-case

package info (click to toggle)
scheme9 2025.08.12-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,080 kB
  • sloc: lisp: 16,752; ansic: 11,869; sh: 806; makefile: 237; sed: 6
file content (22 lines) | stat: -rw-r--r-- 664 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
S9 LIB  (type-case object <clause> ...)  ==>  object
        (type-of object)                 ==>  symbol

        (load-from-library "type-case.scm")

TYPE-OF returns a symbol describing the type of the given OBJECT.
The following symbols may be returned by the procedure:

      boolean char eof-object input-port integer output-port
      pair procedure real string symbol syntax unknown-object
      vector

(Type-case obj ...)  is shorthand for  (case (type-of obj) ...)

(type-of type-of)  ==>  procedure

(let ((x '#(1 2 3))
      (i 0))
  (type-case x
    ((string) (string-ref x i))
    ((vector) (vector-ref x i))
    (else     x)))               ==>  1