lisp

Haskell, Lisp, and verbosity [closed]

。_饼干妹妹 提交于 2019-12-31 07:53:05
问题 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 6 years ago . For those of you experienced in both Haskell and some flavor of Lisp, I'm curious how "pleasant" (to use a horrid term) it is to write

Converting numbers to english letter list

假装没事ソ 提交于 2019-12-31 05:42:10
问题 I have the function below which converts an input of numbers into the partially translated word output of those numbers. Using product and quotient, it adds the word representation of numbers while splitting the number into groups. For example: (number-name 87969087) -> '(87 million 969 thousand 87) (number-name 1000000) -> '(1 million) Im trying to complete my problem by fully translating those numbers which are less than 1000 as well. Im trying to implement a function less-than-1000 which

Setting up a equal function in common lisp using only “eq”

喜欢而已 提交于 2019-12-31 05:42:05
问题 I've given the assingment to write a function in common lisp to compare two lists to see if they are equal and I have been bared from using the "equal" predicate I can only use "eq" and I seem to come to a wall. I get this error with my code EVAL: variable SETF has no value The following restarts are available: and he code: (defun check(L1 L2) (cond ((eq L nil) nil) (setq x (first L1)) (setq y (first L2)) (setf L1 (rest L1)) (setf L2 (rest L2)) (if (eq x y) (check L1 L2)))) (defun b(L1 L2)

shuffle list without duplicate number in Lisp

余生颓废 提交于 2019-12-31 05:13:48
问题 I have this function to create a list with initial element from the other question list with initial-element are start from 99 to 0 in Lisp (defun newList (&optional(n 100)) (loop for i from (- n 1) downto 0 collect i)) (defun board (newList &optional(n 10)) (cond ((null newList) nil) (t (cons (subseq newList 0 n) (board (subseq newList n) n))))) (defun show-board (board) (format T "~%") (mapcar (lambda (x) (format T " ~A ~%" x)) board) (format nil "") ) (show-board (board (newList))) (99 98

How to display first N natural numbers, knowing the divisors in Lisp

点点圈 提交于 2019-12-31 02:54:44
问题 Display first N natural numbers, the divisors of which are only 2, 3 and 7. I wrote something like that. I am a beginner in Lisp. Thank you! defvar x 1 (defun numbers(n) if(mod x 2 ) (loop for x from 1 to n do(print x) ) ) print(numbers()) 回答1: Because I just had some time, you could have a look at this. Might not be the perfect solution but should be a good starting point for a beginner. Check out the books in the info tab to get into the syntax etc. (defun divisible-by (n m) "Returns T if N

seek for some explanation on SICP exercise 1.5

谁说胖子不能爱 提交于 2019-12-30 17:55:22
问题 The question can be found here. In the book, I found one description of normal order evaluation was: "An alternative evaluation model would not evaluate the operands until their values were needed. Instead it would first substitute operand expressions for parameters until it obtained an expression involving only primitive operators, and would then perform the evaluation." I also found another description in short: "fully expand and then reduce". In the exercise, I thought the definition of p

Changing a program while it is running

寵の児 提交于 2019-12-30 12:25:13
问题 Not sure if this is an emacs-SLIME issue or a CL issue or SBCL issue. I've heard it said that the interactive nature of Lisp allows for changing a program while the program is running. Not knowing the specifics of what is meant by this, I tried the following, placing this in a separate file: (defparameter repl-test-var 5) (defun repl-test () (format t "repl-test-var is: ~a" repl-test-var) (fresh-line) (when (not (equal (read-line) "quit")) (repl-test))) Then I compile and run (repl-test) and

Changing a program while it is running

北慕城南 提交于 2019-12-30 12:24:03
问题 Not sure if this is an emacs-SLIME issue or a CL issue or SBCL issue. I've heard it said that the interactive nature of Lisp allows for changing a program while the program is running. Not knowing the specifics of what is meant by this, I tried the following, placing this in a separate file: (defparameter repl-test-var 5) (defun repl-test () (format t "repl-test-var is: ~a" repl-test-var) (fresh-line) (when (not (equal (read-line) "quit")) (repl-test))) Then I compile and run (repl-test) and

How to convert a string to list using clisp?

一曲冷凌霜 提交于 2019-12-30 08:38:07
问题 How can i convert the string "1 2 3 4 5 6 7" into the list (1 2 3 4 5 6 7) elegantly? I am using CLISP. 回答1: Hint: Take a look at with-input-from-string. 回答2: You should use parse-integer in a loop. For example, using loop : (let ((string "1 2 3")) (loop :for (integer position) := (multiple-value-list (parse-integer string :start (or position 0) :junk-allowed t)) :while integer :collect integer)) ⇒ (1 2 3) If you need better control about the splitting, use the split-sequence or cl-ppcre

Can call-with-current-continuation be implemented only with lambdas and closures?

我们两清 提交于 2019-12-30 00:32:22
问题 Does anyone know if call/cc can be implemented with just lambdas and closures? It seems that call/cc interrupts the program's flow (like an exception) but lambdas and closures can't do that. Therefore I think call/cc can't be implemented via lambdas and closures. Any more ideas? 回答1: The question is not particularly clear, since what exactly does "implemented with just lambdas and closures" mean? In any case, continuations can be used in any language with closures by manually writing in