我有一段代码:

; 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:字符集中的字节x90无效:CP1252转换
这很好,除了我找不到方法,在脚本文件中,告诉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)))

最佳答案

概要
要么
使用操作系统:
WindowsHow do I view and change the system locale settings to use my language of choice?
UnixHow to change locale environment variable?
或者
使用-E UTF-8 command line argumentclisp.exe -E UTF-8 /path/....)运行CLISP,或
default encodings中设置init file
请注意,在lisp文件中设置这些变量(错误输出)将不会有帮助,因为当CLISP读取变量时,该文件已经以错误的外部格式打开。
CLISP FAQ: What do charset errors mean?
这意味着您试图从(或到)具有ASCII:EXTERNAL-FORMAT的字符流中读取(无效字节)或写入(字符不能表示)非ASCII字符默认值在-Edomain encoding中描述。
这也可能是由于文件系统访问造成的如果文件名与CUSTOM:*PATHNAME-ENCODING*不兼容,则文件系统访问(例如DIRECTORY)将SIGNALERROR。您需要设置CUSTOM:*PATHNAME-ENCODING*或将-Edomain encoding传递给CLISP使用“1:1”编码(如CHARSET:ISO-8859-1)将有助于避免此错误。
详情请参阅官方网站。
PS.You now owe me 10 zorkmids
是的。您的代码看起来很奇怪,您可能想用(list '(...) '(...) ...)替换它我是说,你的作品也是,只是风格不好。

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

10-11 01:32