lua-users home
lua-l archive

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


Hi,

Thanks William, Sean and Roborto.

I was worried about overusing just one variable (Carg 1) to hold all state information.

Without moving to a more object oriented design using setmetables.

Seems like the nobody does that.

For example :

local Patt = P('ABC')

Cmt (Patt,parent.ABC)

where parent is a object which holds state information.

Rather that what we do today:

local Patt = (Carg 1)*P('ABC')

Cmt (Patt,ABC) -- ABC is stateless

Cheers !

On Thu, May 2, 2019 at 5:02 PM Roberto Ierusalimschy <roberto@inf.puc-rio.br> wrote:
>   You missed one---you could always use global variables and avoid Carg() or
> building a separate grammer entirely.

You can also use closures, avoiding global variables. The functions
in the pattern use external local variables, and some helper
functions allow you to change the values of these variables.

do
  local X

  function helperX (newx) X = newx end

  -- your pattern goes here, using 'X'
  ...
end

-- Roberto