Jump to page: 1 212  
Page
Thread overview
Stupid little iota of an idea
Feb 09, 2011
Nick Sabalausky
Feb 09, 2011
Peter Alexander
Feb 09, 2011
bearophile
Feb 09, 2011
%u
Feb 09, 2011
bearophile
Feb 09, 2011
%u
Feb 09, 2011
spir
Feb 09, 2011
Nick Sabalausky
Feb 09, 2011
bearophile
Feb 09, 2011
Daniel Gibson
Feb 09, 2011
bearophile
Feb 09, 2011
Daniel Gibson
Feb 10, 2011
spir
Feb 09, 2011
Ary Manzana
Feb 09, 2011
Daniel Gibson
Feb 10, 2011
spir
Feb 10, 2011
Jacob Carlborg
Feb 09, 2011
Jérôme M. Berger
Feb 10, 2011
Olivier Pisano
Feb 10, 2011
spir
Feb 10, 2011
Max Samukha
Feb 10, 2011
spir
Feb 10, 2011
Jérôme M. Berger
Feb 10, 2011
Sean Kelly
Feb 11, 2011
Nick Sabalausky
Feb 11, 2011
Jonathan M Davis
Feb 11, 2011
Andrej Mitrovic
Feb 11, 2011
spir
Feb 11, 2011
Jacob Carlborg
Feb 10, 2011
Ary Manzana
Feb 11, 2011
Nick Sabalausky
Feb 11, 2011
spir
Feb 11, 2011
so
Feb 11, 2011
Andrej Mitrovic
Feb 11, 2011
Nick Sabalausky
Feb 11, 2011
Andrej Mitrovic
Feb 11, 2011
Nick Sabalausky
Feb 11, 2011
Jacob Carlborg
Feb 11, 2011
Ary Manzana
Feb 11, 2011
Nick Sabalausky
Feb 11, 2011
Nick Sabalausky
Feb 11, 2011
bearophile
Feb 11, 2011
Andrej Mitrovic
Feb 11, 2011
bearophile
Feb 11, 2011
Nick Sabalausky
Feb 18, 2011
Don
Feb 18, 2011
Simen kjaeraas
Feb 20, 2011
Nick Sabalausky
Feb 20, 2011
Justin Bogner
Feb 10, 2011
spir
Feb 11, 2011
Daniel Gibson
Feb 11, 2011
spir
Feb 11, 2011
bearophile
Feb 11, 2011
Jim
Feb 11, 2011
bearophile
Feb 12, 2011
Brad Roberts
Feb 09, 2011
spir
Feb 09, 2011
Nick Sabalausky
Feb 09, 2011
spir
Feb 12, 2011
Michel Fortin
Feb 12, 2011
bearophile
Feb 12, 2011
Daniel Gibson
Feb 12, 2011
spir
Feb 12, 2011
Daniel Gibson
Feb 12, 2011
spir
Feb 12, 2011
Jacob Carlborg
Feb 12, 2011
bearophile
Feb 12, 2011
Jacob Carlborg
Feb 13, 2011
Nick Sabalausky
Feb 12, 2011
Jonathan M Davis
Feb 12, 2011
bearophile
Feb 12, 2011
spir
Feb 12, 2011
bearophile
Feb 12, 2011
spir
Feb 12, 2011
spir
Feb 12, 2011
Jonathan M Davis
Feb 12, 2011
bearophile
Feb 12, 2011
Andrej Mitrovic
Feb 12, 2011
Jonathan M Davis
Feb 12, 2011
Max Samukha
Feb 12, 2011
retard
Feb 12, 2011
Max Samukha
Feb 12, 2011
retard
Feb 13, 2011
so
Feb 13, 2011
retard
Feb 12, 2011
Jonathan M Davis
Feb 12, 2011
Jérôme M. Berger
Feb 12, 2011
spir
Feb 12, 2011
Jérôme M. Berger
Feb 12, 2011
spir
Feb 12, 2011
Jonathan M Davis
Feb 12, 2011
Jérôme M. Berger
Feb 12, 2011
Jeff Nowakowski
Feb 12, 2011
Jonathan M Davis
Feb 12, 2011
Jérôme M. Berger
Feb 12, 2011
Jonathan M Davis
Feb 12, 2011
Jérôme M. Berger
Feb 12, 2011
spir
February 09, 2011
AUIU, foreach has both of these forms:

    foreach(x; 0..5)
    foreach(x; someRange)

