On Tue, Dec 7, 2010 at 2:15 AM, javajosh <javaj...@gmail.com> wrote:
> Mike and I have had a nice off-line conversation where we enumerated
> the possible things that can come after open-parens. I listed 7, he
> added 3:
>
>> 1. A value (if the paren has a tick '(  )
>> 2. A function.
>> 3. A map - which is a psuedo function that takes a key as an arg.
>> 4. A keyword - which is a psuedo function that takes a map as an arg.
>> 5. A macro. This is the normal case, I think. Looking through the mailing
>> list, it appears that most clojure programming questions revolve around
>> which one of the hundreds of macros to invoke and in which order!
>> 6. The Java form: (MyClass. )
>> 7. The java method form (.doSomething)
> 8. A function returning a function to invoke - ((find-my-function) )
> 9. A loop - (recur )
> 10. The anonymous function macro: #( )
>
> So, at least I know why I feel uneasy about open paren! It's super
> overloaded.

Not really. (...) is a non-atomic s-expression. If it's evaluated
unquoted, the first nested s-expression is evaluated and if it's not
callable an exception is thrown. Macros, special forms (which are sort
of like system-internal macros and are used to build all the other
macros, and functions), Java constructors, Java methods, and functions
are callable (and maps and keywords -- also vectors -- act as
functions for this purpose).

The only real overloading always involves macros:

#() evaluates to a function and doesn't run its insides right away.
Then again so does (defn foo [x] (inc x)) -- the (inc x) is run when
foo is called, calling inc, but not when the (defn ...) is called.
Macros can delay evaluation of their contents, and #() is a reader
macro.

'(x y z) is another reader macro and expands to (quote (x y z)).

And lastly some macros use a Common Lisp style of expecting a
parenthesized list argument whose first element isn't (at some point)
called as an invokable of some sort. The ns macro is particularly
guilty of this. I say guilty because I think it's bad design, which I
guess may have been grandfathered in before the standard was settled
on to use [] around non-executable lists of data such as binding
lists. (In some cases the first element, e.g. when it's :use or
:require, can be thought of as a pseudo-operator defined solely within
the ns form. I don't have an objection in cases where the first
element of the list can be thought of as a command or a call of some
sort. But many of the nested inputs to e.g. :use have the stain.)

But

(x y z w)

is similar to C's

x(y z w);

or Java's

y.x(z w);

in what it generally means. Except when quoted, or in a few macro
arguments (particularly, ns arguments).

> Mike also points out that things that aren't functions (not used in
> that context) can't be aliased with def or use.

Really?

user=> (def a 3)
#'user/a
user=> (def b a)
#'user/b
user=> b
3

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to