Has anyone experimented with memo functions in LC?
Jim Ault
jimaultwins at yahoo.com
Sun Jun 12 00:09:38 EDT 2011
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
This 'do' function seems to work with commas in args,
but it may not be the point you are making
---- start working code
on testDoWithArgs
-- with commas in args
put quote into q
put "dog, cat, buffalo,,," into mammals
put "perch,carp,trout" into fish
put "robin" into birds
put "put concatenate(mammals, fish, birds, "&q&"^"&q& ") into ark"
into cmd
do cmd
;put ark
end testDoWithArgs
function concatenate aaa, bbb, ccc, D
return aaa &D&bbb &D&ccc &D
end concatenate
---- end working code
Jim Ault
Las Vegas
More information about the use-livecode
mailing list