lisp

Saving lisp state

与世无争的帅哥 提交于 2019-12-05 11:48:31
I am a beginner in lisp and have a question. When I writing some code directly in REPL (without any .lisp file!), how can I save my work/state of the interpreter to restore it next time and continue working? (I am using ECL) Thanx! And sorry for my broken english ;) From the ECL manual : Tratidionally, Common Lisp implemenations have provided a function to save the dump all data from a running Lisp process into a file. The result was called the Lisp image and could be shipped to other version compatible implementations.Nowadays, having less control of the systems it runs in, a Lisp

This is a bug in sbcl?

故事扮演 提交于 2019-12-05 11:28:32
Why happen this in sbcl? Maybe a bug? (defclass myclass () ((s1 :initform '((a . 1) (b . 2))) (s2 :initform '((a . 1) (b . 2))))) (defparameter ins (make-instance 'myclass)) (setf (cdr (assoc 'a (slot-value ins 's1))) 43) ;; change only slot s1 ;; here my problem (slot-value ins 's1) ;; => ((a . 44) (b . 2))) (slot-value ins 's2) ;; => ((a . 44) (b . 2))) But if change :initform to : (defclass myclass () ((s1 :initform '((a . 1) (b . 2))) (s2 :initform '((a . 1) (b . 3))))) The problem disappears I test this in sbcl 1.4.3 and 1.4.11 . In clisp it seems that the problem does not arise. No. You

How to set default or optional parameters in scheme?

*爱你&永不变心* 提交于 2019-12-05 10:31:57
I'm trying to figure out how to how to set default or optional parameters in Scheme. I've tried (define (func a #!optional b) (+ a b)) but I can't find of a way to check if b is a default parameter, because simply calling (func 1 2) will give the error: Error: +: number required, but got #("halt") [func, +] I've also tried (define (func a [b 0]) (+ a b)) but I get the following error: Error: execute: unbound symbol: "b" [func] If it helps I'm using BiwaScheme as used in repl.it This works fine in Racket: (define (func a (b 0)) ; same as [b 0] (+ a b)) For example: (func 4) => 4 (func 3 2) => 5

Y Combinator学习总结

倖福魔咒の 提交于 2019-12-05 10:24:57
最近看完The little schemer,第一次看到这种编排的书,一问一答的形式,不知不觉就翻完了整本。很自然的教会大家写递归,怎样写程序,一点点的CPS,还有Y combinator。 个人觉得第九章推导Y combinator过程是我看到的最清晰,简单的一个了,只要花点耐心,就能学会。 scheme版本Y组合子 (define Y (lambda (le) ((lambda (f) (f f)) (lambda (f) (le (lambda (x) ((f f) x))))))) 直接翻译为erlang代码 Y = fun(M) -> (fun(F) -> F(F) end)( fun(F) -> M(fun(X) -> (F(F))(X) end) end ) end. 这样看起来不怎么清晰,抽取函数体,定义为变量,再带入 fun(F) -> F(F) end 即获得 Y = fun(M) -> G = fun (F) -> M(fun(X) -> (F(F))(X) end) end, G(G) end. Y组合子是用于lambda演算中实现递归逻辑的,即是可以实现匿名函数的递归调用。原理就是fixed-point combinator,不动点组合子。高阶函数 f 的不动点是另一个函数 g ,使得 f(g) = g 。那么不动点算子是任何函数 fix 使得对于任何函数

Is there a command to halt the interpreter in Common Lisp?

久未见 提交于 2019-12-05 10:07:08
问题 I'm looking for an expression that will cause the interpreter to exit when it is evaluated. I've found lots of implementation-specific ones but none in the HyperSpec, and I was wondering if there were any that I wasn't seeing defined in the specification. I've found that (quit) is recognized by both CLISP and SLIME, and (exit) is recognized only by CLISP, but I can't find any documentation that references either of these. 回答1: Since most Lisps import a quit function into CL-USER, CL-USER:

How to start REPL for slimv with MIT-Scheme

荒凉一梦 提交于 2019-12-05 09:59:07
问题 My operating system is Debian Squeeze. Here's the vim version: VIM - Vi IMproved 7.2 (2008 Aug 9, compiled Jul 12 2010 02:29:33) I read a tutorial on http://kovisoft.bitbucket.org/tutorial.html and tried to start REPL for MIT-Scheme. Unfortunately, I failed to start. When I pressed ",c", it started a terminal window loading mit-scheme. Nothing showed in the REPL buffer of vim. Some errors showed in the terminal: Listening on port: 4005 ;netcat: "4005: inverse host lookup failed: Unknown host"

how does one compile a clisp program which uses cl-ppcre?

本秂侑毒 提交于 2019-12-05 09:51:10
On Debian, I am trying to compile a CLISP program which uses the cl-ppcre package. A sample, simplified program (which I will call variant 1) looks like this: (asdf:load-system :cl-ppcre) (princ (cl-ppcre:regex-replace-all "a" "abcde" "x")) (terpri) When I ran it thus:: clisp -q a3.lisp I got this: home:~/clisp/ercpp/compiling-program$ clisp -q a3.lisp ; Loading system definition from /usr/share/common-lisp/systems/cl-ppcre.asd into #<PACKAGE ASDF0> ; Registering #<SYSTEM :CL-PPCRE> as CL-PPCRE ; Registering #<SYSTEM :CL-PPCRE-TEST> as CL-PPCRE-TEST 0 errors, 0 warnings xbcde home:~/clisp

第1章 开始 Lisp 之旅 GETTING STARTED WITH LISP

烈酒焚心 提交于 2019-12-05 09:48:12
第1章 开始 Lisp 之旅 GETTING STARTED WITH LISP 翻译者:FreeBlues github版本: https://github.com/FreeBlues/Land-of-lisp-CN 开源中国版本: http://my.oschina.net/freeblues/blog?catalog=516771 目录 Lisp 方言 两种 Lisp 的故事 A Tale of Two Lisps Lisp 的前景 Up-and-Coming Lisps 被用于脚本的 Lisp 方言 Lisp Dialects Used for Scripting ANSI Common Lisp 开始 CLISP 之旅 安装 CLISP Installing CLISP 启动 CLISP Starting Up CLISP 本章你学到的 What You’ve Learned 本章从介绍 Lisp 的各种方言开始。然后我们会讨论一点 ANSI Common Lisp,也就是我们将会在本书使用的 Lisp 方言。最后你将会从安装和试验 CLISP 开始,这是 ANSI Common Lisp 的一种实现,它将会运行本书中你所创建的所有 Lisp 游戏程序。 Lisp 方言 任何遵守 Lisp 核心原则的程序语言都被认为是一种 Lisp 方言。既然这些原则是如此简单

Removing NIL's from a list LISP

大兔子大兔子 提交于 2019-12-05 09:13:47
Simple question. Say I have a bunch of NIL's in my list q . Is there a simple way to remove the NILs and just keep the numbers?. eval doesn't seem to work here. (NIL 1 NIL 2 NIL 3 NIL 4) I need (1 2 3 4) Common Lisp, instead of remove-if you can use remove: (remove nil '(nil 1 nil 2 nil 3 nil 4)) In common lisp and perhaps other dialects: (remove-if #'null '(NIL 1 NIL 2 NIL 3 NIL 4)) If you're using Scheme, this will work nicely: (define lst '(NIL 1 NIL 2 NIL 3 NIL 4)) (filter (lambda (x) (not (equal? x 'NIL))) lst) As I noted in my comment above, I'm not sure which Lisp dialect you are using,

emacs programmatically change window size

我与影子孤独终老i 提交于 2019-12-05 09:02:32
I would like to implement automatic collapse of compilation buffer to small size (but not close at a delete windows), such that upon successful compilation to window is shrunk to minimum size. get-buffer-create returns a buffer. how can I shrink-window on window associated with that buffer? also, is there a way to store previous window size? It is my first foray into emacs lisp programming, thank you for your help. I believe there are two ways to solve this problem. The first is to use the hook `'compilation-finish-functions', which is: [A list of f]unctions to call when a compilation process