lisp

What are the benefits of letrec?

℡╲_俬逩灬. 提交于 2019-12-03 22:52:02
While reading "The Seasoned Schemer" I've begun to learn about letrec . I understand what it does (can be duplicated with a Y-Combinator) but the book is using it in lieu of recurring on the already define d function operating on arguments that remain static. An example of an old function using the define d function recurring on itself (nothing special): (define (substitute new old l) (cond ((null? l) '()) ((eq? (car l) old) (cons new (substitute new old (cdr l)))) (else (cons (car l) (substitute new old (cdr l)))))) Now for an example of that same function but using letrec : (define

why defun is not the same as (setq <name> <lambda>)?

北城以北 提交于 2019-12-03 22:29:09
I'm confused about how defun macro works, because (defun x () "hello") will create function x, but symbol x still will be unbound. If I'll bind some lambda to x then x will have a value, but it will not be treated by interpreter as function in form like this: (x) I think that it is related to the fact that defun should define function in global environment, but I'm not sure what does it exactly mean. Why can't I shadow it in the current environment? Is there any way to force interpreter treat symbol as function if some lambda was bound to it? For example: (setq y (lambda () "I want to be a

What does #+#. mean in lisp?

依然范特西╮ 提交于 2019-12-03 22:26:41
It is almost impossible to google, hence my understanding is limited to contextual clues from reading through the slime source code: perhaps it is part of the object system in common lisp? Something like 'self'? snippet: (cond #+#.(swank-backend::sbcl-with-new-stepper-p) Perhaps this will make it more googleable : pound plus pound // hash plus hash symbol // octothorp plus octothorp That's pretty rare to see. #+clim clim:+red+ #-clim mygraphics:+red+ above means that the reader returns either red symbol and it depends whether there is a symbol with the name CLIM is on the list of features

新年第一篇: 给LISP新手介绍下SLIME这个神器

半世苍凉 提交于 2019-12-03 21:59:46
新年第一篇: 给LISP新手介绍下SLIME这个神器 Posted on 2013/01/04 by Albert Lee 好久没给自己的blog浇水了. 昨晚写的一些东西也是首先发布在douban的LISP小组里,冷落了自家的blog,罪过啊, 贴回来. 初次发布的douban小组帖子地址 假期抽空看了些SLIME的文档和源代码,随便写点感受,主要给LISP的初学者看的,因为这些对老鸟们来说都是老生长谈了。下面内容有些杂乱,主要是自己的学习笔记。 *SLIME 是一个革命性的开发工具*。它的重要性将在未来几年内逐渐被主流开发界所认识(主流总是很迟钝)。任何其他编程语言,如果不能实现SLIME的功能,则不能称之为“高级语言”。 SLIME是: The Superior Lisp Interaction Mode for Emacs 的缩写。 SLIME 的官方网站: http://common-lisp.net/project/slime/ 各种文档,介绍在上述网站中都有。这个网站看上去很out。但,不要被外表欺骗。它里面的开发技术与理念非常的领先前卫。 SLIME是 Emacs 与 Common LISP之间的桥梁,是开发环境与运行环境之间的桥梁。 我个人认为SLIME最重要的一点意义在于:它强调了快速迭代式的开发方式。首先要了解这一点,然后SLIME的各种特性都是为这一点服务的

Common Lisp菜鸟指南(译)

北城余情 提交于 2019-12-03 21:59:29
Common Lisp菜鸟指南(译) 原文见: http://ghostopera.org/blog/2012/06/24/the-newbie-guide-to-common-lisp/ 译文自: http://reverland.org/Tech/2012/06/26/common-lisp/ 渣翻译,见谅。 进入Common Lisp的世界可能非常让人退缩,甚至对有经验的程序猿也是这样。这个语言兼有力与美,但也有许多清晰的边界和没有真正被普遍理解的开端。 这个指南可能将持续一段时间,但是希望它将使踏入Common Lisp的任务变得不那么可怕。 理解Common Lisp Ariel Networks 有个适当形式的 Common Lisp 指南。 The HyperSpec 有完整的 Common Lisp 文档。 CLQR 是一个好的课下载的 Common Lisp 快速参考手册。 了解你的工具 Emacs 1 Emacs 是一个可实用lisp高度定制的编辑器 2 。它可以为lisp提供一个非常独特的实时开发流程。查看 David O’Toole 在通过Emacs和他的 “Blocky.io” 游戏开发系统在一个游戏中的 lightning talk ,来查看实时开发实例。很酷不是吗? Steel Bank Common Lisp 当这世界上有很多可用的 Common

org--agenda-prefix-format %? does not work

戏子无情 提交于 2019-12-03 21:20:02
Currently, I have my global TODO list shown as follows thanks to erikstokes : (org-agenda-prefix-format " %i %?-12(concat \"[ \"(org-format-outline-path (list (nth 1 (org-get-outline-path)))) \" ]\") "))) which outputs: for org layout: However, as you can see, for Task A, even though there is nothing in the project, it still shows up on the list. describe-variable for org-agenda-prefix-format says : If the first character after `%' is a question mark, the entire field will only be included if the corresponding value applies to the current entry. This is useful for fields which should have

c(a|d)+r macro in Racket

不羁岁月 提交于 2019-12-03 20:37:38
I wonder if it's possible to write a macro in Racket that would translate every form of shape (c(a|d)+r xs), where c(a|d)+r is a regular expression matching car, cdr, caar, cadr, ... etc, into the corresponding composition of first and rest. For example, this macro should take (caadr '(1 2 3 4 5)) and transform that to (first (first (rest '(1 2 3 4 5)))). Something like this in Shen (Mark Tarver's new programming language): https://groups.google.com/group/qilang/browse_thread/thread/131eda1cf60d9094?hl=en It is very possible to do exactly that in Racket, and in a much shorter way than done

How do I memoize a recursive function in Lisp?

孤人 提交于 2019-12-03 19:46:17
问题 I'm a Lisp beginner. I'm trying to memoize a recursive function for calculating the number of terms in a Collatz sequence (for problem 14 in Project Euler). My code as of yet is: (defun collatz-steps (n) (if (= 1 n) 0 (if (evenp n) (1+ (collatz-steps (/ n 2))) (1+ (collatz-steps (1+ (* 3 n))))))) (defun p14 () (defvar m-collatz-steps (memoize #'collatz-steps)) (let ((maxsteps (funcall m-collatz-steps 2)) (n 2) (steps)) (loop for i from 1 to 1000000 do (setq steps (funcall m-collatz-steps i))

Read macros: what do you use them for? [closed]

╄→гoц情女王★ 提交于 2019-12-03 19:11:23
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . I'm trying to get a feel for the parts of Lisp that I haven't used very much up to now. Read macros have caught my attention at the

Editing programs “while they are running”? Why?

有些话、适合烂在心里 提交于 2019-12-03 18:18:47
问题 I've been getting more into Lisp and Lispy languages lately, and I'm finding them quite powerful. One thing I've been reading all over the net is that a benefit of writing in Lisp, Clojure, etc, is that you can edit your program "while it's running". Perhaps I'm missing something, but what is the point? Sure, it might save a few seconds, but is that all? Whenever I make a change to my program I just stop it then start it again, and that has been working fine for decades. There must be a