Lisp programs are strings No, they really aren't. Yes, they are. When you write a Lisp program, you encode bytes to a file, same as any other programming language. If you're going to claim that 'In most programming languages, programs are strings.' , then you can't say that Lisp programs aren't also strings. 2006-3-9 What I'm trying to do is have a lisp routine that prints all the tabs. This works if the printer is set up at each station. We are currently trying to convert it so all prints go through one machine on the server. That is where my lisp routine is having problems. Here is what I have. (defun c:W11 ( ) (foreach X (layoutlist) (command 'layout' 'set' x) (command '-plot' 'Y' ' ' 'Dell1700HP.
You have few missteps there: (defun is-prime (n d)(if (= d 1)(print 't')(if (= (% n d) 0)(print 'nil')First of all, don't print your results, just return them. Second, there's no% function, it's rem.The real error is how you make the recursive call. You have an extra parentheses there: (is-prime (n (- d 1) ))))); ^ ^in Lisp, parentheses signify a function call; but you don't intend to call n with an argument (- d 1), they both are arguments to is-prime. So we just need to change it to (is-prime n (- d 1) ))))So what does it do?
It counts down: d, (- d 1). And when (= d 1), it returns t. So, one way to call it is (defun is-prime (n &optional (d (- n 1)))(or (= d 1)(and (/= (rem n d) 0)(is-prime n (- d 1)))))but it is not the most efficient way,:) nor the most safe one, either. It is much better to count up, not down for one thing, because any number is far more likely to have a small factor than a larger one. Then, it lets us optimize where we stop. Well, you're halfway there.Here's my explanation in English:You have written in lisp a function is-prime (btw, 'yes or no' functions like that are usually named whatever-p in lisp) that tells you if n is relatively prime to d.What you need to do is go through all d's less than n, and if it's not relatively prime to any of them, return nil, but if after that loop you haven't returned nil, then return t.
![Please Please](/uploads/1/2/4/3/124392877/148540692.png)
Your friend here is the function 'mod', which tells you whether there is a remainder when its first argument is divided by its second.Something like: (defun primep (n)(cond((= 1 n) nil)(t(loop:with root = (isqrt n):with divisors = (loop:for i:from 3:to root:by 2:collect i):for d = (pop divisors):if (zerop (mod n d)):do (return nil):else:do (setf divisors (delete-if (lambda (x) (zerop (mod x d))) divisors)):while divisors:finally (return t)))))Also, don't print nil, just return nil.