On Mon, Jun 14, 2010 at 4:09 PM, Jared <tri...@gmail.com> wrote:

> I'm trying to grok this hello world template before I move on to other
> stuff. What is the ns line for? I read the documentation on ns, but it
> didn't make much sense to me. Is ns related to scope? All I know is
> when I delete the ns line the program doesn't compile.
>

It's might not be that constructive to grok the hello world template before
moving on. That template is largely about creating a Java executable.

ns creates a namespace. It allows your program to modular and prevents the
likelihood of name clashes.

my-namespace/foo
your-namespace/foo

This way to two functions can have the same name yet be used together in the
same program.


> Why is it that function declarations must have the arguments as
> vector(s), and not lists? As in, why can't I declare a function like
> this?
> (defn my-test
>  (list n)
>     (+ n 1))
>

This is a Clojure syntax thing. Bindings happen inside of vectors.


> In that default template, why does that hello world program even run?
> At what line is main called? By the way, thank you nickikt for the
> explanation that main is an overloaded function. That was not obvious
> to me.
>

ns declaration here is being used to generate a Java class from this
namespace. The class that defines main in a Java program is the entry point.


> Also, I thought this language is functional but I'm able to do change
> declarations in the repl. For example:
> user=> (def x 1)
> #'user/x
> user=> x
> 1
> user=> (def x 2)
> #'user/x
> user=> x
> 2
> user=> (def x (+ 1 x))
> #'user/x
> user=> x
> 3
>

This is definitely one way to introduce mutability into your program but
this is considered bad form.

David

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