Is gensym used for anything except alpha-conversion in macros?

2011-07-10 Thread Kazimir Majorinc

Is gensym used for anything in Clojure except for alpha-conversion in
macros?

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


comparator that compares collections similar to how strings are compared

2011-07-10 Thread Eugen Dück
Say I have this sorted map, using strings as keys:

x=> (sorted-map "ab" 1 "n" 2)
{"ab" 1, "n" 2}

When I do a subseq

x=> (subseq (sorted-map "ab" 1 "n" 2) > "aa")
(["ab" 1] ["n" 2])

I get back both entries.

Now if I do the same subseq on the same map, except that I turn all
strings into character collections, I only get the "ab" entry:

x=> (subseq (sorted-map (vec "ab") 1 (vec "n") 2) > (vec "aa"))
([[\a \b] 1])

I guess that's fine, the length of collections is probably used first
and only if it differs would the actual entries be compared.

Using my own comparator to simulate the string comparison I can get
the string-like behavior:

(defn string-like-coll-comparator
[coll1 coll2]
(first (drop-while zero? (map compare coll1 coll2

x=> (subseq (sorted-map-by string-like-coll-comparator (vec "ab") 1
(vec "n") 2) > (vec "aa"))
([[\a \b] 1] [[\n] 2])

Here's my question - is this the best way to get what I want?

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

2011-07-10 Thread Colin Yates
But then how would all the consultants make their money? ;)

Sent from my iPad

On 10 Jul 2011, at 04:56, Luc Prefontaine  wrote:

> Hey, if it does not take a year and an army of nuclear scientists to 
> implement, it would already
> be better :
>
> On Sun, 10 Jul 2011 09:22:18 +0530
> Vivek Khurana  wrote:
>
>> On Sun, Jul 10, 2011 at 9:06 AM, Luc Prefontaine
>>  wrote:
>>>
>>> Maybe we should create something better than SAP :)
>>
>> Not exactly better than SAP, but I am working on a business
>> management framework based on clojure.
>>
>> regards
>> Vivek
>>
>
>
>
> --
> Luc P.
>
> 
> The rabid Muppet
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.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: Is gensym used for anything except alpha-conversion in macros?

2011-07-10 Thread Luc Prefontaine
No, use it any time you need an arbitrary symbol.


On Sun, 10 Jul 2011 10:41:56 +0200
Kazimir Majorinc  wrote:

> Is gensym used for anything in Clojure except for alpha-conversion in
> macros?
> 



-- 
Luc P.


The rabid Muppet

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


Re: comparator that compares collections similar to how strings are compared

2011-07-10 Thread Eugen Dück
Well, it can't be the best, because it has a bug. Calling it with "a"
instead of "aa" gives me a NPE:

x=> (subseq (sorted-map-by string-like-coll-comparator (vec "ab") 1
(vec "n") 2) > (vec "a"))
NullPointerException   clojure.lang.AFunction.compare (AFunction.java:
59)

The following comparator should do the trick:

(defn string-like-coll-comparator
  [coll1 coll2]
  (or (first (drop-while zero? (map compare coll1 coll2)))
  (- (count coll1) (count coll2

x=> (subseq (sorted-map-by string-like-coll-comparator (vec "ab") 1
(vec "n") 2) > (vec "a"))
([[\a \b] 1] [[\n] 2])

So is this then the best way to get the sorting behavior I need?

On Jul 10, 6:09 pm, Eugen Dück  wrote:
> Say I have this sorted map, using strings as keys:
>
> x=> (sorted-map "ab" 1 "n" 2)
> {"ab" 1, "n" 2}
>
> When I do a subseq
>
> x=> (subseq (sorted-map "ab" 1 "n" 2) > "aa")
> (["ab" 1] ["n" 2])
>
> I get back both entries.
>
> Now if I do the same subseq on the same map, except that I turn all
> strings into character collections, I only get the "ab" entry:
>
> x=> (subseq (sorted-map (vec "ab") 1 (vec "n") 2) > (vec "aa"))
> ([[\a \b] 1])
>
> I guess that's fine, the length of collections is probably used first
> and only if it differs would the actual entries be compared.
>
> Using my own comparator to simulate the string comparison I can get
> the string-like behavior:
>
> (defn string-like-coll-comparator
>     [coll1 coll2]
>     (first (drop-while zero? (map compare coll1 coll2
>
> x=> (subseq (sorted-map-by string-like-coll-comparator (vec "ab") 1
> (vec "n") 2) > (vec "aa"))
> ([[\a \b] 1] [[\n] 2])
>
> Here's my question - is this the best way to get what I want?

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

2011-07-10 Thread Oded Badt
I see

Guess I'm a bit too much used to programming javascript where a
function always carries its source around with it - a very very
convenient tool in very functional languages where functions are
passed along so often

anyway, gr8 thanks!
   Oded

On Jul 7, 12:11 pm, Sunil S Nandihalli 
wrote:
> Oded,
>  If you look at the source of source .. you will notice that the source is
> not stored in the meta information but it just picks up the filename and
> line-number form the meta info of the function and reads the corresponding
> files to obtain the source..
>
> This would not be possible if you defined a function at the repl .. this
> will not possible..
>
> Sunil
>
>
>
>
>
>
>
> On Thu, Jul 7, 2011 at 2:16 PM, Oded Badt  wrote:
> > Thanks, the command you wrote indeed works, but I cant get it to work
> > for just 'some' function I defined in the repl.
> > Here's my repl transcript, let me know what I'm doing wrong
>
> > user=> (def f (let [a 5] (fn [x] (+ x a
> > #'user/f
> > user=> (f 6)
> > 11
> > user=> (read-string (with-out-str (source f)))
> > Source
>
> > thanks
> >    Oded
>
> > On Jul 2, 11:20 pm, Shantanu Kumar  wrote:
> > > To get the source form of the function "map?":
>
> > > (read-string (with-out-str (source map?)))
>
> > > This may not work only when the function has been AOT'ed already. Hope
> > > this helps.
>
> > > Regards,
> > > Shantanu
>
> > > On Jul 2, 11:34 am, Oded Badt  wrote:
>
> > > > Hey,
>
> > > > Does anyone know of a way, given a function, to discover it's closure
> > > > programatically?
> > > > I often find myself holding a pointer to such a function that only
> > > > when knowing to what values it is bound to one can tell what it
> > > > actually does.
>
> > > > So it can be very helpful to be able to query the runtime (generally
> > > > in the repl) what the function is bound to
>
> > > > thanks
> > > >    Oded
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Clojure" group.
> > To post to this group, send email to clojure@googlegroups.com
> > Note that posts from new members are moderated - please be patient with
> > your first post.
> > To unsubscribe from 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: comparator that compares collections similar to how strings are compared

2011-07-10 Thread Eugen Dück
Well, turns out string-like-coll-comparator has a bug:

x=> (subseq (sorted-map-by string-like-coll-comparator (vec "ab") 1
(vec "n") 2) > (vec "a"))
NullPointerException   clojure.lang.AFunction.compare (AFunction.java:
59)

It can be fixed though:

(defn string-like-coll-comparator
  [coll1 coll2]
  (or (first (drop-while zero? (map compare coll1 coll2)))
  (- (count coll1) (count coll2

Now, is this the way to get the sorting behavior I want or is anyone
aware of something simpler or more performant?

On Jul 10, 6:09 pm, Eugen Dück  wrote:
> Say I have this sorted map, using strings as keys:
>
> x=> (sorted-map "ab" 1 "n" 2)
> {"ab" 1, "n" 2}
>
> When I do a subseq
>
> x=> (subseq (sorted-map "ab" 1 "n" 2) > "aa")
> (["ab" 1] ["n" 2])
>
> I get back both entries.
>
> Now if I do the same subseq on the same map, except that I turn all
> strings into character collections, I only get the "ab" entry:
>
> x=> (subseq (sorted-map (vec "ab") 1 (vec "n") 2) > (vec "aa"))
> ([[\a \b] 1])
>
> I guess that's fine, the length of collections is probably used first
> and only if it differs would the actual entries be compared.
>
> Using my own comparator to simulate the string comparison I can get
> the string-like behavior:
>
> (defn string-like-coll-comparator
>     [coll1 coll2]
>     (first (drop-while zero? (map compare coll1 coll2
>
> x=> (subseq (sorted-map-by string-like-coll-comparator (vec "ab") 1
> (vec "n") 2) > (vec "aa"))
> ([[\a \b] 1] [[\n] 2])
>
> Here's my question - is this the best way to get what I want?

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

2011-07-10 Thread Eugen Dück
Hm, google groups did not show my first reply to myself for a while,
and I thought it had gotten lost in the way, so I sent another post,
which can be safely ignored, in case anyone wonders what the
difference between the first and the second reply is - there is none,
fundamentally.

On Jul 10, 7:54 pm, Eugen Dück  wrote:
> Well, turns out string-like-coll-comparator has a bug:
>
> x=> (subseq (sorted-map-by string-like-coll-comparator (vec "ab") 1
> (vec "n") 2) > (vec "a"))
> NullPointerException   clojure.lang.AFunction.compare (AFunction.java:
> 59)
>
> It can be fixed though:
>
> (defn string-like-coll-comparator
>   [coll1 coll2]
>   (or (first (drop-while zero? (map compare coll1 coll2)))
>       (- (count coll1) (count coll2
>
> Now, is this the way to get the sorting behavior I want or is anyone
> aware of something simpler or more performant?
>
> On Jul 10, 6:09 pm, Eugen Dück  wrote:
>
>
>
>
>
>
>
> > Say I have this sorted map, using strings as keys:
>
> > x=> (sorted-map "ab" 1 "n" 2)
> > {"ab" 1, "n" 2}
>
> > When I do a subseq
>
> > x=> (subseq (sorted-map "ab" 1 "n" 2) > "aa")
> > (["ab" 1] ["n" 2])
>
> > I get back both entries.
>
> > Now if I do the same subseq on the same map, except that I turn all
> > strings into character collections, I only get the "ab" entry:
>
> > x=> (subseq (sorted-map (vec "ab") 1 (vec "n") 2) > (vec "aa"))
> > ([[\a \b] 1])
>
> > I guess that's fine, the length of collections is probably used first
> > and only if it differs would the actual entries be compared.
>
> > Using my own comparator to simulate the string comparison I can get
> > the string-like behavior:
>
> > (defn string-like-coll-comparator
> >     [coll1 coll2]
> >     (first (drop-while zero? (map compare coll1 coll2
>
> > x=> (subseq (sorted-map-by string-like-coll-comparator (vec "ab") 1
> > (vec "n") 2) > (vec "aa"))
> > ([[\a \b] 1] [[\n] 2])
>
> > Here's my question - is this the best way to get what I want?

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

2011-07-10 Thread David Jagoe
Thanks for your response Devin.

I guess I had come to the same conclusion by the end of my email. But
I wonder if there is a more direct way of achieving the same thing
without using a macro that spits out a defrecord with in-line method
declarations? I had a quick look at the defrecord code and didn't
follow well enough to see what machinery is being used internally to
extend the record to the java interface.

In short: why can I implement java interfaces within a defrecord body
but not when using extend?


Cheers,
David

On 9 July 2011 02:35, Devin Walters  wrote:
> What I think Kevin meant to say was that you might consider using a macro.
>
> If you have questions about specifics, please do reply. This group is here to 
> Help, and it would be a shame if a response like the previous one steered you 
> away from asking a follow-up.
>
> Sent via mobile
>
> On Jul 8, 2011, at 5:14 PM, Kevin Downey  wrote:
>
>> if only lisp had macros
>>
>> On Fri, Jul 8, 2011 at 12:16 PM, David Jagoe  wrote:
>>> Hi All,
>>>
>>> I am battling with how to deal with the difference between Protocols
>>> and Interfaces in a particular case.
>>>
>>> Consider the following code:
>>>
>>> (defrecord DomainTypeA []
>>>  SomeInternalProtocol
>>>  (foo [this] "foo result")
>>>
>>>  clojure.lang.IFn
>>>  (invoke [this] "invoke result"))
>>>
>>> This code works fine.
>>>
>>> However, I have a number of domain types all of which must use the
>>> same implementation of foo and invoke.
>>>
>>> In the case off foo its easy:
>>>
>>> (defrecord DomainTypeA [])
>>> (extend DomainTypeA SomeInternalProtocol 
>>> internal-protocol-implementation-map)
>>>
>>> However I cannot do:
>>>
>>> (extend DomainTypeA clojure.lang.IFn some-implementation)
>>>
>>> because IFn is a java Interface. How would I get arount this?
>>>
>>> My use case is as follows:
>>>
>>> Every one of my domain objects needs to implement invoke in the same
>>> way, so I don't want to code it in-line on the record definition each
>>> time. The implementation is defined in one place and I eventually want
>>> a macro (e.g. defdomainobj but with a better name!) that would
>>> automatically hook up the IFn def.
>>>
>>> Hmm maybe I just answered my own question:
>>>
>>> Should I just write the macro that spits out the code in my first listing?
>>>
>>> Thanks!
>>>
>>> Cheers,
>>> 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
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from 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: Question on eliminating recur

2011-07-10 Thread Joost
On Jul 10, 7:15 am, Michael Gardner  wrote:
>
> I think Christian wanted to know *why* one "should" eliminate recur. I can't 
> think of a reason to avoid it myself, though I also don't recall hearing any 
> recommendations against using recur.

Just my two cents, but the main reason to consider map/doseq/reduce/
filter etc in favor of loop/recur is that if your algorithm matches
one of the former, you'll need a little less boiler-plate code
(sometimes), makes it easier to use/create lazy sequences and (most
importantly) using map/doseq etc when appropriate conveys a lot of
information about the structure of the algorithm and its input/output
expectations to the human reader.

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

2011-07-10 Thread Jonathan Fischer Friberg
I think the reason is that an interface means that the function must be
'inside' the class.
I.e you can call (.method object). Since it isn't possible to extend a java
class in that way, it isn't possible to use extend. In a defrecord body
however, a new class is defined, which means that it's possible to define
functions 'inside' that class.

Protocols on the other hand doesn't define functions 'inside' the object,
they are simply standard functions.

Jonathan

On Sun, Jul 10, 2011 at 1:15 PM, David Jagoe  wrote:

> Thanks for your response Devin.
>
> I guess I had come to the same conclusion by the end of my email. But
> I wonder if there is a more direct way of achieving the same thing
> without using a macro that spits out a defrecord with in-line method
> declarations? I had a quick look at the defrecord code and didn't
> follow well enough to see what machinery is being used internally to
> extend the record to the java interface.
>
> In short: why can I implement java interfaces within a defrecord body
> but not when using extend?
>
>
> Cheers,
> David
>
> On 9 July 2011 02:35, Devin Walters  wrote:
> > What I think Kevin meant to say was that you might consider using a
> macro.
> >
> > If you have questions about specifics, please do reply. This group is
> here to Help, and it would be a shame if a response like the previous one
> steered you away from asking a follow-up.
> >
> > Sent via mobile
> >
> > On Jul 8, 2011, at 5:14 PM, Kevin Downey  wrote:
> >
> >> if only lisp had macros
> >>
> >> On Fri, Jul 8, 2011 at 12:16 PM, David Jagoe 
> wrote:
> >>> Hi All,
> >>>
> >>> I am battling with how to deal with the difference between Protocols
> >>> and Interfaces in a particular case.
> >>>
> >>> Consider the following code:
> >>>
> >>> (defrecord DomainTypeA []
> >>>  SomeInternalProtocol
> >>>  (foo [this] "foo result")
> >>>
> >>>  clojure.lang.IFn
> >>>  (invoke [this] "invoke result"))
> >>>
> >>> This code works fine.
> >>>
> >>> However, I have a number of domain types all of which must use the
> >>> same implementation of foo and invoke.
> >>>
> >>> In the case off foo its easy:
> >>>
> >>> (defrecord DomainTypeA [])
> >>> (extend DomainTypeA SomeInternalProtocol
> internal-protocol-implementation-map)
> >>>
> >>> However I cannot do:
> >>>
> >>> (extend DomainTypeA clojure.lang.IFn some-implementation)
> >>>
> >>> because IFn is a java Interface. How would I get arount this?
> >>>
> >>> My use case is as follows:
> >>>
> >>> Every one of my domain objects needs to implement invoke in the same
> >>> way, so I don't want to code it in-line on the record definition each
> >>> time. The implementation is defined in one place and I eventually want
> >>> a macro (e.g. defdomainobj but with a better name!) that would
> >>> automatically hook up the IFn def.
> >>>
> >>> Hmm maybe I just answered my own question:
> >>>
> >>> Should I just write the macro that spits out the code in my first
> listing?
> >>>
> >>> Thanks!
> >>>
> >>> Cheers,
> >>> 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
> >
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Clojure" group.
> > To post to this group, send email to clojure@googlegroups.com
> > Note that posts from new members are moderated - please be patient with
> your first post.
> > To unsubscribe from this group, send email to
> > clojure+unsubscr...@googlegroups.com
> > For more options, visit this group at
> > http://groups.google.com/group/clojure?hl=en
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
>

-- 
You received this message 

Re: Clojure 1.3 Beta 1

2011-07-10 Thread Stuart Sierra
Hi Mark,

Please see to http://dev.clojure.org/display/design/Clojure+Contrib

To migrate an old clojure-contrib namespace, just ask on the clojure-dev 
list.

-S

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

Re: Clojure 1.3 Beta 1

2011-07-10 Thread Mark Engelberg
Whoops, I thought I was asking on the dev list, but autocompletion
sent it to the regular clojure list.  Sorry about that.  I'm resending
to the dev list.

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


Local bindings w/o let

2011-07-10 Thread octopusgrabbus
>From Clojure api for max

(defn max
  "Returns the greatest of the nums."
  {:added "1.0"}
  ([x] x)
  ([x y] (if (> x y) x y))
  ([x y & more]
   (reduce max (max x y) more)))

Question 1: Why can y be introduced as a local binding without a let?

Question 2: What is the map   {:added "1.0"} doing?

Thanks.
cmn

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

2011-07-10 Thread octopusgrabbus
For Question 1 this is an example of multiple interfaces. Got it.

On Jul 10, 5:42 pm, octopusgrabbus  wrote:
> From Clojure api for max
>
> (defn max
>   "Returns the greatest of the nums."
>   {:added "1.0"}
>   ([x] x)
>   ([x y] (if (> x y) x y))
>   ([x y & more]
>    (reduce max (max x y) more)))
>
> Question 1: Why can y be introduced as a local binding without a let?
>
> Question 2: What is the map   {:added "1.0"} doing?
>
> Thanks.
> cmn

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

2011-07-10 Thread Luc Prefontaine
2) Meta data, max was introduced in V1.0

On Sun, 10 Jul 2011 14:44:16 -0700 (PDT)
octopusgrabbus  wrote:

> For Question 1 this is an example of multiple interfaces. Got it.
> 
> On Jul 10, 5:42 pm, octopusgrabbus  wrote:
> > From Clojure api for max
> >
> > (defn max
> >   "Returns the greatest of the nums."
> >   {:added "1.0"}
> >   ([x] x)
> >   ([x y] (if (> x y) x y))
> >   ([x y & more]
> >    (reduce max (max x y) more)))
> >
> > Question 1: Why can y be introduced as a local binding without a
> > let?
> >
> > Question 2: What is the map   {:added "1.0"} doing?
> >
> > Thanks.
> > cmn
> 



-- 
Luc P.


The rabid Muppet

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


Native compiler on Clojure

2011-07-10 Thread cran1988

Did anyone started creating native compiler for Clojure language ?

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

2011-07-10 Thread Jonathan Fischer Friberg
There's no interfaces, that's the function definition.

define function max
(defn max

attach docstring
"Returns the greatest of the nums."

attach metadata
{:added "1.0"}

if max is called with one argument, use this function definition
([x] x)

if max is called with two arguments, use this function definition
([x y] (if (> x y) x y))

if max is called with more than two arguments, use this function definition
([x y & more]
  (reduce max (max x y) more)))
___

As you can see, y is introduced in one of the functions definitions.
Also see:
http://clojure.org/special_forms#Special%20Forms--(fn%20name?%20[params*%20]%20exprs*)
and
http://clojure.org/metadata

Jonathan

On Sun, Jul 10, 2011 at 11:44 PM, octopusgrabbus
wrote:

> For Question 1 this is an example of multiple interfaces. Got it.
>
> On Jul 10, 5:42 pm, octopusgrabbus  wrote:
> > From Clojure api for max
> >
> > (defn max
> >   "Returns the greatest of the nums."
> >   {:added "1.0"}
> >   ([x] x)
> >   ([x y] (if (> x y) x y))
> >   ([x y & more]
> >(reduce max (max x y) more)))
> >
> > Question 1: Why can y be introduced as a local binding without a let?
> >
> > Question 2: What is the map   {:added "1.0"} doing?
> >
> > Thanks.
> > cmn
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from 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: Local bindings w/o let

2011-07-10 Thread octopusgrabbus
If the function is called with one argument, what Clojure language
rule allows x to appear outside the vector brackets?

On Jul 10, 7:18 pm, Jonathan Fischer Friberg 
wrote:
> There's no interfaces, that's the function definition.
>
> define function max
> (defn max
>
> attach docstring
> "Returns the greatest of the nums."
>
> attach metadata
> {:added "1.0"}
>
> if max is called with one argument, use this function definition
> ([x] x)
>
> if max is called with two arguments, use this function definition
> ([x y] (if (> x y) x y))
>
> if max is called with more than two arguments, use this function definition
> ([x y & more]
>   (reduce max (max x y) more)))
> ___
>
> As you can see, y is introduced in one of the functions definitions.
> Also 
> see:http://clojure.org/special_forms#Special%20Forms--(fn%20name?%20[params*%20]%20exprs*)
> andhttp://clojure.org/metadata
>
> Jonathan
>
> On Sun, Jul 10, 2011 at 11:44 PM, octopusgrabbus
> wrote:
>
> > For Question 1 this is an example of multiple interfaces. Got it.
>
> > On Jul 10, 5:42 pm, octopusgrabbus  wrote:
> > > From Clojure api for max
>
> > > (defn max
> > >   "Returns the greatest of the nums."
> > >   {:added "1.0"}
> > >   ([x] x)
> > >   ([x y] (if (> x y) x y))
> > >   ([x y & more]
> > >    (reduce max (max x y) more)))
>
> > > Question 1: Why can y be introduced as a local binding without a let?
>
> > > Question 2: What is the map   {:added "1.0"} doing?
>
> > > Thanks.
> > > cmn
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Clojure" group.
> > To post to this group, send email to clojure@googlegroups.com
> > Note that posts from new members are moderated - please be patient with
> > your first post.
> > To unsubscribe from 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: Local bindings w/o let

2011-07-10 Thread octopusgrabbus
I have another question about max. Is there an advantage if this were
re-written with repl?

On Jul 10, 7:18 pm, Jonathan Fischer Friberg 
wrote:
> There's no interfaces, that's the function definition.
>
> define function max
> (defn max
>
> attach docstring
> "Returns the greatest of the nums."
>
> attach metadata
> {:added "1.0"}
>
> if max is called with one argument, use this function definition
> ([x] x)
>
> if max is called with two arguments, use this function definition
> ([x y] (if (> x y) x y))
>
> if max is called with more than two arguments, use this function definition
> ([x y & more]
>   (reduce max (max x y) more)))
> ___
>
> As you can see, y is introduced in one of the functions definitions.
> Also 
> see:http://clojure.org/special_forms#Special%20Forms--(fn%20name?%20[params*%20]%20exprs*)
> andhttp://clojure.org/metadata
>
> Jonathan
>
> On Sun, Jul 10, 2011 at 11:44 PM, octopusgrabbus
> wrote:
>
> > For Question 1 this is an example of multiple interfaces. Got it.
>
> > On Jul 10, 5:42 pm, octopusgrabbus  wrote:
> > > From Clojure api for max
>
> > > (defn max
> > >   "Returns the greatest of the nums."
> > >   {:added "1.0"}
> > >   ([x] x)
> > >   ([x y] (if (> x y) x y))
> > >   ([x y & more]
> > >    (reduce max (max x y) more)))
>
> > > Question 1: Why can y be introduced as a local binding without a let?
>
> > > Question 2: What is the map   {:added "1.0"} doing?
>
> > > Thanks.
> > > cmn
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Clojure" group.
> > To post to this group, send email to clojure@googlegroups.com
> > Note that posts from new members are moderated - please be patient with
> > your first post.
> > To unsubscribe from 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


Rich Hickey up for deletion

2011-07-10 Thread Michal B
Rich Hickey's article in Wikipedia is up for deletion again. Does anyone 
have links to solid articles about Hickey?

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

2011-07-10 Thread Alan Malloy
http://www.codequarterly.com/2011/rich-hickey/ ?

On Jul 10, 6:26 pm, Michal B  wrote:
> Rich Hickey's article in Wikipedia is up for deletion again. Does anyone
> have links to solid articles about Hickey?

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

2011-07-10 Thread Matt Hoyt
The JVM does compile to native code once it is executed a specific number of 
times.  That's what the JIT compiler does.  You can control how many times a 
piece of code executes before it gets compiled by changing this JVM 
option -XX:CompileThreshold=.

If you want to look at other JVM options you can view the whole list 
here http://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html

Someone did post in the mail list earlier this week or last week about a 
project that translate clojure code into C++.
 
Matt Hoyt


From: cran1988 
To: Clojure 
Sent: Sunday, July 10, 2011 5:26 PM
Subject: Native compiler on Clojure


Did anyone started creating native compiler for Clojure language ?

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

jdbc and postgresql type problem

2011-07-10 Thread Wilfred
Hi all

I've started a very simple compojure project to wet my feet with
Clojure. I've written a simple model changing function:

(defn approve! [id]
  (sql/with-connection db
(sql/transaction
 (sql/update-values :comments
["id = ?" id]
{:approved true}

but I can't make it work. The exception thrown is:

#

calling getNextException gives:

#

I'm at a bit of a loss. "UPDATE comments SET approved='1' WHERE id =
'1'" works fine in psql. approved is a boolean field, so is this an
issue with the SQL library producing incorrect SQL?

Full code is at https://github.com/Wilfred/blog-comments and any
pointers would be much appreciated.

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


Re: Local bindings w/o let

2011-07-10 Thread Charlie Griefer
On Sun, Jul 10, 2011 at 4:51 PM, octopusgrabbus
 wrote:
> If the function is called with one argument, what Clojure language
> rule allows x to appear outside the vector brackets?

([x] x)

The x outside of the vector brackets is the value being returned.

So if max is called with only a single argument, that is also the
returned value.

All of the function definitions have values outside of the vector
brackets (the vector brackets are what represent a specific definition
of the function).

For example:

([x y] (if (> x y) x y))

So in the vector brackets, you've got x and y, which represent 2
values being passed in.  Outside fo the vector brackets you've got a
conditional.  if the first argument (x) is greater than the 2nd (y),
return x.  otherwise, return y.

(if (> a b)  ;; if a > b
 a ;; return a
 b ;; otherwise, return b
))

-- 
Charlie Griefer
http://charlie.griefer.com/

I have failed as much as I have succeeded. But I love my life. I love
my wife. And I wish you my kind of success.

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

2011-07-10 Thread Luc Prefontaine
Lets try to clear the confusion a bit here:

(def max1 [x] x)
(def max2 [x y] (if (> x y) x y))
(def max3 ([x y & more] (reduce max (max x y) more)))

The above a three different fns.

max1 has only the arg x.
max2 has only x and y
and max3 has x and y and maybe other arguments to select the maximum from.
The first "[]" in each fn are bindings for function arguments.

Now you are allowed to define a fn with different forms based on the
number of arguments:

(defn max
  "Returns the greatest of the nums."
   {:added "1.0"}
   ([x] x)  ;; <- max1
   ([x y] (if (> x y) x y)) ;; <- max2
   ([x y & more] (reduce max (max x y) more)))  ;; <- max3

is the equivalent of max1, max2 and max3 but using a single name.
Clojure will select the form to execute based on the # of arguments.
"x" is a different binding in each of the forms, not the same "x"
across forms.

Luc P.

On Sun, 10 Jul 2011 16:51:32 -0700 (PDT)
octopusgrabbus  wrote:

> If the function is called with one argument, what Clojure language
> rule allows x to appear outside the vector brackets?
> 
> On Jul 10, 7:18 pm, Jonathan Fischer Friberg 
> wrote:
> > There's no interfaces, that's the function definition.
> >
> > define function max
> > (defn max
> >
> > attach docstring
> > "Returns the greatest of the nums."
> >
> > attach metadata
> > {:added "1.0"}
> >
> > if max is called with one argument, use this function definition
> > ([x] x)
> >
> > if max is called with two arguments, use this function definition
> > ([x y] (if (> x y) x y))
> >
> > if max is called with more than two arguments, use this function
> > definition ([x y & more]
> >   (reduce max (max x y) more)))
> > ___
> >
> > As you can see, y is introduced in one of the functions definitions.
> > Also
> > see:http://clojure.org/special_forms#Special%20Forms--(fn%20name?%20[params*%20]%20exprs*)
> > andhttp://clojure.org/metadata
> >
> > Jonathan
> >
> > On Sun, Jul 10, 2011 at 11:44 PM, octopusgrabbus
> > wrote:
> >
> > > For Question 1 this is an example of multiple interfaces. Got it.
> >
> > > On Jul 10, 5:42 pm, octopusgrabbus 
> > > wrote:
> > > > From Clojure api for max
> >
> > > > (defn max
> > > >   "Returns the greatest of the nums."
> > > >   {:added "1.0"}
> > > >   ([x] x)
> > > >   ([x y] (if (> x y) x y))
> > > >   ([x y & more]
> > > >    (reduce max (max x y) more)))
> >
> > > > Question 1: Why can y be introduced as a local binding without
> > > > a let?
> >
> > > > Question 2: What is the map   {:added "1.0"} doing?
> >
> > > > Thanks.
> > > > cmn
> >
> > > --
> > > You received this message because you are subscribed to the Google
> > > Groups "Clojure" group.
> > > To post to this group, send email to clojure@googlegroups.com
> > > Note that posts from new members are moderated - please be
> > > patient with your first post.
> > > To unsubscribe from this group, send email to
> > > clojure+unsubscr...@googlegroups.com
> > > For more options, visit this group at
> > >http://groups.google.com/group/clojure?hl=en
> 



-- 
Luc P.


The rabid Muppet

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


Re: Rich Hickey up for deletion

2011-07-10 Thread Devin Walters
http://www.linuxjournal.com/article/10708 and 
http://channel9.msdn.com/Shows/Going+Deep/Expert-to-Expert-Rich-Hickey-and-Brian-Beckman-Inside-Clojure
 in combination with http://lambda-the-ultimate.org/node/3630

I'm not entirely clear on all of wikipedia's notability guidelines but these 
reviews stuck out IMO.


On Sunday, July 10, 2011 at 8:30 PM, Alan Malloy wrote:

> http://www.codequarterly.com/2011/rich-hickey/ ?
> 
> On Jul 10, 6:26 pm, Michal B http://gmail.com)> 
> wrote:
> > Rich Hickey's article in Wikipedia is up for deletion again. Does anyone
> > have links to solid articles about Hickey?
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com 
> (mailto:clojure@googlegroups.com)
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com 
> (mailto: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: Question on eliminating recur

2011-07-10 Thread FL


On Jul 9, 8:58 am, Christian Marks <9fv...@gmail.com> wrote:
> The clojure code below applies the constant space algorithm ... of C. J. Gower
...  to the computation of the order of a permutation [Knuth, D. E.,
“Selected Papers on Analysis of
> Algorithms,” CSLI Lecture Notes Number 102, CSLI Publications, (2000),p 4]
...
> I'm using recur, however some clojure programmers inform me that recur
> "should" be eliminated in favor of doseq or fold. I see nothing wrong
> with recur myself--am I missing
> something?
>


Not much. If you replace your

> (defn order-perm [perm]
>         (let [n (count perm)]
>                 (loop [i 0 order 1]
>                         (if (= i n)
>                                 order
>                             (recur (inc i)
>                                    (if (= i (next-cycle-leader perm i))
>                                                      (math/lcm (cycle-length 
> perm i) order)
>                               order))

with the more compact

(defn order-permo [perm]
 (reduce (fn [order i] (if (= i (next-cycle-leader perm i))
(math/lcm (cycle-length perm i)
order)
 order))
  1 perm))

you'll be rewarded with better performance with permutations of size
<= 10,
and slightly worse performance with larger permutations:


knuth=> (load "knuth")
nil
knuth=> (ns knuth)
nil
knuth=> (def p (random-perm 10))
#'knuth/p
knuth=> (time (order-perm p))
"Elapsed time: 958.706617 msecs"
8124696972786944584881000
knuth=> (time (order-permo p))
"Elapsed time: 908.262712 msecs"
8124696972786944584881000
knuth=> (def p (random-perm 100))
#'knuth/p
knuth=> (time (order-perm p))
"Elapsed time: 14699.019199 msecs"
12165632849310917835084160
knuth=> (time (order-permo p))
"Elapsed time: 15338.770595 msecs"
12165632849310917835084160
knuth=>

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

2011-07-10 Thread Ken Wesson
On Sun, Jul 10, 2011 at 5:42 PM, octopusgrabbus
 wrote:
> From Clojure api for max
>
> (defn max
>  "Returns the greatest of the nums."
>  {:added "1.0"}
>  ([x] x)
>  ([x y] (if (> x y) x y))
>  ([x y & more]
>   (reduce max (max x y) more)))
>
> Question 1: Why can y be introduced as a local binding without a let?

Local bindings can be introduced by three special forms, fn*, let*,
and loop*, and by any macro that expands to one of these, including
but by no means limited to fn, let, loop, defn, and with-open.

In this case the two y bindings are introduced by fn* via the defn
macro as function parameter bindings.

> Question 2: What is the map   {:added "1.0"} doing?

Adding arbitrary metadata key/value pairs to the function. The defn
macro will apply it to the symbol 'max and the def special form that
it expands into will propagate it to the Var clojure.core/max:

=> (meta #'clojure.core/max)
{:ns #, :name max, :file "clojure/core.clj",
:line 912, :arglists ([x] [x y] [x y & more]), :added "1.0", :doc
"Returns the greatest of the nums."}

The defn macro will also apply it to the actual function object:

=> (meta clojure.core/max)
{:ns #, :name max, :file "clojure/core.clj",
:line 912, :arglists ([x] [x y] [x y & more]), :added "1.0", :doc
"Returns the greatest of the nums."}



-- 
Protege: What is this seething mass of parentheses?!
Master: Your father's Lisp REPL. This is the language of a true
hacker. Not as clumsy or random as C++; a language for a more
civilized age.

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

2011-07-10 Thread Sean Corfield
I don't (yet) have a PostgreSQL environment to test java.jdbc on but
I'm planning to do that soon. I've also talked to Aaron about how we
can set up DBs for automated testing on build.clojure.org so java.jdbc
can have "real" tests that I can run locally and which will also still
run on the build system. I'll also try to find time this week to test
your app on MySQL to see if it's specific to PostgreSQL or not.

Sean

On Sun, Jul 10, 2011 at 4:52 PM, Wilfred  wrote:
> Hi all
>
> I've started a very simple compojure project to wet my feet with
> Clojure. I've written a simple model changing function:
>
> (defn approve! [id]
>  (sql/with-connection db
>    (sql/transaction
>     (sql/update-values :comments
>                        ["id = ?" id]
>                        {:approved true}
>
> but I can't make it work. The exception thrown is:
>
> # UPDATE comments SET approved='1' WHERE id = '1' was aborted.  Call
> getNextException to see the cause.>
>
> calling getNextException gives:
>
> # does not exist: integer = character varying
>  Hint: No operator matches the given name and argument type(s). You
> might need to add explicit type casts.
>  Position: 42>
>
> I'm at a bit of a loss. "UPDATE comments SET approved='1' WHERE id =
> '1'" works fine in psql. approved is a boolean field, so is this an
> issue with the SQL library producing incorrect SQL?
>
> Full code is at https://github.com/Wilfred/blog-comments and any
> pointers would be much appreciated.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en



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

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

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


Re: Extending a type to an Interface

2011-07-10 Thread David Jagoe
So the Interface specification has to be available when the record is
defined... that makes sense. Thanks Jonathan.

On 10 July 2011 14:28, Jonathan Fischer Friberg  wrote:
> I think the reason is that an interface means that the function must be
> 'inside' the class.
> I.e you can call (.method object). Since it isn't possible to extend a java
> class in that way, it isn't possible to use extend. In a defrecord body
> however, a new class is defined, which means that it's possible to define
> functions 'inside' that class.
>
> Protocols on the other hand doesn't define functions 'inside' the object,
> they are simply standard functions.
>
> Jonathan
>
> On Sun, Jul 10, 2011 at 1:15 PM, David Jagoe  wrote:
>>
>> Thanks for your response Devin.
>>
>> I guess I had come to the same conclusion by the end of my email. But
>> I wonder if there is a more direct way of achieving the same thing
>> without using a macro that spits out a defrecord with in-line method
>> declarations? I had a quick look at the defrecord code and didn't
>> follow well enough to see what machinery is being used internally to
>> extend the record to the java interface.
>>
>> In short: why can I implement java interfaces within a defrecord body
>> but not when using extend?
>>
>>
>> Cheers,
>> David
>>
>> On 9 July 2011 02:35, Devin Walters  wrote:
>> > What I think Kevin meant to say was that you might consider using a
>> > macro.
>> >
>> > If you have questions about specifics, please do reply. This group is
>> > here to Help, and it would be a shame if a response like the previous one
>> > steered you away from asking a follow-up.
>> >
>> > Sent via mobile
>> >
>> > On Jul 8, 2011, at 5:14 PM, Kevin Downey  wrote:
>> >
>> >> if only lisp had macros
>> >>
>> >> On Fri, Jul 8, 2011 at 12:16 PM, David Jagoe 
>> >> wrote:
>> >>> Hi All,
>> >>>
>> >>> I am battling with how to deal with the difference between Protocols
>> >>> and Interfaces in a particular case.
>> >>>
>> >>> Consider the following code:
>> >>>
>> >>> (defrecord DomainTypeA []
>> >>>  SomeInternalProtocol
>> >>>  (foo [this] "foo result")
>> >>>
>> >>>  clojure.lang.IFn
>> >>>  (invoke [this] "invoke result"))
>> >>>
>> >>> This code works fine.
>> >>>
>> >>> However, I have a number of domain types all of which must use the
>> >>> same implementation of foo and invoke.
>> >>>
>> >>> In the case off foo its easy:
>> >>>
>> >>> (defrecord DomainTypeA [])
>> >>> (extend DomainTypeA SomeInternalProtocol
>> >>> internal-protocol-implementation-map)
>> >>>
>> >>> However I cannot do:
>> >>>
>> >>> (extend DomainTypeA clojure.lang.IFn some-implementation)
>> >>>
>> >>> because IFn is a java Interface. How would I get arount this?
>> >>>
>> >>> My use case is as follows:
>> >>>
>> >>> Every one of my domain objects needs to implement invoke in the same
>> >>> way, so I don't want to code it in-line on the record definition each
>> >>> time. The implementation is defined in one place and I eventually want
>> >>> a macro (e.g. defdomainobj but with a better name!) that would
>> >>> automatically hook up the IFn def.
>> >>>
>> >>> Hmm maybe I just answered my own question:
>> >>>
>> >>> Should I just write the macro that spits out the code in my first
>> >>> listing?
>> >>>
>> >>> Thanks!
>> >>>
>> >>> Cheers,
>> >>> 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
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups "Clojure" group.
>> > To post to this group, send email to clojure@googlegroups.com
>> > Note that posts from new members are moderated - please be patient with
>> > your first post.
>> > To unsubscribe from 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 th

Re: jdbc and postgresql type problem

2011-07-10 Thread Brian Carper
On Jul 10, 4:52 pm, Wilfred  wrote:
> I'm at a bit of a loss. "UPDATE comments SET approved='1' WHERE id =
> '1'" works fine in psql. approved is a boolean field, so is this an
> issue with the SQL library producing incorrect SQL?

I think this is an oddity with the JDBC driver for PostgreSQL.  The
driver doesn't seem to like doing automatic typecasting.  Try this:

(sql/update-values :comments
   ["id = cast(? as integer)" id]
   ;; alternatively "id = ?::integer"
   {:approved true})

Or you could (Integer/parseInt id) to do the cast before you pass it
as parameter, though in either case you should validate your id before
casting, if you want to avoid dying on poorly-formed input.

--Brian

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