Re: (iterate inc 2) vs (drop 2 (range)) in corecursion

2012-12-02 Thread Christophe Grand
Hi maclo,

Your code assume there is two "primes" sequences: the result and the one
being constructed. But there's only one and which is infinite.
You define your sequence as being (cons 2 something) and computing
"something" requires evaluating (every? #(pos? (mod 3 %)) (cons 2
something))
since (pos? (mod 3 2)) is true, every? continues processing the seq and
tries to evaluate (every? #(pos? (mod 3 %)) something).
So computing "something" requires knowing "something"!

The take-while is useful in that it reduces the scope of every to primes
already computed.

Your code works only because of a bug/unspecified behaviour which makes the
recursive reference of the sequence to be considered nil.

hth,

Christophe


On Sun, Dec 2, 2012 at 4:30 PM, maclo  wrote:

> Hi
>
>
>  user=> (def primes
>
>>   (cons 2
>> (filter
>>   (fn isprime[n]
>>
>> (every?
>>   #(pos? (mod n %))
>>   (take-while #(<=(* % %)n) primes)))
>>   (iterate inc 3
>> user=> (take 50 primes)
>> (2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97
>> 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193
>> 197 199 211 223 227 229)
>>
>
>  Is it really necessary to call 'take-while' ? The version without it
>
>
> (def primes
>   (cons 2
> (filter
>   (fn isprime? [n]
> (every? #(pos? (mod n %)) primes))
>   (iterate inc 3
>
> works for me as well. Is it safe to use this version or is using
> 'take-while' for some reason necessary ?
>
> maclo
>



-- 
On Clojure http://clj-me.cgrand.net/
Clojure Programming http://clojurebook.com
Training, Consulting & Contracting http://lambdanext.eu/

-- 
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: exception in 'map' mutates result to nil -- bug?

2012-12-02 Thread Hank
Julian, see my other post, it has nothing to do with map per se.

Apart from philosophical questions, the reason I need this to consistently 
raise an exception, is that I want to interrupt the map evaluation when it 
is slow, throwing an InteruptedException. I then want to recommence 
evaluation later. rinse, repeat. I can't recommence it if the sequence has 
been 'closed' with a final nil. Sounds like a fair use case?

On Monday, 3 December 2012 16:35:39 UTC+11, julianrz wrote:
>
> Hmm.. I think you are raising both a technical and a philosophical issue - 
> what exactly should a higher-order function return when some application of 
> the supplied function throws exception... The behaviors could be:
> 1) throw
> 2) return null
> 3) return an empty collection (do not continue after 1st failure)
> 4) same, but continue through all failures
> 5) return collection with valid applications only
> What is good behavior? We should have as little uncertainly as possible... 
> I have to admit my first thought is 'just don't allow it to throw, return 
> null instead'. This would allow to still collect results (where it does not 
> throw), and they will be at the matching index locations...
>
> Now the technicality. The map code I see for 1.4 is trying to append 
> result of all invocations to a buffer upfront. And each time it will fail, 
> and the buffer will be empty, hence empty result Source is a chunked 
> collection and there is only one chunk, it will be done immediately, and 
> not on subsequent calls - laziness has not started yet  
>
> Please contrast it with mapv, which results in a vector, not sequence
> user=> (def mapped (mapv (fn [_] (throw (Exception.))) [1 2 3]))
> Exception   user/fn--1 (NO_SOURCE_FILE:1)
> user=> mapped
> #
>
> Now the lazy-seq example - maybe the difference in behavior can be 
> explained by the fact that lazy-seq caches the result of body evaluation 
> and will keep returning it. Since there is an exception during each 
> evaluation, the caching does not quite happen, and it is re-evaluated?
>
> Should the behavior be the same in all 3 cases? I think so, at least for 
> consistency (unsure it can be achieved, though). But throwing in function 
> passed to map  really is something you should not do, and I would recommend 
> to change map function to return a null or throw -- to let you know that 
> your code can cause odd behavior. BTW I am not aware of any clojure book 
> that alerts you to that. 
>
> Also, maybe the implementation of map function should catch your exception 
> internally and produce a null, and return a sequence of nulls?
>
> -Julian
>
> On Sunday, December 2, 2012 5:58:08 AM UTC-8, Hank wrote:
>>
>> I'm mapping a function that throws an exception over a collection:
>>
>> => (def mapped (map (fn [_] (throw (Exception.))) [1 2 3]))
>> #'user/mapped
>>
>> 'map' is lazy so we're not expecting to see the exception until we're 
>> trying to access the result:
>> => mapped
>> Exception   user/fn--709 (NO_SOURCE_FILE:1)
>>
>> All good, let's do that again:
>> => mapped
>> ()
>>
>> Whoops! Is this by design? Why? Where does that empty sequence come from?
>>
>> 'map' is really just calling the lazy-seq macro but doing this with lazy 
>> seq works just fine:
>> => (def lazy (lazy-seq (throw (Exception.
>> #'user/lazy
>> => lazy
>> Exception   user/fn--733 (NO_SOURCE_FILE:1)
>> => lazy
>> Exception   user/fn--733 (NO_SOURCE_FILE:1)
>>
>> Same exception over and over again as it should be. I stared at the 
>> implementations of 'map' and lazy-seq/LazySeq for some hours but I really 
>> can't see it.
>>
>> Cheers
>> -- hank
>>
>>

-- 
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: exception in 'map' mutates result to nil -- bug?

2012-12-02 Thread Hank
I've got this narrowed down to what seems an interaction issue between 
macros and closures in lazy-seq. Run this code:

(defn gen-lazy []
  (let [coll [1 2 3]]
(lazy-seq
  (when-let [s (seq coll)]
(throw (Exception.))
)
  )
)
  )

(def lazy (gen-lazy))

(try
  (println "lazy:" lazy)
  (catch Exception ex
(println ex))
  )

(try
  (println "lazy, again:" lazy)
  (catch Exception ex
(println ex))
  )

... and explain to me what you see there. The first time, exception, the 
second time, empty list.

Now if you either a) remove the let statement and put the sequence [1 2 3] 
directly into where it says coll then it "works" = same exception in both 
cases.

(defn gen-lazy []
  (lazy-seq
(when-let [s (seq [1 2 3])]
  (throw (Exception.))
  )
)
  )

Or if you take out the when-let macro it works, too:

(defn gen-lazy []
  (let [coll [1 2 3]]
(lazy-seq
  (seq coll)
  (throw (Exception.))
  )
)
  )

Only the combination of closure + when-let macro breaks thigs. I know 
clojure does some funky things to closures in lazy-seq (see "... perform 
closed-over local clearing on the tail call of their body" on this page: 
http://clojure.org/lazy), this is related to the undocumented :once keyword 
on function calls. Maybe that interferes with macros? Or maybe I'm barking 
up the wrong tree.

-- hank


On Monday, 3 December 2012 00:58:08 UTC+11, Hank wrote:
>
> I'm mapping a function that throws an exception over a collection:
>
> => (def mapped (map (fn [_] (throw (Exception.))) [1 2 3]))
> #'user/mapped
>
> 'map' is lazy so we're not expecting to see the exception until we're 
> trying to access the result:
> => mapped
> Exception   user/fn--709 (NO_SOURCE_FILE:1)
>
> All good, let's do that again:
> => mapped
> ()
>
> Whoops! Is this by design? Why? Where does that empty sequence come from?
>
> 'map' is really just calling the lazy-seq macro but doing this with lazy 
> seq works just fine:
> => (def lazy (lazy-seq (throw (Exception.
> #'user/lazy
> => lazy
> Exception   user/fn--733 (NO_SOURCE_FILE:1)
> => lazy
> Exception   user/fn--733 (NO_SOURCE_FILE:1)
>
> Same exception over and over again as it should be. I stared at the 
> implementations of 'map' and lazy-seq/LazySeq for some hours but I really 
> can't see it.
>
> Cheers
> -- hank
>
>

-- 
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: exception in 'map' mutates result to nil -- bug?

2012-12-02 Thread julianrz
Hmm.. I think you are raising both a technical and a philosophical issue - 
what exactly should a higher-order function return when some application of 
the supplied function throws exception... The behaviors could be:
1) throw
2) return null
3) return an empty collection (do not continue after 1st failure)
4) same, but continue through all failures
5) return collection with valid applications only
What is good behavior? We should have as little uncertainly as possible... 
I have to admit my first thought is 'just don't allow it to throw, return 
null instead'. This would allow to still collect results (where it does not 
throw), and they will be at the matching index locations...

Now the technicality. The map code I see for 1.4 is trying to append result 
of all invocations to a buffer upfront. And each time it will fail, and the 
buffer will be empty, hence empty result Source is a chunked collection and 
there is only one chunk, it will be done immediately, and not on subsequent 
calls - laziness has not started yet  

Please contrast it with mapv, which results in a vector, not sequence
user=> (def mapped (mapv (fn [_] (throw (Exception.))) [1 2 3]))
Exception   user/fn--1 (NO_SOURCE_FILE:1)
user=> mapped
#

Now the lazy-seq example - maybe the difference in behavior can be 
explained by the fact that lazy-seq caches the result of body evaluation 
and will keep returning it. Since there is an exception during each 
evaluation, the caching does not quite happen, and it is re-evaluated?

Should the behavior be the same in all 3 cases? I think so, at least for 
consistency (unsure it can be achieved, though). But throwing in function 
passed to map  really is something you should not do, and I would recommend 
to change map function to return a null or throw -- to let you know that 
your code can cause odd behavior. BTW I am not aware of any clojure book 
that alerts you to that. 

Also, maybe the implementation of map function should catch your exception 
internally and produce a null, and return a sequence of nulls?

-Julian

On Sunday, December 2, 2012 5:58:08 AM UTC-8, Hank wrote:
>
> I'm mapping a function that throws an exception over a collection:
>
> => (def mapped (map (fn [_] (throw (Exception.))) [1 2 3]))
> #'user/mapped
>
> 'map' is lazy so we're not expecting to see the exception until we're 
> trying to access the result:
> => mapped
> Exception   user/fn--709 (NO_SOURCE_FILE:1)
>
> All good, let's do that again:
> => mapped
> ()
>
> Whoops! Is this by design? Why? Where does that empty sequence come from?
>
> 'map' is really just calling the lazy-seq macro but doing this with lazy 
> seq works just fine:
> => (def lazy (lazy-seq (throw (Exception.
> #'user/lazy
> => lazy
> Exception   user/fn--733 (NO_SOURCE_FILE:1)
> => lazy
> Exception   user/fn--733 (NO_SOURCE_FILE:1)
>
> Same exception over and over again as it should be. I stared at the 
> implementations of 'map' and lazy-seq/LazySeq for some hours but I really 
> can't see it.
>
> Cheers
> -- hank
>
>

-- 
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] ClojureScript release 0.0-1535 with G.Closure 0.0-2029

2012-12-02 Thread David Nolen
On Sun, Dec 2, 2012 at 2:11 AM, Evan Mezeske  wrote:

>
> That said what's the compelling reason these days for lein-cljsbuild to
>> depend on a specific version of ClojureScript? Are you relying on certain
>> aspects of the analyzer or compiler's API and find that they change quite
>> frequently?
>
>
> I guess the (debatably compelling) reason for that these days is just that
> I like the idea of providing a sensible default.  AFAIK, you can always
> override the version by adding it you a project's :dependencies if you want
> to (I'd test this but am in the middle of moving atm, without access to my
> stuff).
>
> Besides just having a sensible default, I also like to "endorse" a
> particular version of the compiler for a particular version of
> lein-cljsbuild.  Before any release, I do a few rounds of testing with the
> example projects and some of my personal stuff, and confirm that things
> seem to work.
>
> Now, if I'm wrong, and you can't just stick a different version of
> clojurescript in :dependencies and have it work, then I'd consider that a
> bug.
>

That sounds reasonable to me.

-- 
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: math expression simplifier, kibit implementation

2012-12-02 Thread David Nolen
On Sun, Dec 2, 2012 at 1:42 PM, Jonas  wrote:

>
>
> On Sunday, December 2, 2012 7:33:17 PM UTC+2, David Nolen wrote:
>
>> On Sat, Dec 1, 2012 at 12:24 AM, Jonas  wrote:
>>
>>>
>>> * Predicates on logic vars:
>>> [(foo (? x number?)) (bar ?x)] => match (foo 42) but not (foo :bar)
>>>
>>
>> This is now possible since we have constraints.
>>
>
> Awesome. Is this already in a released version of core.logic? Do you know
> of any examples I might study?
>

Not yet - but you can look at the code in master (and the tests) for some
ideas. I plan on adding what Kevin needs fairly soon to the simple unifier
and documenting it the high level interface - it will probably use the CVar
functionality I mentioned. It's a bit hard to make any promises about the
details of the constraint functionality as it's likely to change as I
better understand how all of this should work.


> * Segment vars:
>>> [(* ??x 1 ??y) (* ??x ??y)] => (* 4 3 2 1 2 3 4) would turn into (*
>>> 4 3 2 2 3 4)
>>> and
>>> [(* ??x 0 ??y) 0] => (* 1 2 3 0 4 5 6 7) would turn into 0
>>>
>>
>> This has been possible for some time - but you need to extend
>> unification. You need to create a wrapper around sequences and a new kind
>> of logic var. Kevin's work on the partial map (PMap) functionality is a
>> good starting point as well the work I've done on constrained vars (CVar).
>>
>
> I'd be interested in creating an SVar ("segment var") then. I'll start by
> trying to understand yours and Kevins work on CVar/PMap.
>

I'm not convinced this needs to be in core.logic proper but I'm more than
happy to answer any questions once you understand how PMap & CVar work.
It's a goal to allow many kinds of extensions to core.logic w/o needing to
directly modify the core.

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: Can anyone point me to that library that supports quasiquoting without full namespace expansion?

2012-12-02 Thread Armando Blancas
You can do:

user=> `[~'foo 1]
[foo 1]

On Sunday, December 2, 2012 10:24:29 AM UTC-8, Conrad wrote:
>
> I remember seeing it somewhere recently but I can't find it now...
>
> As you probably know, if you quasiquote in clojure it automatically adds 
> namespaces:
>
> > `[foo ~1]
> [mylibrary.core/foo 1]
>
> The library I am looking for lets you write:
>
> > (template [foo ~1])
> [foo 1]
>
> Thanks for your help!
>

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

Ann: cljs-uuid-utils (Re: CLJS: UUID generator for ClojureScript)

2012-12-02 Thread Frank Siebenlist
I've wrapped my random uuid generator up in a little library at:

https://github.com/franks42/cljs-uuid-utils

---
cljs-uuid-utils

ClojureScript micro-library with an implementation of a type 4, random UUID 
generator compatible with RFC-4122 and cljs.core/UUID (make-random-uuid), a 
uuid-string conformance validating predicate (valid-uuid?), and a UUID factory 
from uuid-string with conformance validation (make-uuid-from).
---

As mentioned before, clojure on the jvm can leverage the ubiquitous 
"java.util.UUID/randomUUID", while there is no generally available random uuid 
generator in the javascript world. Although this micro-lib addresses that issue 
somewhat, I believe that we should have a random-uuid generator as part of the 
batteries-included cljs-distro. 

Another issue that I came across is the fact that the java.util.UUID/fromString 
does do a conformance check of the presented uuid-string, and throws an 
exception if it does not pass. ClojureScript's reader yields a cljs.core/UUID 
instance for uuid-literals, but doesn't check for any conformance and 
essentially accepts any string. This could lead to interesting, surprising bugs 
during cljs-clj interop. 

Please let me know if you use this little library, and any suggestions/comments 
for improvement are always welcome.

Enjoy, FrankS.



On Nov 29, 2012, at 10:20 AM, David Nolen  wrote:

> Also note that testing with the Rhino REPL is not informative about 
> performance in anyway - you absolutely need to test your code against the 
> modern JS engines - V8, JavaScriptCore, or SpiderMonkey (with JIT turned on). 
> For code like this they are often 100X faster if not far greater than that.
> 
> 
> On Thu, Nov 29, 2012 at 1:07 PM, Frank Siebenlist 
>  wrote:
> Thanks for the feedback!
> 
> Defining the two helper functions outside of the function-scope doesn't seem 
> to have any effect on the performance numbers.
> 
> …but I have to confess that all testing was done at the repl without any 
> optimization so far…
> 
> -FS.
> 
> 
> 
> On Nov 29, 2012, at 8:36 AM, David Nolen  wrote:
> 
> > Oh though before you lift them out by hand - I would double check that 
> > :simple optimizations doesn't already do this for you :)
> >
> >
> > On Thu, Nov 29, 2012 at 1:25 AM, Frank Siebenlist 
> >  wrote:
> > I need UUIDs in my CLJS code…
> >
> > cljs.core does include a UUID type, but no generator.
> >
> > I found a couple of efforts and example code at 
> > https://github.com/davesann/cljs-uuid and 
> > http://catamorphic.wordpress.com/2012/03/02/generating-a-random-uuid-in-clojurescript,
> > but they didn't work with cljs.core/UUID or were too slow.
> >
> > There are many javascript versions out there, but that would require 
> > another external js-lib.
> > (really surpising that I couldn't find a UUID generator in closure-lib…)
> >
> > Please take a look at my UUID-playground at 
> > "https://gist.github.com/4159427";,
> > which includes a few implementations with some rudimentary timing results.
> >
> > Appreciate any comments or suggestions, or maybe a pointer to a faster, 
> > cleaner implementation...
> >
> > Thanks, FrankS.
> >
> > PS. I would think that the cljs-community would love to have a UUIDv4 
> > generator as part of the clojurescript distro...
> >
> >
> > --
> > 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
> 
> 
> -- 
> 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 optio

Re: Proposed change to let-> syntax

2012-12-02 Thread Terje Norderhaug
Here is the short form of the proposal below:

1. Make as-> in Clojure 1.5 have a syntax and semantic matching how fn
is used in pipelines.
2. Rename as-> to fn-> reflecting its similarity to fn.

-- Terje Norderhaug

On Sun, Dec 2, 2012 at 5:30 PM, Terje Norderhaug  wrote:
> On Thu, Nov 15, 2012 at 5:17 PM, Alan Malloy  wrote:
>> The primary point of let-> is that you can insert it into an existing ->
>> pipeline.
>>
>> (-> foo
>> (stuff)
>> (blah)
>> (let-> foo-with-stuff
>>   (for [x foo-with-stuff]
>> (inc x)))
>
> This use case of the macro now renamed as-> in Clojure 1.5 is already
> covered by using fn in a pipeline:
>
> (-> foo
> (stuff)
> (blah)
> ((fn [foo-with-stuff]
>(for [x foo-with-stuff]
>  (inc x)
>
> A benefit of using fn here is that it also works with ->> just the
> same. However, there is a place for a construct to simplify multiple
> uses of fn in a pipeline like in:
>
>  (-> foo
> (stuff)
> (blah)
> ((fn [foo]
>(for [x foo]
>  (inc x
> ((fn [foo]
>(for [x foo]
>  (dec x)
>
> I propose fn-> as name for a construct similar to as-> used like this:
>
> (-> foo
> (stuff)
> (blah)
> ((fn-> [foo]
>(for [x foo]
>  (inc x))
>(for [x foo]
>  (dec x)
>
> The fn-> macro defines an anonymous function using the same syntax as
> fn, with its forms threaded like in as-> where each evaluated form is
> bound to a symbol.
>
> In the example above, the result of the first 'for' form is bound to
> the 'foo' used by the second 'for' form. That is, within fn-> the
> items in the list bound to foo is first incremented and the resulting
> list bound to foo, then the items in the list bound to foo is
> decremented with the resulting list returned (incidentally leaving the
> list as before).
>
> Keeping the syntax and semantics of fn-> similar to fn provides an
> smooth upgrade path from current uses of fn in pipelines.
>
> -- Terje Norderhaug
>
>> On Thursday, November 15, 2012 10:35:59 AM UTC-8, Alex Nixon wrote:
>>>
>>> Hi all,
>>>
>>> I find the proposed function let-> in Clojure 1.5 very useful, but a bit
>>> ugly.  The arguments are backwards when compared to vanilla let, and it
>>> doesn't support destructuring where it easily could (which I believe would
>>> be helpful when threading 'state-like' maps, as I find let-> very useful
>>> for).
>>>
>>> I'd like to float an alternative implementation which improves on both
>>> these issues.  Thoughts?
>>>
>>> (defmacro new-let->
>>>   "Establishes bindings as provided for let, evaluates the first form
>>>in the lexical context of that binding, then re-establishes bindings
>>>to that result, repeating for each successive form"
>>>   [bindings & forms]
>>>   (assert (vector? bindings) "binding must be a vector")
>>>   (assert (= 2 (count bindings)) "binding vector must contain exactly two
>>> forms")
>>>   `(let [~@bindings
>>>  ~@(interleave (repeat (bindings 0)) (drop-last forms))]
>>>  ~(last forms)))
>>>
>>> (new-let-> [{:keys [foo bar] :as state} {:foo 1 :bar 2}]
>>>   (assoc state :foo (inc bar))
>>>   (assoc state :bar (inc foo))) ; => {:foo 3, :bar 4}
>>>
>>> --
>>> Alex Nixon
>>>
>>> Software Engineer | SwiftKey
>>>
>>> al...@swiftkey.net | http://www.swiftkey.net/

-- 
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: confused about the scope of variables, or is it something else? ClojureScript

2012-12-02 Thread Sean Corfield
Part of it is laziness: map is lazy so it doesn't do anything unless you
use the result. In the REPL, you print the result so map runs across the
whole sequence. In the function, only the last expression (draggables) is
returned so it is the only thing fully evaluated.

Your code is very procedural tho'... you should not have 'def' anywhere
except the top-level (since it always creates top-level definitions -
globals). You probably want 'let' for local definitions. Since you want
non-lazy behavior, you're not going to want 'for' or 'map' - look at
'doseq' instead.

Hope that helps?


On Sun, Dec 2, 2012 at 5:25 PM, Arash Bizhan zadeh wrote:

> I am playing with clojurescript, and I have this code:
>
> (defn prepare [number]
>   (def targets (take 4 (drop (* 4 (- number 1)) (dom/getElementsByClass
> "place-div"
>   (def target-objects (map #(make-target %) targets))
>   (for [drag draggables target target-objects]
> (.addTarget drag target))
>   (map #(.init %)  draggables)
>   (map #(.init %) target-objects)
>   draggables)
>
> It basically creates  a bunch of dragNdrop objects.
> This code doesn't work in this method - no error, just doesn't do the job
> -
> but if I execute the lines one at a time from repl, it works fine.
> Can someone please explain what the heck is going on ?
>
> much appreciated.
>
> --
> 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




-- 
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
World Singles, LLC. -- http://worldsingles.com/

"Perfection is the enemy of the good."
-- Gustave Flaubert, French realist novelist (1821-1880)

-- 
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: Proposed change to let-> syntax

2012-12-02 Thread Terje Norderhaug
On Thu, Nov 15, 2012 at 5:17 PM, Alan Malloy  wrote:
> The primary point of let-> is that you can insert it into an existing ->
> pipeline.
>
> (-> foo
> (stuff)
> (blah)
> (let-> foo-with-stuff
>   (for [x foo-with-stuff]
> (inc x)))

This use case of the macro now renamed as-> in Clojure 1.5 is already
covered by using fn in a pipeline:

(-> foo
(stuff)
(blah)
((fn [foo-with-stuff]
   (for [x foo-with-stuff]
 (inc x)

A benefit of using fn here is that it also works with ->> just the
same. However, there is a place for a construct to simplify multiple
uses of fn in a pipeline like in:

 (-> foo
(stuff)
(blah)
((fn [foo]
   (for [x foo]
 (inc x
((fn [foo]
   (for [x foo]
 (dec x)

I propose fn-> as name for a construct similar to as-> used like this:

(-> foo
(stuff)
(blah)
((fn-> [foo]
   (for [x foo]
 (inc x))
   (for [x foo]
 (dec x)

The fn-> macro defines an anonymous function using the same syntax as
fn, with its forms threaded like in as-> where each evaluated form is
bound to a symbol.

In the example above, the result of the first 'for' form is bound to
the 'foo' used by the second 'for' form. That is, within fn-> the
items in the list bound to foo is first incremented and the resulting
list bound to foo, then the items in the list bound to foo is
decremented with the resulting list returned (incidentally leaving the
list as before).

Keeping the syntax and semantics of fn-> similar to fn provides an
smooth upgrade path from current uses of fn in pipelines.

-- Terje Norderhaug

> On Thursday, November 15, 2012 10:35:59 AM UTC-8, Alex Nixon wrote:
>>
>> Hi all,
>>
>> I find the proposed function let-> in Clojure 1.5 very useful, but a bit
>> ugly.  The arguments are backwards when compared to vanilla let, and it
>> doesn't support destructuring where it easily could (which I believe would
>> be helpful when threading 'state-like' maps, as I find let-> very useful
>> for).
>>
>> I'd like to float an alternative implementation which improves on both
>> these issues.  Thoughts?
>>
>> (defmacro new-let->
>>   "Establishes bindings as provided for let, evaluates the first form
>>in the lexical context of that binding, then re-establishes bindings
>>to that result, repeating for each successive form"
>>   [bindings & forms]
>>   (assert (vector? bindings) "binding must be a vector")
>>   (assert (= 2 (count bindings)) "binding vector must contain exactly two
>> forms")
>>   `(let [~@bindings
>>  ~@(interleave (repeat (bindings 0)) (drop-last forms))]
>>  ~(last forms)))
>>
>> (new-let-> [{:keys [foo bar] :as state} {:foo 1 :bar 2}]
>>   (assoc state :foo (inc bar))
>>   (assoc state :bar (inc foo))) ; => {:foo 3, :bar 4}
>>
>> --
>> Alex Nixon
>>
>> Software Engineer | SwiftKey
>>
>> al...@swiftkey.net | http://www.swiftkey.net/

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


confused about the scope of variables, or is it something else? ClojureScript

2012-12-02 Thread Arash Bizhan zadeh
I am playing with clojurescript, and I have this code:

(defn prepare [number]
  (def targets (take 4 (drop (* 4 (- number 1)) (dom/getElementsByClass
"place-div"
  (def target-objects (map #(make-target %) targets))
  (for [drag draggables target target-objects]
(.addTarget drag target))
  (map #(.init %)  draggables)
  (map #(.init %) target-objects)
  draggables)

It basically creates  a bunch of dragNdrop objects.
This code doesn't work in this method - no error, just doesn't do the job -
but if I execute the lines one at a time from repl, it works fine.
Can someone please explain what the heck is going on ?

much appreciated.

-- 
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: Can anyone point me to that library that supports quasiquoting without full namespace expansion?

2012-12-02 Thread Brandon Bloom
I just published a new 0.2.0-SNAPSHOT that includes a fix parallel to Rich 
Hickey's change to handling of records in Clojure 1.5.

On Sunday, December 2, 2012 10:27:46 AM UTC-8, Conrad wrote:
>
> Never mind, I just found it on clojars. It is: 
> https://github.com/brandonbloom/backtick
>
> On Sunday, December 2, 2012 12:24:29 PM UTC-6, Conrad wrote:
>>
>> I remember seeing it somewhere recently but I can't find it now...
>>
>> As you probably know, if you quasiquote in clojure it automatically adds 
>> namespaces:
>>
>> > `[foo ~1]
>> [mylibrary.core/foo 1]
>>
>> The library I am looking for lets you write:
>>
>> > (template [foo ~1])
>> [foo 1]
>>
>> Thanks for your help!
>>
>

-- 
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: Change the CCW compile output catalog

2012-12-02 Thread Dave Ray
Hey Laurent,

For what it's worth, I was a little surprised that CCW used it's own
output folder rather than Eclipse's, but I understand why you'd do it
that way.

One thing that was a little problematic was that CCW automatically
created the folder and added it to the Eclipse classpath when all I
had done was open a .clj file for editing. I would have expected a
more explicit "enable Clojure support on this project" action to be
required before it starts making changes to the project. Not a big
deal, but I though I'd share.

Cheers,

Dave

On Sat, Dec 1, 2012 at 1:04 PM, Laurent PETIT  wrote:
> Hello,
>
> 2012/12/1 Vladimir Tsichevski :
>> Hi,
>>
>> CCW always outputs compiled classes into the "classes" catalog. AFAIK, this
>> name is compiled into CCW and hence cannot be changed. My two questions are:
>>
>> 1. Why the catalog path is not configurable? Was this made intentionally?
>
> It is a limitation, for sure, which comes from the past. Will
> eventually go. There's not reason for it to not be configurable, but
> no having dedicated time to do so.
>
>> 2. Why this catalog differs from the Java output catalog? Was it made
>> intentionally, or it is Ok to put all project output classes to same
>> catalog?
>
> Yes, it is intentional that CCW's output is not in the same folder
> hierarchy as other Java output.
> Indeed, it's not possible (or sufficiently complex to have been
> considered so) to inform Eclipse (which manages java source/classes
> via the JDT - Java Development Tools-) that there are contents in the
> same output as where it compiles classes, and that it would be polite
> not to erase the folder content as if it were under its full control.
>
> Now, beyond your interesting in understand why things are how they
> are, I'd be interesting in knowing if that's currently getting in your
> way, and if so, try to see  if I can help you find a workaround until
> this is eventually customizable.
>
>
> HTH,
>
> --
> Laurent
>
> --
> 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: small error on clojure.org/reader

2012-12-02 Thread Andy Fingerhut
The full sentence is this:

Syntax-quote (`, note, the "backquote" character), Unquote (~) and 
Unquote-splicing (~@)

It looks like perhaps someone started writing this:

Syntax-quote (`), Unquote (~) and Unquote-splicing (~@)

and then added some more explanatory text inside the parentheses to emphasize 
which quote character it is.  I'm not saying it is as good as it can be now, 
but I'm not sure this would be much better, as someone is bound to point out 
that the ` character is not in parentheses like all the others are on that page:

Syntax-quote ` (note, the "backquote" character), Unquote (~) and 
Unquote-splicing (~@)

Andy


On Dec 2, 2012, at 12:49 PM, Otto Allmendinger wrote:

> (I couldn't figure out where to put this so I might as well just post it here)
> 
> 
> The page says 
> 
> > Syntax-quote (`
> 
> where it should say
> 
> > Syntax-quote `(
> 
> 
> Otto

-- 
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] modern-cljs - tutorial 9 on testing (part 1)

2012-12-02 Thread Mimmo Cosenza
ops. thanks
mimmo

On Dec 2, 2012, at 10:15 PM, Michael Klishin  
wrote:

> 2012/12/3 Mimmo Cosenza 
> I just published the 9th tutorial of the series modern-cljs.
> 
> It talks about testing. It uses the CLJS proposed patch as  a true sample 
> case to work on.
> HIH
> 
> The link: 
> https://github.com/magomimmo/modern-cljs/blob/master/doc/tutorial-09.md
> 
> Thank you!
> -- 
> MK
> 
> http://github.com/michaelklishin
> http://twitter.com/michaelklishin
> 
> 
> -- 
> 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] vectorz-clj - high performance vector maths for Clojure

2012-12-02 Thread Mikera
Sure - added instructions and uploaded version 0.0.1 to Clojars.

Hopefully that works smoothly, any issues let me know.

On Sunday, 2 December 2012 13:56:07 UTC, Michael Klishin wrote:
>
> 2012/12/2 Mikera >
>
>> The Clojure library is here: https://github.com/mikera/vectorz-clj
>>
>
> Please add installation/dependency instructions to the README.
> -- 
> MK
>
> http://github.com/michaelklishin
> http://twitter.com/michaelklishin
>
>  

-- 
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] modern-cljs - tutorial 9 on testing (part 1)

2012-12-02 Thread Michael Klishin
2012/12/3 Mimmo Cosenza 

> I just published the 9th tutorial of the series modern-cljs.
>
> It talks about testing. It uses the CLJS proposed patch as  a true sample
> case to work on.
> HIH
>

The link:
https://github.com/magomimmo/modern-cljs/blob/master/doc/tutorial-09.md

Thank you!
-- 
MK

http://github.com/michaelklishin
http://twitter.com/michaelklishin

-- 
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: (def some? (comp not nil? some))

2012-12-02 Thread Ben Wolfson
On Sun, Dec 2, 2012 at 12:48 PM, Jim - FooBar();  wrote:
> Its perfectly fine to use some as a predicate as far as I know...works
> excellent with if-let/when-let - what is the problem?

There might be cases in which it matters whether something returns nil
(as 'some' does) or false (as 'some?' would). ('keep', for instance,
unlike 'filter', discriminates between nil and false.)

-- 
Ben Wolfson
"Human kind has used its intelligence to vary the flavour of drinks,
which may be sweet, aromatic, fermented or spirit-based. ... Family
and social life also offer numerous other occasions to consume drinks
for pleasure." [Larousse, "Drink" entry]

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


small error on clojure.org/reader

2012-12-02 Thread Otto Allmendinger
(I couldn't figure out where to put this so I might as well just post it 
here)


The page says 

> Syntax-quote (`

where it should say

> Syntax-quote `(


Otto

-- 
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: (def some? (comp not nil? some))

2012-12-02 Thread Jim - FooBar();
Its perfectly fine to use some as a predicate as far as I know...works 
excellent with if-let/when-let - what is the problem?


Jim


On 02/12/12 19:47, Tom Hall wrote:

Hi Guys,

We seem to have not-any? but not an any? function,
I know we have some but it is not a predicate and I found myself
defining some? above today.
Why not have some? or any? in the core?

Cheers,
Tom



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


[ANN] modern-cljs - tutorial 9 on testing (part 1)

2012-12-02 Thread Mimmo Cosenza
Hi,
I just published the 9th tutorial of the series modern-cljs. 

It talks about testing. It uses the CLJS proposed patch as  a true sample case 
to work on. 
HIH

My best

Mimmo
 

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


(def some? (comp not nil? some))

2012-12-02 Thread Tom Hall
Hi Guys,

We seem to have not-any? but not an any? function,
I know we have some but it is not a predicate and I found myself
defining some? above today.
Why not have some? or any? in the core?

Cheers,
Tom

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


working with multiple handlers

2012-12-02 Thread Frank Lee
Hi,

I'm trying to write an xmpp, which after receiving a message, pushes the 
messages with a websocket using async-push. I can't figure out how to do 
this because both xmpp and async-push use event handlers -- how do I chain 
them together. This code doesn't work, but I guess you get the idea of what 
I'm going for. Thanks in advance for any help!

(ns ws-rand.core
  (:use aleph.http
noir.core
lamina.core)
  (:require
   [noir-async.core :as na]
   [noir-async.utils :as na-util]
   [noir.server :as nr-server]
   [xmpp-clj :as xmpp]))

(defn handle-message [message]
  (let [body (:body message)
from-user (:from-name message)]

; WRONG I don't know how to embed async-push inside of the handler.

(na/defpage-async "/rand" {} conn
  #(na/async-push conn body)

  )))

(defn -main [& m]
  (let [mode (keyword (or (first m) :dev))
port (Integer. (get (System/getenv) "PORT" "3000"))
noir-handler (nr-server/gen-handler {:mode mode})]

(xmpp/start-bot :username "pre...@jabber.org"
:password "password"
:host "jabber.org"
:domain "jabber.org"
:handler (var handle-message))


(start-http-server
  (wrap-ring-handler noir-handler)
  {:port port :websocket true})))

-- 
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: math expression simplifier, kibit implementation

2012-12-02 Thread Jonas


On Sunday, December 2, 2012 7:33:17 PM UTC+2, David Nolen wrote:
>
> On Sat, Dec 1, 2012 at 12:24 AM, Jonas  >wrote:
>
>>
>> * Predicates on logic vars: 
>> [(foo (? x number?)) (bar ?x)] => match (foo 42) but not (foo :bar)
>>
>
> This is now possible since we have constraints.
>

Awesome. Is this already in a released version of core.logic? Do you know 
of any examples I might study?
 

>  
>
>> * Segment vars:
>> [(* ??x 1 ??y) (* ??x ??y)] => (* 4 3 2 1 2 3 4) would turn into (* 4 
>> 3 2 2 3 4)
>> and
>> [(* ??x 0 ??y) 0] => (* 1 2 3 0 4 5 6 7) would turn into 0
>>
>
> This has been possible for some time - but you need to extend unification. 
> You need to create a wrapper around sequences and a new kind of logic var. 
> Kevin's work on the partial map (PMap) functionality is a good starting 
> point as well the work I've done on constrained vars (CVar).
>

I'd be interested in creating an SVar ("segment var") then. I'll start by 
trying to understand yours and Kevins work on CVar/PMap.
   

>
> As far as doing a computer algebra system, I know things like this have 
> been done before in Prolog so I don't see why not.
>

Sorry, I didn't mean to imply that it couldn't be done in core.logic, only 
that the kibit rule system isn't as expressive as I'd like it to be.

Jonas

 

>
> 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: Can anyone point me to that library that supports quasiquoting without full namespace expansion?

2012-12-02 Thread Conrad
Never mind, I just found it on clojars. It is: 
https://github.com/brandonbloom/backtick

On Sunday, December 2, 2012 12:24:29 PM UTC-6, Conrad wrote:
>
> I remember seeing it somewhere recently but I can't find it now...
>
> As you probably know, if you quasiquote in clojure it automatically adds 
> namespaces:
>
> > `[foo ~1]
> [mylibrary.core/foo 1]
>
> The library I am looking for lets you write:
>
> > (template [foo ~1])
> [foo 1]
>
> Thanks for your help!
>

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

Can anyone point me to that library that supports quasiquoting without full namespace expansion?

2012-12-02 Thread Conrad
I remember seeing it somewhere recently but I can't find it now...

As you probably know, if you quasiquote in clojure it automatically adds 
namespaces:

> `[foo ~1]
[mylibrary.core/foo 1]

The library I am looking for lets you write:

> (template [foo ~1])
[foo 1]

Thanks for your help!

-- 
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: math expression simplifier, kibit implementation

2012-12-02 Thread David Nolen
On Sat, Dec 1, 2012 at 12:24 AM, Jonas  wrote:

>
> * Predicates on logic vars:
> [(foo (? x number?)) (bar ?x)] => match (foo 42) but not (foo :bar)
>

This is now possible since we have constraints.


> * Segment vars:
> [(* ??x 1 ??y) (* ??x ??y)] => (* 4 3 2 1 2 3 4) would turn into (* 4
> 3 2 2 3 4)
> and
> [(* ??x 0 ??y) 0] => (* 1 2 3 0 4 5 6 7) would turn into 0
>

This has been possible for some time - but you need to extend unification.
You need to create a wrapper around sequences and a new kind of logic var.
Kevin's work on the partial map (PMap) functionality is a good starting
point as well the work I've done on constrained vars (CVar).

As far as doing a computer algebra system, I know things like this have
been done before in Prolog so I don't see why not.

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

STM - a request for "war stories"

2012-12-02 Thread Paul Butcher
All,

I have a request which I hope the members of this group are uniquely positioned 
to help with. I have recently started working on a new book for The Pragmatic 
Programmers with the working title "Seven Concurrency Models in Seven Weeks" 
(it follows on from their existing "Seven Languages" and "Seven Databases" 
titles).

One of the approaches that I'll be covering is STM, and I'll be presenting it 
in Clojure.

What I'd like to solicit are "war stories" about problems you've solved using 
STM, which demonstrate the strengths of the technique over and above (say) 
threads and locks.

I'm looking for real-world examples instead of presenting yet another hackneyed 
atomically-make-a-bank-account-withdrawal :-)

Very many thanks in advance for your help!

--
paul.butcher->msgCount++

Snetterton, Castle Combe, Cadwell Park...
Who says I have a one track mind?

http://www.paulbutcher.com/
LinkedIn: http://www.linkedin.com/in/paulbutcher
MSN: p...@paulbutcher.com
AIM: paulrabutcher
Skype: paulrabutcher

-- 
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: (iterate inc 2) vs (drop 2 (range)) in corecursion

2012-12-02 Thread maclo
Hi

 user=> (def primes

>   (cons 2
> (filter
>   (fn isprime[n]
>
> (every?
>   #(pos? (mod n %))
>   (take-while #(<=(* % %)n) primes)))
>   (iterate inc 3
> user=> (take 50 primes)
> (2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 
> 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 
> 197 199 211 223 227 229)
>
 
 Is it really necessary to call 'take-while' ? The version without it

(def primes
  (cons 2
(filter
  (fn isprime? [n]
(every? #(pos? (mod n %)) primes))
  (iterate inc 3

works for me as well. Is it safe to use this version or is using 
'take-while' for some reason necessary ?

maclo

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

exception in 'map' mutates result to nil -- bug?

2012-12-02 Thread Hank
I'm mapping a function that throws an exception over a collection:

=> (def mapped (map (fn [_] (throw (Exception.))) [1 2 3]))
#'user/mapped

'map' is lazy so we're not expecting to see the exception until we're 
trying to access the result:
=> mapped
Exception   user/fn--709 (NO_SOURCE_FILE:1)

All good, let's do that again:
=> mapped
()

Whoops! Is this by design? Why? Where does that empty sequence come from?

'map' is really just calling the lazy-seq macro but doing this with lazy 
seq works just fine:
=> (def lazy (lazy-seq (throw (Exception.
#'user/lazy
=> lazy
Exception   user/fn--733 (NO_SOURCE_FILE:1)
=> lazy
Exception   user/fn--733 (NO_SOURCE_FILE:1)

Same exception over and over again as it should be. I stared at the 
implementations of 'map' and lazy-seq/LazySeq for some hours but I really 
can't see it.

Cheers
-- hank

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

[ANN] vectorz-clj - high performance vector maths for Clojure

2012-12-02 Thread Mikera
Hi All,

I just open sourced a new Clojure library vectorz-clj with support for high 
performance vector maths in Clojure. It's fairly general purpose, and 
designed for use in 3D games, simulations and machine learning 
applications. I'm using it for my own machine learning apps and it is 
working very well (e.g. my talk at the Clojure Conj 2012 features some 
example usage)

Design goals:
 - Pure Java (i.e. avoid the need for dependencies on native code libraries 
like BLAS)
 - High performance, roughly defined as "as fast as you can reasonably get 
on the JVM"
 - Support multiple types of concrete vectors, e.g. primitive x,y,z 3D 
vectors as well as large general purpose (1000+ dimension vectors)
 - A nice Clojure API for vector operations (work in progress!)

The need for high performance means that underlying vectors need to be 
mutable (apologies to the purists!), however to make the API nice I've 
provided pure functional versions of operations as well as the in place 
operations that mutate their arguments. Hopefully this is a nice compromise 
between having access to high performance operations when you need them and 
allowing idiomatic Clojure usage when you don't e.g.

In-place "add!" mutates vector a:
  (add! a b)

Pure "add" creates a new vector:
  (let [result (add a b)] )

The Clojure library is here: https://github.com/mikera/vectorz-clj
The underlying vector data structures are in a separate Java 
library: https://github.com/mikera/vectorz

Contributions / comments / suggestions very welcome. API is not yet set in 
stone, so I'm very open to ideas on how to make it better.

  Mike.

-- 
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: Change the CCW compile output catalog

2012-12-02 Thread Vladimir Tsichevski
You aswers had everything I needed to know to move forward. Did not notice 
anything strange in them. It were late hours here in Moscow thought :-)

On Sunday, December 2, 2012 2:32:45 AM UTC+4, lpetit wrote:
>
> 2012/12/1 Laurent PETIT >: 
> > Hello, 
> > 
> > 2012/12/1 Vladimir Tsichevski >: 
> >> Hi, 
> >> 
> >> CCW always outputs compiled classes into the "classes" catalog. AFAIK, 
> this 
> >> name is compiled into CCW and hence cannot be changed. My two questions 
> are: 
> >> 
> >> 1. Why the catalog path is not configurable? Was this made 
> intentionally? 
> > 
> > It is a limitation, for sure, which comes from the past. Will 
> > eventually go. There's not reason for it to not be configurable, but 
> > no having dedicated time to do so. 
> > 
> >> 2. Why this catalog differs from the Java output catalog? Was it made 
> >> intentionally, or it is Ok to put all project output classes to same 
> >> catalog? 
> > 
> > Yes, it is intentional that CCW's output is not in the same folder 
> > hierarchy as other Java output. 
> > Indeed, it's not possible (or sufficiently complex to have been 
> > considered so) to inform Eclipse (which manages java source/classes 
> > via the JDT - Java Development Tools-) that there are contents in the 
> > same output as where it compiles classes, and that it would be polite 
> > not to erase the folder content as if it were under its full control. 
> > 
> > Now, beyond your interesting in understand why things are how they 
> > are, I'd be interesting in knowing if that's currently getting in your 
> > way, and if so, try to see  if I can help you find a workaround until 
> > this is eventually customizable. 
>
> Wow, re-reading myself right now. Either I was drunk, or the 
> spellchecker cheated on me a lot :-) 
>
> > 
> > 
> > HTH, 
> > 
> > -- 
> > Laurent 
>

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