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(); <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<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 <dap...@gmail.com>
>> 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<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<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 a topic in the
> Google Groups "Clojure" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/clojure/yXRXJCdsOrM/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>



-- 
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 clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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.

Reply via email to