unicode - CLisp:将字符串编码设置为 UTF-8

标签 unicode lisp common-lisp clisp

我有一段代码:

; Palatal Pulmonic Consonants
(loop for e in (list
                    '(:nasal "ɲ")
                    '(:plosive "c") '(:plosive "ɟ")
                    '(:fricative "ç") '(:fricative "ʝ")
                    '(:approximant "j")
                    '(:lateral-fricative "ʎ̥˔")
                    '(:lateral-approximant "ʎ")
                    '(:lateral-flap "ʎ̯") ) do
    (add-sound :palatal (car e) (cadr e)))

我有很多用于所有 IPA 符号的这些位,这不是具体的问题所在。

但是,尝试运行我的代码会出现此错误:

SYSTEM::STRING-READER: Invalid byte #x90 in CHARSET:CP1252 conversion

这很好,除了我无法找到一种方法,在脚本文件中,告诉 CLisp 我正在以 UTF-8 格式输入字符串,我希望它以 UTF-8 格式读取并打印它们。

如何在全局范围内永久设置 UTF-8。我的想法类似于 Ruby 的 # encoding: utf-8

具体来说,我使用的是 CLisp 2.48。

编辑:

这是导致问题的文件的完整源列表:

(defstruct sound place means sym)
(defparameter $sounds nil)
(defun add-sound (place means sym)
  (setf $sounds (append $sounds (list (make-sound :place place :means means :sym sym)))))
; There are alot of IPA symbols, so we'll add them column by column.
; The first column is the Bilabial Pulmonic Consonants
(loop for e in (list
                  '(:nasal "m") '(:plosive "p")
                  '(:plosive "b") '(:fricative "ɸ")
                  '(:fricative "β") '(:trill "ʙ")
                  '(:flap "ⱱ̟") ) do
  (add-sound :bilabial (car e) (cadr e)))
; Labiodental Pulmonic Consonants
(loop for e in (list
                    '(:nasal "ɱ") '(:plosive "p̪")
                    '(:plosive "b̪") '(:fricative "f")
                    '(:fricative "v") '(:approximant "ʋ")
                    '(:flap "ⱱ") ) do
    (add-sound :labiodental (car e) (cadr e)))
; Dental Pulmonic Consonants
(loop for e in (list
                    '(:nasal "n̪")
                    '(:plosive "t̪") '(:plosive "d̪")
                    '(:fricative "θ") '(:fricative "ð") ) do
    (add-sound :dental (car e) (cadr e)))
; Alveolar Pulmonic Consonants
(loop for e in (list
                    '(:nasal "n")
                    '(:plosive "t") '(:plosive "d")
                    '(:fricative "s") '(:fricative "z")
                    '(:trill "r")
                    '(:flap "ɾ")
                    '(:lateral-fricative "ɬ") '(:lateral-fricative "ɮ")
                    '(:lateral-approximant "l")
                    '(:lateral-flap "ɺ") ) do
    (add-sound :alveolar (car e) (cadr e)))
; Palato-Alveolar Pulmonic Consonants
(loop for e in (list
                    '(:fricative "ʃ") '(:fricative "ʒ")
                    '(:approximant "ɹ") ) do
    (add-sound :palato-alveolar (car e) (cadr e)))
; Retroflex Pulmonic Consonants
(loop for e in (list
                    '(:nasal "ɳ")
                    '(:plosive "ʈ") '(:plosive "ɖ")
                    '(:fricative "ʂ") '(:fricative "ʐ")
                    '(:approximant "ɻ")
                    '(:trill "ɽ͡r")
                    '(:flap "ɽ")
                    '(:lateral-fricative "ɭ˔̊")
                    '(:lateral-approximant "ɭ")
                    '(:lateral-flap "ɺ̢") ) do
    (add-sound :retroflex (car e) (cadr e)))
; Palatal Pulmonic Consonants
(loop for e in (list
                    '(:nasal "ɲ")
                    '(:plosive "c") '(:plosive "ɟ")
                    '(:fricative "ç") '(:fricative "ʝ")
                    '(:approximant "j")
                    '(:lateral-fricative "ʎ̥˔")
                    '(:lateral-approximant "ʎ")
                    '(:lateral-flap "ʎ̯") ) do
    (add-sound :palatal (car e) (cadr e)))
; Velar Pulmonic Consonants
(loop for e in (list
                    '(:nasal "ŋ")
                    '(:plosive "k") '(:plosive "ɡ")
                    '(:fricative "x") '(:fricative "ɣ")
                    '(:approximant "ɰ")
                    '(:lateral-fricative "ʟ̝̊")
                    '(:lateral-approximant "ʟ") ) do
    (add-sound :velar (car e) (cadr e)))
; Uvular Pulmonic Consonants
(loop for e in (list
                    '(:nasal "ɴ")
                    '(:plosive "q") '(:plosive "ɢ")
                    '(:fricative "χ") '(:fricative "ʁ")
                    '(:trill "ʀ")
                    '(:flap "ɢ̆") ) do
    (add-sound :uvular (car e) (cadr e)))
; Pharyngeal Pulmonic Consonants
(loop for e in (list
                    '(:plosive "ʡ")
                    '(:fricative "ħ") '(:fricative "ʕ")
                    '(:trill "ʜ") '(:trill "ʢ")
                    '(:flap "ʡ̯") ) do
    (add-sound :pharyngeal (car e) (cadr e)))
; Glottal Pulmonic Consonants
(loop for e in (list
                    '(:plosive "ʔ")
                    '(:fricative "h") '(:fricative "ɦ") ) do
    (add-sound :glottal (car e) (cadr e)))

最佳答案

总结

要么

CLISP FAQ: What do charset errors mean?

这意味着您正在尝试从具有 ASCII 的字符流中读取(“无效字节”)或写入(“字符无法表示”)非 ASCII 字符(或向其写入):EXTERNAL-FORMAT . -Edomain encoding 中描述了默认值.

这也可能是由文件系统访问引起的。如果您的文件名称与您的 CUSTOM:*PATHNAME-ENCODING* 不兼容,文件系统访问(例如,DIRECTORY)将SIGNAL这个ERROR。您需要设置 CUSTOM:*PATHNAME-ENCODING* 或将 -Edomain encoding 传递给 CLISP。使用“1:1”编码,例如 CHARSET:ISO-8859-1,应该可以帮助您避免此错误。

请查看官方网站以获取完整文档。

附言。 You now owe me 10 zorkmids

PPS。你的代码 (list '(...) '(...) ...) 看起来很奇怪,你可能想用 '((...) (.. .) ...)。我的意思是,你的作品也是,只是风格不好。

关于unicode - CLisp:将字符串编码设置为 UTF-8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44184774/

相关文章:

lisp - Lisp : The LET binding spec is malformed 错误

naming-conventions - clojure 中如何使用 `*var-name*` 命名约定?

python - Unicode解码错误: 'ascii' codec can't decode byte 0xc3 in position 0: ordinal not in range(128)

python - numpy loadtxt、unicode 和 python 2 或 3

lisp - Common Lisp 宏和 Forth 元编程能力的比较

lisp - 用于 eql 的 Common Lisp 通配符

嵌套的 `defun` 在 Allegro Common Lisp 中产生重复警告

macros - 如何在不使用 `eval` 的情况下编写此宏?

c++ - Unicode 文本在编辑框中显示为问号,即使我使用 SetWindowTextW()

sql-server - 如何正确处理 UTF-8 XML 中的 ?