Arc Forumnew | comments | leaders | submitlogin
1 point by zhtw 5853 days ago | link | parent

Only now I realized that you treat memo as some kind of the way to improve performance (do you?). What I used memo for is to make sure that function won't be called twice:

  (mac delay (e)
    `(memo (fn () ,e)))

  (def force (d) (d))
When I use lazy sequences (of symbols read from input port for example) based on these definitions I can't be sure that readc somewhere inside will never be called twice if I call force for an element of this sequence twice.

So I treat this as a bug. Or maybe I'm just wrong about what memo is for at all. Am I?



1 point by aaronla 5842 days ago | link

I'd venture to guess that memo creates a new cache for each invocation, so two calls

  (map (lambda (f)  ;; invokes f 3 times
               (f) (f) (f) )
       (list (delay (foo bar)) 
             (delay (foo bar))))
I think thiw will call foo exactly twice, because each memo invokation produces a new cache, but I may be mistaken.

[pardon the syntax... this is in scheme. i have only just installed arc and (def hello-world ...) is as far as i've gotten]

-----

1 point by absz 5842 days ago | link

The real problem is that if you do

  (let d (delay (foo bar))
    (force d)
    (force d))
, then there's no guarantee that (foo bar) will be run exactly once---if (foo bar) returns nil, then it won't be cached.

-----