lisp

Given the following LISP eval function - what is required to add defmacro?

本秂侑毒 提交于 2019-12-03 17:53:49
问题 Given the following definition of the LISP eval function - what is required to add the defmacro function? (Or even just evaluate a macro) (defun null. (x) (eq x '())) (defun and. (x y) (cond (x (cond (y 't) ('t '()))) ('t '()))) (defun not. (x) (cond (x '()) ('t 't))) (defun append. (x y) (cond ((null. x) y) ('t (cons (car x) (append. (cdr x) y))))) (defun list. (x y) (cons x (cons y '()))) (defun pair. (x y) (cond ((and. (null. x) (null. y)) '()) ((and. (not. (atom x)) (not. (atom y))) (cons

LISP: How to read content from a file and write it in another file?

℡╲_俬逩灬. 提交于 2019-12-03 17:15:59
I want to write a function that has as arguments the names of the two files and copies the content from the first file to the second one. So far I wrote a function that reads from a file: (defun readFile (name) (let ((in (open name))) (format t "~a~%" (read-line in)) (close in))) And a function that writes a string to a file: (defun writeFile (name content) (with-open-file (stream name :direction :output :if-exists :overwrite :if-does-not-exist :create) (format stream content))) Following Savantes instructions I wrote the function again and this is how it looks: (defun read-write-to-file

Error with define in Racket

本小妞迷上赌 提交于 2019-12-03 17:15:38
问题 I just discovered Racket a few days ago, and I'm trying to get more comfortable with it by writing a little script that generates images to represent source code using #lang slideshow . I know that when programming in a functional paradigm it's good practice to create almost all your variables with let , but I find that it introduces too many levels of nesting and that Racket's let has an overcomplicated API which requires superfluous parentheses. I'm sure this is to remove ambiguity when

How to overcome the lack of local variable for emacs lisp closure

落花浮王杯 提交于 2019-12-03 17:15:05
问题 I'm now studying Emacs Lisp from the reference manual and Common Lisp from a LISP Book. from the Common Lisp book >> (setf power-of-two (let ((previous-power-of-two 1)) #'(lambda () (setf previous-power-of-two (* previous-power-of-two 2))))) >> (funcall power-of-two) 2 >> (funcall power-of-two) 4 >> (funcall power-of-two) 8 The function won't work in Emacs Lisp because of its dynamic binding behavior. I wonder if it is possible to implement the same function in Emacs Lisp without introducing

REPL on console emacs

浪尽此生 提交于 2019-12-03 16:48:16
问题 I'm using the console version of emacs (that is, I'm SSH'ed into a remote machine and using emacs there) and I was wondering how (assuming it's possible) to start up the REPL from there. I'm pretty new to Lisp and emacs. 回答1: How about M-x ielm ? ielm: Inferior Emacs Lisp Mode 回答2: You can run a terminal emulator with M-x term in Emacs and use any REPL you like in there. I prefer it to inferior modes, but I think it's just a matter of taste. 来源: https://stackoverflow.com/questions/4250913

Emacs lisp evaluate variable in alist

穿精又带淫゛_ 提交于 2019-12-03 16:46:54
This is a follow-up question to Emacs Lisp: evaluate variable in alist .. I am trying to set default-frame-alist in my .emacs file. Consider, e.g. (setq default-frame-alist '((auto-lower . nil) (auto-raise . nil) (height . 41) (width . 80) (top . 1) (left . 1))) (I have omitted some values) This works fine.. Suppose now I want set the height according to another variable..Say, I stored the integer value 50 in the variable my-height .. How can I set height to the value of my-height ? I have tried (height . my-height) ``(height . ,my-height)` but neither works.. What am I missing here? You need

如何通过 Common Lisp 调用 iOS simulator 并交互?== 未解决

▼魔方 西西 提交于 2019-12-03 16:42:16
之前根据 CCL 的教程学会了如何在 Common Lisp 中调用 Cocoa 框架,编写 MAC 应用程序。 最近在考虑如何通过 Common Lisp 调用 Cocoa Touch 框架,开发 iOS 程序(iPhone/iPad),首先需要解决的问题就是如何在 Common Lisp 中启动 iOS 模拟器,并且建立起通信,进行交互(把写好的 APP 上传到模拟器中)。 虽然对于 iOS 高手来说没什么技术含量,不过确实是一个必须解决的问题(商业化的 Mocl 已经实现),准备慢慢搞定,这样,以后就可以直接使用 Common Lisp 来开发 iOS 应用了。 话说现在苹果最新发布的 swift 也支持 REPL 了,说明 Lisp 这座金矿还有太多值得挖掘的宝藏,为什么不直接用 Lisp 来开发 app 呢? 搜索了一下,找到下面这篇文档,准备先学习参考一下 原文如下: 地址: http://stackoverflow.com/questions/5770020/has-anyone-got-any-code-examples-of-ecl-lisp-for-iphone-development The ECL for iOS distribution includes a code example of a Common Lisp application running

Compose example in Paul Graham's ANSI Common Lisp

北慕城南 提交于 2019-12-03 16:27:01
问题 Can anybody explain an example in Paul Graham's ANSI Common Lisp page 110? The example try to explain the use &rest and lambda to create functional programming facilities. One of them is a function to compose functional arguments. I cannot find anything explaining how it worked. The code is as follows: (defun compose (&rest fns) (destructuring-bind (fn1 . rest) (reverse fns) #'(lambda (&rest args) (reduce #'(lambda (v f) (funcall f v)) rest :initial-value (apply fn1 args))))) The usage is:

Elisp: How to delete an element from an association list with string key

懵懂的女人 提交于 2019-12-03 15:41:17
问题 Now this works just fine: (setq al '((a . "1") (b . "2"))) (assq-delete-all 'a al) But I'm using strings as keys in my app: (setq al '(("a" . "foo") ("b" . "bar"))) And this fails to do anything: (assq-delete-all "a" al) I think that's because the string object instance is different (?) So how should I delete an element with a string key from an association list? Or should I give up and use symbols as keys instead, and convert them to strings when needed? 回答1: If you know there can only be a

Is there any common lisp docs like linux man? [closed]

依然范特西╮ 提交于 2019-12-03 14:24:23
I am a newbie for emacs and common lisp. I am now using emacs and slime to learn P.Graham “ANSI Common LISP”. However, when I meet something that I don't konw, I can not easily get some useful info like linux man. Is there any common lisp docs like linux man? Common Lisp HyperSpec describes the ANSI Common Lisp standard, and, as such, is more similar to the POSIX Standard than to Linux man pages . Since you use Emacs, you can use clhs.el to lookup specific symbols there: (autoload 'common-lisp-hyperspec "clhs" "Get doc on ANSI CL" t) (define-key help-map "\C-s" 'common-lisp-hyperspec) Note: I