Overloading a clojure.core name in my namespace
Hello all, I want to name a function of mine load in my namespace home.a. The contents of a.clj (in the home directory in one of the root directories of my CLASSPATH, as expected) is (ns a (:refer clojure.core :exclude (load))) (defn load [] 'value) When I (use 'home.a) from the REPL, I get error message: java.lang.Exception: Name conflict, can't def load because namespace: com.benoithamelin.trunk.a refers to:#'clojure.core/load (a.clj:4) I thought the :refer clause of the (ns) form would effectively remove the clojure.core/load mapping to load within my namespace. Is this a bug? Thank you, Benoit --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Overloading a clojure.core name in my namespace
By the way, I am using clojure r1099, porting my stuff (which use to work) across the breaking changes of r1098. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Simple isa? question—ISeq and Sequential
On the type chart (http://clojure.googlegroups.com/web/chart.png? gda=ODsxtzsAAABoLitVpBTEcNIQc_NHg39S4VDJlSuqwy9lITiADmvt9Suq- FEWrXmgYiTWWcOQKecGRdr3QrylPkw2aRbXD_gF), it indicates that ISeq implements Sequential. So why is this false? (isa? clojure.lang.ISeq clojure.lang.Sequential) Incidentally, this is true: (isa? clojure.lang.ASeq clojure.lang.ISeq) Is the chart incorrect? --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Simple isa? question—ISeq and Sequential
On Fri, Nov 14, 2008 at 10:04 AM, samppi [EMAIL PROTECTED] wrote: On the type chart (http://clojure.googlegroups.com/web/chart.png? gda=ODsxtzsAAABoLitVpBTEcNIQc_NHg39S4VDJlSuqwy9lITiADmvt9Suq- FEWrXmgYiTWWcOQKecGRdr3QrylPkw2aRbXD_gF), it indicates that ISeq implements Sequential. So why is this false? (isa? clojure.lang.ISeq clojure.lang.Sequential) Incidentally, this is true: (isa? clojure.lang.ASeq clojure.lang.ISeq) Is the chart incorrect? The change to make ISeq extend Sequential was checked in Mon Oct 6. I assume you're using a version older than that. --Chouser --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
exiting REPL
In the Getting Started section of the wiki it says Press Ctrl+C to get out of it. Shouldn't that be Ctrl+D? That works for me on a Mac and seems cleaner. -- R. Mark Volkmann Object Computing, Inc. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Overloading a clojure.core name in my namespace
That's true only if you use the :refer-clojure (all one keyword): (ns a (:refer-clojure :exclude (load))) No, it doesn't work. The same error message is displayed. It is the same for the clojure.contrib.mmap and clojure.contrib.zip- filter libraries, which have a (:refer-clojure :exclude (%)) clause in their (ns) form. When (use)'ing them in the REPL, one has failure with the same exception thrown. Again, might it be a bug with the r1098 breaking changes? --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: exiting REPL
On Fri, Nov 14, 2008 at 4:43 PM, Mark Volkmann [EMAIL PROTECTED] wrote: In the Getting Started section of the wiki it says Press Ctrl+C to get out of it. Shouldn't that be Ctrl+D? That works for me on a Mac and seems cleaner. Ctrl+D works on Unix. I am pretty sure I have used the equivalent Ctrl+Z to get out of the Repl on Windows. I'm not sure it really makes a difference, though, and maybe there's no point having different instructions for Windows vs. Mac/Linux/whatever when Ctrl+C will work on all of those. -- Michael Wood [EMAIL PROTECTED] --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Simple isa? question—ISeq and Sequential
I see. Yes, I downloaded the latest release on SourceForge, version 20080916. I don't know how to use SVN so I can't get the bleeding edge, but it's okay. I was just puzzled. Thanks for answering! On Nov 14, 8:09 am, Chouser [EMAIL PROTECTED] wrote: On Fri, Nov 14, 2008 at 10:04 AM, samppi [EMAIL PROTECTED] wrote: On the type chart (http://clojure.googlegroups.com/web/chart.png? gda=ODsxtzsAAABoLitVpBTEcNIQc_NHg39S4VDJlSuqwy9lITiADmvt9Suq- FEWrXmgYiTWWcOQKecGRdr3QrylPkw2aRbXD_gF), it indicates that ISeq implements Sequential. So why is this false? (isa? clojure.lang.ISeq clojure.lang.Sequential) Incidentally, this is true: (isa? clojure.lang.ASeq clojure.lang.ISeq) Is the chart incorrect? The change to make ISeq extend Sequential was checked in Mon Oct 6. I assume you're using a version older than that. --Chouser --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Overloading a clojure.core name in my namespace
On Nov 14, 2008, at 11:21 AM, [EMAIL PROTECTED] wrote: Okay, maybe I have not caught on the semantics of (use) and (refer). Let me extend my example a bit. File home/a.clj: (ns home.a (:refer-clojure :exclude (load))) (defn load [] 'my-load) (defn other-fn [] 'other-fn) Then, I start a fresh REPL and: user= (use :verbose ['home.a :as 'a]) (clojure.core/load /com/benoithamelin/trunk/a) java.lang.IllegalStateException: load already refers to: #'clojure.core/load in namespace: user (NO_SOURCE_FILE:0) (clojure.core/in-ns 'user) (clojure.core/alias 'a 'com.benoithamelin.trunk.a) (clojure.core/refer 'com.benoithamelin.trunk.a) (The five lines following the invocation are printed along the execution of the (use) application.) So, the exception that is thrown does not interrupt the execution of the (use) application, which surprises me. That surprises me too. I'll take a look at why that is. Moreover, it refers all the mappings in home.a to the current namespace. I thought that the [... :as ...] clause mapped each public mapping m of home.a to a/m; not to the current namespace. Your model of what's going on would be true if you called require instead of use. use also refers the loaded namespace(s) into the current namespace. --Steve --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Just Wondering: Tag metadata
There's no way to check types at compile time? (defn len2 [#^String x] (. x (length))) (defn wrong [] (len2 10)) Would be good if you could find such errors at compile time. Optional static typing =) Regards. Islon On 12 nov, 21:43, Rich Hickey [EMAIL PROTECTED] wrote: On Nov 12, 7:21 pm, samppi [EMAIL PROTECTED] wrote: Ah, yes. I meant, what are these hints? What does the compiler change? Is it some sort of informal type enforcement or something? The hints are described here: http://clojure.org/java_interop#typehints It is strictly a performance optimization so calls to Java can avoid reflection. There is no compile-time enforcement. Rich --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Correct place to report bugs?
Is this mailing list the correct place to report bugs? The bug list on the SF page looks pretty sparse. -- Howard M. Lewis Ship Creator Apache Tapestry and Apache HiveMind --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Correct place to report bugs?
On Fri, Nov 14, 2008 at 12:16 PM, Howard Lewis Ship [EMAIL PROTECTED] wrote: Is this mailing list the correct place to report bugs? The bug list on the SF page looks pretty sparse. Yes, this is a fine place to report bugs. --Chouser --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
multi-method dispatch for structs
Hi, I'm working on a library where I'd like to be able to dispatch off of whether the arguments are one of a number of different possible structs. I've created a custom hierarchy and everything makes sense with derive etc., but I don't understand how I convert from input values to the symbols needed for calls to (isa? ...) Anyone know how to do this? Does my dispatch function have to inspect the passed in values to figure out which type of struct they are, or can I query that somehow? Thanks, Jeff --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Patch: precompiling Clojure core sources in Ant build script
On Nov 14, 12:51 pm, Stuart Sierra [EMAIL PROTECTED] wrote: Patch attached. This precompiles everything except parallel.clj, which requires an extra Jar. It also omits the source .clj files from the clojure.jar file. -Stuart Sierra Patch applied (svn 1101) - thanks! Rich --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Print compiled Clojure svn revision?
Ok, will submit a patch for this early next week. Current plan is to use a properties file (versioninfo.properties) that will be generated from the ant build script and contain the release version/name, the source repository, a revision indicator (number, tag, or digest), and who built it. All the properties may be defined on the command line when running ant jar. If the properties are not defined, the ant updated build script will try to determine them. The versioninfo.properties file will be included in the jar and loaded by core.clj. Two considerations: * Should we store the properties as a Clojure map instead of as a Java properties file? * Should we generalize versioninfo.properties to clojure.properties with a version prefix? E.g., version.release- name. -Matt On Nov 14, 2008, at 11:43 AM, Graham Fawcett [EMAIL PROTECTED] wrote: On Sat, Nov 8, 2008 at 12:03 PM, Matt Revelle [EMAIL PROTECTED] wrote: If marking SVN revisions and/or release versions is something we still want and want automated, it now looks like using the build tool is the only way to go. The example I sent earlier to the list includes the creation of a versioninfo file from the build script which is then read and stored in a version var in boot.clj. The only problem is that the build script now depends on the svnversion command being available and a SVN repository being used for building. For tarball releases of the source, the versioninfo file can be generated for the release and the build script modified to use the existing file if svnversion isn't working. As for supporting git and other SCMs used to mirror the SVN repos, the build script can be made to use the tools available in any of the other SCMs to identify the SVN revision and generate the versioninfo file. +1. I think it's worth it, and would really like to see this put in place. Best, Graham --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Programming Clojure updated to match the AOT compilation release
Hi all, Make sure you update to Beta 2 of the book [1] and download the updated sample code. Also new: a running example (Lancet) throughout the book. AFAICT on a quick look all the Clojure-Contrib examples in the book already work, using latest head. Nice work Steve! Cheers, Stuart [1] http://pragprog.com/titles/shcloj/programming-clojure --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
[DISCUSS] Improved exception reporting
As a new developer to Clojure, coming from a strong Java/OO background and NOT a functional one, I'd like to make a few observations. One challenge to new developers are exception messages generated by Clojure. I'm seeing a lot of ClassCastExceptions: cribbage= (sort-by card-order (take 11 deck)) java.lang.RuntimeException: java.lang.RuntimeException: java.lang.ClassCastException: clojure.lang.Keyword (NO_SOURCE_FILE:0) cribbage= (.printStackTrace *e) java.lang.ClassCastException: clojure.lang.LazyCons (NO_SOURCE_FILE:0) at clojure.lang.Compiler.eval(Compiler.java:4122) at clojure.lang.Repl.main(Repl.java:91) Caused by: java.lang.ClassCastException: clojure.lang.LazyCons at clojure.nth__461.invoke(boot.clj:844) at cribbage.eval__3056.invoke(Unknown Source) at clojure.lang.Compiler.eval(Compiler.java:4111) ... 1 more nil cribbage= That's not a lot to go on; my eventual error was here: (def face-card-order {:jack 11 :queen 12 :kind 13}) (defn card-order Returns the sort ordering of the card, which is the rank, extended with values for :jack, :queen and :king. [{rank :rank}] (or (face-card-order rank) rank)) (defn card-value Returns point value of card, which ranges from 1 to 10 (for 10 and all face cards). [{rank :rank}] (if (contains? face-card-order rank) 10 rank)) :king vs. :kind inside face-card-order, thus :king was returned (not 10) which cases a comparison error. The point is, an exception that said something like: Expected java.lang.Comparable but received :king would have helped me unravel this much, much easier! I have a lot of experience, inside Tapestry, on these kinds of issues: useful exception reporting. A significant amount of Tapestry's code base revolves around exception reporting, as does a more-than-signficant amount of the test cases. At the very least, I'd like to see a diagnostic with every ClassCastException, identifying what was being cast (and perhaps why) along with the expected type. -- Howard M. Lewis Ship Creator Apache Tapestry and Apache HiveMind --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Clojuring in Denver tomorrow
I will be giving two talks comparing Clojure with other Java.next languages tomorrow at the Rocky Mountain Software Symposium [1] tomorrow. Cheers, Stuart [1] http://www.nofluffjuststuff.com/conference/denver/2008/11/schedule.html --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Patch: precompiling Clojure core sources in Ant build script
On Fri, Nov 14, 2008 at 2:37 PM, Rich Hickey [EMAIL PROTECTED] wrote: On Nov 14, 12:51 pm, Stuart Sierra [EMAIL PROTECTED] wrote: Patch attached. This precompiles everything except parallel.clj, which requires an extra Jar. It also omits the source .clj files from the clojure.jar file. -Stuart Sierra Patch applied (svn 1101) - thanks! Hi folks, Just FYI, this breaks, at least for me, 'slime-edit-definition' in swank-clojure (also known as M-.), which pops open the source definition of the word under point. I'm sure there's a work-around, of course. The meta information is still there: user (meta #'last) {:arglists ([coll]), :doc Return the last item in coll, in linear time, :name last, :file core.clj, :line 161, :ns #Namespace clojure.core} so it must just be a configuration issue. I will read over the swank-clojure code. Best, Graham --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: multi-method dispatch for structs
On Fri, Nov 14, 2008 at 2:11 PM, Jeff Rose [EMAIL PROTECTED] wrote: Does my dispatch function have to inspect the passed in values to figure out which type of struct they are, or can I query that somehow? My understanding is that StructMaps are just Maps with an implementation that's optimized to reduce memory usage. The different basis types don't really function as classes of StractMaps or anything. You can still add new keys to StructMaps, for example, just like any other Map. So if you want some kind of 'type' data do dispatch off of, you'll have to attach that yourself, either as another key that all your Maps share or as metadata. --Chouser --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: [DISCUSS] Improved exception reporting
On Nov 14, 2008, at 3:11 PM, Howard Lewis Ship wrote: The point is, an exception that said something like: Expected java.lang.Comparable but received :king would have helped me unravel this much, much easier! I agree. Clojure should give all the information it can about the object(s) involved in the failure. There are other places where the class of the object is given, but not its string representation. Any juicy info that's easily available should be made part of the exception message. --Steve --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: multi-method dispatch for structs
I wonder if it would good to have something indicating the struct name put in the metadata when creating a struct? On Fri, Nov 14, 2008 at 1:42 PM, Chouser [EMAIL PROTECTED] wrote: On Fri, Nov 14, 2008 at 2:11 PM, Jeff Rose [EMAIL PROTECTED] wrote: Does my dispatch function have to inspect the passed in values to figure out which type of struct they are, or can I query that somehow? My understanding is that StructMaps are just Maps with an implementation that's optimized to reduce memory usage. The different basis types don't really function as classes of StractMaps or anything. You can still add new keys to StructMaps, for example, just like any other Map. So if you want some kind of 'type' data do dispatch off of, you'll have to attach that yourself, either as another key that all your Maps share or as metadata. --Chouser --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Patch: precompiling Clojure core sources in Ant build script
On Nov 14, 2008, at 3:38 PM, Graham Fawcett wrote: I'm sure there's a work-around, of course. The meta information is still there: This appears to be because the sources are no longer included in clojure.jar. I added path-to-clojure-trunk-svn-directory/src/clj to my classpath and now it works. --Steve --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Patch: precompiling Clojure core sources in Ant build script
On Fri, Nov 14, 2008 at 4:01 PM, Stephen C. Gilardi [EMAIL PROTECTED] wrote: On Nov 14, 2008, at 3:38 PM, Graham Fawcett wrote: I'm sure there's a work-around, of course. The meta information is still there: This appears to be because the sources are no longer included in clojure.jar. I added path-to-clojure-trunk-svn-directory/src/clj to my classpath and now it works. Thanks, Steve -- an easy fix! Best, Graham --Steve --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Patch: precompiling Clojure core sources in Ant build script
On Nov 14, 4:09 pm, Graham Fawcett [EMAIL PROTECTED] wrote: On Fri, Nov 14, 2008 at 4:01 PM, Stephen C. Gilardi [EMAIL PROTECTED] wrote: On Nov 14, 2008, at 3:38 PM, Graham Fawcett wrote: I'm sure there's a work-around, of course. The meta information is still there: This appears to be because the sources are no longer included in clojure.jar. I added path-to-clojure-trunk-svn-directory/src/clj to my classpath and now it works. Thanks, Steve -- an easy fix! Best, Graham --Steve M-. will jump to wrong place if defs are not in namespace master .clj. I already reported it to swank-clojure owner. I guess the fix should be in git repo soon. This should fix it. (defn- namespace-to-path [ns] (let [ns-str (name (ns-name ns))] (- ns-str (.substring 0 (.lastIndexOf ns-str .)) (.replace \- \_) (.replace \. \/ (defslimefn find-definitions-for-emacs [name] (let [sym-name (read-from-string name) sym-var (ns-resolve (maybe-ns *current-package*) sym-name)] (when-let [meta (and sym-var (meta sym-var))] (if-let [path (or (slime-find-file-in-paths (str (namespace-to- path (:ns meta)) (.separator File) (:file meta)) (slime-search-paths)) ;; This is OK for namespace master .clj, but not for help files. ; (slime-find-file-in-paths (str (namespace- to-path (:ns meta)) .clj) ;(slime-search- paths)) (slime-find-file-in-paths (:file meta) (slime-search-paths)))] `((~(str (defn (:name meta) )) (:location ~path (:line ~(:line meta)) nil))) `((~(str (:name meta)) (:error Source definition not found.))) regards, - Feng --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Lazy Seq and refs
I thought up an interesting issue the other night. If you map a function over a seq of refs, then change the refs look at the map return value (which will convert it from lazy to ...? Hmm, what's the word - motivated?) then you will get the current value of the refs. The example code is (def refs (into [] (map #(ref %) (range 10 (def dref (map deref refs)) (doseq r refs (dosync (commute r #(* 2 % (println dref) When you consider how map works, this actually makes total sense. However, I think that it is something of a gotcha. Normally you don't need to know that map returns a lazy seq, because normally you would be mapping over immutable data. But if you happen to map over seqs that have refs, then you might have problems. I find it conceptually jarring - normally laziness is a transparent abstraction. I guess the main reason I'm posting this is to point out the issue. I wonder if this gotcha should be highlighted somewhere in the official documentation, or am I making a mountain out of a molehill? Cheers, Brad --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Newbie question: Can a collection contain itself?
On Fri, Nov 14, 2008 at 5:19 PM, samppi [EMAIL PROTECTED] wrote: Would it be at all possible in Clojure for a collection to contain itself? For instance: [3 2 1 [3 2 1 [...]]]. Let's try! user= (def x [3 2 1]) #'user/x user= x [3 2 1] Great, now append it to itself: user= (conj x x) [3 2 1 [3 2 1]] user= (conj x (conj x x)) [3 2 1 [3 2 1 [3 2 1]]] Since collections are immutable, you can't change an existing collection to include itself. The closest you can get is to make a new collection that contains the value of an older collection -- it may look similar, but it's not the same. So the structure will only be as deep as you make it. --Chouser --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Lazy Seq and refs
On Nov 14, 5:48 pm, Chouser [EMAIL PROTECTED] wrote: On Fri, Nov 14, 2008 at 3:51 PM, Bradbev [EMAIL PROTECTED] wrote: (which will convert it from lazy to ...? Hmm, what's the word - motivated?) I think the word you want is eager http://www.zazzle.com/i_get_more_done_when_im_lazy_clojure_shirt-2355... NOO... not another Clojure shirt (shrieks my wallet) Thanks for the example -- was puzzled by it for a couple of minutes, but now it makes sense: (map ...) produces a lazy result, and so dref does not get evaluated until (println dref). Displaying dref before the doseq results in dref being fixed to '(0 1 2 ... 9) no matter what is done to refs -- Michel --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Newbie question: Can a collection contain itself?
you can have a collection that contains a ref to itself. or you could cook something up with lazy-cons, having it produce a copy of itself when needed. (this will be a lazy seq, though) --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Newbie question: Can a collection contain itself?
Yeah, I surmised as much. The thing is, I'm writing a YAML library in Clojure, and YAML allows circular recursion like that: --- x - 3 - 2 - 1 - *x ...So I'm wondering what I should do if a document like that were loaded. Ah well, I'll worry about that later. On Nov 14, 4:05 pm, notallama [EMAIL PROTECTED] wrote: you can have a collection that contains a ref to itself. or you could cook something up with lazy-cons, having it produce a copy of itself when needed. (this will be a lazy seq, though) --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
[DISCUSS] Automatic defs for Repl?
On option I would like for the Repl is an option such that each evaluated expression that does not define a new symbol itself, would (nethertheless) bind a symbol. Many other Repl's for other languages (such as, I believe, Scala) do this: the Repl identifies the bound symbol and the value, not just the value. This should be an option, perhaps another * symbol, like *e. For me, it saves the effort of remembering to (def foo (...)) for temporary values I'm using to test my functions. Instead, I'd just be able to type the expression (...) and see what symbol Repl provided. Obviously, this will impact the ability for data to be GC'ed, so you wouldn't want this in production. Thoughts? -- Howard M. Lewis Ship Creator Apache Tapestry and Apache HiveMind --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: [DISCUSS] Automatic defs for Repl?
I'm not currently at a repl, so I can't check this, but IIRC, 1*, 2*, and 3* bind to the last three return values. Eric On Fri, Nov 14, 2008 at 9:22 PM, Howard Lewis Ship [EMAIL PROTECTED] wrote: On option I would like for the Repl is an option such that each evaluated expression that does not define a new symbol itself, would (nethertheless) bind a symbol. Many other Repl's for other languages (such as, I believe, Scala) do this: the Repl identifies the bound symbol and the value, not just the value. This should be an option, perhaps another * symbol, like *e. For me, it saves the effort of remembering to (def foo (...)) for temporary values I'm using to test my functions. Instead, I'd just be able to type the expression (...) and see what symbol Repl provided. Obviously, this will impact the ability for data to be GC'ed, so you wouldn't want this in production. Thoughts? -- Howard M. Lewis Ship Creator Apache Tapestry and Apache HiveMind --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Getting a flat sequence from a map (and vice versa)
I'm trying to figure out how to do this: (flat-map-seq {:a 3, :b 1, :c 2}) ; returns (:a 3 :b 1 :c 2) ...and vice versa: (map-from-flat-collection {} [:a 3 :b 1 :c 2]) ; returns {:a 3, :b 1, :c 2} Anyone have any idiomatic ideas? --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Getting a flat sequence from a map (and vice versa)
On Nov 14, 10:56 pm, samppi [EMAIL PROTECTED] wrote: I'm trying to figure out how to do this: (flat-map-seq {:a 3, :b 1, :c 2}) ; returns (:a 3 :b 1 :c 2) (defn flat-map-seq [m] (if (empty? m) '() (let [kv (first m)] (lazy-cons (kv 0) (lazy-cons (kv 1) (flat-map-seq (rest m))) ...and vice versa: (map-from-flat-collection {} [:a 3 :b 1 :c 2]) ; returns {:a 3, :b 1, :c 2} (defn map-from-flat-collection [c] (if (empty? c) {} (conj (map-from-flat-collection (rrest c)) [(first c) (frest c)]))) Anyone have any idiomatic ideas? Well, not sure how idiomatic this is; apart from conj, this is how you'd do it in Lisp/Scheme. I'd use fold to do the first function if it's built into Clojure. Regards, -- Michel --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Getting a flat sequence from a map (and vice versa)
Yeah, I need to be able to do this to easily manage trees of maps. I meant, how would you idiomatically implement their algorithms? Fold isn't build into Clojure, but they should still somehow be possible...right? On Nov 14, 9:12 pm, Michel Salim [EMAIL PROTECTED] wrote: On Nov 14, 10:56 pm, samppi [EMAIL PROTECTED] wrote: I'm trying to figure out how to do this: (flat-map-seq {:a 3, :b 1, :c 2}) ; returns (:a 3 :b 1 :c 2) (defn flat-map-seq [m] (if (empty? m) '() (let [kv (first m)] (lazy-cons (kv 0) (lazy-cons (kv 1) (flat-map-seq (rest m))) ...and vice versa: (map-from-flat-collection {} [:a 3 :b 1 :c 2]) ; returns {:a 3, :b 1, :c 2} (defn map-from-flat-collection [c] (if (empty? c) {} (conj (map-from-flat-collection (rrest c)) [(first c) (frest c)]))) Anyone have any idiomatic ideas? Well, not sure how idiomatic this is; apart from conj, this is how you'd do it in Lisp/Scheme. I'd use fold to do the first function if it's built into Clojure. Regards, -- Michel --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Getting a flat sequence from a map (and vice versa)
On Fri, Nov 14, 2008 at 8:17 PM, samppi [EMAIL PROTECTED] wrote: Yeah, I need to be able to do this to easily manage trees of maps. I meant, how would you idiomatically implement their algorithms? Fold isn't build into Clojure, but they should still somehow be possible...right? On Nov 14, 9:12 pm, Michel Salim [EMAIL PROTECTED] wrote: On Nov 14, 10:56 pm, samppi [EMAIL PROTECTED] wrote: I'm trying to figure out how to do this: (flat-map-seq {:a 3, :b 1, :c 2}) ; returns (:a 3 :b 1 :c 2) (defn flat-map-seq [m] (if (empty? m) '() (let [kv (first m)] (lazy-cons (kv 0) (lazy-cons (kv 1) (flat-map-seq (rest m))) ...and vice versa: (map-from-flat-collection {} [:a 3 :b 1 :c 2]) ; returns {:a 3, :b 1, :c 2} (defn map-from-flat-collection [c] (if (empty? c) {} (conj (map-from-flat-collection (rrest c)) [(first c) (frest c)]))) Anyone have any idiomatic ideas? Well, not sure how idiomatic this is; apart from conj, this is how you'd do it in Lisp/Scheme. I'd use fold to do the first function if it's built into Clojure. Regards, -- Michel (apply assoc {} [:a 1 :b 2 :c 3]) - {:c 3, :b 2, :a 1} -- The Mafia way is that we pursue larger goals under the guise of personal relationships. Fisheye --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Getting a flat sequence from a map (and vice versa)
Excellent! I must remember about the apply function. Thank you very much. On Nov 14, 9:35 pm, Kevin Downey [EMAIL PROTECTED] wrote: On Fri, Nov 14, 2008 at 8:33 PM, Kevin Downey [EMAIL PROTECTED] wrote: On Fri, Nov 14, 2008 at 8:17 PM, samppi [EMAIL PROTECTED] wrote: Yeah, I need to be able to do this to easily manage trees of maps. I meant, how would you idiomatically implement their algorithms? Fold isn't build into Clojure, but they should still somehow be possible...right? On Nov 14, 9:12 pm, Michel Salim [EMAIL PROTECTED] wrote: On Nov 14, 10:56 pm, samppi [EMAIL PROTECTED] wrote: I'm trying to figure out how to do this: (flat-map-seq {:a 3, :b 1, :c 2}) ; returns (:a 3 :b 1 :c 2) (defn flat-map-seq [m] (if (empty? m) '() (let [kv (first m)] (lazy-cons (kv 0) (lazy-cons (kv 1) (flat-map-seq (rest m))) ...and vice versa: (map-from-flat-collection {} [:a 3 :b 1 :c 2]) ; returns {:a 3, :b 1, :c 2} (defn map-from-flat-collection [c] (if (empty? c) {} (conj (map-from-flat-collection (rrest c)) [(first c) (frest c)]))) Anyone have any idiomatic ideas? Well, not sure how idiomatic this is; apart from conj, this is how you'd do it in Lisp/Scheme. I'd use fold to do the first function if it's built into Clojure. Regards, -- Michel (apply assoc {} [:a 1 :b 2 :c 3]) - {:c 3, :b 2, :a 1} -- The Mafia way is that we pursue larger goals under the guise of personal relationships. Fisheye user= (apply concat (seq {:c 3, :b 2, :a 1})) (:c 3 :b 2 :a 1) user= -- The Mafia way is that we pursue larger goals under the guise of personal relationships. Fisheye --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Getting a flat sequence from a map (and vice versa)
On Fri, Nov 14, 2008 at 8:33 PM, Kevin Downey [EMAIL PROTECTED] wrote: On Fri, Nov 14, 2008 at 8:17 PM, samppi [EMAIL PROTECTED] wrote: Yeah, I need to be able to do this to easily manage trees of maps. I meant, how would you idiomatically implement their algorithms? Fold isn't build into Clojure, but they should still somehow be possible...right? On Nov 14, 9:12 pm, Michel Salim [EMAIL PROTECTED] wrote: On Nov 14, 10:56 pm, samppi [EMAIL PROTECTED] wrote: I'm trying to figure out how to do this: (flat-map-seq {:a 3, :b 1, :c 2}) ; returns (:a 3 :b 1 :c 2) (defn flat-map-seq [m] (if (empty? m) '() (let [kv (first m)] (lazy-cons (kv 0) (lazy-cons (kv 1) (flat-map-seq (rest m))) ...and vice versa: (map-from-flat-collection {} [:a 3 :b 1 :c 2]) ; returns {:a 3, :b 1, :c 2} (defn map-from-flat-collection [c] (if (empty? c) {} (conj (map-from-flat-collection (rrest c)) [(first c) (frest c)]))) Anyone have any idiomatic ideas? Well, not sure how idiomatic this is; apart from conj, this is how you'd do it in Lisp/Scheme. I'd use fold to do the first function if it's built into Clojure. Regards, -- Michel (apply assoc {} [:a 1 :b 2 :c 3]) - {:c 3, :b 2, :a 1} -- The Mafia way is that we pursue larger goals under the guise of personal relationships. Fisheye user= (apply concat (seq {:c 3, :b 2, :a 1})) (:c 3 :b 2 :a 1) user= -- The Mafia way is that we pursue larger goals under the guise of personal relationships. Fisheye --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Getting a flat sequence from a map (and vice versa)
Another way to create a map is: user= (apply hash-map [:a 1 :b 2 :c 3]) {:a 1, :c 3, :b 2} On Fri, Nov 14, 2008 at 9:42 PM, samppi [EMAIL PROTECTED] wrote: Excellent! I must remember about the apply function. Thank you very much. On Nov 14, 9:35 pm, Kevin Downey [EMAIL PROTECTED] wrote: On Fri, Nov 14, 2008 at 8:33 PM, Kevin Downey [EMAIL PROTECTED] wrote: On Fri, Nov 14, 2008 at 8:17 PM, samppi [EMAIL PROTECTED] wrote: Yeah, I need to be able to do this to easily manage trees of maps. I meant, how would you idiomatically implement their algorithms? Fold isn't build into Clojure, but they should still somehow be possible...right? On Nov 14, 9:12 pm, Michel Salim [EMAIL PROTECTED] wrote: On Nov 14, 10:56 pm, samppi [EMAIL PROTECTED] wrote: I'm trying to figure out how to do this: (flat-map-seq {:a 3, :b 1, :c 2}) ; returns (:a 3 :b 1 :c 2) (defn flat-map-seq [m] (if (empty? m) '() (let [kv (first m)] (lazy-cons (kv 0) (lazy-cons (kv 1) (flat-map-seq (rest m))) ...and vice versa: (map-from-flat-collection {} [:a 3 :b 1 :c 2]) ; returns {:a 3, :b 1, :c 2} (defn map-from-flat-collection [c] (if (empty? c) {} (conj (map-from-flat-collection (rrest c)) [(first c) (frest c)]))) Anyone have any idiomatic ideas? Well, not sure how idiomatic this is; apart from conj, this is how you'd do it in Lisp/Scheme. I'd use fold to do the first function if it's built into Clojure. Regards, -- Michel (apply assoc {} [:a 1 :b 2 :c 3]) - {:c 3, :b 2, :a 1} -- The Mafia way is that we pursue larger goals under the guise of personal relationships. Fisheye user= (apply concat (seq {:c 3, :b 2, :a 1})) (:c 3 :b 2 :a 1) user= -- The Mafia way is that we pursue larger goals under the guise of personal relationships. Fisheye --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: chunk-file function
On Nov 12, 2:20 pm, Brian Doyle [EMAIL PROTECTED] wrote: I had to process each line of a very large file, 120MB, and did not want to read in the whole file at once. I wrote this function, chunk-file, that allows me to pass in a function and args that will process each line. What happens if some mean person stripped all the endlines out of your file? ;-) mfh --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Readable names
On Nov 12, 4:47 am, Dave Newton [EMAIL PROTECTED] wrote: There's terse, and there's concise. I know you're attempting humor, but IMO there's a difference between association/assoc and assoc/a in the amount of information being lost in each pair. Nothing stopping anybody from writing verbose mode macros. Or vice versa, which was basically the original implementation of Arc ;-P mfh --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Readable names
On Nov 12, 5:52 am, David [EMAIL PROTECTED] wrote: No, I think that, if at all, we need a single set of macros. As far as the IDEs are concerned, if we all try inventing our own (or plugins for the existing ones), they will all be half-done at best. It's better to focus on one project than spread the effort across several ones. At least until the developer base is large enough to be able to afford such a distribution. How would you define IDE? There's already Slime (for Emacs) and Vim support for Clojure. Slime can do all kinds of function name completion, link up to documentation, run chunks of code on the fly, and help manage project directories (via Speedbar). Presumably Vim can do the same (I haven't used the Clojure environment for Vim). What is it that characterizes an IDE for you, if I may ask? What features would it need in order to be sufficiently capable? I don't mean in order to win the whole world over to Clojure (Smalltalk had a great IDE but that didn't help); I mean in order to be useful to you, your programmer friends or colleagues? mfh --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---