lisp

Two-layer “Y-style” combinator. Is this common? Does this have an official name?

情到浓时终转凉″ 提交于 2019-12-07 03:56:15
问题 I've been looking into how languages that forbid use-before-def and don't have mutable cells (no set! or setq ) can nonetheless provide recursion. I of course ran across the (famous? infamous?) Y combinator and friends, e.g.: http://www.ece.uc.edu/~franco/C511/html/Scheme/ycomb.html http://okmij.org/ftp/Computation/fixed-point-combinators.html http://www.angelfire.com/tx4/cus/combinator/birds.html http://en.wikipedia.org/wiki/Fixed-point_combinator When I went to implement "letrec" semantics

How to use double-float?

試著忘記壹切 提交于 2019-12-07 02:49:28
问题 I am struggling a little trying to figure out how to tell Lisp that I want to use double-float values. Suppose I have: (let ((x 1)) (format t "~A~%" (/ x 3.0))) Which gives: 0.33333334 If I want to use double-float, I tried this: (let ((x 1)) (declare (type double-float x)) (format t "~A~%" (/ x 3.0))) 0.33333334 So the result is not a double-float. I can, however, force double-float like this: (let ((x 1)) (format t "~A~%" (/ x 3.0d0))) 0.3333333333333333d0 And now I get a double-float

Which Function is the best in terms of Stack Usage Efficiency and Time

大兔子大兔子 提交于 2019-12-07 02:10:34
问题 I wrote 3 functions that count the number of times an-element appears in a-list. I tried various inputs and profiled it but I still dont know which function is the best in terms of stack usage efficiency and time efficiency. Please Help me out. ;; Using an accumulator (defn count-instances1 [a-list an-element] (letfn [(count-aux [list-aux acc] (cond (empty? list-aux) acc :else (if (= (first list-aux) an-element) (count-aux (rest list-aux) (inc acc)) (count-aux (rest list-aux) acc))))] (count

Lisp macro (or function) for nested loops

牧云@^-^@ 提交于 2019-12-07 01:56:15
问题 Is it possible to write a Common Lisp macro that takes a list of dimensions and variables, a body (of iteration), and creates the code consisting of as many nested loops as specified by the list? That is, something like: (nested-loops '(2 5 3) '(i j k) whatever_loop_body) should be expanded to (loop for i from 0 below 2 do (loop for j from 0 below 5 do (loop for k from 0 below 3 do whatever_loop_body))) Follow up As huaiyuan correctly pointed out, I have to know the parameters to pass to

Just getting used to paredit in emacs on OS X - how come C-) doesn't work?

余生颓废 提交于 2019-12-07 01:25:26
问题 I've recently set up a Common Lisp programming environment in Mac OS X Leopard. One emacs module which I've found to be indispensable is paredit. Paredit is doing its part to help me wrangle my Lisp code more easily, but I've ran into a bit of a snare. C-), bound to paredit-forward-slurp-sexp , is not forward slurping sexps but instead echoing the number 0 . I'm using a Mac, alternating between iTerm and Terminal. The same problem is present in both apps. I tried the same key combination in

Why were FEXPRs abandoned in Common Lisp? [closed]

ⅰ亾dé卋堺 提交于 2019-12-07 01:19:41
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 6 years ago . Many LISPs had FEXPRs but they were not included in CL. I read that this was because FEXRPs don't work well with static analysis. Can someone explain this? 回答1: From the Wikipedia article on FEXPRs: At the 1980 Conference on Lisp and Functional Programming, Kent Pitman presented a paper "Special

uses for dynamic scope?

最后都变了- 提交于 2019-12-07 00:26:17
问题 I've been getting my hands wet with emacs lisp, and one thing that trips me up sometimes is the dynamic scope. Is there much of a future for it? Most languages I know use static scoping (or have moved to static scoping, like Python), and probably because I know it better I tend to prefer it. Are there specific applications/instances or examples where dynamic scope is more useful? 回答1: There's a good discussion of this issue here. The most useful part that pertains to your question is: Dynamic

How can I unintern a qualified method?

早过忘川 提交于 2019-12-06 21:35:44
问题 During development I defined an 'initialize-instance :after' method which after a while was not needed anymore and actually gets in my way because inside it calls code that is not valid anymore. Since the unintern function does not have an argument for the qualifier, is there any way I can "unintern" the symbol-qualifier combination of a method so that I don't have to slime-restart-inferior-lisp and load the project again from the start? 回答1: You can use the standard functions find-method and

转向一门更加高级的语言Lisp

≯℡__Kan透↙ 提交于 2019-12-06 21:25:10
以前一直习惯了C语言的使用与思维习惯。但是现在看来,C语言还是很低级,所以再学一门更加高级的语言,对我而言,有三个选项:shell,python和lisp;我刚刚看完Common Lisp的语法部分,所以以后可能会深入学习Lisp,争取有朝一日使用Lisp处理手上的工作和作为研究兴趣的工具。 现在将过去的学习总结如下: Lisp语言的语法很简单,很一致,即使加上CLOS也是如此: (operator argument*) 如果有一个emacs下的slime这样的开发环境,细节的语法根本不用死记。 下面是主体: the root of lisp可以帮助你了解他的优雅,至于他的强大,我还没有真正的需要他,所以没有切身的体会,Lisp的拥护者如此忠诚,所以说实在的,我想看个究竟。哈哈! 最开始学习Lisp会感觉别扭,这是思维习惯问题;然后是难理解(即使不再别扭),我看来理解Lisp的关键是理解符号:symbols are really objects。这样函数和变量可以同名而不混淆(当然函数是动词,变量是名词,没有必要重名),初次见到真是惊呆了。 还有,我觉得Lisp的package管理机制很棒,足够。权限控制毫无必要,所以C++,Java的权限机制实践中没有多大意义,有无皆可。 更多的以后记述! 来源: oschina 链接: https://my.oschina.net/u

Cocoa(Objective-C) 到 Lisp 的桥转换基本规则 (教程翻译)

别说谁变了你拦得住时间么 提交于 2019-12-06 21:24:57
Cocoa(Objective-C) 到 Lisp 的桥转换基本规则 (教程翻译) === 原文地址: 网络: http://trac.clozure.com/ccl/wiki/CocoaBridgeTranslation 原文标题: Cocoa Bridge Translation 翻译者: FreeBlues 2013-07-18 === 目录 0 概述 Overview 1 直接量 literals 2 类型 types 3 常量,枚举和变量 constants, enumerations and variables 4 选择器 selectors 5 类定义 class definition 6 方法定义 method definition 7 实例化对象 instantiating objects 8 方法调用 method call 9 调用设置器/设置属性 calling setters/setting properties 0 概述 这里有一堆从 OBJ-C 代码到等效的 Clozure CL 的 Cocoa 桥代码之间的转换,示范不同的语言习惯如何编码。这些东西有些是 Clozure CL FFI 的一部分,未指定具体的桥,但它们被包含在这里给出一个总体概览。 1 直接量 literals T 和 NIL 被映射到对应的布尔值 YES 和 NO.