Hi....
trouble in LISP ville,,,,
I'm finding that the recursive call to test2 on the (T condition
doesn't increment the divisor. this causes lots of trouble.
BUT I don't know how to fix it.....
Any Ideas????
(defun perf-nums (n)
(DO
((count 1 (+ 1 count )))
((> count n) 'Done)
(print count)
(print n)
(test-perfect count)))
(defun test-perfect (n)
(test2 n 2 0))
(defun test2 (n div sum)
(print n)
(print div)
(print sum)
(cond
((equal n div)
(cond
(( equal n sum
( print n)
(equal (mod n div) 0) (test2 n (+1 div) (+ sum div)))
(print n)
(print div)
(print sum)
(T (Test2 n div sum)))))))
From: Trent Buck
Subject: Re: No Joy in LISPville tonight.................................
Date:
Message-ID: <20050320144446.797def3d@harpo.marx>
Spake Kollege Boy:
> (defun perf-nums (n)
>
> (DO
> ((count 1 (+ 1 count )))
> ((> count n) 'Done)
^
If you indented your code conventionally, you'd notice that there's a
close-paren missing here.
> (print count)
> (print n)
> (test-perfect count)))
>
> (defun test-perfect (n)
> (test2 n 2 0))
>
> (defun test2 (n div sum)
> (print n)
> (print div)
> (print sum)
>
> (cond
> ((equal n div)
^^^^^
AFAICT the operands are always numeric. Therefore it is advisable to
use the numeric comparator '='.
> (cond
> (( equal n sum
> ( print n)
> (equal (mod n div) 0) (test2 n (+1 div) (+ sum div)))
> (print n)
> (print div)
> (print sum)
>
> (T (Test2 n div sum)))))))
I recommend you invest in an editor that understands Lisp syntax, such
as Emacs or Hemlock.
--
Trent Buck, Student Errant
I unplug the UPS every month or so so that the electric company thinks
the machines have been shut off. -- Graham Reed, sharing uptime DSW tips
"Kollege Boy" <···········@mnsu.edu> writes:
> Hi....
>
>
> trouble in LISP ville,,,,
>
> I'm finding that the recursive call to test2 on the (T condition
> doesn't increment the divisor. this causes lots of trouble.
>
> BUT I don't know how to fix it.....
>
> Any Ideas????
>
>
> (equal (mod n div) 0) (test2 n (+1 div) (+ sum div)))
+1 == 1
(+1 div) === (1 div)
1 is not a function...
Execution of a form compiled with errors:
(1 DIV)
Restarts:
0: [ABORT] Return to Top-Level.
Debug (type H for help)
(TEST2 2 2 0)
Source: (TEST2 N (1 DIV) (+ SUM DIV))
0]
--
__Pascal Bourguignon__ http://www.informatimago.com/
You never feed me.
Perhaps I'll sleep on your face.
That will sure show you.
You need a text editor that can automatically indent Lisp code. If you
had one, you wouldn't have so many problems with mismatched
parentheses.
Here are some:
emacs -- Good, and something you should learn to use.
Hemlock -- I haven't used it, but I hear it's nice.
LispWorks IDE -- For a newbie, I recommend this. It'll get you started
fast.
Good luck,
-Peter