lisp

Lisp / Clojure: Is it a good idea to write function generating macros?

旧街凉风 提交于 2020-01-03 09:25:07
问题 This question asks to create a Clojure macro to generate several functions. We figured out a way to do this but were stuck with the question of "Is this a good idea?". My initial reaction is not really , for two reasons You then have functions that are not defined in your code, and this can complicate understanding your code quite a bit! (Imagine somebody has a problem with one of your functions and looks at the source code only to not find it anywhere). It is better to factor out the

Vertical align floats on decimal dot

蓝咒 提交于 2020-01-03 07:19:12
问题 Is there a simple way to align on the decimal dot a column of floats? In other words, I would like an output like the one of (vertical bars '|' are there only for clarity purpose) (format t "~{|~16,5f|~%~}" '(798573.467 434.543543 2.435 34443.5)) which is | 798573.44000| | 434.54355| | 2.43500| | 34443.50000| but with trailing spaces instead of zeros, as follows: | 798573.44 | | 434.54355| | 2.435 | | 34443.5 | 回答1: I do not think that this can easily be done with format 's inbuilt control

Remove integers from list

匆匆过客 提交于 2020-01-03 04:25:14
问题 I have a strange problem that couple of hours can't implement in Scheme. Let's say we have: (define x '( (Orlando (NY 3)) (Chicago (Montana 5) (Orlando 8)) ...and so on ... ) I want to transform it to '( (Orlando NY) (Chicago Montana Orlando) ...and so on ... ) Any help would be greatly appreciated. 回答1: You could also try (map (lambda (x) (cons (car x) (map car (cdr x)))) x) 来源: https://stackoverflow.com/questions/20749277/remove-integers-from-list

Common Lisp: is delete-if the same as setf + remove-if?

懵懂的女人 提交于 2020-01-02 07:31:13
问题 The following code generates prime from 1 to n: (defun prime-list(n) (let ((a)(b)(x (floor (sqrt n)))) (loop for i from (floor n 6) downto 1 do (push (1+ (* 6 i)) a) (push (1- (* 6 i)) a)) (loop while (<= (car a) x) do (push (car a) b) (setf a (remove-if #'(lambda(m)(or (= 0 (mod m (car a))) (> m n))) a))) (append '(2 3) (reverse b) a))) It seems to me the part (setf a (remove-if #'XXX a)) can be replaced by (delete-if #'XXX a) And I hoped this would make it faster. However when I made that

Lisp Formatting Polynomial

自作多情 提交于 2020-01-02 07:21:33
问题 I am representing sparse polynomials as lists of (coefficient, pairs). For example: '((1 2) (3 6) (-20 48)) => x^2 + 3x^6 - 20x^48 I am new to Lisp formatting, but have come across some pretty nifty tools, such as (format nil "~:[+~;-~]" (> 0 coefficient)) to get the sign of the coefficient as text (I know, that's probably not idiomatic). However, there are certain display problems when formatting single terms. For example, the following should all be true: (1 0) => 1x^0 => 1 (reducible) (1 1

Equivalent of 'lein swank' to other Lisp/Scheme implementations with emacs/slime

别等时光非礼了梦想. 提交于 2020-01-02 05:42:06
问题 I've been using emacs/slime for coding lisp, but with Clojure I found 'lein swank'. I must say that it's pretty useful, as I can connect to a server that runs clojure. How about the other Lisp implementations? What Lisp implementations provide the equivalent of 'lein swank' in Clojure? I mean, is there any other Lisp implementations that provide server connectivity so that I use 'M-x slime-connect', not just 'M-x slime'? 回答1: Non-clojure swank backends don't need a lein swank equivalent since

Plotting data sequentially from emacs using Common Lisp and Gnuplot

假装没事ソ 提交于 2020-01-02 04:53:27
问题 Assume that I have some array of data (a vector to be specific). Can I plot it element by element sequentially using Gnuplot such that it seems as if it is a real life signal that is being traced through a monitor? I know that I can write the whole data into a text file using Common Lisp, then using gnuplot I can plot it in a batch format. What I require is that I want to put a point on my plot as data comes sequentially. Data will probably be generated inside a loop, thus you may consider x

How do I manage common lisp dependencies?

一个人想着一个人 提交于 2020-01-02 03:17:17
问题 What's the lisp equivalent of a pip requirement file, ruby gemfile, node package.json, etc? I'm not entirely sure how asdf and quicklisp relate if those are the proper things to use. 回答1: A .asd file is a requirements file. Use quicklisp to install requirements. Use ASDF to define a "system". Create a my-system.asd file. (asdf:defsystem #:my-system :serial t :description "Describe my-system here" :author "My Name <my.name@example.com>" :license "Specify license here" :depends-on (#

Lisp data security/validation

▼魔方 西西 提交于 2020-01-02 03:01:06
问题 This is really just a conceptual question for me at this point. In Lisp, programs are data and data are programs. The REPL does exactly that - reads and then evaluates. So how does one go about getting input from the user in a secure way? Obviously it's possible - I mean viaweb - now Yahoo!Stores is pretty secure, so how is it done? 回答1: The REPL stands for Read Eval Print Loop. (loop (print (eval (read)))) Above is only conceptual, the real REPL code is much more complicated (with error

Changing the nth element of a list

≯℡__Kan透↙ 提交于 2020-01-02 00:52:16
问题 I want to change the nth element of a list and return a new list. I've thought of three rather inelegant solutions: (defun set-nth1 (list n value) (let ((list2 (copy-seq list))) (setf (elt list2 n) value) list2)) (defun set-nth2 (list n value) (concatenate 'list (subseq list 0 n) (list value) (subseq list (1+ n)))) (defun set-nth3 (list n value) (substitute value nil list :test #'(lambda (a b) (declare (ignore a b)) t) :start n :count 1)) What is the best way of doing this? 回答1: How about