[fpc-devel] RFC: Support for new type "tuple" v0.1
Michael Van Canneyt
michael at freepascal.org
Sun Jan 27 16:59:18 CET 2013
On Mon, 28 Jan 2013, Alexander Klenin wrote:
> On Mon, Jan 28, 2013 at 1:26 AM, Paul Ishenin <paul.ishenin at gmail.com> wrote:
>> 27.01.13, 1:43, Sven Barth wrote:
>>>
>>> Based on the results of the "for-in-index" thread I've decided to come
>>> up with a draft for the Tuple type which is thought by many people to be
>>> a better alternative to "for-in-index".
>> I think it is big overkill to implement a new base type for such a small
>> task as returning a key in for-in loop.
> Of course. But note that in this thread, many more uses of tuples
> (which I do NOT want to make a type -- see my previous mail for
> lengthy explanation why).
> Some of the uses are: record and array constructors, adaptation of
> inconvenient signatures,
> better support for "return code" style of error handling, etc.
>
>> And (for Michael) I don't see any beauty in this. Imo, initial index
>> extension is much more beauty than suggested here (a,b,c) := d;
>> constructions.
> I have a compromise suggestion:
> Implement for-index extension with the syntax:
> for (k, v) in a do
> this syntax is forward-compatible with both tuples proposals,
> is simple to do (basically, already done -- only a small change in
> parsing is required)
what concerns syntax, I have no problem with this.
What bothers me immensely is the same what bothered me in the totally braindead
Delphi implementation of the "for in" loop : the bunch of requirements
you put on the iterator implementation: an interface with special status.
You can't get more stupid and ugly than that.
I would gladly kill the borland/inprise/embarcadero engineer who
thought of this, after torturing him for 3 days, just for unleashing
this monstrosity on the world...
[Disclaimer: the above is humor. Just trying to show how bad I think it is]
Your initial proposal makes it even worse by adding more conditions to the interface,
it would not even be an interface any more.
So: No, no, no. It is ugly beyond words.
That is why I think you need a proper "tuple" value to solve this.
it gives a more fundamental solution: the loop variable type equals
the type returned by the iterator/enumerator. No messing with index
(bad syntax) and even worse: special 'interfaces' and whatnot.
Pascal is a strongly typed language. So, if we absolutely must solve this:
introduce a proper type. A tuple fits the job.
Michael.
More information about the fpc-devel
mailing list