Re: Why is next.jdbc using my IP address?

2022-03-03 Thread Kevin Downey
That is a message from MySQL, not next.jdbc.

MySQL allows you to grant permissions to a user base on the host they are
connecting from so permission denied kinds of errors include the username
and the host the users connection came from.

On Thu, Mar 3, 2022, 11:18 Lawrence Krubner  wrote:

> I just wrote a small app that needs to connect to a MySQL app. I was
> running it on my laptop, connecting to MySQL on the laptop, and everything
> was working fine. Then I wanted to connect to one of our test databases in
> RDS in AWS. I've a simple function that finds the environment variables and
> returns them as a map:
>
> (defn get-config
>   []
>   (check-config)
>   {
>:dbtype "mysql"
>:dbname (System/getenv "DATABASE_NAME")
>:user (System/getenv "DATABASE_USER")
>:password (System/getenv "DATABASE_PASSWORD")
>:host (System/getenv "DATABASE_HOST")
>})
>
> This is used simply:
>   ds (jdbc/get-datasource  (get-config))
>
> I've checked the environment values several times and they are correct.
> But when the code tries to write to the RDS database, I get:
>
> *java.sql.SQLException*: *Access denied for user
> 'pulseuser'@'cpe-74-71-234-49.nyc.res.rr.com
> ' (using password: YES)*
>
> I am connecting to the Internet through Spectrum, and apparently "rr.com"
> is Spectrum. I'm confused, why would next.jdbc use this info? Did I forget
> some important value in the hash map?
>
> From my laptop, I can reach the RDS database using the MySQL CLI, so there
> are no problems with connectivity. I whitelisted the IP address of my
> house. This is something specific about what next.jdbc needs in that hash
> map, I think.
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from 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/eadd7b66-d19d-41e8-b02d-76185de0778dn%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/CAE8CPr6D_g1iNX0H%2BtM8MUAaFV6trFKE9f7e4VxOMu5tb0Damg%40mail.gmail.com.


Re: core.async/close! locks on chans with pending transforms

2017-07-03 Thread Kevin Downey

On 07/03/2017 03:12 PM, Vitalie Spinu wrote:




On Monday, 3 July 2017 22:48:40 UTC+2, red...@gmail.com wrote:


Discussion of locks aside, doing blocking operations like io or !! or basically anything that looks like it blocks and isn't >!
or Is this the limitation in general or only when I use the chan with 
blocking transducer withing a go block?  Transducers are not run on a go 
block, are they?




It is kind of complicated, and I haven't traced through everything in 
channels.clj recently, but assume transducers are not magic, the 
computation has to occur on some real thread some where, and the best 
threads available to do that are the consumer thread and the producer 
thread. If those threads are both executing go blocks, and you have a 
transducer doing blocking stuff on a channel they operate on, you may 
not be technically "blocking" in the go block, but the channel machinery 
is now blocking before it yields control back to the go  block. Putting 
blocking operations in a transducer then operating on the channel from 
go blocks turns `!>` and '(just park go blocks), in to operations that do block a whole OS thread, 
of which the core.async threadpool that go blocks execute on only has 8 
by default.


There is this sort of dance where control is handed back and forth 
between channels and go blocks without tying up a thread. When you 
introduce blocking in to the channel machinery (by making the channel 
execute a blocking operation as things are produced or consumed) then 
the dance stops and the thread waits.



--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with 
your first post.

To unsubscribe from 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/d/optout.



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

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


Re: core.async/close! locks on chans with pending transforms

2017-07-03 Thread Kevin Downey

On 07/03/2017 11:03 AM, Vitalie Spinu wrote:


Hi,

Async/close! causes deadlocks if its reducer is stalled (e.g. waits for 
an event from

  another chan).

Consider:

   (let [d (chan)
 s (chan 1 (map (fn [v]
  (println "this:" v)
  (println "from d:" (

Discussion of locks aside, doing blocking operations like io or >!! or basically anything that looks like it blocks and isn't >! or is a very bad idea in a transducer on a channel. You will (eventually) 
block the threadpool and get deadlocks. If you must use a transducer 
that does blocking operations, you should checkout pipeline-blocking. 
pipeline-blocking has a slightly convoluted internal structure exactly 
to avoid blocking operations running on the go block threadpool.


The transducer will be executed when publishing to a channel(this is a 
little bit squishy, sometimes publishing to a channel doesn't actually 
publish because the channel is full and a callback is registered to do 
the publishing the next time a consumer takes), if you publish to a 
channel with a transducer that blocks from a go-block, then you are 
blocking that go block which is bad.



  v)))]
 (go (>! s 1))
 (Thread/sleep 100)
 (println "closing s")
 (async/close! s))

   ;; =>
   ;; this: 1
   ;; closing s
   ;; .. [lock]

This is caused by (.lock mutex) in close! method here:


https://github.com/clojure/core.async/blob/master/src/main/clojure/clojure/core/async/impl/channels.clj#L247


I wonder if it is there "by design" or a bug. IMO it makes little sense 
to lock
external code simply because chan's reducer function is stalled. Just as 
close!

doesn't lock on pending puts it shouldn't stall on pending "half-puts".

I need this for systems with inter-dependent chans. In the above example
component 'd' is a dependency of 's', then system will halt in reverse 
order of

dependencies closing `s` first.

Thank you,

Vitalie

--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with 
your first post.

To unsubscribe from 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/d/optout.



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

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


Re: Leiningen, AOT compilation, and classloaders

2017-03-15 Thread Kevin Downey
On 03/07/2017 09:07 PM, 'Tianxiang Xiong' via Clojure wrote:
> I recently ran into an issue with AOT compilation that I'd like to
> understand better. A minimal working example (MWE) can be found here
> . 
> 
> Basically, using `:aot :all` in `project.clj` with `lein trampoline
> test` results in different classloaders for class `Foo`.  
> 
> |
> Classloaderforlein_trampoline_aot.core.Foo: 
> #object[clojure.lang.DynamicClassLoader
> 0x4982cc36 clojure.lang.DynamicClassLoader@4982cc36]
> Classloaderfor(->Foo): #object[sun.misc.Launcher$AppClassLoader
> 0x55f96302 sun.misc.Launcher$AppClassLoader@55f96302]
> |
> 
> While the same classloaders are used with `lein test`:
> 
> |
> Classloader
> forlein_trampoline_aot.core.Foo: #object[sun.misc.Launcher$AppClassLoader 
> 0x55f96302
> sun.misc.Launcher$AppClassLoader@55f96302]
> Classloaderfor(->Foo): #object[sun.misc.Launcher$AppClassLoader
> 0x55f96302 sun.misc.Launcher$AppClassLoader@55f96302]
> |
> 
> When is one classloader used instead of another, and why do `lein
> trampoline test` and `lein test` behave differently with `:aot :all`?


When you aot compile you generate a class file on disk that is visible
to the system classloader. When the reference to the Foo class is
compiled, it is compiled as a call something like
clojure.lang.RT.classForName("Foo"); RT.classForName uses different
class loaders depend on this that an the other, and in this case it is
using the system classloader (the AppClassLoader) when using lein
trampoline. When you loaded your clojure code it ran through the
compiler which generated bytecode which is loaded via clojure's
DynamicClassLoader.


The way RT.classForName determines which classloader to use is something
like: if there is a DynamicClassloader available from the compiler, use
it, otherwise use the system classloader.

Once you finish loading code the DynamicClassloader the compiler uses
is, uh, for lack of a better word, popped, so it isn't available to
RT.classForName.

So given that and the error we can deduce that `lein trampoline` runs in
to phases a code loading phase, and then an execution phase. Which is a
perfectly reasonable thing to do and easy to do with the command line
options to clojure.main.

I suspect adding an import of the Foo class would work around this
issue, but I strongly recommend you consider not aot compiling instead.
AOT compilation is a source of weird behavior and just isn't worth it.

The #1 reason people aot compile is because they don't know how else to
start their clojure programs, so I have a little write up here
https://github.com/hiredman/clojure-site/blob/df56aef005d5d867213a51c2d3bbec5a86b0acad/content/guides/running_a_clojure_program.adoc



> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from 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/d/optout.


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

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


Re: Error in main using Stuart Sierra's Component when deploying to Heroku

