Hi,
just in case you want a thread-safe, optimal version based on the classic
memoize discussion[1].
(defmacro memofn
[name args & body]
`(let [cache# (atom {})]
(fn ~name [& args#]
(let [update-cache!# (fn update-cache!# [state# args#]
(if-not (cont
Fixed:
(defmacro memofn [name args & body]
`(let [cache# (atom {})]
(fn ~name ~args
(if-let [e# (find @cache# ~args)]
(val e#)
(let [ret# (do ~@body)]
(swap! cache# assoc ~args ret#)
ret#)
--
You received this message because you are subsc
On Fri, Jan 20, 2012 at 1:34 AM, Mark Engelberg
wrote:
> I think this works:
>
> (defmacro memofn [name args body]
> `(let [cache# (atom {})]
> (fn ~name ~args
> (if-let [e# (find @cache# ~args)]
> (val e#)
> (let [ret# ~body]
> (swap! cache# assoc ~args ret#)
I think this works:
(defmacro memofn [name args body]
`(let [cache# (atom {})]
(fn ~name ~args
(if-let [e# (find @cache# ~args)]
(val e#)
(let [ret# ~body]
(swap! cache# assoc ~args ret#)
ret#)
If you spot any problems with this that I'm m
On Thu, Jan 19, 2012 at 9:46 PM, Cedric Greevey wrote:
> Something like
>
> (defn make-memoized [some-param]
> (let [cache (atom {})]
> (fn [& args]
> (when-not (contains? cache args)
> (swap! cache assoc args (expensive-computation some-param args)))
> (cache args
>
Two
Something like
(defn make-memoized [some-param]
(let [cache (atom {})]
(fn [& args]
(when-not (contains? cache args)
(swap! cache assoc args (expensive-computation some-param args)))
(cache args
?
--
You received this message because you are subscribed to the Googl
). So
I need to create the memoized function locally and return it.
But I can't think of any way to do this without letrec.
Any suggestions?
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@g
Hi,
if you always follow the let structure you outlined the following might work.
Untested, though. Note, that things work recursively with this approach.
(def ours? #{#'button #'label ...})
(defmacro panel
[{:keys [id]} & components]
(let [[bindings body]
(reduce (fn [[bindings bod
Hi,
you'll probably have to rewrite your panel macro, so that it recognizes the
button (and label, etc) macros ((= #'button (resolve &env sym)) in 1.3) and
extracts the ids from the subform. Then you construct a global let which
contains all the individual id namings. Then you group all '...' p
Hi,
to implement letrec in a language with eager evaluation strategy some
kind of mutability is probably needed. Consider for example a self-
referential definition such as
(let [fibo (lazy-cat [1 1] (map + fibo (rest fibo)))]
(take 10 fibo))
This will not work since fibo is not in scope when
'declare' wouldn't be good because of the scope of vars. There's no sense
using global (albeit namespaced) variables for what probably only need to
be local identifiers.
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send em
Is 'declare' possibly the missing component here?
On Dec 14, 3:37 pm, Razvan Rotaru wrote:
> Yes. Assuming I have following macros:
>
> (button :id b1 :listener #(...)) => (let [b1 (new JButton)] ...)
> (panel [:id p1] (button :id b1 ...) (button :id b2 ...)) => (let [p1
> (new JPanel) b1 (button
Yes. Assuming I have following macros:
(button :id b1 :listener #(...)) => (let [b1 (new JButton)] ...)
(panel [:id p1] (button :id b1 ...) (button :id b2 ...)) => (let [p1
(new JPanel) b1 (button :id b1 ...) b2 (button :id b2 ...)] ...)
How to make the listener in b1 refer to b2?
Razvan
On Dec
Do you have a minimal example of what you are trying to do?
On Wed, Dec 14, 2011 at 3:53 PM, Razvan Rotaru wrote:
> letfn defines functions. I'm just defining some values. The values
> contain anonymous functions which need to refer to other values.I know
> there are workarounds for this, but thi
letfn defines functions. I'm just defining some values. The values
contain anonymous functions which need to refer to other values.I know
there are workarounds for this, but this means I must change the
interface.
Razvan
On Dec 14, 9:56 pm, David Nolen wrote:
> On Wed, Dec 14, 2011 at 2:53 PM, R
On Wed, Dec 14, 2011 at 2:53 PM, Razvan Rotaru wrote:
> I don't quite understand why people are saying this. Anyway, It's not
> enough for me.
What can't you solve your problem with what was suggested?
David
--
You received this message because you are subscribed to the Google
Groups "Clojure
I don't quite understand why people are saying this. Anyway, It's not
enough for me.
On Dec 14, 9:13 pm, Kevin Downey wrote:
> lazy-seq and letfn should cover anything you would need letrec for
>
>
>
>
>
>
>
>
>
> On Wed, Dec 14, 2011 at 11:09 AM, Razv
lazy-seq and letfn should cover anything you would need letrec for
On Wed, Dec 14, 2011 at 11:09 AM, Razvan Rotaru wrote:
> Hi,
>
> Is there a reliable implementation of letrec in clojure? Anybody using
> it?
> I have found a post from 2008, with an implementation which I don'
Hi,
Is there a reliable implementation of letrec in clojure? Anybody using
it?
I have found a post from 2008, with an implementation which I don't
understand (and it's said to be slow), and which I don't know whether
to trust.(It's also supposed to be slow).
Thanks,
Razvan
-
i like it a lot! what do you think of adding trampoline to it like
> > > so:
>
> > >http://gist.github.com/487019
>
> > Thanks!
>
> > Trampoline in letrec automatically breaks all cases where the value
> > being bound to the local is not a function, s
ot! what do you think of adding trampoline to it like
> > so:
>
> >http://gist.github.com/487019
>
> Thanks!
>
> Trampoline in letrec automatically breaks all cases where the value
> being bound to the local is not a function, so it would interfere with
> what I
On 23 July 2010 06:50, George Jahad wrote:
> i like it a lot! what do you think of adding trampoline to it like
> so:
>
> http://gist.github.com/487019
Thanks!
Trampoline in letrec automatically breaks all cases where the value
being bound to the local is not a function, so it wou
i like it a lot! what do you think of adding trampoline to it like
so:
http://gist.github.com/487019
On Jul 22, 7:38 pm, Michał Marczyk wrote:
> Hi All,
>
> I've written a letrec macro with the goal of hopefully tying the knot
> [1] in Clojure etc. Some examples of w
Hi All,
I've written a letrec macro with the goal of hopefully tying the knot
[1] in Clojure etc. Some examples of what it can do are included in
the Gist (including -- as of now -- two not immediately rewritable in
terms of letfn). So far I haven't caught any bugs, but hey, it'
24 matches
Mail list logo