`
lobin
  • 浏览: 388545 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

ChezScheme

 
阅读更多

1.string

> "abcdefg"

"abcdefg"

 

> (string #\a #\b #\c #\d #\e #\f #\g)

"abcdefg"

 

> (mutable-string? "abcdefg")

#t

> (immutable-string? "abcdefg")

#f

 

> (let ([s "abcdefg"]) (mutable-string? s))

#t

> (let ([s "abcdefg"]) (immutable-string? s))

#f

 

> (string->immutable-string "abcdefg")

"abcdefg"

 

> (let ([s (string->immutable-string "abcdefg")]) (mutable-string? s))

#f

> (let ([s (string->immutable-string "abcdefg")]) (immutable-string? s))

#t

 

 2.list

> '(1 2 3 4 5 6);

(1 2 3 4 5 6)

 

> (list)

()

> (list 1 2 3 4 5)

(1 2 3 4 5)

 

> (list 'a 'b 'c 'd 'e 'f 'g)

(a b c d e f g)

 

> (list* 1 5)

(1 . 5)

 

> (make-list 5)

(#<void> #<void> #<void> #<void> #<void>)

> (make-list 5 5)

(5 5 5 5 5)

 

> (iota 6)

(0 1 2 3 4 5)

 

> (enumerate '())

()

> (enumerate '(a b c d e f g))

(0 1 2 3 4 5 6)

 

> (list-head '(a b c d e f g))

Exception: incorrect argument count in call (list-head (quote (a b c d e f ...)))

Type (debug) to enter the debugger.

> (list-head '(a b c d e f g) 0)

()

> (list-head '(a b c d e f g) 1)

(a)

> (list-head '(a b c d e f g) 2)

(a b)

> (list-head '(a b c d e f g) 3)

(a b c)

> (list-head '(a b c d e f g) 4)

(a b c d)

> (list-head '(a b c d e f g) 5)

(a b c d e)

> (list-head '(a b c d e f g) 6)

(a b c d e f)

> (list-head '(a b c d e f g) 7)

(a b c d e f g)

> (list-head '(a b c d e f g) 8)

Exception in list-head: index 8 is out of range for list (a b c d e f ...)

Type (debug) to enter the debugger.

 

> (remq! 'c '(a b c d e f g))

(a b d e f g)

> (remq! 'x '(a b c d e f g))

(a b c d e f g)

 

> (append! '(a b) '(c d))

(a b c d)

 

3.vector

> '#(a b c d e f g)

#(a b c d e f g)

 

> (vector 'a 'b 'c 'd 'e 'f 'g)

#(a b c d e f g)

 

> (vector->immutable-vector '#(a b c d e f g))

#(a b c d e f g)

 

> (mutable-vector? '#(a b c d e f g))

#t

> (mutable-vector? (vector->immutable-vector '#(a b c d e f g)))

#f

 

> (immutable-vector? '#(a b c d e f g))

#f

> (immutable-vector? (vector->immutable-vector '#(a b c d e f g)))

#t

 

> (let ([v '#(a b c d e f g)]) (vector-set-fixnum! v 3 100) v)

#(a b c 100 e f g)

 

4.fixnum-only vector

> #vfx(1 2 3 4)

#vfx(1 2 3 4)

 

5. record

syntax: (define-record name (fld1 ...) ((fld2 init) ...) (opt ...)) 

syntax: (define-record name parent (fld1 ...) ((fld2 init) ...) (opt ...)) 

 

> (define-record tmap (key value))

 

> (define m1 (make-tmap "adam" "add1"))

> m1

#[#{tmap br6stlesgmpl4cy9bmpnx2bck-0} "adam" "add1"]

 

> (tmap? m1)

#t

> (pair? m1)

#f

> (vector? m1)

#f

 

> (tmap-key m1)

"adam"

> (tmap-value m1)

"add1"

 

 

> (set-tmap-key! m1 "adam v2")

> (set-tmap-value! m1 "add1 v2")

> (tmap-key m1)

"adam v2"

> (tmap-value m1)

"add1 v2"

 

6.define

 

> (define x 1)

> x

1

> (define-syntax y (identifier-syntax 3));

> y

3

> (define-values (x1 y1) (values 1 2))

> x1

1

> y1

2

 

> (map

    (rec sum

      (lambda (x)

        (if (= x 0)

            0

            (+ x (sum

                   (- x 1))))))

    '(0 1 2 3 4 5))

(0 1 3 6 10 15) 

 

> (let

    ([x 100])

    x)

 

100

 

> (define sum

    (lambda

      (x y)

      (+ x y)));

> (sum 1 1);

2

> (sum 10 33);

43

 

 

7.

> (eq? "this" "this")

#f

> (eq? "this" "that")

#f

> (eq? 'this 'this)

#t

 

> (case 3

    (1 "Q1")

    (2 "Q2")

    (3 "Q3")

    (4 "Q4")

    (else "invalid param."))

"Q3"

 

> (case 3

    [1 "Q1"]

    [2 "Q2"]

    [3 "Q3"]

    [4 "Q4"]

    [else "invalid param."])

"Q3"

 

> (case "def"

    (("abc" "def") 'i)

    (((a b c)) 'ii)

    (else 'iii))

i

 

>  (case '(a b c)

     (("abc" "def") 'i)

     (((a b c)) 'ii)

     (else 'iii))

ii

 

> (define calc

    (lambda (x)

      (record-case x

        [(add) (x y) (+ x y)]

        [(sub) (x y) (- x y)]

        [(mul) (x y) (* x y)]

        [(div) (x y) (/ x y)]

        [else (assertion-violationf 'calc "invalid expression ~s" x)])))

 

> (calc '(add 3 4))

7

> (calc '(div 3 4))

3/4 

 

 

8.function

> (define sum

    (lambda

      (x y)

      (+ x y)));

> (sum 1 1);

2

> (sum 10 33);

43

 

9.

 

> (system "ls")

bin  boot  examples

0

 

> (process "ls")

(#<input port pid 17700 stdout>

  #<output port pid 17700 stdin>

  17700)

> (open-process-ports "ls")

#<binary output port pid 14844 stdin>

#<binary input port pid 14844 stdout>

#<binary input port pid 14844 stderr>

14844

 

10.

wget https://github.com/cisco/ChezScheme/archive/v9.5.tar.gz

wget https://github.com/cisco/ChezScheme/releases/download/v9.5/ChezScheme9.5.exe

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics