lua-users home
lua-l archive

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


It was thus said that the Great Hisham once stated:
> On 10 June 2017 at 03:02, Sean Conner <sean@conman.org> wrote:
> >
> > It was thus said that the Great Dirk Laurie once stated:
> > > 4. Do we make big do ... end blocks in our code in order to
> > > restrict the scope of locals?
> >
> >   I do that quite often.  In fact, I'll do things like:
> >
> >         local somevar do
> >           -- code to do a bunch of stuff
> >           somevar = ...
> >         end
> >
> > to make it clear that there is some non-trivial initialization of a local
> > variable.
> 
> Dirk talked about using do-end blocks to restrict the scope of locals,
> but the above example with odd indentation does not do that.

  Took some time, but I found an example that I could give (code that wasn't
written at work):

	local cmdline do
	  local C  = lpeg.C
	  local P  = lpeg.P
	  local SP = P" "
	  
	  local token = C((P(1) - P" ")^1)
	  cmdline = SP^0 * token * (SP * C(P(1)^0))^-1
	end

  -spc (Better?)