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



_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Reply via email to