Lisp 支持中文

 

用Lisp写网站程序的备忘

分类: LISP Web开发 2010-11-07 20:23  1458人阅读  评论(1)  收藏  举报

1。 使用 hunchentoot 作为网站框架,它的功能基本上类似于Python的web.py

2。 模板使用 html-template 

3。 本实例暂不涉及数据库操作

4。 主要的麻烦是中文的设置

 

这里给出的是一个最小的可用程序,可以正确处理中文模板文件与中文变量。

 

[javascript]  view plain copy
  1. ; 一些辅助函数  
  2. (require :asdf)  
  3. (defun loadlib (mod)  
  4.   (asdf:oos 'asdf:load-op mod))  
  5.   
  6. (defun reload ()  
  7.   (load "web.lisp"))  
  8. (defun restart-web ()  
  9.   (progn  
  10.     (reload)  
  11.     (start-web)))  
  12.   
  13. ; load 需要的库    
  14. (loadlib :html-template)  
  15. (loadlib :hunchentoot)  
  16.   
  17. ; 设置 hunchentoot 编码  
  18. (defvar *utf-8* (flex:make-external-format :utf-8 :eol-style :lf))  
  19. (setq hunchentoot:*hunchentoot-default-external-format* *utf-8*)  
  20. ; 设置url handler 转发表  
  21. (push (hunchentoot:create-prefix-dispatcher "/hello" 'hello) hunchentoot:*dispatch-table*)  
  22.           
  23. ; 页面控制器函数  
  24. (defun hello ()  
  25.   (setf (hunchentoot:content-type*) "text/html; charset=utf-8")  
  26.   (with-output-to-string (stream)  
  27.     (html-template:fill-and-print-template  
  28.      #p"index.tmpl"  
  29.      (list :name "Lisp程序员")  
  30.      :stream stream)))  
  31. ; 启动服务器  
  32. (defun start-web (&optional (port 4444))  
  33.   (hunchentoot:start (make-instance 'hunchentoot:acceptor :port port)))  

 

模板 index.tmpl

 

[xhtml]  view plain copy
  1. <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">  
  2. <html>  
  3.   <head>  
  4.     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
  5.     <title>Test Lisp Web</title>  
  6.   </head>  
  7.   <body>  
  8.     <h1>Lisp web开发实例</h1>  
  9.     hi, <!-- TMPL_VAR name -->  
  10.   </body>  
  11. </html>  
from : http://blog.csdn.net/albert_lee/article/details/5993716

Lisp in a box 安装指南

什么是Lispbox?


lispbox 是Common Lisp的集成开发环境。实际是Lispbox只是组合配置了Emacs编辑器,SLIME(Emacs的高级Lisp 交互模式)和Quicklisp 库管理工具和CCL Lisp编译器。

这些工具组合在一起给你了你所期望的一个ide能给你的所用的功能集合,甚至更多。Lispbox使你可以迅速和简单的投入使用。

Lispbox可以让新的Lisp程序员在一流的开发环境上近似于无痛的起步。所以强烈建议新手下载安装Lispbox作为学习Common Lisp的开始。


Lispbox的安装和使用

 

想使用Lispbox很简单,只要下载和解压对应你操作系统的版本即可。不需要安装!可以通过运行lispbox.bat (Windows) / lispbox.sh (Linux) / Emacs (OS X)开始Lispbox使用。

下载地址:http://common-lisp.net/project/lispbox/


Lispbox64位Windows系统兼容问题


将下载后的文件解压到例如D:\Program Files (x86)\的文件夹即可,如果没放到这个文件夹可能会报错

 

Lispbox的中文问题


默认的Emacs没有开启UTF-8字符集支持,所以并不支持中文,甚至中文注释也不行。如果输入中文将会出现如下错误:

CL-USER> '中文支持

 

slime-net-send: Coding system iso-latin-1-unix not suitable for "00004c(:emacs-rex (swank:listener-eval \"'中文支持

\") \"COMMON-LISP-USER\" :repl-thread 4)"

 

要对中文支持需修改文件解压后的文件夹下的文件 emacs-23.2\site-lisp\lispbox.el

在(require 'slime) 这一行的后面增加一行:

(setq slime-net-coding-system 'utf-8-unix)

也可以设置成其它编码,重启Lispbox即可。


from http://zhan.renren.com/astart?gid=3602888498026623432&from=post&checked=true

你可能感兴趣的:(Lisp 支持中文)