Re: two pass compilation, intern and def

2013-09-19 Thread Colin Fleming
This is interesting - are there any other cases where forms are treated
specially at top-level?


On 20 September 2013 10:01, Gary Verhaegen  wrote:

> As Meikel said in his previous mail, 'do' at the top-level is treated
> specially: each form is treated as a separate top-level form. This is, for
> example, useful for defining a macro that defines multiple functions.
>
> So what Meikel was really trying to say is that the reason (do (intern
> 'user 'bob3 3) bob3) works is that it is treated the same as
>  (intern 'user 'bob3 3)
> bob3
>
> This special handling only occurs when do appears as a top-level form,
> which is the reason why your other examples fail.
>
> On Thursday, 19 September 2013, Phillip Lord wrote:
>
>> "Meikel Brandmeyer (kotarak)"  writes:
>> > Clojure's compile unit is one toplevel form. Therefore
>> >
>> > (intern 'user 'bob3 3)
>> > bob3
>> >
>> > works, while
>> >
>> > (is (do (intern 'user 'bob2 2) bob2))
>> >
>> > does not, because the former are two compilation units while the latter
>> is
>> > only one. (Note: (do ...) is a special case. (do (intern 'user 'bob3 3)
>> > bob3) should actually work.)
>>
>> Yep, do on it's own does work.
>>
>> The problem, here, then is that a chunk of code like
>>
>> (do (intern 'user 'bob3 3) bob3)
>>
>> Sometimes works, and sometimes doesn't. And whether it does or does not
>> depends on it's context. As I said in the last post, I'd worked out why
>> the immediate reason it fails. But I cannot understand from looking at
>> the code why
>>
>> (do (intern 'user 'bob3 3) bob3)
>>
>> is two compilation units, while
>>
>> (is (do (intern 'user 'bob3 3) bob3))
>>
>> or
>>
>> (try (do (intern 'user 'bob3 3) bob3))
>>
>> are both one (the latter fails also).
>>
>> Seems rather like a bug to me. If the compiler can identify that
>>
>>   (is (do (def bob3) bob3))
>>
>> is valid, the same should be true for an intern form.
>>
>> Phil
>>
>> --
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clojure@googlegroups.com
>> Note that posts from new members are moderated - please be patient with
>> your first post.
>> To unsubscribe from this group, send email to
>> clojure+unsubscr...@googlegroups.com
>> For more options, visit this group at
>> http://groups.google.com/group/clojure?hl=en
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "Clojure" group.
>> To 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.
>

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

2013-09-19 Thread Joel Holdbrooks
This looks really nice Carlo! It'd be even better if it were on GitHub so I 
could star it :). But I'm definitely going to take a look at this when I'm 
in the SQL world again.

On Wednesday, July 3, 2013 1:48:07 AM UTC-7, Carlo wrote:
>
> Hey guys!
>
> I've been working on a small library to make writing SQL queries a little 
> bit easier. It's along the same lines as ClojureQL, but takes a different 
> approach and compiles into quite different SQL in the end.
>
> At the moment it's quite immature, but it should be able to support any 
> queries which can be expressed in relational algebra. There will be some 
> SQL queries which can't be expressed in clojure-sql, but hopefully there 
> won't be too many of those. A greater limitation is that at the moment the 
> SQL generation is specific to the PostgresSQL database (although any 
> contributions for other databases are welcome!).
>
> Dependency vector: [clojure-sql "0.1.0"]
> Repository: https://bitbucket.org/czan/clojure-sql
> Clojars link: https://clojars.org/clojure-sql
>
> Let me know what you think!
>
> Carlo
>

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

