Arc Forumnew | comments | leaders | submitlogin
1 point by ryantmulligan 6173 days ago | link | parent

Why does prn only return the result of its first argument?

  arc> (prn "hello, " "world")
  hello, world
  "hello, "
Can anyone think of when this is useful at all?


2 points by eds 6171 days ago | link

This is exactly how print, et al work under CL.

I suspect it is a debugging thing. Since pr and prn return their first argument verbatim you can put them in the middle of working code to find what the return value of something is, without breaking anything. As a trivial example:

(+ (prn 2) 3) ; prints 2 and returns 5

Maybe you wouldn't need it if you had a fancy debugging suite, but it can be useful if you are debugging manually.

-----

1 point by bogomipz 6173 days ago | link

I think the reason is that returning the concatenation would be very expensive. It would basically require a temporary write stream just to put together the return value. In the majority of cases, the return value is probably not even used.

To get the effect you want, simply concatenate as a separate step:

  (prn (string "hello, " "world"))

-----

1 point by akkartik 6173 days ago | link

But why not return the last element?

-----