Re: [ANN] analyze 0.1
Yes, that will fix it, but I'm not sure of the implications or why exactly it's necessary. I'll push it to master. Thanks, Ambrose On Tue, Jan 3, 2012 at 3:55 PM, Jonas jonas.enl...@gmail.com wrote: On Tuesday, January 3, 2012 9:45:04 AM UTC+2, Ambrose Bonnaire-Sergeant wrote: It seems if the namespace is not already loaded, then there are issues. That's it! It's simple to fix. Just require the namespaces in the ns form. I can send you a pull request if you want to? /Jonas -- 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 -- 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
Late provide error in compiling clojurescript files
Hi, I have a silly problem compiling my cljs files. I have to run the cljsc command twice in succession to generate javascript source. The first compilation results in: ERROR: JSC_LATE_PROVIDE_ERROR. required foo.bar namespace not provided yet at /home/.../src/../target/classes/public/js/core.js line 18 : 12 Please note that my core.cljs requires foo.bar namespace. The second cljsc command works without any error. I doubt that clojurescript compiler requires running it multiple times in succession and suspect some problem in my usage of it. I would expect closure compiler to process the transitive dependencies correctly. I see the same issue with cljs-watch which is a major productivity issue for me. Has anyone else encountered this issue? Does anybody know the cause of this error? Thanks -- 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
Re: [ANN] swank-clojure 1.3.4 released
Baishampayan Ghose b.gh...@gmail.com writes: Hi Baishampayan, ,[ C-h f ansi-color-for-comint-mode-on RET ] | ansi-color-for-comint-mode-on is an interactive compiled Lisp function in | `ansi-color.el'. | | (ansi-color-for-comint-mode-on) | | Set `ansi-color-for-comint-mode' to t. Thanks Tassilo, but that turns on ansi color for the shell, Well, for all modes that interact with some process using comint, like shell, term, and some others. It seems sldb-mode is not a comint mode. and not the sldb buffer with the stacktrace. Is there any way to enable that globally? Not that I know of. But you could try to run the ansi translation in sldb-mode-hook. --8---cut here---start-8--- (defun th-ansi-colorize-buffer () (ansi-color-apply-on-region (point-min) (point-max))) (add-hook 'sldb-mode-hook 'th-ansi-colorize-buffer) --8---cut here---end---8--- It might be that the hook is run before the stacktrace is actually inserted in the buffer. In that case, you should add the colorizing function into a buffer-local after-change-functions hook like so: --8---cut here---start-8--- (defun th-ansi-colorize-buffer () (ansi-color-apply-on-region (point-min) (point-max))) (defun th-sldb-mode-init () (add-hook 'after-change-functions 'th-ansi-colorize-buffer t t)) (add-hook 'sldb-mode-hook 'th-sldb-mode-init) --8---cut here---end---8--- Bye, Tassilo -- 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
Re: [ClojureScript] Wrapping all def into a load event handler
Hi, Putting javascript at the bottom of body is nice idea. Thanks. 2012/1/2 Stuart Sierra the.stuart.sie...@gmail.com: Hi Takahiro, This will work. It's not 100% idiomatic Clojure, but it's an acceptable workaround to the DOM loading issue. If ClojureScript had `alter-var-root`, which it doesn't, you could use that to set the Vars in your init function. But ClojureScript doesn't really have Vars either, so I wouldn't expect to see `alter-var-root`. If ClojureScript had Clojure's `delay`, you could use that. ClojureScript doesn't have `delay`, but it might make sense to add it. The easiest way, of course, is to load your JavaScript at the bottom of your HTML file, but that's not always convenient. -Stuart Sierra clojure.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 -- 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
Re: [ANN] swank-clojure 1.3.4 released
Tassilo, Not that I know of. But you could try to run the ansi translation in sldb-mode-hook. --8---cut here---start-8--- (defun th-ansi-colorize-buffer () (ansi-color-apply-on-region (point-min) (point-max))) (add-hook 'sldb-mode-hook 'th-ansi-colorize-buffer) --8---cut here---end---8--- It might be that the hook is run before the stacktrace is actually inserted in the buffer. In that case, you should add the colorizing function into a buffer-local after-change-functions hook like so: --8---cut here---start-8--- (defun th-ansi-colorize-buffer () (ansi-color-apply-on-region (point-min) (point-max))) (defun th-sldb-mode-init () (add-hook 'after-change-functions 'th-ansi-colorize-buffer t t)) (add-hook 'sldb-mode-hook 'th-sldb-mode-init) --8---cut here---end---8--- The first option didn't do anything. Calling th-ansi-colorize-buffer manually on the sldb buffer gave me an error saying that the buffer is read-only. The second option gives an error the moment the sldb buffer comes up. It says - error in process filter: insert: Wrong number of arguments: (lambda nil (ansi-color-apply-on-region (point-min) (point-max))), 3 Regards, BG -- Baishampayan Ghose b.ghose at gmail.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
Do you use Monads in your real clojure applications
Dragan R writes: On the net I read that Impure functional programming doesn't really need monads. and It appears that in the presence of mutable state, a lot of the advantages of monads become moot. Monads are an abstraction mechanism, so you never need them. You can always use the lower-level techniques in terms of which monads are implemented. The only language that has made monads nearly inevitable is Haskell, because its standard library is based on monads. But even in Haskell, monads can be avoided, at the cost of rewriting stuff that is already in the standard library. As with all abstractions, the real question is not whether you need them, but whether their use improves your programs. This depends as much on the programmer as on the problem, so there is not clear answer. As a rule of thumb, I'd say that you should consider using monads if your application 1) can profit from more than one of them, or 2) can profit from the generic monad operators. I probably use monad more than the average programme in my own code, but that's also because I happen to be familiar with them. I could very well live with fewer monads in my code. But once you know monads, they appear magically everywhere you look ;-) Konrad. -- 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
Re: Do you use Monads in your real clojure applications
Hi, I used monads in two projects. * The last rewrite of ClojureQL before v1.0 used a state monad to keep track of various things during query creation. * ClojureCheck also uses a monad approach to create and combine generators for test data. * Dave Ray and I tried a monad style in the async branch of seesaw. Both were custom monad implementations. Both work(ed) reasonably well. However things have a relatively high strangeness factor. Since the execution of things is deferred till someone actually runs the monad pipeline, you can't use your usual try/catch construct to take care of problems. Everything has to be constrained to your monadic function. So you need to have some way to error out of your monadic pipeline. This leads you to monad transformers and complicates things even more. In Clojure I haven't seen a use were other approaches weren't just as feasible or were monads would have simplified things. They are a legal approach, but I would judge on a case-by-base basis. Sincerely Meikel -- 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
Re: [ANN] swank-clojure 1.3.4 released
Baishampayan Ghose b.gh...@gmail.com writes: Hi again, The second option gives an error the moment the sldb buffer comes up. It says - error in process filter: insert: Wrong number of arguments: (lambda nil (ansi-color-apply-on-region (point-min) (point-max))), 3 Ah, yes. Now I've installed clj-stacktrace myself, and this is a fully working, hardcore tested emacs config. ;-) --8---cut here---start-8--- (defun th-ansi-colorize-region (start end old-len) (ansi-color-apply-on-region start end)) (defun th-sldb-mode-init () (add-hook 'after-change-functions 'th-ansi-colorize-region nil t)) (add-hook 'sldb-mode-hook 'th-sldb-mode-init) --8---cut here---end---8--- Bye, Tassilo -- 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
Re: [ANN] swank-clojure 1.3.4 released
Getting colors outside M-x clojure-jack-in requires a couple extra steps I forgot to document, I just added it here: https://github.com/technomancy/swank-clojure/commit/94fa71f90e52c55d74 Just curious, you mention loading the file `slime-compile-presave`, but I wonder what it has got to do with colors in the stacktrace. Did you mean this file instead? https://github.com/technomancy/swank-clojure/blob/master/src/swank/payload/slime-frame-colors.el Regards, BG -- Baishampayan Ghose b.ghose at gmail.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
core.match or patterns
I'm trying to use :or patterns with records but I'm getting an error and I'm not sure if I have found a bug (or a not-implemented-yet) or if its the intended behavior (and there are good reasons for it). Without :or patterns I can do: (let [x {:a 1 :b 2}] (clojure.core.match/match [x] [{:a 1 :b b}] b [{:a 2 :b b}] b)) ;= 2 I can group 1 and 2 values with :or and do: (let [x {:a 1 :b 2}] (clojure.core.match/match [x] [{:a (:or 1 2) :b b}] b)) ;= 2 But I'd want to do: (let [x {:a 1 :b 2}] (clojure.core.match/match [x] [(:or {:a 1 :b b} {:a 2 :b b})] b)) which throws and exception and prints: Unable to resolve symbol: b in this context Is this the way it's supposed to be? Thanks, Juan Manuel -- 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
Where is ltrim?
The clojure.string namespace has replaced clojure.contrib.str-utils and clojure.contrib.str-utils2. There's a problem, though: the str-utils2/ltrim function seems to be missing. This is a breaking change for some code I'm porting from 1.2 to 1.3. Where is that function now? -- 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
Re: Where is ltrim?
On 3 January 2012 11:06, Cedric Greevey cgree...@gmail.com wrote: There's a problem, though: the str-utils2/ltrim function seems to be missing. This is a breaking change for some code I'm porting from 1.2 to 1.3. Where is that function now? clojure.string/triml I believe. - James -- 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
Re: Where is ltrim?
On Tue, Jan 3, 2012 at 6:11 AM, James Reeves jree...@weavejester.com wrote: On 3 January 2012 11:06, Cedric Greevey cgree...@gmail.com wrote: There's a problem, though: the str-utils2/ltrim function seems to be missing. This is a breaking change for some code I'm porting from 1.2 to 1.3. Where is that function now? clojure.string/triml I believe. Thank you. Breaking changes are bad enough without making some of them gratuitous. They could have just renamed the namespace without also renaming some of the individual functions. :) -- 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
Re: core.match or patterns
On Tue, Jan 3, 2012 at 4:16 AM, JuanManuel Gimeno Illa jmgim...@gmail.comwrote: I'm trying to use :or patterns with records but I'm getting an error and I'm not sure if I have found a bug (or a not-implemented-yet) or if its the intended behavior (and there are good reasons for it). Without :or patterns I can do: (let [x {:a 1 :b 2}] (clojure.core.match/match [x] [{:a 1 :b b}] b [{:a 2 :b b}] b)) ;= 2 I can group 1 and 2 values with :or and do: (let [x {:a 1 :b 2}] (clojure.core.match/match [x] [{:a (:or 1 2) :b b}] b)) ;= 2 But I'd want to do: (let [x {:a 1 :b 2}] (clojure.core.match/match [x] [(:or {:a 1 :b b} {:a 2 :b b})] b)) which throws and exception and prints: Unable to resolve symbol: b in this context Is this the way it's supposed to be? Thanks, Juan Manuel This works find in master. Which version of core.match are you using? 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
Re: core.match or patterns
I'm using 0.2.0-alpha8 Juan Manuel -- 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
Re: Do you use Monads in your real clojure applications
On 3 January 2012 08:46, googlegro...@khinsen.fastmail.net wrote: Dragan R writes: On the net I read that Impure functional programming doesn't really need monads. and It appears that in the presence of mutable state, a lot of the advantages of monads become moot. Monads are an abstraction mechanism, so you never need them. You can always use the lower-level techniques in terms of which monads are implemented. This +1. You need to be more specific about what you mean when you say code uses monads. In one sense, any code which uses a 'for' sequence comprehension is using a monad, because it satisfies all of the properties of a monad. In another sense, only code which contains and names specific things as monads, and uses general operators which apply to all monads, is using them. I've been using monads a lot recently with Overtone -- by which I mean I've been using (state-t cont-m), the continuation monad transformed to add state. I'm using it because: a) I want to simulate state representing the current beat number, and b) I want to schedule future events using apply-at; so rather than returning from a function to continue a melody, I call apply-at and pass the current continuation to it. As an example of what I've achieved, see this gist: https://gist.github.com/1441831 Using clojure.algo.monads, I have created a basic DSL which allows me to say (wait 1) to pause for one beat, and (at-current-beat (foo)) to schedule event (foo) to happen on the current beat. These commands are relative to the current time, but using monads I can transform them into commands at an absolute time using overtone's built-in 'at and 'apply-at macros, and to automagically handle the scheduling. This is a work in progress; I'm planning a fuller write-up of what I'm doing which I will send to the overtone list once I've ironed out the wrinkles. Phil -- 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
Re: core.match or patterns
Please try using master. If that works for you, I can cut another alpha release. David On Tue, Jan 3, 2012 at 9:11 AM, JuanManuel Gimeno Illa jmgim...@gmail.comwrote: I'm using 0.2.0-alpha8 Juan Manuel -- 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 -- 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
Re: Where is ltrim?
Hi, Am 03.01.2012 um 12:16 schrieb Cedric Greevey: Breaking changes are bad enough without making some of them gratuitous. They could have just renamed the namespace without also renaming some of the individual functions. :) One could also argue the other way around: When we break things already, we can break it really hard and also clean up inconsistent naming of functions and such. Then you have the pain of a breaking change only once. That said: I don't know whether considerations like this were the case here. Sincerely Meikel -- 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
Re: core.match or patterns
El martes 3 de enero de 2012 15:30:24 UTC+1, David Nolen escribió: Please try using master. If that works for you, I can cut another alpha release. Now the example works and I've found no problems using it with my code. Thanks, Juan Manuel -- 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
Re: Where is ltrim?
On Tue, Jan 3, 2012 at 16:09, Meikel Brandmeyer m...@kotka.de wrote: Hi, Am 03.01.2012 um 12:16 schrieb Cedric Greevey: Breaking changes are bad enough without making some of them gratuitous. They could have just renamed the namespace without also renaming some of the individual functions. :) One could also argue the other way around: When we break things already, we can break it really hard and also clean up inconsistent naming of functions and such. Then you have the pain of a breaking change only once. That said: I don't know whether considerations like this were the case here. I think you'll find that the trim/triml/trimr naming came from thread review the clojure.string code from between 2010-05-30 and 2010-06-03. The trimr/triml/trim naming has the nice property of clustering the three functions together in documentation (which tends to be sorted by name). // Ben -- 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
Re: Do you use Monads in your real clojure applications
We use monads within one of our work project, but not to any large amount. It mostly boils down to using the Maybe monad to avoid giant nested if- lets. - Lee Hinman -- 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
Re: Do you use Monads in your real clojure applications
On Jan 3, 2:46 am, googlegro...@khinsen.fastmail.net wrote: I probably use monad more than the average programme in my own code, but that's also because I happen to be familiar with them. I could very well live with fewer monads in my code. But once you know monads, they appear magically everywhere you look ;-) Big +1 to that. I've submitted a talk to ClojureWest that partly touches on how to use monads in Clojure. Basically, monads are like design patterns for writing DSL's. Other than that, while they don't let you do anything you couldn't do in other ways, I really like how they eliminate the need for dealing with state held in symbols. I've found that testing is easier and code is cleaner using them. For instance, I showed how a state monad could be used in Chris Granger's Korma library. https://github.com/ibdknox/Korma/pull/35 Jim -- 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
Sonian is looking for Clojure Developers
For the HR version you can visit this link: http://www.sonian.com/about/careers/principal-software-engineer-cloud/ Here's the IMO version: At Sonian, we have a great team working on interesting problems. Our backend is written in Clojure and runs 100% on the cloud. We distribute work across a cluster of compute nodes. We store over a petabyte of data on S3. We index the data into a distributed search cluster to return subsecond results across millions of indexed objects. We have an IRC bot (written in Clojure) that does our bidding. We live in the future! We are a remote team, and we get together in person a few times a year to run amok in Boston. Feel free to contact me (p...@stadig.name) if you have any question you'd like to ask prior to responding to the job posting. Otherwise, send your cover letter and resume to j...@sonian.net with the subject Principal Software Engineer, Cloud. Happy New Year! Paul Stadig -- 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
Extending core.match to custom types
Hi all, I'm playing around with core.match and trying to extend it to some custom types in terms of extending the IMatchLookup protocol on those. But that's not quite what I need. IMatchLookup only specifies how to access some value out of my custom types, and in the `match' clauses those values are compared by equality to the values specified there. In my patterns, I want to have a :+type key with a value that's basically an interface name given as a symbol. The pattern should match, if the class of the object implements that interface (or an extended interface thereof) directly or indirectly. So that would be my ideal user interface: --8---cut here---start-8--- (match [obj] [{:+type 'Cat :mice 4}] :1 [{:+type 'Dog :cats 3}] :2 [{:+type 'Mammal}]:3 :else :nope) --8---cut here---end---8--- For example, a Cat object with 7 mice would miss the first row but match the third one, because Cat is a specialization of Mammal. I can still achieve what I want by introducing an :+obj key returning the actual object in favour of :+type and then use guards to do the dispatch on type, but that puts the burden on the user. `type-matcher' is a custom function that gets some type specification and returns a predicate that tests if a given object conforms to the type specification. --8---cut here---start-8--- (match [node] [{:+obj (a :when (core/type-matcher node 'Cat)) :mice 4}] :1 [{:+obj (b :when (core/type-matcher node 'Dog)) :cats 3}] :2 [{:+obj (c :when (core/type-matcher node 'Mammal))}]:3 :else :nope) --8---cut here---end---8--- Clearly, that's much worse than the idealized user interface above. So is there a way to do what I want? Maybe even core.match could check, if IMatchLookup/val-at* returned a function, and if so, simply apply it to the value specified in the pattern as match test instead of the hard-coded `='? I have some more use-cases where I would be very benefitical to return predicates for matching from val-at*. For example, if some property of my object is a collection, I'd very much like to have a key whose value should be contained in the collection. Thanks for any hints, Tassilo -- 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
Use You a Spaced Repetition System for Great Good!
Anybody else using a spaced repetition system (SRS) for Clojure learning? What about just general programming? How did it work out for you? I've just started using Anki and I uploaded a Clojure Sequence API shared deck. I'm hoping others might be interested in adding other Clojure related material to Anki. If you aren't familiar with the SRS concept, I wrote a short blog entry about it and how to import the Sequence API deck: http://blog.milehighcode.com/2012/01/use-you-spaced-repetition-system-for.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 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
Re: Extending core.match to custom types
On Tue, Jan 3, 2012 at 11:13 AM, Tassilo Horn tass...@member.fsf.orgwrote: Hi all, I'm playing around with core.match and trying to extend it to some custom types in terms of extending the IMatchLookup protocol on those. But that's not quite what I need. IMatchLookup only specifies how to access some value out of my custom types, and in the `match' clauses those values are compared by equality to the values specified there. In my patterns, I want to have a :+type key with a value that's basically an interface name given as a symbol. The pattern should match, if the class of the object implements that interface (or an extended interface thereof) directly or indirectly. So that would be my ideal user interface: --8---cut here---start-8--- (match [obj] [{:+type 'Cat :mice 4}] :1 [{:+type 'Dog :cats 3}] :2 [{:+type 'Mammal}]:3 :else :nope) --8---cut here---end---8--- This is a known missing feature and there's a couple of open questions as far as how to best implement this. It should probably support Java classes, Java interfaces, types, records, protocols and high performance hinted access to fields. This is not the highest thing on my priority list, but I'm more than happy to help if somebody wants to move forward with this sooner rather then later. 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
How can I make this kind of error message more useful?
I have been solving Clojure problems now for many months and can no longer exactly be considered a Clojure NOOB, but I still have an awful lot to learn about Clojure. One thing that has caused difficulties from the beginning is that I don't know Java and don't know how to exploit the Java eco-structure -- and thus I can't figure out how to use all the inter-op potential, and I have a hard time interpreting Java-oriented error messages. For example, on doing a particular load-file I get this very useful error message: java.lang.Exception: Unmatched delimiter: ] (source-file:323) But my error messages are more likely to look like this: java.lang.Exception: Unsupported binding form: (quote symb) (NO_SOURCE_FILE:5045) Where does the 5045 come from and what does it mean? Is there some way I could manage and load my defn files, or manage my evaluations of defn expressions in the REPL, so that such error messages would always give me a useful line number like the 323 in the first example? Thanks for your help. --Larry -- 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
Re: accessing multiple return values
This is a really neat macro, but would people want to rewrite their programs in continuation-passing style just to be able to return multiple values sometimes? (And a macro is not a first-class entity.) Of course, much of the time, the easiest thing to do \is to return a vector or some other destructureable object. But this changes the interface: the function no longer directly returns a singular value. Metadata avoids this problem, but doesn't work on numbers, among other things. So there really are cases where having multiple return values would help (when you want a function to give you one value unless you want more)preferably without judo! (altough judo is great too.) Replying to Tassilo: I'm not quite sure I understand this problem: then changing its name requires changing all places where clojure.core.quotient/remainder is used surely the call to Values takes place inside the function definition, which happens \once. If you want a different variable name on \use, you use a let; if you want to return a different variable name on \definition, you use a let inside the function (or perhaps Values could have some sugar for renaming variables). It's true that quotient/remainder must be thread-local (in fact it should really be function-local), but this makes it no different than a let-variable or a function parameter; it doesn't necessarily mean it is mutable. Is X mutable in (let [X 1 X (inc X)]) ? If you slapped that X in a data structure, you would not find it changing under your nose. quotient/remainder really has to behave in the same wayimagine the quotient call creates an invisible let every time. Perhaps I should explain why I think this is simple. It's simple because a) it allows you to ignore the extra values unless you want them and b) it gives you ready-to-use names. To my taste, b) is very important. One of the reasons I dislike OOP is all the boilerplate like this.x = x. But how many times do you have to write (let [x (some-expensive function ... )] just so you can use the returned value more than once? What we would do here is write some-expensive-function/ the next time we want to use the value (assuming this is the notation for getting the \default value)so in this case we don't even \care about multiple return values. If we think of this as a name-generating facility that happens to handle multiple values, we could imagine extensions to it for distinguishing more values (quotient 5 2) (quotient 8 3) quotient(5 2)/remainder -- 1 (rand(1) 12) (rand(2) 12) rand(1)(12)/ This is all rather fanciful, and admittedly a huge extension to the language; but what's the harm in thinking about these things? The next time you are telling your kids a bedtime story, you might start as follows: A man ate some soup. The man was bald, and the soup had an unhappy grasshopper in it. The grasshopper Scratch that: you should tell it as follows: Let there be a man my-man, and some soup my-soup, and a grasshopper my- grasshopper. my-man ate some of my-soup. my-man was bald. my-soup had my-grasshopper in it. And my-grasshopper was unhappy This makes for earlier bedtimes but worse storytelling. On Jan 3, 12:36 am, Cedric Greevey cgree...@gmail.com wrote: On Mon, Jan 2, 2012 at 2:16 PM, Tassilo Horn tass...@member.fsf.org wrote: nchurch nchubr...@gmail.com writes: Hi, Someone was asking on the list here about multiple return values, which Clojure does not have. If the facility were ever added, perhaps multiple values could be accessed via namespaces. Functions would possess another level of namespace and have the ability to inject values into the environment under that namespace. For instance: (defn quotient [x y] . (values quotient remainder)) (clojure.core/quotient 5 2) -- 2 clojure.core/quotient/remainder -- 1 This seems simpler than the Common Lisp way. I don't think so. And there are several major problems with that approach. First of all, your clojure.core.quotient/remainder var needs to be a mutable, thread-local var, because else you couldn't be sure that 1 is the remainder of the quotient call directly above, or the remainder of a call that happened a blink later in another thread (or ForkJoinTask). Another problem is that if the var name is determined by the name of the local var in the function which is given to `values', then changing its name requires changing all places where clojure.core.quotient/remainder is used. On top of all that, how often is this needed anyway where destructuring or metadata can't solve the problem? When performance isn't a concern and you control the calling functions (or they're generic things like map and reduce that just pass the return value through to code you control, such as whatever processes the map sequence output) you can replace something with a vector of that something and additional values, and
Re: Use You a Spaced Repetition System for Great Good!
Hi Joshua! I've been using Anki for repeating unsorted Clojure-stuff in about a year. It's good for knowing all the instructions and source code, but the key to success is always to solve more or less complicated problems (4clojure.orgetc). On the practical side I have a lot left to learn, also since I'm not very skilled in algoritms in other languages [because the have so much boilerplate and therefore is boring to program in]. /Linus 2012/1/3 Joshua jos...@milehighcode.com Anybody else using a spaced repetition system (SRS) for Clojure learning? What about just general programming? How did it work out for you? I've just started using Anki and I uploaded a Clojure Sequence API shared deck. I'm hoping others might be interested in adding other Clojure related material to Anki. If you aren't familiar with the SRS concept, I wrote a short blog entry about it and how to import the Sequence API deck: http://blog.milehighcode.com/2012/01/use-you-spaced-repetition-system-for.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 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 -- 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
Re: How can I make this kind of error message more useful?
On Tue, Jan 3, 2012 at 12:09 PM, Larry Travis tra...@cs.wisc.edu wrote: I have been solving Clojure problems now for many months and can no longer exactly be considered a Clojure NOOB, but I still have an awful lot to learn about Clojure. One thing that has caused difficulties from the beginning is that I don't know Java and don't know how to exploit the Java eco-structure -- and thus I can't figure out how to use all the inter-op potential, and I have a hard time interpreting Java-oriented error messages. For example, on doing a particular load-file I get this very useful error message: java.lang.Exception: Unmatched delimiter: ] (source-file:323) But my error messages are more likely to look like this: java.lang.Exception: Unsupported binding form: (quote symb) (NO_SOURCE_FILE:5045) Where does the 5045 come from and what does it mean? Is there some way I could manage and load my defn files, or manage my evaluations of defn expressions in the REPL, so that such error messages would always give me a useful line number like the 323 in the first example? Thanks for your help. --Larry If you want accurate error locations make sure to recompile the whole file instead of evaluating expressions one at a time. The tools could of course improve here by setting the line number explicitly when evaluating expressions one at a time. 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
Re: [ANN] swank-clojure 1.3.4 released
Baishampayan Ghose b.gh...@gmail.com writes: Getting colors outside M-x clojure-jack-in requires a couple extra steps I forgot to document, I just added it here: https://github.com/technomancy/swank-clojure/commit/94fa71f90e52c55d74 Just curious, you mention loading the file `slime-compile-presave`, but I wonder what it has got to do with colors in the stacktrace. Did you mean this file instead? https://github.com/technomancy/swank-clojure/blob/master/src/swank/payload/slime-frame-colors.el Quite right; just a slip up on my part. I've updated the readme. -Phil -- 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
Re: [ANN] swank-clojure 1.3.4 released
Cedric Greevey cgree...@gmail.com writes: Seriously, though. Terminals? Escape codes? Impedance mismatches involving term types and escape codes? What is this, the Dark Ages? Those kinds of problems simply should not trouble us in the 21st century. Plonk. -- 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
Re: [ANN] swank-clojure 1.3.4 released
On Tue, Jan 3, 2012 at 12:32 PM, Phil Hagelberg p...@hagelb.org wrote: Cedric Greevey cgree...@gmail.com writes: Seriously, though. Terminals? Escape codes? Impedance mismatches involving term types and escape codes? What is this, the Dark Ages? Those kinds of problems simply should not trouble us in the 21st century. Plonk. Beg pardon? Just seems to me that reading about someone seeing ANSI escape garbaging up their screen, this long after the 1980s, is like hearing someone complain that their vehicle's engine threw a shoe post-1920-or-so. :) -- 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
Re: How can I make this kind of error message more useful?
Hi, Am 03.01.2012 um 18:24 schrieb David Nolen: On Tue, Jan 3, 2012 at 12:09 PM, Larry Travis tra...@cs.wisc.edu wrote: But my error messages are more likely to look like this: java.lang.Exception: Unsupported binding form: (quote symb) (NO_SOURCE_FILE:5045) Where does the 5045 come from and what does it mean? Is there some way I could manage and load my defn files, or manage my evaluations of defn expressions in the REPL, so that such error messages would always give me a useful line number like the 323 in the first example? You obviously type in a lot in the repl. NO_SOURCE_FILE usually means repl, and 5045 is exactly that line typed into the repl. If you want to change that, you have to put your function definitions into files. Loading from the file will then give the accurate information form the former example. If you want accurate error locations make sure to recompile the whole file instead of evaluating expressions one at a time. The tools could of course improve here by setting the line number explicitly when evaluating expressions one at a time. VimClojure does set the file and line information correctly when sending single definitions from a clojure buffer to a server backend. So the last function sent will always give accurate information. However the definitions following the sent toplevel form might get slowly out of sync. So reloading the whole file from time to time is a good idea to get everything in sync again. (Beware other dangers like redefined protocols etc.) Sincerely Meikel -- 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
Re: accessing multiple return values
nchurch nchubr...@gmail.com writes: Replying to Tassilo: I'm not quite sure I understand this problem: then changing its name requires changing all places where clojure.core.quotient/remainder is used surely the call to Values takes place inside the function definition, which happens \once. If you want a different variable name on \use, you use a let; if you want to return a different variable name on \definition, you use a let inside the function (or perhaps Values could have some sugar for renaming variables). I understand your proposal in such a way, that in a function (defn foo [x] (let [double-x (* 2 x)] (values x double-x))) the `values' was actually a macro that 1. creates a namespace for the function (user.foo) 2. creates a var holding the last second value (user.foo/double-x) where the name of the var is dictated by the local var holding the value 3. expands into code that sets user.foo/double-x at runtime and then returns the first value x Then, if I want to use the second value returned by foo in my code, I'd so something like (let [x (foo 17), dx user.foo/double-x] (do-something-with x dx)) Since I have to refer to user.foo/double-x to get the second value, once that name changes, I have to change my code, too. But probably, I've simply misunderstood your intent. It's true that quotient/remainder must be thread-local (in fact it should really be function-local), but this makes it no different than a let-variable or a function parameter; it doesn't necessarily mean it is mutable. Is X mutable in (let [X 1 X (inc X)]) ? Nope, the latter X shadows the former X. But there's no such thing for vars in a namespace. If you slapped that X in a data structure, you would not find it changing under your nose. quotient/remainder really has to behave in the same wayimagine the quotient call creates an invisible let every time. Sorry, I don't get you. What am I misinterpreting in your approach? To me, it looks like you want to bind the multiple values to vars in an ad-hoc namespace corresponding to a function. Then, there's no such thing as a lexical scope provided by let. A namespace is a globally accessible thingy. Perhaps I should explain why I think this is simple. It's simple because a) it allows you to ignore the extra values unless you want them and Well, the Common Lisp approach does so, too. b) it gives you ready-to-use names. To my taste, b) is very important. To me, that's a major downside. (quotient 5 2) (quotient 8 3) quotient(5 2)/remainder -- 1 Huh, you want to create a namespace not only for each function but for each function call? And then store the multiple values for each of them? Bye, Tassilo -- 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
Re: Use You a Spaced Repetition System for Great Good!
I have built several Anki SRS decks for learning. I am building one now on American Sign Language. A Clojure deck would be a good idea. We could put a simple deck on github and make it so others could contribute. What should it cover? Only language syntax? Idiomatic forms (like lazy sequences)? Sections on Java interop? Tim Daly On Tue, 2012-01-03 at 18:19 +0100, Linus Ericsson wrote: Hi Joshua! I've been using Anki for repeating unsorted Clojure-stuff in about a year. It's good for knowing all the instructions and source code, but the key to success is always to solve more or less complicated problems (4clojure.org etc). On the practical side I have a lot left to learn, also since I'm not very skilled in algoritms in other languages [because the have so much boilerplate and therefore is boring to program in]. /Linus 2012/1/3 Joshua jos...@milehighcode.com Anybody else using a spaced repetition system (SRS) for Clojure learning? What about just general programming? How did it work out for you? I've just started using Anki and I uploaded a Clojure Sequence API shared deck. I'm hoping others might be interested in adding other Clojure related material to Anki. If you aren't familiar with the SRS concept, I wrote a short blog entry about it and how to import the Sequence API deck: http://blog.milehighcode.com/2012/01/use-you-spaced-repetition-system-for.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 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 -- 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 -- 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
Re: Do you use Monads in your real clojure applications
Some of the most common uses for monads have pre-existing mechanisms with Clojure to handle them, e.g.: sequence monad (for) state monad (Clojure has many stateful mechansisms) maybe monad (Clojure programmers usually just return nil for failure, and use something like when-let to process it) In terms of higher-level DSLs constructed out of monads, the most useful monadic frameworks I've seen are monads for parsing, and monads for representing probability distributions. If I needed to do one of those things in Clojure, I'd look closely at monad options. But since I haven't needed to do those things, and the common uses for monads are already covered, I haven't found a need to do any monadic style programming in my own code. --Mark -- 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
Re: accessing multiple return values
You're quite correct that the namespace \mechanism as it stands would not work for thisgood point. I guess I am just suggesting using the \syntax to do something let-like. Perhaps it would be better to make up a completely different syntax. As for your example, I'm still not sure we understand each other: (let [x (foo 17), dx foo/double-x] (do-something-with x dx)) Yes, that is how it would \look (I've dropped the user. as it isn't needed here). But why is the \name user.foo/double-x changing? It is dictated in the definition of foo, which is not itself changing. And (keeping in mind what I said above) once you refer to the \value in this way, it does not change. Later uses of foo should indeed \shadow this usage, not \change it. At any rate, it would be better to describe these as names within a function execution's \scope, not a function \namespace. Hopefully that is less confusing. As for storing values: as I said they should be \function-local, so that in (defn bar [...] (foo ...) (+ foo/double-x ...) ) foo/double-x expires after bar returns. On Jan 3, 2:15 pm, Tassilo Horn tass...@member.fsf.org wrote: nchurch nchubr...@gmail.com writes: Replying to Tassilo: I'm not quite sure I understand this problem: then changing its name requires changing all places where clojure.core.quotient/remainder is used surely the call to Values takes place inside the function definition, which happens \once. If you want a different variable name on \use, you use a let; if you want to return a different variable name on \definition, you use a let inside the function (or perhaps Values could have some sugar for renaming variables). I understand your proposal in such a way, that in a function (defn foo [x] (let [double-x (* 2 x)] (values x double-x))) the `values' was actually a macro that 1. creates a namespace for the function (user.foo) 2. creates a var holding the last second value (user.foo/double-x) where the name of the var is dictated by the local var holding the value 3. expands into code that sets user.foo/double-x at runtime and then returns the first value x Then, if I want to use the second value returned by foo in my code, I'd so something like (let [x (foo 17), dx user.foo/double-x] (do-something-with x dx)) Since I have to refer to user.foo/double-x to get the second value, once that name changes, I have to change my code, too. But probably, I've simply misunderstood your intent. It's true that quotient/remainder must be thread-local (in fact it should really be function-local), but this makes it no different than a let-variable or a function parameter; it doesn't necessarily mean it is mutable. Is X mutable in (let [X 1 X (inc X)]) ? Nope, the latter X shadows the former X. But there's no such thing for vars in a namespace. If you slapped that X in a data structure, you would not find it changing under your nose. quotient/remainder really has to behave in the same wayimagine the quotient call creates an invisible let every time. Sorry, I don't get you. What am I misinterpreting in your approach? To me, it looks like you want to bind the multiple values to vars in an ad-hoc namespace corresponding to a function. Then, there's no such thing as a lexical scope provided by let. A namespace is a globally accessible thingy. Perhaps I should explain why I think this is simple. It's simple because a) it allows you to ignore the extra values unless you want them and Well, the Common Lisp approach does so, too. b) it gives you ready-to-use names. To my taste, b) is very important. To me, that's a major downside. (quotient 5 2) (quotient 8 3) quotient(5 2)/remainder -- 1 Huh, you want to create a namespace not only for each function but for each function call? And then store the multiple values for each of them? Bye, Tassilo -- 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
Understanding the quoting of a symbol in a list
Hi All, So, I've been doing some experimentation in order to better understand the reader, and I can't figure out why I get the following results for these four calls: = ('foo); ((quote foo)) java.lang.IllegalArgumentException: Wrong number of args (0) passed to: Symbol (NO_SOURCE_FILE:0) = ('foo 1) ; ((quote foo) 1) nil = ('foo 1 2) ; ((quote foo) 1 2) 2 = ('foo 1 2 3) java.lang.IllegalArgumentException: Wrong number of args (3) passed to: Symbol (NO_SOURCE_FILE:0) What I expected is that either foo would be invoked (and so I'd see an error because it didn't exist) *or* I'd get a list ala (foo 1 2) - further, I can't understand why I get nil for an arity of 1 but 2 for an arity of two). Anyone have an explanation? I'm off to find the impl for Symbol and see if I can figure out how it is being invoked here... Thanks, Bill -- 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
Re: Understanding the quoting of a symbol in a list
If I could hazard a guess, it has to do with symbol lookup in maps. Try the following: ('foo {'foo 1}) ('foo {'bloo 1} 4) when you do ('foo 1), it can't find foo in 1 (because it isn't there, and 1 isn't even a map), so it returns nil. If you do ('foo 1 2), you've just provided a default value, which it dutifully returns. It's interesting that symbols don't care whether they are passed maps or notfun fact! On Jan 3, 2:47 pm, Bill Caputo logos...@gmail.com wrote: Hi All, So, I've been doing some experimentation in order to better understand the reader, and I can't figure out why I get the following results for these four calls: = ('foo) ; ((quote foo)) java.lang.IllegalArgumentException: Wrong number of args (0) passed to: Symbol (NO_SOURCE_FILE:0) = ('foo 1) ; ((quote foo) 1) nil = ('foo 1 2) ; ((quote foo) 1 2) 2 = ('foo 1 2 3) java.lang.IllegalArgumentException: Wrong number of args (3) passed to: Symbol (NO_SOURCE_FILE:0) What I expected is that either foo would be invoked (and so I'd see an error because it didn't exist) *or* I'd get a list ala (foo 1 2) - further, I can't understand why I get nil for an arity of 1 but 2 for an arity of two). Anyone have an explanation? I'm off to find the impl for Symbol and see if I can figure out how it is being invoked here... Thanks, Bill -- 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
Re: Extending core.match to custom types
David Nolen dnolen.li...@gmail.com writes: Hi David, In my patterns, I want to have a :+type key with a value that's basically an interface name given as a symbol. The pattern should match, if the class of the object implements that interface (or an extended interface thereof) directly or indirectly. So that would be my ideal user interface: --8---cut here---start-8--- (match [obj] [{:+type 'Cat :mice 4}] :1 [{:+type 'Dog :cats 3}] :2 [{:+type 'Mammal}]:3 :else :nope) --8---cut here---end---8--- This is a known missing feature and there's a couple of open questions as far as how to best implement this. It should probably support Java classes, Java interfaces, types, records, protocols and high performance hinted access to fields. I'm not sure, if you've stopped reading there, so let me make my issue clear. I'm *not* especially interested in some new feature for efficiently matching on types, although that wouldn't be bad either. What I'd like to have was a way to influence when a certain key with a certain value matches for my IMatchLookup extending custom type. So if IMatchLookup/val-at would be allowed to return a predicate that given the value from the pattern tests if the match succeeds. Here's a patch against the master version of core.match that makes my Cat, Dog, Mamal example work, but it's only meant for illustration. --8---cut here---start-8--- --- a/src/main/clojure/clojure/core/match.clj +++ b/src/main/clojure/clojure/core/match.clj @@ -864,8 +864,12 @@ (to-source* [this ocr] (cond (= l ()) `(empty? ~ocr) - (and (symbol? l) (not (- l meta :local))) `(= ~ocr '~l) - :else `(= ~ocr ~l))) + (and (symbol? l) (not (- l meta :local))) `(if (fn? ~ocr) + (~ocr '~l) + (= ~ocr '~l)) + :else `(if (fn? ~ocr) + (~ocr ~l) + (= ~ocr ~l Object (toString [_] (if (nil? l) --8---cut here---end---8--- I changed the LiteralPattern to-source* function to include a check if ocr is a function. In that case, I apply it to the value l, else I stick to the usulal (= ocr l) comparison. With that change, I can make my val-at implementations return predicates like so: --8---cut here---start-8--- (extend-protocol IMatchLookup ;; ... de.uni_koblenz.jgralab.Vertex (val-at [this k not-found] (case k :+type (fn [x] ((core/type-matcher (graph this) x) this)) ;; ... (match-attribute this k not-found)) --8---cut here---end---8--- That makes my Cat, Dog, Mammal example work fine. But of course, it works only for literal patterns, whereas my `type-matcher' function above also accepts type specifications like [:and !Cat !Dog!] meaning the object's type must be not a Cat and not exactly a Dog (but some Dog subtype would be fine, and of course Birds, Fish, etc.). So how would one tackle that issue in a general way? I guess, we'd need some new pattern type, PredicatePattern, right? What might be a good syntax for it? If you beat me to it, I'd give it a shot. Bye, Tassilo -- 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
Re: accessing multiple return values
nchurch nchubr...@gmail.com writes: You're quite correct that the namespace \mechanism as it stands would not work for thisgood point. I guess I am just suggesting using the \syntax to do something let-like. Perhaps it would be better to make up a completely different syntax. As for your example, I'm still not sure we understand each other: (let [x (foo 17), dx foo/double-x] (do-something-with x dx)) Yes, that is how it would \look (I've dropped the user. as it isn't needed here). But why is the \name user.foo/double-x changing? Because the developer of the library refactored the foo function and thereby changed the local double-x to double-value. Library developers usually refrain from renaming functions, but the internals of a function itself shouldn't be of any interest to users. At any rate, it would be better to describe these as names within a function execution's \scope, not a function \namespace. Hopefully that is less confusing. As for storing values: as I said they should be \function-local, so that in (defn bar [...] (foo ...) ;; 1 (bar ...) ;; 2 (+ foo/double-x ...) ) foo/double-x expires after bar returns. What if bar is recursive like above. What's the value of foo/double-x in that case? The value of the call in line 1, or the value from the last foo in the recursive call in 2? I think, I'll stop here. You won't convince me that this approach is practicable anytime soon. ;-) Bye, Tassilo -- 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
Re: Understanding the quoting of a symbol in a list
I'm not 100% sure but this is a side effect of the property that symbols can be used as functions that find themselves on maps. For instance: (def m {'a 1 'b 2 'c 3}) ('a m) ;= 1 ('b m) ;= 2 and, when the symbols is not found, we have: ('d m) ;= nilurn ('d m :nono) ;= :nono So a symbol is a function with one or two parameters, the first one the map to find itself too and the second, the value to return if not found. In your example 1 is the supposed map (and 'foo is never found on it) and 2 is the default value to use. If you want to read the implementation is in clojure.lang.Symbolhttps://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Symbol.java . Juan Manuel -- 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
Re: accessing multiple return values
I think, I'll stop here. You won't convince me that this approach is practicable anytime soon. ;-) I certainly won't try too hard either. I'm not questioning here whether it is immediately practicable to implement (maybe not, and in case a very long discussion) but is it potentially useful? (A shorter discussion.) In answer to your questions: The name of a returned value, of course, \does become part of the interface. Perhaps library writers would want to have a discipline of using their own internal names and then passing them out in one final values call inside of a let. As to the second: the recursive (bar ...) call has no effect on any foo-values used outside of it, whether before or after. This accords with our expectation for how functions work. Think of Values as a magical macro that \at \runtime reaches outside of the function it was used in and writes a little let inside the calling function's scope. Is this possible? I don't think so. Presumably it would have to be part of the language, just like Values is part of Common Lisp. -- 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
Re: Extending core.match to custom types
Putting that kind of logic in IMatchLookup doesn't make much sense to me: I'm not sure about the following syntax, but something like this could be done w/o interfering with IMatchLookup. (match [obj] [({:mice 4} :type cat)] ... [({:cats 4} :type dog)] ... [({:cats 4} :type :not [cat dog]] ...) This can be done by creating something like TypePattern which would understand these various cases. However it does sound like you want predicate dispatch. Whatever syntax is decided upon needs to work for the open dispatch case as well as it does for the matching case. Predicate dispatch is on the roadmap but still some ways off. Definitely open to discussion. David On Tue, Jan 3, 2012 at 2:56 PM, Tassilo Horn tass...@member.fsf.org wrote: David Nolen dnolen.li...@gmail.com writes: Hi David, In my patterns, I want to have a :+type key with a value that's basically an interface name given as a symbol. The pattern should match, if the class of the object implements that interface (or an extended interface thereof) directly or indirectly. So that would be my ideal user interface: --8---cut here---start-8--- (match [obj] [{:+type 'Cat :mice 4}] :1 [{:+type 'Dog :cats 3}] :2 [{:+type 'Mammal}]:3 :else :nope) --8---cut here---end---8--- This is a known missing feature and there's a couple of open questions as far as how to best implement this. It should probably support Java classes, Java interfaces, types, records, protocols and high performance hinted access to fields. I'm not sure, if you've stopped reading there, so let me make my issue clear. I'm *not* especially interested in some new feature for efficiently matching on types, although that wouldn't be bad either. What I'd like to have was a way to influence when a certain key with a certain value matches for my IMatchLookup extending custom type. So if IMatchLookup/val-at would be allowed to return a predicate that given the value from the pattern tests if the match succeeds. Here's a patch against the master version of core.match that makes my Cat, Dog, Mamal example work, but it's only meant for illustration. --8---cut here---start-8--- --- a/src/main/clojure/clojure/core/match.clj +++ b/src/main/clojure/clojure/core/match.clj @@ -864,8 +864,12 @@ (to-source* [this ocr] (cond (= l ()) `(empty? ~ocr) - (and (symbol? l) (not (- l meta :local))) `(= ~ocr '~l) - :else `(= ~ocr ~l))) + (and (symbol? l) (not (- l meta :local))) `(if (fn? ~ocr) + (~ocr '~l) + (= ~ocr '~l)) + :else `(if (fn? ~ocr) + (~ocr ~l) + (= ~ocr ~l Object (toString [_] (if (nil? l) --8---cut here---end---8--- I changed the LiteralPattern to-source* function to include a check if ocr is a function. In that case, I apply it to the value l, else I stick to the usulal (= ocr l) comparison. With that change, I can make my val-at implementations return predicates like so: --8---cut here---start-8--- (extend-protocol IMatchLookup ;; ... de.uni_koblenz.jgralab.Vertex (val-at [this k not-found] (case k :+type (fn [x] ((core/type-matcher (graph this) x) this)) ;; ... (match-attribute this k not-found)) --8---cut here---end---8--- That makes my Cat, Dog, Mammal example work fine. But of course, it works only for literal patterns, whereas my `type-matcher' function above also accepts type specifications like [:and !Cat !Dog!] meaning the object's type must be not a Cat and not exactly a Dog (but some Dog subtype would be fine, and of course Birds, Fish, etc.). So how would one tackle that issue in a general way? I guess, we'd need some new pattern type, PredicatePattern, right? What might be a good syntax for it? If you beat me to it, I'd give it a shot. Bye, Tassilo -- 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 -- 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
Re: How can I make this kind of error message more useful?
David and Meikel: Thanks for your responses, but it appears to me that what you say applies only to error messages referring to evaluation of defn expressions. Constructing my function definitions in a file separate from the REPL and then recompiling the entire file with a load-file whenever I make a change results in the correct line number being given to me for errors detected by the compiler -- but if an error occurs later when I am exercising the compiled code, the line number given to me doesn't appear to refer to the source file from which the compiling was done -- nor does the line number given to me for an error occurring in evaluation of an expression entered in the REPL refer to the REPL line within which the expression occurred. To wit, for my original example error message java.lang.Exception: Unsupported binding form: (quote symb) (NO_SOURCE_FILE:5045) the REPL line which resulted in the error message was 15392, not 5045. So where does the 5045 come from? --Larry On 1/3/12 12:59 PM, Meikel Brandmeyer wrote: Hi, Am 03.01.2012 um 18:24 schrieb David Nolen: On Tue, Jan 3, 2012 at 12:09 PM, Larry Travistra...@cs.wisc.edu wrote: But my error messages are more likely to look like this: java.lang.Exception: Unsupported binding form: (quote symb) (NO_SOURCE_FILE:5045) Where does the 5045 come from and what does it mean? Is there some way I could manage and load my defn files, or manage my evaluations of defn expressions in the REPL, so that such error messages would always give me a useful line number like the 323 in the first example? You obviously type in a lot in the repl. NO_SOURCE_FILE usually means repl, and 5045 is exactly that line typed into the repl. If you want to change that, you have to put your function definitions into files. Loading from the file will then give the accurate information form the former example. If you want accurate error locations make sure to recompile the whole file instead of evaluating expressions one at a time. The tools could of course improve here by setting the line number explicitly when evaluating expressions one at a time. VimClojure does set the file and line information correctly when sending single definitions from a clojure buffer to a server backend. So the last function sent will always give accurate information. However the definitions following the sent toplevel form might get slowly out of sync. So reloading the whole file from time to time is a good idea to get everything in sync again. (Beware other dangers like redefined protocols etc.) Sincerely Meikel -- 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
Re: Understanding the quoting of a symbol in a list
On Tue, Jan 3, 2012 at 2:11 PM, JuanManuel Gimeno Illa jmgim...@gmail.com wrote: I'm not 100% sure but this is a side effect of the property that symbols can be used as functions that find themselves on maps. Thanks Juan Manuel - that's the thing I was missing (and thanks for the source link). bill -- 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
Re: Use You a Spaced Repetition System for Great Good!
Hi Tim, Great idea re: GitHub! I'm guessing the Clojure decks could cover, multiple things if tagged appropriately and could be studied in various section. Or there could be multiple decks dealing with differing material. I'm not very familiar with github, but it is high time I really check it out and would be a great place for this sort of project. Have you found using an SRS helped with more than just studying on your own with regard to development? Are you experiencing good retention rates and reduced practice time reviewing with Anki? -Joshua On Jan 3, 12:25 pm, daly d...@axiom-developer.org wrote: I have built several Anki SRS decks for learning. I am building one now on American Sign Language. A Clojure deck would be a good idea. We could put a simple deck on github and make it so others could contribute. What should it cover? Only language syntax? Idiomatic forms (like lazy sequences)? Sections on Java interop? Tim Daly On Tue, 2012-01-03 at 18:19 +0100, Linus Ericsson wrote: Hi Joshua! I've been using Anki for repeating unsorted Clojure-stuff in about a year. It's good for knowing all the instructions and source code, but the key to success is always to solve more or less complicated problems (4clojure.org etc). On the practical side I have a lot left to learn, also since I'm not very skilled in algoritms in other languages [because the have so much boilerplate and therefore is boring to program in]. /Linus 2012/1/3 Joshua jos...@milehighcode.com Anybody else using a spaced repetition system (SRS) for Clojure learning? What about just general programming? How did it work out for you? I've just started using Anki and I uploaded a Clojure Sequence API shared deck. I'm hoping others might be interested in adding other Clojure related material to Anki. If you aren't familiar with the SRS concept, I wrote a short blog entry about it and how to import the Sequence API deck: http://blog.milehighcode.com/2012/01/use-you-spaced-repetition-system... -- 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 -- 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 -- 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
Re: accessing multiple return values
I see two fairly straightforward paths to simulating multiple returns without breaking existing callers. Both take advantage of thread-local state and establish one convention for the caller: before calling the function again, every caller interested the extra return values must ask for these extra returned values before calling the function again. 1. Use and Abuse VarsThe multiple return idea sounds a lot like the global errno facility used commonly in C to communicate out of band errors that cannot be conveniently conveyed via the function's actually return, except with namespacing to help multiple functions cooperate for the scarce resources. That bit of magic can be pretty nasty and metadata usually solves the majority of cases needed to move that auxiliary information (errno changed from a simple global variable to a complicated macro with the advent of multi-threaded C applications). However, in cases that metadata simply is unavailable, one way might be to augment the run time system with a mapping of functions to a thread local store of this auxiliary information just like errno. Clojure already comes with batteries to handle this case called push- thread-bindings. Push-thread-bindings allows a function to arbitrarily associate data with predetermined vars, and get-thread- bindings provides a function to retreive the information stored in the thread. Then, all that would be necessary to establish multiple returns would be to establish a dynamic var associated with each function that wanted to be able to return multiple objects. The interested caller would just know to read this preveriously var (probably via macro) to get the extra data it wanted. The only downside is that, per the documentation, push-thread-bindings does not handle its own housekeeping: it requires the calling function to ensure that the thread bindings are cleaned up via pop-thread- bindings, called in a finally block. This, of course, is not ideal, because the function that establishes the extra information can't be sure when or even if its own caller will use it! A more magical push- thread-bindings that could clean up after itself upon thread completion is necessary. Essentially, it sounds like dynamic vars work basically the way you want. If there is a good way to garbage collect them when the thread dies, a couple macros will make implementation relatively straightforward. By the way, more flexibly handling dynamic vars seems to be part of a general goal for the future: http://dev.clojure.org/display/design/Improve+Binding. Directly using the ThreadLocal class might also provide you with all the machinery necessary to implement this idea and provide garbage collection for free on thread completion. 2. Use and Abuse Metadata on the FunctionSimilar to memoize, we could store extra return values in function's own metadata via an atom that mapped Java thread-id's to extra return values. To return an extra value, the function would simply grab its own metadata set an extra return value by thread-id. Callers wanting to access this extra data would be provided a macro to look this value up on demand, probably passing the function (something like (return-more! f)). Subsequent calls could just continually update this value. This essentially would emulate thread-local variables though, so the first approach is probably preferable. Either way, this sounds like it might be implementable via a nice little library without having to change the language at all, with very little namespace mucking required. Hope that helps,Mark On Jan 3, 12:24 pm, nchurch nchubr...@gmail.com wrote: I think, I'll stop here. You won't convince me that this approach is practicable anytime soon. ;-) I certainly won't try too hard either. I'm not questioning here whether it is immediately practicable to implement (maybe not, and in case a very long discussion) but is it potentially useful? (A shorter discussion.) In answer to your questions: The name of a returned value, of course, \does become part of the interface. Perhaps library writers would want to have a discipline of using their own internal names and then passing them out in one final values call inside of a let. As to the second: the recursive (bar ...) call has no effect on any foo-values used outside of it, whether before or after. This accords with our expectation for how functions work. Think of Values as a magical macro that \at \runtime reaches outside of the function it was used in and writes a little let inside the calling function's scope. Is this possible? I don't think so. Presumably it would have to be part of the language, just like Values is part of Common Lisp. -- 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
Re: accessing multiple return values
It seems like we're talking about conflation of language implementation details to simulate a hash-map. Why not just use a hash-map for named values? Or a lazy sequence? A function returns a 'value', which can be a single thing, a collection of things, or even an arbitrary graph of things. If a indirection by a name is required to reach a value later, then what you really have as your return value conceptually is a map, and actually returning the map would be more obvious than projecting the map onto a namespace, with all the baggage that comes with that. The downside would be having to refer to the first value in calling code by name, which I believe is an upside due to its clarity. A function that returns 'multiple objects' is equivalent to a function that returns a meta-object that points to the multiple objects. Isn't that much more explicit than documenting a hidden var with all its concurrency semantics, simpler, less verbose AFAICT, and more of a functional approach? On Jan 3, 6:05 pm, meb meba...@gmail.com wrote: I see two fairly straightforward paths to simulating multiple returns without breaking existing callers. Both take advantage of thread-local state and establish one convention for the caller: before calling the function again, every caller interested the extra return values must ask for these extra returned values before calling the function again. 1. Use and Abuse VarsThe multiple return idea sounds a lot like the global errno facility used commonly in C to communicate out of band errors that cannot be conveniently conveyed via the function's actually return, except with namespacing to help multiple functions cooperate for the scarce resources. That bit of magic can be pretty nasty and metadata usually solves the majority of cases needed to move that auxiliary information (errno changed from a simple global variable to a complicated macro with the advent of multi-threaded C applications). However, in cases that metadata simply is unavailable, one way might be to augment the run time system with a mapping of functions to a thread local store of this auxiliary information just like errno. Clojure already comes with batteries to handle this case called push- thread-bindings. Push-thread-bindings allows a function to arbitrarily associate data with predetermined vars, and get-thread- bindings provides a function to retreive the information stored in the thread. Then, all that would be necessary to establish multiple returns would be to establish a dynamic var associated with each function that wanted to be able to return multiple objects. The interested caller would just know to read this preveriously var (probably via macro) to get the extra data it wanted. The only downside is that, per the documentation, push-thread-bindings does not handle its own housekeeping: it requires the calling function to ensure that the thread bindings are cleaned up via pop-thread- bindings, called in a finally block. This, of course, is not ideal, because the function that establishes the extra information can't be sure when or even if its own caller will use it! A more magical push- thread-bindings that could clean up after itself upon thread completion is necessary. Essentially, it sounds like dynamic vars work basically the way you want. If there is a good way to garbage collect them when the thread dies, a couple macros will make implementation relatively straightforward. By the way, more flexibly handling dynamic vars seems to be part of a general goal for the future:http://dev.clojure.org/display/design/Improve+Binding. Directly using the ThreadLocal class might also provide you with all the machinery necessary to implement this idea and provide garbage collection for free on thread completion. 2. Use and Abuse Metadata on the FunctionSimilar to memoize, we could store extra return values in function's own metadata via an atom that mapped Java thread-id's to extra return values. To return an extra value, the function would simply grab its own metadata set an extra return value by thread-id. Callers wanting to access this extra data would be provided a macro to look this value up on demand, probably passing the function (something like (return-more! f)). Subsequent calls could just continually update this value. This essentially would emulate thread-local variables though, so the first approach is probably preferable. Either way, this sounds like it might be implementable via a nice little library without having to change the language at all, with very little namespace mucking required. Hope that helps,Mark On Jan 3, 12:24 pm, nchurch nchubr...@gmail.com wrote: I think, I'll stop here. You won't convince me that this approach is practicable anytime soon. ;-) I certainly won't try too hard either. I'm not questioning here whether it is immediately practicable to implement (maybe not, and in case a very
Re: accessing multiple return values
On Tue, Jan 3, 2012 at 6:05 PM, meb meba...@gmail.com wrote: I see two fairly straightforward paths to simulating multiple returns without breaking existing callers. Both take advantage of thread-local state and establish one convention for the caller ... Both of them have reentrancy problems -- in the push-thread-bindings case, only if a caller doesn't use the extra values (and pop the thread bindings), but that may be a common case. You mentioned memoization, though, which might offer a superior alternative in the case of pure functions: (let [foo-memo-cache (atom {}) bar-memo-cache (atom {})] (defn foo ...) (defn bar ...)) ... (foo x y) (bar x y) The idea here is that foo and bar can see and modify one anothers' memoization caches. If computing (foo x y) can cheaply also compute (bar x y), then it can stuff that into bar's memoization cache and return its own result; the subsequent call to (bar x y) then doesn't duplicate the computation, as the result's cached. Works well only if foo and bar are (conceptually) pure functions. May be done so that foo and bar can be called in either order. No problems with reentrancy or thread-safety. -- 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
Re: Do you use Monads in your real clojure applications
In MVC pattern, Model should take responsibility for business logic. Therefore I write validate function for creating in the model. If creating a instance of the model should be safe, I must validate a parameter in the create function. My problem is that a controller have to validate a parameter twice in the validate function and the create function. Ring handler example (defn handler [{:keys [params] :as req}] (if (person/valid? params) {:status 200 :body (json/generate-string (person/create params))} {:status 400})) I think this might be suited to monads, which I don't fully understand. On Jan 4, 4:35 am, Mark Engelberg mark.engelb...@gmail.com wrote: Some of the most common uses for monads have pre-existing mechanisms with Clojure to handle them, e.g.: sequence monad (for) state monad (Clojure has many stateful mechansisms) maybe monad (Clojure programmers usually just return nil for failure, and use something like when-let to process it) In terms of higher-level DSLs constructed out of monads, the most useful monadic frameworks I've seen are monads for parsing, and monads for representing probability distributions. If I needed to do one of those things in Clojure, I'd look closely at monad options. But since I haven't needed to do those things, and the common uses for monads are already covered, I haven't found a need to do any monadic style programming in my own code. --Mark -- 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
Re: [ANN] swank-clojure 1.3.4 released
Phil There are lots of problems with version ranges, but this would be a bad idea for Ring specifically because it would allow backwards-incompatible versions to be pulled in when a new breaking clj-stacktrace version is released. Thank you for sharing your thoughts. 2012/1/2 Phil Hagelberg p...@hagelb.org: Takahiro fat...@googlemail.com writes: http://imgur.com/5NCEW Is any procedure needed? I've tried 1.3.4 with clojure 1.2.1/1.3.0 and Emacs 23.3. My .emacs.el includes only load-path and marmalade settings. including [ring 1.0.1] in my project.clj, which uses clj-stacktrace 0.2.2 instead of 0.2.4. This is actually already mentioned, but I'll try to make it clearer. Do you think this is good? I think ring should specify dependency using version range like below. [clj-stacktrace [0.2.2,)] ;; 0.2.2 = x http://docs.codehaus.org/display/MAVEN/Dependency+Mediation+and+Conflict+Resolution I didn't know it until recently, but now I think wherever possible every library should specify version with it. There are lots of problems with version ranges, but this would be a bad idea for Ring specifically because it would allow backwards-incompatible versions to be pulled in when a new breaking clj-stacktrace version is released. Specifying a range with an upper bound is slightly better, but it will prevent ring from working with newer versions that are compatible but don't exist at the time of ring's release since ranged version numbers are absolute and Maven will refuse to resolve two non-overlapping ranges in the same build. I used to think more people should use version ranges, but I recently discovered these issues and now recommend against their use entirely. -Phil -- 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 -- 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
macro question
hmmm macro question: ; here's a macro that assembles many puts. It serves no purpose to me (and doesn't even make sense in its current form). It's just something I hit playing around and learning macros. (defmacro doto-putter [x y xs] `(doto (java.util.HashMap.) (.put ~x ~y) ~@(for [[k v] xs]`(.put ~k ~v user= (doto-putter c 3 {a 1 b 2}) #HashMap {b=2, c=3, a=1} however: =(defn omg [x y xs](doto-putter x y xs)) CompilerException java.lang.IllegalArgumentException: Don't know how to create ISeq from: clojure.lang.Symbol, compiling:(NO_SOURCE_PATH:2) I'm thinking the issue seems to be that it's not resolving xs because this works: (defmacro doto-putter [x y] `(doto (java.util.HashMap.) (.put ~x ~y) ~@(for [[k v]{a 1 b 2}]`(.put ~k ~v user= (defn omg [x y](doto-putter x y)) #'user/omg user=(omg c 3) #HashMap {b=2, c=3, a=1} what am I missing? None of my other macros have this problem. -- 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
Re: macro question
On Jan 3, 7:22 pm, Trevor tcr1...@gmail.com wrote: hmmm macro question: ; here's a macro that assembles many puts. It serves no purpose to me (and doesn't even make sense in its current form). It's just something I hit playing around and learning macros. (defmacro doto-putter [x y xs] `(doto (java.util.HashMap.) (.put ~x ~y) ~@(for [[k v] xs]`(.put ~k ~v user= (doto-putter c 3 {a 1 b 2}) #HashMap {b=2, c=3, a=1} however: =(defn omg [x y xs](doto-putter x y xs)) CompilerException java.lang.IllegalArgumentException: Don't know how to create ISeq from: clojure.lang.Symbol, compiling:(NO_SOURCE_PATH:2) I'm thinking the issue seems to be that it's not resolving xs because this works: (defmacro doto-putter [x y] `(doto (java.util.HashMap.) (.put ~x ~y) ~@(for [[k v]{a 1 b 2}]`(.put ~k ~v user= (defn omg [x y](doto-putter x y)) #'user/omg user=(omg c 3) #HashMap {b=2, c=3, a=1} what am I missing? None of my other macros have this problem. http://stackoverflow.com/questions/5813075/passing-map-of-functions-to-a-macro is another symptom of the same problem. The point is that macros have access only to the code they're changing, not any related/nearby values or code, and since you gave it the *symbols* (that is, code) x, y, and xs, it doesn't know their values. You're asking a macro to work with runtime values, not compile-time code; it can't do that, but fortunately a function easily can! So this is just another case of using a macro when a function will do. -- 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
Storing clojure lists and maps in Redis
I am trying to use Redis as a data structure cache for my clojure application. Does anybody have experience/code/ideas that can write/ read a clojure complex data structure to the Redis cache. For example I have a list of maps as shown below: (def m1 [{ total {:end_mv_base 721470021.02M, :ret_base -2.1510871798903652, :val_added_base -15748655.52M, :adj_mv_base 758084903.7M, :beg_mv_base 740767309.10M, :pct_contrib_fx 0.6974363304530005, :ccy_spot 0.49639198233447535, :pct_contrib_base -2.1510871798904274, :sec_count 90, :ret_period_base -2.1523676719086393} 55 {:end_mv_base 5513170.48M, :ret_base 7.038528325335092, :val_added_base 362529.33M, :adj_mv_base 5541883.033M, :beg_mv_base 5150641.15M, :pct_contrib_fx 0.004896503822395695, :ccy_spot 0.004572016877500618, :pct_contrib_base 0.04959174749327096, :sec_count 1, :ret_period_base 7.0385282034552965} 45 {:end_mv_base 4265060.12M, :ret_base -1.1595615568738782, :val_added_base -50036.20M, :adj_mv_base 4550627.682M, :beg_mv_base 4315096.32M, :pct_contrib_fx 0.0045309069298927205, :ccy_spot 0.003163500114766722, :pct_contrib_base -0.00614820276001893, :sec_count 1, :ret_period_base -1.1595616030211309} }]) How can I store the above to Redis and read it back to recreate it? Thanks Shoeb -- 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
Re: Storing clojure lists and maps in Redis
On Tue, Jan 3, 2012 at 22:30, Shoeb Bhinderwala shoeb.bhinderw...@gmail.com wrote: I am trying to use Redis as a data structure cache for my clojure application. Does anybody have experience/code/ideas that can write/ read a clojure complex data structure to the Redis cache. […] How can I store the above to Redis and read it back to recreate it? Personally, I would use JSON, MesssagePack, Protocol Buffers, or something else language independent to encode the data. This has two advantages: one, someone else already worked out how to do it, and ported it to Java or Clojure, and two, you can also access it from some other language. (When, eventually, you find you need that.) Daniel -- ♲ Made with 100 percent post-consumer electrons -- 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
Re: Storing clojure lists and maps in Redis
Shoeb, What about storing it as a string? You can either use pr-str or data.json/generate-string. You can then read it back using read-string or the equivalent json fn. Regards, BG On Wed, Jan 4, 2012 at 12:00 PM, Shoeb Bhinderwala shoeb.bhinderw...@gmail.com wrote: I am trying to use Redis as a data structure cache for my clojure application. Does anybody have experience/code/ideas that can write/ read a clojure complex data structure to the Redis cache. For example I have a list of maps as shown below: (def m1 [{ total {:end_mv_base 721470021.02M, :ret_base -2.1510871798903652, :val_added_base -15748655.52M, :adj_mv_base 758084903.7M, :beg_mv_base 740767309.10M, :pct_contrib_fx 0.6974363304530005, :ccy_spot 0.49639198233447535, :pct_contrib_base -2.1510871798904274, :sec_count 90, :ret_period_base -2.1523676719086393} 55 {:end_mv_base 5513170.48M, :ret_base 7.038528325335092, :val_added_base 362529.33M, :adj_mv_base 5541883.033M, :beg_mv_base 5150641.15M, :pct_contrib_fx 0.004896503822395695, :ccy_spot 0.004572016877500618, :pct_contrib_base 0.04959174749327096, :sec_count 1, :ret_period_base 7.0385282034552965} 45 {:end_mv_base 4265060.12M, :ret_base -1.1595615568738782, :val_added_base -50036.20M, :adj_mv_base 4550627.682M, :beg_mv_base 4315096.32M, :pct_contrib_fx 0.0045309069298927205, :ccy_spot 0.003163500114766722, :pct_contrib_base -0.00614820276001893, :sec_count 1, :ret_period_base -1.1595616030211309} }]) How can I store the above to Redis and read it back to recreate it? Thanks Shoeb -- 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 -- Baishampayan Ghose b.ghose at gmail.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
Re: Storing clojure lists and maps in Redis
We use Clojure's reader representation to serialize data structures as strings here and we still have some Java and JRuby code around. Previously we were using YAML (json was in it's infancy when we opted for YAML). A real pain in the ass... Now we use a couple of protocols callable from every where to decipher messages in an unified way crossing languages and representations (from/to low level representations, strings or persistent structures). It's faster, shorter, much more transparent, easier to debug and elegant. Luc Shoeb, What about storing it as a string? You can either use pr-str or data.json/generate-string. You can then read it back using read-string or the equivalent json fn. Regards, BG On Wed, Jan 4, 2012 at 12:00 PM, Shoeb Bhinderwala shoeb.bhinderw...@gmail.com wrote: I am trying to use Redis as a data structure cache for my clojure application. Does anybody have experience/code/ideas that can write/ read a clojure complex data structure to the Redis cache. For example I have a list of maps as shown below: sing (def m1 [{ total {:end_mv_base 721470021.02M, :ret_base -2.1510871798903652, :val_added_base -15748655.52M, :adj_mv_base 758084903.7M, :beg_mv_base 740767309.10M, :pct_contrib_fx 0.6974363304530005, :ccy_spot 0.49639198233447535, :pct_contrib_base -2.1510871798904274, :sec_count 90, :ret_period_base -2.1523676719086393} 55 {:end_mv_base 5513170.48M, :ret_base 7.038528325335092, :val_added_base 362529.33M, :adj_mv_base 5541883.033M, :beg_mv_base 5150641.15M, :pct_contrib_fx 0.004896503822395695, :ccy_spot 0.004572016877500618, :pct_contrib_base 0.04959174749327096, :sec_count 1, :ret_period_base 7.0385282034552965} 45 {:end_mv_base 4265060.12M, :ret_base -1.1595615568738782, :val_added_base -50036.20M, :adj_mv_base 4550627.682M, :beg_mv_base 4315096.32M, :pct_contrib_fx 0.0045309069298927205, :ccy_spot 0.003163500114766722, :pct_contrib_base -0.00614820276001893, :sec_count 1, :ret_period_base -1.1595616030211309} }]) How can I store the above to Redis and read it back to recreate it? Thanks Shoeb -- 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 -- Baishampayan Ghose b.ghose at gmail.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 -- Softaddictslprefonta...@softaddicts.ca sent by ibisMail! -- 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
Re: Storing clojure lists and maps in Redis
Daniel, Baishampayan - Thanks for the suggestion. I was able to do this extremely easily using the JSON library. I used the json-str and read-json functions. Shoeb On Jan 4, 1:38 am, Baishampayan Ghose b.gh...@gmail.com wrote: Shoeb, What about storing it as a string? You can either use pr-str or data.json/generate-string. You can then read it back using read-string or the equivalent json fn. Regards, BG On Wed, Jan 4, 2012 at 12:00 PM, Shoeb Bhinderwala shoeb.bhinderw...@gmail.com wrote: I am trying to use Redis as a data structure cache for my clojure application. Does anybody have experience/code/ideas that can write/ read a clojure complex data structure to the Redis cache. For example I have a list of maps as shown below: (def m1 [{ total {:end_mv_base 721470021.02M, :ret_base -2.1510871798903652, :val_added_base -15748655.52M, :adj_mv_base 758084903.7M, :beg_mv_base 740767309.10M, :pct_contrib_fx 0.6974363304530005, :ccy_spot 0.49639198233447535, :pct_contrib_base -2.1510871798904274, :sec_count 90, :ret_period_base -2.1523676719086393} 55 {:end_mv_base 5513170.48M, :ret_base 7.038528325335092, :val_added_base 362529.33M, :adj_mv_base 5541883.033M, :beg_mv_base 5150641.15M, :pct_contrib_fx 0.004896503822395695, :ccy_spot 0.004572016877500618, :pct_contrib_base 0.04959174749327096, :sec_count 1, :ret_period_base 7.0385282034552965} 45 {:end_mv_base 4265060.12M, :ret_base -1.1595615568738782, :val_added_base -50036.20M, :adj_mv_base 4550627.682M, :beg_mv_base 4315096.32M, :pct_contrib_fx 0.0045309069298927205, :ccy_spot 0.003163500114766722, :pct_contrib_base -0.00614820276001893, :sec_count 1, :ret_period_base -1.1595616030211309} }]) How can I store the above to Redis and read it back to recreate it? Thanks Shoeb -- 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 -- Baishampayan Ghose b.ghose at gmail.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
Re: [ANN] swank-clojure 1.3.4 released
The main feature in this release is Derek Mansen's work integrating clj-stacktrace into the debugger frames, so now you can get stack traces with alignment and colorization. I'm very excited about this release since it's a significant usability improvement: http://imgur.com/fD3rA I get the aligned and nicer stack traces, but no colors. I see Invalid face color in *Messages* repeated many times, so I suspect that has something to do with it. I've tried both clojure-jack-in and the lein swank instructions given in the README. I'm using GNU Emacs 24.0.92.1 with clojure-mode 1.11.5. Any ideas? jack. -- 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