2013-09-19 Thread Marco Munizaga
This release seemed to introduce a subtle bug with (clj->js ...) in advanced 
compilation. Here is the demo project (https://github.com/MarcoPolo/test-cljs). 
If you run (lein cljsbuild clean && lein cljsbuild auto) and use lein 
trampoline repl-listen (just for the webserver), the first compilation results 
in the expected (cljs->js {:command "function"}) to {command:"function"}, but 
subsequent compilations (after adding or deleting a line in core.cljs) causes 
(cljs->js {:command "function"}) to return {command:null}. This doesn't seem to 
happen in r1859. 
On Sunday, September 8, 2013 7:42:51 PM UTC-4, David Nolen wrote:
> ClojureScript, the Clojure compiler that emits JavaScript source code.
> 
> 
> README and source code: https://github.com/clojure/clojurescript
> 
> 
> New release version: 0.0-1877
> 
> 
> Leiningen dependency information:
> 
>     [org.clojure/clojurescript "0.0-1877"]
> 
> 
> 
> 
> 
> Breaking Changes: 
> 
> * Keywords are no longer represented as JavaScript Strings
> 
> 
> 
> 
> Enhancements: 
> 
> * Only analyze files that need re-analysis, significant speedup for 
> incremental compilation
> * Leiningen project.clj provided
> 
> 
> Fixes:
> * CLJS-582: duplicate items in sets
> 
> * CLJS-585: ChunkedCons does not implement INext
> * ClojureScript clojure.string/split same behavior as Clojure
> 
> * CLJS-565: Allow the clojurescript reader to read "%"
> * CLJS-580: def + fn bug when fn in a data literal
> 
> * CLJS-509: spurious protocol warning under incremental compilation

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


Safely flush old value out of an atom

2013-09-19 Thread Adam Clements
Hi,

I have been working on a setup where I batch a number of updates in a
queue, which I store in an atom with multiple threads potentially adding
things to it. Periodically I want to flush that queue, leaving an empty
list in the atom and passing the current batch of values on for further
processing.

I can't use swap! for this, because my further processing is side effecting
and I wouldn't want to dispatch the same information twice, and I can't use
reset! because that just throws away the old contents of the atom, and
derefing it in the line before I am likely to lose data if another thread
adds something at the last minute.

I could change to an agent with append and flush actions which would get
queued up and run only once each, and that would work. But it has quite a
lot of thread overhead which I think is unnecessary.

What I ended up doing was writing a version of reset! which returns the old
value instead of the new value (why would I want the new value? I know
that, I put it in!)

(defn flush! [atom newval]
   (let [val @atom]
  (if (compare-and-set! atom val newval)
 val
 (recur atom newval

=> (def a (atom [1 2 3 4]))
#'user/a
=> (flush! a [])
[1 2 3 4]
=> @a
[]

Is there already a standard library fn I should be using for this? Is this
a bad idea for some reason I don't fathom?

Adam

https://github.com/AdamClements

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

2013-09-19 Thread Mikera
Sounds to me like you should use an agent for this. 

Don't worry about the overhead prematurely, it's actually pretty minimal. 
Just make sure you choose between "send" and "send-off" appropriately (i.e. 
does your further processing block or not?)

On Friday, 20 September 2013 00:20:11 UTC+8, Adam Clements wrote:
>
> Hi,
>
> I have been working on a setup where I batch a number of updates in a 
> queue, which I store in an atom with multiple threads potentially adding 
> things to it. Periodically I want to flush that queue, leaving an empty 
> list in the atom and passing the current batch of values on for further 
> processing.
>
> I can't use swap! for this, because my further processing is side 
> effecting and I wouldn't want to dispatch the same information twice, and I 
> can't use reset! because that just throws away the old contents of the 
> atom, and derefing it in the line before I am likely to lose data if 
> another thread adds something at the last minute.
>
> I could change to an agent with append and flush actions which would get 
> queued up and run only once each, and that would work. But it has quite a 
> lot of thread overhead which I think is unnecessary.
>
> What I ended up doing was writing a version of reset! which returns the 
> old value instead of the new value (why would I want the new value? I know 
> that, I put it in!)
>
> (defn flush! [atom newval]
>(let [val @atom]
>   (if (compare-and-set! atom val newval)
>  val
>  (recur atom newval
>
> => (def a (atom [1 2 3 4]))
> #'user/a
> => (flush! a []) 
> [1 2 3 4]
> => @a 
> []
>
> Is there already a standard library fn I should be using for this? Is this 
> a bad idea for some reason I don't fathom?
>
> Adam 
>
> https://github.com/AdamClements
>  

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

2013-09-19 Thread Gary Verhaegen
As Meikel said in his previous mail, 'do' at the top-level is treated
specially: each form is treated as a separate top-level form. This is, for
example, useful for defining a macro that defines multiple functions.

So what Meikel was really trying to say is that the reason (do (intern
'user 'bob3 3) bob3) works is that it is treated the same as
(intern 'user 'bob3 3)
bob3

This special handling only occurs when do appears as a top-level form,
which is the reason why your other examples fail.

On Thursday, 19 September 2013, Phillip Lord wrote:

> "Meikel Brandmeyer (kotarak)" > writes:
> > Clojure's compile unit is one toplevel form. Therefore
> >
> > (intern 'user 'bob3 3)
> > bob3
> >
> > works, while
> >
> > (is (do (intern 'user 'bob2 2) bob2))
> >
> > does not, because the former are two compilation units while the latter
> is
> > only one. (Note: (do ...) is a special case. (do (intern 'user 'bob3 3)
> > bob3) should actually work.)
>
> Yep, do on it's own does work.
>
> The problem, here, then is that a chunk of code like
>
> (do (intern 'user 'bob3 3) bob3)
>
> Sometimes works, and sometimes doesn't. And whether it does or does not
> depends on it's context. As I said in the last post, I'd worked out why
> the immediate reason it fails. But I cannot understand from looking at
> the code why
>
> (do (intern 'user 'bob3 3) bob3)
>
> is two compilation units, while
>
> (is (do (intern 'user 'bob3 3) bob3))
>
> or
>
> (try (do (intern 'user 'bob3 3) bob3))
>
> are both one (the latter fails also).
>
> Seems rather like a bug to me. If the compiler can identify that
>
>   (is (do (def bob3) bob3))
>
> is valid, the same should be true for an intern form.
>
> Phil
>
> --
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com 
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To 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: [ANN] Cognitect

2013-09-19 Thread Devin Walters
Congratulations. *pops a bottle if champagne*

BTW, the new site looks great.

Cheers,
'(Devin Walters)

On Sep 17, 2013, at 3:01 AM, Mikera  wrote:

> Congrats on the new venture - wishing you the best of luck!
> 
> On Monday, 16 September 2013 21:50:46 UTC+8, Rich Hickey wrote:
>> 
>> I just wanted to let everyone know that Metadata Partners (the company 
>> behind Datomic) and I have merged with Relevance, Inc., to form Cognitect, 
>> Inc. This merger is great for Clojure, adding considerable resources and 
>> stability to its development and support, including new enterprise support 
>> offerings and reinvigorated community support. (You should read the hiring 
>> of Alex Miller as the first example of the latter). 
>> 
>> I hope the availability of enterprise support for the entire platform makes 
>> it easier for people to introduce Clojure into their organizations. 
>> 
>> This is a very exciting time for Clojure and the platform and ecosystem 
>> surrounding it. You can find out more at: 
>> 
>> http://cognitect.com 
>> 
>> Thanks, 
>> 
>> Rich
> 
> -- 
> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> --- 
> You received this message because you are subscribed to the Google Groups 
> "Clojure" group.
> To 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: [ClojureScript] Re: ANN: ClojureScript 0.0-1877 (Breaking change)

2013-09-19 Thread Monte Johnston
I am using 1889. Since the update, my keywords are getting printed as #<[object 
Object]> How do I print a keyword now?
 

On Wednesday, September 11, 2013 11:09:29 PM UTC-4, David Nolen wrote:
> 1878 went out today, the only change was fixing a bug introduced by 1877 that 
> caused spurious warnings when incrementally compiling.
> 
> 
> 
> On Mon, Sep 9, 2013 at 9:50 PM, Brandon Bloom  wrote:
> 
> 
> 
> > a (very) temporary workaround is to use the old code 
> 
> 
> 
> Why not just switch (k coll) to (get coll k) ?
> 
> 
> If you know that coll is non-nil, you can also just use (coll k). Both forms 
> also accept an optional not-found value.
> 
> 
> 
> 
> 
> 
> 
> -- 
> 
> Note that posts from new members are moderated - please be patient with your 
> first post.
> 
> --- 
> 
> You received this message because you are subscribed to the Google Groups 
> "ClojureScript" group.
> 
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to clojurescrip...@googlegroups.com.
> 
> To post to this group, send email to clojur...@googlegroups.com.
> 
> Visit this group at http://groups.google.com/group/clojurescript.

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

2013-09-19 Thread Adam Clements
It's possible with a ref, but I don't need to coordinate multiple bits of
state so a ref feels like overkill, and it makes adding to the list far
more cumbersome as it needs to be inside a dosync, and I essentially end up
writing atom-like functions to make that easier... by which point I may as
well have used an atom and my function.

Are refs faster? I guess I could add to my list commutatively which might
give some slight benefit, depending how many threads are bashing it. But I
still think there's value in being able to retrieve the old value of an
atom as part of a reset! type operation.

Adam


Adam Clements

+44 7947 724 795
--
This email and any files transmitted with it are confidential. If you are
not the intended recipient, you are hereby notified that any disclosure,
distribution or copying of this communication is strictly prohibited.


On Thu, Sep 19, 2013 at 5:21 PM, Ben Wolfson  wrote:

> Is there some reason you can't use a ref for this?
>
>
> On Thu, Sep 19, 2013 at 9:20 AM, Adam Clements wrote:
>
>> Hi,
>>
>> I have been working on a setup where I batch a number of updates in a
>> queue, which I store in an atom with multiple threads potentially adding
>> things to it. Periodically I want to flush that queue, leaving an empty
>> list in the atom and passing the current batch of values on for further
>> processing.
>>
>> I can't use swap! for this, because my further processing is side
>> effecting and I wouldn't want to dispatch the same information twice, and I
>> can't use reset! because that just throws away the old contents of the
>> atom, and derefing it in the line before I am likely to lose data if
>> another thread adds something at the last minute.
>>
>> I could change to an agent with append and flush actions which would get
>> queued up and run only once each, and that would work. But it has quite a
>> lot of thread overhead which I think is unnecessary.
>>
>> What I ended up doing was writing a version of reset! which returns the
>> old value instead of the new value (why would I want the new value? I know
>> that, I put it in!)
>>
>> (defn flush! [atom newval]
>>(let [val @atom]
>>   (if (compare-and-set! atom val newval)
>>  val
>>  (recur atom newval
>>
>> => (def a (atom [1 2 3 4]))
>> #'user/a
>> => (flush! a [])
>> [1 2 3 4]
>> => @a
>> []
>>
>> Is there already a standard library fn I should be using for this? Is
>> this a bad idea for some reason I don't fathom?
>>
>> Adam
>>
>> https://github.com/AdamClements
>>
>> --
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clojure@googlegroups.com
>> Note that posts from new members are moderated - please be patient with
>> your first post.
>> To unsubscribe from 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.
>>
>
>
>
> --
> 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
> ---
> 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: How do new defrecords get the implementation for hashmaps ?

2013-09-19 Thread Laurent PETIT
Hello,


2013/9/19 Murtaza Husain 

>
> Wow ! Thanks for the link Jozef.
>
> Another question  -
>
> From the Stuart Sierra blog on Lifecycle Composition -
>
>
> (defrecord Database [uri connection-atom]
>   Lifecycle
>   (start [_]
> (future (reset! connection-atom (connect uri
>   (stop [_]
> (.close @connection-atom)
> (future (reset! connection-atom nil
>
> (defn database [uri]
>   (->Database uri (atom nil)))
>
> I know I can create record objects as (Database. uri (atom nil))
>
> However I cant understand how and why the above (-> Database uri (atom
> nil)) works ?
>

No, it's (->Database uri (atom nil)) : there's no space between -> and
Database.

This factory function ->Database is automatically created by the defrecord
macro
(see the end of the docstring for defrecord:
http://clojure.github.io/clojure/clojure.core-api.html#clojure.core/defrecord)

HTH,

-- 
Laurent


>
> Thanks,
> Murtaza
>
>
> On Thursday, September 19, 2013 9:04:53 PM UTC+5:30, Jozef Wagner wrote:
>>
>> The example you've given is just a stub, not a full implementation of the
>> record. The magic is happening in emit-defrecord https://github.**
>> com/clojure/clojure/blob/**master/src/clj/clojure/core_**deftype.clj#L148
>>
>> Best,
>> JW
>>
>>
>>
>> On Thu, Sep 19, 2013 at 5:21 PM, Murtaza Husain > *com> wrote:
>>
>>> Hi,
>>>
>>> I was going through the article regarding clojure protocols and
>>> datatypes - http://www.ibm.com/**developerworks/java/library/j-**
>>> clojure-protocols/index.html
>>>
>>> In it an example is given for a new defrecord that the author creates.
>>> The generated java source for the record as given in the article -
>>>
>>>
>>> public class PurchaseOrder
>>> implements Fulfillment,
>>>java.io.Serializable,
>>>java.util.Map,
>>>java.lang.Iterable,
>>>clojure.lang.IPersistentMap {
>>>
>>> public final Object date;
>>> public final Object customer;
>>> public final Object products;
>>>
>>> public PurchaseOrder(Object date, Object customer, Object products) {
>>> this.date = date;
>>> this.customer = customer;
>>> this.products = products;
>>> }
>>> }
>>>
>>>
>>> My question - I can see that the generated class implements the
>>> java.util.Map and clojure.lang.IPersistentMap interfaces. However where are
>>> the code for implementations of the interfaces ? I do not see any concrete
>>> code other than the constructor and some fields.
>>>
>>> Thanks,
>>> Murtaza
>>>
>>>  --
>>> --
>>> 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/**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.
>

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

Re: How do new defrecords get the implementation for hashmaps ?

2013-09-19 Thread Murtaza Husain

Wow ! Thanks for the link Jozef.

Another question  - 

>From the Stuart Sierra blog on Lifecycle Composition - 

(defrecord Database [uri connection-atom]
  Lifecycle
  (start [_]
(future (reset! connection-atom (connect uri
  (stop [_]
(.close @connection-atom)
(future (reset! connection-atom nil

(defn database [uri]
  (->Database uri (atom nil)))

I know I can create record objects as (Database. uri (atom nil))

However I cant understand how and why the above (-> Database uri (atom 
nil)) works ? 

Thanks,
Murtaza


On Thursday, September 19, 2013 9:04:53 PM UTC+5:30, Jozef Wagner wrote:
>
> The example you've given is just a stub, not a full implementation of the 
> record. The magic is happening in emit-defrecord 
> https://github.com/clojure/clojure/blob/master/src/clj/clojure/core_deftype.clj#L148
>
> Best,
> JW
>
>
>
> On Thu, Sep 19, 2013 at 5:21 PM, Murtaza Husain <
> murtaza...@sevenolives.com > wrote:
>
>> Hi,
>>
>> I was going through the article regarding clojure protocols and datatypes 
>> - 
>> http://www.ibm.com/developerworks/java/library/j-clojure-protocols/index.html
>>
>> In it an example is given for a new defrecord that the author creates. 
>> The generated java source for the record as given in the article - 
>>
>> public class PurchaseOrder
>> implements Fulfillment, 
>>java.io.Serializable, 
>>java.util.Map,
>>java.lang.Iterable,
>>clojure.lang.IPersistentMap {
>>
>> public final Object date;
>> public final Object customer;
>> public final Object products;
>>
>> public PurchaseOrder(Object date, Object customer, Object products) {
>> this.date = date;
>> this.customer = customer;
>> this.products = products;
>> }
>> }
>>
>>
>> My question - I can see that the generated class implements the 
>> java.util.Map and clojure.lang.IPersistentMap interfaces. However where are 
>> the code for implementations of the interfaces ? I do not see any concrete 
>> code other than the constructor and some fields.
>>
>> Thanks,
>> Murtaza
>>
>>  -- 
>> -- 
>> 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/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: Safely flush old value out of an atom

2013-09-19 Thread Ben Wolfson
Is there some reason you can't use a ref for this?


On Thu, Sep 19, 2013 at 9:20 AM, Adam Clements wrote:

> Hi,
>
> I have been working on a setup where I batch a number of updates in a
> queue, which I store in an atom with multiple threads potentially adding
> things to it. Periodically I want to flush that queue, leaving an empty
> list in the atom and passing the current batch of values on for further
> processing.
>
> I can't use swap! for this, because my further processing is side
> effecting and I wouldn't want to dispatch the same information twice, and I
> can't use reset! because that just throws away the old contents of the
> atom, and derefing it in the line before I am likely to lose data if
> another thread adds something at the last minute.
>
> I could change to an agent with append and flush actions which would get
> queued up and run only once each, and that would work. But it has quite a
> lot of thread overhead which I think is unnecessary.
>
> What I ended up doing was writing a version of reset! which returns the
> old value instead of the new value (why would I want the new value? I know
> that, I put it in!)
>
> (defn flush! [atom newval]
>(let [val @atom]
>   (if (compare-and-set! atom val newval)
>  val
>  (recur atom newval
>
> => (def a (atom [1 2 3 4]))
> #'user/a
> => (flush! a [])
> [1 2 3 4]
> => @a
> []
>
> Is there already a standard library fn I should be using for this? Is this
> a bad idea for some reason I don't fathom?
>
> Adam
>
> https://github.com/AdamClements
>
> --
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from 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.
>



-- 
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
--- 
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: How do new defrecords get the implementation for hashmaps ?

2013-09-19 Thread Jozef Wagner
The example you've given is just a stub, not a full implementation of the
record. The magic is happening in emit-defrecord
https://github.com/clojure/clojure/blob/master/src/clj/clojure/core_deftype.clj#L148

Best,
JW



On Thu, Sep 19, 2013 at 5:21 PM, Murtaza Husain <
murtaza.hus...@sevenolives.com> wrote:

> Hi,
>
> I was going through the article regarding clojure protocols and datatypes
> -
> http://www.ibm.com/developerworks/java/library/j-clojure-protocols/index.html
>
> In it an example is given for a new defrecord that the author creates. The
> generated java source for the record as given in the article -
>
>
> public class PurchaseOrder
> implements Fulfillment,
>java.io.Serializable,
>java.util.Map,
>java.lang.Iterable,
>clojure.lang.IPersistentMap {
>
> public final Object date;
> public final Object customer;
> public final Object products;
>
> public PurchaseOrder(Object date, Object customer, Object products) {
> this.date = date;
> this.customer = customer;
> this.products = products;
> }
> }
>
>
> My question - I can see that the generated class implements the
> java.util.Map and clojure.lang.IPersistentMap interfaces. However where are
> the code for implementations of the interfaces ? I do not see any concrete
> code other than the constructor and some fields.
>
> 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
> ---
> 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.


How do new defrecords get the implementation for hashmaps ?

2013-09-19 Thread Murtaza Husain
Hi,

I was going through the article regarding clojure protocols and datatypes - 
http://www.ibm.com/developerworks/java/library/j-clojure-protocols/index.html

In it an example is given for a new defrecord that the author creates. The 
generated java source for the record as given in the article - 

public class PurchaseOrder
implements Fulfillment, 
   java.io.Serializable, 
   java.util.Map,
   java.lang.Iterable,
   clojure.lang.IPersistentMap {

public final Object date;
public final Object customer;
public final Object products;

public PurchaseOrder(Object date, Object customer, Object products) {
this.date = date;
this.customer = customer;
this.products = products;
}
}


My question - I can see that the generated class implements the 
java.util.Map and clojure.lang.IPersistentMap interfaces. However where are 
the code for implementations of the interfaces ? I do not see any concrete 
code other than the constructor and some fields.

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
--- 
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: XML namespace parsing - any movement?

2013-09-19 Thread Chris Perkins
On Wednesday, September 18, 2013 6:35:40 PM UTC-6, Korny wrote:
>
> So, the background - there is a page about fuller xml support at 
> http://dev.clojure.org/display/DXML/Fuller+XML+support - 
>
> Currently none of the xml parsing options support this - the best I've 
> found is https://github.com/grammati/eksemel but it hasn't been touched 
> in 2 years, and the last commit mentioned "embarrassingly slow" :)
>
>
I am the author of eksemel, and you're right that I no longer work on it (I 
no longer use XML much, if at all).

I don't recall exactly how slow it was - I think my performance 
measurements were pretty superficial. Probably the biggest problem with it 
at the moment is that it eagerly instantiates whole documents in memory, 
rather than lazily like data.xml, so is unusable for very large documents.

I do have a CA on file, so if you feel inclined to extract any of the code 
into a patch for data.xml, you are certainly welcome to do so. Having put 
in the work, I would love to see this code get into a state where it could 
actually be useful to someone. Unfortunately, I don't anticipate having 
much time to do so myself in the near future.

- Chris Perkins


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


Functional Programming in Bioinformatics, Birds-of-a-Feather Session at CUFP

2013-09-19 Thread Ashish Agarwal
 Functional Programming in Bioinformatics
 Birds-of-a-Feather Session at CUFP 2013
   September 23, 2013 at 6:00 PM
  Boston, MA United States

Bioinformatics is a discipline applying computational methods to biological
problems. Due to advances in experimental techniques, especially in
next-generation DNA sequencing, the amount of data being generated by
biologists is exponentially increasing. The resulting data deluge promises
to accelerate fundamental advances in human health, agriculture, and basic
research. However, progress is hindered due to the lack of software tools
for managing, analyzing, visualizing, and sharing such data.

The goal of this meeting is to bring together researchers and practitioners
of functional programming, logic, type theory, and related fields who are
interested in applying their skills to biology and medicine. We also
welcome biologists who are curious about state-of-the-art software
engineering techniques. The meeting will be casual with no presentations.
Our goal is simply to meet and discuss our interests, and propose future
events and collaborations. We will meet at Connolly’s Publik House within
the conference venue, the Hilton Boston Logan Airport Hotel, on Monday
September 23rd at 6:00 PM.

Everyone is welcome to attend this meeting regardless of whether you
registered for any ICFP or CUFP events. RSVP is not required, but to help
with planning, please email “agarwal1975 at gmail.com” if you know you will
attend.

Please also join the Well-Formed-Bio mailing list [1], which we welcome
everyone to use for discussions around the topic of formal software methods
applied to biology.

[1] https://groups.google.com/forum/#!forum/well-formed-bio
[2]
http://cufp.org/conference/sessions/2013/birds-feather-functional-programming-bioinformatic

Organizers: Ashish Agarwal, Jeff Hammerbacher

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

2013-09-19 Thread Phillip Lord
"Meikel Brandmeyer (kotarak)"  writes:
> Clojure's compile unit is one toplevel form. Therefore
>
> (intern 'user 'bob3 3) 
> bob3
>
> works, while
>
> (is (do (intern 'user 'bob2 2) bob2))
>
> does not, because the former are two compilation units while the latter is 
> only one. (Note: (do ...) is a special case. (do (intern 'user 'bob3 3) 
> bob3) should actually work.)

Yep, do on it's own does work.

The problem, here, then is that a chunk of code like

(do (intern 'user 'bob3 3) bob3)

Sometimes works, and sometimes doesn't. And whether it does or does not
depends on it's context. As I said in the last post, I'd worked out why
the immediate reason it fails. But I cannot understand from looking at
the code why

(do (intern 'user 'bob3 3) bob3)

is two compilation units, while 

(is (do (intern 'user 'bob3 3) bob3))

or 

(try (do (intern 'user 'bob3 3) bob3))

are both one (the latter fails also).

Seems rather like a bug to me. If the compiler can identify that 

  (is (do (def bob3) bob3))

is valid, the same should be true for an intern form.

Phil

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

2013-09-19 Thread Meikel Brandmeyer (kotarak)
Hi,

the difference between type and class is, that type inspects the metadata 
first for a :type keyword. This let's you bless data structures with a type 
tag eg. for printing or multimethod dispatching. This predates records and 
protocols. It is used in pr, which triggers the exception while printing in 
the repl. It's not a bug. It's a (old) feature.

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
--- 
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: two pass compilation, intern and def

2013-09-19 Thread Meikel Brandmeyer (kotarak)
Hi,

Clojure's compile unit is one toplevel form. Therefore

(intern 'user 'bob3 3) 
bob3

works, while

(is (do (intern 'user 'bob2 2) bob2))

does not, because the former are two compilation units while the latter is 
only one. (Note: (do ...) is a special case. (do (intern 'user 'bob3 3) 
bob3) should actually work.)

Then there is a separate effect in that def immediately creates the Var 
when encountered during compilation. That explains why the def variant 
works as well. (And as a side-note: that's also why you don't do (defn foo 
[] (def a ...) ...))

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


two pass compilation, intern and def

2013-09-19 Thread Phillip Lord


In a clean repl, try the following...

(use 'clojure.test)
(is (do (intern 'user 'bob2 2) bob2))
(is (do (def bob3 3) bob3))

The first is form breaks with a "Unable to resolve symbol" error 
at the compilation stage. The second one, on the other hand is quite
happy.

Now, I guess what is happening is this. At the compilation stage,
clojure has identified that

(def bob3 3)

happens before

bob3

so, everything is fine. But the same is not happening with the intern
statement. But surely it should be? After all

(intern 'user 'bob3 3)
bob3

is perfectly happy.

I want to use intern because I can do stuff like

(let [nm "bob4"
  vl 4]
  (intern 'user (symbol nm) vl))

which is harder to do with def.

Any advice?

Phil
 

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