Lisp format a character a number of times
It’s nice to see so many solutions: ~A, ~<, and ~{ so far. The ~@{ iteration construct provides a concise solution: (format nil “~v@{~A~:*~}” 3 #\*)
It’s nice to see so many solutions: ~A, ~<, and ~{ so far. The ~@{ iteration construct provides a concise solution: (format nil “~v@{~A~:*~}” 3 #\*)
Here’s what I’d do: (ql:quickload “alexandria”) (alexandria:flatten list) That works mainly because I have Quicklisp installed already.
Let’s do this. • I know that lazy sequences only evaluate the items in the sequence that are asked for, how does it do this? Lazy sequences (henceforth LS, because I am a LP, or Lazy Person) are composed of parts. The head, or the part(s, as really 32 elements are evaluated at a time, … Read more
function (aka #’) is used to quote functions, whereas quote (aka ‘) is used to quote data. Now, in Emacs-Lisp a symbol whose function cell is a function is itself a function, so #’symbol is just the same as ‘symbol in practice (tho the intention is different, the first making it clear that one is … Read more
Here’s another approach that celebrates Clojure’s Java interop. This takes 374ms on a 2.4 Ghz Core 2 Duo (running single-threaded). I let the efficient Miller-Rabin implementation in Java’s BigInteger#isProbablePrime deal with the primality check. (def certainty 5) (defn prime? [n] (.isProbablePrime (BigInteger/valueOf n) certainty)) (concat [2] (take 10001 (filter prime? (take-nth 2 (range 1 Integer/MAX_VALUE))))) … Read more
LET itself is not a real primitive in a Functional Programming Language, since it can replaced with LAMBDA. Like this: (let ((a1 b1) (a2 b2) … (an bn)) (some-code a1 a2 … an)) is similar to ((lambda (a1 a2 … an) (some-code a1 a2 … an)) b1 b2 … bn) But (let* ((a1 b1) (a2 … Read more
How about (defun get-file (filename) (with-open-file (stream filename) (loop for line = (read-line stream nil) while line collect line)))
There are two different issues: First: Dynamic binding as a bug Not sure what he means, but generally in McCarthy’s EVAL the use of dynamic binding can be seen as a bug. He does not implement lexical scope for variables. The bug shows up for example here: http://www-formal.stanford.edu/jmc/recursive/node3.html See the functions maplist and diff. Both … Read more
(note: the answer is at the bottom of this post) The 2nd function, (define (swap-ends x) ; swap [] = [] (if (or (equal (length x) 0) (equal (length x) 1)) ; swap [x] = [x] x ; swap (x:xs) (cons (first (swap-ends (rest x))) ; | (a:b) <- swap xs (swap-ends (cons (first x) … Read more
Multiple Values in CL The language Common lisp is described in the ANSI standard INCITS 226-1994 (R2004) and has many implementations. Each can implement multiple values as it sees fit, and they are allowed, of course, to cons up a list for them (in fact, the Emacs Lisp compatibility layer for CL does just that … Read more