2017-03-13 Thread Kevin Downey
On 03/13/2017 09:38 AM, 'Rickesh Bedia' via Clojure wrote:
> I am trying to start my clojure application on my heroku dyno but I keep
> getting and error in my stuartsierra.component/start.
> 
> Below is my core file containing my main function.
> 
> (defrecord Listener [listener]
>   component/Lifecycle
>   (start [component]
> (assoc component :listener (yada/listener
>  ["/"
>   [(view/view-route)
>routes/route-handler
>["public/" (new-directory-resource
> (io/file "target/cljsbuild/public") {})]
>[true (as-resource nil)]]]
>  (or (env :port) (get (read-config
> "resources/config.edn" {:profile :dev}) :webserver))

resources/config.edn is likely incorrect, depending on how you are
running your app. The "resources/" directory is typically on the
classpath, so you refer a file in it as just "config.edn". Referring to
it as "resources/config.edn" is the kind of thing that will work
sometimes at the repl, but depending on how you are packaging and
deploying you app will fail.

The file business with target/ is also something that is likely to fail.

I am not familiar with how heroku deploys clojure, but it looks like
they build an uberjar and run that, so if you want to see how your code
will work there run `lein uberjar` then `java -jar your-uberjar.jar`.

>  )))
>   (stop [component]
> (when-let [close (-> component :listener :close)]
>   (close))
> (assoc component :listener nil)))
> 
> (defn new-system []
>   (component/system-map
> :listener (map->Listener {})
> ))
> 
> (def system nil)
> 
> (defn init []
>   (alter-var-root #'system
>   (constantly (new-system
> 
> (defn start []
>   (alter-var-root #'system component/start))
> 
> (defn stop []
>   (alter-var-root #'system
>   (fn [s] (when s (component/stop s)
> 
> (defn go []
>   (init)
>   (start))
> 
> (defn reset []
>   (stop)
>   (refresh :after 'web.core/go))
> 
> (defn -main
>   [& [port]]
>   (component/start (new-system))
>   (println "System Started")
>   @(promise))
> 
> This is my core file with all my stuartsierra.component code. This all
> works perfectly when I run it locally on my laptop doing lein repl and
> then (go) and also when I just do lein run. So I am confused as to why
> it doesn't work when I push this to the heroku dyno.
> 
> The error I get is
> 
> Exception in thread "main" clojure.lang.ExceptionInfo: Error in
> component :listener in system com.stuartsierra.component.SystemMap
> calling #'com.stuartsierra.component/start {:reason
> :com.stuartsierra.component/component-function-threw-exception,
> :function #'com.stuartsierra.component/start, :system-key :listener,
> :component #web.core.Listener{:listener nil}, :system #},
> compiling:(/tmp/form-init9049917434081554913.clj:1:73)
> This is telling me that my :listener is nil in the system-map. When I
> check locally (doing lein repl (go)) in (keys system) is (:listener)
> which is good so that means that the listener is starting and is in the
> system.
> 
> When I do (-> system :listener) I get #web.core.Listener{:listener
> {:port 3300, :close #object[yada.aleph$listener$fn__21671 0xa5d4865
> "yada.aleph$listener$fn__21671@a5d4865"], :server
> #object[aleph.netty$start_server$reify__13574 0x3cc9a232
> "aleph.netty$start_server$reify__13574@3cc9a232"]}} which is perfect as
> the port has loaded up (3300) and the server has started.
> 
> This makes it all the more confusing as to why the :listener is nil in
> my heroku app
> 
> Any help would be much appreciated. 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 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/d/optout.


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

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

Re: loop macro generates a wrapping let

2017-03-06 Thread Kevin Downey
On 03/06/2017 03:28 PM, juan.facorro wrote:
> While I was debugging some code I found something related to the *loop
> *macro that I found curious. I'm probably missing something but here it
> goes.
> 
> The expression generated by the *loop* macro includes a wrapping *let
> *when there is any de-structuring in the bindings.
> 
> (require '[clojure.walk :as walk])
> (walk/macroexpand-all '(loop [[x & xs] xs a 3]))

The init value of `a` could rely on `x` or `xs`, so those bindings need
to be established before the loop, which is what the outer loop does.
For example checkout `(walk/macroexpand-all '(loop [[x & xs] xs a x]))`.

> 
> Which returns:
> 
> 
> (let*[G__1249xsvec__1250G__1249x(clojure.core/nthvec__12500nil)
> xs(clojure.core/nthnextvec__12501) a3] (loop*[G__1249G__1249a a]
> (let*[vec__1251G__1249x(clojure.core/nthvec__12510nil)
> xs(clojure.core/nthnextvec__12511) aa])))
> 
> 
> Since all bindings get re-defined in the inner *let*, why is the outer
> *let* even generated? Is there a reason for not having the following
> generated instead? 
> 
> 
> (loop* [G__1249 xs a a]
>   (let* [vec__1251 G__1249
>  x (clojure.core/nth vec__1251 0 nil)
>  xs (clojure.core/nthnext vec__1251 1)
>  a a]))
> 
> 
> The change in the loop macro is pretty simple and it seems to work (at
> least with the tests available in GitHub's clojure/clojure).
> 
> 
> (defmacro loop
>   "Evaluates the exprs in a lexical context in which the symbols in
> the binding-forms are bound to their respective init-exprs or parts
> therein. Acts as a recur target."
>   {:added "1.0", :special-form true, :forms '[(loop [bindings*] exprs*)]}
>   [bindings & body]
> (assert-args
>   (vector? bindings) "a vector for its binding"
>   (even? (count bindings)) "an even number of forms in binding vector")
> (let [db (destructure bindings)]
>   (if (= db bindings)
> `(loop* ~bindings ~@body)
> (let [vs (take-nth 2 (drop 1 bindings))
>   bs (take-nth 2 bindings)
>   gs (map (fn [b] (if (symbol? b) b (gensym))) bs)]
>   `(loop* ~(vec (interleave gs vs))
>   (let ~(vec (interleave bs gs))
> ~@body))
> 
> 
> But maybe this hasn't been changed because of the importance of the
> *loop* macro, or maybe the impact in compile- and run-time is
> insignificant to justify the change.
> 
> Anyways... I thought I'd put the question out there.
> 
> 
> Cheers!
> 
> Juan
> 
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from 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/d/optout.


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

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


Re: is it a bug in clojure? unchecked-multiply

2017-03-03 Thread Kevin Downey
On 03/03/2017 12:14 AM, BongHyeon. Jo wrote:
> (unchecked-multiply 1000 1000)

The default type clojure uses for integers is the jvm's long (or the
boxed variant Long) type. Longs are signed 64bit numbers.
100 is outside the range of longs.
`(* 1000 1000)` will throw an error because of the
overflow. `(*' 1000 1000)` will promote the result to a
BigInt (most ops have a primed variant that auto promotes). The
`unchecked` in `unchecked-multiply` means it doesn't check the result,
so overflow silently happens, as you have seen. The `unchecked` variants
are intended for use when you are sure overflow is ok and you want the
fastest possible math.

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

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


Re: When did this start? java.lang.IllegalAccessError cond* does not exist nippy

2017-02-07 Thread Kevin Downey
definitely turn on
https://github.com/technomancy/leiningen/blob/master/sample.project.clj#L81
:pedantic? :abort and resolve the issues lein deps :tree shows you.

given that you are aot compiling, but have implicit clean disabled, my
guess is you compiled the project once using a version of some library
where cond* was present and nippy could use it, made some changes to the
versions you were using, but didn't blow away the compiled class files,
so nippy was never compiled again, so there was never an error about the
missing cond* macro. So the error was never noticed when it was
introduced, and now some time later for whatever nippy is being compiled
again (fresh checkout, run lein clean, dunno) and versions conflict and
the macro is missing.

This is just a theory, could be all kinds of stuff.

I strongly recommend disabling aot compilation entirely, and if you are
going to aot compile, regularly delete target/. AOT compilation can be a
reliable source of bugs that break things at a large distance from the
cause. If you are aot compiling only to get a nice launcher for your
program, it is not worth it. I have a guide I am trying to contribute to
the official docs on how to launch a clojure program without using aot,
you can see it here
https://github.com/hiredman/clojure-site/blob/df56aef005d5d867213a51c2d3bbec5a86b0acad/content/guides/running_a_clojure_program.adoc,
https://github.com/clojure/clojure-site/pull/141 is the pr.

On 02/07/2017 02:32 PM, Laws wrote:
> Sorry about that. Here is the whole of my project.clj. It is a fairly
> small app. 
> 
> (defproject csv-to-dynamodb "1.0"
>   :description "Takes a Super company import file, of CSV format, and
> stores the data in DynamoDB, using the company_name as the sharding key"
>   :url "https://bitbucket.org/super/poi;
>   :license {:name "Copyright Super 2016"
> :url "http://www.super.com/"}
>   :dependencies [
>  [org.clojure/clojure "1.7.0"]
>  [org.clojure/test.check "0.9.0"]
>  [org.clojure/data.json "0.2.6"]
>  [defun "0.3.0-RC1"]
>  [http-kit "2.2.0"]
>  [com.taoensso/timbre "4.3.1"]
>  [dire "0.5.4"]
>  [slingshot "0.12.2"]
>  [me.raynes/fs "1.4.4"]
>  [clj-stacktrace "0.2.7"] 
>  [overtone/at-at "1.2.0"]
>  [com.taoensso/faraday "1.9.0"]
>  ]
>   :disable-implicit-clean true
>   :warn-on-reflection true
>   :source-paths  ["src/clojure"]
>   :java-source-paths ["src/java"]
>   :main csv-to-dynamodb.core
>   :aot :all
>   :jvm-opts ["-Xms50m" "-Xmx50m" "-XX:-UseCompressedOops"])
> 
> 
> 
> And this:
> 
> lein deps :tree
> 
> shows me: 
> 
> [com.taoensso/faraday "1.9.0"] -> [com.taoensso/nippy "2.12.0"] ->
> [com.taoensso/encore "2.67.1"]
> 
> 
> The full output: 
> 
> lein deps :tree
> 
> Possibly confusing dependencies found:
> 
> [lein-checkall "0.1.1"] -> [jonase/eastwood "0.0.2"] ->
> [org.clojure/tools.namespace "0.1.2"]
>  overrides
> [lein-checkall "0.1.1"] -> [lein-kibit "0.0.8"] -> [jonase/kibit
> "0.0.8"] -> [org.clojure/tools.namespace "0.2.1"]
>  and
> [lein-checkall "0.1.1"] -> [lein-bikeshed "0.1.3"] ->
> [org.clojure/tools.namespace "0.2.3"]
> 
> Consider using these exclusions:
> [lein-checkall "0.1.1" :exclusions [org.clojure/tools.namespace]]
> [lein-checkall "0.1.1" :exclusions [org.clojure/tools.namespace]]
> 
> Possibly confusing dependencies found:
> [org.clojure/clojure "1.7.0"]
>  overrides
> [defun "0.3.0-RC1"] -> [org.clojure/clojure "1.8.0"]
> 
> Consider using these exclusions:
> [defun "0.3.0-RC1" :exclusions [org.clojure/clojure]]
> 
> [com.taoensso/timbre "4.3.1"] -> [com.taoensso/encore "2.36.2"]
>  overrides
> [com.taoensso/faraday "1.9.0"] -> [com.taoensso/nippy "2.12.0"] ->
> [com.taoensso/encore "2.67.1"]
>  and
> [com.taoensso/faraday "1.9.0"] -> [com.taoensso/encore "2.67.2"]
> 
> Consider using these exclusions:
> [com.taoensso/faraday "1.9.0" :exclusions [com.taoensso/encore]]
> [com.taoensso/faraday "1.9.0" :exclusions [com.taoensso/encore]]
> 
> [com.taoensso/timbre "4.3.1"] -> [com.taoensso/encore "2.36.2"] ->
> [com.taoensso/truss "1.1.1"]
>  overrides
> [com.taoensso/faraday "1.9.0"] -> [com.taoensso/nippy "2.12.0"] ->
> [com.taoensso/encore "2.67.1"] -> [com.taoensso/truss "1.3.3"]
>  and
> [com.taoensso/faraday "1.9.0"] -> [com.taoensso/encore "2.67.2"] ->
> [com.taoensso/truss "1.3.3"]
> 
> Consider using these exclusions:
> [com.taoensso/faraday "1.9.0" :exclusions [com.taoensso/truss]]
> [com.taoensso/faraday "1.9.0" :exclusions [com.taoensso/truss]]
> 
> [me.raynes/fs "1.4.4"] -> [org.apache.commons/commons-compress "1.4"] ->
> [org.tukaani/xz "1.0"]
>  overrides
> [com.taoensso/faraday "1.9.0"] -> [com.taoensso/nippy "2.12.0"] ->
> [org.tukaani/xz "1.5"]
> 
> Consider using these exclusions:
> [com.taoensso/faraday "1.9.0" :exclusions [org.tukaani/xz]]
> 

Re: Is there a standard name for this transducer? Or a more idiomatic way to do it?

2016-09-14 Thread Kevin Downey
looks like a variation of partition-by

On 09/14/2016 07:16 PM, Marshall handheld Flax wrote:
> This looks like a standard thing you might want to do with a transducer:
> accept a stream of inputs and statefully group them into a stream of
> varying-length vectors.  A typical example might be to accept a series
> of bowling throws and emit them grouped into bowling frames.  So you
> have a generic "vectorTransducer" which is defined by the rule as to
> when one frame is full and the next begins.  Does such a thing have a
> standard name?
> 
> Thanks!
> 
> Marshall
> 
> (defn vectorTransducer [timeForNextVector]
>   (fn [rf]
> (let [pending (volatile! [])]
>   (fn
> ([] (rf))
> ([result] (if (not-empty @pending)
> (rf result @pending)
> (rf result)))
> ([result input]
>  (let [appended (conj @pending input)]
>(if (timeForNextVector appended)
>  (do (vreset! pending [])
>  (rf result appended))
>  (do (vreset! pending appended)
>  result
> 
> (defn bowlingTransducer[]
>   (vectorTransducer
>(fn ([v]
> (or (<= 2 (count v))
> (<= 10 (reduce + v)))
> 
> (into [] (bowlingTransducer)
>   (concat (range 11) (range 11)))
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from 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/d/optout.


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

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


Re: [ANN] Clojure 1.9.0-alpha11

2016-09-01 Thread Kevin Downey
instrument is going to have issues with any calling convention outisde
of the normal deref var + invoking path.
http://dev.clojure.org/jira/browse/CLJ-1941 is a similar case with some
discussion in the comments.

On 09/01/2016 11:33 AM, Ambrose Bonnaire-Sergeant wrote:
> Hi,
> 
> There seems to be some issues instrumenting functions that
> compile to .invokePrim calls.
> 
> user=> (s/fdef blah :args (s/cat :foo int?) :ret any?)
> user/blah
> user=> (defn blah [^long a])
> #'user/blah
> user=> (st/instrument)
> [clojure.core/symbol user/blah]
> user=> (blah 1)
> 
> ClassCastException clojure.spec.test$spec_checking_fn$fn__13057 cannot
> be cast to clojure.lang.IFn$LO  user/eval70134
> (form-init2184258571072833082.clj:1)
> user=> 
> 
> I'm about to tackle this problem in core.typed, so I should have some useful
> utilities to fix this soon (if interested).
> 
> Thanks,
> Ambrose
> 
> On Friday, August 19, 2016 at 2:15:06 PM UTC-4, Alex Miller wrote:
> 
> Clojure 1.9.0-alpha11 is now available.
> 
> Try it via
> 
> - Download:
> https://repo1.maven.org/maven2/org/clojure/clojure/1.9.0-alpha11
> 
> - Leiningen: [org.clojure/clojure "1.9.0-alpha11"]
> 
> 1.9.0-alpha11 includes the following changes since 1.9.0-alpha10:
> 
> Clojure now has specs for the following clojure.core macros: let,
> if-let, when-let, defn, defn-, fn, and ns. Because macro specs are
> checked during macroexpansion invalid syntax in these macros will
> now fail at compile time whereas some errors were caught at runtime
> and some were not caught at all.
> 
> - CLJ-1914 - Fixed race condition in concurrent range realization
> - CLJ-1870 - Fixed reloading a defmulti removes metadata on the var
> - CLJ-1744 - Clear unused locals, which can prevent memory leaks in
> some cases
> - CLJ-1423 - Allow vars to be invoked with infinite arglists (also,
> faster)
> - CLJ-1993 - Added *print-namespace-maps* dynamic var that controls
> whether to use namespace map syntax for maps with keys from the same
> namespace. The default is false, but standard REPL bindings set this
> to true.
> - CLJ-1985 - Fixed with-gen of conformer losing unform fn
> - Fixed clojure.spec.test/check to skip spec'ed macros
> - Fixed regression from 1.9.0-alpha8 where type hints within
> destructuring were lost
> - Fixed clojure.spec/merge docstring to note merge doesn't flow
> conformed values
> - Fixed regex ops to use gen overrides if they are used
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from 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/d/optout.


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

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


Re: Why is this not considered to be in a go block?

2016-08-25 Thread Kevin Downey
The analysis for the go macro to determine that the fn never escapes the
go block is not something core.async does. Because of that functions are
sort of a black box to the transforms the go macro does.

http://dev.clojure.org/jira/browse/ASYNC-93 is a declined issue
regarding this. http://dev.clojure.org/jira/browse/ASYNC-57 is another
similar declined issue.

On 08/25/2016 04:21 PM, hiskennyness wrote:
> I am getting an error about >! not being in a go block with this code:
> 
> |
>   (go-loop [state :nl
> column 0
> last-ws nil
> buff ""]
> (let [line-out(fn [c b]
>  (>!out(apply str b (repeat (-col-width (count
> b))\space]
>   (cond
> (>=column col-width)
> (condp =state
>   :ws (do
> (line-out\|buff)
> (recur :nl 0nil""))
>  ..etc etc
> |
> 
> I just changed the line-out call to just do...
> 
> |
> (>!out-chan buff)
> |
> 
> ...and it worked fine.
> 
> So the failing code is both dynamically and lexically within the scope
> of the go-loop --- is that supposed to be that way? Or am I completely
> missing something?
> 
> -kt
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from 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/d/optout.


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

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


Re: clojure.spec & protocol fn

2016-06-05 Thread Kevin Downey
http://dev.clojure.org/jira/browse/CLJ-1941 has some discussion about
places where instrumenting won't work.

On 06/05/2016 09:57 AM, Claudius Nicolae wrote:
> It seems that protocol fns don't participate in s/fdef specfications. It
> would be nice they were. Sample:
> 
> (ns sample
>   (:require [clojure.spec :as s]))
> 
> (s/instrument-all)
> 
> ;; Spec a fn
> 
> (s/fdef f
>   :args (s/cat :i integer?)
>   :ret integer?)
> 
> (defn f [i] i)
> 
> (f "1") ; will fail
> 
> ;; Spec a fn of a protocol
> 
> (defprotocol P
>   (g [p i]))
> 
> (s/fdef g
>   :args (s/cat :p (partial satisfies? P)
>:i integer?)
>   :ret integer?)
> 
> (defrecord R []
>   P
>   (g [_ i] i))
> 
> (g (->R) "2") ; will pass
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from 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/d/optout.


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

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


Re: atoms not working same in cljs as in clj?

2016-05-20 Thread Kevin Downey
This is a difference in the type function. The clojurescript type
function ignores metadata. So the clojurescript type function is like
the clojure class function, and clojurescript doesn't have a class function.

On 05/20/2016 09:22 AM, hiskennyness wrote:
> I see here
> https://github.com/clojure/clojurescript/wiki/Differences-from-Clojure
> that "Atoms work as in Clojure.", but I think I see a difference:
> 
> 1. I am using a custom type hierarchy in a namespace
> tiltontec.modeller.cell_types:
> 
> |
> (defonce ia-types (-> (make-hierarchy)
>   (derive ::model ::object)
>   (derive ::cell ::object)
>   (derive ::c-formula ::cell)))
> 
> |
> 
> 2. At the repl I switch to the cell types namespace and create an atom:
> 
> |
> (def my-formula (atom 42 :meta {:type ::c-formula}))
> |
> 
> 3. In Clojure:
> 
> |
> (type my-formula) => :tiltontec.modeller.cell-types/c-formula
> |
> 
> 4. In cljs:
> 
> |
> (type my-formula) => cljs.core.Atom
> |
> 
> Sanity check:
> 
> |
> (meta my-formula) => {:type :tiltontec.modeller.cell-types/c-formula}
> |
> 
> Am I missing something?
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from 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/d/optout.


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

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


Re: :default catch blocks with core.async and clojurescript

2016-05-16 Thread Kevin Downey
On 05/15/2016 06:39 PM, Kevin Downey wrote:
> On 05/14/2016 09:31 PM, cameron wrote:
>> I'm having an issue where :default catch blocks are not working in
>> clojurescript when in a go block.
>>
>> The following code prints "a str" as expected:
>>
>> (prn (try
>>(throw "a str")
>>(catch :default e e )))
>>
>> The same code in a go block results in an unhandled exception 
>> (go (prn (try
>> (throw "a str")
>> (catch :default e e 
>>
>> I can see an old core.async issue that added support for :default
>> (http://dev.clojure.org/jira/browse/ASYNC-42) 
>> but no other references, is this a regression or something I'm missing?
>>
>> I'm using clojurescript  "1.8.51"  and core.async "0.2.374"
>>
>> Cameron.
>>
>> -- 
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clojure@googlegroups.com
>> Note that posts from new members are moderated - please be patient with
>> your first post.
>> To unsubscribe from 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
>> <mailto:clojure+unsubscr...@googlegroups.com>.
>> For more options, visit https://groups.google.com/d/optout.
> 
> You will likely find that (throw (js/String. "a str")) will work the
> same in both.
> 
> This issue has two parts:
> 
> 1. String literals are somehow not objects or something in javascript (I
> don't entirely understand this, but I vaguely recall that it is a thing)
> 
> 2. The go macro uses js/Object as the exception type in the "catch all"
> exception handler it creates to emulate exception handling.
> 
> You can verify that the combination of these two things causes this
> problem by playing with this code:
> 
> (try (throw "foo") (catch js/Object e :good))
> 
> (try (throw (js/String. "foo")) (catch js/Object e :good))
> 
> (try (throw "foo") (catch :default e :good))
> 
> The "Fix" for the issue you linked didn't change "js/Object" to
> ":default" in the catch all, so it didn't actually fix anything.
> 

I am not entirely sure what to do with this. What I did was re-open
async-42 with a link to this thread

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

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


Re: :default catch blocks with core.async and clojurescript

2016-05-15 Thread Kevin Downey
On 05/14/2016 09:31 PM, cameron wrote:
> I'm having an issue where :default catch blocks are not working in
> clojurescript when in a go block.
> 
> The following code prints "a str" as expected:
> 
> (prn (try
>(throw "a str")
>(catch :default e e )))
> 
> The same code in a go block results in an unhandled exception 
> (go (prn (try
> (throw "a str")
> (catch :default e e 
> 
> I can see an old core.async issue that added support for :default
> (http://dev.clojure.org/jira/browse/ASYNC-42) 
> but no other references, is this a regression or something I'm missing?
> 
> I'm using clojurescript  "1.8.51"  and core.async "0.2.374"
> 
> Cameron.
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from 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/d/optout.

You will likely find that (throw (js/String. "a str")) will work the
same in both.

This issue has two parts:

1. String literals are somehow not objects or something in javascript (I
don't entirely understand this, but I vaguely recall that it is a thing)

2. The go macro uses js/Object as the exception type in the "catch all"
exception handler it creates to emulate exception handling.

You can verify that the combination of these two things causes this
problem by playing with this code:

(try (throw "foo") (catch js/Object e :good))

(try (throw (js/String. "foo")) (catch js/Object e :good))

(try (throw "foo") (catch :default e :good))

The "Fix" for the issue you linked didn't change "js/Object" to
":default" in the catch all, so it didn't actually fix anything.

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

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


Re: Strange exception: Cannot cast to compile stub??

2016-05-09 Thread Kevin Downey
There is a jira issue http://dev.clojure.org/jira/browse/CLJ-1226 and it
looks like it is marked as fixed in 1.8

On 05/09/2016 01:10 AM, Kevin Downey wrote:
> If I recall correctly, looking at the code at around line 483, I think I
> have seen that error arise when using (set! (.fieldName this-reference)
> value) inside defrecord and deftype bodies. if you use (set! fieldName
> value) syntax you might be fine.
> 
> On 05/08/2016 07:21 PM, JvJ wrote:
>> I'm implementing a data structure with persistent and transient
>> implementations.   (Code is
>> here: 
>> https://github.com/JvJ/cross-map/blob/master/src/cross_map/core.cljc#L446).
>>
>> When I try to convert a persistent cross-map to a transient cross-map, I
>> get the following exception:
>>
>> ClassCastException cross_map.core.TransientCrossMap cannot be cast to
>> compile__stub.cross_map.core.TransientCrossMap
>>  cross-map.core.TransientCrossMap (core.cljc:483)
>>
>> I don't understand what this means.  Does anyone have insight on it.
>>
>> -- 
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clojure@googlegroups.com
>> Note that posts from new members are moderated - please be patient with
>> your first post.
>> To unsubscribe from 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
>> <mailto:clojure+unsubscr...@googlegroups.com>.
>> For more options, visit https://groups.google.com/d/optout.
> 
> 


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

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


Re: Strange exception: Cannot cast to compile stub??

2016-05-09 Thread Kevin Downey
If I recall correctly, looking at the code at around line 483, I think I
have seen that error arise when using (set! (.fieldName this-reference)
value) inside defrecord and deftype bodies. if you use (set! fieldName
value) syntax you might be fine.

On 05/08/2016 07:21 PM, JvJ wrote:
> I'm implementing a data structure with persistent and transient
> implementations.   (Code is
> here: 
> https://github.com/JvJ/cross-map/blob/master/src/cross_map/core.cljc#L446).
> 
> When I try to convert a persistent cross-map to a transient cross-map, I
> get the following exception:
> 
> ClassCastException cross_map.core.TransientCrossMap cannot be cast to
> compile__stub.cross_map.core.TransientCrossMap
>  cross-map.core.TransientCrossMap (core.cljc:483)
> 
> I don't understand what this means.  Does anyone have insight on it.
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from 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/d/optout.


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

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


Re: Possible bug with (keys some-container) in a try-catch?

2016-04-22 Thread Kevin Downey
keys is lazy, you see the exception at the repl because printing out the
result forces the sequence, but if you don't do anything with the result
then it isn't forced, so no errors.

On 04/22/2016 01:28 PM, Steve Riley wrote:
> I am trying to determine if a container, x, passed to a function, is a
> map or not.
> 
> If I evaluation (keys x) at a REPL prompt, and, x is instantiated list,
> vector or set, I will get a java.lang.ClassCastException that some item
> in x cannot be cast to java.util.Map$Entry.
> 
> On the other hand, if I evaluate (try (keys x) true), the form evaluates
> to true. It will also evaluation to true if I add a catch expression
> with the last value of false. I've tried catching both
> ClassCastException and just Exception.
> 
> (try (/ 10 0) true (catch ArithmeticException _ "divide by zero!"))
> and (try (/ 10 1) true (catch ArithmeticException _ "divide by zero!")),
> for example, evaluate as expected.
> 
> Is this a feature I don't understand?
> 
> Some of you may recognize the 4Clojure problem I am working on. I'm not
> interested in solutions to that problem...just curious about this
> behavior and if there is something I am missing in the try (keys x)
> catch formulation.
> 
> Many 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 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/d/optout.


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

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


Re: [core.logic] What's the difference between "q" and a fresh LVar? Or: "java.lang.ClassCastException: clojure.core.logic.LVar cannot be cast to java.lang.Number"

2016-04-09 Thread Kevin Downey
Check 'lein deps :tree' for conflicting core.logic versions, and delete
the target directory to make sure you don't have old classfiles sitting
around.

On 04/09/2016 04:47 AM, Daniel Ziltener wrote:
> Oops, yes, in my actual code it was both ":db/id", so that's not the
> issue. It's really confusing - today, it works. No idea why. I restarted
> the REPL multiple times to try it, and it never worked. Today it worked
> with the exact same code file on the first try. After getting a very
> strange exception that "clojure.core.logic.core" couldn't be compiled
> due to "clojure.lang.Compiler$CompilerException:
> java.lang.ClassNotFoundException:
> clojure.core.logic.protocols.ITreeConstraint,
> compiling:(clojure/core/logic.clj:1:1)
>java.lang.ClassNotFoundException:
> clojure.core.logic.protocols.ITreeConstraint". I'm thoroughly confused,
> but I hope it will keep working.
> 
> Am Samstag, 9. April 2016 03:45:00 UTC+2 schrieb red...@gmail.com:
> 
> Hard to say, the class cast exception will have more information in it
> that could cast light on the issue. You also are using :id in one
> variation, and :db/id in the other.
> 
> On 04/08/2016 05:46 PM, Daniel Ziltener wrote:
> > Hi clj,
> >
> > I'm trying to do some simple core.logic stuff. My input is a
> vector of
> > maps, which I turn into a source for core.logic using
> > |
> > (defn make-datamap-rel [datapile]
> >   (fn [q]
> > (fn [a]
> >   (to-stream
> >(map #(unify a % q) (flatten datapile))
> > |
> >
> > Now I have written two variants for solving my problem. The first
> works
> > flawlessly:
> > |
> > (defn-find-cat-and-tag-id [pile cat]
> >   (let [datamap-rel (make-datamap-rel pile)]
> > (run*[q]
> > (datamap-rel (partial-map {:id q :category cat}))
> > )))
> > |
> >
> > The second variant throws the ClassCastException:
> > |
> > (defn-find-cat-and-tag-id [pile cat]
> >   (let [datamap-rel (make-datamap-rel pile)]
> > (run*[q]
> >   (fresh [qid]
> > (datamap-rel (partial-map {:db/id qid :category cat}))
> > (==q qid)
> > 
> > |
> >
> > I have no idea why this fails. It just doesn't make any sense. Any
> ideas?
> >
> > Best regards,
> > zilti
> >
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Clojure" group.
> > To post to this group, send email to clo...@googlegroups.com
> 
> > Note that posts from new members are moderated - please be patient
> with
> > your first post.
> > To unsubscribe from this group, send email to
> > clojure+u...@googlegroups.com 
> > For more options, visit this group at
> > http://groups.google.com/group/clojure?hl=en
> 
> > ---
> > You received this message because you are subscribed to the Google
> > Groups "Clojure" group.
> > To unsubscribe from this group and stop receiving emails from it,
> send
> > an email to clojure+u...@googlegroups.com 
> > .
> > For more options, visit https://groups.google.com/d/optout
> .
> 
> 
> -- 
> And what is good, Phaedrus,
> And what is not good—
> Need we ask anyone to tell us these things?
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> 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/d/optout.


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

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

Re: Attempt At Futures

2016-04-09 Thread Kevin Downey
The thing to remember is map is lazy, so you are lazily (on demand)
creating a bunch of futures. Then doseq walks through those futures,
demanding one at a time. You deref the future immediately after doseq
requested it from the lazy-seq and are blocking on its completion then
doseq can move on to demanding the next future be created.

This effectively creates a future and then waits on its completion
before creating the next future. So you end up with everything happening
in sequence.

On 04/08/2016 10:38 PM, Chris White wrote:
> Spoiler alert: I'm really really new to this language so don't expect
> quality code
> 
> In an attempt to see how futures work I'm trying to make code that does
> the following:
> 
>  1. Take a list of sites
>  2. Loop through the sites and retrieve the HEAD content via a future
> for each individual site
>  3. In the main loop once the futures have been created print the HEAD
> content as each future completes
> 
> Now I have this code which I'm getting stuck at:
> 
> 
> (ns cjr-http-test.core
>   (:require [clj-http.client :as client]))
> 
> (defn get-head-response-for-sites
>   [sites]
>   (map (fn [site] (future (client/head site))) sites))
> 
> (doseq [head-data (get-head-response-for-sites '("http://www.google.com;
> "http://www.yahoo.com; "http://www.bing.com;))]
>   (println (deref head-data)))
> 
> (shutdown-agents)
> 
> 
> (Please note I know that the list of sites I'd normally expect to be
> something from a DB/text file. I'm just trying to get it working without
> adding extra things to think about)
> 
> 
> So get-head-response-for-sites is where I'm trying to do #2. It gets me
> a list of futures that I can use. Where  I'm having trouble is that the
> current println line, which is where I'm trying to deal with #3, blocks
> due to deref-ing so it's basically not really all that different than if
> I did it non threading.
> 
> What I (think) I need is something that keeps looping through all the
> futures, checking their status, and println’ing the result when
> something has come back. This will be repeated until all the futures are
> done. The reason I want this is that for example if the first site takes
> 3 minutes to respond I want the other two sites to print their HEAD
> content as soon as it’s retrieved. Here's what I'm trying to figure out
> in order of importance:
> 
>  1. How do I get a constant loop through the futures, println'ing the
> HEAD content as they finish, until all futures are finished?
>  2. Is there a better way to structure this?
>  3. Is there something in Clojure/contrib that's better suited for this?
>  4. Is there a 3rd party library better suited for this?
> 
> Thanks for any and all response. Once again I apologize for the not so
> pro code but some code is better than nothing I hope.
> 
> 
> - Chris White ( @cwgem )
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from 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/d/optout.


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

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


Re: [core.logic] What's the difference between "q" and a fresh LVar? Or: "java.lang.ClassCastException: clojure.core.logic.LVar cannot be cast to java.lang.Number"

2016-04-08 Thread Kevin Downey
Hard to say, the class cast exception will have more information in it
that could cast light on the issue. You also are using :id in one
variation, and :db/id in the other.

On 04/08/2016 05:46 PM, Daniel Ziltener wrote:
> Hi clj,
> 
> I'm trying to do some simple core.logic stuff. My input is a vector of
> maps, which I turn into a source for core.logic using
> |
> (defn make-datamap-rel [datapile]
>   (fn [q]
> (fn [a]
>   (to-stream
>(map #(unify a % q) (flatten datapile))
> |
> 
> Now I have written two variants for solving my problem. The first works
> flawlessly:
> |
> (defn-find-cat-and-tag-id [pile cat]
>   (let [datamap-rel (make-datamap-rel pile)]
> (run*[q]
> (datamap-rel (partial-map {:id q :category cat}))
> )))
> |
> 
> The second variant throws the ClassCastException:
> |
> (defn-find-cat-and-tag-id [pile cat]
>   (let [datamap-rel (make-datamap-rel pile)]
> (run*[q]
>   (fresh [qid]
> (datamap-rel (partial-map {:db/id qid :category cat}))
> (==q qid)
> 
> |
> 
> I have no idea why this fails. It just doesn't make any sense. Any ideas?
> 
> Best regards,
> zilti
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from 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/d/optout.


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

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


Re: Webassembly as a Clojure target platform

2016-04-04 Thread Kevin Downey
I recommend reading up on WebAssembly, a good place to start might be
https://github.com/WebAssembly/design/blob/master/FAQ.md#is-webassembly-only-for-cc-programmers/

In those three paragraphs, it is pretty clear that, at least as it
stands now, wasm is much closer semantically to actual asm than the jvm.
A whole host of facilities that you get both by running on the jvm, and
by compiling to javascript (garbage collection, types, etc) are not
available. No existing Clojure, ClojureScript, or some derivative there
of delivers those things themselves, they all build on some existing
runtime's facilities.

Some additional relevant reading is here:
https://github.com/WebAssembly/design/blob/master/GC.md

On 04/03/2016 11:50 PM, JvJ wrote:
> Is there any plan in the future to have clojure (or some dialect of
> clojure) compile to webassembly?  I can't say for sure if it is the
> "next big thing" for the web, but it is a very interesting concept.
> 
> I suppose that, if Java bytecode could cross-compile to Webassembly, we
> would essentially get this for free, but I'm not sure if that will happen.
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from 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/d/optout.


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

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


Re: Nesting semantics for the thread last operator

2016-03-19 Thread Kevin Downey
They are a logical consequence of the machine.

->> is a mechanical transformation taking a form (->> x (a ... w))
turning it into (a ... w x), and this same mechanical transformation is
in place when nested. You example expands in steps like:

(->> a b c (->> d e f))
(->> (b a) c (->> d e f))
(->> (c (b a)) (->> d e f))
(->> d e f (c (b a)))
(->> (e d) f (c (b a)))
(->> (f (e d)) (c (b a)))
(c (b a) (f (e d)))

you can see each step in the expansion results come from applying the
exact same transformation (this transformation is exactly the ->>
macro). this is the natural result of a recursive style of definition.
While it is technically possible to change the behavior to what you are
suggesting, but it would require special casing ->> and any derivative
of ->>.

So we could have something that always works the same uniform way, or we
could have am ever growing list of special cases.

On 03/19/2016 04:57 PM, Arun Sharma wrote:
> => (clojure.walk/macroexpand-all '(->> a b c (->> d e f)))
> (c (b a) (f (e d)))
> 
> I was hoping that it would return
> 
> (f (e d) (c (b a)))
> 
> Can someone here explain the rationale for the current semantics?
> 
> Context: some of the queries towards the end of this post.
> 
> https://code.facebook.com/posts/1737605303120405/dragon-a-distributed-graph-query-engine/
> 
>  -Arun
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from 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/d/optout.


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

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


Re: Strange problem with input stream starting clojure 1.7.0-alpha6

2016-03-07 Thread Kevin Downey
you can still structure you computation as a reduce, even if it is side
effectful.

(reduce (fn [sink record] (emit sink record) sink) sink source)

There is also a function introduced in 1.7 called "run!"
which is for processing a collection using reduce for side effects.

On 03/07/2016 04:49 PM, shlomivak...@gmail.com wrote:
> Thanks for your reply, 
> 
> ArchiveReader is actually an Iterator for ArchiveRecord
> (see 
> https://github.com/iipc/webarchive-commons/blob/master/src/main/java/org/archive/io/ArchiveReader.java#L51).
> I also tried to explicitly do (iterator-seq (.iterator warc-value)) but
> got the same "got 0" everywhere.
> 
> However, your remark about the lazy-seq was indeed very helpful. I tried
> to use a loop instead of doseq, and it did the trick!
> I also succeeded in using coll-reduce instead of the explicit loop.
> However, it seems odd to use it, since I am really only doing a
> side-effecting loop (emitting key/values for hadoop's reducer) rather
> than making a transformation..
> 
> Is there a nicer (idiomatic core) way to treat non-chunk-able java
> iterables other than an explicit loop for side-effects?
> 
> 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 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/d/optout.


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

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


Re: Strange problem with input stream starting clojure 1.7.0-alpha6

2016-03-07 Thread Kevin Downey
Hard to say, I can't think of a change that would directly change how
the shaed code would work.

The "ArchiveReader" type hint on "warc-value" seems to be incorrect,
because it is used as a seq by "doseq". Assuming this is the correct
ArchiveReader
(http://crawler.archive.org/apidocs/org/archive/io/ArchiveReader.html) I
don't see how it could be a seq. So warc-value must be a seq, and is
likely to be lazy-seq. I wonder if you could be running in to a problem
with chunking or something(maybe you have a lazy-seq that needs to be
consumed strictly one after another, but a chunked seq would realize 32
at a time). "iterate" and "range" I think both had changes around then
so I would look at how that seq is constructed. If this is the issue,
you may want to look at using the clojure.core.protocols/CollReduce
protocol to process whatever the warc-value seq is based on instead of
using a seq.

On 03/07/2016 03:25 PM, shlomivak...@gmail.com wrote:
> Hey clojurians,
> 
> I am using a java library that reads WARC files (an internet archive
> format) to use with hadoop. 
> 
> I was recently motivated to upgrade this project's clojure from 1.6 to
> 1.8 (to be able to use the recent (wonderful!) cider), and I got quite a
> strange behavior, that I managed to reduce to a simple example (on
> github
> )
> 
>   
> (defn mapper-map [this ^Text key ^ArchiveReader warc-value ^MapContext
> context]
> 
> (doseq [^ArchiveRecord r warc-value]
>   (let [header (.getHeader r)
>   mime (.getMimetype header)]
>   (if (plain-text? mime)
>   (println "got " (.available r))
>   
> 
>   
> 
> 
> Using any clojure version prior to 1.7.0-alpha6 (meaning, alpha5 and
> below), this code works great, and I get plenty of different "got %d"
> printed to the console with different sizes.
> 
> However, upgrading to 1.7.0-alpha6 and above, I am getting constant "got
> 0" for every record in the file, and nothing (obviously) gets computed.
> 
> I tried to see if I can find the culprit
> using 
> https://github.com/clojure/clojure/compare/clojure-1.7.0-alpha5...clojure-1.7.0-alpha6
> and couldnt find an obvious problem. I thought I might ask the list for
> pointers before I deep dive into this any further. 
> 
> If you wish to help with this problem by checking it on your machine,
> you could clone https://github.com/vadali/warc-cc/tree/upgrade-clojure
> (use upgrade-clojure branch), get the example file into the root dir of
> the cloned project using 
> 
>s3cmd get
> s3://aws-publicdatasets/common-crawl/crawl-data/CC-MAIN-2013-48/segments/1387345775423/wet/CC-MAIN-20131218054935-00092-ip-10-33-133-15.ec2.internal.warc.wet.gz
> 
> and run using lein test warc-cc.example.
> 
> 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 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/d/optout.


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

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


Re: #'lamina.core. - No implementation of method: :enqueue for class: nil

2016-03-06 Thread Kevin Downey
On 03/05/2016 10:18 PM, Nasko wrote:
> I am trying to implement a simple asynchronous chat service using Aleph
> and Lamina. However, it looks like the enqueue function coming from
> lamina cannot be implemented and causes an exception. This is what my
> chat function looks like:
> |
> (defn chat [ch request]
>   "View handler that handles a chat room. If it's not
>   a websocket request then return a rendered html response."
>   (let [params(:route-paramsrequest)
> room   (:room params)]
> (if(:websocket request)
>   (chat-handler ch room)
>   (enqueue ch (wrapped-sync-app request)
> |
> I don't understand why the value of (wrapped-sync-app request) is nil.
> Any feedback would be helpful.

Hard to say, since you don't give a definition for the wrapped-sync-app
function. Some google and it shows up in a few example apps as some kind
of ring handler. If you are using compojure (maybe other routing
libraries) returning nil is what it does by default if no routes match a
give request (as a result of how it determines if a route matches).

But looking at your subject line, given that error it is likely 'ch' is
nil, not the result of calling wrapped-sync-app. I would sprinkle
printlns liberally throughout.

As an aside, your docstring (if you intend it to be a docstring) is in
the wrong place. Docstrings go before the argument vector if you want
them to be accessible via 'doc' in the repl.
https://github.com/jonase/eastwood has a linter that catches this kind
of thing.

> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from 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/d/optout.


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

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


Re: Implementing Clojure

2016-03-01 Thread Kevin Downey
On 02/28/2016 10:40 AM, evins.mi...@gmail.com wrote:
> 
> 
> On Sunday, February 28, 2016 at 4:13:23 AM UTC-6, puzzler wrote:
> 
> Yes, unfortunately, Clojure doesn't have an actual spec.  The lack
> of a spec probably helps keep the language more "agile", but I know
> several people who automatically discount the language because of that.
> 
> 
> I don't discount it; it's a good language with a good ecosystem. A spec
> would be nice when writing an implementation, though. Even more
> convenient would be a suite of compliance tests. I can use the linked
> reference docs, of course, but it's more work to slog through them, and
> is exactly what I was hoping to avoid.

The lack of a spec combined with a goal of "embracing the host" and
having two implementations you might choose to emulate (clojure and
clojurescript) can lead to a lot of confusion. Clojure and ClojureScript
have differences, so if you are targeting a new runtime, do you just
sort of aim between the two and add your own set of hosting embracing
mechanisms and tradeoffs? Clojure came before ClojureScript, and I have
alot more experience with it, so my sort of default stance is the
trade-offs and different things ClojureScript does are are compromises
due to compiling to javascript, and Clojure(JVM) is the best. But other
people point out that ClojureScript is newer, so is based on ideas that
did not appear in Clojure until after it had already go through several
releases. So ClojureScript is more refined and the best.

The definitive reference for both ClojureScript and Clojure remains
their respective compilers. The ClojureScript compiler is, I think more
approachable because it is written in Clojure and outputs Javascript. I
think because of this, getting ClojureScript up and running on a new
backend is a much more approachable target (someone did a lua backend at
one point, and I know a few people who have kicked around an elisp
backend). This kind of drives me nuts, because as I said, Clojure on the
JVM seems more like the "real" Clojure to me.

Nicola Mometto actually maintains a Clojure compiler written in Clojure
https://github.com/clojure/tools.emitter.jvm, but turning Clojure into
JVM bytecode is still more complex than emitting javascript.

> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from 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/d/optout.


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

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


Re: Compile time constants not generated with the appropriate type.

2016-02-24 Thread Kevin Downey
On 02/24/2016 02:53 AM, Michael du Breuil wrote:
> The following (this is interop with libgdx if anyone is curious,
> hud-corner-top-left is a delayed TextureRegion
> 
> (.draw batch ^TextureRegion @hud-corner-top-left
>(float -199)
>(float -32))
> 
> Which yields the following:
>  
> .draw((TextureRegion)((IFn)const__5.getRawRoot()).invoke(const__41.getRawRoot()),
>  
>   RT.uncheckedFloatCast(-199L), 
>   RT.uncheckedFloatCast(-32L));null;((SpriteBatch)batch)

I think the best response to this is a far more polite than I can manage
"so what?". Which is not to imply that was meant to be impolite, just as
a way to prompt for more, it can seem impolite.

Bytecode is a means to end, the execution of Clojure on the JVM. So in
some sense, who cares what it looks like, as long as Clojure is running
well. The most common answer to "Why does the bytecode look like this?"
is going to be something like "It was the easiest bytecode to generate
for the given Clojure code". What you really should be asking yourself
here is, why when you call the function `float`; which is a Clojure
function, held in a var, represented as an Object implementing IFn, does
all that var lookup, and IFn invocation code disappear and is replaced
with one call to the static uncheckedFloatCast method.

Is this a quantifiable issue, or an aesthetic issue to you?

If it is an aesthetic issue, I would not expect other people to care
that much about it one way or another. Which means if you want to change
it, you need to write the patch yourself, and hope the patch gets
reviewed and accepted. If you do end up writing a patch, please also add
uncheckedFloat to Intrinsics.java.

If it is a quantifiable issue (these are usually performance issues),
many more people will care about it, and someone else may care enough to
write a patch. I would be really surprised if this effects performance
at all, since it seems like the kind of a jit would eat for breakfast,
but I am far from an expert, so who knows.


> 
> Unless I'm missing something on how to interpret bytecode :) I can post
> more source if you want but that is one interop call and its generated
> code, the rest will look the same.
> 
> On Wednesday, February 24, 2016 at 3:44:11 AM UTC-7, Nicola Mometto wrote:
> 
> Can you post the code?
> 
> > On 24 Feb 2016, at 10:26, Michael du Breuil
>  wrote:
> >
> > I have some interop code that I have carefully specified all the
> arguments to be in the correct type (IE the function signature takes
> 3 floats, so I cast everything to float so that I can avoid
> reflection). What I'm surprised by is compile time constants such as
> (float -173) or (float 8.5) are not saved as the correct primitive
> type, using jd-gui I see that these were actually turned into
> RT.uncheckedFloatCast(-173L), and RT.uncheckedFloatCast(8.5D),
> respectively. Why isn't this just saved as a the correct primitive
> directly in the generated bytecode? This is with clojure 1.8.0
> >
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Clojure" group.
> > To post to this group, send email to clo...@googlegroups.com
> 
> > Note that posts from new members are moderated - please be patient
> with your first post.
> > To unsubscribe from this group, send email to
> > clojure+u...@googlegroups.com 
> > For more options, visit this group at
> > http://groups.google.com/group/clojure?hl=en
> 
> > ---
> > You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> > To unsubscribe from this group and stop receiving emails from it,
> send an email to clojure+u...@googlegroups.com .
> > For more options, visit https://groups.google.com/d/optout
> .
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from 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/d/optout.


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

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to 

Re: (type ...) vs (class ...)

2016-02-12 Thread Kevin Downey
On 02/12/2016 01:37 PM, Alan Thompson wrote:
> Hey - Just saw something on the clojure.core/type function:
> 
> 
> 
> (defn type
>   "Returns the :type metadata of x, or its Class if none"
>   {:added "1.0"
>   :static true}
>   [x]
>   (or (get (meta x) :type) (class x)))
> 
> 
> 
> I have never seen this before, and it appears the :type metadata is not
> used in the clojure.core source code itself.  Is this ever used for
> anything or is it just a vestigial remnant from long ago?
> 
> Alan

It is used by the printing system (see core_print.clj). If I write a
multimethod that is dispatching on type/class whatever, `type` is the
first function I reach for.

> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from 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/d/optout.


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

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


Re: (type ...) vs (class ...)

2016-02-12 Thread Kevin Downey
On 02/12/2016 01:47 PM, Kevin Downey wrote:
> On 02/12/2016 01:37 PM, Alan Thompson wrote:
>> Hey - Just saw something on the clojure.core/type function:
>>
>>
>>
>> (defn type
>>  "Returns the :type metadata of x, or its Class if none"
>>  {:added "1.0"
>>  :static true}
>>  [x]
>>  (or (get (meta x) :type) (class x)))
>>
>>
>>
>> I have never seen this before, and it appears the :type metadata is not
>> used in the clojure.core source code itself.  Is this ever used for
>> anything or is it just a vestigial remnant from long ago?
>>
>> Alan
> 
> It is used by the printing system (see core_print.clj). If I write a
> multimethod that is dispatching on type/class whatever, `type` is the
> first function I reach for.

Oh, my mistake, print-method actually re-implements `type`, with the
added restriction that is has to be a keyword.

> 
>>
>> -- 
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clojure@googlegroups.com
>> Note that posts from new members are moderated - please be patient with
>> your first post.
>> To unsubscribe from 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
>> <mailto:clojure+unsubscr...@googlegroups.com>.
>> For more options, visit https://groups.google.com/d/optout.
> 
> 


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

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


Re: top-level lets or private globals

2015-08-26 Thread Kevin Downey
On 8/25/15 12:06 AM, Kurt Sys wrote:
 I'm refering to a few posts in an old thread:
 https://groups.google.com/d/msg/clojure/r_ym-h53f1E/RzUdb5oYeX4J
 
 What really puzzles me is that it doesn't seem to be generally
 regarded as idiomatic Clojure style to just use top-level (let)s for
 your private globals.
 
  
 So, here's the question: what's considered best practice in Clojure
 (what is idiomatic in Clojure): using private (namespace-scoped) globals
 variables or one big let over all (or at least, most) defns in a
 namespace? And why :)?
 

I have found the access control stuff in Java to be an incredible pain.
When attempting to compose a larger system from the parts. Generally
everything is compulsively private, so if an api doesn't exactly expose
what you want, you either have to write what you want completely from
scratch, or use reflection to get a the bits you want to compose in to
what you want.

Avoid private as much as you can, and if you think you can't, ask
yourself, is this really private or is it a bit of instance state that
really shouldn't be a global def anyway.

When I make the case for making everything public generally the argument
I get back is about api evolution and how do users know what the stable
parts of the api are? I think this concern is a result of using
languages and tooling that don't do a good job of distinguishing source
code used to build an artifact and an artifact. Clojure tooling is
mostly built on top of maven, which does an excellent job of
distinguishing between the two. If you build your code using a jar out
of maven with a fixed version of 1.0.1, unless you change your
dependency you will always get the same code, so who cares what the
author decided is the stable public api and what is the private api.
Anything that you can make use of you can, and it will be the same until
you change it.

The answer to that is generally something about semantic versioning,
which due to every high profile project that uses it having at some
point a heated argument about what does and does not constitute a patch
release, who knows what you getting anyway.

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

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


Re: Reflection warnings in async/go-loop

2015-07-23 Thread Kevin Downey
Regardless of the outcome of the type issue, this code is doing blocking
io inside a go block, which should be avoided. Consider using `thread`
and `loop`, which would also likely work around the type hinting issue
because it would avoid the state machine transform. The code already
using the blocking version of channel put (!!) which shouldn't be used
inside a go block, but is fine for use outside of it.

On 7/23/15 9:38 AM, Adam Krieg wrote:
 Hi all,
 
 I have an issue with references to closed over references outside the go
 block not resolving types.  The first function resolves fine.  The
 second one cannot resolve (.readLine buf-reader)
 
 (defn parser-process-good
   Consumes lines from a file, transforms entries of interest and puts them 
 on a channel
   [^String file pred xform out-channel]
   (let [buf-reader (BufferedReader. (FileReader. file))]
 (async/go-loop [^BufferedReader reader buf-reader]
   (when-let [line (.readLine reader)]
 (do
   (if (pred line) (async/!! out-channel (xform line)))
   (recur reader))
 ))
 ))
 
 (defn parser-process-bad
   Consumes lines from a file, transforms entries of interest and puts them 
 on a channel
   [^String file pred xform out-channel]
   (let [buf-reader ^BufferedReader (BufferedReader. (FileReader. file))]
 (async/go-loop []
   (when-let [line (.readLine buf-reader)]  ;reference to field or no args 
 method call readLine cannot be resolved
 (do
   (if (pred line) (async/!! out-channel (xform line)))
   (recur))
 ))
 ))
 
 
 The closed Jira item I found was ASYNC-28, but it was closed as not
 reproducible.  I'm getting this using 0.1.346.0-17112a-alpha.
 
 
 
 
 
 -- 
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from 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
 mailto:clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.


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

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


Re: lazy list comprehension

2014-06-27 Thread Kevin Downey
On 6/27/14, 8:01 AM, Glen Rubin wrote:
 I have a list that I want to combine in some way with an incremented list, 
 so I was trying to write a for expression like this:
 
 (for [i '(my-list-of-crap), j (iterate inc 0)] (str i j))

the equivalent of this code written using map and mapcat is

(mapcat (fn [i] (map (fn [j] (str i j)) (iterate inc 0
'(my-list-of-crap))


so for every element of '(my-list-of-crap) you are creating an infinite
seq of numbers (iterate inc 0) and creating a string of each element of
'(my-list-of-crap) paired with each element of (iterate inc 0),
obviously an infinite seq of things, which will certainly take all your
memory

the main thing to realize is the nesting behaviour of for, and the
mechanical translation of for in to an inner call to map wrapped in
calls to mapcat

 
 
 The problem with this is that it yields an out of memory area.  I assume 
 this is b/c of my poor use of the iterate fn.  How can I do this in a lazy 
 way?  So that iterate only produces as many items as is needed to match the 
 number of items I have in '(my-list-of-crap).  Thanks!
 


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

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


Re: test.check, quickcheck concurrency

2014-03-31 Thread Kevin Downey
On 3/28/14, 9:48 PM, Brian Craft wrote:
 Re: John Hughes' talk at clojure/west, at the end he did a fairly 
 incredible demo of testing concurrency. It doesn't look like this was 
 implemented in test.check (or I'm not finding it). Are there any plans?
 

from my understanding his approach is using quickcheck to generate
histories and then check those histories for linearizability.

maybe some combination of test.check and
https://github.com/aphyr/knossos could do that.

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

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


Re: let bindings

2014-01-20 Thread Kevin Downey
On 1/20/14, 12:38 PM, Andy Smith wrote:
 Hi,
 
 (let bindings form) is a special form. As I understand it, let can be 
 reformulated in terms of functions e.g.
 
  (let [x 2] (* x 20)) equivalent to ((fn [x] (* x 20)) 2)
 (let [x 3 y (* x x)] (- y x)) equivalent to ((fn [x] ((fn [x y] (- y x)) x 
 (* x x))) 3)
  
 So if we can always reformulate in this was, why cant let be implemented as 
 a macro rather than a special form?
 
 Where have I gone wrong in my understanding here?
 
 Andy
 

Clojure has made several choices which make implementing let via macro
expanding to function application a nonstarter:

1. Clojure is compiled.
  There is no interpreter for clojure, all clojure code is compiled to
bytecode before executing, even at the repl. So the compiler needs to be
fast for interactive work and cannot spend a lot of time in optimizing
passes typically used to avoid function call overhead for every local
name binding.

2. Debuggers
  There are a number of nice debugging tool kits for Java/the JVM. They
operating by reading metadata (like local names) from class files.
Because clojure maps let bound locals to the same JVM construct as Java,
you can re-use Java debuggers for Clojure.

3. JVM interop
  The JVM does not have TCO built in, so in order to provide general
constant space tail calls you must do extensive code transforms(breaks 1
and 2) or use your own calling convention(method call and trampoline,
instead of just a method call) which would complicate interop. Clojure
instead provides less general construct loop/recur for constant space
iteration. loop/recur is local to a function body, so if let macro
expanded to a fn call, you would not be able to recur from inside a let.

So while technically possible (there are scheme impls on the jvm that
may) Clojure does not expand let in to a fn call

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

-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
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: odd failure on recursive use of protocol member

2013-12-10 Thread Kevin Downey
extend mutates some state (the protocol definition), so what is happen
here is comp is returning a new function built from the value of the
rest-serialize var (the protocol function before the extend changes it)
and the value of the deref var.

I have not verified this, but I suspect if you use (fn [x]
(rest-serialize (deref x))) instead of the comp version, you will get
the behaviour you expected

On 12/10/13, 11:50 AM, Michael Blume wrote:
 I have a protocol RestSerializable to represent data that can be serialized 
 to json from a REST interface.
 
 (defprotocol RestSerializable
   (rest-serialize [this]
Convert to something Cheshire can JSONify))
 
 By default, things are left alone
 
 (extend Object
   RestSerializable
   {:rest-serialize identity})
 
 But I want atoms and the like to be transparent when serialized
 
 (extend clojure.lang.IDeref
   RestSerializable
   {:rest-serialize (comp rest-serialize deref)})
 
 I would expect this to mean that, say, 
 
 (- 42 atom atom atom atom rest-serialize)
 
 would just unwrap to 42, but in fact it only unwraps the outer atom and 
 leaves the inner ones alone.
 
 Here's where it gets weird though. If I just evaluate the extend 
 clojure.lang.IDeref form again, rest-serialize suddenly gains the ability 
 to unwrap *two* layers of atoms. Eval it again and it can unwrap *three*. 
 Kinda feels like the exercises in Little Schemer when they're building up 
 to the Y Combinator.
 
 Here's my REPL session demonstrating this (not shown, but I've verified 
 this behavior is the same in Clojure 1.5.1 and Clojure 1.6.0-alpha3)
 
 $ lein repl
 nREPL server started on port 46049 on host 127.0.0.1
 REPL-y 0.2.1
 Clojure 1.5.1
 Docs: (doc function-name-here)
   (find-doc part-of-name-here)
   Source: (source function-name-here)
  Javadoc: (javadoc java-object-or-class-here)
 Exit: Control+D or (exit) or (quit)
  Results: Stored in vars *1, *2, *3, an exception in *e
 
 user= (defprotocol RestSerializable
   #_=   (rest-serialize [this]
   #_=Convert to something Cheshire can JSONify))
 RestSerializable
 user= 
 
 user= (extend Object
   #_=   RestSerializable
   #_=   {:rest-serialize identity})
 nil
 user= 
 
 user= (extend clojure.lang.IDeref
   #_=   RestSerializable
   #_=   {:rest-serialize (comp rest-serialize deref)})
 nil
 user= (- 7 atom atom atom rest-serialize)
 #Atom@56153406: #Atom@a0aa211: 7
 user= (- 7 atom atom atom rest-serialize)
 #Atom@3c19a5b0: #Atom@37cce4a3: 7
 user= (- 7 atom atom atom rest-serialize)
 #Atom@9f6e629: #Atom@308092db: 7
 user= (extend clojure.lang.IDeref
   #_=   RestSerializable
   #_=   {:rest-serialize (comp rest-serialize deref)})
 nil
 user= (- 7 atom atom atom rest-serialize)
 #Atom@7fb48906: 7
 user= (- 7 atom atom atom rest-serialize)
 #Atom@41e224a5: 7
 user= (extend clojure.lang.IDeref
   #_=   RestSerializable
   #_=   {:rest-serialize (comp rest-serialize deref)})
 nil
 user= (- 7 atom atom atom rest-serialize)
 7
 user= (quit)
 Bye for now!
 


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



signature.asc
Description: OpenPGP digital signature


Re: core.logic merge substitutions map?

2013-11-18 Thread Kevin Downey
https://github.com/sonian/Greenmail/blob/master/src/clj/greenmail/db.clj#L98-L126
has an example, using clojure.core.logic/all to make a goal which is a
conjunction of the clojure.core.logic/== goals

On 11/16/13, 5:04 PM, Mark wrote:
 d'oh!  Answering my own question:  Just compose the unify functions a la 
 (unify (unify a v1 (:v1 r) v2 (:v2 r))
 
 I have a feeling there is a library function/macro that would make this 
 less messy but I can't find it from the cheatsheet.
 
 On Saturday, November 16, 2013 10:31:50 AM UTC-8, Mark wrote:

 I stumbled across Timothy Baldridge's excellent video 
 http://www.youtube.com/watch?v=HHZ8iqswiCwexplaining how to incorporate 
 data sources into core.logic.  It reinvigorated my interest in using 
 core.logic to query SQL RDBMS.  I'm stumbling on a pretty simple thing, I 
 think.  I've got a table that has three columns, a single primary key 
 column and two value columns.  Using the pattern Tim outlines in his video, 
 I've got a relation function that takes three parameters, one for each 
 column and I'm trying to work through the case where the primary key is 
 ground and the value columns are lvars.  This translates to a query of the 
 form SELECT v1, v2 FROM t WHERE pkey=?.  Of course, this returns two values 
 that must be unified.  That's where I'm stuck.

 I know I want to return a substitution map, but I have two lvars to 
 unify.  How do I merge the two substitution maps?

 Sample code:
 (defn pkey-v1-v2-o [pkey v1 v2]
   (fn [a]
 (let [pkey (walk a pkey)
   v1 (walk a v1)
   v2(walk a v2)]
   (condp = [(not (lvar? pkey))
 (not (lvar? v1))
 (not (lvar? v2))]
 [true false false ] (to-stream 
   (let [r (first (query [SELECT v1, v2 FROM T 
 WHERE pkey=? pkey]))]
 (some-merge-fn (unify a v1 (:v1 r))
(unify a v2 (:v2 r)

 


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



signature.asc
Description: OpenPGP digital signature


Re: Surprising behaviour related to records, protocols and AOT

2013-10-28 Thread Kevin Downey
I don't know about the rest of this thread, but loom seems to suffer
from what I've outlined in
http://dev.clojure.org/jira/browse/CLJ-322?focusedCommentId=32246page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-32246
pulling in the interface that the protocol generates instead of the
protocol.

On 10/26/13, 5:42 PM, Aysylu Greenberg wrote:
 I was wondering if anybody has found a solution to this problem. I'm 
 experiencing the same issue in this project https://github.com/aysylu/loom. 
 If you disable aot (this 
 linehttps://github.com/aysylu/loom/blob/master/project.clj#L9), 
 the tests start failing with a similar error message.
 
 Thanks,
 Aysylu
 
 On Thursday, April 18, 2013 8:27:53 AM UTC-4, Ragnar Dahlén wrote:

 Thank you for your explanation. I also suspect there is some subtle
 issue with the class file being used by the different constructors.

 However, I would be surprised if this behaviour is intended, and that 
 the 'hackery' you proposed is the only, and prefered way of solving this.

 To better illustrate the core issue, I updated the example slightly
 as follows:

 Premise: 
 defrecordissue.arecord and defrecordissue.protocol constitute some
 library.

 1. defrecordissue.arecord defines a record type, and a function that
will return an instance of the record:

 (ns defrecordissue.arecord)

 (defrecord ARecord [])

 (defn make-record
   []
   (-ARecord))

 2. defrecordissue.protocol defines a protocol, and extends it to the
record type defined in 1. It also defines a public function
intended to be used by libraries:

 (ns defrecordissue.aprotocol
   (:require [defrecordissue.arecord])
   (:import [defrecordissue.arecord ARecord]))
  
 (defprotocol AProtocol
   (afn [this]))
  
 (extend-protocol AProtocol
   ARecord
   (afn [this] 42))

 (defn some-public-fn
   []
   (afn (defrecordissue.arecord/make-record)))

 3. defrecordissue.consumer is a consumer of the library, knows
nothing of any protocols or records, but only wants to call a
function thats part of the public api:

 (ns defrecordissue.consumer
   (:require [defrecordissue.aprotocol]))
  
 (defrecordissue.aprotocol/some-public-fn)

 This fails with the same root cause.

 I've created a new branch for this in the GitHub repo.

 https://github.com/ragnard/defrecordissue/tree/more-realistic

 /Ragge

 On Thursday, 18 April 2013 12:19:35 UTC+1, Andrew Sernyak wrote:

 I guess extend-type does changes only to generated java class and the var 
 defrecordissue.arecord-ARecord 
 contains the 'old' version of ARecord constructor. Obviously it would be 
 weird for defprotocol to change the variable in another namespace. 
 Especially when you can extend a record from anywhere.

 So If you want to create a record that implements your protocol via var 
 from record namespace, you should do some hackery to update that variable. 
 I've done a pull-request for you, but using direct constructor will be more 
 idiomatic

 ;
 ; this won't work unless you update manualy a variable -ARecord in the 
 namespace
 ;
 ;(defrecordissue.aprotocol/afn (defrecordissue.arecord/-ARecord))
 ; 
 ; like
 (defmacro from-ns[nmsps  body] 
   launches body from namespace
   `(binding 
  [*ns* (find-ns ~nmsps)] 
(eval
   (quote (do ~@body)
 (from-ns 'defrecordissue.arecord 
  (import '(defrecordissue.arecord.ARecord))
  (alter-var-root 
('-ARecord (ns-publics 'defrecordissue.arecord)) 
(fn[x] (fn[] (new ARecord)
 (println  (defrecordissue.aprotocol/afn 
 (defrecordissue.arecord/-ARecord)))
 ; 42


 ndrw 


 


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



signature.asc
Description: OpenPGP digital signature


Re: Clojure On Java Friendly Microcontrollers, Beaglebone, etc

2013-09-05 Thread Kevin Downey
Fiddling with the pins via the filesystem is where I started, but PyBBIO
mmaps the pins so you can flip them by reading/writing directly to
memory, and I ported that to clojure using
https://github.com/hiredman/beaglebone-jni-utils and
https://github.com/hiredman/blackbox/blob/master/src/blackbox/gpio.clj.

I have not done anything with I2C, the last thing I did was work on
wiring the beaglebone to a mini arduino driving an ultrasonic range
finder. I used a java library, I think was called rxtx, for reading data
from the serial port.

On 9/4/13 2:45 PM, Jeremy Wright wrote:
 Thanks for the slide deck Kevin. I'm not sure I've found all the slides 
 yet, but it's great information. Do you have any links or information on 
 Clojure robotics work you've done since the 2012 Conj? Any thoughts on 
 using the GPIO pins through the file system versus using I2C (or maybe SPI)?
 
 On Wednesday, September 4, 2013 3:59:33 PM UTC-4, red...@gmail.com wrote:

 I also have a vertigo inducing slide deck to go with the robot lightening 
 talk (which I didn't end up using) 
 http://thelibraryofcongress.s3.amazonaws.com/conj2012-robot/index.html 

 On Sunday, September 1, 2013 8:21:46 PM UTC-7, Jeremy Wright wrote:

 Here are some updates on my own research.

1. This 
 posthttp://thelibraryofcongress.s3.amazonaws.com/beagleboneled.htmlis a 
 little over a year old, but has the type of information on the 
BeagleBone I'm looking for. It covers doing some simple I/O using 
 Clojure. 
The author states that he's unsure what he's doing on the hardware side 
 of 
things, but it's a start.
2. This 
 posthttp://nakkaya.com/2011/03/15/clojure-on-the-beagleboard/says it's 
 easy to get Clojure working on the Beagleboard, but is a couple 
of years old and doesn't give too much detail. I do like that the author 
does some benchmarking that could be adapted to the BeagleBone Black 
 though.
3. This 
 posthttp://blog.gonzih.me/blog/2012/09/07/clojure-on-beaglebone-openjdk-vs-oracle-embedded-jre-benchmark/is
  about a year old, and gives a benchmark comparison of OpenJDK vs 
Oracle's Embedded JRE on a BeagleBone.
4. Videos of Kevin Downey (less than a year old) showing a robot 
using Clojure on a BeagleBone. He gives some insight into how to make 
 using 
the Bone's I/O system in Clojure a little easier.
1. Video 1 of 3 https://www.youtube.com/watch?v=XMIKfOmAMjQ
   2. Video 2 of 3 https://www.youtube.com/watch?v=QPN2DFrlrYo
   3. Video 3 of 3 https://www.youtube.com/watch?v=iQK9p0XV2IY
5. Kevin Downey's Beaglebone robot code on 
 Githubhttps://github.com/hiredman/blackbox
.
6. Kevin Downey mentioned 
 clojure-jnahttps://github.com/Chouser/clojure-jna which 
should make working with native code (to do I/O) on the Bone a little 
easier. The clojure-jna code on GitHub is about 4 years old though, and 
 I 
may have read something about a newer replacement on this mailing list. 
 I 
can't remember for sure though.

 That's what I've found so far. The information has some age on it and is 
 focused on the older BeagleBone and Beagleboard. It's good information to 
 get started with though I think.

 On Saturday, August 31, 2013 11:13:59 PM UTC-4, Jeremy Wright wrote:

 I recently watched Carin Meier's OSCON talk The Joy of Flying Robots 
 with Clojure http://www.youtube.com/watch?v=Ty9QDqV-_Ak and it made 
 me wonder about Clojure on embedded systems. A quick search on this list 
 didn't turn up much so I thought I'd ask. How much work has been done with 
 Clojure on either Java friendly microcontroller systems (i.e. 
 Systronixhttp://www.systronix.com/), 
 or on something like a Beaglebone or Beagleboard? I'm very new to Clojure, 
 so I don't yet understand the challenges that Clojure would face trying to 
 run on a system that may not support all the JVM's features.

 Any thoughts on this? Any links you can give me on what's been/being 
 done?

 Thanks.


 


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



signature.asc
Description: OpenPGP digital signature


Re: ANN: clj-tuple, efficient small collections

2013-08-26 Thread Kevin Downey
A Tuple protocol that defines get0 get1 get3 etc for fast element access
that doesn't tie you to using field names might be a good idea.

On 8/25/13 9:35 AM, Zach Tellman wrote:
 I don't think so, even the existence of all the Tuple* types are an 
 implementation detail, and you'd need to hint it as the right one to get 
 sane performance.  (nth t n) has good performance, you should prefer that.
 
 On Saturday, August 24, 2013 8:15:40 PM UTC-7, Ben wrote:

 Are the element names .e0, .e1 etc. considered part of the public 
 interface of tuple objects?


 On Sat, Aug 24, 2013 at 7:38 PM, Zach Tellman ztel...@gmail.comjavascript:
 wrote:

 I just pulled some code I wrote while trying to optimize 'memoize' into 
 its own library: https://github.com/ztellman/clj-tuple.  It only has the 
 one function, so I assume no one will need too much explanation.  However, 
 there may still be room for performance improvements, so if anyone wants to 
 take a stab, pull requests are welcome.

 Zach

 -- 
 -- 
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clo...@googlegroups.comjavascript:
 Note that posts from new members are moderated - please be patient with 
 your first post.
 To unsubscribe from this group, send email to
 clojure+u...@googlegroups.com javascript:
 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+u...@googlegroups.com javascript:.
 For more options, visit https://groups.google.com/groups/opt_out.




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

  
 


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



signature.asc
Description: OpenPGP digital signature


Re: ANN: clj-tuple, efficient small collections

2013-08-26 Thread Kevin Downey
looking at clj-tuple a call to (nth some-tuple 0) turns in to a case
dispatch

(case idx
  0 e0
  ...)

or something.

if you have a Tuple protocol with a function like get0 you can avoid the
overhead of the case there, and the jvm has a better change of inlining
the rest away.

for hotspot to optimize the case away is much more challenging (requires
the jit to track the index value, which it may actually do?) than
optimizing a method which is basically just a java getter (very common
code pattern the jvm sees all the time).

the last time I looked in to this was before criterium was available, so
I don't have proper jvm benchmarking for it, but I do believe a Tuple
protocol with something like get0 will be faster than (nth ... 0).

the down side of the get0 approach is you cannot destructuring that way.

On 8/26/13 11:02 AM, Asim Jalis wrote:
 I believe this is what clj-tuple is doing under the hood with macros.
 
 On Aug 26, 2013, at 10:38 AM, Kevin Downey redc...@gmail.com wrote:
 
 A Tuple protocol that defines get0 get1 get3 etc for fast element access
 that doesn't tie you to using field names might be a good idea.

 On 8/25/13 9:35 AM, Zach Tellman wrote:
 I don't think so, even the existence of all the Tuple* types are an 
 implementation detail, and you'd need to hint it as the right one to get 
 sane performance.  (nth t n) has good performance, you should prefer that.

 On Saturday, August 24, 2013 8:15:40 PM UTC-7, Ben wrote:

 Are the element names .e0, .e1 etc. considered part of the public 
 interface of tuple objects?


 On Sat, Aug 24, 2013 at 7:38 PM, Zach Tellman 
 ztel...@gmail.comjavascript:
 wrote:

 I just pulled some code I wrote while trying to optimize 'memoize' into 
 its own library: https://github.com/ztellman/clj-tuple.  It only has the 
 one function, so I assume no one will need too much explanation.  
 However, 
 there may still be room for performance improvements, so if anyone wants 
 to 
 take a stab, pull requests are welcome.

 Zach

 -- 
 -- 
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clo...@googlegroups.comjavascript:
 Note that posts from new members are moderated - please be patient with 
 your first post.
 To unsubscribe from this group, send email to
 clojure+u...@googlegroups.com javascript:
 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+u...@googlegroups.com javascript:.
 For more options, visit https://groups.google.com/groups/opt_out.



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


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

 


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



signature.asc
Description: OpenPGP digital signature


Re: What are the phases of the Clojure compiler?

2013-08-06 Thread Kevin Downey
On 8/6/13 2:23 PM, gixxi wrote:
 Hi there,
 
 I wanne dive a bit more deep into the clojure compiler and I wonder whether 
 it follows the std procedure for compiled languages
 
 Character Stream - Scanner (lexical analysis) - Token Stream
 Token Stream - Parser (syntax analysis) - Parse Tree
 Parse Tree - Semantic Analysis - Abstract Syntax Tree (AST)
 (Optional) AST - Machine Independent code improvement) - Modified AST
 Modified AST - Target Code Generation - Target Language (here Java Byte 
 Code)
 
 Thanks for hints and references regarding this topic. Literature on this 
 topic (e.g.  O'Reilly Clojure Programming by Emerick, Carper et Grand) 
 states that clojure programs are written using clojure datastructures and 
 directly represent an AST. But a task of semantic analysis is to check 
 whether a statement given in the programming language is valid in terms of 
 the programming language semantics. So some component has to check whether 
 the symbol foo in the list (foo baz) denotes either a static function 
 applicable to a string literal or a instance function of the string literal 
 itself. Which component serves this job?
 
 thanks  cheers
 
 christian
 

being a lisp with a reader the converting of the character stream to
data structures doesn't happen in the compiler, the compiler's input is
a data structure produced by the reader.

the compiler does:

1. macro expansion
2. analysis
3. code generation

you could argue that macro expansion is just part of analysis (analysis
code calls macroexpand) but I think it is more useful mentally to keep
it as a distinct phase just before analysis.

the clojure compiler is not very complicated and does a pretty straight
forward mapping of clojure expressions to jvm byte code, depending on
the jvm's jit for optimizations.

the compilation unit in clojure is a single top level expression,
however there are some special purpose hooks in the compiler for
compiling a whole source file at a time. those hooks don't really change
anything about the generated code; they change the context the generated
code is emitted in to. the target being jvm byte code you can't just
emit instructions, the instructions have to belong to a method, and the
method has to belong to a class.

there is a meme going around that lisp is its own ast, but if you'd
worked on a compiler and are familiar with the richness of a real ast,
that tends to just seem silly. the clojure compiler does an analysis of
the clojure datastructures and emits a tree of richer expression objects
which is the ast, which the code generator uses to generate bytecode.
the ast objects have methos like emit(...) which is how the code
generation is actually done.

all this being said I don't think anyone is a huge fan of the current
compiler, but it has three huge advantage over alternatives:

1. it works (this might be debatable)
2. it has been in use for many years now
3. and alternative would involve making lots of effort to ultimately get
back to where we are

which is(my opinion) why it still persists.

the clojurescript compiler (which shares no code with the clojure
compiler) could be considered a more modern approach to clojure
complication, but there are important parts of the clojure environment
(vars mainly) that are missing from the clojurescript environment. the
clojurescript compiler has a very rich intermediate representation using
maps. in my opinion the intermediate representation is so rich it is
actually kind of hard to work with.


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



signature.asc
Description: OpenPGP digital signature


Re: Two Dimensional Associative Map

2013-08-05 Thread Kevin Downey
On 8/2/13 8:08 PM, JvJ wrote:
 Actually, what I'm looking for is a way to use arbitrary types of keys 
 rather than integers.
 
 I have this so far:
 
  Table data structure.
  For now, the table data structure is a map of maps.
 
 (defn row
   Get a row of the table.
  If only the key is passed, a row
 lookup function is returned.
   ([r]
  #(row r %))
   ([r m]
  (get m r)))
 
 (defn col
   Get a column of the table.
   ([c]
  #(col c %))
   ([c m]
  (for [[rk r] m
:let [x (get r c)]
:when x]
[rk x])))
 
 (defn t-get
   Get values in a table.
   [m {:keys [r c]}]
   (cond
(and r c) (get-in m [r c])
r (row r m)
c (col c m)
:else m))
 
 (defn t-update
   Update a value or values in the map.
   [m f {:keys [r c]}]
   (cond
(and r c) (update-in m [r c] f)
r (update-in m [r] f)

;; This O(n) column update is making me angry!
c (let [res (f (into {} (t-get m :c c)))]
(println f result:  res)
(reduce
 (fn [acc k]
   (if-let [v (get res k)]
 (update-in acc [k] assoc c v)
 (if (contains? (get m k) c)
   (update-in acc [k] dissoc c)
   acc)))
 m
 (clojure.set/union (set (keys m))
(set (keys res)))
 
 (defn t-set
   Set a value or values in the map.
   [m v  r]
   (apply t-update m (constantly v) r))
 
 It works pretty well for swapping out rows or individual cells, but setting 
 a column seems like an inefficient operation.  I don't know how much I'll be
 using that.
 
 On Thursday, 1 August 2013 17:59:40 UTC-7, JvJ wrote:

 I'm looking for an associative data structure that can be accessed by both 
 rows and columns, and could potentially be sparse.

 Suppose the following table is called t:

 |   | :A   | :B   | :C   ||---+--+--+--|| 1 |  | 
  | '[x y z] || 2 | 2a | 2b |  || 3 |  |  |  || 3 
 | :3a  |  | Foo|


 Then (t :A) would return {2 2a, 3 :3a}, and (t 2) would return {:A 2a, 
 :B 2b}.
 (t :A 2) or (t 2 :A) would return 2a.

 I'm thinking of implementing it as a simple map of maps with some extra 
 functions, but I'm not sure if
 that would be the best option.



 

please, please, use clojure.set/index, it does what you want, better the
code you shared.

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



signature.asc
Description: OpenPGP digital signature


Re: Two Dimensional Associative Map

2013-08-02 Thread Kevin Downey
On 8/1/13 5:59 PM, JvJ wrote:
 I'm looking for an associative data structure that can be accessed by both 
 rows and columns, and could potentially be sparse.
 
 Suppose the following table is called t:
 
 |   | :A   | :B   | :C   ||---+--+--+--|| 1 |  |  
 | '[x y z] || 2 | 2a | 2b |  || 3 |  |  |  || 3 | 
 :3a  |  | Foo|
 
 
 Then (t :A) would return {2 2a, 3 :3a}, and (t 2) would return {:A 2a, 
 :B 2b}.
 (t :A 2) or (t 2 :A) would return 2a.
 
 I'm thinking of implementing it as a simple map of maps with some extra 
 functions, but I'm not sure if
 that would be the best option.
 
 
I would recommend looking at the clojure.set namespace. it has an index
function which builds indices

user (require '[clojure.set :as s])
nil
user (clojure.repl/doc s/index)
-
clojure.set/index
([xrel ks])
  Returns a map of the distinct values of ks in the xrel mapped to a
  set of the maps in xrel with the corresponding values of ks.
nil
user (s/index [{:row 1 :col 2}] [:row])
{{:row 1} #{{:row 1, :col 2}}}
user (merge (s/index [{:row 1 :col 2}] [:row]) (s/index [{:row 1 :col
2}] [:col]) (s/index [{:row 1 :col 2}] [:row :col]))
{{:col 2, :row 1} #{{:row 1, :col 2}}, {:col 2} #{{:row 1, :col 2}},
{:row 1} #{{:row 1, :col 2}}}
user (def d (merge (s/index [{:row 1 :col 2}] [:row]) (s/index [{:row 1
:col 2}] [:col]) (s/index [{:row 1 :col 2}] [:row :col])))
#'user/d
user (get d {:col 2})
#{{:row 1, :col 2}}
user (get d {:row 1})
#{{:row 1, :col 2}}
user (get d {:row 1 :col 2})
#{{:row 1, :col 2}}
user

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



signature.asc
Description: OpenPGP digital signature


Re: Getting a living standalone jar with lein uberjar and a handful of resources

2013-07-31 Thread Kevin Downey
On 7/31/13 4:18 AM, Alex Fowler wrote:
 I have an application which is built fine with uberjar with an exception of 
 two things which do not get incuded:
 1) Additonal jar files (about 150Mb) from various Java libraries that are 
 not present on Clojars and that I have no power of will or time of trying 
 to upload them there. This folder is speciiified with :resource-paths in 
 project.clj 
 2) About 150Mb of resources such as pictures and video-files which are 
 loaded by these java libraries using *their own methods* which I cannot 
 change.
 
 What lein uberjar does - it skips these files and simply creates an 
 incomplete jar with my compiled sources, which does not launch because it 
 is missing those files. However, lein run works just fine!
 
 My question is: how do I make a single jar with lein that, being run with 
 java -jar exposes the same behavior as simply lein run?
 
 PS: As an idea: when I was programming in Scala, I was using 
 com.jdotsoft.jarloader.JarClassLoader which was the entry point in my app 
 and I could simply put all files into the jar and it would search them in 
 that order:
 1) recursively inside the jar
 2) in the same folder as the jar (which would allow simple externalizing of 
 files like settings files if needed to be exposed to users).
 3) in system path folders...
 Maybe there is a way to use that magical JarClassLoader with 
 Leiningen/Clojure?
 

clojars is just a maven repo, and a simple maven repo is just a http server.

you can setup your own private maven repo easily by copying the
directory structure of your ~/.m2 to an http server somewhere.

for something more full featured you can setup something like apache
archiva (which is what I use at work) http://archiva.apache.org/index.cgi

once you have a private maven repo you can deploy whatever you want to
it, and use whatever you deploy has a dependency as normal


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



signature.asc
Description: OpenPGP digital signature


Re: Clojure 1.5.1 head holding

2013-07-01 Thread Kevin Downey
On 7/1/13 3:49 AM, Gerrard McNulty wrote:
 Suppose I had code like:
 
 ((fn [rs] (take-last 3 rs)) (range 2000))
 
 This seems to run fine with no head holding.  But if I write something like:
 
 (defn- log [f]
   (println start)
   (f)
   (println end))
 
 ((fn [rs] (log #(take-last 3 rs))) (range 2000))
 
 Then this seems to hold on to the head.  Is there a way I can write code 
 like this where I can add functions like log without the head being held?


Closing over a sequence causes the head to be held. When a sequence is
passed as an argument clojure can do locals clearing to help avoid
holding on to head, but doesn't do so for closed over values, and doing
so for closed over values in an automated way is non-trivial.

You can tag closures you know are only going to be used once with ^:once
which will do the equivalent of locals clearing for closed over values,
but it will clear closed over values after they are used, so it is not
generally safe unless you know you are only calling the function once.
And :once may be considered an implementation detail, so I wouldn't
sprinkle it around everywhere.

If you pass a function that produces a seq instead of passing a seq it
avoids the whole mess:

((fn [rs] (log #(take-last 3 (rs #(range 20))

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



signature.asc
Description: OpenPGP digital signature


Re: Clojure 1.6 API: clojure.lang.IFn and clojure.api.API

2013-06-24 Thread Kevin Downey
On 6/24/13 7:53 AM, Jörg Winter wrote:
 Hi Stuart,
 
 ok, so my question is actually more about how to create some clojure Runtime, 
 filling it with additional namespaces, i.e. more than just clojure.core.
 I just discovered the RT class which could be what I want ( though its not 
 official API ?)
 
 I need to make clojure runtime avail. for an IDE plugin, thats the background 
 here.
 
 What do you think of Using RT like that ?
 I mean instantiating a clojure environment by RT.doInit maybe
 
 I really dont need to have a REPL for this, as I just want to query for 
 functions and vars via API
 
 Best,
 Joerg
 
the ticket http://dev.clojure.org/jira/browse/CLJ-1188 for API might be
enlightening. it has some discussion and also links to the design wiki page.

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



signature.asc
Description: OpenPGP digital signature


Re: Making things go faster

2013-06-04 Thread Kevin Downey
midje makes each test a top level form, so test runs happen as a side
effect of code loading, which means you cannot really run tests in a good
way from the repl without doing some kind of ridiculous forced code
reloading. I would definitely recommend staying far away from midje, if you
want a tight test loop the repl is your best bet, and midje's design makes
using it from the repl really awkward.

I have heard horror stories about drip jvms being launched with stale args,
etc, but that is anecdotal, and a while ago so maybe it is great, I don't
use it and have no interest in it, largely because I use the repl.


On Wed, Jun 5, 2013 at 12:09 AM, Hoàng Minh Thắng p...@banphim.net wrote:

 * Is there a faster cycle than to change code, change tests and type lein
 test to see the results?

 my favourite workflow is with lein-midje (you can run both midje tests and
 clojure tests!)
 https://github.com/marick/lein-midje

 * Is there a way to keep everything in a hot JVM (I've done a little
 research on Nailgun... but it seems to be out of vogue) so there's no JVM
 start-up penalty?

 Try drip:
  https://github.com/flatland/drip/

 --
 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from 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.






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

-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
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: realizing a lazy line-seq inside with-open

2013-05-27 Thread Kevin Downey
doall doesn't recurse, so you are not realizing the lazy-seq, you want
something like [msg (doall sig-strs)]

if you are looking to play around with io stuff, I recommend looking in to
using reducers for io, they allow you to sort of invert control, keeping
the nice property of with-open always cleanly closing resources after use,
but making it easier to break up io processing in functional steps with out
needing to deal with the dynamic scoping issues of with-open and the lazy
issues with line-seq


On Mon, May 27, 2013 at 6:10 PM, Elango Cheran elango.che...@gmail.comwrote:

 Much simpler, although I'm still seeing the following exception, unless I
 keep the form (str [msg sig-strs]):

 IOException Stream closed  java.io.BufferedReader.ensureOpen
 (BufferedReader.java:115)

 Any ideas why?


 On Mon, May 27, 2013 at 5:44 PM, Sean Corfield seancorfi...@gmail.comwrote:

 Just use doall:

 (doall [msg sig-strs])

 No need for the let / result / promise / deliver.

 On Mon, May 27, 2013 at 5:32 PM, Elango Cheran elango.che...@gmail.com
 wrote:
  Hi everyone,
  I had a function that reads the contents of a file (in this case, it
  represents a license) and then verifies the contents.
 
  As I started to expand the code for verifying, it made sense to break
 the
  function up into a function for file parsing and a function for
  verification.  The following is the function that I created to return
 the
  contents of the file parsing:
 
  (defn- lic-file-msg-sigs
return a vector containing the original license string/message and a
 seq
  of each signature line generated. the input is the string of the entire
  license file
[lic-file-str]
(let [result (promise)]
  (with-open [rdr (BufferedReader. (StringReader. lic-file-str))]
(let [lines (line-seq rdr)
  line-sandwich-middle-fn (fn [lines line-before line-after]
   (- lines
(drop-while #(not (re-find
  (re-pattern line-before) %)))
rest
(take-while #(not (re-find
  (re-pattern line-after) %)
  msg-lines (line-sandwich-middle-fn lines LICENSE-BEGIN
  LICENSE-END)
  sig-strs (line-sandwich-middle-fn lines SIGNATURE-BEGIN
  SIGNATURE-END)
  msg (clojure.string/join \newline msg-lines)]
  (str msg sig-strs) ;; need to realize the values to force file
  ;; parsing before file is closed. couldn't figure out how to
  ;; force realization except for the str function
  (deliver result [msg sig-strs])))
  @result))
 
 
  My question is related to the comments towards the end -- is there a
 better
  way to force the realization of the contents of the line-seq before I
  deliver it?
 
  (If there is a better way to write this code, let me know  In case
 you
  are wondering, I wanted to use line-seq for parsing the file so that I
 get
  the contents of the lines in between special sentinel lines.  line-seq
  requires a reader, and readers are best used with with-open.  But
 with-open
  closes the reader object at the end of its scope, so any code using the
  contents of the reader need to be realized before the reader is closed.
  In
  order to return the contents outside of the with-open form, I used a
 promise
   deliver.)
 
  Thanks,
  Elango
 
  --
  --
  You received this message because you are subscribed to the Google
  Groups Clojure group.
  To post to this group, send email to clojure@googlegroups.com
  Note that posts from new members are moderated - please be patient with
 your
  first post.
  To unsubscribe from 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.
 
 



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

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

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

Re: features expression

2013-03-07 Thread Kevin Downey
Class names are read in as symbols
On Mar 7, 2013 7:10 AM, Andy Fingerhut andy.finger...@gmail.com wrote:

 I may be wrong, but I think this, and anything else that tries to solve
 this problem after read time, will fail for one of the primary uses of
 feature macros: Java packages/namespaces that exist for Clojure/JVM but not
 ClojureScript, and JavaScript namespaces that exist for ClojureScript but
 not Clojure/JVM.  Each of those would cause a compilation error for the
 other, I believe.

 e.g. java.lang.Long and java.util.Date don't exist in ClojureScript, and
 are the kinds of things you would want to conditionally compile on for
 Clojure/JVM.

 Andy

 On Thu, Mar 7, 2013 at 5:44 AM, Jonathan Fischer Friberg 
 odysso...@gmail.com wrote:

 Isn't it possible to solve this with a simple macro?

 (case-dialect
:clojure (... clojure code ...)
:clojurescript (... clojurescript code ...))

 Then, in jvm clojure, it could be implemented as:
 (defmacro case-dialect [ {:keys [clojure]}] clojure)

 and in clojurescript:
 (defmacro case-dialect [ {:keys [clojurescript]}] clojurescript)

 Alternatively, we could have a def, say *clojure-dialect*, then:
 (defmacro case-dialect [ {:as m}] (get m *clojure-dialect*))

 (although the dialect should probably be part of *clojure-version* ...
 you get the idea)

 Jonathan


 On Thu, Mar 7, 2013 at 10:04 AM, Akhil Wali akhil.wali...@gmail.comwrote:

 IMHO features expressions should be evaluated at read-time only.
 Putting it off till the compilation phase only complicates things.
 So I'm actually favoring a preprocessing step like here -
 http://dev.clojure.org/display/design/Feature+Expressions?focusedCommentId=6390066#comment-6390066

 The idea is simple; when the reader parses a sexpr, and if there's a
 feature expression,then  only use the part that's relevant to the current
 Clojure dialect.
 The only complication with this scheme is that all information in
 *clojure-version* is related to the version numbers only; however, this
 could be changed easily.



 On Thu, Mar 7, 2013 at 7:46 AM, Brent Millare 
 brent.mill...@gmail.comwrote:

 +1

 Isn't is possible to accomplish all these efforts using tagged
 literals? https://github.com/miner/wilkins

 This way the facilities for read-time code generation can be customized
 and any reader that supports tagged-literals will support this. All of this
 is data provided as arguments, no evaluation. Evaluation happens from the
 tag function.

 On Wednesday, March 6, 2013 8:24:15 PM UTC-5, Brian Goslinga wrote:

 Do we really need new syntax for feature expressions? Although it
 would be more ugly than CL's feature expressions, we could use a reader
 literal. For example #feature [feature expression value]. Using a
 reader literal is simple, compatible with EDN, and allows for the feature
 expressions to be backported to an older version of Clojure using a 
 library.

  --
 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from 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.






 --
 Akhil Wali

 # http://github.com/darth10 https://github.com/darth10
 # http://darth10.github.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.
 For more options, visit https://groups.google.com/groups/opt_out.




  --
 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from 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 

Re: Clojure crash on OpenJDK 8

2013-02-27 Thread Kevin Downey
what version of clojure are you using? I doubt line #100 of main is the
correct line in server.clj, the content of the stacktrace looks more like
https://github.com/clojure/tools.nrepl/blob/master/src/main/clojure/clojure/tools/nrepl/server.clj#L146,
what version of nrepl?

https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Compiler.java#L7504has
a comment that sort of explains why the compiler generates stub
classes, this sort of looks like the name of the stub is not getting
unmunged somewhere.




On Wed, Feb 27, 2013 at 8:53 AM, AtKaaZ atk...@gmail.com wrote:

 the stacktrace points here:
 https://github.com/clojure/tools.nrepl/blob/master/src/main/clojure/clojure/tools/nrepl/server.clj#L100
 but that's all I got:)


 On Wed, Feb 27, 2013 at 5:47 PM, Ben Evans 
 benjamin.john.ev...@gmail.comwrote:

 Hi,

 lein repl is crashing on OpenJDK 8 consistently for me, with this error:

 Exception in thread main java.lang.ClassCastException:
 clojure.tools.nrepl.server.Server cannot be cast to
 compile__stub.clojure.tools.nrepl.server.Server
 at clojure.tools.nrepl.server.Server.valAt(server.clj:100)
 at clojure.lang.KeywordLookupSite$1.get(KeywordLookupSite.java:45)
 at user$eval966.invoke(NO_SOURCE_FILE:1)
 at clojure.lang.Compiler.eval(Compiler.java:6511)
 at clojure.lang.Compiler.eval(Compiler.java:6501)
 at clojure.lang.Compiler.eval(Compiler.java:6477)
 at clojure.core$eval.invoke(core.clj:2797)
 at clojure.main$eval_opt.invoke(main.clj:297)
 at clojure.main$initialize.invoke(main.clj:316)
 at clojure.main$null_opt.invoke(main.clj:349)
 at clojure.main$main.doInvoke(main.clj:427)
 at clojure.lang.RestFn.invoke(RestFn.java:421)
 at clojure.lang.Var.invoke(Var.java:419)
 at clojure.lang.AFn.applyToHelper(AFn.java:163)
 at clojure.lang.Var.applyTo(Var.java:532)
 at clojure.main.main(main.java:37)

 Is there someone out there with better knowledge of Clojure's
 internals than me who would like to spend some cycles working with me
 to try to get to the bottom of this?

 I have a Mac build of OpenJDK 8 which reproduces the problem, and can
 bring my knowledge of JVM internals to the party. If you were in
 London  could collaborate face-face, so much the better.

 Thanks,

 Ben

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





 --
 Please correct me if I'm wrong or incomplete,
 even if you think I'll subconsciously hate it.

  --
 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from 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.






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

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

2013-02-27 Thread Kevin Downey
clojure uses a class called DynamicClassloader to load runtime generated
classes, but it is a pretty strait forward extension of URLClassloader


On Wed, Feb 27, 2013 at 11:27 AM, Ben Evans
benjamin.john.ev...@gmail.comwrote:

 On Wed, Feb 27, 2013 at 5:42 PM, Kevin Downey redc...@gmail.com wrote:
  what version of clojure are you using? I doubt line #100 of main is the
  correct line in server.clj, the content of the stacktrace looks more like
 
 https://github.com/clojure/tools.nrepl/blob/master/src/main/clojure/clojure/tools/nrepl/server.clj#L146
 ,
  what version of nrepl?

 From the working Java 7 install:

 lein repl
 nREPL server started on port 53804
 REPL-y 0.1.9
 Clojure 1.4.0

 [snip]

 user= (System/getProperty java.version)
 1.7.0_11

 
 https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Compiler.java#L7504
  has a comment that sort of explains why the compiler generates stub
 classes,
  this sort of looks like the name of the stub is not getting unmunged
  somewhere.

 I'll investigate further in that source - thanks.

 To add a bit more light on this, my JDK 8 Mac build is from the lambda
 repo, so may have changes which are ahead of mainline JDK8 (to
 Herwig's point).

 Does Clojure make use of custom classloading? If so, is there a
 concise description of how it does so? My top two guesses for a root
 cause were name mangling  custom classloading.

 Thanks,

 Ben

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





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

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

2013-02-21 Thread Kevin Downey
The are a few tools for doing interop with COM from the JVM. They all kind
of suck. We use com4j at work with Clojure. Com4j generates JVM stubs for
COM libraries.
On Feb 21, 2013 3:53 PM, octopusgrabbus octopusgrab...@gmail.com wrote:

 Does Clojure have a module that allows initializing, passing data to, and
 finalizing COM objects? I am asking, because I need to write a Clojure
 program to communicate with a COM toolkit. 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 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.




-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: Associative extends Seqable?

2013-01-18 Thread Kevin Downey
use ILookup instead of Associative


On Fri, Jan 18, 2013 at 11:00 AM, Ben Wolfson wolf...@gmail.com wrote:

 I've got a bit of code implementing Associative, in order to provide a
 fake map that responds to all calls to valAt with the same object, no
 matter what the key is.

 Since it therefore contains every possible key, it doesn't make much
 sense to call keys or seq on it (and it doesn't make *much* sense to
 call vals on it if you expect the result of vals to be equinumerous
 with the key/value pairs in the map). Nor does it make much sense to
 call count on it.

 However, since Associative extends IPersistentCollection extends
 Seqable, the result is an instance of Seqable, and coll? returns true,
 etc., even though, as I said, the promises those interfaces make don't
 really make sense.

 I could just extend ILookup, which contains only valAt, but I'd also
 like to be able to implement containsKey and entryAt, which AFAICT are
 only found in Associative. (If I'm wrong, please let me know---I know
 that count is found in e.g. both IPersistentCollection and Counted.)
 And in any case I'd like to be able to use IPersistentMap as well, for
 without. There are sensible definitions of all the functions
 specifically defined for IPersistentMap and Associative, but there are
 *not* sensible definitions for all of what they bring along.

 Is there a way to weasel out of this? Force coll? to return false,
 make the runtime think these pseudo-maps aren't instances of Seqable?
 Being enumerable or seqable is not a necessary property of something
 that maps keys to values.

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

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




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

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

Re: First test with JavaFx and blocked yet :(

2012-12-01 Thread Kevin Downey
if you read the docs on the java command -cp and -jar are mutually
exclusive options


On Sat, Dec 1, 2012 at 1:19 AM, Christian Sperandio 
christian.speran...@gmail.com wrote:

 Thanks :)
 I got my error. Because I declared my code as a class, my mind turned into
 a object logic and I forget I was always in Clojure and in functional mind.

 I'd like understand an another point too. When I generate a jar with lein
 uberjar, the code works. But if I do only a lein jar, the running failed
 with a NoClassDef exception. Even if when I run the jar I use the java
 command's option -cp to give the jfxrt.java's place.
 Do I forget something?


 Chris

 Le 1 déc. 2012 à 01:14, Kevin Downey redc...@gmail.com a écrit :

 here is an example https://gist.github.com/4179694


 On Fri, Nov 30, 2012 at 4:13 PM, Kevin Downey redc...@gmail.com wrote:

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





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

 Hi,

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

   (:gen-class
:extends javafx.application.Application))

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

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

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

   (:gen-class
:extends javafx.application.Application))

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

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


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

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

 Thanks for your help.

 Chris

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




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




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

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

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




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

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

Re: First test with JavaFx and blocked yet :(

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





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

 Hi,

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

   (:gen-class
:extends javafx.application.Application))

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

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

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

   (:gen-class
:extends javafx.application.Application))

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

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


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

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

 Thanks for your help.

 Chris

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




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

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

Re: First test with JavaFx and blocked yet :(

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


On Fri, Nov 30, 2012 at 4:13 PM, Kevin Downey redc...@gmail.com wrote:

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





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

 Hi,

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

   (:gen-class
:extends javafx.application.Application))

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

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

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

   (:gen-class
:extends javafx.application.Application))

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

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


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

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

 Thanks for your help.

 Chris

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




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




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

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

Re: Check that a protocol exists

2012-10-24 Thread Kevin Downey
you can check for the existence of the protocol's var just like you
would for any var. not sure what B. Ghose is getting at, but I would
recommend not checking for the existence of the interface.

http://clojure.org/vars

On Wed, Oct 24, 2012 at 12:23 PM, Baishampayan Ghose b.gh...@gmail.com wrote:
 What about the technique Clojure uses in the reducers library?

 https://github.com/clojure/clojure/blob/master/src/clj/clojure/core/reducers.clj#L37

 -BG

 On Wed, Oct 24, 2012 at 12:20 PM, Michael Klishin
 michael.s.klis...@gmail.com wrote:
 Is there a way to check if a protocol exists?

 For example, if I want to extend clojure.data.json protocols but only if it
 is available, how would I go about it?

 This way does not work at least some of the time (referenced namespace
 causes a ClassNotFound exception
 during compilation):

 https://github.com/clojurewerkz/support/blob/master/src/clojure/clojurewerkz/support/json.clj#L18-33

 Any better solutions? I'd like to avoid adding any new dependencies, if
 possible.

 Thank you in advance.
 --
 MK

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

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



 --
 Baishampayan Ghose
 b.ghose at gmail.com

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



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

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


Re: I can get this if() clause to ever be true

2012-10-19 Thread Kevin Downey
conj can surely produce maps, and does so happily in the following cases:

(conj {} [:foo :bar])
(conj {} {:foo :bar})

I suggesting adding printlns or logging or a debugger and checking the
value of this-users-params, it is almost certainly not what you expect
it to be.

as a side note creating a date object just to call getTime is kind of
gross, try (System/currentTimeMillis)

On Fri, Oct 19, 2012 at 12:42 AM, Sean Corfield seancorfi...@gmail.com wrote:
 On Fri, Oct 19, 2012 at 12:10 AM, larry google groups
 lawrencecloj...@gmail.com wrote:

 (defn add-to-logged-in-registry [this-users-params]
   (let [right-now (. (Date.) getTime)
 new-user-entry (conj this-users-params { updated right-now })]
 (if (:username new-user-entry)
   (swap! registry assoc (:username new-user-entry) new-user-entry

 The if statement seems to never be true.


 conj produces a sequence, not a map, so the lookup of :username fails. Try
 new-user-entry (assoc this-users-params updated right-now)
 --
 Sean A Corfield -- (904) 302-SEAN
 An Architect's View -- http://corfield.org/
 World Singles, LLC. -- http://worldsingles.com/

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

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



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

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


Re: I can get this if() clause to ever be true

2012-10-19 Thread Kevin Downey
you have `username` a symbol as the key in your map, but you are
looking for `:username` they keyword as a key

On Fri, Oct 19, 2012 at 8:47 AM, larry google groups
lawrencecloj...@gmail.com wrote:


 Also:



 I suggesting adding printlns or logging or a debugger and checking the
 value of this-users-params, it is almost certainly not what you expect
 it to be.

 I showed the output previously, but I will do it again.

 If I add a println like this:


 (defn add-to-logged-in-registry [this-users-params]
   (let [right-now (. (Date.) getTime)
 new-user-entry (conj this-users-params { updated right-now })]
 (println apply str new-user-entry)

 (if (:username new-user-entry)
   (swap! registry assoc (:username new-user-entry) new-user-entry

 This code works perfectly at the REPL so to show a problem I have to upload
 this to the live server. So I compile this and upload it to the server and
 start it up and immediately the Javascript in the browsers of dozens of
 users starts to bombard the app:

 java -jar who-is-logged-in-1.0.1-standalone.jar 4
 App 'Who is logged in?' is starting
 port:  4
 2012-10-19 11:37:02.731:INFO:oejs.Server:jetty-7.x.y-SNAPSHOT
 2012-10-19 11:37:02.846:INFO:oejs.AbstractConnector:Started
 SelectChannelConnector@0.0.0.0:4

 #core$apply clojure.core$apply@d1fba79 #core$str
 clojure.core$str@7dfde44e {updated 1350661023079, username rumbella,
 first_name , last_name , user_image , site www.wpquestions.com}

 #core$apply clojure.core$apply@d1fba79 #core$str
 clojure.core$str@7dfde44e {updated 1350661023140, username karlorihoo,
 first_name Karlo, last_name Rihoo, user_image , site www.wpquestions.com}

 #core$apply clojure.core$apply@d1fba79 #core$str
 clojure.core$str@7dfde44e {updated 1350661023698}

 #core$apply clojure.core$apply@d1fba79 #core$str
 clojure.core$str@7dfde44e {updated 1350661024149, username Rainner,
 first_name Rainner, last_name Lins, user_image Rainner_phptZ2nEJ.jpg, site
 www.javascriptquestions.com}

 #core$apply clojure.core$apply@d1fba79 #core$str
 clojure.core$str@7dfde44e {updated 1350661024159}

 #core$apply clojure.core$apply@d1fba79 #core$str
 clojure.core$str@7dfde44e {updated 1350661024269}

 #core$apply clojure.core$apply@d1fba79 #core$str
 clojure.core$str@7dfde44e {updated 1350661024646}

 #core$apply clojure.core$apply@d1fba79 #core$str
 clojure.core$str@7dfde44e {updated 1350661024833, username dbranes,
 first_name Dbranes, last_name , user_image dbranes_phpPJVl3f.jpg, site
 www.wpquestions.com}

 #core$apply clojure.core$apply@d1fba79 #core$str
 clojure.core$str@7dfde44e {updated 1350661025140, username Christianto,
 first_name Christianto, last_name , user_image Christianto_phpqESzHW.jpg,
 site www.wpquestions.com}

 #core$apply clojure.core$apply@d1fba79 #core$str
 clojure.core$str@7dfde44e {updated 1350661025337, username jsoni,
 first_name Jatin, last_name Soni, user_image jsoni_phpYlWQTr.jpg, site
 www.wpquestions.com}

 #core$apply clojure.core$apply@d1fba79 #core$str
 clojure.core$str@7dfde44e {updated 1350661025651}

 #core$apply clojure.core$apply@d1fba79 #core$str
 clojure.core$str@7dfde44e {updated 1350661025996}

 So, why does this not work? And what is the right way to be sure that this:

 {updated 1350661025996}

 Is never added to the registry (since there is no username).










 On Friday, October 19, 2012 3:53:26 AM UTC-4, red...@gmail.com wrote:

 conj can surely produce maps, and does so happily in the following cases:

 (conj {} [:foo :bar])
 (conj {} {:foo :bar})

 I suggesting adding printlns or logging or a debugger and checking the
 value of this-users-params, it is almost certainly not what you expect
 it to be.

 as a side note creating a date object just to call getTime is kind of
 gross, try (System/currentTimeMillis)

 On Fri, Oct 19, 2012 at 12:42 AM, Sean Corfield seanco...@gmail.com
 wrote:
  On Fri, Oct 19, 2012 at 12:10 AM, larry google groups
  lawrenc...@gmail.com wrote:
 
  (defn add-to-logged-in-registry [this-users-params]
(let [right-now (. (Date.) getTime)
  new-user-entry (conj this-users-params { updated right-now
  })]
  (if (:username new-user-entry)
(swap! registry assoc (:username new-user-entry)
  new-user-entry
 
  The if statement seems to never be true.
 
 
  conj produces a sequence, not a map, so the lookup of :username fails.
  Try
  new-user-entry (assoc this-users-params updated right-now)
  --
  Sean A Corfield -- (904) 302-SEAN
  An Architect's View -- http://corfield.org/
  World Singles, LLC. -- http://worldsingles.com/
 
  Perfection is the enemy of the good.
  -- Gustave Flaubert, French realist novelist (1821-1880)
 
  --
  You received this message because you are subscribed to the Google
  Groups Clojure group.
  To post to this group, send email to clo...@googlegroups.com
  Note that posts from new members are moderated - please be patient with
  your
  first post.
  To unsubscribe from this group, send email to
  

Re: trampoline not compatible with reducers?

2012-10-16 Thread Kevin Downey
you are declaring the functions return doubles, but in fact returning
functions or doubles

On Tue, Oct 16, 2012 at 11:06 AM, Jim - FooBar(); jimpil1...@gmail.com wrote:
 Hi everyone,

 I'm pretty sure i'm using trampoline the right way but still I get this
 exception:

 ClassCastException Clondie24.lib.search$search$minimize__3075$fn__3076
 cannot be cast to java.lang.Number
 Clondie24.lib.search/search/minimize--3075 (search.clj:47)

 here is the code:

 (defn search The recursive bit of the min-max algorithm.
 [eval-fn tree depth]
 (letfn [(minimize ^double [tree d] (if (zero? d) (eval-fn (:root tree)
 (:direction tree))
 #(r/reduce my-min
   (r/map (fn [child] (maximize (:tree child)
 (dec d))) (:children tree)
 (maximize ^double [tree d] (if (zero? d) (eval-fn (:root tree)
 (:direction tree))
 #(r/reduce my-max
(r/map (fn [child] (minimize (:tree
 child) (dec d))) (:children tree)]
 (trampoline minimize tree (int depth

 Can anyone shine some light? Is it something that has to do with reducers?

 Jim

 ps: it works fine without trampoline and '#' behind 'r/reduce'.




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



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

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


Re: trampoline not compatible with reducers?

2012-10-16 Thread Kevin Downey
if you look further down the stacktrace (where it refers to your code
instead of clojure.lang.Numbers.lt) it will give you line numbers in
your code to look at.

you are calling these trampolined functions without trampoline.

On Tue, Oct 16, 2012 at 11:24 AM, Jim - FooBar(); jimpil1...@gmail.com wrote:
 On 16/10/12 19:15, Kevin Downey wrote:

 you are declaring the functions return doubles, but in fact returning
 functions or doubles

 yes you're right (my bad) but the same thing happens without the
 type-hinting - albeit in a different place and different originating
 function:

 ClassCastException Clondie24.lib.search$search$maximize__3081$fn__3082
 cannot be cast to java.lang.Number  clojure.lang.Numbers.lt
 (Numbers.java:219)

 Jim




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



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

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


Re: AOT-compilation, record types and DynamicClassLoader

2012-10-16 Thread Kevin Downey
have you cleaned out the classes/ directory recently? AOT'ing,
deftypes/defrecords, and lein when combined can exhibit issues with
stale generate classes for deftypes/defrecords. I would also try
adding (:gen-class) to your ns form. AOT compilation is effectively a
nop for the namespace without it, except for any
deftypes/records/protocols in the namespace, so a possible place for
those to get out of sync with the rest of the code.

DynamicClassloader generally means some compilation (code generation)
has happened, if a namespace has been AOT'ed the generate classes will
be loaded and the DynamicClassloader isn't required.

On Tue, Oct 16, 2012 at 2:17 PM, Chris Jeris cje...@brightcove.com wrote:
 I have a problem where I am trying to do an isa? or instance? check on an
 object of a record type which is defined in an AOT-compiled namespace.  The
 isa? check fails because -- under circumstances which I do not yet well
 understand -- the object I actually have is an instance of its class in a
 clojure.lang.DynamicClassLoader, whereas a reference to the class by its
 literal name yields the class in the base sun.misc.Launcher$AppClassLoader.

 My Clojure code is compiled into a jar which is included into a Jetty server
 whose app code is largely written in Java.  Here is an example which
 illustrates the problem:

 ;; src/foo/core.clj
 (ns foo.core)
 (defrecord T [a b])

 ;; project.clj
 (defproject foo 1.0.0-SNAPSHOT
   :dependencies [[org.clojure/clojure 1.4.0]]
   :aot [foo.core])

 Now if I add the artifact foo/foo as a Maven dependency of the Jetty server,
 and attach a liverepl to the running server (without taking any action to
 call the Clojure code from Java), I see the following:

 Clojure 1.4.0
 user= (require '[foo.core])
 nil
 user= (.getClassLoader foo.core.T)
 #AppClassLoader sun.misc.Launcher$AppClassLoader@a6eb38a
 user= (.getClassLoader (type (foo.core.T. 1 2)))
 #AppClassLoader sun.misc.Launcher$AppClassLoader@a6eb38a
 user= (.getClassLoader (type (foo.core/-T 1 2)))
 #DynamicClassLoader clojure.lang.DynamicClassLoader@433d3253

 My actual case is more complicated, but the principle is the same: instances
 of foo.core.T which were built by the defrecord constructor function -T do
 not inhabit the AppClassLoader version of the class, but rather a
 DynamicClassLoader version.  The result is that instance? or instanceof
 checks -- whether in my own Clojure code or in that of Java clients of my
 library who are trying to downcast -- do not behave as expected.

 This example cannot be reduced too far:  if one just builds an uberjar and
 invokes a repl on the Clojure library alone, using 'java -cp
 target/foo-1.0.0-SNAPSHOT-standalone.jar clojure.main', the result is
 different:

 Clojure 1.4.0
 user= (require '[foo.core])
 nil
 user= (.getClassLoader foo.core.T)
 #AppClassLoader sun.misc.Launcher$AppClassLoader@43be2d65
 user= (.getClassLoader (type (foo.core.T. 1 2)))
 #AppClassLoader sun.misc.Launcher$AppClassLoader@43be2d65
 user= (.getClassLoader (type (foo.core/-T 1 2)))
 #AppClassLoader sun.misc.Launcher$AppClassLoader@43be2d65

 Unfortunately I don't understand enough about the Clojure class loading
 mechanism to understand what might be causing the DynamicClassLoader to be
 invoked in one case and not the other.

 This problem seems to have been described by Ryan Senior about 20 months ago
 on clojure-dev, but I do not find any follow-up posts:
 https://groups.google.com/forum/?fromgroups=#!topic/clojure-dev/VBJFMEFBeFY

 Can anyone shed light on the situation?

 thanks, Chris Jeris
 --
 Chris Jeris
 cje...@brightcove.com (617) 686-3271
 freenode/twitter/github: ystael

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



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

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


Re: Cljs-repl server as ring middleware?

2012-10-08 Thread Kevin Downey
I'd checkout nrepl and nrepl middlewares, which can be exposed over
http (via ring middleware) or other transports.

https://github.com/hiredman/drawbridge-cljs is an nrepl http client
for clojurescript

https://github.com/hiredman/nrepl-cljs-middleware is an example of a
nrepl middleware, which exposes clojurescript compilation as an nrepl
command

On Mon, Oct 8, 2012 at 9:51 AM, Frank Siebenlist
frank.siebenl...@gmail.com wrote:
 I've been digging through the clojurescript code lately, and making some 
 changes to the repl-related code. This is quite difficult as clojurescript 
 seems to have its own proprietary implementation of a webserver that serves 
 the repl-communication as well as other possible handlers, like the 
 reflection-based stuff.

 Having a repl-server based on ring-middleware would give you more modularity, 
 and easier pluggability with the ring-based webserver code that in many/most 
 cases will coexist with the repl-session.

 I've searched for any discussiond or efforts in this space, but couldn't find 
 any…

 Would such a ring-based alternative make sense?
 Any existing efforts in this space?
 Any reasons why the current hardcoded web server would be better/preferable?

 -FrankS.



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



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

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


Re: how to securely store parameters in config files

2012-09-28 Thread Kevin Downey
if you use a password to encrypt your config, you will need config2
for the password, and of course you do not want people to have access
to config2, so you should encrypt that, and put the password in
config3, and ...

I recommend using lein test selectors to split out tests that hit
external services in to a different class of tests, tests that don't
require the credentials can be loaded and run by anyone, tests that do
require a config file that is not checked in.

On Fri, Sep 28, 2012 at 4:33 AM, Murtaza Husain
murtaza.hus...@sevenolives.com wrote:
 Hi,

 I am using a config file to store passwords / keys for DB and connection to
 other services like AWS.

 I am using Travis CI for build, and running my tests, and then deploying it
 to live server.

 I would like to encrypt the variables in my config file and only the
 application should be able to read it. This is the criteria -

 1) The application should be able to decrypt it in multiple environments,
 from the build server to multiple deployment servers.

 2) The password used to decrypt the config file is not avalaible to the
 developers.

 Also are there any leiningen plugins / features that will aid in this ?

 Thanks,
 Murtaza

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



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

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


Re: Reducers reduce my performance

2012-09-14 Thread Kevin Downey
On Fri, Sep 14, 2012 at 4:22 AM, Tassilo Horn t...@gnu.org wrote:
 Hi all,

 I have some code which uses a lot of map/mapcat/filter stuff and is
 totally eager (result is always an ordered set).  That looked to me like
 a good candidate for reducers.

 Basically, my code enables me to write something like this:

 --8---cut here---start-8---
 (reachables p [p-seq
 [-- 'ContainsType]
 [p-+ [p-seq
[-- 'Defines]
[-- 'Imports]
[p-opt [-- 'ContainsType])
 --8---cut here---end---8---

 which calculates the set of reachable vertices in a graph starting at a
 vertex p (or a set of vertices p) which can be reached by traversing a
 path matching the structure given as vector.  So from p, we navigate a
 sequence (p-seq) of one forward ContainsType-edge, then one-or-many
 times (p-+) traversing the sequence of an incoming Defines-edge followed
 by an outgoing Imports-edge followed by optionally (p-opt) an incoming
 ContainsType-edge.

 p-seq, p-+, p-opt, --, -- are all functions receiving a set of
 vertices and the nested rest of the vector or edge type symbol.  The
 current implementation simply recurses over the vector and applies the
 functions, combining their results.

 Ok, that works very good and performs well, but I've though reducers
 might give me some extra-performance.  So now I rewrote all those
 functions to use reducers and return reducibles instead of ordered sets.
 The shape has changed to this, so instead of recursively applying the
 functions in a vector we create one big reducer function that does the
 job, and reachables simply applies that to p.

 --8---cut here---start-8---
 (reachables p (p-seq
(-- 'ContainsType)
(p-+ (p-seq
  (-- 'Defines)
  (-- 'Imports)
  (p-opt (-- 'ContainsType))
 --8---cut here---end---8---

 The good thing is that it calculates exactly the same set.  The bad
 thing is that it's about a factor of 2 or 3 slower.

 I tried to track down the cause, and the main bottleneck is the p-+
 function which got much slower than before.

 This is the new version using reducers (:as r).  The problem here is
 that to stop the iteration, one has to reduce the intermediate result in
 every step and check if new reachable vertices (n) could be found.  If
 so, we need to do another iteration.

this is almost certainly the problem, if you are using reducers you
should not make intermediate results concrete. given the structure of
your computation it may not be a good fit for reducers.

you might be able to restructure in such a way as return something
with a custom impl of CollReduce that performs this computation when
reduced, which would get you out of returning concrete results.

 --8---cut here---start-8---
 (defn ^:private p-*-or-+
   [p include-coll]
   (fn [coll] ;; coll is a reducible
 (loop [ret (if include-coll
  (into (ordered.set/ordered-set) coll)
  (ordered.set/ordered-set))
n (into (ordered.set/ordered-set)
(if include-coll
  (r/remove ret (p coll))
  (p coll)))]
   (if (seq n)
 (recur (into ret n)
(into (ordered.set/ordered-set)
  (r/remove ret (p n
 ret

 (defn p-+ [p]
   (p-*-or-+ p false))
 --8---cut here---end---8---

 This is the original version, where the ordered set of vertices to start
 with is already given as first parameter, and the fn does the job itself
 rather than returning a fn that can do it.  (As you can see, the old
 version uses reducers internally, too, but the functions themselves all
 receive and return sets).

 --8---cut here---start-8---
 (defn ^:private p-*-or-+
   [v p ret]
   (let [n (into (ordered.set/ordered-set)
 ;; oset is like set for ordered-sets
 (r/remove ret (oset (*p-apply* v p]
 (if (seq n)
   (recur n p (into-oset ret n))
   ret)))

 (defn p-* [v p]
   (p-*-or-+ v p (oset v)))
 --8---cut here---end---8---

 So is that simply a use-case where reducers don't fit in very well, or
 am I doing something wrong?

 Thanks for any hints,
 Tassilo

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

Re: Is anyone relying on the js* special form?

2012-09-12 Thread Kevin Downey
I've used it to make ClojureScript functions in to javascript object
constructors

(defn Foo [] (js* /*) (js* */))

results in the generated return being commented out, so (Foo.) works

I use this in a macro for creating new types that are based on
existing Google Closure types


On Wed, Sep 12, 2012 at 4:12 PM, Brandon Bloom snprbo...@gmail.com wrote:
 I'm exploring some changes to the ClojureScript compiler backend and am
 curious if anyone is using one particular implementation detail: The js*
 special form.

 Note that I'm not asking about the js/ pseudo-namespace, only the js*
 special form.

 Are you using it in your ClojureScript projects? If so, what for?

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



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

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


Re: redefining multimethods at the repl

2012-09-05 Thread Kevin Downey
if I recall, the current defonce like behavior of multimethods was a
response to the situation where if you have your multimethods split
across multiple files reloading the file with the defmulti in it would
re-def the multimethod with the new dispatch, but it would not have
any of the methods loaded from the other files.

oscillating between these poles at about 6.31139e7hz seems less than ideal.

maybe defmethod could try and capture the ns a method is defined in,
and defmulti would try to force a reload? seems overly complicated for
core.

On Wed, Sep 5, 2012 at 9:58 AM, Stuart Halloway
stuart.hallo...@gmail.com wrote:
 Brian,

 I share  your pain. A standardized contrib solution for this would be
 welcomed.

 Are there other things like this that cause people to restart REPL
 unnecessarily? I would like to identify the whole list of such things and
 kill them.

 Stu

 Thanks. I think I'll write my own `defgeneric` to hide an `ns-unmap` from
 the reader. (I like the terminology of generic function better than
 multimethod anyway, as an introduction to the idea.)


 On Sep 4, 2012, at 5:41 PM, Ulises wrote:

 Binding to the var instead of the value will allow it to be udpated.


 Alternatively you could ns-unmap the multimethod before redefining it.


 U


 --

 You received this message because you are subscribed to the Google

 Groups Clojure group.

 To post to this group, send email to clojure@googlegroups.com

 Note that posts from new members are moderated - please be patient with your
 first post.

 To unsubscribe from this group, send email to

 clojure+unsubscr...@googlegroups.com

 For more options, visit this group at

 http://groups.google.com/group/clojure?hl=en


 -
 Brian Marick, Artisanal Labrador
 Contract programming in Ruby and Clojure
 Occasional consulting on Agile
 Writing /Functional Programming for the Object-Oriented Programmer/:
 https://leanpub.com/fp-oo



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



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

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


Re: Isolated Clojure Environments

2012-08-30 Thread Kevin Downey
https://github.com/hiredman/polycosm
On Aug 30, 2012 6:38 PM, Dave Ray dave...@gmail.com wrote:

 Hi,

 I'm looking for the best way to execute some Clojure code in a more or
 less completely isolated environment. That is, say we load one piece
 of code:

 A:
 ---
 (ns my-ns)

 (def foo [] (println hi))

 (foo)
 ---

 if a second piece of code was loaded:

 B:
 ---
 (ns my-ns)

 (foo) ; -- This should fail
 ---

 the reference to foo would fail because they're two completely
 different environments.

 What seems to be foiling this goal is the static global
 clojure.lang.Namespace.namespaces. Even if I compile the code in
 separate class loaders, the namespace map is still shared.

 The best solution I've come up with so far is just to load the Clojure
 jar in its own class loader so there's no chance of different
 environments messing with each other through the global namespace
 table. It also means loading multiple copies of Clojure.

 I've looked a bit at the tryclojure/clojail approach of restricting
 access to (in-ns), (ns), etc and just generating a unique namespace
 for each piece of code. That may be an easier approach at the risk of
 the code being less isolated.

 This is being integrated into a larger, existing framework, which is
 where the isolation requirements come from.

 Thoughts?

 Thanks,

 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: cljs is not defined

2012-07-26 Thread Kevin Downey
On Wed, Jul 25, 2012 at 6:48 PM, trashhalo step...@mindjunk.org wrote:
 If I compile...

 (def x 5)

 ... with advanced optimization it comes out as

 cljs.a.x = 5;

means something like make x, in the namespace cljs.a equal to 5 so
you are missing an (ns cljs.a) somewhere

  Which throws 'cljs is not defined' in firefox and chrome. I am sure I am
 doing something wrong but I can't figure it out based on the documentation.
 Any help would be greatly appreciated.

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



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

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


Re: auxiliary methods like :before and :after for multimethods?

2012-07-26 Thread Kevin Downey
https://github.com/technomancy/robert-hooke/

On Thu, Jul 26, 2012 at 2:15 PM, George Oliver georgeolive...@gmail.com wrote:
 hi, I'm wondering if anyone has extended multimethods with auxiliary methods
 like CL-style :before and :after, and if not what a suitable substitute
 might be.


 thanks, George

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



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

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


Re: atom and lock

2012-07-17 Thread Kevin Downey
if you do it as a lock, then readers must block writers (think it
through). Clojure's reference types + immutable datastructures and the
views on perception that underlay them are strongly opposed to readers
interfering with writers.

http://www.infoq.com/presentations/Are-We-There-Yet-Rich-Hickey around
27:48 Rich discusses perception

On Tue, Jul 17, 2012 at 3:57 PM, Warren Lynn wrn.l...@gmail.com wrote:
 I have a hard time understanding why there is a need to retry when doing
 swap! on an atom. Why does not Clojure just lock the atom up-front and do
 the update? I have this question because I don't see any benefit of the
 current just try and then re-try if needed (STM?) approach for atom (maybe
 OK for refs because you cannot attach a lock to unknown ref combinations in
 a dosync clause). Right now I have an atom in my program and there are two
 swap! functions on it. One may take a (relatively) long time, and the
 other is short. I don't want the long swap! function to retry just because
 in the last minute the short one sneaked in and changed the atom value. I
 can do the up-front lock myself, but I wonder why this is not already so in
 the language. Thank you for any enlightenment.

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



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

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


Re: atom and lock

2012-07-17 Thread Kevin Downey
On Tue, Jul 17, 2012 at 4:58 PM, Warren Lynn wrn.l...@gmail.com wrote:


 On Tuesday, July 17, 2012 7:50:10 PM UTC-4, red...@gmail.com wrote:

 if you do it as a lock, then readers must block writers (think it
 through). Clojure's reference types + immutable datastructures and the
 views on perception that underlay them are strongly opposed to readers
 interfering with writers.



 Why is it so? Does not the reader just get a snapshot copy of the atom state
 and does not care who writes to the original atom? If a lock is needed, it
 is only needed for a very short commit time (cannot read when a writer is
 committing), but not during the whole swap! function. That still sounds a
 lot better than re-try to me.

Finish the thought, what happens when there is contention, a thread
reads then writes before you acquire the lock to commit. You can try
and making locking work, but you'll just up with CAS based on a lock


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



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

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


Re: Concatenating InputStreams (was: Re: Parsing SGML)

2012-07-13 Thread Kevin Downey
http://docs.oracle.com/javase/1.5.0/docs/api/java/io/SequenceInputStream.html

On Fri, Jul 13, 2012 at 7:29 AM, Meikel Brandmeyer (kotarak)
m...@kotka.de wrote:
 Hi again,

 talking about thread safety.

 Am Freitag, 13. Juli 2012 16:13:54 UTC+2 schrieb Meikel Brandmeyer
 (kotarak):

   (close
 []
 (when @is
   (.close @is)
   (doseq [s @streams] (.close s


 (close
   []
   (locking this
 (when @is
   (.close @is)
   (doseq [s @streams] (.close s)

 Kind regards
 Meikel

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



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

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


Re: Concatenating InputStreams (was: Re: Parsing SGML)

2012-07-13 Thread Kevin Downey
thank you for responding personally to me, but I sent my message to
clojure google group.

given the thread has the subject Concatenating InputStreams and I
linked javadocs for a standard part of java.io that does exactly that,
I am surprised that you decided to respond with tl;dr, but I have
noted your response and will in the future let you prattle on endless
reinventing functionality that already exists.

On Fri, Jul 13, 2012 at 12:42 PM, Meikel Brandmeyer m...@kotka.de wrote:
 tl;dr

 Am 13.07.2012 um 18:35 schrieb Kevin Downey:

 http://docs.oracle.com/javase/1.5.0/docs/api/java/io/SequenceInputStream.html




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

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


Re: [ANN] clojure.java.jdbc 0.2.3 available on Maven Central

2012-06-27 Thread Kevin Downey
that is very interesting, I've played around with generating sql from
datalog queries, but stopped when I ran up against generating queries
for recursive datalog rules because I wasn't aware of WITH RECURSIVE

On Tue, Jun 26, 2012 at 6:29 PM, Chas Emerick c...@cemerick.com wrote:
 Random thought: recursive queries are possible in SQL using recursive common
 table expressions.  The PostgreSQL manual has a good introduction to them:

 http://www.postgresql.org/docs/9.1/static/queries-with.html

 And another introduction to them, in the particular area of querying
 hierarchical data using recursive CTEs:

 http://explainextended.com/2009/07/17/postgresql-8-4-preserving-order-for-hierarchical-query/

 Cheers,

 - Chas

 On Jun 26, 2012, at 8:26 AM, Niels van Klaveren wrote:

 Yeah, it's a pain to include Datomic's Datalog implementation through Maven
 dependencies, since you need to install the jar by hand. Afaik
 clojure.contrib.datalog didn't compile to SQL. Theoretically it should be
 possible to do so, since Datalog is a superset of SQL. However, the extra
 functionality in Datalog would be hard to implement in SQL (for instance,
 recursive queries), and result in a lot of not very optimal SQL queries.

 On Tuesday, June 26, 2012 11:45:15 AM UTC+2, mnicky wrote:

 Thanks! However it'd be nice if it was released as a separate library.

 Also, I thought that clojure.contrib.datalog worked for SQL queries...
 That would be even better ;)

 On Monday, June 25, 2012 1:50:19 PM UTC+2, Niels van Klaveren wrote:

 You can use the Datomic datalog implementation to query Clojure
 collections. I think this is the same use clojure.contrib.datalog had.

 On Monday, June 25, 2012 12:47:29 PM UTC+2, mnicky wrote:



 On Saturday, June 23, 2012 1:20:30 AM UTC+2, Niels van Klaveren wrote:


 I was thinking if an SQL generation DSL / library could be based on
 core.logic ?


 Something like revival of clojure.contrib.datalog would be great.


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



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

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


Re: [ANN] clojure.java.jdbc 0.2.3 available on Maven Central

2012-06-21 Thread Kevin Downey
On Thu, Jun 21, 2012 at 9:33 AM, Sean Corfield seancorfi...@gmail.com wrote:
 On Thu, Jun 21, 2012 at 12:33 AM, Vinzent ru.vinz...@gmail.com wrote:
 Actually, jsql looks very much like clojureql\korma.

 jsql has completely different goals to ClojureQL/Korma and is mostly a
 convenience for generating the sort of SQL that the update!, insert!
 and delete! methods need under the hood (c.j.jdbc has to generate that
 SQL anyway - might as well make the methods public). The
 select/where/order-by has evolved out of our common usage at World
 Singles where we have get-by-id and find-by-keys and similar CRUD
 functions. jsql is deliberately very close to the metal of SQL and
 is not intended to be composable etc. Folks wanting a full-blown DSL
 should indeed use Korma (or ClojureQL).

 Honetly, I wish see
 better support for clojureql rather than new similar DSLs coming up.

 Lau hasn't updated ClojureQL for a while - if you want better support,
 perhaps you should approach him and contribute to that project?
 --
 Sean A Corfield -- (904) 302-SEAN
 An Architect's View -- http://corfield.org/
 World Singles, LLC. -- http://worldsingles.com/

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

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

given java.jdbc's position as the sort of lower level glue all these
libraries are built on, maybe better then including a DSL in java.jdbc
would be including an AST (some data representation of sql) and a
compiler for same.

you can argue that well code is data so the dsl is an exposed data
representation of sql, none of the dsls are low level enough to be
targeted by any of the others.

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

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


Re: clojure.inspector.inspect-table gives up when first element is nil...

2012-06-18 Thread Kevin Downey
if you are printing tables using Clojure, you should checkout doric:
http://github.com/joegallo/doric

On Mon, Jun 18, 2012 at 11:22 AM, Jim - FooBar(); jimpil1...@gmail.com wrote:
 the very first let binding in clojure.inspector/old-table-model should be:

 row1 (some #(when-not (nil? %) %) data)

 instead of

 row1 (first data)

 simply because it will fail if the (first data) returns nil...

 where do we submit minor improvements like this?

 Jim



 On 16/06/12 13:26, Jim - FooBar(); wrote:

 It would be nice to have the option to supply the keys to 'inspect-table'
 just in case the first element is nil...this is exactly the behaviour of
 'clojure.pprint.print-table' where  providing the keys is indeed an option.
 Both will fail when the first element is nil but at least 'print-table'
 allows us to provide the keys in advance...

 Jim


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



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

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


Re: [ANN] Clojure JSR 223 Implementation

2012-05-23 Thread Kevin Downey
you might want to use something like
https://github.com/flatland/classlojure or
https://github.com/hiredman/polycosm to provide an isolated clojure
runtime per instance of ClojureScriptEngine.

single segment namespaces are bad because the generate classes end up
in the default package.

checking jars in to git is bad form, github provides a downloads
feature if you want to host a downloadable jar there.

On Wed, May 23, 2012 at 4:56 PM, eduardoejp eduardo...@gmail.com wrote:
 Since the only other alternatives (http://code.google.com/p/clojure-jsr223/
 and https://github.com/pmf/clojure-jsr223) seem pretty much dead, I decided
 to write my own (in Clojure).

 You can get the jar downloading it from Clojars with lein dep and then just
 drop it in the desired class-path to have Clojure support.

 Here's the link: http://clojars.org/clj-jsr223

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



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

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


Re: defrecord with inheritance

2012-05-20 Thread Kevin Downey
On Sun, May 20, 2012 at 10:22 AM, Warren Lynn wrn.l...@gmail.com wrote:
 So from what I read  the philosophy of Clojure discourages inheritance
 on concrete data types. However, maybe I am too entrenched in my OO
 thinking, how do I define a new record type that includes all the data
 members of another record type? I am thinking about the classic
 Employee/Person example.

Don't make data members. Use maps and multimethods. You don't need
types for this. You have data about a thing, keep it has data,
suddenly all the functions that work on data structures (select-keys,
update-in, clojure.set) all work on your data instead of having your
data locked away in a type.

 If I can define a record of Employee with Person's data members
 included, even that is not true inheritance (as no protocols of
 Person will be automatically extended to Employee), I need that
 for function re-use (so a function working on Person will
 automatically work on Employee because Employee is guaranteed to have
 all the data members in Person).

 Also, again, maybe I am too OO minded, is there a way inherit another
 record type's protocol implementation? That seems to give the best
 combination of both worlds (OO and functional), so you can either have
 you own very customized combination of data type/protocols, or use the
 very common OO pattern. Just like we have both the single-typed
 dispatching (which is more OO like and covers a large portion of use
 cases), and more advanced multimethods.

 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



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

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


Re: defrecord with inheritance

2012-05-20 Thread Kevin Downey
On Sun, May 20, 2012 at 1:50 PM, Warren Lynn wrn.l...@gmail.com wrote:
 Thanks. That will work. But I wish things can get more concise and
 elegant.

 I like the Python idea of make simple things easier and difficult
 things possible. So I think the limited inheritance I mentioned can
 make a large portion of use cases easier, without sacrificing any of
 Clojure's more advanced features. Basically, I wish to have something
 like:

 1. (defrecord Employee [x y] :base Person)
 so I can have all data fields in Person also included in Employee
 2. (extend-type Employee
  GetName :reuse Person)
so I simply reuse GetName implementation from Person

you have no reason to give up the flexibility of maps and data for the
rigidness of types and an object graph.

{:employee? true} beats the above hands down.

 Maybe there is already something like that I am not aware of. But if
 not, I really hope more people will concur and so it will get into the
 language.

 More broadly, I think the success of a language depends on two things:
 1. Flexible so it is not just usable on trivial problems.
 2. Provides/encourages good patterns so the flexibility won't get out
 of control, especially on large projects.

 Of course the challenge is how to balance these two. OO provides very
 natural patterns for people to work with, so I think we should embrace
 it as much as possible without sacrificing the unique flexibility/
 power Clojure brings.

 On May 20, 1:56 pm, Vinzent ru.vinz...@gmail.com wrote:
 You can reuse methods by putting them in a map and then just merging it
 with the new methods:

 (extend Employee
 AProtocol
 (merge default-implementation {:new-function (fn ...)}))

 The problem is that you can't reuse methods defined inline, i.e. you can't
 say my record implements this protocol just like that other record.

 воскресенье, 20 мая 2012 г., 23:22:55 UTC+6 пользователь Warren Lynn
 написал:









  So from what I read  the philosophy of Clojure discourages inheritance
  on concrete data types. However, maybe I am too entrenched in my OO
  thinking, how do I define a new record type that includes all the data
  members of another record type? I am thinking about the classic
  Employee/Person example.

  If I can define a record of Employee with Person's data members
  included, even that is not true inheritance (as no protocols of
  Person will be automatically extended to Employee), I need that
  for function re-use (so a function working on Person will
  automatically work on Employee because Employee is guaranteed to have
  all the data members in Person).

  Also, again, maybe I am too OO minded, is there a way inherit another
  record type's protocol implementation? That seems to give the best
  combination of both worlds (OO and functional), so you can either have
  you own very customized combination of data type/protocols, or use the
  very common OO pattern. Just like we have both the single-typed
  dispatching (which is more OO like and covers a large portion of use
  cases), and more advanced multimethods.

  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



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

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


Re: defrecord with inheritance

2012-05-20 Thread Kevin Downey
On Sun, May 20, 2012 at 2:05 PM, Warren Lynn wrn.l...@gmail.com wrote:
 I don't quite understand where I introduced the rigidity. And what I
 described is not a true inheritance as in traditional OO languages
 (hence the quoted inheritance). It seems just some simple almost
 syntax-level change (maybe some macros can solve it) will make
 people's life a little bit easier

2. Functions delay binding; data structures induce binding. Moral:
Structure data late in the programming process.
-- http://www.cs.yale.edu/quotes.html

putting your data in specific types like Employee and Person instead
of just using maps is a kind of rigidity

 On May 20, 4:55 pm, Kevin Downey redc...@gmail.com wrote:
 On Sun, May 20, 2012 at 1:50 PM, Warren Lynn wrn.l...@gmail.com wrote:
  Thanks. That will work. But I wish things can get more concise and
  elegant.

  I like the Python idea of make simple things easier and difficult
  things possible. So I think the limited inheritance I mentioned can
  make a large portion of use cases easier, without sacrificing any of
  Clojure's more advanced features. Basically, I wish to have something
  like:

  1. (defrecord Employee [x y] :base Person)
  so I can have all data fields in Person also included in Employee
  2. (extend-type Employee
   GetName :reuse Person)
 so I simply reuse GetName implementation from Person

 you have no reason to give up the flexibility of maps and data for the
 rigidness of types and an object graph.

 {:employee? true} beats the above hands down.









  Maybe there is already something like that I am not aware of. But if
  not, I really hope more people will concur and so it will get into the
  language.

  More broadly, I think the success of a language depends on two things:
  1. Flexible so it is not just usable on trivial problems.
  2. Provides/encourages good patterns so the flexibility won't get out
  of control, especially on large projects.

  Of course the challenge is how to balance these two. OO provides very
  natural patterns for people to work with, so I think we should embrace
  it as much as possible without sacrificing the unique flexibility/
  power Clojure brings.

  On May 20, 1:56 pm, Vinzent ru.vinz...@gmail.com wrote:
  You can reuse methods by putting them in a map and then just merging it
  with the new methods:

  (extend Employee
  AProtocol
  (merge default-implementation {:new-function (fn ...)}))

  The problem is that you can't reuse methods defined inline, i.e. you can't
  say my record implements this protocol just like that other record.

  воскресенье, 20 мая 2012 г., 23:22:55 UTC+6 пользователь Warren Lynn
  написал:

   So from what I read  the philosophy of Clojure discourages inheritance
   on concrete data types. However, maybe I am too entrenched in my OO
   thinking, how do I define a new record type that includes all the data
   members of another record type? I am thinking about the classic
   Employee/Person example.

   If I can define a record of Employee with Person's data members
   included, even that is not true inheritance (as no protocols of
   Person will be automatically extended to Employee), I need that
   for function re-use (so a function working on Person will
   automatically work on Employee because Employee is guaranteed to have
   all the data members in Person).

   Also, again, maybe I am too OO minded, is there a way inherit another
   record type's protocol implementation? That seems to give the best
   combination of both worlds (OO and functional), so you can either have
   you own very customized combination of data type/protocols, or use the
   very common OO pattern. Just like we have both the single-typed
   dispatching (which is more OO like and covers a large portion of use
   cases), and more advanced multimethods.

   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

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

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



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

-- 
You received this message because you are subscribed to the Google
Groups

Re: defrecord with inheritance

2012-05-20 Thread Kevin Downey
On Sun, May 20, 2012 at 2:13 PM, Warren Lynn wrn.l...@gmail.com wrote:
 Maybe for Person/Employee example with very simple functions do not
 need data types, but I don't think that is generally true (isn't
 defrecord trying to patching that up?).  When I say need I am not
 saying you cannot achieve what you want to do without it (just as
 assembly code can do anything), but things will get so flexible (hence
 the lack of pattern) the language will be powerful only on paper
 very soon. I am glad Clojure does not seem to be heading that
 direction, but still I think there might be things we can improve on.

defrecord, deftype, and defprotocol provide extensible low level
abstractions like the kind Clojure is built on.

As a Clojure programmer you should only need them rarely.

As a beginner you should never use them.

 On May 20, 4:51 pm, Kevin Downey redc...@gmail.com wrote:
 On Sun, May 20, 2012 at 10:22 AM, Warren Lynn wrn.l...@gmail.com wrote:
  So from what I read  the philosophy of Clojure discourages inheritance
  on concrete data types. However, maybe I am too entrenched in my OO
  thinking, how do I define a new record type that includes all the data
  members of another record type? I am thinking about the classic
  Employee/Person example.

 Don't make data members. Use maps and multimethods. You don't need
 types for this. You have data about a thing, keep it has data,
 suddenly all the functions that work on data structures (select-keys,
 update-in, clojure.set) all work on your data instead of having your
 data locked away in a type.









  If I can define a record of Employee with Person's data members
  included, even that is not true inheritance (as no protocols of
  Person will be automatically extended to Employee), I need that
  for function re-use (so a function working on Person will
  automatically work on Employee because Employee is guaranteed to have
  all the data members in Person).

  Also, again, maybe I am too OO minded, is there a way inherit another
  record type's protocol implementation? That seems to give the best
  combination of both worlds (OO and functional), so you can either have
  you own very customized combination of data type/protocols, or use the
  very common OO pattern. Just like we have both the single-typed
  dispatching (which is more OO like and covers a large portion of use
  cases), and more advanced multimethods.

  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

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

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



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

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


Re: defrecord with inheritance

2012-05-20 Thread Kevin Downey
On Sun, May 20, 2012 at 2:16 PM, nicolas.o...@gmail.com
nicolas.o...@gmail.com wrote:
 I had wished such a feature all week.
 You don't need it often, but when you need it, it is really annoying
 to circumvent.
 traits would really be useful.

If you find yourself wanting traits you are using defrecord, deftype,
and defprotocol too often.

If everything has the same implementation for X, should X really be
polymorphic on the type? shouldn't it just be another function?

If you find yourself using a polymorphic mechanism like protocols or
interfaces to give different types the same behavior then you need to
go back to the drawing board.

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



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

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


Re: defrecord with inheritance

2012-05-20 Thread Kevin Downey
On Sun, May 20, 2012 at 2:23 PM, Warren Lynn wrn.l...@gmail.com wrote:
 Well, I don't want to be a beginner for too long, :-)

then As a Clojure programmer you should only need them rarely.

 On May 20, 5:19 pm, Kevin Downey redc...@gmail.com wrote:
 On Sun, May 20, 2012 at 2:13 PM, Warren Lynn wrn.l...@gmail.com wrote:
  Maybe for Person/Employee example with very simple functions do not
  need data types, but I don't think that is generally true (isn't
  defrecord trying to patching that up?).  When I say need I am not
  saying you cannot achieve what you want to do without it (just as
  assembly code can do anything), but things will get so flexible (hence
  the lack of pattern) the language will be powerful only on paper
  very soon. I am glad Clojure does not seem to be heading that
  direction, but still I think there might be things we can improve on.

 defrecord, deftype, and defprotocol provide extensible low level
 abstractions like the kind Clojure is built on.

 As a Clojure programmer you should only need them rarely.

 As a beginner you should never use them.









  On May 20, 4:51 pm, Kevin Downey redc...@gmail.com wrote:
  On Sun, May 20, 2012 at 10:22 AM, Warren Lynn wrn.l...@gmail.com wrote:
   So from what I read  the philosophy of Clojure discourages inheritance
   on concrete data types. However, maybe I am too entrenched in my OO
   thinking, how do I define a new record type that includes all the data
   members of another record type? I am thinking about the classic
   Employee/Person example.

  Don't make data members. Use maps and multimethods. You don't need
  types for this. You have data about a thing, keep it has data,
  suddenly all the functions that work on data structures (select-keys,
  update-in, clojure.set) all work on your data instead of having your
  data locked away in a type.

   If I can define a record of Employee with Person's data members
   included, even that is not true inheritance (as no protocols of
   Person will be automatically extended to Employee), I need that
   for function re-use (so a function working on Person will
   automatically work on Employee because Employee is guaranteed to have
   all the data members in Person).

   Also, again, maybe I am too OO minded, is there a way inherit another
   record type's protocol implementation? That seems to give the best
   combination of both worlds (OO and functional), so you can either have
   you own very customized combination of data type/protocols, or use the
   very common OO pattern. Just like we have both the single-typed
   dispatching (which is more OO like and covers a large portion of use
   cases), and more advanced multimethods.

   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

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

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

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

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



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

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


Re: defrecord with inheritance

2012-05-20 Thread Kevin Downey
why does defrecord and deftype exist? shouldn't deftype be sufficient?
Why is defrecord encouraged over deftype, with defype reserved for low
level bits?

it is because records can act like a generic map, which means data is
not hidden inside the type, which makes types created with defrecord
much more useful. How much more useful then is an ordinary map(Where
you can actually remove all the keys)?

I was the first person to introduce protocols and records into our
code base work, and I have colleagues who are even more ragingly
anti-protocols/types. Which I think is a little crazy, they are useful
and service a purpose. But even I am outraged by how quickly
multimethods (things of beauty, joy, and power) were abandoned by the
community once a shiny new toy (types/protocols) was available that if
you squinted at looked sort of like the object stuff.

On Sun, May 20, 2012 at 2:26 PM, Kevin Downey redc...@gmail.com wrote:
 On Sun, May 20, 2012 at 2:23 PM, Warren Lynn wrn.l...@gmail.com wrote:
 Well, I don't want to be a beginner for too long, :-)

 then As a Clojure programmer you should only need them rarely.

 On May 20, 5:19 pm, Kevin Downey redc...@gmail.com wrote:
 On Sun, May 20, 2012 at 2:13 PM, Warren Lynn wrn.l...@gmail.com wrote:
  Maybe for Person/Employee example with very simple functions do not
  need data types, but I don't think that is generally true (isn't
  defrecord trying to patching that up?).  When I say need I am not
  saying you cannot achieve what you want to do without it (just as
  assembly code can do anything), but things will get so flexible (hence
  the lack of pattern) the language will be powerful only on paper
  very soon. I am glad Clojure does not seem to be heading that
  direction, but still I think there might be things we can improve on.

 defrecord, deftype, and defprotocol provide extensible low level
 abstractions like the kind Clojure is built on.

 As a Clojure programmer you should only need them rarely.

 As a beginner you should never use them.









  On May 20, 4:51 pm, Kevin Downey redc...@gmail.com wrote:
  On Sun, May 20, 2012 at 10:22 AM, Warren Lynn wrn.l...@gmail.com wrote:
   So from what I read  the philosophy of Clojure discourages inheritance
   on concrete data types. However, maybe I am too entrenched in my OO
   thinking, how do I define a new record type that includes all the data
   members of another record type? I am thinking about the classic
   Employee/Person example.

  Don't make data members. Use maps and multimethods. You don't need
  types for this. You have data about a thing, keep it has data,
  suddenly all the functions that work on data structures (select-keys,
  update-in, clojure.set) all work on your data instead of having your
  data locked away in a type.

   If I can define a record of Employee with Person's data members
   included, even that is not true inheritance (as no protocols of
   Person will be automatically extended to Employee), I need that
   for function re-use (so a function working on Person will
   automatically work on Employee because Employee is guaranteed to have
   all the data members in Person).

   Also, again, maybe I am too OO minded, is there a way inherit another
   record type's protocol implementation? That seems to give the best
   combination of both worlds (OO and functional), so you can either have
   you own very customized combination of data type/protocols, or use the
   very common OO pattern. Just like we have both the single-typed
   dispatching (which is more OO like and covers a large portion of use
   cases), and more advanced multimethods.

   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

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

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

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

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with your 
 first post.
 To unsubscribe from

Re: Bootstrapping Clojure-in-Clojure

2012-05-15 Thread Kevin Downey
On Tue, May 15, 2012 at 8:05 AM, Timothy Baldridge tbaldri...@gmail.com wrote:
 There seems to be a few steps involved in this from, what I'm seeing.

 From what I'm seeing of the source, there's two files I'll be dealing with

 closure.clj -- defines functions for looking up info about libraries,
 functions, etc.
 compiler.clj -- actually defines the compiler

 To start with, I'm thinking of trying to compile ClojureScript in
 ClojureScript. I know this won't work if the user has optimized
 ClojureScript at all, but it should be a good testing point.

 The first step in this process would then be to write a version of
 closure.clj in ClojureScript. Somehow it would present the same
 interface as closure.clj but in a JS environment. I'll have to look
 into how well that may work out. I'm going to call this file the
 platform.clj file.

 From there I'll need to take a look at the GSOC work (where is that
 currently?) to see how much of the compiler I'd need to modify. But
 we'd basically need to re-write the compiler to use only ClojureScript
 compatible forms. From there it should be fairly complete.

 So the way I'd then port ClojureScript to Python would be the following:

 1) Write a platform.clj (closure.clj) file for Python. This would
 somehow allow Java to tap into Python and run reflection on the
 modules in Python.
 2) Implement a Python back-end for the GSOC pluggable-backend
 3) Compile compiler.clj into one massive python file
 4) Write a new platform.clj file to just look at the Python VM instead
 of going from Java-Python-Modules
 5) Compile compiler.clj into one massive python file
 6) ...
 7) Profit!

 Long term I'm only seeing that we'll need to write 3 files each time
 we want to port ClojureScript to a new platform:

 1) The Java version of platform.clj
 2) The compiler backend
 3) A native version of platform.clj

 I'm going to look into the GSOC stuff next to make sure I'm not going
 to duplicate anyone's work.

 Timothy

Logically the interface between the analyzer and the emitter is data
(maps, etc) which can be serialized as json or some platform specific
representation. Then all you need to do is write an emitter on your
platform of choice that can emit code for the data.

So for Python:
1. run the analyzer on itself to get the data describing it
2. serialize that data in some format Python can read
3. write an emitter in Python
4. feed the analyzer data to the emitter
5. hook the emitted analyzer code up to the emitter

so the whole thing pivots around the data emitted from the analyzer

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



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

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


Re: Bootstrapping Clojure-in-Clojure

2012-05-15 Thread Kevin Downey
On Tue, May 15, 2012 at 11:25 AM, Timothy Baldridge
tbaldri...@gmail.com wrote:
 Logically the interface between the analyzer and the emitter is data
 (maps, etc) which can be serialized as json or some platform specific
 representation. Then all you need to do is write an emitter on your
 platform of choice that can emit code for the data.

 So for Python:
 1. run the analyzer on itself to get the data describing it
 2. serialize that data in some format Python can read
 3. write an emitter in Python
 4. feed the analyzer data to the emitter
 5. hook the emitted analyzer code up to the emitter

 so the whole thing pivots around the data emitted from the analyzer

 One question. Let's say that we are analyzing (require 'foo.bar).
 How does the analyzer know if foo.bar exists? Are you suggesting that
 we leave that to the emitter?

 I like this idea...I'm going to think about it a bit more...

 Timothy

It sort of depends in some sense (require 'foo.bar) is just calling
the function require with a symbol as an argument.

 I can certainly imagine cases where the analyzer might want
reflection on types etc of the given platform, but I think that is
really an optimization, trading off compile/analyzer time reflection
for runtime reflection. That platform reflective information would be
provided by something like clojure.reflect, and could either run via
querying a running instance of the platform, or via just a static data
file of the information. But that info is, I think, mostly required to
make generated code fast, but it should be possible to generate slower
reflective code generically for the initial bootstrap without it.

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



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

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


Re: Bootstrapping Clojure-in-Clojure

2012-05-15 Thread Kevin Downey
On Tue, May 15, 2012 at 12:51 PM, Timothy Baldridge
tbaldri...@gmail.com wrote:
  I can certainly imagine cases where the analyzer might want
 reflection on types etc of the given platform, but I think that is
 really an optimization, trading off compile/analyzer time reflection
 for runtime reflection. That platform reflective information would be
 provided by something like clojure.reflect, and could either run via
 querying a running instance of the platform, or via just a static data
 file of the information. But that info is, I think, mostly required to
 make generated code fast, but it should be possible to generate slower
 reflective code generically for the initial bootstrap without it.

 The real reason this is done, is because Clojure is a compiled
 language. For instance:

 user= (defn z [baz] baz)
 #'user/z
 user= (defn foo [] (z.))
 java.lang.IllegalArgumentException: Unable to resolve classname: z 
 (NO_SOURCE_FI
 LE:10)

I dunno what the defn z above is supposed to demonstrate. the analyzer
result for (z.) would be something like this is code creating an
instance of a type named 'z' in the namespace 'foo without arguments,
it doesn't reference any locals

 The other thing I'm starting to wonder is what doing all the above
 really gets us?

 For instance, let's say the analyzer sees this function:

 (defn as-str [x] (.toString x))

. is an interop form, the analysis would result in something like
call the interop toString on the local x, dunno what type x is

 That can't port to Python, or really any other VM besides JS. So if
 we're looking at translating the analyzer itself we have to develop
 some sort of base set of libraries that every thing else can build
 upon. So either we need to define a ur-clojure function called
 toString, and then every emitter will need to implement that
 seperately.

 At that point, I have to wonder what's the point of this analyzer
 step? In Clojure code is data is code. The more I think about what
 this serialized output would look like the more I think it would look
 just like Clojure code. What are we actually saving with this process?

 Timothy

the point of the analysis step is to generate a richer (more verbose)
set of information about the code, there is a lot of information you
would like to have when compiling (for example, for some platforms it
would be nice to know at the start of a function what locals exist in
the that function, or what locals it closes over) which are
extractable from the regular clojure data that represents code, but
it's takes an annoying amount of repetitive work to do so.

This is not to say you might not end up with a platform specific
analyzer (which would kind of be a shame, because I can imagine a
library of platform agnostic optimizers that run over analyzer
output), just a place to start from when bootstrapping.
 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with your 
 first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en



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

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


Re: Bootstrapping Clojure-in-Clojure

2012-05-14 Thread Kevin Downey
http://www.lambdassociates.org/blog/klambda.htm suggests a possible
bootstrapping mechanism, some kind of reduced set of clojure
functionality ur-clojure that is designed to be easy to write and
interpreter for, and a compiler backend that generates ur-clojure,
after compiling the compiler+platform backend to ur-clojure you write
an ur-clojure interpreter on the platform in question, feed the
compiler+backend through the interpreted compiler+backend to compile
it for the platform you are bootstrapping, and then you are
bootstrapped.

You could do something similar, but maybe simpler, by taking the maps
output from the analysis phase of the compiler run over the compiler
and serliazing them as json (so they are easily readable on different
platforms) effectively substituting the maps output from the analysis
phase for ur-clojure.

On Mon, May 14, 2012 at 11:36 AM, David Nolen dnolen.li...@gmail.com wrote:
 On Mon, May 14, 2012 at 2:32 PM, Armando Blancas abm221...@gmail.com
 wrote:

 Much of the more recent code in Clojure is very cross platform. Stuff
 like reducers can simply be copied over, fixed up a bit, and it runs.

 I wonder how is the fork/join part carrier over for reducers.


 Sounds straightforward for any language that provides task level parallelism
 natively or via a library.

 David

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



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

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


Re: Support for complex numbers added

2012-03-27 Thread Kevin Downey
On Mar 27, 2012 6:26 PM, Andrea Chiavazza ndrch...@gmail.com wrote:

 Hello everyone

 I had a go at adding support for complex numbers, it's at:
 https://github.com/andrea-chiavazza/clojure/tree/complex

 Some repl usage examples:

 user= (/ (complex 73 13) (complex 15 25))
 #Complex (142/85 -163/85i)

 user= (/ (complex 73 13) (complex 15.0 25.0))
 #Complex (1.6705882352941177 -1.9176470588235295i)

 user= (+ (complex 13 34) (complex 29 -34))
 42

 user= (require 'clojure.math)

 user= (clojure.math/abs (complex -14.94 21))
 25.772147756832375

 user= (clojure.math/sqrt -3)
 #Complex (0 +1.7320508075688772i)

 user= (clojure.math/sqrt 2)
 1.4142135623730951

 user= (clojure.math/sqrt (complex 2 3))
 #Complex (1.6741492280355401 +0.895977476129838i)

 user= (= (complex 12 34) (complex 12 34.0))
 false
 user= (== (complex 12 34) (complex 12 34.0))
 true

 I'm still not sure why #Complex comes up, while #Ratio doesn't with
similar operations.

You need to define a custom print-method for Complex.

 What also worries me a bit is that I changed a bunch of methods in
Numbers.java from accepting Object to being overloaded to accept Number and
Complex.

My intuition here is that the public interface of Numbers.java always
operates on Objects (essentially data with an unknown type at compile
time). The methods in Numbers.java that take more specific types are for
the compiler's use when optimizing, via inlining, type hinting, and
intrinsics.

 For example, this:
 static public Number add(Object x, Object y){
 return ops(x).combine(ops(y)).add((Number)x, (Number)y);
 }

 Has become:
 static public Number add(Number x, Number y){
 return ops(x).combine(ops(y)).add(x, y);
 }

 So that I could overload with this:
 static public Object add(Complex x, Complex y) {
 Number r = add(x.real, y.real);
 Number im = add(x.imaginary, y.imaginary);
 if (isZero(im))
 return r;
 else
 return new Complex(r, im);
 }

 A consequence is that this test:
   (is (thrown? ClassCastException (+ ab cd))) ); no string
concatenation
 Has become:
   (is (thrown? IllegalArgumentException (+ ab cd))) ); no string
concatenation

 I thought that overloading would be nicer and would avoid having to check
for the class of the Object.
 On the other hand all methods seem to accept an Object and then cast to
Number rather than just accepting a Number, so there might be a good reason
for that.
 Could somebody please enlighten me on this so that I can do it the right
way ?

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
your first post.
 To unsubscribe from 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: Compilable clojure program, but unreadable?

2012-03-11 Thread Kevin Downey
On Mar 11, 2012 4:10 PM, Stuart Sierra the.stuart.sie...@gmail.com
wrote:

 The syntax ::s/kwd is incorrect syntax: it should be either ::kwd (which
will resolve in the current namespace) or :s/kwd (only one colon).

 -S

::s/kwd is valid, it will cause the namespace of the resulting keyword to
be resolved via the namespace aliases in the current namespace.

please enjoy rhickey explaining this to cemerick:
http://clojure-log.n01se.net/date/2009-04-30.html#08:11

Clojure 1.4.0-master-SNAPSHOT

user= :s/k

:s/k

user= ::s/k

RuntimeException Invalid token: ::s/k  clojure.lang.Util.runtimeException
(Util.java:170)

user= (require '[clojure.string :as s])

nil

user= ::s/k

:clojure.string/k

user=


 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
your first post.
 To unsubscribe from 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: PersistentHashMap vs PersistentArrayMap in Postal Question

2012-03-04 Thread Kevin Downey
Your example is calling read-string so the resulting map has symbols
instead of strings
On Mar 4, 2012 7:23 AM, Brad Lucas b...@beaconhill.com wrote:

 I'm using Postal (https://github.com/drewr/postal) and found something
 I don't know how to fix.

 I have my application working fine if I have a var with my smtp
 properties created as follows:

 (def smtp-original {:host foo.com
  :port 2525
  :user me
  :pass pwd
  })

 Since I want to release my project for others I thought to modify it
 to read the smtp values from a Properties file. I used the routine
 from Dave Ray's answer on StackOverFlow (http://stackoverflow.com/a/
 7781443/406220).

 ;; Load smtp information out of a file from
 http://stackoverflow.com/a/7781443/406220
 (defn load-props
  [file-name]
  (with-open [^java.io.Reader reader (clojure.java.io/reader file-
 name)]
(let [props (java.util.Properties.)]
  (.load props reader)
  (into {} (for [[k v] props] [(keyword k) (read-string v)])

 This works well in that it returns a Map that looks just like the smtp-
 original when reading the following file.

 host=foo.com
 port=2525
 user=me
 pass=pwd


 The trouble is when I run my app and it calls into Postal I get a
 java.lang.ClassCastException.

 I notice that the smtp-original created with a def is a
 clojure.lang.PersistentHashMap while the return from load-props is a
 clojure.lang.PersistentArrayMap.

 I looked into Postal but don't see why this matters.

 So, I guess I have a few questions.

 Can I convert the PersistentArrayMap to a PersistentHashMap? Is this
 the right way to go?
 Is load-props doing something unusual? It seems fine.
 Does anyone understand the internals of Postal? Why would it not work
 with the PersistentArrayMap?

 Any ideas or pointers would be greatly appreciated. I'm looking to
 understand what is going on.

 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

Re: Hierarchical logs

2012-02-15 Thread Kevin Downey
https://gist.github.com/1314616 is a small example of a custom
dispatch, doesn't do custom indenting though

On Tue, Feb 14, 2012 at 6:33 PM, jweiss jeffrey.m.we...@gmail.com wrote:
 It occurred to me that ultimately what I want is just a pretty-printed
 output that I can put on a webpage and apply syntaxhighlighter to.

 I should be able to use a custom pprint dispatch to take this
 [[(+ 5 (- 4 2 (* 9 3)) (* 5 (+ 6 3))) nil]
  [(- 4 2 (* 9 3)) nil]
  [(* 9 3) nil]
  [27 true]
  [-25 true]
  [(* 5 (+ 6 3)) nil]
  [(+ 6 3) nil]
  [9 true]
  [45 true]
  [25 true]]

 and print something like this:

 (+ 5 (- 4 2 (* 9 3)) (* 5 (+ 6 3)))
  (- 4 2 (* 9 3))
    (* 9 3)
    27
  -25
  (* 5 (+ 6 3))
    (+ 6 3)
    9
  45
 25

 Without even converting it into a tree.  But I am having a hard time
 finding an example of custom dispatch, or docs on how to write one.  I
 really just want things printed the same as pprint currently does, but
 being able to specify extra indent for the whole block.  I had
 originally planned to output html where each item was properly nested
 as html divs, but I think that is getting overly complex.

 -jeff

 On Feb 14, 10:14 am, jweiss jeffrey.m.we...@gmail.com wrote:
 Thanks, Alan,

 The solution I used looks exactly like yours:

 (defn mktree [vz [i out?]]
   (if out?
     (- vz (zip/append-child i) zip/up )
     (- vz (zip/append-child [i]) zip/down zip/rightmost)))

 (defn as-tree [tracelist]
   (zip/root (reduce mktree (zip/vector-zip []) tracelist)))

 Thinking about it some more, I don't think I'm going to come up with a
 solution that's any more efficient or easy to code as this one.  The
 real work is figuring out where the next element needs to be
 inserted.  Zipper keeps that information as part of the data structure
 so it doesn't have to be re-calculated every iteration.  My previous
 solution using loop had kept an accumulator (a list of indices to pass
 to assoc-in).

 -jeff

 On Feb 12, 3:42 am, Alan Malloy a...@malloys.org wrote:







  I toyed with some simple ways of doing this, but I don't think any of
  them will actually work out. I think the advice you got in #clojure to
  use zippers is probably correct. Here's a sketch I bashed out that
  seems to do roughly what you want:https://gist.github.com/1807340(I
  took the liberty of wrapping the whole thing in another [] under the
  assumption you'd want to record multiple top-level calls; if not you
  can just call first on the result).

  On Feb 11, 8:39 pm, jweiss jeffrey.m.we...@gmail.com wrote:

   I've been working on a tracing library, that works much like
   clojure.contrib.trace (based on it, actually).   One sticky problem
   I've found is, hierarchical logs are really crappy to try to stream to
   a file.  You can't just keep writing to the end of the file - new data
   needs to be inserted before existing end-tags.  So what I'm doing is
   storing the data as a list, until I know the data is complete, and
   then i turn it back into a tree to write the file.

   However I can't think of a simple way to do it, even though it seems
   like a simple operation.

   I want to turn this list of pairs (first item is the fn call or return
   value, the second is a truthy value marking whether it's a call or
   return)

   '[[(+ 1 (- 5 2) nil]
    [(- 5 2) nil]
    [3 true]
    [4 true]]

   I want to turn that into
   [(+ 1 (- 5 2))
       [(- 5 2)
        3]
    4]

   Is there a simple way to do 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.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en



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

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


Re: Why don't these two functions produce equivalent results?

2012-01-27 Thread Kevin Downey
Please don't use transients unless you read and understand the
documentation.
On Jan 27, 2012 12:41 PM, Bill Robertson billrobertso...@gmail.com
wrote:

 I don't understand why the two functions below (recurs and transi) do
 not produce the same result. To the best of my understanding doseq
 will consume an entire sequence as demonstrated here:

 user= (doseq [x (range 0 10)] (print x))
 0123456789nil

 user= *clojure-version*
 {:major 1, :minor 3, :incremental 0, :qualifier nil}

 user= (defn recurs [dest src]
  (if-let [element (first src)]
(recur (assoc dest element element) (rest src))
dest))
 #'user/recurs
 user= (count (recurs {} (range 0 2)))
 2

 user= (defn transi [dest src]
  (let [temp (transient dest)]
(doseq [x src]
  (assoc! temp x x))
(persistent! temp)))
 #'user/transi
 user= (count (transi {} (range 0 2)))
 8
 user= (count (transi {} (range 0 20)))
 8
 user= (count (transi {} (range 0 8)))
 8
 user= (count (transi {} (range 0 7)))
 7

 Any ideas about why the first function does not behave the same as the
 second?

 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

Re: Conflicting transactions

2012-01-24 Thread Kevin Downey
On Tue, Jan 24, 2012 at 8:49 AM, Ersin Er ersin...@gmail.com wrote:
 Hi,

 What does conflicting transactions actually mean in terms of Clojure STM?
 Are they write-write transactions on a data structure or are they more
 granularly considered conflicting for example if they are manipulating the
 same element of a target data structure (e.g. HashMap)?

 Thanks.

Conflicts occur if two transactions alter or ref-set the same ref. It
seems obvious from your question that you haven't looked at the stm at
all (or clojure for that matter) so I suggest you read some
documentation or watch a video on it.

http://blip.tv/clojure/clojure-concurrency-819147

 --
 Ersin Er

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



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

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


Re: Bug in 1.3 with sets as functions?

2012-01-21 Thread Kevin Downey
Sets when used as functions are not predicates the do not return true or
false based on membership.

They return the looked up value, in this case false. You can say well I
passed in the value, why would I want it back but sets don't need to
return an identical object, just an equal object (could have different
metadata etc.

This behavior is not a bug. It seems unlikely that this interface/contract
would be changed, do you have compelling case for change?
On Jan 21, 2012 7:46 PM, Mark Engelberg mark.engelb...@gmail.com wrote:

 I believe it is a bug that:
 (#{true false} false) yields false
 whereas
 (contains? #{true false} false) yields true

 Can someone confirm or deny 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.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 would I learn more about Clojure's class loading system?

2012-01-05 Thread Kevin Downey
On Thu, Jan 5, 2012 at 12:21 PM, Daniel Bell dchristianb...@gmail.com wrote:
 So school has started, and I'm laden with syllabi, either in print or
 online.  I'm a stats student, so all my professors use LaTex
 for...well, everything.  So I have all these .pdf files.

 I had the idea of parsing them and extracting the homework schedules
 and then making a simple Android app that showed what was due
 depending on the date.  This is admittedly kind of overengineering the
 whole thing, but I just got the phone for Christmas and I've been
 itching to write something for it.

 In the process of trying to extract the text (I was using Apache's
 PDFBox), I ran into a NoClassDefFound error when importing certain
 classes.  I checked that all the .jars were in all the right places,
 etc, to no avail.

 I wasn't so much frustrated by the error (they happen) as with my
 inability to do much about it or really poke at it.  According to the
 Java docs, NCDF occurs when a class definition that was present at
 (Java's) compile time is absent at (Java's) runtime.  I'm not really
 sure how that could happen---where could I go for more insight into
 how java packages/classes are loaded?  (I actually have the
 clojure.core source in front of me as I write this, but can't seem to
 find where defmacro import becomes...well, whatever java it becomes)

 tl, dr: If I never wanted to have a classpath/library loading issue in
 Clojure ever again, what should I read?

 Thanks,

 Daniel

I don't know that anyone can help you without more details about your
environment.

Are you using lein? What version?
What version of PDFBox? What class can't it find?

etc.

feel free to hop on the #clojure irc channel on freenode

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



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

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


Re: How would I learn more about Clojure's class loading system?

2012-01-05 Thread Kevin Downey
There are a number of different possibilities.

Without anything more specific the only realistic answer is read the
source of all the libraries you are using, and of clojure, and of lein and
look for tricks with classloaders

Clojure does some classloader fiddling, but so do most jvm build tools and
many libraries and frameworks.

From memory:

Clojure uses a dynamic classloader stored in a var in a static field on the
compiler class.

The parent of the dynamic classloader is either the context classloader or
the system classloader.

In certain cases the compiler will use a new dynamic classloader for the
extent of compilation.

The relevent code is in RT.java, DynamicClassloader.java, and Compiler.java
On Jan 5, 2012 3:00 PM, Daniel Bell dchristianb...@gmail.com wrote:

 Thanks Kevin, but I'm not so much looking for debugging help on this
 specific issue as I'm asking what I should do if I want to be able to,
 say, help others with similar issues in the future.  Classpath stuff
 is a common bugaboo even for experienced Java developers (or so I
 hear), and all the finer points of clojure/Java interop have been a
 thorn in my side for a while now.  I'd like to just blow a weekend or
 three immersing myself in the stuff and get a more fundamental
 understanding of it than I have now.

 Your mention of lein reminds me that I should probably spend some time
 digging through that as well, since I use it for all my projects.

 Anyway, sorry to be so unclear; part of the problem is that I'm not
 expert enough to know exactly what I'm looking for.  But thanks for
 taking the time.

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from 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: Potential bug w/ inlined functions

2012-01-02 Thread Kevin Downey
On Jan 2, 2012 11:43 AM, Sam Ritchie sritchi...@gmail.com wrote:

 You're right, it's macro more than inlining. Tag metadata doesn't throw
an error, but it doesn't fix the reflection warning either (assuming I'm
doing it correctly):

 (defmacro barr= [^{:tag bytes} x ^{:tag bytes} y]
   `(java.util.Arrays/equals ~x ~y))

 (defmacro barr= [ x  y]
   `(java.util.Arrays/equals ^{:tag bytes} ~x
 ^{:tag bytes} ~y))


The pevious macro is incorrectly written.

 As for the approach, I wanted to start out by mimicking the
implementation of clojure.core/=. I haven't written inlined functions
before, and was curious about the potential speedup. I do like the idea of
a generic arr=.

 On Mon, Jan 2, 2012 at 11:27 AM, David Nolen dnolen.li...@gmail.com
wrote:

 I suspect this has more to do with type-hinting inside a macro. Did you
try adding :tag metadata to those symbols?

 As a side note I do find this approach a bit strange. Why not just
define a generic arr= that with multi-arity inlining?

 David

 On Mon, Jan 2, 2012 at 1:43 PM, Sam Ritchie sritchi...@gmail.com wrote:

 Hey all,

 I'm writing a function called barr= that looks just like
clojure.core/=, but uses java.util.Arrays/equals instead of equiv. To speed
up the function I tried adding type hints to both the function definition
and the 2-argument inlined version. Type hinting the inline function threw
an exception that makes me think the compiler is interpreting Here's the
gist: https://gist.github.com/1551640

 Type hints on the function definition work great:

 (defn barr=
   ([x] true)
   ([^bytes x ^bytes y]
  (java.util.Arrays/equals x y))
   ([x y  more]
  (if (barr= x y)
(if (next more)
  (recur y (first more) (next more))
  (barr= y (first more)))
false)))

 But hinting the inline version causes an exception:

 (defn barr=
   {:inline-arities #{2}
:inline (fn [x y] `(let [^bytes x# ~x
 ^bytes y# ~y]
(java.util.Arrays/equals x# y#)))}
   ([x] true)
   ([^bytes x ^bytes y]
  (java.util.Arrays/equals x y))
   ([x y  more]
  (if (barr= x y)
(if (next more)
  (recur y (first more) (next more))
  (barr= y (first more)))
false)))

 ;; CompilerException java.lang.IllegalArgumentException: Unable to
resolve classname:
 ;; clojure.core/bytes, compiling:(NO_SOURCE_PATH:54)

 The compiler seems to be interpreting this type hint as a var. Are type
hints not allowed inside of inline definitions for some reason?

 Cheers,
 --
 Sam Ritchie, Twitter Inc
 703.662.1337
 @sritchie09

 (Too brief? Here's why! http://emailcharter.org)

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
your first post.
 To unsubscribe from 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




 --
 Sam Ritchie, Twitter Inc
 703.662.1337
 @sritchie09

 (Too brief? Here's why! http://emailcharter.org)

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
your first post.
 To unsubscribe from 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

  1   2   3   >