CLisp:将字符串编码设置为 UTF-8
CLisp: set encoding to UTF-8 for strings
我有一段代码:
; 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)))
总结
或者
使用OS:
或
- 运行 CLISP with
-E UTF-8
command line argument (clisp.exe -E UTF-8 /path/....
), OR
- 设置default encodings in the init file。
注意设置这些变量在你的 lisp 文件中,如果出现错误将NOT帮助,因为到 CLISP读取变量,文件已经以错误的外部格式打开。
CLISP FAQ: What do charset errors mean?
这意味着您正在尝试从具有 ASCII 的字符流中读取(“无效字节”)或写入(“无法表示字符”)非 ASCII 字符 :EXTERNAL-FORMAT
. The default is described in -Edomain encoding .
这也可能是由文件系统访问引起的。如果您的文件名称与您的 CUSTOM:*PATHNAME-ENCODING*
不兼容,文件系统访问(例如 DIRECTORY
)将 SIGNAL
这个 ERROR
。您将需要设置 CUSTOM:*PATHNAME-ENCODING*
或将 -Edomain encoding
传递给 CLISP。使用“1:1”编码,例如 CHARSET:ISO-8859-1
,应该可以帮助您避免此错误。
请查看官方网站以获取完整文档。
PS。 You now owe me 10 zorkmids
PPS。您的代码 (list '(...) '(...) ...)
看起来很奇怪,您可能想将其替换为 '((...) (...) ...)
。我的意思是,你的作品也一样,只是风格不好。
我有一段代码:
; 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)))
总结
或者
使用OS:
或
- 运行 CLISP with
-E UTF-8
command line argument (clisp.exe -E UTF-8 /path/....
), OR - 设置default encodings in the init file。 注意设置这些变量在你的 lisp 文件中,如果出现错误将NOT帮助,因为到 CLISP读取变量,文件已经以错误的外部格式打开。
CLISP FAQ: What do charset errors mean?
这意味着您正在尝试从具有 ASCII 的字符流中读取(“无效字节”)或写入(“无法表示字符”)非 ASCII 字符 :EXTERNAL-FORMAT
. The default is described in -Edomain encoding .
这也可能是由文件系统访问引起的。如果您的文件名称与您的 CUSTOM:*PATHNAME-ENCODING*
不兼容,文件系统访问(例如 DIRECTORY
)将 SIGNAL
这个 ERROR
。您将需要设置 CUSTOM:*PATHNAME-ENCODING*
或将 -Edomain encoding
传递给 CLISP。使用“1:1”编码,例如 CHARSET:ISO-8859-1
,应该可以帮助您避免此错误。
请查看官方网站以获取完整文档。
PS。 You now owe me 10 zorkmids
PPS。您的代码 (list '(...) '(...) ...)
看起来很奇怪,您可能想将其替换为 '((...) (...) ...)
。我的意思是,你的作品也一样,只是风格不好。