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

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

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,

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

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 ddellaco...@gmail.comwrote: I know you said clj-time solved this for you, but here's another way to handle it which avoids using a macro

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

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

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

calling java static member using string?

2013-08-13 Thread Daniel Meneses Báez
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,

Re: calling java static member using string?

2013-08-13 Thread Daniel Meneses Báez
ok I'm trying CompilerException java.lang.NoSuchFieldException: s, compiling:(NO_SOURCE_PATH:1:1) user (defmacro is [s instant] `(= (.get ~instant Calendar/DAY_OF_WEEK) (. Calendar ~s))) #'user/is user (is 'TUESDAY (Calendar/getInstance)) CompilerException

Re: calling java static member using string?

2013-08-13 Thread Sean Corfield
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)) ;;