Recent

Author Topic: Passing parameters by name  (Read 1102 times)

MarkMLl

  • Hero Member
  • *****
  • Posts: 6646
Passing parameters by name
« on: January 19, 2021, 11:19:29 pm »
Can somebody provide an update on defining records using named fields at runtime? I believe that this was supposed to be implemented at some point but I've just been idly experimenting and it doesn't (yet) work.

Or I'm doing something stupid, which is of course likely :-)

Code: Pascal  [Select][+][-]
  1. program test;
  2.  
  3. type
  4.   opType= record
  5.             name: string[255];
  6.             priority: integer
  7.           end;
  8.  
  9. const
  10.   add: opType= (name: '+'; priority: 5);   // OK
  11. //  sub: opType= (priority: 5; name: '-'); // Compile-time error (as documented)
  12.   mul: opType= (name: '*');                // Compile-time warning
  13.  
  14.  
  15. procedure defineOp(const op: opType);
  16.  
  17. begin
  18. end { defineOp } ;
  19.  
  20.  
  21. begin
  22.   defineOp(add);                   // OK
  23.   defineOp(name: '+'; priority: 5) // Compile-time error
  24. end.
  25.  

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Josh

  • Hero Member
  • *****
  • Posts: 1270
Re: Passing parameters by name
« Reply #1 on: January 20, 2021, 12:17:42 am »
 
Code: [Select]
mul: opType= (name: '*');if you add your priority param
Code: [Select]
mul: opType= (name: '*'; priority: 2);
The best way to get accurate information on the forum is to post something wrong and wait for corrections.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5444
  • Compiler Developer
Re: Passing parameters by name
« Reply #2 on: January 20, 2021, 08:19:17 am »
Can somebody provide an update on defining records using named fields at runtime? I believe that this was supposed to be implemented at some point but I've just been idly experimenting and it doesn't (yet) work.

This is not supported and there are no plans to do so.

MarkMLl

  • Hero Member
  • *****
  • Posts: 6646
Re: Passing parameters by name
« Reply #3 on: January 20, 2021, 10:28:51 am »
Code: [Select]
mul: opType= (name: '*');if you add your priority param
Code: [Select]
mul: opType= (name: '*'; priority: 2);

Yes. But the documentation was unclear whether a missing field was a compilation or runtime error.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

MarkMLl

  • Hero Member
  • *****
  • Posts: 6646
Re: Passing parameters by name
« Reply #4 on: January 20, 2021, 10:33:01 am »
Can somebody provide an update on defining records using named fields at runtime? I believe that this was supposed to be implemented at some point but I've just been idly experimenting and it doesn't (yet) work.

This is not supported and there are no plans to do so.

OK. My mistake, I thought you'd said in the past that this sort of tuple would eventually be supported.

Unfortunate decision IMO, since I've had situations in the past where changing the number of parameters of a function with a final optional parameter resulted in a bug which was very difficult to pin down, and being able to pass parameters by name rather than position would avoid that.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

PascalDragon

  • Hero Member
  • *****
  • Posts: 5444
  • Compiler Developer
Re: Passing parameters by name
« Reply #5 on: January 20, 2021, 01:30:03 pm »
Can somebody provide an update on defining records using named fields at runtime? I believe that this was supposed to be implemented at some point but I've just been idly experimenting and it doesn't (yet) work.

This is not supported and there are no plans to do so.

OK. My mistake, I thought you'd said in the past that this sort of tuple would eventually be supported.

There was the suggestion by Ryan Joseph to add support for record constructors that are similar to the variable/constant initializations. And maybe I said that this might be investigated.

MarkMLl

  • Hero Member
  • *****
  • Posts: 6646
Re: Passing parameters by name
« Reply #6 on: January 20, 2021, 01:35:14 pm »
There was the suggestion by Ryan Joseph to add support for record constructors that are similar to the variable/constant initializations. And maybe I said that this might be investigated.

Maybe. This might have been about three years ago.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

 

TinyPortal © 2005-2018