Colin's Blog

Recent content on Colin's Blog

马上订阅 Colin's Blog RSS 更新: https://blog.oyyko.com/index.xml

Scheme Review 1

finalwind42@gmail.com (Oyyko)
2023年7月4日 08:00

https://courses.cs.washington.edu/courses/cse341/04wi/lectures/14-scheme-quote.html

Quote

Scheme has a convenient syntax for representing data literals: prefix any expression with ’ (single quote) and the expression, rather than being evaluated, will be returned as data:

 1'3        ; => 3                 (a number) 2'"hi"     ; => "hi"              (a string) 3'a        ; => a                 (a symbol) 4'(+ 3 4)  ; => (list '+ '3 '4)   (a list) 5'(a b c)  ; => (list 'a 'b 'c)   (a list) 6 7'(define x 25)                   (a list) 8          ; => (list 'define 'x '25) 9          ; => (list 'define 'x 25)1011'(lambda (x) (+ x 3))            (a list)12          ; => (list 'lambda (list 'x) (list '+ 'x '3))13          ; => (list 'lambda (list 'x) (list '+ 'x 3))

As these examples illustrate, “quoted” data remains unevaluated, and provides a convenient way of representing Scheme programs. This is one of the big payoffs of Lisp’s simple syntax: since programs themselves are lists, it is extremely simple to represent Lisp programs as data. Compare the simplicity of quoted lists with the ML...

剩余内容已隐藏

查看完整文章以阅读更多