On Wed, May 18, 2011 at 8:06 PM, Sean Corfield <seancorfi...@gmail.com> wrote:
> Now, I will say here that most n00bs I've seen exposed to the REPL
> expect two things to "just work":
> 1. typing help or (help) should display _something_ useful (even if
> it's just a link to the docs),
> 2. typing exit, (exit), quit or (quit) should exit the REPL (if we
> tell them control-d works in advance, problem solved).

Easy enough to fix:

(ns clojure.core
  ...)

...

(def help "See http://www.foobar.com/baz/quux.html for a tutorial.")

(def exit "Type (quit) to exit.")

(defn quit [] (System/exit 0))

>> Rich Hickey likes to use single-character variables
>
> And the Library Coding Standards page emphasizes that:
> http://dev.clojure.org/display/design/Library+Coding+Standards
>
> (I'm surprised it doesn't recommend k / v for key / value when dealing
> with maps)

Probably should. Most of the short-and-descriptive but
more-than-one-letter names for things will tend to shadow core
functions. Shadowing e.g. list is bad enough; list isn't called very
often, and if it's been shadowed by an actual list, boom!

#<CompilerException java.lang.ClassCastException:
clojure.lang.PersistentList cannot be cast to clojure.lang.IFn>

right at the call site. The error message pretty much tells you
exactly what's going wrong there, too.

Shadowing map is much worse, as map is called quite often, and if it's
been shadowed by an actual map you'll be scratching your head for
hours:

(map f some-seq)

with an actual map in a local named "map" will attempt to look up f in
it, and on not finding it (extremely likely) will return some-seq as
the "not found" value. This of course is exactly what (map identity
some-seq) would be expected to do, so you're likely to think f is for
some inexplicable reason failing to actually do anything and may spend
quite a while testing and debugging f and tearing out your hair before
realizing what went wrong. Oh, I think the benefits of Clojure being a
Lisp-1 are worth this risk, but it's something to watch out for.
Fortunately, most IDEs highlight the names of core functions
distinctively, so you should instantly realize if you're shadowing
something while typing in a new let or loop binding or argvec.

-- 
Protege: What is this seething mass of parentheses?!
Master: Your father's Lisp REPL. This is the language of a true
hacker. Not as clumsy or random as C++; a language for a more
civilized age.

-- 
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