Re: a record that implements the iFn protocol can itself be called as a function?

2015-05-15 Thread skuro
Why not trying it right away in the REPL? user= (defrecord Bar [state]) ; - not implementing IFn user.Bar user= ((-Bar foo)) ClassCastException user.Bar cannot be cast to clojure.lang.IFn user/eval15532 (form-init5689008917050406381.clj:1) user= (defrecord Foo [state] clojure.lang.IFn

a record that implements the iFn protocol can itself be called as a function?

2015-05-14 Thread piastkrakow
-drinky dude) belun(having daiquiri): uuumm But if a record implements clojure.lang.IFn it can be called directly? Do I understand this correctly? When I run macroexpand-all on defrecord-ifn, as defined here: https://github.com/overtone/overtone/blob/e200075da27375727db1f5ce342e2e1c22ea1dbd/src

how does one unquote a list of records that implement IFn without treating the first item as a function?

2013-09-05 Thread Jim - FooBar();
to records which implement IFn... doing ~attrs tries to invoke the list as a function-call because the first symbol happens to be a function but I just want the list of records (eval'd symbols) so the assertion can proceed... any ideas? Jim -- -- You received this message because you

Re: how does one unquote a list of records that implement IFn without treating the first item as a function?

2013-09-05 Thread Dave Ray
-pipe my own basic stemming pipe my-ssplit my-tokenizer porter-stemmer) where the last three symbols refer to records which implement IFn... doing ~attrs tries to invoke the list as a function-call because the first symbol happens to be a function but I just want the list of records (eval'd

Re: how does one unquote a list of records that implement IFn without treating the first item as a function?

2013-09-05 Thread Jim - FooBar();
symbols refer to records which implement IFn... doing ~attrs tries to invoke the list as a function-call because the first symbol happens to be a function but I just want the list of records (eval'd symbols) so the assertion can proceed... any ideas? Jim -- -- You

Re: Easy way to implement IFn in java?

2012-11-03 Thread JvJ
Thanks! Works like a charm. On Friday, 2 November 2012 19:58:19 UTC-4, AtKaaZ wrote: looks like you can use AFn() in your example ie. static IFn assoc = new AFn(){ @Override public Object invoke(Object m, Object k, Object v) { return RT.assoc(m, k, v); } }; (code

Easy way to implement IFn in java?

2012-11-02 Thread JvJ
I'm writing a Java interface to some Clojure code, and some of the code needs functions as parameters. I'd like to be able create objects from anonymous inner classes. Something like this: func = new IFn(){ public Object invoke(obj1,...){ //code in here } }; I'd like

Re: Easy way to implement IFn in java?

2012-11-02 Thread AtKaaZ
looks like you can use AFn() in your example ie. static IFn assoc = new AFn(){ @Override public Object invoke(Object m, Object k, Object v) { return RT.assoc(m, k, v); } }; (code from clojure.lang.Var.assoc) On Sat, Nov 3, 2012 at 12:51 AM, JvJ kfjwhee...@gmail.com wrote

Re: Extending IFn

2011-10-28 Thread Meikel Brandmeyer (kotarak)
Hi, since IFn is a Java interface and not a protocol, I'm afraid there is no better way to define this. However I would write the macro slightly differently. I find this more approachable. YMMV. (def max-arities 20) (defmacro definvokable [type fields deftype-tail] (let [f(fields

Re: Extending IFn

2011-10-28 Thread Sean Devlin
...@kotka.de wrote: Hi, since IFn is a Java interface and not a protocol, I'm afraid there is no better way to define this. However I would write the macro slightly differently. I find this more approachable. YMMV. (def max-arities 20) (defmacro definvokable   [type fields deftype-tail]   (let

Extending IFn

2011-10-27 Thread Sean Devlin
I'm experimenting with creating my own fn types. I was wondering if there was a better way of extending IFn than this: https://gist.github.com/1321330 Is there a more idiomatic way? -- You received this message because you are subscribed to the Google Groups Clojure group. To post

Re: Records implementing IFn

2011-02-08 Thread Mark Fredrickson
] (repeat n this))) user.Example user (def e (Example. I am e)) #'user/e user (e 2) (#:user.Example{:data I am e} #:user.Example{:data I am e}) user (def some-es (e 5)) ; Throws java.lang.AbstractMethodError I can't tell if I am doing something wrong with respect to the IFn definition

Records implementing IFn

2011-02-07 Thread Mark Fredrickson
{:data I am e}) user (e) #:user.Example{:data I am e} user (def some-es (e 5)) ; Throws java.lang.AbstractMethodError I can't tell if I am doing something wrong with respect to the IFn definition, or if I am encountering a bug. I have not tried building up a deftype by hand. That may well solve my

Re: Records implementing IFn

2011-02-07 Thread Alex Osborne
I am e} #:user.Example{:data I am e}) user (def some-es (e 5)) ; Throws java.lang.AbstractMethodError I can't tell if I am doing something wrong with respect to the IFn definition, or if I am encountering a bug. I think you need to implement applyTo for a properly working IFn implementation

