lisp

208_emacs lisp变量赋值

旧时模样 提交于 2020-02-09 17:39:51
完整的common lisp的学习集合整理如下: https://github.com/GreyZhang/g_lisp 看emacs的配置的时候,反复看到一个函数setq。从代码意图上看,应该是给变量赋值的。查看相应的帮助如下: 简单 的一个小结:赋值功能,把后面的表达式赋值给前面的变量。应该可以实现多个变量的赋值。 做几个测试如下: 初次赋值成功。 表达式求职成功。 在执行这个之前,我先执行了第3行代码。 从这个结果看得出来,这个列表赋值是可以进行多组的。而且赋值有一个从前到后的顺序。 简单做这么一点总结,估计这些信息基本上可以让我继续往下学习其他的东西了。 其他的lisp相关的学习笔记汇总,可以参考如下链接: https://github.com/GreyZhang/g_lisp 来源: CSDN 作者: grey_csdn 链接: https://blog.csdn.net/grey_csdn/article/details/104221124

199_emacs lisp之defconst-常量定义

白昼怎懂夜的黑 提交于 2020-02-03 21:59:28
完整的common lisp的学习集合整理如下: https://github.com/GreyZhang/g_lisp 继续分析我现在使用的emacs配置实现,今天的小结涉及到2个语句。用到了同一个函数:defconst。 源代码如下: 接下来,查一下用到的这个函数(很可能是一个宏)的相关帮助文档: 这个功能的实现也是通过C代码来实现的,这个确实是很有意思。我现在最初接触的几个功能的实现都是使用了C代码而不是lisp,这从一方面让我想到了这个功能是效率攸关的功能或者使用机器频繁的功能,从另一方面倒也让我对C语言赞叹有加。似乎,很多语言最初的构建都是基于C语言,emacs lisp虽说不是百分之百,但是最起码从我这一开始接触就看到了这样的影子。 从形式以及功能设计上看,这个函数的功能行为与setq比较类似,相关的描述可以参考如下链接: https://blog.csdn.net/grey_csdn/article/details/104158807 形式上不同的是,这个定义可以增加一个描述信息。 Defconst定义的是一个常量,读了一下上面的说明,我想到了《C专家编程》的一句话“C语言中的const其实理解为read only或许更加贴切”。我个人觉得,兴许这个描述也适用于这里。只不过,这里的修改发生在全局以及局部重叠的时候,这里有一个我理解不透的地方

Can Scheme expand a list as arguments?

ⅰ亾dé卋堺 提交于 2020-01-30 04:43:46
问题 Considered that I have a procedure (plus x y) witch takes exactly two args. And now I also have a list which contains two objects like (list 1 2) . So, if there's any magic way to expand the list as two arguments. We have a dot notion version, but that isn't what i want. I just want to expand the list to make Scheme believe I passed two arguments instead of a list. Hope those Ruby codes help: a = [1, 2] def plus(x,y); x+y; end plus(*a) # See that a is an array and the plus method requires #

LET versus LET* in Common Lisp

我只是一个虾纸丫 提交于 2020-01-26 21:56:49
问题 I understand the difference between LET and LET* (parallel versus sequential binding), and as a theoretical matter it makes perfect sense. But is there any case where you've ever actually needed LET? In all of my Lisp code that I've looked at recently, you could replace every LET with LET* with no change. Edit: OK, I understand why some guy invented LET*, presumably as a macro, way back when. My question is, given that LET* exists, is there a reason for LET to stay around? Have you written

(self self) call inside the let statement, in strict language

十年热恋 提交于 2020-01-25 00:48:11
问题 I am currently, going through this article on Y-combinator by Mike Vanier. Along the way of Y-combinator derivation, this code: (define (part-factorial self) (lambda (n) (if (= n 0) 1 (* n ((self self) (- n 1)))))) ((part-factorial part-factorial) 5) ==> 120 (define factorial (part-factorial part-factorial)) (factorial 5) ==> 120 is worked out to: (define (part-factorial self) (let ((f (self self))) (lambda (n) (if (= n 0) 1 (* n (f (- n 1))))))) (define factorial (part-factorial part

How to get output of a Lisp program into Python?

五迷三道 提交于 2020-01-24 17:51:07
问题 I've got a very large Lisp project whose output I'd like to programmatically pipe to a Python program, i.e. use Python to call the Lisp program on some input and get the output back into Python. The project only compiles in Clozure Common Lisp (ccl64) and I did try to find a way to turn it into an executable (I'm using Mac OS X), but that ran into a lot of dead ends (I am not a Lisp programmer). This documentation for Clozure Common Lisp should provide the solution to the above, but I was not

LISP: how to trace macros

…衆ロ難τιáo~ 提交于 2020-01-24 06:37:09
问题 This is probably a stupid question, but I'm walking through the PG lisp book, and I wanted to step through some example macros that he provides with actual values, for instance: (defmacro our-let (binds &body body) `( (lambda ,( mapcar #'(lambda (x) (if (consp x) (car x) x)) binds ) ,@body ) ,@(mapcar #'(lambda (x) (if (consp x) (cadr x) nil)) binds) ) ) I naively tried to run (trace our-let) and then (our-let ((x 1) (y 2)) (+ x y)) but I'm getting an error, can't use encapsulation to trace

Is there a relationship between untyped/typed code quotations in F# and macro hygiene?

最后都变了- 提交于 2020-01-23 07:20:31
问题 I wonder if there is a relationship between untyped/typed code quotations in F# and the hygiene of macro systems. Do they solve the same issues in their respective languages or are they separate concerns? 回答1: Quotations are a form of meta-programming. They allow you to manipulate abstract syntax trees programmatically, which can be in turned spliced into code, and evaluated. Typed quotations embed the reified type of the AST in the host language's type system, so they ensure you cannot

sleep in emacs lisp

爷,独闯天下 提交于 2020-01-23 04:37:33
问题 script A (insert (current-time-string)) (sleep-for 5) (insert (current-time-string)) M-x eval-buffer , two time strings are inserted with 5 secs apart script B some comint code (that add hook, and start process) (sleep-for 60) ;delay a bit for process to finish (insert "ZZZ") M-x eval-buffer , "ZZZ" is inserted right away, without any time delay what might have happened? btw, it's Emacs 23.2 on Win XP 回答1: If all you want to do is to wait for a process to finish, you should probably not use

How do I increment or decrement a number in Common Lisp?

送分小仙女□ 提交于 2020-01-20 17:14:46
问题 What is the idiomatic Common Lisp way to increment/decrement numbers and/or numeric variables? 回答1: Use the built-in "+" or "-" functions, or their shorthand "1+" or "1-", if you just want to use the result, without modifying the original number (the argument). If you do want to modify the original place (containing a number), then use the built-in "incf" or "decf" functions. Using the addition operator: (setf num 41) (+ 1 num) ; returns 42, does not modify num (+ num 1) ; returns 42, does