lisp

Generate unique random numbers in a loop

血红的双手。 提交于 2019-12-10 09:23:22
问题 OK, after few hours of insane debugging, I finally have this: (defmacro assoc-bind (bindings expression &rest body) (let* ((i (gensym)) (exp (gensym)) (abindings (let ((cursor bindings) result) (while cursor (push (caar cursor) result) (push (cdar cursor) result) (setq cursor (cdr cursor))) (setq result (nreverse result)) (cons (list i `(quote ,result)) (cons (list exp expression) result))))) `(let (,@abindings) (while ,i (set (car ,i) (caar ,exp)) (setq ,i (cdr ,i)) (set (car ,i) (cdar ,exp)

Using 'ash' in LISP to perform a binary search?

别说谁变了你拦得住时间么 提交于 2019-12-10 06:25:29
问题 So, I'm reading Land of Lisp now, and Lisp is turning out to be quite different than other programming languages that I've seen. Anyways, the book provides some code that we're meant to enter into the CLISP REPL: (defparameter *small* 1) (defparameter *big* 100) (defun guess-my-number () (ash (+ *small* *big*) -1)) (defun smaller () (setf *big* (1- (guess-my-number))) (guess-my-number)) (defun bigger () (setf *small* (1+ (guess-my-number))) (guess-my-number)) Now, the basic goal is to create

This is a bug in sbcl?

孤街浪徒 提交于 2019-12-10 05:32:15
问题 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

emacs programmatically change window size

我与影子孤独终老i 提交于 2019-12-10 04:22:57
问题 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. 回答1: I believe there are two ways to solve this problem. The first is to use

关于《Land of Lisp》的翻译说明

孤街醉人 提交于 2019-12-10 03:44:36
Land-of-lisp-CN 《Land of Lisp》中文翻译 || Translating [Land of Lisp] to Chinese 《Land of Lisp》是一本很不错的 Common Lisp 教程,特别适合于初学者,计划把它的内容翻译为中文。 笔者一向认为,学习一种技术,最好能准备两到三种不同的教材,这样就可以从不同的角度去了解这门技术,有助于初学者迅速理解,有时候某本书里某个概念半天想不明白,翻开另外一名作者写的书,从不同的角度描述的这个概念,也许很容易就弄懂了,所以学习 Common Lisp 也不要拘泥于一本书,而是尽量多看看,因此基于这种考虑,笔者选择了这本《Land of Lisp》作为学习 Common Lisp 的补充教材。 事实上这本书本身也很有趣,基本上通过各种小游戏的开发把 Common Lisp 的相关概念都讲解了一番。 翻译的原因其实很简单,笔者英文水平一般,但是很多时候又不得不去阅读英文技术文档,虽然当时看懂了,可是有时想回头再看看,于是又得重复一遍“大脑翻译”的过程,于是就想,干脆第一遍读懂的时候就直接翻译成中文文档,这样不仅自己回头看方便,也可以分享给其他跟我一样英语不怎么好的技术爱好者,于是就有了这个发愿。因此,译文中必然有一些翻译得不甚准确的地方,希望水平高的读者发现了能提醒笔者修改,谢谢! 本文的翻译会在两个地方发布

Does a setfable nthcdr implementation exist?

谁说我不能喝 提交于 2019-12-10 03:38:49
问题 I am using clisp and I wonder if there is any library with a setfable version of nthcdr that I can use. 回答1: You can hack around it with: (let ((lst (list 1 2 3 4)) (n 2)) (setf (cdr (nthcdr (1- n) lst)) '(5 6 7)) l) > (1 2 5 6 7) Or define your own setf for it: ;; !!warning!! only an example, lots of nasty edge cases (defsetf nthcdr (n lst) (new-val) `(setf (cdr (nthcdr (1- ,n) ,lst)) ,new-val)) I do not know why nthcdr does not have a setf defined. Even Alexandria seems to define setf for

Common Lisp 函数 require 和 provide 源代码分析

◇◆丶佛笑我妖孽 提交于 2019-12-10 03:34:28
Common Lisp 函数 require 和 provide 源代码分析 === 涉及文件: l1-files.lisp l1-init.lisp 作者: FreeBlues 2013-08-19 === 目录 0 概述 1 源代码: 2 代码分析 2.1 函数 provide 代码分析 2.2 函数 require 代码分析 2.3 其他辅助函数 0 概述 require 使用场景, 使用 quicklisp 安装好一个模块后,该模块实际上并未被自动加载到 lisp 映像中, 所以每次使用该模块之前, 需要执行 (require 模块名) 来加载该模块. provide 使用场景, 自定义模块时, 需要在该模块代码最后一行执行 (provide 模块名) 来保证该模块被加载一次后就把模块名导入到 *module* 列表中. require 用来加载一个模块到 lisp 映像, 如果它已经被加载过, 则保持原样, 不会重新加载(看起来跟 load 函数类似, 不过 load 需要输入文件路径和文件名, 而 require 则只要提供模块名就可以了). 可以指定加载路径, HyperSpec 中有如下几种形式: Examples: ;;; This illustrates a nonportable use of REQUIRE, because it ;;; depends

Common Lisp 初学者快速入门指导

百般思念 提交于 2019-12-10 03:30:50
Common Lisp 初学者快速入门指导 V 0.90 目录 一、简单介绍 1、本文目标 2、适用读者 3、迭代式学习 4、本章内容小结 二、快速上手 1、推荐开发环境 Lispbox 2、开发环境简要介绍 3、第一个简单的 Lisp 程序 4、为程序增加些复杂性 5、这么好的程序一定要保存起来 6、补充阅读:让程序支持中文符号 7、本章内容小结 三、适用于初学者的基本概念 1、Lisp 程序由 S-表达式组成,表达式是列表或单个原子 2、Lisp 中的列表是什么样的? 3、Lisp 中的原子又是什么样的? 4、Lisp 中求值的概念:对数字、符号、字符串和列表求值 5、对列表中函数调用形式、宏形式和特殊形式求值 6、单引号的特殊作用--构建宏的基础 7、本章内容小结 四、一个简单实践:文本数据库-藏书阁 1、项目简单说明 2、定义你的原型数据结构 3、开工:首先是数据录入模块 4、其次是数据显示模块 5、充分发挥迭代的优势:改进一下输入方式 6、保存和加载已经录入的数据 7、查询数据库 8、更新记录 9、再次迭代:用宏来消除重复 10、本章内容小结 五、跨越初学者阶段 1、其实说实话我也是初学者… 2、HyperSpec:Common Lisp 有哪些“标准库函数”? 3、如何查找各种具体实现(如SBCL、CCL、LispWorks)的帮助信息 4、更深一步的学习 5

Does learning one Lisp help in learning the other?

大城市里の小女人 提交于 2019-12-10 02:33:40
问题 Is there any synergy between learning different Lisp languages? I'm currently learning Emacs Lisp, as it is immediately useful in my daily Emacs usage, however i'm fascinated with all Lisps, so maybe someday i will learn and use others. Will learning Emacs Lisp help me, when i start digging in Common Lisp, Scheme or Clojure? In other words, will it be for me like learning a completely new language, or some notions and paradigms are common? I'm also interested in comparison of unique

Is it possible to generate 40,000+ element of Fibonacci recursively in Lisp?

馋奶兔 提交于 2019-12-09 20:44:57
问题 I'm trying to solve Project Euler question 2 with Lisp. This recursive solution blows the stack on execution, but I thought Lisp (using clisp) would recognize the tail recursion. This is being entered into the top-level. (defun e2-problem (&optional (f1 1) (f2 1) (sum 0)) "Sum fibonacci sequence, even terms up to 4 million" (if (> f2 4000000) sum) (e2-problem f2 (+ f1 f2) (if (evenp f2) (+ sum f2) sum)) Is my implementation not correctly arranged for optimization? I imagine this would hinder