io - binding or passing crap around?

4 views
Skip to first unread message

Mike Benfield

unread,
Jan 13, 2008, 3:14:14 PM1/13/08
to Clojure
Is the intent that we primarily do text io via *in* and *out*, binding
them to a different reader/writer as necessary, or that we write
functions that actually accept readers and writers as arguments? When
pr and prn were modified to not accept a writer as an argument, I was
disgusted. But then I played with it and realized that worked just
fine, and that sometimes it was nice to use functions that operated
through vars rather than an explicit argument.

Mike

Rich Hickey

unread,
Jan 13, 2008, 5:26:18 PM1/13/08
to Clojure
There are sound arguments, with which I agree, that things like
Clojure's vars are necessary for program modularity:

http://lambda-the-ultimate.org/classic/message9361.html

Clojure's vars ensure thread independence and stack unwinding, so are
not 'disgusting' in the way globals are in other languages. I'm glad
you tried it, as I am satisfied with the defaults for prn et al. You
can always build a version that takes a writer when that makes sense.
If there's enough demand I guess the library could have prn-to etc.

One example of when vars win over explicit args is when you want to
use library functions like map, which don't 'thread' the args you
need.

Another way to look at it is as a policy decision - i.e. To where are
we printing? akin to, Are we logging?, To where?, To what database
should we connect? etc. All things I find extremely cumbersome to
thread though code in languages without dynamic vars. I've seen apps
with lots of policy args being threaded through stacks of functions
that shouldn't know or care.

Rich

Mike Benfield

unread,
Jan 15, 2008, 12:31:11 AM1/15/08
to Clojure
Yes, you have converted me. On a few other issues too.

Mike
Reply all
Reply to author
Forward
0 new messages