Thank you, Meikel and Christian! - Srini
On Mar 9, 7:43 am, Christian Vest Hansen <karmazi...@gmail.com> wrote: > On Tue, Mar 9, 2010 at 6:26 AM, Srini <devfac...@gmail.com> wrote: > > Hi. I am completely new to clojure - my 3rd day or so. Need to go buy > > a book on the subject. So please help me with a couple of things: > > > Item 1) I have two calls to count. One works, and the other does not. > > > ; counts number of items in collection > > user=> (count (list 1 2 3 4 "er" 34) ) > > 6 > > > ; count does not work. I get an exception. Need to figure out what I > > am doing wrong here. > > user=> (count (list 23 "3er" oel" 5) ) > > java.lang.Exception: EOF while reading string > > You are missing a double-quotation character before eol" > > > > > > > > > Item 2) I see from the documentation that the contains? function (it > > is a function, right? just want to be sure. this is my 2nd or 3rd day > > learning about clojure.) returns true if key is present in collection. > > And there is a reference in the online docs to "numerically indexed > > collections like vectors and Java arrays". In the following examples, > > the first one works as I expected. But the second one does not work as > > I thought. How do I check if an item is in a list? > > > ; does the vector contain index 0? > > user=> (contains? [1 2 3 4] 0) > > true > > > ; could not get it to work for lists. apparently works only for > > numerically indexed collections like vectors. > > ; doesn't throw an exception either. "intuitively", I think the > > following should have returned true. > > user=> (contains? (list "3e" "2 tired" "1 more") "3e" ) > > false > > I think contains? only work on things that are associative: > > user=> (associative? []) > true > user=> (associative? (list)) > false > > So a list is not associative, as it has no (near) constant-time way of > looking up things in it by index, key or value. > > Maybe you want to use a set instead of a list: > > user=> (contains? #{"3e" "2 tired" "1 more"} "3e" ) > true > > > > > > > > > Your help is much appreciated. > > > Thank you for your time. - Srini > > As an aside, I guess I am approaching this as I have regular > > procedural languages like C, C++, Java, C#, VB, and my all-time > > favourite so far - Python, etc. And its taking a different kind of > > thinking to even understand the basics of closure since its just so > > different from the others. I am recording my learning experiences in > > my very first blog ever :)http://closurefp.blogspot.com/Hopefully it > > will help someone. > > > -- > > 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 > > -- > Venlig hilsen / Kind regards, > Christian Vest Hansen. -- 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