lisp

Swap two elements in list in Scheme [closed]

孤街浪徒 提交于 2019-12-23 16:06:02
问题 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 7 years ago . I need to switch 2 elements on entered indexes in list in Scheme lang. For example: (swap-index 0 3 '(1 2 3 4 5)) (4 2 3 1 5) Can

How to set a part of arguments from a list in Emacs Lisp?

自闭症网瘾萝莉.ら 提交于 2019-12-23 14:48:22
问题 I want to set PROGRAM-ARGS of start-process from a list. Like, (start-process process-name "*foobar*" process-path (append some-args (list (concat "the" "other" "arg")))) But this makes error that "... is not string", because start-process accepts only string arguments. How can I solve this? 回答1: You want either apply or sometimes funcall . In this particular case I would go with apply but you need to be familiar with them both. (apply #'start-process process-name "*foobar*" process-path some

In Lisp, what is the relationship between a form and a file?

我怕爱的太早我们不能终老 提交于 2019-12-23 11:59:15
问题 I'm having one little hiccup in understanding Lisp. According to the Common Lisp standard, a form is an atom or list that is meant to be evaluated. That seems easy enough. In the real world, at the moment, we store programs in files. SBCL, Clojure, and the like all have the notion of a file that can also be evaluated. How is this understood? Is a file treated ultimately like a single form to be evaluated, is it a collection of forms? For some reason, this has been really confusing me. 回答1:

Changing copies of lists in LISP

心已入冬 提交于 2019-12-23 11:53:25
问题 In LISP, I have a function that is passed a list. I would like to change an element of this list without changing the original list. Normally, I would use copy-list to create the local copy of the list which I will change, but this doesn't seem to be working: CL-USER> (defun test (item) (let ((copy (copy-list item))) (setf (nth 0 (nth 0 (nth 0 copy))) t) (print item) (print copy))) CL-USER> (defparameter item `(((NIL NIL) (NIL NIL) (NIL NIL)) ((NIL NIL NIL) (NIL NIL NIL)) ((3 3) (NIL NIL))))

LISP语言学习资源

我与影子孤独终老i 提交于 2019-12-23 10:51:54
LISP的介绍: Paul Graham 的主页 http://paulgraham.com/index.html Lisp之根源 - 保罗·格雷厄姆 http://daiyuwen.freeshell.org/gb/rol/roots_of_lisp.html 创造者的鉴赏力 - 保罗·格雷厄姆 http://daiyuwen.freeshell.org/gb/taste/taste.html 为什么Lisp语言如此先进?(译文) http://www.ruanyifeng.com/blog/2010/10/why_lisp_is_superior.html 安装LISP: 在windows上安装common lisp开发环境 https://www.cnblogs.com/yaoyaohust/p/10228788.html Welcome to CLISP http://clisp.sourceforge.net/ 学习LISP: 计算机程序的构造和解释(Structure and Interpretation of Computer Programs)中文勘误表(机械工业出版社,2004年2月出版): http://www.is.pku.edu.cn/~qzy/books/sicp/errata.htm Archive for the 'LISP'/'SICP'

In what languages can you dynamically rewrite functions on the fly?

本小妞迷上赌 提交于 2019-12-23 10:47:11
问题 I recently had the necessity of rewriting a javascript function in javascript, dynamically. The ease with which I did it, and how fun it was, astounded me. Over here I've got some HTML: <div id="excelExport1234" onclick="if(somestuff) location.href='http://server/excelExport.aspx?id=56789&something=else'; else alert('not important');" >Click here to export to excel</div> And I couldn't change the outputted HTML, but I needed to add an extra parameter to that link. I started thinking about it,

make-keyword-map in Clojure - Idiomatic?

∥☆過路亽.° 提交于 2019-12-23 10:14:10
问题 I have been writing some Clojure recently, and I found myself using the following pattern frequently enough: (let [x (bam) y (boom)] {:x x :y y}) So I went ahead and wrote the following macro: (defmacro make-keyword-map [& syms] `(hash-map ~@(mapcat (fn [s] [(keyword (name s)) s]) syms))) With that, code now looks like: (let [x (bam) y (boom)] (make-keyword-map x y) Would this sort of macro be considered idiomatic? Or am I doing something wrong, and missing some already established pattern to

Unable to use eval on user input in Racket

人走茶凉 提交于 2019-12-23 09:50:35
问题 I'm currently learning Scheme (using Racket), but one of the challenges I'm coming upon is trying to execute the following bit of code, which is meant to execute Racket code from user input using eval : (display (eval (read))) Here's some of the weird behavior I've observed so far: (display (eval (read))) in the definition window prompts for keyboard input, as expected, when the definitions are run. However, providing the input ((lambda (x) (+ x 1)) 1) gives the error ?: function application

zip function in Racket/Scheme

隐身守侯 提交于 2019-12-23 07:47:14
问题 Given two lists, return a list whose elements are lists of size two, such that for the i -th list, the first element is the i -th element of the first original list, and the second element is the i -th element of the second original list. If one list is smaller than the other, the resulting list is of the smallest size; and so if one of the lists is empty, return an empty list. For example: > (zip '(1 2) '(3 4)) '((1 3) (2 4)) > (zip '(1 2 3) '()) '() > (zip '() '(4 5 6)) '() > (zip '(8 9) '

Can you return nothing from a function in Scheme?

三世轮回 提交于 2019-12-23 07:24:53
问题 I'm writing a scheme interpreter, and in the case of an if statement such as: (if (< 1 0) 'true) Any interpreter I've tried just returns a new prompt. But when I coded this, I had an if for whether there was an alternative expression. What can I return in the if such that nothing gets printed? (if (has-alternative if-expr) (eval (alternative if-expr)) #f) ;; what do I return here? 回答1: According to the R6RS specification: If <test> yields #f and no <alternate> is specified, then the result of