星期三, 一月 12, 2011

ECL 10.7.1 如何才能正确打印出汉字

ecl.exe>(load "d:\\temp\\foo.lsp" :external-format :CP936)

foo.lsp文件内容
;foo.lsp
(ext::stream-external-format-set *standard-input* :CP936)
(ext::stream-external-format-set *standard-output* :CP936)

(print (length "好吧"))

(print "TEST" *standard-output*)
(princ "好吧" *standard-output*)
(format t "~%汉字来也")

这个代码只能在文件中执行,如果在ecl console里逐行敲入这些代码,反而出现错误:
ECL (Embeddable Common-Lisp) 10.7.1
Copyright (C) 1984 Taiichi Yuasa and Masami Hagiya
Copyright (C) 1993 Giuseppe Attardi
Copyright (C) 2000 Juan J. Garcia-Ripoll
ECL is free software, and you are welcome to redistribute it
under certain conditions; see file 'Copyright' for details.
Type :h for Help.
Top level in: #<process TOP-LEVEL>.
> (ext::stream-external-format-set *standard-input* :CP936)

> (ext::stream-external-format-set *standard-output* :CP936)

> (format t "汉字来也")
鹤酪
NIL
> (format t "汉字来也")
鹤酪
NIL
>

星期四, 一月 06, 2011

LISP在package如何访问TOPLEVEL定义的全局变量(Global Variable)?

如果在一个main.lisp中分别(load "*....lisp"),载入定义的package或者一些全局的数据.
往往会出现如下场景类似的问题:

 CL-USER> (defvar foo 108) FOO CL-USER> foo 108 CL-USER>
CL-USER> (in-package :asdf) #<PACKAGE "ASDF"> ASDF>
The variable FOO is unbound. [Condition of type UNBOUND-VARIABLE]

避免这个情况,就是用如下引用方式:
ASDF> cl-user::foo 108 ASDF>