Has anyone experimented with memo functions in LC?

Geoff Canyon Rev gcanyon+rev at gmail.com
Thu Jun 16 02:12:46 EDT 2011


This would work for a particular function. I was looking for a general
solution that would allow memo-ing any function without further
consideration. In J, for example, you just and "M." to the function
definition, and you're done. If I were to do something like this in LC I'd
want to implement something similarly robust and simple to use.

As to why I want to: no particular reason, other than memo seems vaguely
possible in LC, and a useful thing to have. I like pushing the language
forward.

gc

On Tue, Jun 14, 2011 at 4:27 PM, Dick Kriesel <dick.kriesel at mail.com> wrote:

> Hi, Geoff.  Here's a way to memoize without parsing the functions'
> arguments, so commas won't be a pain.
>
> local sMemo
> function memoize pFunctionName, pParam1, pParam2
>   local tDigest
>   put md5( the params ) into tDigest
>   if tDigest is among the keys of sMemo then
>      get sMemo[ tDigest ]
>   else
>      get value( pFunctionName & "(" & item 2 to -1 of the params )
>      put it into sMemo[ tDigest ]
>   end if
>   return it
> end memoize
>
> Calling MD5 makes the array's keys shorter.  IIRC, that's good, although
> when I tried to find evidence about it in the current docs, I couldn't find
> it.
>
> Does this help?
>
> -- Dick
>
>
> On Jun 11, 2011, at 2:23 PM, Geoff Canyon Rev wrote:
>
> > http://en.wikipedia.org/wiki/Memoization
> >
> > I'm wondering if anyone has experimented with creating an automatic
> > memoization function within LC? Given that we can access argument lists,
> and
> > have "do," it seems possible, but I'm betting commas in the arguments
> would
> > be a pain. Something like this:
> >
> > function m functionName
> >   local callHistory,callHistoryValue
> >
> >   -- parse out addition arguments to m
> >   -- concatenate functionName & arguments into functionCallString
> >
> >   if callHistory[functionCallString] is not empty then
> >      return callHistoryValue[functionCallString]
> >   end if
> >
> >   -- get the function result
> >
> >   put it into callHistoryValue[functionCallString]
> >   put 1 into callHistory[functionCallString]
> >
> >   return it
> >
> > end m
> > _______________________________________________
> > use-livecode mailing list
> > use-livecode at lists.runrev.com
> > Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> > http://lists.runrev.com/mailman/listinfo/use-livecode
>
>
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>



More information about the use-livecode mailing list