lisp

Subset / Subsequence Recursive Procedure in Simply Scheme Lisp

别等时光非礼了梦想. 提交于 2019-12-12 11:28:35
问题 I am working my way through Simply Scheme in combination with the Summer 2011 CS3 Course from Berkley. I am struggling with my understanding of the subset / subsequence procedures. I understand the basic mechanics once I'm presented with the solution code, but am struggling to grasp the concepts enough to come up with the solution on my own. Could anyone point me in the direction of something that might help me understand it a little bit better? Or maybe explain it differently themselves?

In lisp, how do I use the second value that the floor function returns?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-12 11:27:07
问题 When I do (floor 4 3) I got 1 1/3 But how do I use that 1/3? 回答1: You can for instance bind it to a variable using multiple-value-bind . (multiple-value-bind (quot rem) (floor 4 3) (format t "The remainder is ~f~%" rem)) Another possibility, if you're only interested in one non-primary value, is nth-value . (format t "The remainder is also ~f~%" (nth-value 1 (floor 4 3))) For reference, see the Hyperspec. 来源: https://stackoverflow.com/questions/6986880/in-lisp-how-do-i-use-the-second-value

Lisp: CHAR is neither declared nor bound

有些话、适合烂在心里 提交于 2019-12-12 11:24:13
问题 I have decided to learn (Common) Lisp a few days ago and I realize that this is quite a newbie question and it is probably extremely trivial to someone with at least a bit of experience. So basically what happens is that I load up Emacs + Slime (via Lisp in a Box) and write my program (included below): (defun last-char (s) "Get last character" (char s (- (length s) 1))) And then I try to compile it with C - c M - k , but then I get the following warning: CHAR is neither declared nor bound, it

What are improper lists for?

元气小坏坏 提交于 2019-12-12 11:05:42
问题 This is a follow-up of my previous question: Why do we need nil? Clearly, proper lists are used most of the time. But what is the purpose of an improper list? 回答1: For no good reason. The only thing that improper lists are truly good for is as part of the syntax for association lists—and even there, a custom syntax for key-value pairs would be better. Any use you can think of for improper lists can be better implemented with record types—which, after all, subsume lists: you can define Lisp

Multiply without + or *

丶灬走出姿态 提交于 2019-12-12 10:52:54
问题 I'm working my way through How to Design Programs on my own. I haven't quite grasped complex linear recursion, so I need a little help. The problem: Define multiply , which consumes two natural numbers, n and x , and produces n * x without using Scheme's * . Eliminate + from this definition, too. Straightforward with the + sign: (define (multiply n m) (cond [(zero? m) 0] [else (+ n (multiply n (sub1 m)))])) (= (multiply 3 3) 9) I know to use add1 , but I can't it the recursion right. Thanks.

Clojure reference Project up to date?

徘徊边缘 提交于 2019-12-12 10:44:00
问题 Starting with Clojure I discovered a talk by Rich Hickey where he demonstrates some of Clojure's strengths on a basic Ant-Simulator. Can this code still be considered as a good reference for Clojure? Especially the parts when he recursively sends off functions to agents to simulate a game loop. Example: (defn animation [x] (when b/running (send-off *agent* #'animation)) (. panel (repaint)) (. Thread (sleep defs/animation-sleep-ms)) nil) Edit: I am not interested in the #' reader macro but

Problems with ltk (common lisp)

巧了我就是萌 提交于 2019-12-12 10:38:59
问题 I installed ltk to Steel Bank Common Lisp with asdf-install, but I can't even start using it V_V. The code below is the simplest example in the documentation, and is copied almost verbatim. (asdf:operate 'asdf:load-op :ltk) (defun hello-1() (with-ltk () (let ((b (make-instance 'button :master nil :text "Press Me" :command (lambda () (format t "Hello World!~&"))))) (pack b)))) (hello-1) This is the error message I get from sbcl: > ; in: LAMBDA NIL ; (PACK B) ; ; caught STYLE-WARNING: ;

lisp - should be a lambda expression

拟墨画扇 提交于 2019-12-12 10:23:54
问题 I'm trying to return (values str ((+ x 3) y)) from the function it resides in. code snippet: (if (<my condition>) (values str ((+ x 3) y)) (values str ((+ x 2) y))) gives error: (+ X 3) SHOULD BE A LAMBDA EXPRESSION but (values str (y (+ x 3))) works fine. why? 回答1: The S-expression ((+ x 3) y) cannot be evaluated because the first list element is not funcallable (it should name a function or be a lambda expression). So, to avoid evaluation, you need to quote it: (if (<my condition>) (values

LISP - Program to search a specific function through its parameters

半腔热情 提交于 2019-12-12 10:08:29
问题 For a course project I got to write a program in lisp. The program should contain the most important lisp functions, their input and output parameters and maybe optional parameters. For example: function - first, input - list, output - object (first member of list). The program should work in 2 different ways: You give the program the name of a function and it should return the function parameters. You enter function parameters and if a function with these parameters exists, it should return

Implementing basic library functions in LISP (manually)

醉酒当歌 提交于 2019-12-12 10:07:55
问题 Is there any way by which I can define functions my_list , my_cons , my_append which perform similar function as list , cons and append respectively? Otherwise where can I find the implementation of these functions? Thanks 回答1: For my_list and my_append, the solutions are: (defun my_list (&rest arguments) `(,@arguments) ) (defun my_append (a_list an_item) `(,@a_list ,an_item) ) (my_append (my_list 'a 'b 'c) 'd) I'm probably wrong but I dont know any alternative method to make pairs, so an