Also, we have:

    auto someRange = iota(0, 5);

Little idea: How about this genralized lowering?

    0..5
    // iota says "Gimme some sugar, baby."
    // and thus it is lowered to ->
    iota(0, 5)

Of course, if that hinders optimization for foreach(x; 0..5), then the compiler could just "optimize" that particular case by not bothering with the lowering and doing as it currently does.

But the benefit is things like this:

    // Stealing Andrei's "filter even" example:
    filter!`a % 2 == 0`(iota(1, 5))
    // Give iota some sugar, baby:
    filter!`a % 2 == 0`(1..5)

I suppose the obnoxious float-literal definition could get in the way, but when is it ever legal syntax in D to have two numeric literals next to each other? (And foreach seems ok with it anyway)

Pardon if this has already been suggested.



February 09, 2011
On 9/02/11 3:08 AM, Nick Sabalausky wrote:
> AUIU, foreach has both of these forms:
>
>      foreach(x; 0..5)
>      foreach(x; someRange)
>
> Also, we have:
>
>      auto someRange = iota(0, 5);
>
> <snip>
> Pardon if this has already been suggested.

I have suggested it in the past, and I believe people had suggested it before me. I agree, it does make perfect sense to add that syntax, although it probably shouldn't be tied into Phobos (maybe add a druntime version of iota?)
February 09, 2011
Nick Sabalausky:

> AUIU, foreach has both of these forms:

D is currently very not-orthogonal.

I have added the enhancement request time ago: http://d.puremagic.com/issues/show_bug.cgi?id=5395 http://d.puremagic.com/issues/show_bug.cgi?id=4112

Bye,
bearophile
February 09, 2011
== Quote from bearophile (bearophileHUGS@lycos.com)'s article
> D is currently very not-orthogonal.

I think you might the person to ask this:
I've seen the concept of orthogonality pop up more and more and it was especially
prominent in the awkward Go vs D reddit discussion, can you maybe explain what it
exactly means?
And, also how it relates to your enhancement?

> I have added the enhancement request time ago:
> http://d.puremagic.com/issues/show_bug.cgi?id=5395
> http://d.puremagic.com/issues/show_bug.cgi?id=4112
> Bye,
> bearophile


February 09, 2011
%u:

> can you maybe explain what it exactly means?
> And, also how it relates to your enhancement?

In programming languages it means features that have fully separated purposes, that can be combined together in clean and safe ways to create more complex functionalities. Combining in "clean and safe ways" means they don't have unwanted interactions, their lower level nature is sufficiently encapsulated and doesn't leak out too much, so their sub-systems are mostly sealed, if you want to see it with systems theory ideas.

In the current discussion foreach(i;iota(5)) and foreach(i;0..5) are usable for the same purpose, so those two "features" don't have fully separated purposes. On the other hand you can't use 0..5 where you want a lazy range:
auto r = 0 .. 5;
You need to us iota:
auto r = iota(0, 5);
So the 0..5 can't be combined to many other language functionalities to produce something bigger.
This is why several people have asked for a more orthogonal interval syntax in D.

Bye,
bearophile
February 09, 2011
== Quote from bearophile (bearophileHUGS@lycos.com)'s article
> %u:
> > can you maybe explain what it exactly means?
> > And, also how it relates to your enhancement?
> In programming languages it means features that have fully separated purposes,
that can be combined together in clean and safe ways to create more complex functionalities. Combining in "clean and safe ways" means they don't have unwanted interactions, their lower level nature is sufficiently encapsulated and doesn't leak out too much, so their sub-systems are mostly sealed, if you want to see it with systems theory ideas.
> In the current discussion foreach(i;iota(5)) and foreach(i;0..5) are usable for
the same purpose, so those two "features" don't have fully separated purposes. On the other hand you can't use 0..5 where you want a lazy range:
> auto r = 0 .. 5;
> You need to us iota:
> auto r = iota(0, 5);
> So the 0..5 can't be combined to many other language functionalities to produce
something bigger.
> This is why several people have asked for a more orthogonal interval syntax in D.
> Bye,
> bearophile

Thanks!!

