smithzv wrote:Hmmm... is it really true that learning Lisp will help with RPL programming? Maybe learning Forth, but Lisp?
Anyway, to get you started, the error you are getting, ">: ANG is not a real number", is using "real" in the mathematic sense. It means that the data that symbol ANG contains is either complex, or not a number at all. It needs to be real because complex numbers (and of course anything that is not a number) cannot be greater than or less than something else; basic complex math. So the error is coming from the form (> z0 0).
Well, UserRPL is really similar to LISP, even though it uses RPN.
I thought the same thing, maybe the interpreter (is the right word) considered my input as a string, instead of a real number. But take a look at this program I wrote before the one I posted:
- Code: Select all
(setq vec (vector 45. 26.5650511771 14.0362434679 7.1250163489 3.576334375 1.78991060825 .895173710211 .447614170861 .223810500369 .111905677066 5.59528918938E-2 .027976452617 1.39882271423E-2 6.99411367535E-3 3.4970568507E-3 1.74852842698E-3 8.74264213694E-4 4.37132106872E-4 2.18566053439E-4 1.0928302672E-4 5.46415133601E-5 2.732075668E-5 1.36603783401E-5 6.83018917003E-6 3.41509458501E-6))
(format t "~% ~%Inserisci l'angolo da cercare: ")
(setq ang (read))
(setq calc 0)
(loop as i below 24
((> (- ang calc) 0) (setq calc (+ calc (svref vec i))))
((< (- ang calc) 0) (setq calc (- calc (svref vec i))))
(format t "L'angolo calcolato vale ~F° ~%" calc)
(format t "La differenza tra i due angoli vale ~F°" (abs (- calc ang)))
(format t "~% ~% ~%")
It is more or less the same, and there are no problems. Is there a funtion that can force the interpreter to consider real an input?
You may need to clarify what you mean by "run" if you need further help. For instance, ANG is not a real number is a quite likely error since ANG is read from the user. What did you input for ANG? I suspect that you invoking this from a command line, in which case it might be a good time to wrap it up in a single function and call it from the CLISP REPL where most people write their code to be run from. Once you have that working, you can make it invokable from the command line if you still desire.
I always insert 30 as input, so i can see if the program is correct (the output should be more or less 0.5).
The program is saved in a .lisp file, and then on the terminal I write clisp myfile.lisp
. Then I write the number and hit return (well, I would do these stuff, the error break the program before letting me do this).
By the way, the error is right in the line you said.
I cannot see an error in the program. Maybe the error message means ":ANG is not a real number". This could mean that you have mistakenly put a colon in front of ang somewhere else.
I can't either, the program is only the piece of code I posted. No colon anywhere