Re: Different behavior at REPL vs compiled code

2012-05-20 Thread Brandon Bickford
The type of "n" (passed to main) is a string. Command line arguments are strings.  - Brandon On Thu, May 17, 2012 at 11:39 PM, Ankit Goel wrote: > Hi, > > I have recently started learning clojure and have been setting up > leiningen for managing projects. > I create a new project using "lein n

Re: Different behavior at REPL vs compiled code

2012-05-19 Thread Armando Blancas
> > Why is there this difference in behavior between interactive and > compiled code? > In case you'd wonder why it works at the repl since what we type there are strings, too. The repl gets them through a call to (read) which parses strings into data structures that are Clojure code. This st

Re: Different behavior at REPL vs compiled code

2012-05-19 Thread Michael Gardner
On May 19, 2012, at 3:19 AM, Andy Fingerhut wrote: > Whereas Perl would automatically convert from a string to a number in a case > like this, Clojure does not. One could argue that such auto-conversion of > types, while convenient in many cases in Perl, is also a source of errors in > program

Re: Different behavior at REPL vs compiled code

2012-05-19 Thread Andy Fingerhut
Clojure does "know" the type -- it knows that it is a string, rather than a number, and it does not support doing arithmetic operations on strings, hence the error. Whereas Perl would automatically convert from a string to a number in a case like this, Clojure does not. One could argue that su

Re: Different behavior at REPL vs compiled code

2012-05-19 Thread Ankit Goel
Thanks a lot for the help Meikel and Jim. @ Meikel: it worked great as per your suggestion. I was just hoping it would be a bit more dynamic and infer the types!! On May 18, 11:48 pm, "Jim - FooBar();" wrote: > Try wrapping your if statement in a let with a binding : [k > (Integer/parseInt n) ]

Re: Different behavior at REPL vs compiled code

2012-05-18 Thread Jim - FooBar();
Try wrapping your if statement in a let with a binding : [k (Integer/parseInt n) ] and then use k from then onas Ankit said, arguments passed from cmd are always strings... Jim On 18/05/12 07:39, Ankit Goel wrote: Hi, I have recently started learning clojure and have been setting up lei

Re: Different behavior at REPL vs compiled code

2012-05-18 Thread Meikel Brandmeyer
Hi, because in the repl you probably call (fact 1) while running the same from the commandline passes a string: (fact "1"). You should get the same error when calling the fact functions with a string at the repl. Kind regards Meikel -- You received this message because you are subscribed to t

Different behavior at REPL vs compiled code

2012-05-18 Thread Ankit Goel
Hi, I have recently started learning clojure and have been setting up leiningen for managing projects. I create a new project using "lein new" and modified the "src/ factorial/core.clj" file to contain the following code (ns factorial.core (:gen-class)) (defn fact [n] (if (= n 1) 1