Use a procedural type for declare a procedure\function

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Use a procedural type for declare a procedure\function

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                          mailto:[hidden email]

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Use a procedural type for declare a procedure\function

Free Pascal - General mailing list

Am 20.04.2017 08:44 schrieb "Andrey M, Zubarev" <[hidden email]>:
>
> 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


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Use a procedural type for declare a procedure\function

Michael Van Canneyt
In reply to this post by Andrey M, Zubarev


On Wed, 19 Apr 2017, Andrey M, Zubarev wrote:

> 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.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal