On Tuesday, September 24, 2013, Dirk Laurie wrote:
2013/9/23 Andrew Starks <andrew.starks@trms.com>:
> I have many setter methods that handle properties that represent an
> inventory of one or more objects of the same class (to borrow from
> OOP).
>
> So that I don't need to write a "set_prop" and "set_props" function, I
> write this quite a bit:
>
> local function f(arg, ...)
> if (...) then
> return arg, f(...)
> else
> return arg
> end
> end
I assume something non-trivial is being done too, i.e
local function f(arg, ...)
if (...) then
return arg, f(...)
else
arg = complicated_function_of(arg)
return arg
end end
Not really and it wouldn't be the first time I've labored under an ignorance that others shed in chapter 1 of PiL. :P This example might be better:
function f:add_one_or_more_props(args,...)
--do stuff to add props
if (...) then
self:add_one_or_more_props(...)
else
return self
end
end
Or another variant:
function f:add_one_or_more_props(args,...)
if not args then return self end
--do stuff
f:add_one_or_more_props(...)
end
I think that it's a much simpler question than I communicated and the second version might be my answer, although erroring on the first call, if it doesn't contain arguments, is not possible...
-Andrew
I shouldn't post when I first wake up...
This question only makes sense in the cases where I'm returning the values of the recursion as independent values, effectively creating: