tools for minimizing forward declaration

2013-08-14 Thread Phillip Lord

One of the things that I find unusual with clojure is the requirement
for forward declaration. While I can see the advantages, managing it by
hand can be a pain. 

So I was wondering, are there any tools for adding declare statements
when necessary. And better for working out how to reorder function
declarations to minimize the requirement for forward declarations.

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: Do you like the Clojure syntax?

2013-08-14 Thread Răzvan Rotaru

marți, 13 august 2013, 23:13:39 UTC+3, Russell Whitaker a scris:
>
> Speaking of "the purpose of the poll," what is it? What purpose does an 
> off-list 
> poll serve that an on-list answer doesn't? I'm curious: is this for a 
> school assignment 
> or for an employer or...? 
>
> R 
>
>
Statistics. I want to know how many Clojure users actually like the syntax 
and find it beautiful, and how many just go along with it, with it's good 
and bad. No school or employer assignment.
I am surprised and happy that so many have expressed their opinion on this 
thread. Thanks.

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




Re: calling java static member using string?

2013-08-14 Thread Daniel Meneses
Hi!

Thanks for your answer Sean I got it solved using clj-time

Also I found the problem with my macro attempt

user> (defmacro is
[s instant]
`(= (.get ~instant Calendar/DAY_OF_WEEK)
(. Calendar ~s)))
#'current-day.core/is
user> (is FRIDAY (Calendar/getInstance))
false
user> (is WEDNESDAY (Calendar/getInstance))
true

I was quoting the symbol !!

On Tuesday, August 13, 2013 8:21:39 PM UTC-4, Sean Corfield wrote:
>
> Perhaps clj-time might help you? 
>
> https://github.com/clj-time/clj-time 
>
> (ns time.core 
>   (:require [clj-time.core :as time] 
> [clj-time.local :as local] 
> [clj-time.predicates :as p])) 
>
> (p/monday? (time/now)) ;; false 
> (p/tuesday? (time/now)) ;; false 
> (p/wednesday? (time/now)) ;; true (for me in California since (time/now) 
> is UTC) 
>
> (p/monday? (local/local-now)) ;; false 
> (p/tuesday? (local/local-now)) ;; true (for me) 
> (p/wednesday? (local/local-now)) ;; false (not yet in California) 
>
> Sean 
>
> On Tue, Aug 13, 2013 at 3:14 PM, Daniel Meneses Báez 
> > 
> wrote: 
> > Hi :) 
> > 
> > I really want to know if there is a way to do this: 
> > 
> > (ns ... 
> >(:import [java.util Calendar])) 
> > 
> > (defsomething ;; if it is possible using a macro I'm ok with that 
> >calendar-member 
> >[member] 
> > (symbol (str "Calendar/" member))) 
> > 
> > what I want to know if an instance of Calendar "isMonday", "isFriday" 
> > "isSunday" etc... 
> > 
> > so I was thinking to write something like 
> > 
> > (defn- isss [day instant] 
> > (= (.get instant Calendar/DATE) (calendar-member day))) 
> > 
> > and then use it like (def is-friday (partial isss 'FRIDAY)) ;; 
> > 
> > am I being to crazy? 
> > 
> > btw I'm really loving the language. 
> > 
> > 
> > 
> > -- 
> > Daniel Meneses Báez 
> > 
> > -- 
> > -- 
> > 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. 
> > 
> > 
>
>
>
> -- 
> Sean A Corfield -- (904) 302-SEAN 
> An Architect's View -- http://corfield.org/ 
> World Singles, LLC. -- http://worldsingles.com/ 
>
> "Perfection is the enemy of the good." 
> -- Gustave Flaubert, French realist novelist (1821-1880) 
>

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




Re: calling java static member using string?

2013-08-14 Thread Jim - FooBar();

why on earth is this a macro and not a regular fn?


Jim

On 14/08/13 16:19, Daniel Meneses wrote:

Hi!

Thanks for your answer Sean I got it solved using clj-time

Also I found the problem with my macro attempt

user> (defmacro is
[s instant]
`(= (.get ~instant Calendar/DAY_OF_WEEK)
(. Calendar ~s)))
#'current-day.core/is
user> (is FRIDAY (Calendar/getInstance))
false
user> (is WEDNESDAY (Calendar/getInstance))
true

I was quoting the symbol !!

On Tuesday, August 13, 2013 8:21:39 PM UTC-4, Sean Corfield wrote:

Perhaps clj-time might help you?

https://github.com/clj-time/clj-time


(ns time.core
  (:require [clj-time.core :as time]
[clj-time.local :as local]
[clj-time.predicates :as p]))

(p/monday? (time/now)) ;; false
(p/tuesday? (time/now)) ;; false
(p/wednesday? (time/now)) ;; true (for me in California since
(time/now) is UTC)

(p/monday? (local/local-now)) ;; false
(p/tuesday? (local/local-now)) ;; true (for me)
(p/wednesday? (local/local-now)) ;; false (not yet in California)

Sean

On Tue, Aug 13, 2013 at 3:14 PM, Daniel Meneses Báez
> wrote:
> Hi :)
>
> I really want to know if there is a way to do this:
>
> (ns ...
>(:import [java.util Calendar]))
>
> (defsomething ;; if it is possible using a macro I'm ok with that
>calendar-member
>[member]
> (symbol (str "Calendar/" member)))
>
> what I want to know if an instance of Calendar "isMonday",
"isFriday"
> "isSunday" etc...
>
> so I was thinking to write something like
>
> (defn- isss [day instant]
> (= (.get instant Calendar/DATE) (calendar-member day)))
>
> and then use it like (def is-friday (partial isss 'FRIDAY)) ;;
>
> am I being to crazy?
>
> btw I'm really loving the language.
>
>
>
> --
> Daniel Meneses Báez
>
> --
> --
> 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
.
>
>



-- 
Sean A Corfield -- (904) 302-SEAN

An Architect's View -- http://corfield.org/
World Singles, LLC. -- http://worldsingles.com/

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

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

To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google 
Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send 
an 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: calling java static member using string?

2013-08-14 Thread Daniel Meneses Báez
I don't know if you have a differente approach, but as a defn it doesn't
work

user> (import '[java.util Calendar])
java.util.Calendar
user> (defn is [s instant]
(= (.get instant Calendar/DAY_OF_WEEK)
   (. Calendar s)))
CompilerException java.lang.NoSuchFieldException: s,
compiling:(NO_SOURCE_PATH:3:12)

user> (defmacro is [s instant]
`(= (.get ~instant Calendar/DAY_OF_WEEK)
   (. Calendar ~s)))
#'user/is
user> (is WEDNESDAY (Calendar/getInstance))
true

I think that when you declare this as a function it will it attempt to
validate that Calendar has an 's' member, at this point that is an error,
on the other hand when the macro gets replaced the generated form is valid.

just for the fun of it, I got this working:

user> (defmacro is [s]
`#(= (.get % Calendar/DAY_OF_WEEK)
   (. Calendar ~s)))
#'user/is
user> ((is WEDNESDAY) (Calendar/getInstance))
true

now I can write what I had in mind

user> (def is-friday (is FRIDAY))
#'user/is-friday
user> (is-friday (Calendar/getInstance))
false
user> (def is-wednesday (is WEDNESDAY))
#'user/is-wednesday
user> (is-wednesday (Calendar/getInstance))
true

cool xD



On Wed, Aug 14, 2013 at 11:33 AM, Jim - FooBar(); wrote:

>  why on earth is this a macro and not a regular fn?
>
>
> Jim
>
> On 14/08/13 16:19, Daniel Meneses wrote:
>
> Hi!
>
> Thanks for your answer Sean I got it solved using clj-time
>
> Also I found the problem with my macro attempt
>
> user> (defmacro is
> [s instant]
> `(= (.get ~instant Calendar/DAY_OF_WEEK)
> (. Calendar ~s)))
> #'current-day.core/is
> user> (is FRIDAY (Calendar/getInstance))
> false
> user> (is WEDNESDAY (Calendar/getInstance))
> true
>
> I was quoting the symbol !!
>
> On Tuesday, August 13, 2013 8:21:39 PM UTC-4, Sean Corfield wrote:
>>
>> Perhaps clj-time might help you?
>>
>> https://github.com/clj-time/**clj-time
>>
>> (ns time.core
>>   (:require [clj-time.core :as time]
>> [clj-time.local :as local]
>> [clj-time.predicates :as p]))
>>
>> (p/monday? (time/now)) ;; false
>> (p/tuesday? (time/now)) ;; false
>> (p/wednesday? (time/now)) ;; true (for me in California since (time/now)
>> is UTC)
>>
>> (p/monday? (local/local-now)) ;; false
>> (p/tuesday? (local/local-now)) ;; true (for me)
>> (p/wednesday? (local/local-now)) ;; false (not yet in California)
>>
>> Sean
>>
>> On Tue, Aug 13, 2013 at 3:14 PM, Daniel Meneses Báez 
>> wrote:
>> > Hi :)
>> >
>> > I really want to know if there is a way to do this:
>> >
>> > (ns ...
>> >(:import [java.util Calendar]))
>> >
>> > (defsomething ;; if it is possible using a macro I'm ok with that
>> >calendar-member
>> >[member]
>> > (symbol (str "Calendar/" member)))
>> >
>> > what I want to know if an instance of Calendar "isMonday", "isFriday"
>> > "isSunday" etc...
>> >
>> > so I was thinking to write something like
>> >
>> > (defn- isss [day instant]
>> > (= (.get instant Calendar/DATE) (calendar-member day)))
>> >
>> > and then use it like (def is-friday (partial isss 'FRIDAY)) ;;
>> >
>> > am I being to crazy?
>> >
>> > btw I'm really loving the language.
>> >
>> >
>> >
>> > --
>> > Daniel Meneses Báez
>> >
>> > --
>> > --
>> > 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.
>>
>> >
>> >
>>
>>
>>
>> --
>> Sean A Corfield -- (904) 302-SEAN
>> An Architect's View -- http://corfield.org/
>> World Singles, LLC. -- http://worldsingles.com/
>>
>> "Perfection is the enemy of the good."
>> -- Gustave Flaubert, French realist novelist (1821-1880)
>>
>  --
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it,

Re: Do you like the Clojure syntax?

2013-08-14 Thread Phillip Lord
Răzvan Rotaru  writes:
> Statistics. I want to know how many Clojure users actually like the syntax 
> and find it beautiful, and how many just go along with it, with it's good 
> and bad. No school or employer assignment.
> I am surprised and happy that so many have expressed their opinion on this 
> thread. Thanks.

You shouldn't be. Syntax is one of the holy wars amoung programmers.
Which operating system, which IDE, typed vs untyped, and of course, the
all time classic 2, 4 or 8 space indentation.

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: Do you like the Clojure syntax?

2013-08-14 Thread Chris Ford
Two obviously. It's the only compromise between those who want everything
to be a prime number, and those who want everything to be a power of two.


On 14 August 2013 18:48, Phillip Lord  wrote:

> Răzvan Rotaru  writes:
> > Statistics. I want to know how many Clojure users actually like the
> syntax
> > and find it beautiful, and how many just go along with it, with it's good
> > and bad. No school or employer assignment.
> > I am surprised and happy that so many have expressed their opinion on
> this
> > thread. Thanks.
>
> You shouldn't be. Syntax is one of the holy wars amoung programmers.
> Which operating system, which IDE, typed vs untyped, and of course, the
> all time classic 2, 4 or 8 space indentation.
>
> 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: calling java static member using string?

2013-08-14 Thread Dave Della Costa
I know you said clj-time solved this for you, but here's another way to
handle it which avoids using a macro (using a map of keywords to
java.util.Calendar weekday enums for convenience and to be more
Clojure-esque, but it isn't necessary):

user=> (def weekdays {:mon Calendar/MONDAY :tues Calendar/TUESDAY :wed
Calendar/WEDNESDAY :thurs Calendar/THURSDAY :fri Calendar/FRIDAY :sat
Calendar/SATURDAY :sun Calendar/SUNDAY})
#'user/weekdays
user=> (defn is-day-of-week? [day-enum] (= Calendar/DAY_OF_WEEK
(day-enum weekdays)))
#'user/is-day-of-week?
user=> (is-day-of-week? :sat)
false
user=> (is-day-of-week? :wed)
true
user=>

You don't need to use all the Java interop syntax you're using, you can
refer to and compare these static fields directly.  In the end these are
simply Integer comparisons.

DD

(2013/08/14 11:45), Daniel Meneses Báez wrote:
> I don't know if you have a differente approach, but as a defn it doesn't
> work
> 
> user> (import '[java.util Calendar])
> java.util.Calendar
> user> (defn is [s instant]
> (= (.get instant Calendar/DAY_OF_WEEK)
>(. Calendar s)))
> CompilerException java.lang.NoSuchFieldException: s,
> compiling:(NO_SOURCE_PATH:3:12)
> 
> user> (defmacro is [s instant]
> `(= (.get ~instant Calendar/DAY_OF_WEEK)
>(. Calendar ~s)))
> #'user/is
> user> (is WEDNESDAY (Calendar/getInstance))
> true
> 
> I think that when you declare this as a function it will it attempt to
> validate that Calendar has an 's' member, at this point that is an
> error, on the other hand when the macro gets replaced the generated form
> is valid.
> 
> just for the fun of it, I got this working:
> 
> user> (defmacro is [s]
> `#(= (.get % Calendar/DAY_OF_WEEK)
>(. Calendar ~s)))
> #'user/is
> user> ((is WEDNESDAY) (Calendar/getInstance))
> true
> 
> now I can write what I had in mind
> 
> user> (def is-friday (is FRIDAY))
> #'user/is-friday
> user> (is-friday (Calendar/getInstance))
> false
> user> (def is-wednesday (is WEDNESDAY))
> #'user/is-wednesday
> user> (is-wednesday (Calendar/getInstance))
> true
> 
> cool xD
> 
> 
> 
> On Wed, Aug 14, 2013 at 11:33 AM, Jim - FooBar();  > wrote:
> 
> why on earth is this a macro and not a regular fn?
> 
> 
> Jim
> 
> On 14/08/13 16:19, Daniel Meneses wrote:
>> Hi!
>>
>> Thanks for your answer Sean I got it solved using clj-time
>>
>> Also I found the problem with my macro attempt
>>
>> user> (defmacro is
>> [s instant]
>> `(= (.get ~instant Calendar/DAY_OF_WEEK)
>> (. Calendar ~s)))
>> #'current-day.core/is
>> user> (is FRIDAY (Calendar/getInstance))
>> false
>> user> (is WEDNESDAY (Calendar/getInstance))
>> true
>>
>> I was quoting the symbol !!
>>
>> On Tuesday, August 13, 2013 8:21:39 PM UTC-4, Sean Corfield wrote:
>>
>> Perhaps clj-time might help you?
>>
>> https://github.com/clj-time/__clj-time
>> 
>>
>> (ns time.core
>>   (:require [clj-time.core :as time]
>> [clj-time.local :as local]
>> [clj-time.predicates :as p]))
>>
>> (p/monday? (time/now)) ;; false
>> (p/tuesday? (time/now)) ;; false
>> (p/wednesday? (time/now)) ;; true (for me in California since
>> (time/now) is UTC)
>>
>> (p/monday? (local/local-now)) ;; false
>> (p/tuesday? (local/local-now)) ;; true (for me)
>> (p/wednesday? (local/local-now)) ;; false (not yet in California)
>>
>> Sean
>>
>> On Tue, Aug 13, 2013 at 3:14 PM, Daniel Meneses Báez
>>  wrote:
>> > Hi :)
>> >
>> > I really want to know if there is a way to do this:
>> >
>> > (ns ...
>> >(:import [java.util Calendar]))
>> >
>> > (defsomething ;; if it is possible using a macro I'm ok with
>> that
>> >calendar-member
>> >[member]
>> > (symbol (str "Calendar/" member)))
>> >
>> > what I want to know if an instance of Calendar "isMonday",
>> "isFriday"
>> > "isSunday" etc...
>> >
>> > so I was thinking to write something like
>> >
>> > (defn- isss [day instant]
>> > (= (.get instant Calendar/DATE) (calendar-member day)))
>> >
>> > and then use it like (def is-friday (partial isss 'FRIDAY)) ;;
>> >
>> > am I being to crazy?
>> >
>> > btw I'm really loving the language.
>> >
>> >
>> >
>> > --
>> > Daniel Meneses Báez
>> >
>> > --
>> > --
>> > 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 m

Re: Do you like the Clojure syntax?

2013-08-14 Thread Christian Sperandio
And if you're a JavaScript developer with an extreme mind, you minimize
your code to have no space.
Le 14 août 2013 18:12, "Dan Cross"  a écrit :

> On Wed, Aug 14, 2013 at 12:08 PM, Chris Ford 
> wrote:
>
>> Two obviously. It's the only compromise between those who want everything
>> to be a prime number, and those who want everything to be a power of two.
>>
>
> I used to sometimes use 3 spaces, just to be a contrarian.  Then I learned
> the error of my ways.  The real answer is, of course, 1 space: it's a
> factor of everything.
>
>
>>
>>
>> On 14 August 2013 18:48, Phillip Lord wrote:
>>
>>> Răzvan Rotaru  writes:
>>> > Statistics. I want to know how many Clojure users actually like the
>>> syntax
>>> > and find it beautiful, and how many just go along with it, with it's
>>> good
>>> > and bad. No school or employer assignment.
>>> > I am surprised and happy that so many have expressed their opinion on
>>> this
>>> > thread. Thanks.
>>>
>>> You shouldn't be. Syntax is one of the holy wars amoung programmers.
>>> Which operating system, which IDE, typed vs untyped, and of course, the
>>> all time classic 2, 4 or 8 space indentation.
>>>
>>> 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.
>
>
>

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

2013-08-14 Thread Dan Cross
On Wed, Aug 14, 2013 at 12:08 PM, Chris Ford wrote:

> Two obviously. It's the only compromise between those who want everything
> to be a prime number, and those who want everything to be a power of two.
>

I used to sometimes use 3 spaces, just to be a contrarian.  Then I learned
the error of my ways.  The real answer is, of course, 1 space: it's a
factor of everything.


>
>
> On 14 August 2013 18:48, Phillip Lord wrote:
>
>> Răzvan Rotaru  writes:
>> > Statistics. I want to know how many Clojure users actually like the
>> syntax
>> > and find it beautiful, and how many just go along with it, with it's
>> good
>> > and bad. No school or employer assignment.
>> > I am surprised and happy that so many have expressed their opinion on
>> this
>> > thread. Thanks.
>>
>> You shouldn't be. Syntax is one of the holy wars amoung programmers.
>> Which operating system, which IDE, typed vs untyped, and of course, the
>> all time classic 2, 4 or 8 space indentation.
>>
>> 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: calling java static member using string?

2013-08-14 Thread Daniel Meneses Báez
m... the function you wrote only returns true on saturdays

but I get the point!

thanks for your answer


On Wed, Aug 14, 2013 at 12:14 PM, Dave Della Costa wrote:

> I know you said clj-time solved this for you, but here's another way to
> handle it which avoids using a macro (using a map of keywords to
> java.util.Calendar weekday enums for convenience and to be more
> Clojure-esque, but it isn't necessary):
>
> user=> (def weekdays {:mon Calendar/MONDAY :tues Calendar/TUESDAY :wed
> Calendar/WEDNESDAY :thurs Calendar/THURSDAY :fri Calendar/FRIDAY :sat
> Calendar/SATURDAY :sun Calendar/SUNDAY})
> #'user/weekdays
> user=> (defn is-day-of-week? [day-enum] (= Calendar/DAY_OF_WEEK
> (day-enum weekdays)))
> #'user/is-day-of-week?
> user=> (is-day-of-week? :sat)
> false
> user=> (is-day-of-week? :wed)
> true
> user=>
>
> You don't need to use all the Java interop syntax you're using, you can
> refer to and compare these static fields directly.  In the end these are
> simply Integer comparisons.
>
> DD
>
> (2013/08/14 11:45), Daniel Meneses Báez wrote:
> > I don't know if you have a differente approach, but as a defn it doesn't
> > work
> >
> > user> (import '[java.util Calendar])
> > java.util.Calendar
> > user> (defn is [s instant]
> > (= (.get instant Calendar/DAY_OF_WEEK)
> >(. Calendar s)))
> > CompilerException java.lang.NoSuchFieldException: s,
> > compiling:(NO_SOURCE_PATH:3:12)
> >
> > user> (defmacro is [s instant]
> > `(= (.get ~instant Calendar/DAY_OF_WEEK)
> >(. Calendar ~s)))
> > #'user/is
> > user> (is WEDNESDAY (Calendar/getInstance))
> > true
> >
> > I think that when you declare this as a function it will it attempt to
> > validate that Calendar has an 's' member, at this point that is an
> > error, on the other hand when the macro gets replaced the generated form
> > is valid.
> >
> > just for the fun of it, I got this working:
> >
> > user> (defmacro is [s]
> > `#(= (.get % Calendar/DAY_OF_WEEK)
> >(. Calendar ~s)))
> > #'user/is
> > user> ((is WEDNESDAY) (Calendar/getInstance))
> > true
> >
> > now I can write what I had in mind
> >
> > user> (def is-friday (is FRIDAY))
> > #'user/is-friday
> > user> (is-friday (Calendar/getInstance))
> > false
> > user> (def is-wednesday (is WEDNESDAY))
> > #'user/is-wednesday
> > user> (is-wednesday (Calendar/getInstance))
> > true
> >
> > cool xD
> >
> >
> >
> > On Wed, Aug 14, 2013 at 11:33 AM, Jim - FooBar();  > > wrote:
> >
> > why on earth is this a macro and not a regular fn?
> >
> >
> > Jim
> >
> > On 14/08/13 16:19, Daniel Meneses wrote:
> >> Hi!
> >>
> >> Thanks for your answer Sean I got it solved using clj-time
> >>
> >> Also I found the problem with my macro attempt
> >>
> >> user> (defmacro is
> >> [s instant]
> >> `(= (.get ~instant Calendar/DAY_OF_WEEK)
> >> (. Calendar ~s)))
> >> #'current-day.core/is
> >> user> (is FRIDAY (Calendar/getInstance))
> >> false
> >> user> (is WEDNESDAY (Calendar/getInstance))
> >> true
> >>
> >> I was quoting the symbol !!
> >>
> >> On Tuesday, August 13, 2013 8:21:39 PM UTC-4, Sean Corfield wrote:
> >>
> >> Perhaps clj-time might help you?
> >>
> >> https://github.com/clj-time/__clj-time
> >> 
> >>
> >> (ns time.core
> >>   (:require [clj-time.core :as time]
> >> [clj-time.local :as local]
> >> [clj-time.predicates :as p]))
> >>
> >> (p/monday? (time/now)) ;; false
> >> (p/tuesday? (time/now)) ;; false
> >> (p/wednesday? (time/now)) ;; true (for me in California since
> >> (time/now) is UTC)
> >>
> >> (p/monday? (local/local-now)) ;; false
> >> (p/tuesday? (local/local-now)) ;; true (for me)
> >> (p/wednesday? (local/local-now)) ;; false (not yet in
> California)
> >>
> >> Sean
> >>
> >> On Tue, Aug 13, 2013 at 3:14 PM, Daniel Meneses Báez
> >>  wrote:
> >> > Hi :)
> >> >
> >> > I really want to know if there is a way to do this:
> >> >
> >> > (ns ...
> >> >(:import [java.util Calendar]))
> >> >
> >> > (defsomething ;; if it is possible using a macro I'm ok with
> >> that
> >> >calendar-member
> >> >[member]
> >> > (symbol (str "Calendar/" member)))
> >> >
> >> > what I want to know if an instance of Calendar "isMonday",
> >> "isFriday"
> >> > "isSunday" etc...
> >> >
> >> > so I was thinking to write something like
> >> >
> >> > (defn- isss [day instant]
> >> > (= (.get instant Calendar/DATE) (calendar-member day)))
> >> >
> >> > and then use it like (def is-friday (partial isss 'FRIDAY)) ;;
> >> >
> >> > am I being

Re: calling java static member using string?

2013-08-14 Thread Jim - FooBar();

On 14/08/13 16:45, Daniel Meneses Báez wrote:

(defn is [s instant]
(= (.get instant Calendar/DAY_OF_WEEK)
   (. Calendar s)))


(def ^:private day->int
{:MONDAY 2 :TUESDAY 3 :WEDNESDAY 4 :THURSDAY 5 :FRIDAY 6 :SATURDAY 7 
:SUNDAY 1})



(defn is-today?
([s instant]
  (= (.get instant Calendar/DAY_OF_WEEK)
  ((keyword s) day->int)))
([s]
  (is s (Calendar/getInstance)))
([]
 (let [int-id (.get (Calendar/getInstance) Calendar/DAY_OF_WEEK)]
  (->> (some (fn [[k v]] (when (= v int-id) k)) day->int)
str
(drop 1)
(apply str)
symbol))) )

(is-today? 'WEDNESDAY)
=> true

(is-today? MONDAY)
=> false

(is-today?)
=> WEDNESDAY

Jim

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

2013-08-14 Thread Rick Moynihan
Ahhh, the good old Lisp syntax debate!

I learned Clojure back in 2008, and it was my first Lisp (and is still the
only Lisp I'm comfortable with).

I've had lots of Java experience, and a fair amount of Ruby experience over
the years... With occasional bits and pieces in other languages like
Erlang, Prolog, Python etc... and more recently I've been learning Haskell
on and off.

Syntax is pretty much the least important thing about a programming
language (it's all about the semantics), but of all these syntaxes
Clojure's is definitely the one I love the most.  It's simple, logical,
unambiguous, consistent and very user friendly when it comes to moving
chunks of code around in a good editor (e.g. Emacs + paredit).

Subjectively I found Erlang's syntax pretty horrible (though I like the
language itself), Ruby's is superficially beautiful but in practice
ambiguous and not without its warts...

I don't know Scala but whenever I read introductions to the language the
amount of syntax terrifies me...  I accept that this is an irrational
reaction; similar to what many people get about s-expressions...  I just
find it interesting that it goes both ways.

I'm no where near proficient in Haskell (very much still learning), but
it's syntax is pretty confusing in parts... though it has bits that I
really like.

R.

On 12 August 2013 08:52, Răzvan Rotaru  wrote:

> Hi,
>
> I'm curious about the general opinion on the Clojure syntax, whether
> people actually like it or just use it because it provides macros. So I
> would like to ask you to participate in a poll. Thank You.
>
> Here's the link:
>
> https://docs.google.com/forms/d/1GSgfkeThpUYlgFVzhhNIgA1JbTilu6S9eudq_Sbxl34/viewform
>
> Răzvan
>
> --
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from 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: calling java static member using string?

2013-08-14 Thread Jim - FooBar();
and the non-reflective version which also fixes the typos and the 
inefficient transform from keyword -> symbol.


(def ^:private day->int
{:MONDAY 2 :TUESDAY 3 :WEDNESDAY 4 :THURSDAY 5 :FRIDAY 6 :SATURDAY 7 
:SUNDAY 1})


(defn is-today?
([s ^java.util.GregorianCalendar instant]
  (= (.get instant Calendar/DAY_OF_WEEK)
  ((keyword s) day->int)))
([s]
  (is-today? s (Calendar/getInstance)))
([]
 (let [inst (Calendar/getInstance)
   int-id (.get inst Calendar/DAY_OF_WEEK)]
  (-> (some (fn [[k v]] (when (= v int-id) k)) day->int)
name
symbol))) )

(is-today? (is-today?))
=> true

Jim



On 14/08/13 17:46, Jim - FooBar(); wrote:

On 14/08/13 16:45, Daniel Meneses Báez wrote:

(defn is [s instant]
(= (.get instant Calendar/DAY_OF_WEEK)
   (. Calendar s)))


(def ^:private day->int
{:MONDAY 2 :TUESDAY 3 :WEDNESDAY 4 :THURSDAY 5 :FRIDAY 6 :SATURDAY 7 
:SUNDAY 1})



(defn is-today?
([s instant]
  (= (.get instant Calendar/DAY_OF_WEEK)
  ((keyword s) day->int)))
([s]
  (is s (Calendar/getInstance)))
([]
 (let [int-id (.get (Calendar/getInstance) Calendar/DAY_OF_WEEK)]
  (->> (some (fn [[k v]] (when (= v int-id) k)) day->int)
str
(drop 1)
(apply str)
symbol))) )

(is-today? 'WEDNESDAY)
=> true

(is-today? MONDAY)
=> false

(is-today?)
=> WEDNESDAY

Jim


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

2013-08-14 Thread Dave Della Costa
Sorry, somehow I got the wrong line pasted in there!  Should be:

user=> (defn is-day-of-week? [day-enum] (= (.get (Calendar/getInstance)
Calendar/DAY_OF_WEEK) (day-enum weekdays)))

...but you probably figured that out. ;-)

DD


(2013/08/14 12:43), Daniel Meneses Báez wrote:
> m... the function you wrote only returns true on saturdays
> 
> but I get the point!
> 
> thanks for your answer
> 
> 
> On Wed, Aug 14, 2013 at 12:14 PM, Dave Della Costa
> mailto:ddellaco...@gmail.com>> wrote:
> 
> I know you said clj-time solved this for you, but here's another way to
> handle it which avoids using a macro (using a map of keywords to
> java.util.Calendar weekday enums for convenience and to be more
> Clojure-esque, but it isn't necessary):
> 
> user=> (def weekdays {:mon Calendar/MONDAY :tues Calendar/TUESDAY :wed
> Calendar/WEDNESDAY :thurs Calendar/THURSDAY :fri Calendar/FRIDAY :sat
> Calendar/SATURDAY :sun Calendar/SUNDAY})
> #'user/weekdays
> user=> (defn is-day-of-week? [day-enum] (= Calendar/DAY_OF_WEEK
> (day-enum weekdays)))
> #'user/is-day-of-week?
> user=> (is-day-of-week? :sat)
> false
> user=> (is-day-of-week? :wed)
> true
> user=>
> 
> You don't need to use all the Java interop syntax you're using, you can
> refer to and compare these static fields directly.  In the end these are
> simply Integer comparisons.
> 
> DD
> 
> (2013/08/14 11:45), Daniel Meneses Báez wrote:
> > I don't know if you have a differente approach, but as a defn it
> doesn't
> > work
> >
> > user> (import '[java.util Calendar])
> > java.util.Calendar
> > user> (defn is [s instant]
> > (= (.get instant Calendar/DAY_OF_WEEK)
> >(. Calendar s)))
> > CompilerException java.lang.NoSuchFieldException: s,
> > compiling:(NO_SOURCE_PATH:3:12)
> >
> > user> (defmacro is [s instant]
> > `(= (.get ~instant Calendar/DAY_OF_WEEK)
> >(. Calendar ~s)))
> > #'user/is
> > user> (is WEDNESDAY (Calendar/getInstance))
> > true
> >
> > I think that when you declare this as a function it will it attempt to
> > validate that Calendar has an 's' member, at this point that is an
> > error, on the other hand when the macro gets replaced the
> generated form
> > is valid.
> >
> > just for the fun of it, I got this working:
> >
> > user> (defmacro is [s]
> > `#(= (.get % Calendar/DAY_OF_WEEK)
> >(. Calendar ~s)))
> > #'user/is
> > user> ((is WEDNESDAY) (Calendar/getInstance))
> > true
> >
> > now I can write what I had in mind
> >
> > user> (def is-friday (is FRIDAY))
> > #'user/is-friday
> > user> (is-friday (Calendar/getInstance))
> > false
> > user> (def is-wednesday (is WEDNESDAY))
> > #'user/is-wednesday
> > user> (is-wednesday (Calendar/getInstance))
> > true
> >
> > cool xD
> >
> >
> >
> > On Wed, Aug 14, 2013 at 11:33 AM, Jim - FooBar();
> mailto:jimpil1...@gmail.com>
> > >> wrote:
> >
> > why on earth is this a macro and not a regular fn?
> >
> >
> > Jim
> >
> > On 14/08/13 16:19, Daniel Meneses wrote:
> >> Hi!
> >>
> >> Thanks for your answer Sean I got it solved using clj-time
> >>
> >> Also I found the problem with my macro attempt
> >>
> >> user> (defmacro is
> >> [s instant]
> >> `(= (.get ~instant Calendar/DAY_OF_WEEK)
> >> (. Calendar ~s)))
> >> #'current-day.core/is
> >> user> (is FRIDAY (Calendar/getInstance))
> >> false
> >> user> (is WEDNESDAY (Calendar/getInstance))
> >> true
> >>
> >> I was quoting the symbol !!
> >>
> >> On Tuesday, August 13, 2013 8:21:39 PM UTC-4, Sean Corfield
> wrote:
> >>
> >> Perhaps clj-time might help you?
> >>
> >> https://github.com/clj-time/__clj-time
> >> 
> >>
> >> (ns time.core
> >>   (:require [clj-time.core :as time]
> >> [clj-time.local :as local]
> >> [clj-time.predicates :as p]))
> >>
> >> (p/monday? (time/now)) ;; false
> >> (p/tuesday? (time/now)) ;; false
> >> (p/wednesday? (time/now)) ;; true (for me in California since
> >> (time/now) is UTC)
> >>
> >> (p/monday? (local/local-now)) ;; false
> >> (p/tuesday? (local/local-now)) ;; true (for me)
> >> (p/wednesday? (local/local-now)) ;; false (not yet in
> California)
> >>
> >> Sean
> >>
> >> On Tue, Aug 13, 2013 at 3:14 PM, Daniel Meneses Báez
> >> mail

with-redefs vs. constant folding

2013-08-14 Thread Ben Wolfson
Is this a bug?

user> (with-redefs [list +] (list 1 2)) ;; expected: 3
3 ;; huzzah

user> (with-redefs [+ list] (+ 1 2)) ;; expected: (1 2)
3 ;; blast!



-- 
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: with-redefs vs. constant folding

2013-08-14 Thread Chas Emerick
No; functions with :inline-* metadata (go look at the source for +, for 
example) are...inlined, thus eliminating var lookups, and any effect of 
binding, with-redefs, etc.  The workaround for this is to call through 
the var:


user=> (with-redefs [+ list] (#'+ 1 2))
(1 2)

Cheers,

- Chas

On 08/14/2013 03:50 PM, Ben Wolfson wrote:

Is this a bug?

user> (with-redefs [list +] (list 1 2)) ;; expected: 3
3 ;; huzzah

user> (with-redefs [+ list] (+ 1 2)) ;; expected: (1 2)
3 ;; blast!



--
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: function creation, partial or #()

2013-08-14 Thread Stefan du Fresne
So I'm new to Clojure, and have been working through how to make Clojure 
code performant (i.e. what approaches are faster than others, how to 
profile, etc) by writing a (embarrassingly) simple ray-tracer.

In a ray tracer there is a tight loop that runs per pixel, where you 
determine which of a list of object in the scene intersects with the ray 
for that pixel, and which is closest. At one point I was using partial as 
part of that logic. Changing partial to #() made the rendering time for a 
specific scene go down from 4.7s to 4.1s.

#() is ugly though, and partial, as people has said, is more readable, 
because it speaks more to how that bit of code is going to be used. So I 
wrote the following macro:

(defmacro partialn
  [n f & args]
  (let [params (map (fn [_] (gensym "fnp-")) (range n))]
`(fn [~@params] (~f ~@args ~@params

This is just a first cut and I'm sure there are rough edges, but you get 
the idea: we're using a macro to hide the creation of a 'static' anonymous 
function instead of writing it ourselves.

When using this in my code in place of #(), the performance result is 
essentially identical.

Apologies in advance if I've missed something obvious here, but is this 
something other people are interested in? Would this be useful in core? As 
far as I can tell it's something that is-- if you know the number of args 
you expect-- a strict upgrade to partial, though I'm willing to plead 
ignorance here. You could even re-write partial so supported both 
signatures (f & args) and (f n & args), though I'm not sure if that's 
idiomatic.

Below is the specific data from bench. Note that these benchmarks aren't 
particularly scientific, they've all been running on a 2009MBP, from the 
REPL, with a :reload-all in between each run to swap code around. Each of 
these calls was essentially (map (partial f x) list-of-ys) -> (f x y), so 
one arg passed on creation and one at runtime. The laptop was at the very 
least left alone while they were running, so any variance wasn't explicitly 
introduced by me.

; for (partial ..)
Evaluation count : 60 in 60 samples of 1 calls.
 Execution time mean : 4.788510 sec
Execution time std-deviation : 39.595196 ms
   Execution time lower quantile : 4.744957 sec ( 2.5%)
   Execution time upper quantile : 4.884646 sec (97.5%)
   Overhead used : 18.475768 ns

Found 3 outliers in 60 samples (5. %)
  low-severe   1 (1.6667 %)
  low-mild   2 (3. %)
 Variance from outliers : 1.6389 % Variance is slightly inflated by outliers

; for #(..)
Evaluation count : 60 in 60 samples of 1 calls.
 Execution time mean : 4.106831 sec
Execution time std-deviation : 54.371302 ms
   Execution time lower quantile : 4.010274 sec ( 2.5%)
   Execution time upper quantile : 4.191842 sec (97.5%)
   Overhead used : 18.475768 ns

Found 1 outliers in 60 samples (1.6667 %)
  low-severe   1 (1.6667 %)

; for (partialn 1 ..)
Evaluation count : 60 in 60 samples of 1 calls.
 Execution time mean : 4.200536 sec
Execution time std-deviation : 56.566857 ms
   Execution time lower quantile : 4.104481 sec ( 2.5%)
   Execution time upper quantile : 4.304463 sec (97.5%)
   Overhead used : 18.475768 ns

Found 2 outliers in 60 samples (3. %)
  low-severe   1 (1.6667 %)
  low-mild   1 (1.6667 %)
 Variance from outliers : 1.6389 % Variance is slightly inflated by outliers

On Wednesday, 14 August 2013 06:50:43 UTC+12, John Hume wrote:
>
> Though in some cases the performance impact could be significant, my 
> concern is readability. My understanding of the concept of partial function 
> application is that it's about supplying some but not all of the arguments. 
> So when I see `partial` in code, I expect more arguments to be supplied 
> later, which is confusing when that's not the case. (Obviously context can 
> make it easy to see that there will be no more arguments, but often that 
> context is not present.)
>
>
>
> On Tue, Aug 13, 2013 at 7:47 AM, Jay Fields 
> > wrote:
>
>> Say you have a simple function: (defn do-work [f] (f))
>>
>> When you want to call do-work you need a function, let's pretend we
>> want to use this function: (defn say-hello [n] (println "hello" n))
>>
>> Which of the following solutions do you prefer?
>>
>> (do-work (partial say-hello "bob"))
>> (do-work #(say-hello "bob"))
>>
>> I'd been using partial (which I font-lock**), but a teammate recently
>> pointed out that partial's documentation explicitly calls out the fact
>> that the number of args to partial should be less than the number of
>> args to f. In practice it's been working 'fine', but I can't help but
>> wonder if I'm sacrificing something I'm not aware of (performance?)
>>
>> ** with a font-lock, using partial *displays* the same number of chars
>> as the reader macro solution, and I find it more readable when
>> everything is in the parenthesis. -
>> http://blog.jayfields.com/2013/05/emacs-lisp-font-lock-f

Re: Do you like the Clojure syntax?

2013-08-14 Thread Benny Tsai
On Wednesday, August 14, 2013 10:14:24 AM UTC-7, Rick Moynihan wrote:

> Subjectively I found Erlang's syntax pretty horrible (though I like the 
> language itself), Ruby's is superficially beautiful but in practice 
> ambiguous and not without its warts...
>

Have you had a chance to check out Elixir (http://elixir-lang.org/)?  It's 
a language with Ruby-inspired syntax (plus goodies like Clojure-style 
protocols and true macros) running on the Erlang VM. 

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

2013-08-14 Thread Mark
Thanks!  

On Tuesday, August 13, 2013 12:18:33 PM UTC-7, Norman Richards wrote:
>
>
>
>
> On Mon, Aug 12, 2013 at 4:03 PM, Mark  >wrote:
>
>>
>> At run level 6, I get all the permutations of [1 2 3], just as expected.  
>> However, at 7, the program does not terminate and I'd like to understand 
>> why.  I feel like I need to constrain the relation between o-h and o better 
>> but I'm not sure what else to say about it.
>>
>
> Looking at this, it's clear that this will never terminate.  Your 
> recursion is unbounded on the rembero.  When you get to rembero, your l and 
> o-h are both always fresh.  (rembero :anyting (lvar) (lvar)) will produce 
> an infinite set of results. 
>
> After you've generated all your 6 results, remberallo will of course fail 
> on everything rembero produces, but you've got nothing that stops rembero.
>
> Now, consider putting the remberallo BEFORE the rembero:
>
> (defne remberallo [s l o]
>   ([() l l])
>   ([[h . r] _ _]
>  (fresh [o-h]
> (remberallo r o-h o)
> (rembero h l o-h
>
> Now, imagine you are on a final remberallo call where h is some number and 
> r is the empty list.  The recursive remberallo will will only produce one 
> answer, unifying o-h and o.  Now o-h is no longer fresh and your rembero 
> will have enough information to terminate.
>
>
>
>
>
>  
>

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


clojure.java.jdbc, idiomatic way to use a connection

2013-08-14 Thread Kyle Cordes
Hello. I've coded quite a lot of JDBC usage in Java, and enough Clojure to 
know my way around pretty well; yet I've been unable to figure out the 
following by reading the source and docs for clojure.java.jdbc. I've read 
http://clojure.github.io/java.jdbc/ and many pages linked from there.

The question is:

How do I get a connection, then run a series of operations on that same 
connection? All the API I can find (except for the deprecated, pre-0.3 API) 
seems to work on a model of: give it a DB connection spec, it connects, 
runs, and disconnects. Great for playing with a command at a time, less so 
for doing a series of things that need to happen on the same connection.

-- 
Kyle Cordes
http://kylecordes.com

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


Re: clojure.java.jdbc, idiomatic way to use a connection

2013-08-14 Thread Keith Irwin
I think you can use db-connection, something like:

  (let [conn (db-connection spec)
 meta (.getMetaData conn)]
(doall (.getTables meta nil "schema" "%s" nil))
(.close conn))

Or what have you. I wrote a little macro `with-meta-data` that was something 
like that, with added try/catch/finally to make sure the conn got closed. 

Is `with-open` a possibility?

  (with-open [conn (db-connection spec)]
 …)

Would that work?

On Aug 14, 2013, at 8:02 PM, Kyle Cordes  wrote:

> Hello. I've coded quite a lot of JDBC usage in Java, and enough Clojure to 
> know my way around pretty well; yet I've been unable to figure out the 
> following by reading the source and docs for clojure.java.jdbc. I've read 
> http://clojure.github.io/java.jdbc/ and many pages linked from there.
> 
> The question is:
> 
> How do I get a connection, then run a series of operations on that same 
> connection? All the API I can find (except for the deprecated, pre-0.3 API) 
> seems to work on a model of: give it a DB connection spec, it connects, runs, 
> and disconnects. Great for playing with a command at a time, less so for 
> doing a series of things that need to happen on the same connection.
> 
> -- 
> Kyle Cordes
> http://kylecordes.com
> 
> 
> -- 
> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> --- 
> You received this message because you are subscribed to the Google Groups 
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

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


Re: clojure.java.jdbc, idiomatic way to use a connection

2013-08-14 Thread Benny Tsai
Does db-transaction work in your case?

"Evaluates body in the context of a transaction on the specified database 
connection.

The binding provides the database connection for the transaction and the name 
to which
that is bound for evaluation of the body.
See db-transaction* for more details."

Given a spec, you can use db-transaction like this:

(db-transaction [t-db spec]

  (insert! t-db ...)

  (update! t-db ...)

  ...)


On Wednesday, August 14, 2013 8:02:52 PM UTC-7, Kyle Cordes wrote:
>
> Hello. I've coded quite a lot of JDBC usage in Java, and enough Clojure to 
> know my way around pretty well; yet I've been unable to figure out the 
> following by reading the source and docs for clojure.java.jdbc. I've read 
> http://clojure.github.io/java.jdbc/ and many pages linked from there.
>
> The question is:
>
> How do I get a connection, then run a series of operations on that same 
> connection? All the API I can find (except for the deprecated, pre-0.3 API) 
> seems to work on a model of: give it a DB connection spec, it connects, 
> runs, and disconnects. Great for playing with a command at a time, less so 
> for doing a series of things that need to happen on the same connection.
>
> -- 
> Kyle Cordes
> http://kylecordes.com
>
>

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


Re: clojure.java.jdbc, idiomatic way to use a connection

2013-08-14 Thread Sean Corfield
The `db-spec` can have a `:connection` member and all operations will
use that. You are responsible for closing it when you're done.
Something like (untested, off the top of my head):

(with-open [conn (get-connection db-spec)]
  (let [db (assoc db-spec :connection conn)]
...
(query db ...)
...
(insert! db ...)
...))

This sort of thing needs to be added to the (community-editable)
documentation since it's one of the most frequently asked questions:
http://clojure-doc.org/articles/ecosystem/java_jdbc/home.html

For the most part, the way we use it at World Singles is to define a
pool datasource connection and use that as the db-spec (which _is_
documented at that URL for both c3p0 and BoneCP).

Sean


On Wed, Aug 14, 2013 at 8:02 PM, Kyle Cordes  wrote:
> Hello. I've coded quite a lot of JDBC usage in Java, and enough Clojure to
> know my way around pretty well; yet I've been unable to figure out the
> following by reading the source and docs for clojure.java.jdbc. I've read
> http://clojure.github.io/java.jdbc/ and many pages linked from there.
>
> The question is:
>
> How do I get a connection, then run a series of operations on that same
> connection? All the API I can find (except for the deprecated, pre-0.3 API)
> seems to work on a model of: give it a DB connection spec, it connects,
> runs, and disconnects. Great for playing with a command at a time, less so
> for doing a series of things that need to happen on the same connection.
>
> --
> Kyle Cordes
> http://kylecordes.com
>
> --
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.



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

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

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