Re: [fpc-pascal] Re: Delphi's anonymous functions in Free Pascal

2011-11-05 Thread Bernd
2011/10/25  :

>> targethread.queue(
>>  procedure(targetobject:ttargetobject;a:integer;b:someobject;c:string)
>>             begin
>>               targetobject.destinationprocedure(a,b,c);
>>             end;
>>
>> Note how common this looks compared to the original.
>
> One point is that you could do the above with a local (and named) procedure
> as well, and still have all the context. At the very least you would not be
> raping pascal's readability by putting a
> complete procedure declaration inside a code block.

How would you preserve the context without finding some place
somewhere (on the heap) to store the current values of a, b, and c?


The natural alternative to a closure if you don't have them in an OO
language is instead of passing a closure you pass an object (this
pattern is called Functor). The object contains the function along
with some state. Of course in a static language this involves a lot of
boiler plate to define the needed classes with their methods (one
class definition for every different closure) but once you have done
this you can use it like the closure in the above example and its
usage is totally readable:

targetthread.queue(TMyFunctor.Create(targetobject, a, b, c));
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Re: Delphi's anonymous functions in Free Pascal

2011-11-05 Thread Bernd
2011/10/25 Marco van de Voort :
> Equivalent solution with anon functions:
>
> targethread.queue(
>   procedure(targetobject:ttargetobject;a:integer;b:someobject;c:string)
>              begin
>                targetobject.destinationprocedure(a,b,c);
>              end;

shouldn't this be

targethread.queue(
  procedure
 begin
   targetobject.destinationprocedure(a,b,c);
 end;

without any parameters since all these variables are captured from the
current scope into the closure? The other thread should not need to
know anything about them to call it.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Re: Delphi's anonymous functions in Free Pascal

2011-11-05 Thread Marco van de Voort
In our previous episode, Bernd said:
> > Equivalent solution with anon functions:
> >
> > targethread.queue(
> > ? procedure(targetobject:ttargetobject;a:integer;b:someobject;c:string)
> > ? ? ? ? ? ? ?begin
> > ? ? ? ? ? ? ? ?targetobject.destinationprocedure(a,b,c);
> > ? ? ? ? ? ? ?end;
> 
> shouldn't this be
> 
> targethread.queue(
>   procedure
>  begin
>targetobject.destinationprocedure(a,b,c);
>  end;
> 
> without any parameters since all these variables are captured from the
> current scope into the closure? The other thread should not need to
> know anything about them to call it.

Afaik you are right. Delphi also allowed the other form, but I thought the
syntax would force immediately evaluation of the parameters (and thus only
the parameters be stored in case any of a ,b or c are expressions, not all
parts of the expressions).

But indeed then the other side also has to call it with parameters, and in
this example that defeats the purpose.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Re: Delphi's anonymous functions in Free Pascal

2011-11-05 Thread Alexander Shishkin

05.11.2011 22:42, Bernd пишет:

2011/10/25:


targethread.queue(
  procedure(targetobject:ttargetobject;a:integer;b:someobject;c:string)
 begin
   targetobject.destinationprocedure(a,b,c);
 end;

Note how common this looks compared to the original.


One point is that you could do the above with a local (and named) procedure
as well, and still have all the context. At the very least you would not be
raping pascal's readability by putting a
complete procedure declaration inside a code block.


How would you preserve the context without finding some place
somewhere (on the heap) to store the current values of a, b, and c?


The natural alternative to a closure if you don't have them in an OO
language is instead of passing a closure you pass an object (this
pattern is called Functor). The object contains the function along
with some state. Of course in a static language this involves a lot of
boiler plate to define the needed classes with their methods (one
class definition for every different closure) but once you have done
this you can use it like the closure in the above example and its
usage is totally readable:

targetthread.queue(TMyFunctor.Create(targetobject, a, b, c));
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


But modern trend is to add closures into OO languages, because code 
become more laconic.

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Re: Delphi's anonymous functions in Free Pascal

2011-11-05 Thread Michael Van Canneyt



On Sat, 5 Nov 2011, Bernd wrote:


2011/10/25  :


targethread.queue(
 procedure(targetobject:ttargetobject;a:integer;b:someobject;c:string)
            begin
              targetobject.destinationprocedure(a,b,c);
            end;

Note how common this looks compared to the original.


One point is that you could do the above with a local (and named) procedure
as well, and still have all the context. At the very least you would not be
raping pascal's readability by putting a
complete procedure declaration inside a code block.


How would you preserve the context without finding some place
somewhere (on the heap) to store the current values of a, b, and c?



Procedure SomeOuter;

Var
  d,e,f : SomeType;

  Procedure 
SomeInner(targetobject:ttargetobject;a:integer;b:someobject;c:string)
  begin
     targetobject.destinationprocedure(a,b,c);
  end;

begin
  Targethread.queue(@SomeInner(aobject,d,e,f));
end;

No difference with 'closure', except more readable.

Michael.___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Re: Delphi's anonymous functions in Free Pascal

2011-11-05 Thread Alexander Shishkin

06.11.2011 1:46, Michael Van Canneyt пишет:



On Sat, 5 Nov 2011, Bernd wrote:


2011/10/25 :


targethread.queue(
 procedure(targetobject:ttargetobject;a:integer;b:someobject;c:string)
begin
  targetobject.destinationprocedure(a,b,c);
end;

Note how common this looks compared to the original.


One point is that you could do the above with a local (and named)
procedure
as well, and still have all the context. At the very least you would
not be
raping pascal's readability by putting a
complete procedure declaration inside a code block.


How would you preserve the context without finding some place
somewhere (on the heap) to store the current values of a, b, and c?



Procedure SomeOuter;

Var
d,e,f : SomeType;

Procedure
SomeInner(targetobject:ttargetobject;a:integer;b:someobject;c:string)
   begin
 targetobject.destinationprocedure(a,b,c);
   end;

begin
Targethread.queue(@SomeInner(aobject,d,e,f));
end;

No difference with 'closure', except more readable.

Michael.


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Closures can be returned as a function result but nested procedure not 
(more strictly, this can be complied but will not work because of 
lifetime of nested procedure).

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Re: Delphi's anonymous functions in Free Pascal

2011-11-05 Thread Bernd
2011/11/5 Michael Van Canneyt :
> Procedure SomeOuter;
>
> Var
>  d,e,f : SomeType;
>
>  Procedure
> SomeInner(targetobject:ttargetobject;a:integer;b:someobject;c:string)
>   begin
>      targetobject.destinationprocedure(a,b,c);
>   end;
>
> begin
>  Targethread.queue(@SomeInner(aobject,d,e,f));
> end;
>
> No difference with 'closure', except more readable.
>
> Michael.

I doubt that this would even compile. Also As I pointed out already
the example was wrong, the procedure does not have any arguments, the
closure must be "closed over" these variables.

and this:

begin
  Targethread.queue(@SomeInner);
end;

would compile but it would just pass the procedure variable. This is
not a closure. How is the other thread supposed to know the values of
the variables that existed only in the scope of SomeOuter?

A closure would be something like this:

Procedure SomeOuter;
Var
  d,e,f : SomeType;

  Procedure SomeInner
  begin
targetobject.destinationprocedure(a,b,c);
  end;

begin
  Targethread.queue(SomeInner);
end;

The compiler would need to create an object on the heap containing the
procedure *along* with the needed variables a,b,c and then pass the
entire object. The receiving side could then call this method and it
would still have access to these variables.

A closure has enclosed variables from the surrounding scope where it
was created, hence the name 'closure'. You cannot do this with a
procedure variable alone, you need an object on the heap to contain
the enclosed variables. The Delphi compiler will behind the scenes
create a reference counted object with an 'invoke' method (the
procedure SomeInner) and all its needed variables.

It is basically a syntactic shortcut to explicitly defining this
class, and creating an instance of it.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


[fpc-pascal] Free Pascal 2.6.0rc1 released

2011-11-05 Thread Marco van de Voort
Hello,

We have placed the first release-candidate of the Free Pascal Compiler
version 2.6.0 on our ftp-servers.

You can help improve the upcoming 2.6.0 release by downloading and
testing this release. If you want you can report what you have done here:
http://wiki.freepascal.org/Testers_2.6.0

Changes that may break backwards compatibility are documented at:
http://wiki.freepascal.org/User_Changes_2.6.0

Downloads are available at the FTP server at:

ftp://freepascal.stack.nl/pub/fpc/beta/2.6.0-rc1/

Enjoy!

The Free Pascal Compiler Team


Free Pascal Compiler

Version 2.6.0rc1

**
  What's New in 2.6.0rc1
**

Free Pascal 2.6.0 is a new major version of the Free Pascal compiler.

Please also see http://wiki.freepascal.org/User_Changes_2.6.0 for a list
of changes that may affect the behaviour of previously working code, and
how to cope with these changes.

Some highlights are:

Platforms:
  * iPhoneSimulator target

Compiler:
  * Many new language features:
 * Objective-Pascal dialect, supported on all Mac OS X and iOS targets
 * constref parameter modifier for "const by reference"
 * Pascal boolean types with multiple sizes (boolean16/32/64)
 * ISO 7185 language mode (except for I/O). Features amongst others:
* nested procedure variables
* non-local goto's
 * Mac Pascal mode improvements
* nested procedure variables
* univ modifier
 * Intrinsics
* sar (shift arithmetic right)
* bsf/bsr (bitscan forward/reverse)
 * Delphi compatibility mode improvements
* Nested types, class variables and class local constants
* Advanced records syntax (no constructors yet)
* (for..in) Enumerators in records
* Class and record helpers
* Generic records, arrays and procedural types
* Delphi-compatibility of generics improved
* Scoped enumerations
* Custom messages for "deprecated" directive
* Ability to use "&" for escaping keywords
  * New ARM code generator features
 * ARM VFPv2 and VFPv3 floating point unit support
 * Thumb-2 support

Packages:
  * Many improvements to the rtl
  * Many improvements to the database units (fcl-db)
  * Objective-Pascal interfaces to Foundation, AppKit, CoreData and WebCore
  * OpenGL headers updated to OpenGL 4.0
  
Details about these new features can be found at
http://wiki.freepascal.org/FPC_New_Features_2.6.0

See http://bugs.freepascal.org/changelog_page.php for the list of reported
bugs that have been fixed in this release.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Free Pascal 2.6.0rc1 released

2011-11-05 Thread Luiz Americo Pereira Camara

On 5/11/2011 20:27, Marco van de Voort wrote:

Downloads are available at the FTP server at:

ftp://freepascal.stack.nl/pub/fpc/beta/2.6.0-rc1/


Cant download

550 /pub/fpc/beta/2.6.0-rc1/: Permission denied.


Luiz
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Free Pascal 2.6.0rc1 released

2011-11-05 Thread silvioprog
2011/11/5 Luiz Americo Pereira Camara :
> On 5/11/2011 20:27, Marco van de Voort wrote:
>>
>> Downloads are available at the FTP server at:
>>
>> ftp://freepascal.stack.nl/pub/fpc/beta/2.6.0-rc1/
>
> Cant download
>
> 550 /pub/fpc/beta/2.6.0-rc1/: Permission denied.
>
> Luiz

x(

http://imagebin.org/182703

-- 
Silvio Clécio
===
Blog - 
Twitter - 
Facebook - 
LazSolutions - 
Lazarus-BR - 
===
   * Conheça nosso canal IRC sobre Lazarus: #lazarus-br *
===
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Free Pascal 2.6.0rc1 released

2011-11-05 Thread Ralf A. Quint

At 04:47 PM 11/5/2011, Luiz Americo Pereira Camara wrote:

On 5/11/2011 20:27, Marco van de Voort wrote:

Downloads are available at the FTP server at:

ftp://freepascal.stack.nl/pub/fpc/beta/2.6.0-rc1/


Cant download

550 /pub/fpc/beta/2.6.0-rc1/: Permission denied.


ditto... :-(

Ralf 


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Free Pascal 2.6.0rc1 released

2011-11-05 Thread Alexander Shishkin

06.11.2011 3:47, Luiz Americo Pereira Camara пишет:

On 5/11/2011 20:27, Marco van de Voort wrote:

Downloads are available at the FTP server at:

ftp://freepascal.stack.nl/pub/fpc/beta/2.6.0-rc1/


Cant download

550 /pub/fpc/beta/2.6.0-rc1/: Permission denied.


Luiz
___
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal



ftp://ftp.freepascal.org/pub/fpc/beta/2.6.0-rc1/
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Re: Delphi's anonymous functions in Free Pascal

2011-11-05 Thread Michael Van Canneyt



On Sat, 5 Nov 2011, Bernd wrote:



A closure has enclosed variables from the surrounding scope where it
was created, hence the name 'closure'. You cannot do this with a
procedure variable alone, you need an object on the heap to contain
the enclosed variables. The Delphi compiler will behind the scenes
create a reference counted object with an 'invoke' method (the
procedure SomeInner) and all its needed variables.

It is basically a syntactic shortcut to explicitly defining this
class, and creating an instance of it.


I understand all that. That's not the issue.

I didn't mean to say that my example will work with the compiler NOW.
Obviously, it would need some extension of the compiler to implement closures.

The only thing I am arguing is that the syntax could have been more clear.
Definining a function inside code (or as an argument to another function)
is just not Pascal; It goes against everything Pascal stands for.

You could perfectly explicitly declare the closure function outside the code block 
it is used in, as long as it is AFTER the variables it would need from the 
outer scope. That is what I wanted to show with my snippet of code. Probably 
you'd need some kind of extra keyword to distinguish it from 'normal' nested functions.


I am not against closure functionality, although I highly doubt it is *that* 
useful as some people make it out to be. Even so, I use it in my Javascript 
programming.


But in Pascal, I would like to see it implemented in a way that doesn't go 
against Pascal philosophy. In that regard, I consider the way that
Borland/CodeGear/Embarcadero implemented it a monstrosity. 
It simply hurts the eyes...


Michael.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


[fpc-pascal] Re: Free Pascal 2.6.0rc1 released

2011-11-05 Thread Seth Grover
> We have placed the first release-candidate of the Free Pascal Compiler
> version 2.6.0 on our ftp-servers.

Congratulations! That's an impressive list of new features. I've been
anticipating this release for some time.

A couple of questions: where can this be found in svn? I don't see a
tag for it, and fixes_2_6 hasn't been modified for 8 weeks or so.

Secondly, will there be additional merges from trunk to fixes_2_6? If
I recall the last time I checked the page with the list of potential
merges from trunk to fixes_2_6 I believe it was quite long.
Particularly I was hoping for revision 19036 (resolving issue 19404,
fixing shared library loading and unloading for Linux platforms) to
make it into the 2.6 release.

Again, congratulations. I'll start using the release candidate next
week at work and will report any issues I find.

-SG

--
This email is fiction. Any resemblance to actual events
or persons living or dead is purely coincidental.

Seth Grover
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Re: Free Pascal 2.6.0rc1 released

2011-11-05 Thread Jonas Maebe

On 06 Nov 2011, at 02:32, Seth Grover wrote:

> A couple of questions: where can this be found in svn? I don't see a
> tag for it, and fixes_2_6 hasn't been modified for 8 weeks or so.

http://svn.freepascal.org/svn/fpc/tags/release_2_6_0_rc1/


Jonas
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


[fpc-pascal] Re: Free Pascal 2.6.0rc1 released

2011-11-05 Thread Seth Grover
Jonas, thanks for the link. For some reason it wasn't showing up on
the viewvcs interface until I cleared my browser cache and refreshed.

Thanks again.

-SG

--
This email is fiction. Any resemblance to actual events
or persons living or dead is purely coincidental.

Seth Grover
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal