[fpc-pascal] Better usage of "with"

Ryan Joseph ryan at thealchemistguild.com
Thu Jun 14 10:33:06 CEST 2018



> On Jun 14, 2018, at 3:23 PM, Marco van de Voort <marcov at stack.nl> wrote:
> 
>> // works with function parameters also.
>> // this is almost like a class helper or at very least mimics ?self? in methods.
>> 
>> procedure OpenDoor(with var door: TDoor);
>> begin
>> 	state := true; // with imports door namespace into entire function scope
>> end;
> 
> you set a runtime variable to add a compiletime scope ? I don't understand.
> 
> Is your reference language an interpreter?


the “with” in the parameter is like a “with door do” block inside the entire function scope. I really liked this idea of his because it’s basically something Pascal already does but it’s automatic with this syntax.

procedure OpenDoor(var door: TDoor);
begin
  with door do
   begin
     state := true; // with imports door namespace into entire function scope
   end;
end;


Regards,
	Ryan Joseph




More information about the fpc-pascal mailing list