Re: an object of class created using defrecord does not implement IFn .. while it behaves very similar to map otherwise ..

2010-12-31 Thread Alyssa Kwan
: Am 31.12.2010 03:29, schrieb Alex Baranosky: I've been playing with making a macro to encapsulate Stuart's post, like this: (defmacro defrecord-ifn [name args]    `(defrecord ~name ~...@args      clojure.lang.IFn      (invoke [this key] (get this key (defrecord-ifn Foo

Re: an object of class created using defrecord does not implement IFn .. while it behaves very similar to map otherwise ..

2010-12-31 Thread Robert McIntyre
want to capture the parameters, so I would use ~'this. On Dec 30, 11:54 pm, André Thieme splendidl...@googlemail.com wrote: Am 31.12.2010 03:29, schrieb Alex Baranosky: I've been playing with making a macro to encapsulate Stuart's post, like this: (defmacro defrecord-ifn [name args

an object of class created using defrecord does not implement IFn .. while it behaves very similar to map otherwise ..

2010-12-30 Thread Sunil S Nandihalli
Hello everybody, An object of class created using defrecord does not implement IFn .. while it behaves very similar to map otherwise .. Is this way by design? can it be made to behave like a hash-map without any performance penalty in terms of behaving like a function? Thanks, Sunil. -- You

Re: an object of class created using defrecord does not implement IFn .. while it behaves very similar to map otherwise ..

2010-12-30 Thread Chas Emerick
Yes, that's intentional – implementing IFn is (as you can see) orthogonal to implementing IPersistentMap, IPersistentCollection, etc. Of course, keyword access of record slots is most idiomatic, e.g. (:my-slot some-record) If you'd like to pass around a function that accesses a record, there's

Re: an object of class created using defrecord does not implement IFn .. while it behaves very similar to map otherwise ..

2010-12-30 Thread Stuart Sierra
You can make it implement IFn easily enough: (defrecord Foo [a b c] clojure.lang.IFn (invoke [this key] (get this key))) It has been debated whether or not this is a good idea, design-wise, but it should not be a performance penalty. -Stuart Sierra clojure.com -- You received

Re: an object of class created using defrecord does not implement IFn .. while it behaves very similar to map otherwise ..

2010-12-30 Thread Alex Baranosky
I've been playing with making a macro to encapsulate Stuart's post, like this: (defmacro defrecord-ifn [name args] `(defrecord ~name ~...@args clojure.lang.IFn (invoke [this key] (get this key (defrecord-ifn Foo [a b c]) (def foo (Foo. A B C)) (prn (map foo [:a :c])) = (A, C) I

Re: an object of class created using defrecord does not implement IFn .. while it behaves very similar to map otherwise ..

2010-12-30 Thread Alex Osborne
Alex Baranosky alexander.barano...@gmail.com writes: I've been playing with making a macro to encapsulate Stuart's post, like this: (defmacro defrecord-ifn [name args]   `(defrecord ~name ~...@args     clojure.lang.IFn     (invoke [this key] (get this key (defrecord-ifn Foo [a b c

Re: an object of class created using defrecord does not implement IFn .. while it behaves very similar to map otherwise ..

2010-12-30 Thread Alex Baranosky
Worked like a charm. Thanks Alex. -- 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

Re: an object of class created using defrecord does not implement IFn .. while it behaves very similar to map otherwise ..

2010-12-30 Thread Alyssa Kwan
Technically, there's no possibility of variable capture, but you should use gensyms: (defmacro defrecord-ifn [name args] `(defrecord ~name ~...@args clojure.lang.IFn (invoke [this# key#] (get this# key# Thanks, Alyssa On Dec 30, 9:29 pm, Alex Baranosky alexander.barano

Re: an object of class created using defrecord does not implement IFn .. while it behaves very similar to map otherwise ..

2010-12-30 Thread Sunil S Nandihalli
alyssa.c.k...@gmail.com wrote: Technically, there's no possibility of variable capture, but you should use gensyms: (defmacro defrecord-ifn [name args] `(defrecord ~name ~...@args clojure.lang.IFn (invoke [this# key#] (get this# key# Thanks, Alyssa On Dec 30, 9:29 pm

Re: an object of class created using defrecord does not implement IFn .. while it behaves very similar to map otherwise ..

2010-12-30 Thread André Thieme
Am 31.12.2010 03:29, schrieb Alex Baranosky: I've been playing with making a macro to encapsulate Stuart's post, like this: (defmacro defrecord-ifn [name args] `(defrecord ~name ~...@args clojure.lang.IFn (invoke [this key] (get this key (defrecord-ifn Foo [a b c]) (def foo

Re: I am unclear on how I can call an Ifn stored in a map usefully

2010-06-23 Thread Tim Robinson
Perfect! And Thanks! Tim On Jun 22, 7:00 pm, Michał Marczyk michal.marc...@gmail.com wrote: Firstly, consider using Delays rather than IFn. See (doc delay) and (doc delay?). In Clojure, many sorts of things are IFns, including (among others) sets, vectors and maps, and you probably don't want

I am unclear on how I can call an Ifn stored in a map usefully

2010-06-22 Thread Tim Robinson
Hello Folks, I'm a noob to both programming (1 year part-time) and to Clojure (1 week). I am unclear on how I can call an Ifn stored in a map usefully and I am hoping you can help me. I have stored data in a few maps (both functions and data): user= (def uhoh* (ref {:event {:date #(date

Re: I am unclear on how I can call an Ifn stored in a map usefully

2010-06-22 Thread Daniel Gagnon
MDT, :name EOW} I need the date representing the time I assign the def (evaluated at call time) and I don't know which keys will have an Ifn or just a string etc. Is there existing falicilites to make this happen? An existing function call perhaps not obvious to me? Or do I need to write

Re: I am unclear on how I can call an Ifn stored in a map usefully

2010-06-22 Thread Michał Marczyk
Firstly, consider using Delays rather than IFn. See (doc delay) and (doc delay?). In Clojure, many sorts of things are IFns, including (among others) sets, vectors and maps, and you probably don't want to call those. (def uhoh* (ref {:event {:date (delay (java.util.Date.)) :name EOW}})) (def why

Re: refs implement IFn, atoms and agents do not?

2009-10-04 Thread Stephen C. Gilardi
/browse_thread/thread/534dd074f18851ab suggests that reference types implementing IFn isn't the intended behavior. Using deref or @ works with all reference types: user (defn my-fn [x] (+ x 3)) #'user/my-fn user (def my-agent (agent my-fn)) #'user/my-agent

Re: refs implement IFn, atoms and agents do not?

2009-10-04 Thread Stephen C. Gilardi
On Oct 4, 2009, at 5:04 PM, Mark Volkmann wrote: Minor technicality ... Vars are a reference type, but deref and @ don't work with them. I'm guessing you're thinking of an interaction like this: user= (def a 3) #'user/a user= @a java.lang.ClassCastException:

Re: refs implement IFn, atoms and agents do not?

2009-10-04 Thread Mark Volkmann
On Sun, Oct 4, 2009 at 4:26 PM, Stephen C. Gilardi squee...@mac.com wrote: On Oct 4, 2009, at 5:04 PM, Mark Volkmann wrote: Minor technicality ... Vars are a reference type, but deref and @ don't work with them. I'm guessing you're thinking of an interaction like this:        user= (def

refs implement IFn, atoms and agents do not?

2009-10-03 Thread Stuart Halloway
Is there a principled reason for this? I have written some code that (unintentionally) limits itself to refs because it assumes that all reference types can sit in function position. Thanks, Stu --~--~-~--~~~---~--~~ You received this message because you are

Re: Why doesn't regex implement ifn?

2009-08-29 Thread eyeris
I have the same urge, to want to use regexps as predicates. However I definitely would not like to read such code. I can only imagine having to try to read such code if I didn't understand regexps. E.g. (filter #\d+ maybe-numbers) is clear enough to someone who understands regexps. However

Re: Why doesn't regex implement ifn?

2009-08-28 Thread Shawn Hoover
On Thu, Aug 27, 2009 at 9:05 PM, Chas Emerick cemer...@snowtide.com wrote: On Aug 27, 2009, at 1:34 PM, Chouser wrote: The benefits of # producing a real java.util.regex.Pattern object instead of some Clojury wrapper will decrease as it becomes more common to write Clojure code that can

Re: Why doesn't regex implement ifn?

2009-08-28 Thread Chouser
On Thu, Aug 27, 2009 at 9:05 PM, Chas Emerickcemer...@snowtide.com wrote: On Aug 27, 2009, at 1:34 PM, Chouser wrote: The benefits of # producing a real java.util.regex.Pattern object instead of some Clojury wrapper will decrease as it becomes more common to write Clojure code that can run

Re: Why doesn't regex implement ifn?

2009-08-28 Thread Chas Emerick
On Aug 28, 2009, at 10:01 AM, Shawn Hoover wrote: Why wouldn't # produce whatever the corollary regex object is on each host platform? I had a couple suggestions on clojure-dev for ClojureCLR that line up with the produce the corollary idea:

Re: Why doesn't regex implement ifn?

2009-08-28 Thread Chouser
for the original IFn point). But is it true? The amount of overlap between, for example, JVM and JavaScript is quite substantial, both having borrowed features and syntax quite heavily from perl. http://www.regular-expressions.info/refflavors.html I think that a s long as we're not trying to support ancient

Re: Why doesn't regex implement ifn?

2009-08-28 Thread Chas Emerick
becomes rather less useful (except I suppose for the original IFn point). But is it true? The amount of overlap between, for example, JVM and JavaScript is quite substantial, both having borrowed features and syntax quite heavily from perl. http://www.regular-expressions.info/refflavors.html

Re: Why doesn't regex implement ifn?

2009-08-27 Thread Sean Devlin
On Aug 27, 1:06 am, Timothy Pratley timothyprat...@gmail.com wrote: Granted, this wouldn't work for anything that gets passed to Java, but the following gist would be a start. http://gist.github.com/176032 You already have a getPattern method for those cases. Which suggests another

Re: Why doesn't regex implement ifn?

2009-08-27 Thread eyeris
number-text? maybe-numbers) My point is that, since magic numbers are bad, you should be giving the regex a meaningful name, so implementing IFn for regexps isn't a big savings because it pretty much just transforms: (defn number-text? [s] (re-match? #^\d+$ s)) into this: (defn number-text? [s

Re: Why doesn't regex implement ifn?

2009-08-27 Thread Sean Devlin
) ; good code (defn re-match? [re s] (not (nil? (re-matches re s (defn number-text? [s] (re-match? #^\d+$ s)) (filter number-text? maybe-numbers) My point is that, since magic numbers are bad, you should be giving the regex a meaningful name, so implementing IFn for regexps isn't a big

Re: Why doesn't regex implement ifn?

2009-08-27 Thread Chouser
On Thu, Aug 27, 2009 at 11:41 AM, Sean Devlinfrancoisdev...@gmail.com wrote: On Aug 27, 1:06 am, Timothy Pratley timothyprat...@gmail.com wrote:  If #X created a (re-fn X) then all the re functions could accept a function and call it in order to avoid having to do (re-find (pp) s). The

Re: Why doesn't regex implement ifn?

2009-08-27 Thread Sean Devlin
Hmmm... I think you're confusing the issue. Your compliant seems to be more directed at magic numbers than regexes. If I understand your argument (which I agree with): ;bad code (filter #\d+ maybe-numbers) ;good code (let [is-number-regex #\d+] (filter is-number-regex maybe-numbers))

Re: Why doesn't regex implement ifn?

2009-08-27 Thread Sean Devlin
Awesome. +1 On Aug 27, 9:57 pm, Timothy Pratley timothyprat...@gmail.com wrote: The only feature I want is the ability to use a regex as a predicate.  Would automatically forcing the first step to get a nice 'nil' be unacceptable? Sounds good to me! This can be quite easily

Re: Why doesn't regex implement ifn?

2009-08-27 Thread Timothy Pratley
The only feature I want is the ability to use a regex as a predicate.  Would automatically forcing the first step to get a nice 'nil' be unacceptable? Sounds good to me! This can be quite easily accommodated: (defn re-fn Construct a regular expression from string. Calling a regular

Re: Why doesn't regex implement ifn?

2009-08-27 Thread Chas Emerick
On Aug 27, 2009, at 1:34 PM, Chouser wrote: The benefits of # producing a real java.util.regex.Pattern object instead of some Clojury wrapper will decrease as it becomes more common to write Clojure code that can run on non-JVM platforms. So although this idea has come up and then been

Why doesn't regex implement ifn?

2009-08-26 Thread Sean Devlin
Okay, I'm sure this has come up before. I was just wondering if anyone knew why the regex literal doesn't implement IFn? At first glance it seems like the following would be useful: user=(#\d{3} 123) true This is defined as... user=(not (nil? (re-matches #\d{3} 123))) true What am I missing

Re: Why doesn't regex implement ifn?

2009-08-26 Thread Chas Emerick
On Aug 26, 2009, at 9:17 PM, Sean Devlin wrote: Okay, I'm sure this has come up before. I was just wondering if anyone knew why the regex literal doesn't implement IFn? At first glance it seems like the following would be useful: user=(#\d{3} 123) true This is defined as... user

Re: Why doesn't regex implement ifn?

2009-08-26 Thread Timothy Pratley
java.util.regex.Pattern I imagine a wrapper class could be returned instead that implemented IFn and Pattern, but which function would it call? (re-find m) (re-find re s) (re-groups m) (re-matcher re s) (re-matches re s) (re-pattern s) (re-seq re s) I don't think there is a clear implicit

Re: Why doesn't regex implement ifn?

2009-08-26 Thread Chas Emerick
On Aug 26, 2009, at 9:46 PM, Timothy Pratley wrote: java.util.regex.Pattern I imagine a wrapper class could be returned instead that implemented IFn and Pattern, Pattern is a final concrete class, so that's not possible. ...I'm counting down until I see an all-clojure regex implementation

Re: Why doesn't regex implement ifn?

2009-08-26 Thread Rich Hickey
On Aug 26, 9:46 pm, Timothy Pratley timothyprat...@gmail.com wrote: java.util.regex.Pattern I imagine a wrapper class could be returned instead that implemented IFn and Pattern, Unfortunately, Pattern is a final class. Rich --~--~-~--~~~---~--~~ You

Re: Why doesn't regex implement ifn?

2009-08-26 Thread Sean Devlin
that implemented IFn and Pattern, Unfortunately, Pattern is a final class. Rich --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts

Re: Why doesn't regex implement ifn?

2009-08-26 Thread Timothy Pratley
Granted, this wouldn't work for anything that gets passed to Java, but the following gist would be a start. http://gist.github.com/176032 You already have a getPattern method for those cases. Which suggests another solution: (defn re-fn Uses ss to construct a java.util.Pattern. Returns a

Why do Refs implement IFn and Atoms don't?

2009-05-14 Thread David Nolen
Just curious about the reasoning behind this decision? ((ref +) 3 4) ; - 7 ((atom +) 3 4) ; Exception --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to

Re: Why do Refs implement IFn and Atoms don't?

2009-05-14 Thread Christophe Grand
David Nolen a écrit : Just curious about the reasoning behind this decision? ((ref +) 3 4) ; - 7 ((atom +) 3 4) ; Exception Last time I asked, Rich said to not rely on refs implementing IFn. (It may be a remain from the time where vars and refs were the same thing -- just guessing

Re: IFn?

2009-04-19 Thread eyeris
Generally, if you see this in a runtime exception, you tried to call something that does not implement the IFn interface. On Apr 18, 11:37 pm, tmountain tinymount...@gmail.com wrote: Sorry for the newbie question, but can someone tell me what IFn means exactly? I keep running

Re: IFn?

2009-04-19 Thread tmountain
Thanks, makes sense. Travis On Apr 19, 12:47 am, Kevin Downey redc...@gmail.com wrote: ifn? returns true for things that implement clojure.lang.IFn, IFn is the interface for things that can be put in the operator position in a s-expr: functions vectors maps sets keywords symbols

IFn?

2009-04-18 Thread tmountain
Sorry for the newbie question, but can someone tell me what IFn means exactly? I keep running into it in the docs particularly in the keyword documentation, and Google has yet to expain. Thanks, Travis --~--~-~--~~~---~--~~ You received this message because you

Re: IFn?

2009-04-18 Thread Kevin Downey
ifn? returns true for things that implement clojure.lang.IFn, IFn is the interface for things that can be put in the operator position in a s-expr: functions vectors maps sets keywords symbols ...? fn? returns true for just functions On Sat, Apr 18, 2009 at 9:37 PM, tmountain tinymount