memoize, or delay maybe

On Sun, Jan 20, 2013 at 10:29 PM, AtKaaZ <atk...@gmail.com> wrote:

> memoize?
>
>
> On Mon, Jan 21, 2013 at 7:27 AM, Larry Travis <tra...@cs.wisc.edu> wrote:
>
>> One of the neat things about Clojure (maybe all functional languages) is
>> that functions can be defined either extensionally or intensionally. How
>> can one create a Clojure structure that mixes these two types of definition?
>>
>> That is, I would like to define a function f that saves its result the
>> first time it is called against any particular argument so that if and when
>> f is later called against the same argument, it does a look-up via a hash
>> map rather than repeating a possibly expensive computation. I think I see
>> how to do this with a ref to a mutable map (where, given an argument k, f
>> would first try to find (f k) in the map but, if k is not currently a key
>> of the map, the function would compute the value v = (f k) and then, in
>> addition to returning v, add the entry <k v> to the map as a side effect.
>> But this seems ugly. Is there some way to do what I want here without
>> making explicit use of refs?
>>
>> Lazy-seqs don't give me what I want because the arguments to be given to
>> f don't occur in any kind of predictable sequence.
>>
>>   --Larry
>>
>> --
>> 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 from this group, send email to
>> clojure+unsubscribe@**googlegroups.com<clojure%2bunsubscr...@googlegroups.com>
>> For more options, visit this group at
>> http://groups.google.com/**group/clojure?hl=en<http://groups.google.com/group/clojure?hl=en>
>>
>
>
>
> --
> I may be wrong or incomplete.
> Please express any corrections / additions,
> they are encouraged and appreciated.
> At least one entity is bound to be transformed if you do ;)
>
> --
> 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 from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
>

-- 
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 from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to