1

I have the following code:

(defun Areacircle ()
  (princ "Enter Radius: ")
  (defparameter radius (read))
  (defparameter area (* 3.1416 radius radius))
  (princ "Area: ")
  (write area))
(AreaCircle)

The problem is that, slime runs it with no problem but when I compile it with (compile-file "area.lisp" :output-file "area") it evaluates the (read) part first; it ask to pass the value to radius before printing anything.

Kolt Penny
  • 164
  • 1
  • 13
  • 1
    Look into force-output. – Joshua Taylor Oct 12 '15 at 17:27
  • 2
    Though not bad per se, it is unusual to use `defparameter` inside functions like you did. Also, I would write the function `circle-area`. Joshua Taylor is right about force-output (http://clhs.lisp.se/Body/f_finish.htm) – coredump Oct 12 '15 at 17:31

1 Answers1

1

Nothing in your code is forcing the (buffered) output to be sent to the terminal. Adding a call to (force-output) or (finish-output) will help.

Additionally, you re using defparameter where you should be using let. You're possibly also better off using pi instead of your approximation and using format with a suitable format string to print the result.

Vatine
  • 20,782
  • 4
  • 54
  • 70