Re: cljs.test :after fixture not called if test errors

2020-11-27 Thread Stuart Campbell
Makes sense. Thanks all!

On Wed, Nov 25, 2020, 6:46 PM David Nolen  wrote:

> In the async case just handle the error yourself and fail the test.
> There's really not a good way to detect async errors since there isn't one
> way to. do async (promises, core.async, etc.).
>
> David
>
> On Wed, Nov 25, 2020 at 1:19 AM Stuart Campbell  wrote:
>
>> That unfortunately doesn't work for async tests, which require the map
>> fixture style (with :before/:after keys).
>>
>> On Tue, 24 Nov 2020 at 21:23, Estevo U. C. Castro 
>> wrote:
>>
>>> Try
>>>
>>> (use-fixtures :once
>>>   (fn [f]
>>> (println "before")
>>> (try (f)
>>>   (finally (println "after")
>>>
>>> O mércores, 25 de novembro de 2020 á/s 00:17:03 UTC+1,
>>> stuart.will...@gmail.com escribiu:
>>>
>>>> Hello,
>>>>
>>>> I'm experimenting with fixtures and it seems like :after fixtures
>>>> aren't run if a test unexpectedly errors. E.g.:
>>>>
>>>> (use-fixtures :once {:before #(println "before")
>>>>  :after #(println "after")})
>>>>
>>>> (deftest a-test
>>>>   (raise (js/Error. "oops")))
>>>>
>>>> In this example I expected to see "after" printed somewhere after the
>>>> test failed. Is this intentional?
>>>>
>>>> (I'm writing some tests for an Electron app using Spectron and want to
>>>> make sure the app is always shut down after the tests are complete.)
>>>>
>>>> Regards,
>>>> Stuart
>>>>
>>> --
>>> 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 a topic in the
>>> Google Groups "Clojure" group.
>>> To unsubscribe from this topic, visit
>>> https://groups.google.com/d/topic/clojure/N28pFLtNWpo/unsubscribe.
>>> To unsubscribe from this group and all its topics, send an email to
>>> clojure+unsubscr...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/clojure/84dff1cf-6ea0-438c-a4c0-fac097223201n%40googlegroups.com
>>> <https://groups.google.com/d/msgid/clojure/84dff1cf-6ea0-438c-a4c0-fac097223201n%40googlegroups.com?utm_medium=email_source=footer>
>>> .
>>>
>> --
>> 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 unsubscribe from this group and stop receiving emails from it, send an
>> email to clojure+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/clojure/CAFuJp1n1Vz8NKf%3DmxakTYn1EXF8UUqTQwc5NiDUKGMOj-BKBsQ%40mail.gmail.com
>> <https://groups.google.com/d/msgid/clojure/CAFuJp1n1Vz8NKf%3DmxakTYn1EXF8UUqTQwc5NiDUKGMOj-BKBsQ%40mail.gmail.com?utm_medium=email_source=footer>
>> .
>>
> --
> 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 a topic in the
> Google Groups "Clojure" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/cloju

Re: cljs.test :after fixture not called if test errors

2020-11-24 Thread Stuart Campbell
That unfortunately doesn't work for async tests, which require the map
fixture style (with :before/:after keys).

On Tue, 24 Nov 2020 at 21:23, Estevo U. C. Castro 
wrote:

> Try
>
> (use-fixtures :once
>   (fn [f]
> (println "before")
> (try (f)
>   (finally (println "after")
>
> O mércores, 25 de novembro de 2020 á/s 00:17:03 UTC+1,
> stuart.will...@gmail.com escribiu:
>
>> Hello,
>>
>> I'm experimenting with fixtures and it seems like :after fixtures aren't
>> run if a test unexpectedly errors. E.g.:
>>
>> (use-fixtures :once {:before #(println "before")
>>  :after #(println "after")})
>>
>> (deftest a-test
>>   (raise (js/Error. "oops")))
>>
>> In this example I expected to see "after" printed somewhere after the
>> test failed. Is this intentional?
>>
>> (I'm writing some tests for an Electron app using Spectron and want to
>> make sure the app is always shut down after the tests are complete.)
>>
>> Regards,
>> Stuart
>>
> --
> 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 a topic in the
> Google Groups "Clojure" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/clojure/N28pFLtNWpo/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> clojure+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/clojure/84dff1cf-6ea0-438c-a4c0-fac097223201n%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/clojure/CAFuJp1n1Vz8NKf%3DmxakTYn1EXF8UUqTQwc5NiDUKGMOj-BKBsQ%40mail.gmail.com.


cljs.test :after fixture not called if test errors

2020-11-24 Thread Stuart Campbell
Hello,

I'm experimenting with fixtures and it seems like :after fixtures aren't 
run if a test unexpectedly errors. E.g.:

(use-fixtures :once {:before #(println "before")
 :after #(println "after")})

(deftest a-test
  (raise (js/Error. "oops")))

In this example I expected to see "after" printed somewhere after the test 
failed. Is this intentional?

(I'm writing some tests for an Electron app using Spectron and want to make 
sure the app is always shut down after the tests are complete.)

Regards,
Stuart

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/clojure/53969332-2819-48fe-ab01-a27fd3b0cc00n%40googlegroups.com.


clojure.tools.logging / log4j / lein2

2013-01-29 Thread Stuart Campbell
Hello,

I'm working on a library that uses clojure.tools.logging, and I'm using
Leiningen 2 to build it.

If I include log4j in my project's :dev-dependencies, I get weird logging
output, e.g.:

Jan 29, 2013 8:45:31 PM clojure.tools.logging$eval373$fn__377 invoke
INFO: Hello

But if I include log4j in my project's :dependencies, it looks normal:

2013-01-29 20:44:41,966 INFO  user: hello

Ideally I'd like to use :dev-dependencies for this.

My guess is there's some classloading ordering issue, but I'm not quite
sure how to resolve it. Any ideas?

Thanks,
Stuart

-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: clojure.tools.logging / log4j / lein2

2013-01-29 Thread Stuart Campbell
Hmm, perhaps I should RTFM. Apparently :dev-dependencies no longer exists
in lein2.
Adding this to my project.clj resolves the issue:

:profiles {:dev {:dependencies [[log4j 1.2.17]]}}


On 29 January 2013 21:24, Stuart Campbell stu...@harto.org wrote:

 Hello,

 I'm working on a library that uses clojure.tools.logging, and I'm using
 Leiningen 2 to build it.

 If I include log4j in my project's :dev-dependencies, I get weird logging
 output, e.g.:

 Jan 29, 2013 8:45:31 PM clojure.tools.logging$eval373$fn__377 invoke
 INFO: Hello

 But if I include log4j in my project's :dependencies, it looks normal:

 2013-01-29 20:44:41,966 INFO  user: hello

 Ideally I'd like to use :dev-dependencies for this.

 My guess is there's some classloading ordering issue, but I'm not quite
 sure how to resolve it. Any ideas?

 Thanks,
 Stuart


-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: ClojureScript def, vars, and binding

2013-01-14 Thread Stuart Campbell
Sorry to dig up such an old thread.

I'd also like to maintain the bindings of dynamic vars across asynchronous 
function calls.

Is there a workaround that people use in the absence of bound-fn, etc?

Cheers,
Stuart

On Friday, 27 January 2012 16:49:10 UTC+11, Brandon Bloom wrote:

 The ClojureScript 
 wikihttps://github.com/clojure/clojurescript/wiki/Differences-from-Clojurestates
  that the user experience of [binding] is similar to that in 
 Clojure but my very first experiment produced wildly different results 
 between platforms.

 Here's a Clojure on the JVM session:

 user= (import java.lang.Thread)
 java.lang.Thread
 user= (defn set-timeout [ms fn] (.run (Thread. #(do (Thread/sleep ms) 
 (fn)
 #'user/set-timeout
 user= (def x top level)
 #'user/x
 user= (binding [x in binding] (println x) (set-timeout 1000 #(println 
 x)))
 in binding
 in binding
 nil

 And here's the analogous ClojureScript session:

 ClojureScript:cljs.user (def x top level)
 top level
 ClojureScript:cljs.user (binding [x in binding] (println x) 
 (js/setTimeout #(println x) 1000))
 in binding
 21
 top level

 So ignoring the sequencing and nil vs timeout-id return values, the 
 binding of 'x wasn't preserved in the asynchronous callback.

 I raised this issue in #clojure and @dnolen said that that's the behavior 
 there's nothing much to fix, but that didn't sit right with me. This seems 
 like either 'binding is bugged, or maybe I don't understand something about 
 its intent.

 On the topic of Vars proper, I understand their usefulness in 
 repl-centric development, where you can redefine functions at runtime. The 
 wiki also makes some mention of this, but I can't wrap my head around the 
 context and jargon. I've run into this problem before in Javascript, where 
 some level of indirection is necessary to support run-time redefinitions. 
 You can't do `var fn = package.fn;` and dynamically redefine `fn` from 
 `package` later because a copy of the reference is made. How does 
 ClojureScript address this problem?

 Cheers,
 Brandon


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

2013-01-03 Thread Stuart Campbell
In case anybody's interested, I'm messing around with a ClojureScript
wrapper type that can implement various core protocols, e.g.:

(deftype ClojureObject [o]
  IFn
  (-invoke [_] (.invoke o))
  (-invoke [_ a] (.invoke o a))
  ;; etc
  )



On 31 December 2012 09:56, Stuart Campbell stu...@harto.org wrote:

 OK, unless there's some way to set arbitrary properties on a Java object,
 I guess this isn't possible...

 ClojureScript:cljs.user (aset js/Packages.clojure.lang.IFn prototype
 (js/Object.))
 Error evaluating: (aset js/Packages.clojure.lang.IFn prototype
 (js/Object.)) :as (Packages.clojure.lang.IFn[\prototype\] = (new
 Object()));\n
 org.mozilla.javascript.EvaluatorException: Java class clojure.lang.IFn
 has no public instance field or method named prototype. (cljs repl#9)
 at cljs repl:9 (anonymous)
 at cljs repl:9


 On 31 December 2012 09:41, Stuart Campbell stu...@harto.org wrote:

 Ah, you're right -- thanks. That leads me to another error:

 ClojureScript:cljs.user (extend-type js/Packages.clojure.lang.IFn IFn
 (-invoke ([this] (.invoke this
 Error evaluating: (extend-type js/Packages.clojure.lang.IFn IFn
 (-invoke ([this] (.invoke this :as
 Packages.clojure.lang.IFn.prototype.cljs$core$IFn$ =
 true;\nPackages.clojure.lang.IFn.prototype.call = (function
 (this_sym23394){\nvar this_sym23394__23395 = this;\nvar this__23396 =
 this_sym23394__23395;\nreturn
 this__23396.invoke();\n});\nPackages.clojure.lang.IFn.prototype.apply =
 (function (this_sym23392,args23393){\nreturn
 this_sym23392.call.apply(this_sym23392,[this_sym23392].concat(args23393.slice()));\n});\n
 org.mozilla.javascript.EcmaError: TypeError: Cannot set property
 cljs$core$IFn$ of null to true (cljs repl#25)
 at cljs repl:25 (anonymous)
 at cljs repl:25 (anonymous)
 at cljs repl:25

 I'll keep investigating.

 On 30 December 2012 12:31, David Nolen dnolen.li...@gmail.com wrote:

 I think you've just formatted your code incorrectly. Did you try
 something like this?

 (extend-type js/Packages.clojure.lang.IFn
   IFn
   (-invoke
 ([this] (.invoke this))
 ([this a] (.invoke this a)))
   )


  On Sat, Dec 29, 2012 at 8:22 PM, Stuart Campbell stu...@harto.orgwrote:

  Hi all,

 I'm toying with a way to use Clojure objects from a Rhino-based
 ClojureScript environment (https://github.com/harto/rhino-bridge).

 I've been able to export a Clojure function into the ClojureScript
 environment without too much difficulty. Ideally, I'd like to be able to
 call that function as if it were a regular ClojureScript function.

 I was hoping I could do something like:

 (extend-type js/Packages.clojure.lang.IFn
   IFn
   (-invoke [this] (.invoke this))
   (-invoke [this a] (.invoke this a))
   ;; etc
   )

 However, this yields an error that I don't quite understand:

 java.lang.UnsupportedOperationException: nth not supported on this
 type: Symbol
 at clojure.lang.RT.nthFrom(RT.java:846)
 at clojure.lang.RT.nth(RT.java:796)
 at
 cljs.core$extend_type$assign_impls__7365$fn__7377$adapt_params__7380.invoke(core.clj:486)
 at clojure.core$map$fn__4087.invoke(core.clj:2434)

 In fact, I'm not sure this will work at all, since (type) doesn't
 appear to work with non-native JS objects.

 Is the extend-type method feasible?

 Cheers,
 Stuart

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en


  --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en





-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: cljs-clj interop

2012-12-30 Thread Stuart Campbell
Ah, you're right -- thanks. That leads me to another error:

ClojureScript:cljs.user (extend-type js/Packages.clojure.lang.IFn IFn
(-invoke ([this] (.invoke this
Error evaluating: (extend-type js/Packages.clojure.lang.IFn IFn (-invoke
([this] (.invoke this :as
Packages.clojure.lang.IFn.prototype.cljs$core$IFn$ =
true;\nPackages.clojure.lang.IFn.prototype.call = (function
(this_sym23394){\nvar this_sym23394__23395 = this;\nvar this__23396 =
this_sym23394__23395;\nreturn
this__23396.invoke();\n});\nPackages.clojure.lang.IFn.prototype.apply =
(function (this_sym23392,args23393){\nreturn
this_sym23392.call.apply(this_sym23392,[this_sym23392].concat(args23393.slice()));\n});\n
org.mozilla.javascript.EcmaError: TypeError: Cannot set property
cljs$core$IFn$ of null to true (cljs repl#25)
at cljs repl:25 (anonymous)
at cljs repl:25 (anonymous)
at cljs repl:25

I'll keep investigating.

On 30 December 2012 12:31, David Nolen dnolen.li...@gmail.com wrote:

 I think you've just formatted your code incorrectly. Did you try something
 like this?

 (extend-type js/Packages.clojure.lang.IFn
   IFn
   (-invoke
 ([this] (.invoke this))
 ([this a] (.invoke this a)))
   )


 On Sat, Dec 29, 2012 at 8:22 PM, Stuart Campbell stu...@harto.org wrote:

 Hi all,

 I'm toying with a way to use Clojure objects from a Rhino-based
 ClojureScript environment (https://github.com/harto/rhino-bridge).

 I've been able to export a Clojure function into the ClojureScript
 environment without too much difficulty. Ideally, I'd like to be able to
 call that function as if it were a regular ClojureScript function.

 I was hoping I could do something like:

 (extend-type js/Packages.clojure.lang.IFn
   IFn
   (-invoke [this] (.invoke this))
   (-invoke [this a] (.invoke this a))
   ;; etc
   )

 However, this yields an error that I don't quite understand:

 java.lang.UnsupportedOperationException: nth not supported on this type:
 Symbol
 at clojure.lang.RT.nthFrom(RT.java:846)
 at clojure.lang.RT.nth(RT.java:796)
 at
 cljs.core$extend_type$assign_impls__7365$fn__7377$adapt_params__7380.invoke(core.clj:486)
 at clojure.core$map$fn__4087.invoke(core.clj:2434)

 In fact, I'm not sure this will work at all, since (type) doesn't appear
 to work with non-native JS objects.

 Is the extend-type method feasible?

 Cheers,
 Stuart

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en


  --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: cljs-clj interop

2012-12-30 Thread Stuart Campbell
OK, unless there's some way to set arbitrary properties on a Java object, I
guess this isn't possible...

ClojureScript:cljs.user (aset js/Packages.clojure.lang.IFn prototype
(js/Object.))
Error evaluating: (aset js/Packages.clojure.lang.IFn prototype
(js/Object.)) :as (Packages.clojure.lang.IFn[\prototype\] = (new
Object()));\n
org.mozilla.javascript.EvaluatorException: Java class clojure.lang.IFn
has no public instance field or method named prototype. (cljs repl#9)
at cljs repl:9 (anonymous)
at cljs repl:9


On 31 December 2012 09:41, Stuart Campbell stu...@harto.org wrote:

 Ah, you're right -- thanks. That leads me to another error:

 ClojureScript:cljs.user (extend-type js/Packages.clojure.lang.IFn IFn
 (-invoke ([this] (.invoke this
 Error evaluating: (extend-type js/Packages.clojure.lang.IFn IFn (-invoke
 ([this] (.invoke this :as
 Packages.clojure.lang.IFn.prototype.cljs$core$IFn$ =
 true;\nPackages.clojure.lang.IFn.prototype.call = (function
 (this_sym23394){\nvar this_sym23394__23395 = this;\nvar this__23396 =
 this_sym23394__23395;\nreturn
 this__23396.invoke();\n});\nPackages.clojure.lang.IFn.prototype.apply =
 (function (this_sym23392,args23393){\nreturn
 this_sym23392.call.apply(this_sym23392,[this_sym23392].concat(args23393.slice()));\n});\n
 org.mozilla.javascript.EcmaError: TypeError: Cannot set property
 cljs$core$IFn$ of null to true (cljs repl#25)
 at cljs repl:25 (anonymous)
 at cljs repl:25 (anonymous)
 at cljs repl:25

 I'll keep investigating.

 On 30 December 2012 12:31, David Nolen dnolen.li...@gmail.com wrote:

 I think you've just formatted your code incorrectly. Did you try
 something like this?

 (extend-type js/Packages.clojure.lang.IFn
   IFn
   (-invoke
 ([this] (.invoke this))
 ([this a] (.invoke this a)))
   )


  On Sat, Dec 29, 2012 at 8:22 PM, Stuart Campbell stu...@harto.orgwrote:

  Hi all,

 I'm toying with a way to use Clojure objects from a Rhino-based
 ClojureScript environment (https://github.com/harto/rhino-bridge).

 I've been able to export a Clojure function into the ClojureScript
 environment without too much difficulty. Ideally, I'd like to be able to
 call that function as if it were a regular ClojureScript function.

 I was hoping I could do something like:

 (extend-type js/Packages.clojure.lang.IFn
   IFn
   (-invoke [this] (.invoke this))
   (-invoke [this a] (.invoke this a))
   ;; etc
   )

 However, this yields an error that I don't quite understand:

 java.lang.UnsupportedOperationException: nth not supported on this type:
 Symbol
 at clojure.lang.RT.nthFrom(RT.java:846)
 at clojure.lang.RT.nth(RT.java:796)
 at
 cljs.core$extend_type$assign_impls__7365$fn__7377$adapt_params__7380.invoke(core.clj:486)
 at clojure.core$map$fn__4087.invoke(core.clj:2434)

 In fact, I'm not sure this will work at all, since (type) doesn't appear
 to work with non-native JS objects.

 Is the extend-type method feasible?

 Cheers,
 Stuart

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

cljs-clj interop

2012-12-29 Thread Stuart Campbell
Hi all,

I'm toying with a way to use Clojure objects from a Rhino-based
ClojureScript environment (https://github.com/harto/rhino-bridge).

I've been able to export a Clojure function into the ClojureScript
environment without too much difficulty. Ideally, I'd like to be able to
call that function as if it were a regular ClojureScript function.

I was hoping I could do something like:

(extend-type js/Packages.clojure.lang.IFn
  IFn
  (-invoke [this] (.invoke this))
  (-invoke [this a] (.invoke this a))
  ;; etc
  )

However, this yields an error that I don't quite understand:

java.lang.UnsupportedOperationException: nth not supported on this type:
Symbol
at clojure.lang.RT.nthFrom(RT.java:846)
at clojure.lang.RT.nth(RT.java:796)
at
cljs.core$extend_type$assign_impls__7365$fn__7377$adapt_params__7380.invoke(core.clj:486)
at clojure.core$map$fn__4087.invoke(core.clj:2434)

In fact, I'm not sure this will work at all, since (type) doesn't appear to
work with non-native JS objects.

Is the extend-type method feasible?

Cheers,
Stuart

-- 
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: apply a function to every item in a sequence without realizing the sequence

2012-05-02 Thread Stuart Campbell
On 2 May 2012 14:44, Baishampayan Ghose b.gh...@gmail.com wrote:

 You can't use `map` because `map` will return a sequence of the same
 size and that can blow your heap.


Isn't `map` lazy too?

Regards,
Stuart

-- 
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: ClassCastException clojure.lang.Var$Unbound Help

2012-04-30 Thread Stuart Campbell
Hi Travis,

 (def get-id
   (session/get :uid))

 (defn set-user! [user]
   (session/put! :uid {:_id user}))

Only set-user! is a function here. The value of get-id is evaluated at
compile-time.

I don't know about the implementation of noir.session/get, but the error
message suggests that it uses some dynamic var that is unbound at
compile-time. That makes sense since you couldn't reference a session
without an associated request.

Changing get-id to something like:

(defn get-id []
  (session/get :uid))

will probably do what you expect.

= (meta #'get-id)
 {:ns #Namespace app-admin.models.current-user, :name get-id}

 So it's there, the fn is bound [...]


Actually no, you're looking up the metadata on the var, not the value.
Observe the following:

user (def foo)
#'user/foo
user foo
#Unbound Unbound: #'user/foo
user (meta #'foo)
{:ns #Namespace user, :name foo, :line 1, :file NO_SOURCE_FILE}

See also http://clojure.org/vars

Regards,
Stuart

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: ClojureScript: can't (:use) protocol in another namespace

2012-04-29 Thread Stuart Campbell
It does. Ticket opened: http://dev.clojure.org/jira/browse/CLJS-216

Cheers,
Stuart

On 28 April 2012 01:30, David Nolen dnolen.li...@gmail.com wrote:

 Does this work in Clojure? If so file a ticket in JIRA.

 David

 On Fri, Apr 27, 2012 at 5:09 AM, Stuart Campbell stu...@harto.org wrote:

 Hello,

 I'm not sure if what I'm doing is supported or whether I'm doing it
 incorrectly.

 I have two ClojureScript namespaces:

 (ns foo)

 (defprotocol SomeProtocol
   (some-function [this]))

 (ns bar
   (:use [foo :only (SomeProtocol)]))

 (defrecord SomeRecord
   SomeProtocol
   (some-function [_] :quux))

 The protocol function is compiled as though SomeProtocol was defined in
 the bar namespace, e.g.:

 bar.SomeType.prototype.bar$SomeProtocol$ = true;
 bar.SomeType.prototype.bar$SomeProtocol$some_function = function(this$) {
   var this__14211 = this;
   return\ufdd0'quux
 };

 This causes an error at runtime.

 Should I be able to do this, or should I stick with (:require foo) and
 foo/SomeProtocol?

 Cheers,
 Stuart

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

ClojureScript: can't (:use) protocol in another namespace

2012-04-27 Thread Stuart Campbell
Hello,

I'm not sure if what I'm doing is supported or whether I'm doing it
incorrectly.

I have two ClojureScript namespaces:

(ns foo)

(defprotocol SomeProtocol
  (some-function [this]))

(ns bar
  (:use [foo :only (SomeProtocol)]))

(defrecord SomeRecord
  SomeProtocol
  (some-function [_] :quux))

The protocol function is compiled as though SomeProtocol was defined in the
bar namespace, e.g.:

bar.SomeType.prototype.bar$SomeProtocol$ = true;
bar.SomeType.prototype.bar$SomeProtocol$some_function = function(this$) {
  var this__14211 = this;
  return\ufdd0'quux
};

This causes an error at runtime.

Should I be able to do this, or should I stick with (:require foo) and
foo/SomeProtocol?

Cheers,
Stuart

-- 
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: Help with #'

2012-04-22 Thread Stuart Campbell
Hi Dave,

If you write

  (run-jetty routes ...)

then the current value of routes is looked-up and passed to run-jetty.
You won't see any change if you subsequently redefine routes, because the
original definition is what was passed to run-jetty.

On the other hand,

  (run-jetty #'routes ...)

passes a var (see http://clojure.org/vars) to run-jetty. Now whenever
run-jetty invokes your handler function, the currently-bound value of
routes is invoked.

Here's a simplified example:

  user (defn foo [] hello)
  #'user/foo
  user (def a foo)
  #'user/a
  user (def b #'foo)
  #'user/b
  user (defn foo [] goodbye)
  #'user/foo
  user (a)
  hello
  user (b)
  goodbye

Cheers,
Stuart

On 23 April 2012 06:01, David Simmons shortlypor...@gmail.com wrote:

 Hi

 I'm new to Clojure but very keen to learn. I'm following Web
 Development with Clojure (http://www.vijaykiran.com/2012/01/11/web-
 application-development-with-clojure-part-1/) and came across the
 following code:

  (run-jetty #'routes {:port (or port 8080) :join? false}))

 I know that #'routes is the same as (var routes) and that it is
 passing the object rather than the actual value BUT I don't
 understand why this is used. Specifically if I replace #'route with
 route the code works fine. I've read somewhere this is something to do
 with autoloading changes to code when developing for the web. Does
 anyone have a simple explanaition for #' and why it is used here. If
 you have some simple clojure code to illustrate its use I'd be really
 grateful.

 many thanks in advance for any help.

 Dave

 --
 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: Typed Clojure 0.1-alpha2

2012-04-21 Thread Stuart Campbell
The ClojureScript compiler doesn't seem to do those kinds of checks, but
the Clojure compiler does.

On 21 April 2012 09:18, Casper Clausen casp...@gmail.com wrote:

 Looks interesting.

 Personally I always thought clojure's handling of function arity is a
 bit strange. I don't understand why calling a function like this

 (defn testfn [one two] ...)

 (test-fn 1)

 is not at least a compiler warning, possibly with a switch for the
 compiler for strict checking. I understand that it is not always
 possible to perform this check, but why not do it when possible? It
 would make clojure alot safer to use without a test suite covering
 every code path.


 On Apr 20, 8:50 pm, Ambrose Bonnaire-Sergeant
 abonnaireserge...@gmail.com wrote:
  Hi,
 
  I know there are a few people interested in trying Typed Clojure,
  so I've cut an early alpha release to give a taste.
 
  These are *very* early days, but looking through the readme will
  give you some hints as to what works in this release. Don't
  expect too much.
 
  https://github.com/frenchy64/typed-clojure
 
  Please give it a whirl, feedback welcome!
 
  Thanks,
  Ambrose

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

ClojureScript function params shadow top-level namespace segments

2012-04-13 Thread Stuart Campbell
Given the following ClojureScript:

(ns foo)
(defn bar [] 42)

(ns baz
  (:require [foo :as x]))

(defn quux [foo]
  (x/bar))

baz.quux compiles to:

baz.quux = function quux(foo) {
  return foo.bar.call(null)
};

i.e. the parameter name shadows the top-level foo namespace.

Is that a bug?

Regards,
Stuart

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: ClojureScript function params shadow top-level namespace segments

2012-04-13 Thread Stuart Campbell
Done: http://dev.clojure.org/jira/browse/CLJS-180

On 13 April 2012 22:14, David Nolen dnolen.li...@gmail.com wrote:

 Yes. Please open a ticket in JIRA.

 Thanks!

 On Fri, Apr 13, 2012 at 3:40 AM, Stuart Campbell stu...@harto.org wrote:

 Given the following ClojureScript:

 (ns foo)
 (defn bar [] 42)

 (ns baz
   (:require [foo :as x]))

 (defn quux [foo]
   (x/bar))

 baz.quux compiles to:

 baz.quux = function quux(foo) {
   return foo.bar.call(null)
 };

 i.e. the parameter name shadows the top-level foo namespace.

 Is that a bug?

 Regards,
 Stuart

  --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en


  --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Problems with map of empty collections

2012-04-03 Thread Stuart Campbell
I think quoting plays a part here:

Clojure 1.3.0
user= {(list 1 2 3) :list [1 2 3] :vec}
IllegalArgumentException Duplicate key: (1 2 3)
clojure.lang.PersistentArrayMap.createWithCheck (PersistentArrayMap.java:70)

Stuart

On 3 April 2012 22:41, JuanManuel Gimeno Illa jmgim...@gmail.com wrote:

 More examples in clojure 1.3.0:

 user= {[1 2 3] :vector '(1 2 3) :list}
 {[1 2 3] :list}

 but

 user= #{[1 2 3] (1 2 3)}
 IllegalArgumentException Duplicate key: (1 2 3)
  clojure.lang.PersistentHashSet.createWithCheck (PersistentHashSet.java:68)

 ... anyone has an explanation?

 Juan Manuel

 On Tuesday, April 3, 2012 10:55:26 AM UTC+2, mnicky wrote:

 Another interesting fact is that:

 Clojure 1.2.1
 user= {'(1) :list [1] :vector}
 java.lang.**IllegalArgumentException: Duplicate key: (1)
 (NO_SOURCE_FILE:0)

 Clojure 1.3.0
 user= {'(1) :list [1] :vector}
 {(1) :vector}

 Clojure 1.4.0-beta1
 user= {'(1) :list [1] :vector}
 {(1) :vector}

 ...but I don't know what's going on.


 On Tuesday, April 3, 2012 9:11:50 AM UTC+2, JuanManuel Gimeno Illa wrote:

 Playing with some problems of 4clojure, I wanted to make a map which,
 for each empty collection, returns a keyword. But it seems that it is
 impossible to have both an empty list and an empty vector in the same map.

 user= {() :list}
 {() :list}
 user= {() :list [] :vector}
 IllegalArgumentException Duplicate key: clojure.lang.PersistentList$**
 EmptyList@1  clojure.lang.**PersistentArrayMap.**createWithCheck
 (PersistentArrayMap.java:70)
 user= {[] :vector}
 {[] :vector}

 I supposed that this is due to (= [] ()) but

 user= {'(1) :list [1] :vector}
 {(1) :vector}
 user= (= [1]'(1))
 true

 What am I missing?

 Juan Manuel

  --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en


-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: 'contains?' on 'sorted-set-by' based on the comparator only? (possible bug?)

2012-03-15 Thread Stuart Campbell
Actually, sorted-map-by does behave the same way, but in your example you
tried to lookup a value instead of a key:

user (def m (sorted-map-by #( (%1 0) (%2 0)) [1 :a] [2 :b]))
#'user/m
user (get m [1 :foo])
[2 :b]

It looks like 
PersistentTreeMap.entryAthttps://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/PersistentTreeMap.java#L285is
responsible for this behaviour.

Regards,
Stuart

On 13 March 2012 05:20, mnicky markus.mas...@gmail.com wrote:

 It seems that when using the sorted set with my own comparator
 (sorted-set-by),
 the lookup via 'contains?' function is based only on the part of the items
 that participate in the ordering:

 (contains? (sorted-set [1 :a] [2 :b]) [2 :c])
 ;= false

 (contains? (sorted-set-by #( (%1 0) (%2 0)) [1 :a] [2 :b]) [2 :c])
 ;= true

 The documentation of 'sorted-set-by' says that the _whole_ items are keys:

 (doc sorted-set-by)
 ; clojure.core/sorted-set-by
 ; ([comparator  keys])
 ; Returns a new sorted set with supplied keys, using the supplied
 comparator.
 ; nil

 So according to the documentation of 'contains?', it should do lookup
 based on the whole items, not just their parts used in the comparator:

 (doc contains?)
 ; clojure.core/contains?
 ; ([coll key])
 ; Returns true if key is present in the given collection, otherwise
 ; returns false. Note that for numerically indexed collections like
 ; vectors and Java arrays, this tests if the numeric key is within the
 ; range of indexes. 'contains?' operates constant or logarithmic time;
 ; it will not perform a linear search for a value. See also 'some'.
 ; nil


 It's also worth noting that 'sorted-map-by' doesn't behave in this way:

 (contains? (sorted-map-by #( (%1 0) (%2 0)) [1 :a] [2 :b]) [2 :c])
 ;= false

 Can this be a bug? If not, what's the reason behind this behavior?


 -- Mnicky

  --
 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: Resolving vars and quoting

2012-03-15 Thread Stuart Campbell
Almost, but you do need to resolve the symbols to functions when you
evaluate the operation:

(defn arith [x y]
  (map (fn [op] [((resolve op) x y) (list op x y)]) '[+ - / *]))

Regards,
Stuart

On 16 March 2012 02:52, Jack Moffitt j...@metajack.im wrote:

  If I apply the following function to 4 and 6
 
  (defn arith [x y]
   (map (fn [op] [(op x y) `(~op ~x ~y)]) [+ - / *]))
 
  I'd like to get a result of the form
 
  ([10 (+ 4 6)] [-2 (- 4 6)] ...)
 
  but instead I get something like
  ([10 (#core$_PLUS_ clojure.core$_PLUS_@4f6de641 4 6)] ...

 You want to quote the [+ - / *] so it doesn't resolve to the functions:

 (defn arith [x y]
  (map (fn [op] [(op x y) `(~op ~x ~y)]) '[+ - / *]))

 jack.

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en


-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: ClojureScript: browser REPL omitting namespace in generated JS

2012-03-14 Thread Stuart Campbell
I see what you mean. In fact, if I enter (ns foo) at the REPL instead of
(in-ns 'foo), the namespace is created in cljs.compiler/namespaces and
the compiled JS is output correctly.

On 3 March 2012 12:12, Brenton bashw...@gmail.com wrote:

 Thanks Stuart,

 Looks like the problem might be here:


 https://github.com/clojure/clojurescript/blob/master/src/clj/cljs/repl.clj#L117

 I'll dig into this this weekend.

 On Mar 2, 6:30 pm, Stuart Campbell stu...@harto.org wrote:
  Done!http://dev.clojure.org/jira/browse/CLJS-157
 
  On 3 March 2012 01:15, David Nolen dnolen.li...@gmail.com wrote:
 
 
 
 
 
 
 
   Please open a ticket in JIRA. Thanks!
 
   On Fri, Mar 2, 2012 at 4:50 AM, Stuart Campbell stu...@harto.org
 wrote:
 
   Hello,
 
   I'm encountering a problem where the browser REPL sometimes omits the
   ClojureScript namespace in its generated JavaScript, e.g. (def x 42)
   compiles to .x = 42 instead of foo.x = 42.
 
   I've put together a minimal project, with steps to reproduce, on
 GitHub:
  https://github.com/harto/cljs-eval-test
 
   It looks to me like compiling a set of ClojureScript files (using
   cljs.closure/build) causes some side-effect that prevents the
 problem. See
   the GitHub README for details.
 
   I'm on Mac OS X 10.5 with Java 1.6.0_26.
 
   Regards,
   Stuart
 
--
   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 options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Clojurescript: named/numbered releases?

2012-03-08 Thread Stuart Campbell
Hello,

According to a past thread (
https://groups.google.com/forum/?fromgroups#!topic/clojure/L4e8DtzdThY):

ClojureScript has no release versions yet. Instead we have a
 revision number, calculated as the number of commits on the master
 branch since the beginning of the project. ClojureScript is currently
 at revision 927. In Maven/Leiningen, this is represented as version
 0.0-927.


The latest release is 0.0-993.

Regards,
Stuart

On 8 March 2012 15:02, kovas boguta kovas.bog...@gmail.com wrote:

 It's great to see the steady activity on the clojurescript github page.

 However I'm not totally comfortable developing against the master branch.

 As it stands now, if I change development environments, or deploy on a
 new machine, the master branch may have moved.

 I could choose an arbitrary commit as my stable reference point,  and
 periodically make a judgement call about upgrading to a new arbitrary
 commit, but thats not easy for someone not involved in the internals.

 I gather this is still pre-1.0 , but it would still be nice to have
 some incremental version numbers to rationalize things.

 thanks for listening.

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

ClojureScript: browser REPL omitting namespace in generated JS

2012-03-02 Thread Stuart Campbell
Hello,

I'm encountering a problem where the browser REPL sometimes omits the
ClojureScript namespace in its generated JavaScript, e.g. (def x 42)
compiles to .x = 42 instead of foo.x = 42.

I've put together a minimal project, with steps to reproduce, on GitHub:
https://github.com/harto/cljs-eval-test

It looks to me like compiling a set of ClojureScript files (using
cljs.closure/build) causes some side-effect that prevents the problem. See
the GitHub README for details.

I'm on Mac OS X 10.5 with Java 1.6.0_26.

Regards,
Stuart

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Clojurescript One: (def fiv 5) compiles to .fiv = 5;\n ?

2012-03-02 Thread Stuart Campbell
Hi,

I've come across this too. Please see my message ClojureScript: browser
REPL omitting namespace in generated JS.

Regards,
Stuart

On 16 January 2012 08:14, Indy inder...@indy.io wrote:

 Having the same issue and the only way I've resolved it is by having both
 the server and the cljs-repl running in the same repl.

- run script/repl from the *shell* or launch it as an inferior-lisp
- (use '[one.sample.dev-server :only (run-server cljs-repl)])
- (run-server)
- (cljs-repl)



 --
 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: ClojureScript: browser REPL omitting namespace in generated JS

2012-03-02 Thread Stuart Campbell
Done! http://dev.clojure.org/jira/browse/CLJS-157

On 3 March 2012 01:15, David Nolen dnolen.li...@gmail.com wrote:

 Please open a ticket in JIRA. Thanks!

 On Fri, Mar 2, 2012 at 4:50 AM, Stuart Campbell stu...@harto.org wrote:

 Hello,

 I'm encountering a problem where the browser REPL sometimes omits the
 ClojureScript namespace in its generated JavaScript, e.g. (def x 42)
 compiles to .x = 42 instead of foo.x = 42.

 I've put together a minimal project, with steps to reproduce, on GitHub:
 https://github.com/harto/cljs-eval-test

 It looks to me like compiling a set of ClojureScript files (using
 cljs.closure/build) causes some side-effect that prevents the problem. See
 the GitHub README for details.

 I'm on Mac OS X 10.5 with Java 1.6.0_26.

 Regards,
 Stuart

  --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en


  --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Calling all Melbourne, Australia, Clojure users

2012-02-07 Thread Stuart Campbell
Hi James,

I'm currently only using Clojure for side projects, but I'm very keen to
catch up!

Stu

On 7 February 2012 22:23, James Sofra james.so...@gmail.com wrote:

 Hi all,

 I have been discussing recently possibly starting a Melbourne Clojure
 meetup.
 We have a possible location scouted out already but I really don't have a
 good idea of who may be using Clojure in Melbourne.

 I met a couple of people at the Conj last year so I am in contact with
 them and there is this list of people at
 http://clojure.meetup.com/members/au/melbourne/

 If I can find enough interested people I will go ahead and organise
 something more official but for the moment I am just trying to scout out to
 see if there is any interest.

 So please drop a note here, or you email me directly, to let me know if
 you are in Melbourne and interesting in catching up to chat about and hack
 Clojure.

 BTW, anyone had any experience with meetup.com, is it worth paying the
 dues to use?

 Cheers,
 James Sofra

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: How to get the vector?

2011-12-20 Thread Stuart Campbell
Those return values are native Java arrays.

user (def x (int-array '(1 2 3)))
#'user/x
user x
#int[] [I@12554d5

You can convert them to Clojure vectors using (vec):

user (vec x)
[1 2 3]

Regards,
Stuart

On 21 December 2011 11:59, Antonio Recio amdx6...@gmail.com wrote:

 When I try to get the position of two variables I get a bizzare code, but
 not the vector. How I can get the vector in the form of position iren [0 0
 0]?

 user= (.GetEventPosition iren)
 #int[] [I@62114b17

 user= (.GetPickPosition picker)
 #double[] [D@1aef4504

 --
 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: casting spels in clojure problem

2011-12-11 Thread Stuart Campbell
Hello,

You'll need to include the source of the spel-print function, i.e. the
(defn spel-print ...) part of the code.

The error means that you're calling spel-print with either too many or too
few arguments. But we can't tell unless you provide the code for that
function :)

Regards,
Stuart

On 12 December 2011 17:51, jayvandal s...@ida.net wrote:

 I am trying castin spels in clojure and I get this error. What does it
 mean??


 user= (spel-print describe-paths 'living-room game-map)
 java.lang.IllegalArgumentException: Wrong number of args (3) passed
 to: user$spel-print (NO_SOURCE_FILE:0)
 ==
 code is

   snoring loudly on the couch -)
  (west door garden)
  (upstairs stairway attic))
   'garden '((you are in a beautiful garden -
  there is a well in front of you -)
 (east door living-room))
   'attic '((you are in the attic of the
 wizards house - there is a giant
 welding torch in the corner -)
(downstairs stairway living-room
 ;; Object locations in a hash map
 (def object-locations (hash-map
   'whiskey-bottle 'living-room
   'bucket 'living-room
   'chain 'garden
   'frog 'garden))
 (def location 'living-room)
 (defn describe-location [location game-map]
  (first (location game-map)))
 ;; in clojure backquote mode, the ~ escapes the mode instead of the
 comma
 (defn describe-path [path]
  `(there is a ~(second path) going ~(first path) from here -))
 (defn describe-paths [location game-map]
  (apply concat (map describe-path (rest (get game-map location)
 (defn is-at? [obj loc obj-loc] (= (obj obj-loc) loc))

 --
 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: Problem with Korma and clj-soap

2011-11-26 Thread Stuart Campbell
Libraries probably shouldn't ship with a log4j configuration. The logging
configuration should be left entirely to the application IMO.

On 26 November 2011 19:37, Ivan Koblik ivankob...@gmail.com wrote:

 I'm pretty sure this is because of log4j.xml [1] in src directory of
 Korma. I think it's take from here [2]. If you take a look at it, it sets
 root debug level to debug.

 Try creating your own configuration and pointing to it with command line
 argument:
 -Dlog4j.configuration=your_log4j.xml

 What are the usual rule for the libraries? Is it OK to create log4j.xml in
 default location? If not how should it be done?

 [1] https://github.com/ibdknox/Korma/blob/master/src/log4j.xml
 [2] http://wiki.apache.org/logging-log4j/Log4jXmlFormat

 Cheers,
 Ivan.



 On 25 November 2011 16:43, Dennis Crenshaw crensha...@gmail.com wrote:

 So I'm trying to create a drop-in implementation of a SOAP webservice
 with Clojure. Naturally I look into libraries that accomplish the different
 bits. I need something to do SQL work with a relational db 
 (Kormahttps://github.com/ibdknox/korma,
 check!) and I need to present a SOAP interface 
 (clj-soaphttps://bitbucket.org/taka2ru/clj-soap,
 check!)

 Unfortunately I'm having tooling issues putting the two together.

 The first problem, I'm pretty sure, was simply a Clojure version
 mismatch: I and Korma were using Clojure 1.3 and alj-soap was using 1.2--
 so I checked out the clj-soap source and updated the libraries (Clojure to
 1.3, the Axis2 libraries to their latest) and ran the tests to make sure
 all was still working-- it was. So I pushed the 'new' clj-soap to clojars
 as [org.clojars.crenshawda/clj-soap 0.1.2] and tried again.

 Much to my chagrin I started getting seemingly endless byzantine DEBUG
 log traces spewed out into the repl when I try to start the soap server.

 If I comment Korma out of the project.clj, lein deps, and lein repl the
 same thing works like a charm. I also checked out each of Korma's
 dependencies individually and ran the same serve function and it worked
 (the log4j dep made it complin, but it still served just fine.)

 I'm not exactly sure WHAT is causing the collision between Korma and
 clj-soap, but it's damaging my calm at this point. :) I have a gut feeling
 that it's somehow logging related, but I don't know why it would cause
 clj-soap to flip out so badly.

 To recreate my scenario, start a new project and add these dependencies
 to the project.clj:

 [org.clojure/clojure 1.3.0] ;; if is isn't already there by default, I
 want to use 1.3
 [korma 0.3.0-apha4]
 [org.clojars.crenshawda/clj-soap 0.1.2] ;; use [clj-soap 0.1.1] if
 you want to see what I was talking about with the 1.2/1.3 mismatch

 Since Axis2 (what clj-soap is build upon) requires compiled classes to
 serve soap, you'll probably have to define a service in a clj file so 'lein
 repl' will pre-compile it for convenience sake.

 You can use this:

 (soap/defservice service.Hello
 (hello ^String [^String s]
 (str Hello Yourself)))

 So when you start your repl you should have classes/services/Hello.class
 in your classes/ directory. After you have to invoke clj-soap's serve
 function:

 (serve service.Hello)

 ... nd you should have a lovely logging wreck in your repl. I'd be
 happier if I could at least figure out WHY it happens when I put Korma in
 my dependencies. Sorry for the wall of text, but I figure too much info is
 usually better than not enough. :)

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en


  --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en


-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: ANN: j18n 1.0.0 – taming ResourceBundles

2011-11-24 Thread Stuart Campbell
Hi Meikel,

Thanks for this library.

I noticed that each bundle's keyset is cached via memoization. I believe
this prevents adding more bundle properties at runtime (e.g. during
interactive development).

Is there a way to reset a resource bundle? Is this something that you
might consider in a future release?

Regards,
Stuart

On 5 September 2011 05:32, Meikel Brandmeyer m...@kotka.de wrote:

 Dear international Clojurians,

 I'd like to announce j18n. A small wrapper around ResourceBundles to
 provide easy internationalization of Clojure applications. j18n will power
 the i18n features of the upcoming seesaw release.

 The interface consits (at the moment) of a single function: resource.
 (resource ::my-message) will look up the key my-message in the
 ResourceBundle of the current namespace.

 Further enhancements like MessageFormat or specifying resources in clojure
 syntax are planned for the next releases.

 Code: http://bitbucket.org/kotarak/j18n
 Library on clojars: [j18n 1.0.0]

 Sincerely
 Meikel

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en

-- 
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: j18n 1.0.0 – taming ResourceBundles

2011-11-24 Thread Stuart Campbell
Ah, I see. Thanks.

On 24 November 2011 23:06, Meikel Brandmeyer (kotarak) m...@kotka.de wrote:

 Hi,

 the ResourceBundles themselves are memoized by the Java runtime. You can
 reset this cache with ResourceBundle/clearCache. Then the underlying
 ResourceBundle will be retrieved again on the next access. Then the
 memoization does not trigger. But the memoization itself is probably
 premature optimisation and should be removed.


 Sincerely
 Meikel

  --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en


-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Where can I inqure about bugs?

2011-11-20 Thread Stuart Campbell
I think you might be using comparator incorrectly. It appears to expect a
function that returns a true/false value:

user (source comparator)
(defn comparator
  Returns an implementation of java.util.Comparator based upon pred.
  {:added 1.0}
  [pred]
(fn [x y]
  (cond (pred x y) -1 (pred y x) 1 :else 0)))

So something like this might work:

user (def string-comparator
(comparator (fn [a b]
  (neg? (.compareTo a b)
#'user/string-comparator
user (string-comparator a b)
-1
user (string-comparator b a)
1
user (string-comparator a a)
0

Doesn't seem very useful though.

Regards,
Stuart

On 20 November 2011 14:28, Randy Pensinger rspensin...@gmail.com wrote:

 I am having a lot of trouble finding a place to mention a possible
 clojure bug. Is this it?

 I am trying to write a custom comparator, but the comparator never
 seems to work. I simplified the comparator below.

 user= (def stringComparator
  (comparator (fn [a b]
(do
  (println (str comparing ' a ' to ' b '))
  (.compareTo a b)
 #'user/stringComparator
 user= (.compare stringComparator b a)
 comparing 'b' to 'a'
 -1
 user= (compare b a)
 1
 user= (clojure-version )
 1.3.0


 Am I doing something wrong?

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

JavaScript `debugger' statement

2011-11-10 Thread Stuart Campbell
I'm trying to enter the Firebug debugger when an exception is caught:

(try
  ; ...
  (catch js/Error e
js/debugger))

This doesn't work, because js/debugger compiles to debugger$; per
cljs.compiler/munge.

Any ideas how I can get around this?

Thanks,
Stu

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: ClojureScript auto-recompile option

2011-09-18 Thread Stuart Campbell
Cool - wasn't aware of that.

On 16 September 2011 15:07, Chris Granger ibdk...@gmail.com wrote:

 FWIW there's also cljs-watch:

 http://github.com/ibdknox/cljs-watch

 On Sep 15, 6:35 am, Stuart Campbell stu...@harto.org wrote:
  Hello,
 
  I've written a small hack for the ClojureScript compiler that is useful
 for
  working with static HTML projects. When invoked with the :watch option,
 the
  cljsc program watches a source directory and recompiles sources whenever
 a
  change is detected.
 
  https://github.com/harto/clojurescript/commit/f5bb720523f7121ab5fc8ad...
 
  Usage: cljsc src '{:watch true}' foo.js
 
  The change depends on the jpathwatch library, which should be downloaded
 (http://sourceforge.net/projects/jpathwatch/files/jpathwatch-0-94.zip/...)
  into the clojurescript/lib directory.
 
  Regards,
  Stuart

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

ClojureScript auto-recompile option

2011-09-15 Thread Stuart Campbell
Hello,

I've written a small hack for the ClojureScript compiler that is useful for
working with static HTML projects. When invoked with the :watch option, the
cljsc program watches a source directory and recompiles sources whenever a
change is detected.

https://github.com/harto/clojurescript/commit/f5bb720523f7121ab5fc8add014fd64846dc8e19

Usage: cljsc src '{:watch true}' foo.js

The change depends on the jpathwatch library, which should be downloaded (
http://sourceforge.net/projects/jpathwatch/files/jpathwatch-0-94.zip/download)
into the clojurescript/lib directory.

Regards,
Stuart

-- 
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: run clj file get user/counter-app error?

2011-09-14 Thread Stuart Campbell
That line is the string representation of a Var. It isn't an error - it's
just the return value of the expression you entered.

(load-file) evaluates all expressions in a file and returns the value of the
last one. In your case, it's the value of (defn counter-app [] ...), which
defines the counter-app function.

You can invoke the defined function by typing:
  (counter-app)

Regards,
Stuart

On 14 September 2011 15:42, jayvandal s...@ida.net wrote:

 I am running a  swing tutorial clojure program file and when I run the
 result is
 ++
 user= (load-file c:/clojure-1.2.1/counter-app.clj)
 #'user/counter-app
 user=
 ++

 What does this line mean?
 #'user/counter-app

 The name of my file is counter-app.clj
 program listing on win Vista IS
 --
 (import '(javax.swing JLabel JButton JPanel JFrame))


 (defn counter-app []
  (let [counter (atom 0)
label (JLabel. Counter: 0)
button (doto (JButton. Add 1)
 (on-action evnt  ;; evnt is not used
   (.setText label
  (str Counter:  (swap! counter inc)
panel (doto (JPanel.)
(.setOpaque true)
(.add label)
(.add button))]
(doto (JFrame. Counter App)
  (.setContentPane panel)
  (.setSize 300 100)
  (.setVisible 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


-- 
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: N00b alert! - A question on immutable/mutable data structures...

2011-09-14 Thread Stuart Campbell
Hi Trevor,

I hope I've understood your problem correctly.

You can modify nested structures using e.g. update-in:

  (let [k user1 v 1234]
(swap! user-queues update-in k conj v))

That's assuming that a user queue already exists in the map. If it doesn't,
you could do something like:

  (let [k user1 v 1234]
(swap! user-queues #(assoc % k (conj (get % k
clojure.lang.PersistentQueue/EMPTY) v

Regards,
Stuart

On 14 September 2011 11:10, Trevor tcr1...@gmail.com wrote:

 Thanks for the quick responses.

 I'll try to answer Andy's question: How do you know, in advance, that
 it doesn't need to handle such concurrent changes? ... and at the
 same time I will try to provide this example to Stuart, hoping I can
 see how using a map inside an atom might work:

 Let's say my users log into a web page and each user has a queue that
 does stuff for them. Since the users id is unique and each user can
 only be logged in from one session, when I use the user id as a key
 within a hash-map then I know *well-enough* there will not be any
 concurrent changes to that key value pair, particularly since enqueing
 means each change is actually an just addition to the stack. -- So I
 am picking queue's to make a point... -- Queue's are chosen over lists
 as they are both constant time and fast. Being atomic is great, but
 wouldn't making a copy of a queue and re-assembling it defeat the
 purpose of using it?

 So let's try this:

  (def user-queues* (atom (hash-map)))
 #'project/user-queues*

  (swap! user-queues* assoc user1 clojure.lang.PersistentQueue/EMPTY)
 {user1 #PersistentQueue clojure.lang.PersistentQueue@0}

  (@user-queues* user1)
 #PersistentQueue clojure.lang.PersistentQueue@0

 I would like to add an item to the users queue, but it seems when
 using an atom I can only swap in and out the value as opposed to
 modifying the value in-place.


 So let's start with just the basic atom'd queue:

  (def q (atom clojure.lang.PersistentQueue/EMPTY))
 #'project/q

  (swap! q conj (seconds))
 #PersistentQueue clojure.lang.PersistentQueue@d3232253

  (apply list (swap! q conj (seconds)))
 (1315961557 1315961570)

 awesome.

 Now I want to store each users queue in the user-queues* hash-map. How
 would I do that while maintaining a real queue? My initial attempts
 always lead to reading the full queue into a list, then to conj and
 item on that list, then I have to remake a queue to then be stored
 back into the map via swapso it's at that point I might as well
 not be using a queue - right?

 Certainly hash-maps with queue's would be a reasonable idea - right?.

 Thanks.














 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en


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

ClojureScript keywords

2011-09-02 Thread Stuart Campbell
Hi,

When I compile the following to JavaScript, I expected it to output
foo in the console log:

  (.log js/console (name :foo))

However, it outputs ï· 'foo.

Is that right?

Regards,
Stuart

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: ClojureScript keywords

2011-09-02 Thread Stuart Campbell
Please excuse the self-reply;

Looking at the compiled version of (keyword?), I can see a line that appears
to compare the first character of the keyword string against a
multi-character string constant:

cljs.core.keyword_QMARK_ = (function keyword_QMARK_(x){
var and__3574__auto2211 = goog.isString.call(null,x);

if(cljs.core.truth_(and__3574__auto2211))
{*return cljs.core._EQ_.call(null,x.charAt(0),ï· );*
} else
{return and__3574__auto2211;
}
});

Stepping into cljs.core._EQ_ in the debugger shows that the first argument
is one character long, but the second is 3 characters long.

Is this just some encoding issue in my setup? I'm on Mac OS X 10.5, and I
got the same result in FF 6 and Chrome 13.

On 2 September 2011 17:41, Stuart Campbell 
stuart.william.campb...@gmail.com wrote:
 Hi,

 When I compile the following to JavaScript, I expected it to output
 foo in the console log:

  (.log js/console (name :foo))

 However, it outputs ï· 'foo.

 Is that right?

 Regards,
 Stuart

 --
 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: ClojureScript keywords

2011-09-02 Thread Stuart Campbell
Thanks David.

I added meta charset=UTF-8 to my HTML document (this is just a static
test project) and it fixed the problem.

Regards,
Stuart

On 2 September 2011 18:36, David Powell d...@djpowell.net wrote:

 Clojurescript represents symbols and keywords as strings with a one
 character unicode prefix (as an implementation detail).

 But, by default it outputs javascript as utf-8, and unless you are serving
 javascript from a server and have setup the headers accordingly, this will
 be misinterpreted by the browser as 3x iso-8859-1 characters.

 However, if you run with the advanced compiler, it will escape everything
 to ascii so you won't get these encoding issues.

 There is a jira issue to make the unoptimised path do the same encoding as
 the advanced compiler, but this isn't fixed yet.

 --
 Dave
 On 2 Sep 2011 09:28, Stuart Campbell stuart.william.campb...@gmail.com
 wrote:
  Please excuse the self-reply;
 
  Looking at the compiled version of (keyword?), I can see a line that
 appears
  to compare the first character of the keyword string against a
  multi-character string constant:
 
  cljs.core.keyword_QMARK_ = (function keyword_QMARK_(x){
  var and__3574__auto2211 = goog.isString.call(null,x);
 
  if(cljs.core.truth_(and__3574__auto2211))
  {*return cljs.core._EQ_.call(null,x.charAt(0),ï· );*
  } else
  {return and__3574__auto2211;
  }
  });
 
  Stepping into cljs.core._EQ_ in the debugger shows that the first
 argument
  is one character long, but the second is 3 characters long.
 
  Is this just some encoding issue in my setup? I'm on Mac OS X 10.5, and I
  got the same result in FF 6 and Chrome 13.
 
  On 2 September 2011 17:41, Stuart Campbell 
  stuart.william.campb...@gmail.com wrote:
  Hi,
 
  When I compile the following to JavaScript, I expected it to output
  foo in the console log:
 
  (.log js/console (name :foo))
 
  However, it outputs ï· 'foo.
 
  Is that right?
 
  Regards,
  Stuart
 
  --
  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 options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Another ClojureScript app in the wild

2011-08-21 Thread Stuart Campbell
Ha! I was considering doing this exact same thing.

I'm working on a vanilla js version that I was considering porting to cljs.
It might be interesting to compare implementations:
https://github.com/harto/pacman

Thanks for sharing,
Stuart

On 18 August 2011 08:00, Matthew Gilliard matthew.gilli...@gmail.comwrote:

 I've been playing around writing a fun little ClojureScript project -
 it's a bit different, so I thought you might like to see it:

  http://mjg123.github.com/pacman/pacman.html

 As I was feeling my way quite blindly through ClojureScript and
 gClosure I have let the code get into a bit of a mess and I don't
 think I'll really work on it much more.  I have learned an awful lot
 though (which was the main objective) - my main lessons are:

  - ClojureScript is awesome.  The performance and stability of it are
 really astounding.  Really great work guys.
  - Debugging a ClojureScript app is hard.  I never figured out how to
 get js/console to work.  My best solution was to compile  run very
 often, so that errors were caught quickly.  Better yet would have been
 thorough testing ;)

  - it *is* possible to write a game with no mutable state (well, I use
 an atom to hold the most-recently-pressed key, but apart from that...
 The state-of-the-world datastructure is immutable)

  - Some functions missing from ClojureScript which surprised me: range, int
  - Some functions behave differently between Clojure and ClojureScript
 (due to underlying platform differences): mod

  - Testing is very important.  The gClosure jsunit stuff looks nice
 but I'd love a midje-like API for it.

 Browser-compatibility:  Chrome - OK, Firefox 6 - sometimes crashes
 with too much recursion, IE/Safari - Forget it.

 Happy to answer any questions, otherwise I'll be over here hacking
 some Clojure   :)

  Matthew

 --
 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: help with some code

2011-07-12 Thread Stuart Campbell
If you use vectors instead of lists, you can avoid quoting altogether:

user (def alist [1 (fn [x y] (+ x y))])
#'user/alist
user (apply (second alist) [1 3])
4

Regards,
Stuart

On 13 July 2011 08:09, Joop Kiefte iko...@gmail.com wrote:

 Didn't try, but shoudn't (def alist `(1 ~(fn [x y] (+ x y be better?
 Then you don't need the eval :)


 2011/7/12 Benny Tsai benny.t...@gmail.com

 alist is missing parens around the fn, so it's really a list of 4 elements
 like so:


   (1, fn, [x y], (+ x y))

 So (second alist) returns just the symbol 'fn.  And when you apply a
 Symbol to a list, the result is the last item in the list (not sure why).

 To do what you want, alist should be defined like this:

   (def alist '(1 (fn [x y] (+ x y

 Also, it seems that the definition of the function needs to be eval'ed
 first to become an apply-able function.  The following returns 4 in my REPL:

   (apply (eval (second alist)) '(1 3))

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en


  --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en


-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Wisdom sought for functional iterative processing

2011-06-14 Thread Stuart Campbell
On 14 June 2011 12:37, Matthew Phillips mattp...@gmail.com wrote:

 The only way I can think of to write it in Clojure is:

 (reduce
  (fn [items op]
(let [items1 (if (:delete op) (drop-index (:delete op) items)
 items)]
  (if (:insert op) (cons (:insert op) items1) items1)))
  items ops)

 i.e. I'm using a cascade of conditional let's. This isn't _too_ bad in
 this case, but you can image how unreadable this could get.


How about something like this (borrowing from Mark's loop/recur suggestion
above):

(defn maybe-delete [items op]
  (if-let [index (:delete op)]
(drop-index index items)
items))

(defn maybe-insert [items op]
  (if-let [new-item (:insert op)]
(cons new-item items)
items))

(loop [items items ops ops]
  (if-not ops
items
(let [op (first op)]
  (recur (- items
 (maybe-delete op)
 (maybe-insert op))
 (next ops)

Looks more verbose on the surface, but I'm sure you could abstract away some
common bits of maybe-delete and maybe-insert using a macro.

Regards,
Stuart

-- 
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: using reduce instead of loop recur

2011-05-31 Thread Stuart Campbell
For this particular case, you could also use regexps:

user (require '[clojure.string :as s])
nil
user (s/replace   bb cc # +  )
 bb cc

Regards,
Stuart

On 31 May 2011 08:15, iz bash killernemesisbl...@gmail.com wrote:

 so clojures like my first programming language. most of the time
 now ,i use map /reduce/.. with lazy sequences  but sometimes i just
 cant seem to find a solution other than using loop-recur. then i read
 somewhere almost all loop recur situations can be translated into
 reduce. so ive posted a function below...how'd you implement it using
 only higher order functions?


 (defn rem-dup [stri]
(loop [[x y  z] (seq stri) ,bui []]
   (cond (nil? x)   bui
 (= x y \space) (recur (cons y z) bui)
 :else  (recur (cons y z) (conj bui x)


 (rem-dup   bb cc)  =[\a \a \a \a \space \b
 \b \space \c \c]

 also itd be great if you guys could give some pointers on using higher
 order functions and lazy sequences in place of a loop recur.

 Thanks!!
 and btw clojures totally awesome :)

 --
 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: Grabbing Rotten Tomatoes movie ratings in clojure

2011-01-16 Thread Stuart Campbell
Hi,

Have you used Enlive[1]? It's a nice tool for HTML scraping and templating -
it might be more robust than your regexp-based solution. It takes a bit of
learning, though.

Regards,
Stuart

[1] https://github.com/cgrand/enlive

On 16 January 2011 05:57, justinhj justi...@gmail.com wrote:

 Sharing my first useful Clojure program. Feedback welcome.

 http://bit.ly/clojure-rotten-tomatoes



  --
 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.comclojure%2bunsubscr...@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: Clojure Quizzes?

2011-01-12 Thread Stuart Campbell
On 12 January 2011 14:07, Robert McIntyre r...@mit.edu wrote:

 You can use the latest version of clojure if you include it as a
 dependency in your submission, so even though they say they only
 support clojure1.0 they really support all of them.


Are other 3rd-party libs allowed, too?

Cheers,
Stuart

-- 
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: Ring startup processing?

2010-11-28 Thread Stuart Campbell
On 28 November 2010 16:51, lprefonta...@softaddicts.ca wrote:

 We use a dedicated servlet for every web app to make sure all prerequisites
 are met. Since it's loaded first, we can find problems by looking at a
 single
 piece of the log files just after the container messages announcing that
 it's loading the app.


There's also ServletContextListener (
http://download.oracle.com/javaee/5/api/javax/servlet/ServletContextListener.html),
which is configured in web.xml too.

Regards,
Stuart

-- 
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: Ring startup processing?

2010-11-28 Thread Stuart Campbell
Ah, OK. We just use Tomcat 6 for everything here :)

On 29 November 2010 12:16, lprefonta...@softaddicts.ca wrote:

 Yep but some app servers have bugs with this interface (GlassFish 2,
 jetty 6.1, tomcat 5.5, ...) and the interface is not called appropriately.
 There are less problems reported with the load-on-startup flag.

 Of course if you know your app server's behavior regarding this feature,
 it might not be a problem.

 I got caught once so I prefer a safer mechanism, we are not always using
 the same app server here. Might work in dev and not in prod... oups...

 Luc P.

 Stuart Campbell stu...@harto.org wrote ..
  On 28 November 2010 16:51, lprefonta...@softaddicts.ca wrote:
 
   We use a dedicated servlet for every web app to make sure all
 prerequisites
   are met. Since it's loaded first, we can find problems by looking at a
   single
   piece of the log files just after the container messages announcing
 that
   it's loading the app.
  
 
  There's also ServletContextListener (
 

 http://download.oracle.com/javaee/5/api/javax/servlet/ServletContextListener.html
 ),
  which is configured in web.xml too.
 
  Regards,
  Stuart
 
  --
  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.comclojure%2bunsubscr...@googlegroups.com
  For more options, visit this group at
  http://groups.google.com/group/clojure?hl=en
 Luc P.

 
 The rabid Muppet

 --
 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.comclojure%2bunsubscr...@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: every-nth

2010-11-24 Thread Stuart Campbell
On 25 November 2010 16:56, Ken Wesson kwess...@gmail.com wrote:

 Eh. This is weird. It seems that (partition n coll) drops the last
 part of coll if it's not a multiple of n in size; e.g. (partition 3 [1
 2 3 4 5]) yields ((1 2 3)) and not ((1 2 3) (4 5)). (partition n n []
 coll) does do that though.


See also partition-all:

 user= (partition-all 3 [1 2 3 4 5])
((1 2 3) (4 5))

Regards,
Stuart

-- 
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: ClojureQL 1.0.0 finally released as public beta

2010-11-18 Thread Stuart Campbell
On 19 November 2010 06:10, LauJensen lau.jen...@bestinclass.dk wrote:

 Hi gents,

 For those of you who have followed the development
 of ClojureQL over the past 2.5 years you'll be excited
 to know that ClojureQL is as of today being released
 as 1.0.0 beta1.

 That means that the significant primitives from Relational
 Algebra are all in place and functional. The documentation
 is there and I've even made a screencast in order to get
 you guys started.

 Personally Im excited about this version because it really
 does change the way you work with a database. Queries
 are incredibly composable!

 For more information, please checkout this blogpost +
 screencast:
 http://bestinclass.dk/index.clj/2010/11/clojureql--1.0.0-now-in-beta.html

 Best regards,
 Lau


Looks great! Can't wait to try it out!

Cheers,
Stuart

-- 
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: fastest way to remove nils

2010-11-16 Thread Stuart Campbell
On 17 November 2010 12:37, lprefonta...@softaddicts.ca wrote:

 user= (time (filter identity [ nil 1 2 nil 4]))
 Elapsed time: 0.053219 msecs
 (1 2 4)

 user= (time (remove nil? [ nil 1 2 nil 4]))
 Elapsed time: 0.065092 msecs
 (1 2 4)

 Choose the flavor your prefer...

 Luc P.


Those aren't exactly equivalent:

user (filter identity [1 2 false 3 nil 4])
(1 2 3 4)
user (remove nil? [1 2 false 3 nil 4])
(1 2 false 3 4)

Regards,
Stuart

-- 
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: max-key taking a list rather than different number of args

2010-11-14 Thread Stuart Campbell
On 15 November 2010 14:17, Tom Hall thattommyh...@gmail.com wrote:

 Hi,

 I think a better usage for max-key would be
 (max-key f someseq)
 rather than passing the values as args.

 I used
 (defn max-key-seq [f someseq]
  (apply max-key (into [f] someseq)))
 to make it do what I wanted

 Is there a better way?


You should be able to use (apply max-key f someseq); apply takes a variable
number of args, and only the last is expanded.

Regards,
Stuart

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: macro debugger

2010-11-09 Thread Stuart Campbell
On 10 November 2010 02:50, Moritz Ulrich ulrich.mor...@googlemail.comwrote:

 I don't think there's a full-featured macro debugger for clojure, but
 clojure has two simple functions called macroexpand and macroexpand-1:

 user (doc macroexpand-1 )
 -
 clojure.core/macroexpand-1
 ([form])
   If form represents a macro form, returns its expansion,
   else returns form.


There are some handy SLIME key bindings that can be useful when exploring a
source file:

   - C-c RET - (macroexpand-1) form at point
   - C-c M-m - (macroexpand) form at point

Regards,
Stuart

-- 
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: *warn-on-reflection* broken in 1.2?

2010-11-03 Thread Stuart Campbell
I get the expected result in my REPL via SLIME:

user *clojure-version*
{:major 1, :minor 2, :incremental 0, :qualifier }
user (set! *warn-on-reflection* true)
true
user (defn foo [s] (.charAt s 1))
Reflection warning, NO_SOURCE_FILE:1 - call to charAt can't be resolved.
#'user/foo

Regards,
Stuart

On 4 November 2010 15:11, Ken Wesson kwess...@gmail.com wrote:

 The website has this example:

 (set! *warn-on-reflection* true)
 - true
 (defn foo [s] (.charAt s 1))
 - Reflection warning, line: 2 - call to charAt can't be resolved.
 - #user/foo

 When I try this in a Clojure 1.2 REPL generated by Enclojure 1.4.0/NB
 6.9.1 I don't see the reflection warning in any of Repl, *err*, and
 *out*.

 Is this actually broken in Clojure 1.2 or is it Enclojure screwing up?

 --
 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.comclojure%2bunsubscr...@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: Fastest way to generate comma-separated list

2010-10-27 Thread Stuart Campbell
On 28 October 2010 13:22, andrei andrei.zhabin...@gmail.com wrote:


 I was seeking `interpose` function, thanks. But it still doesn't work
 for strings - they are not wrapped by \\. E.g.

 (apply str (interpose ,  (list 1 2 3 4 5)))  == 1, 2, 3, 4, 5

 and

 (apply str (interpose ,  (list 1 2 3 4 5))) == 1, 2, 3,
 4, 5

 The problem is that applying `str` to strings just concatenates them
 and doesn't include inverted commas. It's the same issue that applies
 to `print` and `pr` functions - first just prints, and the second
 prints in the form that can be read by reader. Is there an equivalent
 of `pr` that returns string as is?

 Of course, I can make such trick:

 (defn pr-to-str [o]
  (let [sw (StringWriter.)]
(binding [*out* sw]
  (pr o))
(str sw)))


 But aren't there such built-in function?


Are you looking for pr-str?

user (pr-str foo)
\foo\

Regards,
Stuart

-- 
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: challenge with vectors

2010-10-26 Thread Stuart Campbell
On 27 October 2010 12:54, Glen Rubin rubing...@gmail.com wrote:

 I have a sequence like this:

 [ [a b] [a b] [a b] [a b] ]

 where a and b are numbers.  I would like to return the vector and its
 index for which b is the least in this collection.

 For example, if my data is as follows

 [ [22 5] [56 8] [99 3] [43 76] ]

 I would like to return 3rd vector in the collection where b is lowest
 [99 3], but I also would like to know that it is the 3rd vector, so
 maybe something like:

 [99 3 3]

 any suggestions???

 thx a mil!!


Hi Glen,

Here's a solution:

user (- [[22 5] [56 8] [99 3] [43 76]]
   (map-indexed #(conj %2 (inc %1)))
   (sort-by second)
   (first))
[99 3 3]

Regards,
Stuart

-- 
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: SQLAlchemy in Clojure?

2010-10-19 Thread Stuart Campbell
On 19 October 2010 02:18, Sean Devlin francoisdev...@gmail.com wrote:

 Okay, I just finished a Python app for work.  Using SQLAlchemy was a
 joy.  Has anyone ported this yet?


I've never used SQLAlchemy. How does it compare with e.g. Django's ORM?

Regards,
Stuart

-- 
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: sql utilities

2010-10-14 Thread Stuart Campbell
Thanks Kyle. Looks useful!

On 15 October 2010 09:25, Saul Hazledine shaz...@gmail.com wrote:

 On Oct 14, 9:16 pm, Kyle R. Burton kyle.bur...@gmail.com wrote:
  I've written some sql helper functions that will do things like list
  the objects in the database and describe a table.  I've found these
  handy when doing interactive development as I don't have to jump over
  to another app to see what the make up of tables are.  I've also used
  it in some scenarios when generating code from the database schema.
 

 Very cool. If you have no joy getting it into contrib you can have
 write access to clj-sql if you want it:

 http://github.com/alienscience/clj-sql

 Otherwise, as Shanatu says, a github project of your own would be
 welcome and is sure to be used by others.

 Saul

 --
 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.comclojure%2bunsubscr...@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: Idiomatic Way to Build String or Simply Use StringBuilder

2010-09-29 Thread Stuart Campbell
On 30 September 2010 12:48, HiHeelHottie hiheelhot...@gmail.com wrote:


 Is there an idiomatic way to build up a string over different lines of
 code?  Or, should one simply use StringBuilder.


I would just use (str) - it uses a StringBuilder when given more than one
argument:

user (source str)
(defn str
  With no args, returns the empty string. With one arg x, returns
  x.toString().  (str nil) returns the empty string. With more than
  one arg, returns the concatenation of the str values of the args.
  {:tag String
   :added 1.0}
  ([] )
  ([^Object x]
   (if (nil? x)  (. x (toString
  ([x  ys]
 ((fn [^StringBuilder sb more]
  (if more
(recur (. sb  (append (str (first more (next more))
(str sb)))
  (new StringBuilder ^String (str x)) ys)))

Regards,
Stuart

-- 
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: Using macro to generate part of fn

2010-09-18 Thread Stuart Campbell

 Macroexpansion is part of the expression evaluation mechanism. In your
 example


(defn foo
  ([bar] (foo bar :default))
  (special-fn-spec))

 the whole defn-form is macroexpanded first, yielding something like

(def foo (fn ([bar] (foo bar :default)) (special-fn-spec))

 Then the fn form is evaluated, yielding a compiled function. At that point,
 the compiler checks its syntax, and finds two bodies, one well-formed (arg
 list followed by expression) and a second ill-formed one (just an
 expression). The function bodies are *not* macroexpanded because they are
 not evaluated either. The only other subform of your example that is ever
 macroexpanded is (foo bar :default).

 There are a couple of ways to generate function bodies programmatically,
 but it is difficult to give useful advice without knowing what you need this
 for.

 Konrad.


Thanks Konrad, that makes sense.

I suppose I was a bit confused about when macroexpansion occurs.

My real use-case involves wrapping a Java object, which has a number of
methods with varying numbers of optionally nullable parameters. E.g.

DatabaseMetaData#getExportedKeys(String, String, String)

In this method, the first two parameters may be null. So, my fn looks like
this:

(defn exported-keys
  ([table]
 (exported-keys nil table))
  ([schema table]
 (exported-keys nil schema table))
  ([catalog schema table]
 (fetch-metadata-rs .getExportedKeys catalog schema table)))

I was trying to automatically generate the final function body since it
duplicates the parameter list, and I expect to have a lot of these kinds of
methods. Although, it's not too bad as it is (I've already pulled some
common bits into fetch-metadata-rs).

Not sure if that makes sense or not... ?

Cheers,
Stuart

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

Using macro to generate part of fn

2010-09-17 Thread Stuart Campbell
Hello,

In the following contrived example, I get an error when macroexpanding (defn
foo ...):

(defmacro special-fn-spec []
  '([bar baz] (println bar baz)))

(defn foo
  ([bar] (foo bar :default))
  (special-fn-spec))

The error is:
Parameter declaration special-fn-spec should be a vector
  [Thrown class java.lang.IllegalArgumentException]

I'm a bit confused about the order in which things are happening here. My
assumption was that (special-fn-spec) would be evaluated before the fn
definition. Is there a way to do something like this?

Thanks
Stuart

-- 
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: NullPointerExecption after Java class import

2010-08-31 Thread Stuart Campbell
You could call (import) directly after you've initialised the Gate class:

(gate-init foo)
(import gate.Factory)
; use Factory class as required

Cheers,
Stuart

On 31 August 2010 01:01, zm zygiman...@medelis.lt wrote:


 Initialization exception can be avoided if Factory class is
 initialized indirectly:

 (let [factory (.newInstance (Class/forName gate.Factory))] ...)

 The problem is that Factory can only be initialized (its static
 fields) after Gate.init was called. But clojure reader (or what it is)
 initializes all the classes mentioned in the namespace. Thus Factory
 gets created before cojure function calls which do Gate/init.

 Is this workaround ok? Or are there better ways to solve it?

 On Aug 30, 2:39 pm, zm zygiman...@medelis.lt wrote:
  Indeed if exception is thrown in static initializer block then clojure
  import throws exception as well.
 
  The following class will cause this:
 
  package aaa;
  public class Test {
  static{
  Object o = null;
  o.toString();
  }
 
  }
 
  Then in clojure:
 
  (ns x (:import (aaa Test))
 
  Results in:
 
  Exception in thread main java.lang.ExceptionInInitializerError
  (core.clj:1)
 
  Why does this happen in clojure? If you do the same in java, import
  aaa.Test, then nothing happens. NLP will be thrown when you actualy
  try to initialize the class.
 
  On Aug 30, 6:12 am, Stuart Campbell stu...@harto.org wrote:
 
 
 
   Hello,
 
   I don't know this library specifically, but the NPE is probably
 occurring in
   a static initialisation block. I believe static initialisation occurs
 when
   the class is first loaded.
 
   Regards,
   Stuart
 
   On 30 August 2010 06:42, zm zygiman...@medelis.lt wrote:
 
I am using GATE java libs in my clojure code and behaviour of the
application changes after Java class import. I don't even have to
initialize it.
 
This runs fine (a bit shorter version than it is):
 
 (ns gate
 (:import
(gate Gate)
(java.io File)))
 
(defn gate-init
 [gate-home]
 (Gate/setGateHome (File. gate-home))
 (Gate/init)))
 
Now if I import gate.Factory class, like this (gate Gate Factory), I
get the exception:
 
Caused by: java.lang.NullPointerException
   at gate.Factory.createResource(Factory.java:154)
 
How can import of a class cause this?
 
--
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.comclojure%2bunsubscr...@googlegroups.com
 clojure%2bunsubscr...@googlegroups.comclojure%252bunsubscr...@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.comclojure%2bunsubscr...@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: NullPointerExecption after Java class import

2010-08-29 Thread Stuart Campbell
Hello,

I don't know this library specifically, but the NPE is probably occurring in
a static initialisation block. I believe static initialisation occurs when
the class is first loaded.

Regards,
Stuart

On 30 August 2010 06:42, zm zygiman...@medelis.lt wrote:


 I am using GATE java libs in my clojure code and behaviour of the
 application changes after Java class import. I don't even have to
 initialize it.

 This runs fine (a bit shorter version than it is):

  (ns gate
  (:import
 (gate Gate)
 (java.io File)))

 (defn gate-init
  [gate-home]
  (Gate/setGateHome (File. gate-home))
  (Gate/init)))

 Now if I import gate.Factory class, like this (gate Gate Factory), I
 get the exception:

 Caused by: java.lang.NullPointerException
at gate.Factory.createResource(Factory.java:154)

 How can import of a class cause this?

 --
 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.comclojure%2bunsubscr...@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: Unexpected FileNotFoundException

2010-08-22 Thread Stuart Campbell
On 21 August 2010 08:39, Tim McIver tmci...@verizon.net wrote:

 Can someone help clear up my confusion?

 My problem started while working through Stuart Halloway's book (p.
 52) where he builds up his 'index-filter' function.  This function
 uses an 'indexed' function which he states is in clojure-contrib. The
 API docs found on clujure-contrib's github page shows that 'indexed'
 is found in 'clojure.contrib.seq.'  Stuart Campbell's response (below)
 gives a link to a different API doc which does not contain a
 'clojure.contrib.seq' package.  I found the 'indexed' function in the
 seq-utils package and so it looked like it was moved at some point.
 So my question is: is the documentation on the github page wrong or am
 I confused about the various versions and/or branches of clojure-
 contrib?


I think the documentation you're referring to (
http://richhickey.github.com/clojure-contrib/) reflects the master branch
(i.e. contrib 1.2). The documentation I linked to shows the 1.1 docs.

It seems that c.c.seq was added post-1.1.

You can switch between branches using the links at the top-left corner of
the documentation page.

Hope that helps,

Regards,
Stuart

-- 
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: Unexpected FileNotFoundException

2010-08-19 Thread Stuart Campbell
On 20 August 2010 11:52, Tim McIver tmci...@verizon.net wrote:

 Hello everyone.  Clojure noob here.  I apologize in advance for what
 may turn out to be a dumb question.  When trying to (use
 '[clojure.contrib.seq]) I get the following error:

 java.io.FileNotFoundException: Could not locate clojure/contrib/
 seq__init.class or clojure/contrib/seq.clj on classpath:
 (NO_SOURCE_FILE:1)

 which is strange because others succeed, like (use
 '[clojure.contrib.str-utils]).  I'm using Clojure 1.1.0 and Clojure-
 contrib 1.1.0, and clojure-contrib.jar is on the classpath.  Any help
 is appreciated.


According to the c.c 1.1
docshttp://richhickey.github.com/clojure-contrib/branch-1.1.x/index.html,
there is no clojure.contrib.seq - perhaps you meant
clojure.contrib.seq-utils?

-- 
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: Log SQL in clojure.contrib.sql

2010-07-29 Thread Stuart Campbell
On 29 July 2010 15:17, ngocdaothanh ngocdaoth...@gmail.com wrote:

 I found:
 http://code.google.com/p/log4jdbc/


That looks useful - thanks!

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: any downside to putting everything into CLASSPATH?

2010-05-23 Thread Stuart Campbell

 JVM newbie question here. Aside from the clojure  clojure-contrib jars, is
 there any downside to automatically setting up my CLASSPATH so that all jars
 on my box are available - even if I might only be using 1 or 2 for the code
 I'm working on at the moment?


The problem with such a scheme is inclusion of multiple versions of the same
library. This can result in obscure 'unresolved compilation' errors cropping
up when you try to use a method or class that doesn't exist in whichever
library the JVM happened to choose.

Does the jvm do any expensive initialisation for each jar? Or does it not
 make a difference until I explicitly import a jar in my clojure code?


I don't think it would make a difference. Static initialisation etc. doesn't
happen until a class is explicitly loaded.

Regards,
Stuart

-- 
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't call public method of non-public class

2010-03-23 Thread Stuart Campbell
Hi Konstantin,

From JDK docs (
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/ProcessBuilder.html#environment%28%29
):

The behavior of the returned map is system-dependent. A system may not allow
 modifications to environment variables or may forbid certain variable names
 or values. For this reason, attempts to modify the map may fail with
 UnsupportedOperationExceptionhttp://java.sun.com/j2se/1.5.0/docs/api/java/lang/UnsupportedOperationException.htmlor
 IllegalArgumentExceptionhttp://java.sun.com/j2se/1.5.0/docs/api/java/lang/IllegalArgumentException.htmlif
  the modification is not permitted by the operating system.


Regards,
Stuart

On 24 March 2010 02:43, Konstantin Barskiy zuftw...@gmail.com wrote:

 I'm trying to reproduce ProcessBuilder example from java documentation
 http://java.sun.com/javase/6/docs/api/java/lang/ProcessBuilder.html
 This is that example:

 ProcessBuilder pb = new ProcessBuilder(myCommand, myArg1,
 myArg2);
  MapString, String env = pb.environment();
  env.put(VAR1, myValue);
  env.remove(OTHERVAR);
  env.put(VAR2, env.get(VAR1) + suffix);
  pb.directory(new File(myDir));
  Process p = pb.start();

 I'm typing folowing in clojure repl:

 D:\Users\Konstantinjava -jar clojure.jar
 Clojure 1.1.0
 user= (def pb (new ProcessBuilder [myCommand myArg]))
 #'user/pb
 user= (def env (.environment pb))
 #'user/env
 user= (.put env VAR1, myValue)
 java.lang.IllegalArgumentException: Can't call public method of non-
 public class: public java.lang.String
 java.lang.ProcessEnvironment.put(java.lang.String,java.lang.String)
 (NO_SOURCE_FILE:0)

 What does this error mean and what i am doing wrong?

 --
 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.comclojure%2bunsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en

 To unsubscribe from this group, send email to clojure+
 unsubscribegooglegroups.com or reply to this email with the words REMOVE
 ME as the subject.


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

To unsubscribe from this group, send email to 
clojure+unsubscribegooglegroups.com or reply to this email with the words 
REMOVE ME as the subject.


Re: Can't call public method of non-public class

2010-03-23 Thread Stuart Campbell
Whoops... I completely glazed over the fact that the equivalent Java code
worked perfectly :(

On 24 March 2010 11:19, Armando Blancas armando_blan...@yahoo.com wrote:

 You want Clojure to treat 'env' as a Map instead of its implementation
 class, which is not public. Just add the type hint #^Map to 'env''s
 def:

 user= (def pb (new ProcessBuilder [myCommand myArg]))
 #'user/pb
 user= (def #^Map env (.environment pb))
 #'user/env
 user= (.put env VAR1, myValue)
 myValue

 --
 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.comclojure%2bunsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en

 To unsubscribe from this group, send email to clojure+
 unsubscribegooglegroups.com or reply to this email with the words REMOVE
 ME as the subject.


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

To unsubscribe from this group, send email to 
clojure+unsubscribegooglegroups.com or reply to this email with the words 
REMOVE ME as the subject.


Re: Interesting integer behavior

2010-03-11 Thread Stuart Campbell
I took a look at the code for Clojure 1.1, in clojure.lang.Numbers,
and it seems that results of numerical ops on BigIntegers
(BigIntegerOps) are passed to a 'reduce' method, which appears to
return the most economical representation of a number:

static public Number reduce(BigInteger val){
int bitLength = val.bitLength();
if(bitLength  32)
return val.intValue();
else if(bitLength  64)
return val.longValue();
else
return val;
}

The class that operates on Integers, IntegerOps, doesn't have an
equivalent reduce() method.

On Mar 11, 7:53 am, Brian Hurt bhur...@gmail.com wrote:
 In a recent clojure:

 user= (class 2147483647)
 java.lang.Integer
 user= (class (inc 2147483647))
 java.math.BigInteger
 user= (class (inc (inc 2147483647)))
 java.lang.Long
 user=

 This isn't *technically* a bug, but it is an odd behavior.

 Brian

-- 
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: Slime and stuff

2009-10-22 Thread Stuart Campbell
Thanks Brian. In fact, I hadn't properly installed SLIME. However, I
discovered that clojure-mode has an installation function which downloads
and installs all dependencies (clojure, clojure-contrib, slime and
swank-clojure).

It all seems to be working correctly now.

2009/10/22 blcooley blcoo...@gmail.com


 I run SLIME with Clojure on Aquamacs, and I used Geoffrey Grosenbach's
 emacs starter kit (http://github.com/topfunky/emacs-starter-kit) to
 get set up.

 The emacswiki suggests that loading the .emacs file is deprecated
 (http://www.emacswiki.org/emacs/PreferencesInAquamacs), and I couldn't
 get it to load .emacs.d/init.el, so I put all the code from .emacs.d/
 init.el in ~/Library/Preferences/Aquamacs Emacs/Preferences.el and got
 it working that way. I suppose you could just load your ~/.emacs or
 ~/.emacs.d/init.el in Preferences.el if you also use other versions of
 emacs on the same box and want to avoid duplication.

 Hope that helps.

 -Brian Cooley

 On Oct 21, 6:31 am, Stuart Campbell
 stuart.william.campb...@gmail.com wrote:
  Jeffrey, did this work for you? I followed the instructions on the
  screencast and I couldn't get a REPL to open in Aquamacs. (The only thing
 I
  did differently was put the contents of customizations.el into ~/.emacs.)
 
  Do I have to install SLIME separately... ?
 

 


--~--~-~--~~~---~--~~
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: Slime and stuff

2009-10-21 Thread Stuart Campbell
Jeffrey, did this work for you? I followed the instructions on the
screencast and I couldn't get a REPL to open in Aquamacs. (The only thing I
did differently was put the contents of customizations.el into ~/.emacs.)

Do I have to install SLIME separately... ?

2009/10/21 Jeffrey Straszheim straszheimjeff...@gmail.com

 Thanks!


 On Tue, Oct 20, 2009 at 4:01 AM, Giancarlo Angulo igan.l...@gmail.comwrote:


 http://paulbarry.com/articles/2008/07/02/getting-started-with-clojure-and-aquamacs



 =
 ANGOL
 =
 -|-^...@^_^, =|+^_^X++~_~,@-

 The only thing worse than a hopeless romantic is a hopeful one

 Magbasa bago Mamuna. Mag-isip bago mambatikos

 Without Truth there is no Justice,
 Without Justice, there is Tyranny

 Semper fi

 Proof of Desire is Pursuit

 www.onthe8spot.com
 igan.l...@gmail.com
 09173822367


 On Tue, Oct 20, 2009 at 2:30 AM, Jeffrey Straszheim 
 straszheimjeff...@gmail.com wrote:

 So, I just upgraded my machine to a Macbook Pro, and am reinstalling
 everything.
 I'm thinking about using Slime with Aquamacs.  Does anyone have a link to
 a tutorial getting Slime up and running w/ Aquamacs?







 


--~--~-~--~~~---~--~~
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: Beginner: performance of vector creation/modification

2009-10-19 Thread Stuart Campbell
2009/10/19 Danny Woods dannywo...@gmail.com


 harto wrote:
  Hello,
 
  I've just started learning Clojure, so I'm trying to figure out the
  correct way of doing things. I've been trying to create and 'modify' a
  large vector for an online programming exercise, but I'm running into
  some performance issues.
 
  Any general tips would be appreciated!
 

 Well, I'm a beginner too, but I'll take a stab at answering your questions.

  Firstly, I'm creating a vector of booleans like this:
 
  (defn vector-of [n value]
(vec (for [_ (range n)] value)))
 
  It takes quite a long time for large values of n, though:
 
  user= (time (dorun (vector-of 1e7 true)))
  Elapsed time: 6734.509528 msecs
 
 I suspect you're being bitten by the repeated creation of the underlying
 data structures.  'range' is going to create a lazy sequence, from which
 'for' is going to create its own, lazy structure, which 'vec' then
 iterates over to create its own.  Just running '(time (dorun (range
 1e7)))' shows that it's taking up a non-trivial amount of time just on
 its own.


Ah, OK. I didn't understand the implications of using those lazy sequences.
I think I need to do some more reading on lazy data structures.

Thanks for your input!



 This modified version does the same thing a little more quickly:

 (defn vector-of [n value]
   (loop [v []
 c 0]
(if ( c n) (recur (assoc v c value) (inc c)

 user (time (dorun (vector-of 1e7 true)))
 Elapsed time: 1000.409039 msecs


  Secondly, I'm iterating across one of these large vectors using
  something like the following (contrived) function:
 
  (defn set-flags [v]
(loop [i 0
   v v]
  (if ( i (count v))
  (recur (inc i) (assoc v i false))
  v)))
 
  user= (let [v (vector-of 1e7 true)] (time (dorun (set-flags v
  Elapsed time: 15563.916114 msecs
 
  Am I missing anything obvious here? That seems like a really long time
  to me.
 
 With the modified vector-of, above, this problem seems to go away for me:

 user (time (dorun (set-flags (vector-of 1e7 true
 Elapsed time: 1009.362723 msecs

 Cheers,
 Danny.

 


--~--~-~--~~~---~--~~
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: Beginner: performance of vector creation/modification

2009-10-19 Thread Stuart Campbell
2009/10/19 Christophe Grand christo...@cgrand.net

 Hi,

 On Mon, Oct 19, 2009 at 7:59 AM, harto 
 stuart.william.campb...@gmail.comwrote:

 I've just started learning Clojure, so I'm trying to figure out the
 correct way of doing things. I've been trying to create and 'modify' a
 large vector for an online programming exercise, but I'm running into
 some performance issues.

 Any general tips would be appreciated!

 Firstly, I'm creating a vector of booleans like this:

 (defn vector-of [n value]
  (vec (for [_ (range n)] value)))

 It takes quite a long time for large values of n, though:

 user= (time (dorun (vector-of 1e7 true)))
 Elapsed time: 6734.509528 msecs


 You don't need dorun here: dorun is sometimes used in benchmarks to force
 the computation of lazy-seqs but here you are using a vector, not a lazy
 seq. So calling dorun on it causes the allocation of a seq of 1e7 items
 which takes time. If you used dorun to prevent the printing of the vector at
 the REPL, just di (tcime (count (vector-of 1e7 true))). See:
 user= (time (dorun (vector-of 1e7 nil)))
 Elapsed time: 4155.616985 msecs
 nil
 user= (time (count (vector-of 1e7 nil)))
 Elapsed time: 2384.609217 msecs
 1000


OK, thanks. I thought I'd need dorun to get a true benchmark because I was
using those intermediate lazy sequences. But, it looks like I was misusing
those anyway :)



 If you study your function:
 (defn vector-of [n value]
  (vec (for [_ (range n)] value)))

 You'll see that to create a vector of n items you use two intermediate seqs
 of size n items (range and the result of for).
 If you get rid of some allocations, you'll get huge speed-ups.

 (defn vector-of [n value]
   (loop [n (int n) v []]
 (if (zero? n)
   v
   (recur (dec n) (conj v value)

 user= (time (count (vector-of 1e7 nil)))
 Elapsed time: 1170.371793 msecs
 1000

 Since you don't care about intermediate values of v, you can use
 transients:
 (defn vector-of [n value]
   (loop [n (int n) v (transient [])]
 (if (zero? n)
   (persistent! v)
   (recur (dec n) (conj! v value)

 user= (time (count (vector-of 1e7 nil)))
 Elapsed time: 228.272239 msecs
 1000



 Secondly, I'm iterating across one of these large vectors using
 something like the following (contrived) function:

 (defn set-flags [v]
  (loop [i 0
 v v]
(if ( i (count v))
(recur (inc i) (assoc v i false))
v)))

 user= (let [v (vector-of 1e7 true)] (time (dorun (set-flags v
 Elapsed time: 15563.916114 msecs


 For reference (using my fastest vector-of):
 user= (let [v (vector-of 1e7 true)] (time (count (set-flags v
 Elapsed time: 5653.562953 msecs
 1000

 Here too you don't care about intermediate values of v:
 (defn set-flags [v]
  (loop [i 0 v (transient v)]
(if ( i (count v))
(recur (inc i) (assoc! v i false))
(persistent! v

 user= (let [v (vector-of 1e7 true)] (time (count (set-flags v
 Elapsed time: 1423.473584 msecs
 1000

 And if you store (count n) in a local:
 (defn set-flags [v]
   (let [n (count v)]
 (loop [i 0 v (transient v)]
   (if ( i n)
(recur (inc i) (assoc! v i false))
(persistent! v)

 user= (let [v (vector-of 1e7 true)] (time (count (set-flags v
 Elapsed time: 931.911668 msecs
 1000


Thanks very much. I wasn't aware of transients until reading this. In fact,
I had to search the Clojure website to find the relevant page (
http://clojure.org/transients).

Cheers!



 hth,

 Christophe



 --
 Professional: http://cgrand.net/ (fr)
 On Clojure: http://clj-me.blogspot.com/ (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
-~--~~~~--~~--~--~---