作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个包含字母的列表。
当我做 (car '(a)) 时,它给了我符号 a。
我如何将它与字符 a 进行比较?
我必须做 (eq? (car list) (car '(a)) 吗?
最佳答案
符号和字符是不同种类的数据。幸运的是,Scheme 愿意让你转换几乎任何你想要的东西。在 Racket 中,例如:
#lang racket
;; the symbol a:
'a
;; the character a:
#\a
;; are they equal? no.
(equal? 'a #\a) ;; produces #f
;; converting a character to a symbol:
(define (char->symbol ch)
(string->symbol (string ch)))
(char->symbol #\a) ;;=> produces 'a
;; converting a symbol to a character
(define (symbol->char sym)
(match (string->list (symbol->string sym))
[(list ch) ch]
[other (error 'symbol->char
"expected a one-character symbol, got: ~s" sym)]))
(symbol->char 'a) ;; => produces #\a
关于scheme - 如何将符号 a 与字符 a 进行比较?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5397144/
我是一名优秀的程序员,十分优秀!