Re: math expression simplifier, kibit implementation

2012-11-30 Thread Jonas
Hi 

The function `simplify-one` in kibit.core is the “brain” behind kibit:

(defn simplify-one [expr rules]
  (let [alts (logic/run* [q]
(logic/fresh [pat subst]
  (logic/membero [pat subst] rules)
  (logic/project [pat subst]
(logic/all (pat expr)
 (subst q)]
(if (empty? alts) expr (first alts

The line `(logic/membero [pat subst] rules)` picks a rule (both the pattern 
and the substitution part). Both `pat` and `subst` are functions who have 
closed over the same logic vars. pat takes a form and subst takes the logic 
var representing the result as arguments. Since both pat and subst contain 
the same logic vars the final expression `(logic/all (pat expr) (subst q))` 
will only succeed if (pat expr) succeeds. If (pat expr) succeeds it has 
presumably bound its logic vars and since the same vars are closed over in 
subst, the final answer is unified with q, giving us a result. 

Rules are compiled with

(defn compile-rule [rule]
  (let [[pat alt] (logic/prep rule)]
[(fn [expr] (logic/== expr pat))
 (fn [sbst] (logic/== sbst alt))]))

(logic/prep rule) walks the rule (where a rule is e.g., [(+ ?x 1) (inc 
?x)]) and replaces symbols starting with `?` with logic vars. The 
compile-rule function is defined in the kibit.rules.util namespace.

This is basically how the kibit rule system works. I don’t think it’s 
powerful enough to create a full-blown computer algebra system and often 
It’s not powerful enough for the kind of rules I’d like to express in 
kibit. Two enhancements I’d like to add are

* Predicates on logic vars: 
[(foo (? x number?)) (bar ?x)] => match (foo 42) but not (foo :bar)
* 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

David Nolen and Kevin Lynagh has discussed enhancements to the core.logic 
unifier on IRC lately. I haven’t been able to follow along as much as I’d 
like so I’m not completely sure what enhancements they are aiming for. You 
can see some of the results of those discussions in many of Kevins gists on 
github (https://gist.github.com/lynaghk)

Cheers,
Jonas 

On Saturday, December 1, 2012 12:08:16 AM UTC+2, Brent Millare wrote:
>
> Hey all,
>
> Before I diving in detail into the code, can someone provide me a high 
> level explanation of how kibit simplifies code? I understand underneath it 
> uses core.logic and rules but its not clear to me how it picks one form 
> over the other.
>
> I'm trying to extend this to data that represents mathematical 
> expressions. Ideally in the future I'd like to have many types of 
> transformations that enable one to shape a mathematical expression in one 
> way or another depending on the  user's requirements.
>
> My current work (which requires dj atm since its under heavy development) 
> is available here
>
> https://github.com/bmillare/dj.math
>
>

-- 
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: Clojure CLR and System.Double Behavior

2012-11-30 Thread dmiller
Patched in master branch.

Clojure 1.5.0-master-SNAPSHOT
user=>
user=> (defn bar [^Double d] d)
#'user/bar
user=> (defn baz [^System.Double d] d)
#'user/baz
user=> (bar 1.2)
1.2
user=> (baz 1.2)
1.2
user=> (defprotocol FP (foo [_]))
FP
user=> (extend-protocol FP System.Double (foo [d] d))
nil
user=> (foo 1.2)
1.2


You can now type hint with double, Double and System.Double.

One should keep in mind that this is the CLR, not C# (or the JVM).  Thus, 
int, Int32, System.Int32 and float, Single, System.Single.

Note  that a type hint such as ^System.Int32 x  is actually using the 
symbol System.Int32 as the value for :tag -- that is how the LispReader 
works. However, if you were to put :tag metadata on programmatically and 
actually use the type System.Int32 -- well, that should work also. 


-David


> On Thursday, November 29, 2012 11:02:19 AM UTC-6, ffailla wrote:
>>
>> I have discovered some odd behavior when type-hinting fns with 
>> ^System.Double:
>>
>> user=> (defn bar [^System.Double d] d)
>> #'user/bar
>> user=> (bar 1.2)
>> 2.35293190771409E-316
>> user=> (bar 1)
>> 2.35069794048985E-316
>>
>> The same behavior occurs when extending double via extend-protocol or 
>> extend-type:
>>
>> user=> (defprotocol FooProto (foo [_]))
>> user=> (extend-protocol FooProto System.Double (foo [d] d))
>> nil
>> user=> (foo 1.2)
>> 2.25126584588049E-316
>>
>> Any ideas?  Thanks.
>>
>> -Frank Failla
>>
>>

-- 
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: CLJS: extending types like keyword, symbol and string?

2012-11-30 Thread Frank Siebenlist
Sorry - just noticed the "Re: cljs: extend-protocol to Keyword" discussion of a 
few days ago.

Maybe we should start maintaining an FAQ-like wiki-page with summaries of those 
issues/features…

-FS.


On Nov 30, 2012, at 5:17 PM, Frank Siebenlist  
wrote:

> When I ask for the type of a keyword, symbol or string, cljs gives me the 
> same answer:
> 
> ---
> ClojureScript:cljs.user> (type "jaja")
> #
> ClojureScript:cljs.user> (type 'jaja)
> #
> ClojureScript:cljs.user> (type :jaja)
> #
> ClojureScript:cljs.user> (= (type :jaja)(type 'jaja)(type "jaja"))
> true
> ---
> 
> but the predicates for those types seem to work:
> 
> ---
> ClojureScript:cljs.user> (and (string? "jaja")(symbol? 'jaja)(keyword? :jaja))
> true
> ClojureScript:cljs.user> (or (string? 'jaja)(symbol? :jaja)(keyword? "jaja"))
> false
> ---
> 
> I understand that all those types map to javascript's native string.
> 
> The Q is, can you entend those types with protocols?
> 
> ...and if so how?
> 
> Thanks, FrankS.
> 
> 

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


CLJS: extending types like keyword, symbol and string?

2012-11-30 Thread Frank Siebenlist
When I ask for the type of a keyword, symbol or string, cljs gives me the same 
answer:

---
ClojureScript:cljs.user> (type "jaja")
#
ClojureScript:cljs.user> (type 'jaja)
#
ClojureScript:cljs.user> (type :jaja)
#
ClojureScript:cljs.user> (= (type :jaja)(type 'jaja)(type "jaja"))
true
---

but the predicates for those types seem to work:

---
ClojureScript:cljs.user> (and (string? "jaja")(symbol? 'jaja)(keyword? :jaja))
true
ClojureScript:cljs.user> (or (string? 'jaja)(symbol? :jaja)(keyword? "jaja"))
false
---

I understand that all those types map to javascript's native string.

The Q is, can you entend those types with protocols?

...and if so how?

Thanks, FrankS.


-- 
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-11-30 Thread David Nolen
Can we move forward on this? Option 1 seems best to me. 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?


On Fri, Nov 16, 2012 at 7:50 PM, Stuart Sierra
wrote:

> Tracking this at http://dev.clojure.org/jira/browse/CLJS-418
>
> -S
>
>
>  --
> 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: First test with JavaFx and blocked yet :(

2012-11-30 Thread Kevin Downey
here is an example https://gist.github.com/4179694


On Fri, Nov 30, 2012 at 4:13 PM, Kevin Downey  wrote:

> javafx.application.Application/launch is looking at the class that the
> method that calls it belongs to, in this case it belongs to the IFn class
> generated for the -main function, there is an arity for launch that takes
> the class you want to use instead of the weird detection thing
>
>
>
>
>
> On Fri, Nov 30, 2012 at 3:38 PM, Christian Sperandio <
> christian.speran...@gmail.com> wrote:
>
>> Hi,
>>
>> I'm testing JavaFX with Clojure 1.4 and I've got some issues.
>> I wrote this code:
>> (ns test-javafx2-clj.core
>>   (:import javafx.application.Application
>>javafx.stage.Stage
>>(javafx.scene Parent Scene))
>>
>>   (:gen-class
>>:extends javafx.application.Application))
>>
>> (defn -main
>>   "I don't do a whole lot ... yet."
>>   [& args]
>>   (println "Before the launch call")
>>   (javafx.application.Application/launch args))
>>
>> (defn -start
>>   [this stage]
>>   (println "Arf!"))
>>   ;(.setTitle stage "Hello World!"))
>>
>> My project.clj is the following:
>> (ns test-javafx2-clj.core
>>   (:import javafx.application.Application
>>javafx.stage.Stage
>>(javafx.scene Parent Scene))
>>
>>   (:gen-class
>>:extends javafx.application.Application))
>>
>> (defn -main
>>   "I don't do a whole lot ... yet."
>>   [& args]
>>   (println "Before the launch call")
>>   (javafx.application.Application/launch args))
>>
>> (defn -start
>>   [this stage]
>>   (println "Arf!"))
>>   ;(.setTitle stage "Hello World!"))
>>
>>
>> I build my jar with the command lein uberjar, and when I launch the
>> generated jar I get this error:
>> Exception in thread "main" java.lang.RuntimeException: Error: class
>> test_javafx2_clj.core$_main is not a subclass of
>> javafx.application.Application
>>  at javafx.application.Application.launch(Application.java:211)
>> at test_javafx2_clj.core$_main.doInvoke(core.clj:14)
>>  at clojure.lang.RestFn.invoke(RestFn.java:397)
>> at clojure.lang.AFn.applyToHelper(AFn.java:159)
>> at clojure.lang.RestFn.applyTo(RestFn.java:132)
>>  at test_javafx2_clj.core.main(Unknown Source)
>>
>> It's very strange because I well wrote the
>> :extends  javafx.application.Application. So, I don't understand why I've
>> got this error.
>>
>> Thanks for your help.
>>
>> Chris
>>
>> --
>> 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
>
>
>
>
> --
> And what is good, Phaedrus,
> And what is not good—
> Need we ask anyone to tell us these things?
>



-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

-- 
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: First test with JavaFx and blocked yet :(

2012-11-30 Thread Kevin Downey
 javafx.application.Application/launch is looking at the class that the
method that calls it belongs to, in this case it belongs to the IFn class
generated for the -main function, there is an arity for launch that takes
the class you want to use instead of the weird detection thing





On Fri, Nov 30, 2012 at 3:38 PM, Christian Sperandio <
christian.speran...@gmail.com> wrote:

> Hi,
>
> I'm testing JavaFX with Clojure 1.4 and I've got some issues.
> I wrote this code:
> (ns test-javafx2-clj.core
>   (:import javafx.application.Application
>javafx.stage.Stage
>(javafx.scene Parent Scene))
>
>   (:gen-class
>:extends javafx.application.Application))
>
> (defn -main
>   "I don't do a whole lot ... yet."
>   [& args]
>   (println "Before the launch call")
>   (javafx.application.Application/launch args))
>
> (defn -start
>   [this stage]
>   (println "Arf!"))
>   ;(.setTitle stage "Hello World!"))
>
> My project.clj is the following:
> (ns test-javafx2-clj.core
>   (:import javafx.application.Application
>javafx.stage.Stage
>(javafx.scene Parent Scene))
>
>   (:gen-class
>:extends javafx.application.Application))
>
> (defn -main
>   "I don't do a whole lot ... yet."
>   [& args]
>   (println "Before the launch call")
>   (javafx.application.Application/launch args))
>
> (defn -start
>   [this stage]
>   (println "Arf!"))
>   ;(.setTitle stage "Hello World!"))
>
>
> I build my jar with the command lein uberjar, and when I launch the
> generated jar I get this error:
> Exception in thread "main" java.lang.RuntimeException: Error: class
> test_javafx2_clj.core$_main is not a subclass of
> javafx.application.Application
> at javafx.application.Application.launch(Application.java:211)
> at test_javafx2_clj.core$_main.doInvoke(core.clj:14)
> at clojure.lang.RestFn.invoke(RestFn.java:397)
> at clojure.lang.AFn.applyToHelper(AFn.java:159)
> at clojure.lang.RestFn.applyTo(RestFn.java:132)
> at test_javafx2_clj.core.main(Unknown Source)
>
> It's very strange because I well wrote the
> :extends  javafx.application.Application. So, I don't understand why I've
> got this error.
>
> Thanks for your help.
>
> Chris
>
> --
> 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




-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

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

Clamq - simple clojure test to send/receive message over activemq

2012-11-30 Thread shuaybi
Can someone please look at the below code to see why it is not working. I 
am trying to write simple clojure code to send/receive message over 
activemq.

I am starting two REPL sessions and loading the same code below in each 
session. In one session I invoke the start-consumer function and in the 
other session the send-msg function. The REPL running the consumer code 
does not get the message.

(ns perf.prg
  (:require
[clamq.activemq :as amq]
[clamq.protocol.connection :as connection]
[clamq.protocol.consumer :as consumer]
[clamq.protocol.producer :as producer]))

(def broker-uri "tcp://MDCDSK01BHINDSA:61616")

(def connection (amq/activemq-connection broker-uri))

(def queue-name "producer-consumer-test-queue")

(defn recv-msg [message]
  (pprint (str "message received: " message)))

(defn start-consumer [connection]
  (let [consumer (connection/consumer connection {:endpoint queue-name 
:on-message recv-msg :transacted false})]
(consumer/start consumer)
(Thread/sleep 6)
(consumer/close consumer)))

(defn send-msg [connection msg]
  (let [producer (connection/producer connection)]
(producer/publish producer queue-name msg)))

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

First test with JavaFx and blocked yet :(

2012-11-30 Thread Christian Sperandio
Hi,

I'm testing JavaFX with Clojure 1.4 and I've got some issues.
I wrote this code:
(ns test-javafx2-clj.core
  (:import javafx.application.Application
   javafx.stage.Stage
   (javafx.scene Parent Scene))
  
  (:gen-class
   :extends javafx.application.Application))

(defn -main
  "I don't do a whole lot ... yet."
  [& args]
  (println "Before the launch call")
  (javafx.application.Application/launch args))

(defn -start
  [this stage]
  (println "Arf!"))
  ;(.setTitle stage "Hello World!"))

My project.clj is the following:
(ns test-javafx2-clj.core
  (:import javafx.application.Application
   javafx.stage.Stage
   (javafx.scene Parent Scene))
  
  (:gen-class
   :extends javafx.application.Application))

(defn -main
  "I don't do a whole lot ... yet."
  [& args]
  (println "Before the launch call")
  (javafx.application.Application/launch args))

(defn -start
  [this stage]
  (println "Arf!"))
  ;(.setTitle stage "Hello World!"))


I build my jar with the command lein uberjar, and when I launch the 
generated jar I get this error:
Exception in thread "main" java.lang.RuntimeException: Error: class 
test_javafx2_clj.core$_main is not a subclass of 
javafx.application.Application
at javafx.application.Application.launch(Application.java:211)
at test_javafx2_clj.core$_main.doInvoke(core.clj:14)
at clojure.lang.RestFn.invoke(RestFn.java:397)
at clojure.lang.AFn.applyToHelper(AFn.java:159)
at clojure.lang.RestFn.applyTo(RestFn.java:132)
at test_javafx2_clj.core.main(Unknown Source)

It's very strange because I well wrote the 
:extends  javafx.application.Application. So, I don't understand why I've 
got this error.

Thanks for your help.

Chris

-- 
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-11-30 Thread Alex Baranosky
gate-> is an interesting possiblity.

On Fri, Nov 30, 2012 at 1:53 PM, Sean Corfield wrote:

> On Fri, Nov 30, 2012 at 7:37 AM, Rich Hickey  wrote:
>
>> A) let-> becomes as->
>>
>
> Fine with that.
>
>
>> B) test-> becomes cond->
>>
>
> Fine with that (because I can't think of anything better).
>
>
>> C) when-> becomes some->
>>
>> and in doing so, tests for non-nil rather than truth.
>>
>
> Given that some-> threads while non-nil but the fn some stops with the
> first logical true value, this seems counter-intuitive to me. when-> seems
> better here, or while-> perhaps? What other names were considered?
> --
> 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
>

-- 
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 - Conjure 2.1.1 - Lightweight mocking library

2012-11-30 Thread John Gabriele
On Tuesday, November 27, 2012 3:22:29 AM UTC-5, Alex Baranosky wrote:
>
> Conjure is a lightweight mocking library intended to be used on top of 
> clojure.test.
>
> We've been using it at Runa for a long time, and it is compatible with all 
> versions of Clojure from 1.2 to 1.5-beta1.
>
> https://github.com/amitrathore/conjure
>
> Alex
>
>
Took a little for it to click, but I just remembered that there's also a 
web framework of the same name:  https://github.com/macourtney/Conjure .

---John

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

math expression simplifier, kibit implementation

2012-11-30 Thread Brent Millare
Hey all,

Before I diving in detail into the code, can someone provide me a high 
level explanation of how kibit simplifies code? I understand underneath it 
uses core.logic and rules but its not clear to me how it picks one form 
over the other.

I'm trying to extend this to data that represents mathematical expressions. 
Ideally in the future I'd like to have many types of transformations that 
enable one to shape a mathematical expression in one way or another 
depending on the  user's requirements.

My current work (which requires dj atm since its under heavy development) 
is available here

https://github.com/bmillare/dj.math

-- 
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-11-30 Thread Sean Corfield
On Fri, Nov 30, 2012 at 7:37 AM, Rich Hickey  wrote:

> A) let-> becomes as->
>

Fine with that.


> B) test-> becomes cond->
>

Fine with that (because I can't think of anything better).


> C) when-> becomes some->
>
> and in doing so, tests for non-nil rather than truth.
>

Given that some-> threads while non-nil but the fn some stops with the
first logical true value, this seems counter-intuitive to me. when-> seems
better here, or while-> perhaps? What other names were considered?
-- 
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-11-30 Thread Rich Hickey

On Nov 30, 2012, at 1:49 PM, Steve Miner wrote:

> I propose guard-> to avoid the cond-> confusion.
> 

Yeah, that came up. Guards in other langs are short circuiting, just like cond.

Another in that camp was gate->

-- 
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-11-30 Thread Rich Hickey

On Nov 30, 2012, at 1:15 PM, Alex Baranosky wrote:

> I've got a utility function I've been using called `conditionally-transform` 
> which is a non-macro version of `test->`.  I think both cond-> and if-> have 
> a similar problem in that, if you already understand if/cond/-> then it gives 
> you little insight into how the new threading macro works. 
> 
> Both these names focus on the conditional nature of the macro.  Perhaps a 
> name based on the transformative nature of the macro: trans-> or transform-> 
> ?  These convey the idea of threading through various transformations.
> 

All threading macros are transforms. cond-> has test forms like cond.

> For when->, how about non-nil-> ?  I'd feel better about some-> if it came, 
> as you said, with other new functions that use the syllable 'some', thus 
> expanding the Clojure lexicon.  As it stands I don't feel like some-> has a 
> particularly intuitive meaning.


Intuitive meaning is not always available, given everyone has different 
intuitions :)

-- 
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-11-30 Thread Ben Wolfson
On Fri, Nov 30, 2012 at 10:15 AM, Alex Baranosky
 wrote:
> I've got a utility function I've been using called `conditionally-transform`
> which is a non-macro version of `test->`.

Likewise, except with use a HOF:

(defn conditionalize [pred f]
  (fn [& args] (if (apply pred args) (apply f args) (apply identity args

Jay's example would then be (-> x ((conditionalize number? str))
(conditionalize string? count))).

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


Re: Proposed change to let-> syntax

2012-11-30 Thread Ben Wolfson
On Fri, Nov 30, 2012 at 10:15 AM, Alex Baranosky
 wrote:
> I've got a utility function I've been using called `conditionally-transform`
> which is a non-macro version of `test->`.

Likewise, except with use a HOF called "conditionalize":

(defn conditionalize
  "When called with a function f, returns a function that returns its
arguments if they
   arguments do not satisfy pred, or the result of the application of
f to its arguments otherwise."
  [pred f]
  (fn [& args] (if  (apply pred args) (apply f args) (apply identity args

Jay's example would then be (-> x ((conditionalize number? str))
(conditionalize string? count))), which tbh I like more because (a) it
doesn't introduce a new macro that can only be used in one syntactic
position (and there are other cases where you'd want to be able to
pass these transformed functions around) and (b) it groups the
transformations syntactically with their tests.

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


Re: Proposed change to let-> syntax

2012-11-30 Thread Steve Miner
I propose guard-> to avoid the cond-> confusion.

If we're voting, as-> is good.  I liked when->.


On Nov 30, 2012, at 10:37 AM, Rich Hickey  wrote:

> I'm not satisfied with the names for the new threading macros either. 
> 
> The new names being considered for let->, test-> and when-> are:
> 
> A) let-> becomes as->
> 
> reduces arg order and destructuring expectations.
> 
> B) test-> becomes cond->
> 
> cond-> was the original name, and, protestations about not short-circuiting 
> like cond notwithstanding, it is still the best fit. The doc string will say:
> 
> "Note that, unlike cond branching, cond-> threading does
>  not short circuit after the first true test expression."
> 
> C) when-> becomes some->
> 
> and in doing so, tests for non-nil rather than truth.
> 
> ==
> This last one touches on the general area of non-nil-ness, often needed. 
> Other possible (future) ideas in line with this are:
> 
> (some? x) == (not (nil? x))
> 
> (some coll) ;;note no pred, == (some some? coll)
> 
> this is tricky, as we are bridging CL's some and Maybe's Some
> 
> if-some, when-some et al.
> 
> (some! x) ;;(or somex ?) identity for all but nil, which throws
> 
> etc
> ==
> 
> Last chance for fabulous and better names than these: (as->, cond-> and 
> some->). Note that "cond-> doesn't match cond's short-circuit" has been 
> considered already, please do not repeat.
> 
> Thanks,
> 
> Rich
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> 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: Proposed change to let-> syntax

2012-11-30 Thread Alex Baranosky
I've got a utility function I've been using called
`conditionally-transform` which is a non-macro version of `test->`.  I
think both cond-> and if-> have a similar problem in that, if you already
understand if/cond/-> then it gives you little insight into how the new
threading macro works.

Both these names focus on the conditional nature of the macro.  Perhaps a
name based on the transformative nature of the macro: trans-> or
transform-> ?  These convey the idea of threading through various
transformations.

For when->, how about non-nil-> ?  I'd feel better about some-> if it came,
as you said, with other new functions that use the syllable 'some', thus
expanding the Clojure lexicon.  As it stands I don't feel like some-> has a
particularly intuitive meaning.

Alex

On Fri, Nov 30, 2012 at 9:33 AM, Jay Fields  wrote:

> On Fri, Nov 30, 2012 at 10:37 AM, Rich Hickey 
> wrote:
> > The new names being considered for let->, test-> and when-> are:
> >
> > A) let-> becomes as->
>
> I prefer ->as, but don't feel strongly about it.
>
> (-> 1
> str
> (->as one-str
>   (count one-str)
>   (* 2 one-str))) ;; returns 2
>
> The thing that I like about this is that it reads to me as "thread
> as", and the ordering of "->" and "as" reminds me that the args are
> slightly different from traditional threading macros (i.e. it's not
> (thread-macro x & forms).
>
> > B) test-> becomes cond->
>
> I don't like cond-> for the same reason I didn't like let->, the
> cond-> isn't easy to understand if you already understand cond and ->.
> To try to come up with a name that I like, I tried to write some
> similar code to see what I would use. I came up with the following:
>
> (->> 1
>  (#(if (number? %) (str %) %))
>  (#(if (string? %) (count %) %))) ;; returns 1
>
> Which led me to the following (the best I can come up with right now).
>
> (if-> 1
>   number? str
>   string? count) ;; returns 1
>
> I don't think this is a homerun, as the understanding of "if" and "->"
> wouldn't guarantee an understanding of this. However, I couldn't come
> up with an example of solving a similar problem with -> and cond in
> any sensible way. I don't think the shape of the arguments should
> define the name, which is the only reason you'd want to use "cond",
> imho.
>
> I also considered something that expressed "if or identity. Perhaps
> something like the following
>
> (ifoi-> 1
>  number? str
>  string? count) ;; ifoi stands for "if or identity".
>
> You could also use ifei->, for "if else identity"
>
> Perhaps the issue is resolved if the form can take an else fn. Then
> the original if-> example becomes
>
> (if-> 1
>   number? str identity
>   string? count identity)
>
> This also gives you the freedom to put any function you want in the
> else clause. I don't know if that's a good thing or not.
>
> Or, since the significant majority of us have auto-complete, perhaps
> the following works
>
> (if-else-identity-> 1
> number? str
> string? count)
>
> > C) when-> becomes some->
>
> I don't see any issue with when->, that one actually seems very clear.
> Is the issue that you want to be able to continue the threading with
> false? If so, I wouldn't overload the meaning of "some", I'd simply
> make it take a test fn - then you can use any pred you want.
>
> (->when (comp not nil) (f1) (f2))
>
> Which is even more clear if you define not-nil? in core. Then all of
> the following would easily work
>
> (->when 1 not-nil? (f1) (f2)) ; thread when not nil
> (->when 1 identity (f1) (f2)) ; thread when truthy
> (->when 1 #{1 2 3} (f1) (f2)) ; thread when the value is 1 2 or 3.
>
> note, I switched the order again, as I like the way it reads (e.g.
> "thread when 1 is not nil"), and it reminds me that this is a
> threading macro that takes more than x & forms.
>
> --
> 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: Proposed change to let-> syntax

2012-11-30 Thread Jay Fields
On Fri, Nov 30, 2012 at 10:37 AM, Rich Hickey  wrote:
> The new names being considered for let->, test-> and when-> are:
>
> A) let-> becomes as->

I prefer ->as, but don't feel strongly about it.

(-> 1
str
(->as one-str
  (count one-str)
  (* 2 one-str))) ;; returns 2

The thing that I like about this is that it reads to me as "thread
as", and the ordering of "->" and "as" reminds me that the args are
slightly different from traditional threading macros (i.e. it's not
(thread-macro x & forms).

> B) test-> becomes cond->

I don't like cond-> for the same reason I didn't like let->, the
cond-> isn't easy to understand if you already understand cond and ->.
To try to come up with a name that I like, I tried to write some
similar code to see what I would use. I came up with the following:

(->> 1
 (#(if (number? %) (str %) %))
 (#(if (string? %) (count %) %))) ;; returns 1

Which led me to the following (the best I can come up with right now).

(if-> 1
  number? str
  string? count) ;; returns 1

I don't think this is a homerun, as the understanding of "if" and "->"
wouldn't guarantee an understanding of this. However, I couldn't come
up with an example of solving a similar problem with -> and cond in
any sensible way. I don't think the shape of the arguments should
define the name, which is the only reason you'd want to use "cond",
imho.

I also considered something that expressed "if or identity. Perhaps
something like the following

(ifoi-> 1
 number? str
 string? count) ;; ifoi stands for "if or identity".

You could also use ifei->, for "if else identity"

Perhaps the issue is resolved if the form can take an else fn. Then
the original if-> example becomes

(if-> 1
  number? str identity
  string? count identity)

This also gives you the freedom to put any function you want in the
else clause. I don't know if that's a good thing or not.

Or, since the significant majority of us have auto-complete, perhaps
the following works

(if-else-identity-> 1
number? str
string? count)

> C) when-> becomes some->

I don't see any issue with when->, that one actually seems very clear.
Is the issue that you want to be able to continue the threading with
false? If so, I wouldn't overload the meaning of "some", I'd simply
make it take a test fn - then you can use any pred you want.

(->when (comp not nil) (f1) (f2))

Which is even more clear if you define not-nil? in core. Then all of
the following would easily work

(->when 1 not-nil? (f1) (f2)) ; thread when not nil
(->when 1 identity (f1) (f2)) ; thread when truthy
(->when 1 #{1 2 3} (f1) (f2)) ; thread when the value is 1 2 or 3.

note, I switched the order again, as I like the way it reads (e.g.
"thread when 1 is not nil"), and it reminds me that this is a
threading macro that takes more than x & forms.

-- 
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-11-30 Thread Rich Hickey
I'm not satisfied with the names for the new threading macros either. 

The new names being considered for let->, test-> and when-> are:

A) let-> becomes as->

reduces arg order and destructuring expectations.

B) test-> becomes cond->

cond-> was the original name, and, protestations about not short-circuiting 
like cond notwithstanding, it is still the best fit. The doc string will say:

"Note that, unlike cond branching, cond-> threading does
  not short circuit after the first true test expression."

C) when-> becomes some->

and in doing so, tests for non-nil rather than truth.

==
This last one touches on the general area of non-nil-ness, often needed. Other 
possible (future) ideas in line with this are:

(some? x) == (not (nil? x))

(some coll) ;;note no pred, == (some some? coll)

this is tricky, as we are bridging CL's some and Maybe's Some

if-some, when-some et al.

(some! x) ;;(or somex ?) identity for all but nil, which throws

etc
==

Last chance for fabulous and better names than these: (as->, cond-> and 
some->). Note that "cond-> doesn't match cond's short-circuit" has been 
considered already, please do not repeat.

Thanks,

Rich

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
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: call superclass method in classes created by Clojure?

2012-11-30 Thread Vladimir Tsichevski
Thank you David, it works!

On Thursday, November 29, 2012 5:44:06 PM UTC+4, David Powell wrote:
>
> proxy is basically a more interop-oriented version of reify though, and it 
> can extend classes, and you can use proxy-super to call superclass methods 
> from there.
> On Nov 29, 2012 1:40 PM, "Vladimir Tsichevski" 
> > 
> wrote:
>
>> Thanks
>>
>> On Thursday, November 29, 2012 5:33:20 PM UTC+4, David Powell wrote:
>>>
>>>
>>> reify can only implement interfaces and protocols, so there aren't any 
>>> superclass methods to call (except the ones in Object I guess).
>>>
>>>
>>> On Thu, Nov 29, 2012 at 1:30 PM, Vladimir Tsichevski >> > wrote:
>>>
 Thanks,

 is there something like that for reify?


 On Thursday, November 29, 2012 2:52:56 AM UTC+4, Meikel Brandmeyer 
 (kotarak) wrote:
>
> Am 28.11.12 23:10, schrieb Vladimir Tsichevski: 
> > Is it possible? 
> See exposes-methods in documentation for gen-class. 
>
> http://clojure.github.com/**cloj**ure/clojure.core-api.html#**cloj**
> ure.core/gen-class
>  
>
> Kind regards 
> Meikel 
>
>  -- 
 You received this message because you are subscribed to the Google
 Groups "Clojure" group.
 To post to this group, send email to clo...@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+u...@**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 clo...@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+u...@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: (iterate inc 2) vs (drop 2 (range)) in corecursion

2012-11-30 Thread Christophe Grand
Hallo,

On Thu, Nov 29, 2012 at 11:20 PM, Ulrich  wrote:

> Now should we consider this a clojure bug?
>

It is, see http://dev.clojure.org/jira/browse/CLJ-457

What clojure version are you using btw to get the exceptions?


master from Github with my patch to CLJ-457 applied :-)

Now, that's clear, anyway, the main point was and still is,
> that the code (the version corrected with a base case)
>
> (def primes
>   (cons
> 2
> (filter
>   (fn[n]
> (every?
>   #(pos? (mod n %))
>   (take-while #(<=(*%%)n) primes)
>   )
> )
>   (drop 3 (range))
>   )
> )
>   )
>
>
> SHOULD imho properly work in a proper clojure implementation,
> n'est ce pas?
>

Genau and it certainly worked in Clojure 1.0 (chunked sequences were
introduced in 1.1).

So, with my patch applied, this code still does not work but at least we
get an exception rather than an incorrect result. Not perfect but, in my
opinion, a step towards correctness (and it should also break some rare
code ("recursive" chunked seqs only) which happens to work by luck).

Christophe

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

class loading problem in embedded clojure

2012-11-30 Thread Vladimir Tsichevski
Hi,

I've embedded Clojure 1.4 with nREPL into my Eclipse RCP application.

Now in nREPL I define a function which builds a menu with some actions. 
Everything seemes to work as expected.
Now I select some menu item which executes the following code:

  (println PlatformUI)
  (println (PlatformUI/getWorkbench))

where 'PlatformUI' is a class from Eclipse base distribution imported 
earlier in the ns declaration, and 'getWorkbench' is its static method. 
This code works Ok also.

Now I remove the first line and run just

  (println (PlatformUI/getWorkbench))

And got the exception below. Anybody can explain this?

java.lang.NoClassDefFoundError: org/eclipse/ui/PlatformUI
at myApp.clojure.menu$menu$fn__1475.invoke(Unknown Source)
at myApp.clojure.menu.proxy$org.eclipse.jface.action.Action$0.run(Unknown 
Source)
at org.eclipse.jface.action.Action.runWithEvent(Action.java:498)
at 
myApp.clojure.menu.proxy$org.eclipse.jface.action.Action$0.runWithEvent(Unknown 
Source)
at 
org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:584)
at 
org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:501)
at 
org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:411)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1258)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3588)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3209)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2701)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2665)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2499)
at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:679)
at 
org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at 
org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:668)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at myApp.rcp.MyAppApp.start(MyAppApp.java:24)
at 
org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at 
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at 
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at 
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
at 
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
at org.eclipse.equinox.launcher.Main.main(Main.java:1386)
Caused by: java.lang.ClassNotFoundException: org.eclipse.ui.PlatformUI
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at clojure.lang.DynamicClassLoader.findClass(DynamicClassLoader.java:61)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 32 more

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