February 01, 2008 Re: getAttr method | ||||
|---|---|---|---|---|
| ||||
Posted in reply to downs | "downs" <default_357-line@yahoo.de> wrote in message news:fnvs99$qm$1@digitalmars.com... > the following code is entirely valid D if you have scrapple.tools > installed: > auto generator = stackthread = (void delegate(int) yield) { int i; while > (true) yield(i++); }; > writefln(generator(), generator(), generator()); You should start an IODCC. Your code would win every time. | |||
February 02, 2008 Re: getAttr method | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Jarrett Billingsley | Jarrett Billingsley wrote:
> "downs" <default_357-line@yahoo.de> wrote in message news:fnvs99$qm$1@digitalmars.com...
>
>> the following code is entirely valid D if you have scrapple.tools
>> installed:
>> auto generator = stackthread = (void delegate(int) yield) { int i; while
>> (true) yield(i++); };
>> writefln(generator(), generator(), generator());
>
> You should start an IODCC. Your code would win every time.
>
>
gentoo-pc ~ $ cat test.d; rebuild test.d && echo "---------" && ./test
// sorry, I left out the indentation because I was in a hurry.
module test;
import tools.stackthreads, std.stdio;
void main()
{
auto generator = stackthread = (void delegate(int) yield)
{
int i;
while (true)
{
yield(i);
i++;
}
};
writefln([generator(), generator(), generator()]);
}
// better? :)
// --downs
---------
[0,1,2]
gentoo-pc ~ $
| |||
February 02, 2008 Re: getAttr method | ||||
|---|---|---|---|---|
| ||||
Posted in reply to downs | "downs" <default_357-line@yahoo.de> wrote in message news:fo0i97$1cla$1@digitalmars.com... > auto generator = stackthread = (void delegate(int) yield) ... In this code, I'm mostly concerned with your (ab)use of the property syntax to call functions which aren't properties. This looks like assignment, but sure as heck doesn't have the semantics thereof. You do realize that writing obtuse, unreadable code is not something to be proud of? | |||
February 02, 2008 Re: getAttr method | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Jarrett Billingsley | Jarrett Billingsley wrote:
> "downs" <default_357-line@yahoo.de> wrote in message news:fo0i97$1cla$1@digitalmars.com...
>
>> auto generator = stackthread = (void delegate(int) yield) ...
>
> In this code, I'm mostly concerned with your (ab)use of the property syntax to call functions which aren't properties. This looks like assignment, but sure as heck doesn't have the semantics thereof.
>
> You do realize that writing obtuse, unreadable code is not something to be proud of?
It is creative and clever. You can be proud of an unusual ability to write such code, but not if you are incapable of writing readable code.
| |||
February 02, 2008 Re: getAttr method | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Jarrett Billingsley | Jarrett Billingsley wrote:
> "downs" <default_357-line@yahoo.de> wrote in message news:fo0i97$1cla$1@digitalmars.com...
>
>> auto generator = stackthread = (void delegate(int) yield) ...
>
> In this code, I'm mostly concerned with your (ab)use of the property syntax to call functions which aren't properties. This looks like assignment, but sure as heck doesn't have the semantics thereof.
>
> You do realize that writing obtuse, unreadable code is not something to be proud of?
>
>
Actually, joke's on you - that actually is opAssign. Static opAssign. stackthread is a struct. :p
You're right about the semantics though. The problem is that I don't want to use a function call, because it requires you to place a closing paren far, far away at the other end of the delegate literal, and it is my firm conviction that }); looks butt ugly and should die.
So, if you can recommend a better operator than opAssign, one with better semantics, I'm all ears. :)
--downs
| |||
February 02, 2008 Re: getAttr method | ||||
|---|---|---|---|---|
| ||||
Posted in reply to downs | downs wrote:
> Jarrett Billingsley wrote:
>> "downs" <default_357-line@yahoo.de> wrote in message news:fo0i97$1cla$1@digitalmars.com...
>>
>>> auto generator = stackthread = (void delegate(int) yield) ...
>> In this code, I'm mostly concerned with your (ab)use of the property syntax to call functions which aren't properties. This looks like assignment, but sure as heck doesn't have the semantics thereof.
>>
>> You do realize that writing obtuse, unreadable code is not something to be proud of?
>>
>>
>
> Actually, joke's on you - that actually is opAssign. Static opAssign. stackthread is a struct. :p
>
> You're right about the semantics though. The problem is that I don't want to use a function call, because it requires you to place a closing paren far, far away at the other end of the delegate literal, and it is my firm conviction that }); looks butt ugly and should die.
> So, if you can recommend a better operator than opAssign, one with better semantics, I'm all ears. :)
>
> --downs
Oh, and note that if we had trailing delegate syntax, we could use the far superior "auto generator = stackthread (void delegate(int) yield) { };" :)
--downs, PS
| |||
February 02, 2008 Re: getAttr method | ||||
|---|---|---|---|---|
| ||||
Posted in reply to downs | On 2/2/08, downs <default_357-line@yahoo.de> wrote:
> > So, if you can recommend a better operator than opAssign, one with better semantics, I'm all ears. :)
The only thing that comes to mind is member assignment. e.g.
stackthread.dg = { ... };
instead of
stackthread = { ... };
You still get the braces at the end, and it's clear you're assigning a property of stackthread, rather than overwriting its entire value. (It is more typing though).
| |||
February 02, 2008 Re: getAttr method | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Janice Caron | Janice Caron wrote:
> On 2/2/08, downs <default_357-line@yahoo.de> wrote:
>>> So, if you can recommend a better operator than opAssign, one with better semantics, I'm all ears. :)
>
> The only thing that comes to mind is member assignment. e.g.
>
> stackthread.dg = { ... };
>
> instead of
>
> stackthread = { ... };
>
> You still get the braces at the end, and it's clear you're assigning a property of stackthread, rather than overwriting its entire value. (It is more typing though).
I'm not though. Semantically, I'm creating a new StackThread from a delegate. ^^
I wish we could overload arbitrary keywords. "stackthread of " or "stackthread from " would be perfect.
I'm tending towards either "stackthread/ (void delegate(int) yield) { " (in keeping with the rest of my syntax), or "stacthread ~ (void delegate(int", because ~ is less semantically burdened. Or, you know, keeping "=" :)
The best thing is probably to not read it as "assign to stackthread", but as "auto generator [= stackthread] [= (void delegate(int) yield) { ... }];" i.e. assign to generator a stackthread; assign to generator this delegate; meaning "assign to generator this delegate which is also a stackthread." :)
--downs
| |||
February 08, 2008 Re: getAttr method | ||||
|---|---|---|---|---|
| ||||
Posted in reply to downs |
On Sat, 2 Feb 2008, downs wrote:
> Jarrett Billingsley wrote:
>> "downs" <default_357-line@yahoo.de> wrote in message
>> news:fnvs99$qm$1@digitalmars.com...
>>
>>> the following code is entirely valid D if you have scrapple.tools
>>> installed:
>>> auto generator = stackthread = (void delegate(int) yield) { int i; while
>>> (true) yield(i++); };
>>> writefln(generator(), generator(), generator());
>>
>> You should start an IODCC. Your code would win every time.
>>
>>
>
> gentoo-pc ~ $ cat test.d; rebuild test.d && echo "---------" && ./test
> // sorry, I left out the indentation because I was in a hurry.
> module test;
> import tools.stackthreads, std.stdio;
>
> void main()
> {
> auto generator = stackthread = (void delegate(int) yield)
> {
> int i;
>
> while (true)
> {
> yield(i);
> i++;
> }
> };
>
> writefln([generator(), generator(), generator()]);
> }
>
> // better? :)
> // --downs
> ---------
> [0,1,2]
> gentoo-pc ~ $
Lazy lists would be much cleaner:
l = [0,1..]
Start = take 3 l // => [0,1,2]
Of course stackthreads have their use too.
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply