First impressions

1 view
Skip to first unread message

noahr

unread,
Aug 26, 2008, 1:35:29 PM8/26/08
to Clojure
Some more first impressions from a newbie. The language is AWESOME,
but here are some of the first specific questions I wondered about.


1) I found myself wanting to do an import *, though I understand this
has been commented on already, and argued against. I'm not really
arguing FOR it, but I think a lot of Java developers will also have
the same thought and try to do that, especially on their inital
attempts to hack around on it.

2) The great attraction of lisp for me is the power to get rid of any
sort of redundancy wherever I see it. One of the very first things
that stood out to me about a Clojure program, was big long Java class
names at the top (imports), and again in the code itself. Regardless
of whether or not doing so would be a 'good' thing, it seemed to me,
especially in a lispy dynamic language like this, that there should be
some way to eliminate this. Consider the following:

(import '(me.stuff MyBigFatClassName))
(. MyBigFatClassName staticDoSomething)

It seems (to me) I ought to be able to replace MyBigFatClassName with
a variable/alias of some sort, or an expression/fn/macro that
evaluates to the same thing. I haven't yet found a way, maybe just due
to my ignorance. I do realize for instance expressions, u can have a
'let' variable assigned to the instance, and use that, but the
question remains for static access, method names, etc. Supposed i want
to replace 'System' with 's' and do a (. s out). I was especially
surprised using the (symbol "..") form didn't work.

3) On a super minor nit-picky note, I was surprised that some of the
'(pr ...)' ish methods didn't return the result of what they were
printing. One of the very first things I wanted to do was to wrap
another expression around (pr ..) for debugging purposes, but since it
didn't return its argument, I couldn't do this (it broke the higher up
expression using the value). Granted writing my own version that did
just this was super trivial, but I find myself wondering why you
wouldn't want functions to always return something if at all possible,
for convenience just in case it needs to be used. Maybe I'm missing a
conceptual reason why this is so?


Allen Rohner

unread,
Aug 27, 2008, 10:23:43 AM8/27/08
to Clojure

> 3) On a super minor nit-picky note, I was surprised that some of the
> '(pr ...)' ish methods didn't return the result of what they were
> printing. One of the very first things I wanted to do was to wrap
> another expression around (pr ..) for debugging purposes, but since it
> didn't return its argument, I couldn't do this (it broke the higher up
> expression using the value). Granted writing my own version that did
> just this was super trivial, but I find myself wondering why you
> wouldn't want functions to always return something if at all possible,
> for convenience just in case it needs to be used. Maybe I'm missing a
> conceptual reason why this is so?

Sorry, I'm noobish enough that I can only answer the third point. (pr)
is used to print a representation that the compiler will understand
later, (print) is for humans to read. Sort of like the difference
between __str__ and __repr__ in python, if you've used that. Look at
(println-str) that might do what you're looking for.

HTH,

Allen
Reply all
Reply to author
Forward
0 new messages