everything is wrong

Discussion of Common Lisp
hill0093
Posts: 8
Joined: Sun Sep 21, 2014 12:56 am

Re: everything is wrong

Post by hill0093 » Tue Sep 23, 2014 8:40 am

I used you're model and tried several calls following it, and they were correct:
CL-USER 1 > (defun intDiv (num den)
(let ((ans (truncate num den)))
ans))
INTDIV

CL-USER 2 > (print (intDiv -3 2))

-1
-1

CL-USER 3 > (print (intDiv -2 2))

-1
-1

CL-USER 4 >

Why do I get two prints from Lispworks for each call?

hill0093
Posts: 8
Joined: Sun Sep 21, 2014 12:56 am

Re: everything is wrong

Post by hill0093 » Tue Sep 23, 2014 8:46 am

I used you're example and several calls which were all correct.
CL-USER 1 > (defun intDiv (num den)
(let ((ans (truncate num den)))
ans))
INTDIV

CL-USER 2 > (print (intDiv -3 2))

-1
-1

CL-USER 3 > (print (intDiv -2 2))

-1
-1

CL-USER 4 >
Why are there two answer prints from Lispworks for each print call?

Goheeca
Posts: 271
Joined: Thu May 10, 2012 12:54 pm
Contact:

Re: everything is wrong

Post by Goheeca » Tue Sep 23, 2014 8:49 am

print returns its first argument and your Lispworks is running REPL. When you want test your function just call it in the REPL and don't use print, it's redundant.
cl-2dsyntax is my attempt to create a Python-like reader. My mirror of CLHS (and the dark themed version). Temporary mirrors of aferomentioned: CLHS and a dark version.

hill0093
Posts: 8
Joined: Sun Sep 21, 2014 12:56 am

Re: everything is wrong

Post by hill0093 » Tue Sep 23, 2014 9:31 pm

(setf linDa 735868) ;linDa of 20140927 is 735868
(print linDa)
;int r=linDa+1721060+68569;
(setf r (+ linDa 1721060 68569))
(print r)
;int f=4*r/146097; //if both are integer type, quotient is integer
(setf f (truncate (* 4 r) 146097))
(print f)
;r=r-(146097*f+3)/4;
(setf r (- r (truncate (+ (* 146097 f) 3) 4)))
(print r)
;int y=4000*(r+1)/1461001;
(setf y (truncate (* 4000 (+ r 1)) 1461001))
(print y)
;r=r-(1461*y/4-31);
(setf r (- r (- (truncate (* 1461 y) 4) 31)))
(print r)
;int m=80*r/2447;
(setf m (truncate (* 80 r) 2447))
(print m)
;int da=r-2447*m/80;
(setf da (- r (truncate (* 2447 m) 80)))
(print da)
;r=m/11;
(setf r (truncate m 11))
(print r)
;int mo=m+(2-12*r);
(setf mo (+ m (- 2 (* 12 r))))
(print mo)
;int yr=100*(f-49)+y+r;
(setf yr (+ (* 100 (- f 49)) y r)
(print yr)
;int calDa=yr*10000+mo*100+da;
(setf calDa (+ (* yr 10000) (* mo 100) da))
(print calDa)
;return(calDa)

I am trying to translate some simple java code to Lisp.
I place the exact above code into "LispWorks 6.1 Personal" and
and yr and calDa do not print (why?) but the previous ones print and
agree exactly with a similar version of my java code which I know
is correct because it's been extensively tested.

Post Reply