inline callback functions?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

inline callback functions?

Ryan Joseph
I’m seeing feature this in other languages and it’s pretty useful. Has anyone ever considered this for Pascal?

Instead of declaring a method in the class (or other function) it’s written inline from the callers scope and inherits from that scope. The only advantage is readability since everything appears in one line and it’s cleaner since you don’t pollute the class with methods are only used in a single location and never called directly.

procedure TMyClass.FadeOut;
var
        fadeAction: TSpriteAction;
begin
        fadeAction := TAction.ActionWithDuration(self, 2.0);
        fadeAction.SetEndedAction(@
                begin
                        ... // scoped in the calling class so "self" is available
                end;
        );
        fadeAction.FadeOut;
end;

Regards,
        Ryan Joseph

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

Re: inline callback functions?

Mattias Gaertner
On Mon, 7 Aug 2017 10:52:35 -0600
Ryan Joseph <[hidden email]> wrote:

>[...]

Note that "inline" functions in FPC have a different meaning:
https://www.freepascal.org/docs-html/prog/progsu36.html

What you mean are "anonymous functions" or "closures".

State in FPC:
http://lists.freepascal.org/pipermail/fpc-devel/2016-August/037328.html

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

Re: inline callback functions?

Ryan Joseph

> On Aug 7, 2017, at 1:47 PM, Mattias Gaertner <[hidden email]> wrote:
>
> What you mean are "anonymous functions" or "closures".
>
> State in FPC:
> http://lists.freepascal.org/pipermail/fpc-devel/2016-August/037328.html

Yes, closures. Seems like development may be abandoned but it’s a good idea none the less.

Thanks.

Regards,
        Ryan Joseph

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

Re: inline callback functions?

Free Pascal - General mailing list

Am 09.08.2017 06:21 schrieb "Ryan Joseph" <[hidden email]>:
>
>
> > On Aug 7, 2017, at 1:47 PM, Mattias Gaertner <[hidden email]> wrote:
> >
> > What you mean are "anonymous functions" or "closures".
> >
> > State in FPC:
> > http://lists.freepascal.org/pipermail/fpc-devel/2016-August/037328.html
>
> Yes, closures. Seems like development may be abandoned but it’s a good idea none the less.

The development is still in progress, albeit slowly.

Regards,
Sven


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Loading...