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
-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
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
-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
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
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
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
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
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
...@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
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
] (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
{: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
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
:
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
/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
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:
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
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
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
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
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
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:
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
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
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
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
)
; 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
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
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))
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
60 matches
Mail list logo