lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Sun, 21 Apr 2013 19:45:46 +0200
Dirk Laurie <dirk.laurie@gmail.com> wrote:

> 2013/4/21 Steve Litt <slitt@troubleshooters.com>:
> 
> > By the way, are you going to let the other shoe drop and do the same
> > thing in the subroutine *call*?
> >
> > function f(x=3, y=4)
> >    whatever()
> > end
> >
> > f(y=7)   -- no need to articulate x
> 
> This is immeasurably harder. The other one is mere syntax sugar, a
> trivial modification to the source string before passing it along.

Never mind then. Luckily, Lua features tables so:

function whatever(t)
  for k,v in pairs(t) do
    print(k,' : ', v)
  end
end

function f(t)
  t.x=t.x or 3
  t.y=t.y or 4
  whatever(t)
end

local t={}
t.y=7
f(t)


This is how I wrote my infamous "Relevant Lines" continue statement
workaround -- zillions of defaults in a table made it useful under
widely varying circumstances, and also made it spectacular for break
logic:

http://www.troubleshooters.com/codecorn/lua/luaclosures.htm#_A_Practical_Line_Skipper_Iterator

Thanks,

SteveT

Steve Litt                *  http://www.troubleshooters.com/
Troubleshooting Training  *  Human Performance