Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2017-04

Use a procedural type for declare a procedure\function

3 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Andrey M, Zubarev

Hi All,

Why can't use procedural type for declare a procedure\function?
Why ever allow the exact same signature? It's uncomfortable
Maybe it makes sense to introduce into the language such a possibility?
For example such code:
[code]
type TMyCommand=function(arg1:TMyArg):TMyCommandResult
begin
...
end;
function command1(arg1:TMyArg):TMyCommandResult;
begin
...
end;
function command2(arg1:TMyArg):TMyCommandResult;
begin
...
end;
function command100500(arg1:TMyArg):TMyCommandResult;
begin
...
end;
var
...
com:TMyCommand;
...
com:=GetNeededCommand;
res:=com(arg1:TMyArg)
[/code]

Could look like this

[code]
type TMyCommand=function(arg1:TMyArg):TMyCommandResult
begin
...
end;
command1 TMyCommand;
begin
...
end;
command2 TMyCommand;
begin
...
end;
command100500 TMyCommand;
begin
...
end;
...
var
com:TMyCommand;
..
com:=GetNeededCommand;
res:=com(arg1:TMyArg)
[/code]
Best regards, Zubarev

Reply by email

Sven Barth
to Andrey M, Zubarev
Show quoted text 6 lines
Hi All, Why can't use procedural type for declare a procedure\function? Why ever allow the exact same signature? It's uncomfortable Maybe it makes sense to introduce into the language such a possibility?

No, that makes no sense. Function/procedures/methods are independent of of function/procedure/message types, maybe even declared indifferent units not related to each other and used together only in a third unit.

Also it would be harder to see easily which parameters a routine takes as you'd need to check the corresponding type first.
(And if you now say that an IDE can help with that, well 1) not everyone uses one and 2) the same could be said about your original problem)

Regards,
Sven

Reply by email

Michael Van Canneyt
to Andrey M, Zubarev: Why can't use procedural type for declare a procedure\function? Why ever allow the exact…
Zubarev wrote 17 lines
Hi All, Why can't use procedural type for declare a procedure\function? Why ever allow the exact same signature? It's uncomfortable Maybe it makes sense to introduce into the language such a possibility? For example such code: [code] type TMyCommand=function(arg1:TMyArg):TMyCommandResult begin ... end; command1 TMyCommand; begin ... end;

You can do this already using a macro

{$define mysig:=(arg1:TMyArg):TMyCommandResult}
type TMyCommand = function mysig;
function command1 mysig;

Michael.

Reply by email