Thrush calls in Common Lisp
Implement the "->" operator of Clojure: http://clojuredocs.org/clojure_core/clojure.core/-%3E in CL, that's funny.
->
Threads the expr through the forms. Inserts x as the second item in the first form, making a list of it if it is not a list already. If there are more forms, inserts the first form as the second item in second form, etc.
(defmacro -> (x &optional (form nil form-supplied-p) &rest more)
(if form-supplied-p
(if more
`(-> (-> ,x ,form) ,@more)
(if (listp form)
`(,(car form) ,x ,@(cdr form))
(list form x)))
x))
How does it works?
CL-USER> (-> 1
(+ 1)
(+ 2)
(+ 3))
7
CL-USER>
=== (+ (+ (+ 1 1) 2) 3)
See another example:
CL-USER> (-> 10
(- 5)
(- 5)
(- 5))
-5
CL-USER>
=== (- (- (- 10 5) 5) 5)
How if I want (- 5 (- 5 (- 5 10)))?
There is ->> to do this. http://clojuredocs.org/clojure_core/clojure.core/-%3E%3E
->>
Threads the expr through the forms. Inserts x as the last item in the first form, making a list of it if it is not a list already. If there are more forms, inserts the first form as the last item in second form, etc.
(defmacro ->> (x &optional (form nil form-supplied-p) &rest more)
(if form-supplied-p
(if more
`(->> (->> ,x ,form) ,@more)
(if (listp form)
`(,(car form) ,@(cdr form) ,x)
(list form x)))
x))
This one looks more useful sometimes.
CL-USER> (->> (list 1 2 3 4 5)
(reduce '+)
(* 2)
(- 5))
-25
CL-USER>
=== (- 5 (* 2 (reduce '+ '(1 2 3 4 5))))
Secure your cookies of Hunchentoot in Common Lisp.
Encrypt and decrypt cookies in hunchentoot. What is COOKIE?
Hunchentoot - The Common Lisp web server formerly known as TBNL
Hunchentoot is a web server written in Common Lisp and at the same time a toolkit for building dynamic websites. As a stand-alone web server, Hunchentoot is capable of HTTP/1.1 chunking (both directions), persistent connections (keep-alive), and SSL.
By default, hunchentoot supports cookies, but all cookies will be exposed once a request was done from the client. And there is not a solution to secure the cookies transform by now in hunchentoot. So the temporary choice is using the hunchentoot session:
这么玩 lisp,实在让人蛋疼!
取个环境变量都要这么折腾:
(defun getenv (var)
#+cmu (cdr (assoc (if (symbolp var)
var
(intern var :keyword))
ext:*environment-list*))
#+sbcl (sb-ext:posix-getenv (string var))
#+lispworks (hcl:getenv var)
#+clisp (ext:getenv (string var))
#+allegro (sys:getenv (string var))
#-(or cmu sbcl lispworks clisp allegro)
(error "GETENV not implemented for your Lisp platform."))
To clean up old packages in quicklisp
(map nil 'ql-dist:clean (ql-dist:all-dists))
A nice ORM library in common lisp
Crane project home page: http://eudoxia0.github.io/crane/
(filter 'user) ;; Returns everything
(filter 'user :name "Eudoxia")(filter 'user (:> :age 21))
;; Returns a single object
(single 'user :name "Eudoxia");;Throws an error ifthis returns more
;; than one object(single!'user (:< age 35))
;; t if a match exists, nil otherwise
(exists 'user :name "Eudoxia");;Ifthis record doesn't exist create it
(get-or-create 'user :name "Eudoxia":age 19)
cl-common-blog博客功能基本完善
划了个 0.2 版本, 个人测试, 已经相当稳定了, 而且比现在的博客方便, 再过不久我就完全使用cl-common-blog. 博客地址改为 http://blog.gihnius.net/.
写一个博客太简单了, 很多lisp的特性/功能都没有用到, 可能还不如写一个emacs插件折腾人. 当然, 这么说也是基于自己对博客应用的定义, 如果想的复杂, 就可以做得非常复杂, 可是没用.
接下来, 我计划使用common lisp开发一些应用. Planing...
用Common Lisp写的博客程序可用了!
发布了源代码, 并部署到 dev.gihnius.net .
功能很普通, 只能算一个可运行的程序. 毕竟是第一次试手 lisp 的 web 应用.
一个人工智能聊天机器人
听说是 lisp 写的.比较有趣, 有空不妨跟它聊几句!