View mode: basic / threaded / horizontal-split · Log in · Help
July 06, 2007
pseudo array properties
In V2, were we meant to lose the (undocumented) facility to have pseudo
properties for arrays?

In other words, the code below compiled and ran for V1 but it doesn't for
V2.

char[] foo(char[] a) { return a; }
void main()
{
   char[] q;
   q = q.foo;  // Invoke 'foo' as if it were a property.
}


-- 
Derek
(skype: derek.j.parnell)
Melbourne, Australia
6/07/2007 11:50:31 AM
July 06, 2007
Re: pseudo array properties
That will be a serious loss.  This 'feature' was an awesome one, and a 
shame it never made it into the specs.

Derek Parnell wrote:
> In V2, were we meant to lose the (undocumented) facility to have pseudo
> properties for arrays?
> 
> In other words, the code below compiled and ran for V1 but it doesn't for
> V2.
> 
> char[] foo(char[] a) { return a; }
> void main()
> {
>     char[] q;
>     q = q.foo;  // Invoke 'foo' as if it were a property.
> }
> 
>
July 06, 2007
Re: pseudo array properties
On Fri, 6 Jul 2007 11:52:38 +1000, Derek Parnell wrote:

> In V2, were we meant to lose the (undocumented) facility to have pseudo
> properties for arrays?
> 
> In other words, the code below compiled and ran for V1 but it doesn't for
> V2.
> 
> char[] foo(char[] a) { return a; }
> void main()
> {
>     char[] q;
>     q = q.foo;  // Invoke 'foo' as if it were a property.
> }

Ok, maybe I got this wrong 'cos I can't get it to run in V1 either. Didn't
we used to be able to do this?

-- 
Derek
(skype: derek.j.parnell)
Melbourne, Australia
6/07/2007 12:17:14 PM
July 06, 2007
Re: pseudo array properties
Charlie wrote:
> That will be a serious loss.  This 'feature' was an awesome one, and a 
> shame it never made it into the specs.

Personally, I'd like to see it generalized to more than just arrays...


> 
> Derek Parnell wrote:
>> In V2, were we meant to lose the (undocumented) facility to have pseudo
>> properties for arrays?
>>
>> In other words, the code below compiled and ran for V1 but it doesn't for
>> V2.
>>
>> char[] foo(char[] a) { return a; }
>> void main()
>> {
>>     char[] q;
>>     q = q.foo;  // Invoke 'foo' as if it were a property.
>> }
>>
>>
July 06, 2007
Re: pseudo array properties
> Personally, I'd like to see it generalized to more than just arrays...

Yes me too.  I guess we now have to convice Andrei , who will in turn 
convince Walter, since Walter has been ignoring our pleads lately.

Jason House wrote:
> Charlie wrote:
>> That will be a serious loss.  This 'feature' was an awesome one, and a 
>> shame it never made it into the specs.
> 
> Personally, I'd like to see it generalized to more than just arrays...
> 
> 
>>
>> Derek Parnell wrote:
>>> In V2, were we meant to lose the (undocumented) facility to have pseudo
>>> properties for arrays?
>>>
>>> In other words, the code below compiled and ran for V1 but it doesn't 
>>> for
>>> V2.
>>>
>>> char[] foo(char[] a) { return a; }
>>> void main()
>>> {
>>>     char[] q;
>>>     q = q.foo;  // Invoke 'foo' as if it were a property.
>>> }
>>>
>>>
July 06, 2007
Re: pseudo array properties
> That will be a serious loss.  This 'feature' was an awesome one, and a 
> shame it never made it into the specs.
> 

On the contrary, it's in the specs for both 1.0 and 2.0:
http://www.digitalmars.com/d/arrays.html

See under "Functions as Array Properties"

Yes, I agree, it should be generalized to non-arrays. As I mentioned before, I love the natural feel of the Ruby-esque:

---
import tango.io.Stdout;

void times(int n, void delegate() action)
{
   for(int i = 0; i < n; i++)
       action();
}

void main
{
   3.times(
   {
       Stdout("Hello!").newline;
   });
}
---
July 06, 2007
Re: pseudo array properties
Derek Parnell skrev:
> On Fri, 6 Jul 2007 11:52:38 +1000, Derek Parnell wrote:
> 
>> In V2, were we meant to lose the (undocumented) facility to have pseudo
>> properties for arrays?
>>
>> In other words, the code below compiled and ran for V1 but it doesn't for
>> V2.
>>
>> char[] foo(char[] a) { return a; }
>> void main()
>> {
>>     char[] q;
>>     q = q.foo;  // Invoke 'foo' as if it were a property.
>> }
> 
> Ok, maybe I got this wrong 'cos I can't get it to run in V1 either. Didn't
> we used to be able to do this?

The limitation (that has always been there) is that for "pseudo 
properties", you need to call them with the trailing parentheses:

q = q.foo(); // should work

-- 
Oskar
July 06, 2007
Re: pseudo array properties
Derek Parnell wrote:
> In V2, were we meant to lose the (undocumented) facility to have pseudo
> properties for arrays?

I think this was actually added to the spec for v1.0.


Sean
July 08, 2007
Re: pseudo array properties
Charlie wrote:

>  > Personally, I'd like to see it generalized to more than just arrays...
> 
> Yes me too.  I guess we now have to convice Andrei , who will in turn
> convince Walter, since Walter has been ignoring our pleads lately.
> 

FWIW, this has been proposed before and nothing happened. For example Scala
language generalizes it in a nice way.
Top | Discussion index | About this forum | D home