Question: Understanding a package using local variable in a particular way

Hello,

I would to understand a code that I have where the structure of packages are often using a local variable in a particular way. A variable local _DO_CONSTRAINT with the same name as the procedure DO_CONSTRAINT is created.

The code is the following :

module () 
local _DO_CONSTRAINT; 
export DO_CONSTRAINT; 
option package; 

_DO_CONSTRAINT:=proc (phi::list, varslist::list) 
table([obj = CONSTRAINT, expr = phi, vars = varslist]) 
end proc

DO_CONSTRAINT:=proc (phi::{list, scalar}, vars::{list, scalar}) 
if type(phi, scalar) and type(vars, scalar) then 
_DO_CONSTRAINT([phi], [vars]) 
elif type(phi, list) and type(vars, list) and nops(phi) = nops(vars) then 
_DO_CONSTRAINT(phi, vars) 
else ERROR("The number of expressions <phi> and variables <vars> are not equal") 
end if 
end proc

end module
 

Question :
1) It seems me that this technique enable to adapt the procedure  (DO_CONSTRAINT) to different types of inputs that we can try on it (lists or scalars). Do I right ? May you give me more informations on how it works ?
2) Is it the only possibility to do this ? In other words, is there a possibility to make a similar code and also concise but without using this local variable ?

Thanks a lot for your help.

 

Please Wait...