int[3] arr = [0..5:2];
February 09, 2011
On 02/09/2011 04:08 AM, Nick Sabalausky wrote:
> AUIU, foreach has both of these forms:
>
>      foreach(x; 0..5)
>      foreach(x; someRange)
>
> Also, we have:
>
>      auto someRange = iota(0, 5);
>
> Little idea: How about this genralized lowering?
>
>      0..5
>      // iota says "Gimme some sugar, baby."
>      // and thus it is lowered to ->
>      iota(0, 5)
>
> Of course, if that hinders optimization for foreach(x; 0..5), then the
> compiler could just "optimize" that particular case by not bothering with
> the lowering and doing as it currently does.
>
> But the benefit is things like this:
>
>      // Stealing Andrei's "filter even" example:
>      filter!`a % 2 == 0`(iota(1, 5))
>      // Give iota some sugar, baby:
>      filter!`a % 2 == 0`(1..5)
>
> I suppose the obnoxious float-literal definition could get in the way, but
> when is it ever legal syntax in D to have two numeric literals next to each
> other? (And foreach seems ok with it anyway)
>
> Pardon if this has already been suggested.

I like this. Maybe a slightly different approach would be for both 1..5 and iota(1,5) to be expressions for a simple and range-semantic-compatible struct-like thingy. Then, actually, iota would be superfluous, but some may still like it syntactically or semantically (because Iota is explicitely defined as a range type).
Side-question: what is actually 1..5 as of now for a thing? Or is it conceptually "unconstructed" by rewriting to (probably) an ordinary for loop? Anyway, the point above applies to language-side semantics, whatever optimisation may happen.

Denis
-- 
_________________
vita es estrany
spir.wikidot.com

February 09, 2011
On 02/09/2011 04:08 AM, Nick Sabalausky wrote:
> AUIU, foreach has both of these forms:
>
>      foreach(x; 0..5)
>      foreach(x; someRange)
>
> Also, we have:
>
>      auto someRange = iota(0, 5);
>
> Little idea: How about this genralized lowering?
>
>      0..5
>      // iota says "Gimme some sugar, baby."
>      // and thus it is lowered to ->
>      iota(0, 5)
>
> Of course, if that hinders optimization for foreach(x; 0..5), then the
> compiler could just "optimize" that particular case by not bothering with
> the lowering and doing as it currently does.
>
> But the benefit is things like this:
>
>      // Stealing Andrei's "filter even" example:
>      filter!`a % 2 == 0`(iota(1, 5))
>      // Give iota some sugar, baby:
>      filter!`a % 2 == 0`(1..5)
>
> I suppose the obnoxious float-literal definition could get in the way, but
> when is it ever legal syntax in D to have two numeric literals next to each
> other? (And foreach seems ok with it anyway)
>
> Pardon if this has already been suggested.

PS: your proposal would also logically allow, I guess, expressions like (n in min..max). Would love it.

Denis
-- 
_________________
vita es estrany
spir.wikidot.com

February 09, 2011
"spir" <denis.spir@gmail.com> wrote in message news:mailman.1422.1297254724.4748.digitalmars-d@puremagic.com...
>
> Side-question: what is actually 1..5 as of now for a thing? Or is it conceptually "unconstructed" by rewriting to (probably) an ordinary for loop? Anyway, the point above applies to language-side semantics, whatever optimisation may happen.
>

AIUI: Syntactically, it doesn't exist at all, at least not by itself. It's just part of one of the foreach syntaxes:

  'foreach' '(' {declaration list} ';' {expression} '..' {expression} ')'

and also part of one of the slice syntaxes:

  (from the docs:)
  PostfixExpression [ AssignExpression .. AssignExpression ]

Although it's possible I've understood it wrong.

Don't have a clue how it's handled beyond that though.


February 09, 2011
"spir" <denis.spir@gmail.com> wrote in message news:mailman.1423.1297254917.4748.digitalmars-d@puremagic.com...
>
> PS: your proposal would also logically allow, I guess, expressions like (n in min..max). Would love it.
>

Unfortunately, not unless "in" was changed to allow "{expr} in {range}". And from prior discussions of "in", I seem to remember Walter and Andrei are strongly against allowing "in" to be used to check for element values rather than just AA keys.

But Andrei did recently propose an "any", IIRC, that would allow something like what you're suggesting.


« First   ‹ Prev
1 2 3 4 5 6 7 8 9 10 11