Thank you for the explanation; I understand it a lot better now. The
reason that I decided to use Delays was that I thought I would need to
change less. Now that I've actually changed everything to Delays, it
seems that they take much more time (the opposite of what I was trying
to do :(. But when
Hi sampii,
The problem, as I see it (& as Konrad suggested above), is that you're
not passing *functions* to (alt); you're passing values returned from
function calls, even though in the case of the sub-functions you
define those returned values are functions. Functions evaluate to
themselves, so
> After a calling
> of "alt" finishes, what happens to all those Delay objects and their
> cached values? Are they garbage-collected, or will they remain
> indefinitely? Should I worry?
>
I believe the references to the delays will be dropped as alt
executes, so they'll be eligible for grabage c
On Jan 12, 2009, at 17:11, samppi wrote:
> Awesome—thanks for everyone's answers; I think I'll go with delay/
> force. What I'm a little worried about is the caching. After a calling
> of "alt" finishes, what happens to all those Delay objects and their
> cached values? Are they garbage-collected
Awesome—thanks for everyone's answers; I think I'll go with delay/
force. What I'm a little worried about is the caching. After a calling
of "alt" finishes, what happens to all those Delay objects and their
cached values? Are they garbage-collected, or will they remain
indefinitely? Should I worry
Not a macro, but does what you want:
(defn alt [& functions]
(fn [tokens]
(some #((force %) tokens) functions)))
;define sub-functions the same way
(defn a-meta-meta-function [c]
(alt (delay (sub-function1 c)) (delay (sub-function2 c)) (delay (sub-
function3 c
--~--~-~--~-
On 12.01.2009, at 01:01, samppi wrote:
> The problem is that even though "some" and "filter" are lazy, "alt" is
> still not, so calling "(alt (sub-function1 c) ...)" in the meta-meta-
> function still evaluates (sub-function1 c), etc. It could be shown in
> the REPL:
How about changing the inter
The problem is that even though "some" and "filter" are lazy, "alt" is
still not, so calling "(alt (sub-function1 c) ...)" in the meta-meta-
function still evaluates (sub-function1 c), etc. It could be shown in
the REPL:
Clojure
user=> (defn alt [& functions]
(fn [tokens]
(some #(% tokens)
"some" is already lazy, so you may not need to change anything at
all. You might also be able to use "filter", which will not do
anything until you consume the output sequence.
-Stuart Sierra
On Jan 11, 4:44 pm, samppi wrote:
> Let's say I have a function, alt:
>
> (defn alt [& functions]
>
Let's say I have a function, alt:
(defn alt [& functions]
(fn [tokens]
(some #(% tokens) functions)))
It creates a function from a bunch of sub-functions that accepts one
collection of tokens and figures out which sub-function returns a true
value when the tokens are plugged into it.
Is t
10 matches
Mail list logo