lisp

Please advise on Ruby vs Python, for someone who likes LISP a lot

笑着哭i 提交于 2019-12-04 15:42:42
问题 I am a C++ developer, slowly getting into web development. I like LISP a lot but don't like AllegroCL and web-frameworks available for LISP. I am looking for more freedom and ability to do cool hacks on language level. I don't consider tabs as a crime against nature. Which one is closer to LISP: Python or Ruby? I can't seem to be able to choose from Python and Ruby: they seem very similar but apparently Ruby is more functional and object-oriented, which are good things, while Python is more

Is it possible to generate 40,000+ element of Fibonacci recursively in Lisp?

*爱你&永不变心* 提交于 2019-12-04 15:14:18
I'm trying to solve Project Euler question 2 with Lisp. This recursive solution blows the stack on execution, but I thought Lisp (using clisp) would recognize the tail recursion. This is being entered into the top-level. (defun e2-problem (&optional (f1 1) (f2 1) (sum 0)) "Sum fibonacci sequence, even terms up to 4 million" (if (> f2 4000000) sum) (e2-problem f2 (+ f1 f2) (if (evenp f2) (+ sum f2) sum)) Is my implementation not correctly arranged for optimization? I imagine this would hinder my Lisp education quite a bit if I could not rely on idiomatic recursion. 1) Correct syntax error in

How can I get all possible permutations of a list with Common Lisp?

会有一股神秘感。 提交于 2019-12-04 11:18:30
问题 I'm trying to write a Common Lisp function that will give me all possible permutations of a list, using each element only once. For example, the list '(1 2 3) will give the output ((1 2 3) (1 3 2) (2 1 3) (2 3 1) (3 1 2) (3 2 1)). I already wrote something that kind of works, but it's clunky, it doesn't always work and I don't even really understand it. I'm not asking for code, just maybe for some guidance on how to think about it. I don't know much about writing algorithms. Thanks, Jason 回答1

In common lisp, how can I check the type of an object in a portable way

橙三吉。 提交于 2019-12-04 10:51:07
问题 I want to define a method that will specialize on an object of array type with unsigned byte 8 elements. In sbcl, when you (make-array x :element-type '(unsigned-byte 8)) the object class is implemented by SB-KERNEL::SIMPLE-ARRAY-UNSIGNED-BYTE-8. Is there an implementation independent way of specializing on unsigned-byte array types? 回答1: Use a sharpsign-dot to insert the implementation dependent object class at read-time: (defmethod foo ((v #.(class-of (make-array 0 :element-type '(unsigned

Recursing in a lambda function

若如初见. 提交于 2019-12-04 10:28:24
问题 I have the following 2 functions that I wish to combine into one: (defun fib (n) (if (= n 0) 0 (fib-r n 0 1))) (defun fib-r (n a b) (if (= n 1) b (fib-r (- n 1) b (+ a b)))) I would like to have just one function, so I tried something like this: (defun fib (n) (let ((f0 (lambda (n) (if (= n 0) 0 (funcall f1 n 0 1)))) (f1 (lambda (a b n) (if (= n 1) b (funcall f1 (- n 1) b (+ a b)))))) (funcall f0 n))) however this is not working. The exact error is *** - IF: variable F1 has no value I'm a

Sending HTTP POST in Racket

限于喜欢 提交于 2019-12-04 09:57:54
I am trying to send a string via http/post in Racket, this is what I tried so far after reading the Racket HTTP Client Documentation #lang racket (require net/http-client) (define myUrl "https://something.com") (http-conn-send! (http-conn-open myUrl #:ssl? #t) #:version "1.1" #:method "POST" #:data "Hello") But with this I receive the following error: tcp-connect: connection failed detail: host not found address: https://www.w3.org/ port number: 443 step: 1 system error: nodename nor servname provided, or not known; errno=8 I tried it with several different adresses. I am new to racket and

Do property lists in Common Lisp refer to some global state?

孤街醉人 提交于 2019-12-04 09:26:12
The code below has z as a local variable, yet it behaves as if it is a global: (defun foo (m) (let ((z '(stuff nil))) (push m (getf z 'stuff)) (print z))) (foo 1) (foo 2) (foo 3) I would expect the output to be (STUFF (1)) (STUFF (2)) (STUFF (3)) T but when running it with SBCL I see (STUFF (1)) (STUFF (2 1)) (STUFF (3 2 1)) T Why is this the case? Is this behaviour peculiar to property lists? In foo , z is bound to the literal expression '(stuff nil) . The function destructively alters z , thus destructively changing the value of the literal. How LISP behaves in circumstances like this is

What are the tasks of the “reader” during Lisp interpretation?

本秂侑毒 提交于 2019-12-04 09:23:39
问题 I'm wondering about the purpose, or perhaps more correctly, the tasks of the "reader" during interpretation/compilation of Lisp programs. From the pre-question-research I've just done, it seems to me that a reader (particular to Clojure in this case) can be thought of as a "syntactic preprocessor". It's main duties are the expansion of reader macros and primitive forms. So, two examples: 'cheese --> (quote cheese) {"a" 1 "b" 2} --> (array-map "a" 1 "b" 2) So the reader takes in the text of a

Using Lisp or Scheme for runtime configuration of Java programs

╄→尐↘猪︶ㄣ 提交于 2019-12-04 09:19:33
问题 I have now seen several projects ending at a point where the actual configuration depended on things only available at run-time. The typical way to configure a Java program is to read one or more property files according to some application specific rules and then take action depending on their values. At one point or another this breaks down and you need actual program logic in your configuration which then can be indicated with a flag and adding code to your application which then handles

Replace an item in a list in Common Lisp?

一笑奈何 提交于 2019-12-04 08:55:30
问题 I have a list of things (I'll call it L), an index(N) and a new thing(NEW). If I want to replace the thing in L at N with NEW, what is the best way to do this? Should I get the sublist up to N and from N to the end of the list and then glue together a new list from the first part, NEW, and the last part using list? Or is there a better way to do this? 回答1: (setf (nth N L) NEW) should do the trick. 回答2: How often are you going to do this; if you really want an array, you should use an array.