If Clojure type checking becomes a frequent request/complaint, please
build a lint type tool, not some twisted logic embedded in the
compiler :)))

C did not have any decent type checking when it came out and we had to
use lint to find bad parameter on fn calls and other similar errors.
They were no function prototypes at the time so passing a pointer
address instead of the pointer value did not bother the compiler at all.
In fact you could pass crap in most places and end up at run time with a
bad pointer address or corrupted stack.

You cannot call C a dynamic language, a semi-assembler that evolved to a
higher status over time, 
however it lacked basic type checking in it's early incarnations...
Quite a challenge for a typed language (byte, short, int, long, 8? 16?
32 bits ?).
Debugging stack corruptions daily is not really an efficient way to
program so rules where added to the compiler to eventually
flag data type improper uses.

I never saw a dynamically typed language that had type checking at
compile time :))) In my mind it's mutually exclusive...

Lisp compilers came out in the 1970s if I recall. To compile Lisp you
needed special declarations to define unbound variables and other
similar things
to get the compiler to create a runnable file.
Symbols where not bound to lexical scope so the compiler needed some
hints from time to time telling it that these things would eventually be
available at run time.
This did not apply to symbols within a function, they could appear
without an explicit declaration. It was assumed they were
somewhere on the stack at run time. That's even more dynamic that what
Clojure allows... maybe a bit too much.

The Clojure compiler is in the same vein, it checks for undeclared stuff
BUT mandates that everything used be visible in the lexical
scope. No run time bindings not lexically visible are allowed, that's a
very good compromise, debugging for missing dynamic bindings on the
stack
at run time is not very funny.

This compiler has nothing to do with a data typed compiler that
validates that the "proper" typed variables are used in an acceptable
manner... 

These are two unrelated things. We call them both "compilers" but its
not required for a compiler to do data type checking.
The only thing they may have in common is that they both generate code.


Luc

On Tue, 2009-12-15 at 06:20 -0800, Tayssir John Gabbour wrote:

> On Dec 15, 1:23 pm, Baishampayan Ghose <b.gh...@ocricket.com> wrote:
> > PS - If you are worried about "compile time type checking", I think it's
> > prudent to mention now that Clojure is a dynamically typed programming
> > language where types are checked at run-time and not compile time.
> 
> Actually, there are Common Lisp compilers (like SBCL) which signal a
> warning if they infer a type error. I think it's handy, and doesn't do
> anything drastic like refuse to compile your program because of it.
> 
> 
> All the best,
> Tayssir
> 
> 
> On Dec 15, 1:23 pm, Baishampayan Ghose <b.gh...@ocricket.com> wrote:
> > Ajay,
> >
> > > It tried the following in REPL and got no error. Personally, I feel that
> > > I should get an error because calling square on strings is wrong in both
> > > cases.
> >
> > > Is there a way out of this in Clojure?
> >
> > > |(defn square[n]  (*  n n))
> >
> > > (if  (=  0  0)  (println"hello")  (map square["a"  "b"]))
> >
> > What did you expect from Clojure? In the above form the `map` is a part
> > of the else form and that's why it's not executed.
> >
> > If you don't know already, the syntax for `if` in Clojure is like this -
> >
> > (if expression
> >    (then form)
> >    (else form))
> >
> > If you have multiple then or else forms, you can wrap them inside a `do`
> > form like this -
> >
> > (if expression
> >    (do
> >      (then form)
> >      (more then form))
> >    (else form))
> >
> > > The following gives error (because it gets evaluated):
> >
> > > |(defn square[n]  (*  n n))
> >
> > > (if  (=  0  1)  (println"hello")  (map square["a"  "b"]))
> >
> > In the above form, the map is a part of the else form and since 1 is not
> > equal to 0, the `map` is executed.
> >
> > I hope your confusion is cleared.
> >
> > PS - If you are worried about "compile time type checking", I think it's
> > prudent to mention now that Clojure is a dynamically typed programming
> > language where types are checked at run-time and not compile time.
> >
> > Regards,
> > BG
> >
> > --
> > Baishampayan Ghose <b.gh...@ocricket.com>
> > oCricket.com
> 

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