Re: Tuple assignment

2015-05-11 Thread Jacob Carlborg via Digitalmars-d
On 2015-05-10 10:14, Oren Tirosh wrote: I think it should work for any two structs as long their fields are public and individually assignment-compatible. Just for the record, "tupleof" bypasses protection. -- /Jacob Carlborg

Re: Tuple assignment

2015-05-10 Thread Walter Bright via Digitalmars-d
On 5/10/2015 1:18 AM, Russel Winder via Digitalmars-d wrote: Using LDC, the tuple version generates more code unoptimized, but with optimization, the exact same assembly language code is generated for the two cases. Win. This is what makes D's ranges+algorithms so attractive. They are easier t

Re: Tuple assignment

2015-05-10 Thread Iain Buclaw via Digitalmars-d
On 10 May 2015 at 21:41, John Colvin via Digitalmars-d wrote: > On Sunday, 10 May 2015 at 08:07:38 UTC, Russel Winder wrote: >> >> On Sat, 2015-05-09 at 13:07 -0700, Walter Bright via Digitalmars-d wrote: >>> >>> […] >>> It probably depends on the compiler. The way to find out is to look at >>> th

Re: Tuple assignment

2015-05-10 Thread John Colvin via Digitalmars-d
On Sunday, 10 May 2015 at 08:07:38 UTC, Russel Winder wrote: On Sat, 2015-05-09 at 13:07 -0700, Walter Bright via Digitalmars-d wrote: […] It probably depends on the compiler. The way to find out is to look at the generated assembler. assembly language file, not assembler (which is the progra

Re: Tuple assignment

2015-05-10 Thread Walter Bright via Digitalmars-d
On 5/10/2015 1:07 AM, Russel Winder via Digitalmars-d wrote: ldc2 and gdc have options to write the assembly language file, maybe I am missing it but dmd appears not to advertise such an option. http://www.digitalmars.com/ctg/obj2asm.html

Re: Tuple assignment

2015-05-10 Thread Russel Winder via Digitalmars-d
On Sun, 2015-05-10 at 08:47 +, Oren Tirosh via Digitalmars-d wrote: > […] > > > tuple(current, next) = tuple(next , current +next); > > […] > Works for me. If this is version or compiler dependent this > definitely needs investigation. It does not for me using rdmd 2.067. My implementa

Re: Tuple assignment

2015-05-10 Thread Oren Tirosh via Digitalmars-d
. I did not mean imply that it doesn't, just that what I wrote is not some proposed syntax for tuple assignment but something that actually works now. This works right now and is quite aesthetically pleasing: tuple(current, next) = tuple(next , current +next); This does not

Re: Tuple assignment

2015-05-10 Thread Russel Winder via Digitalmars-d
On Sun, 2015-05-10 at 08:14 +, Oren Tirosh via Digitalmars-d wrote: > On Saturday, 9 May 2015 at 17:16:58 UTC, Russel Winder wrote: > > […] > > TypeTuple!(current, next) = tuple(next , current +next); This works. > This works right now and is quite aesthetically pleasing: > > t

Re: Tuple assignment

2015-05-10 Thread Russel Winder via Digitalmars-d
On Sat, 2015-05-09 at 13:07 -0700, Walter Bright via Digitalmars-d wrote: > On 5/9/2015 10:16 AM, Russel Winder via Digitalmars-d wrote: > > Python has tuple assignment so you see things like: > > > > previous, current = current, previous + current > > >

Re: Tuple assignment

2015-05-10 Thread weaselcat via Digitalmars-d
On Saturday, 9 May 2015 at 20:07:00 UTC, Walter Bright wrote: It probably depends on the compiler. The way to find out is to look at the generated assembler. fwiw, I tried to look at this earlier and found out a single tuple generates too much assembly for asm.dlang.org to display ;)

Re: Tuple assignment

2015-05-10 Thread Oren Tirosh via Digitalmars-d
On Saturday, 9 May 2015 at 17:16:58 UTC, Russel Winder wrote: Python has tuple assignment so you see things like: previous, current = current, previous + current especially if you are doing silly things like calculating Fibonacci Sequence values. Translating this to D, you end up

Re: Tuple assignment

2015-05-10 Thread Russel Winder via Digitalmars-d
On Sat, 2015-05-09 at 13:07 -0700, Walter Bright via Digitalmars-d wrote: > […] > It probably depends on the compiler. The way to find out is to look > at the > generated assembler. assembly language file, not assembler (which is the program to do the transformation) ldc2 and gdc have options t

Re: Tuple assignment

2015-05-09 Thread Walter Bright via Digitalmars-d
On 5/9/2015 10:16 AM, Russel Winder via Digitalmars-d wrote: Python has tuple assignment so you see things like: previous, current = current, previous + current especially if you are doing silly things like calculating Fibonacci Sequence values. Translating this to D, you end up with

Tuple assignment

2015-05-09 Thread Russel Winder via Digitalmars-d
Python has tuple assignment so you see things like: previous, current = current, previous + current especially if you are doing silly things like calculating Fibonacci Sequence values. Translating this to D, you end up with: TypeTuple!(current, next) = tuple(next , current +next

Re: Tuple literal syntax + Tuple assignment

2010-10-29 Thread Bruno Medeiros
On 07/10/2010 19:45, Andrei Alexandrescu wrote: On 10/7/10 12:45 CDT, Michel Fortin wrote: On 2010-10-07 12:34:33 -0400, Andrei Alexandrescu said: My suggestion is that we deprecate TypeTuple and we call it AliasTuple because that's really what it is - it's a tuple of stuff that can be passed

Re: Tuple assignment

2010-10-08 Thread Leandro Lucarella
Juanjo Alvarez, el 9 de octubre a las 04:02 me escribiste: > On Fri, 08 Oct 2010 16:11:53 -0400, bearophile > wrote: > >This syntax you have explained doesn't do what you think it does: > >a, b, c, _ = ('tuple', 'of', 'three') > > That was a typo, I meant to write: > > a, b, _ = ('tuple', 'of',

Re: Tuple assignment

2010-10-08 Thread Juanjo Alvarez
On Fri, 08 Oct 2010 16:11:53 -0400, bearophile wrote: This syntax you have explained doesn't do what you think it does: a, b, c, _ = ('tuple', 'of', 'three') That was a typo, I meant to write: a, b, _ = ('tuple', 'of', 'three')

Re: Tuple assignment

2010-10-08 Thread Jérôme M. Berger
Juanjo Alvarez wrote: > On Thu, 07 Oct 2010 15:14:12 -0400, bearophile > wrote: >> This is false both in Python2 and Python3. > > > What is exactly false on what I said? > python Python 2.6.5 (r265:79063, Apr 1 2010, 05:28:39) [GCC 4.4.3 20100316 (prerelease)] on linux2 Type "help", "copyright

Re: Tuple assignment

2010-10-07 Thread Juanjo Alvarez
On Thu, 07 Oct 2010 15:14:12 -0400, bearophile wrote: This is false both in Python2 and Python3. What is exactly false on what I said? a, *bc = ('tuple', 'of', 'three') Yes, that's the syntax for assignment of the remainder, I was speaking about *ignoring* the remainder without having i

Re: Tuple literal syntax + Tuple assignment

2010-10-07 Thread bearophile
Andrei: Another possible useful feature for tuples is to unpack them in foreach too: import std.algorithm, std.stdio, std.range; void main() { foreach (p; zip([1, 2, 3], "abcd")) writeln(p[0], " ", p[1]); writeln(); foreach ((a, b); zip([1, 2, 3], "abcd")) writeln(a, "

Re: Tuple literal syntax + Tuple assignment

2010-10-07 Thread bearophile
kenji hara: > My proposals are: > 1. We should name definitions of structures. > - "Structure that all of fields have name" shuld be called 'Struct'. > - "Structure that some of fields have name" shuld be called 'Odd struct'. > - "Structure that none of fields have name" shuld be called 'Record

Re: Tuple assignment

2010-10-07 Thread bearophile
Juanjo Alvarez: > Python has the special symbol "_" which is used exactly as > a no-op (you could call it "foo" it you wanted, but "_" > doesn't create new memory assignments) so you can expand > arbitrary tuples without creating new symbols: > > a, b, c, _ = ('tuple', 'of', 'three') This is fal

Re: Tuple assignment

2010-10-07 Thread Tomek Sowiński
Walter Bright napisał: > If expr represents a tuple, we (Andrei and I) were thinking about the > syntax: > > auto (a, b, c, d) = expr; > > being equivalent to: > > auto t = expr; auto a = t[0]; auto b = t[1]; auto c = t[2 .. $]; Typo? If not, what is 'd'? Either way, I'd like mismatc

Re: Tuple literal syntax + Tuple assignment

2010-10-07 Thread Andrei Alexandrescu
On 10/7/10 12:45 CDT, Michel Fortin wrote: On 2010-10-07 12:34:33 -0400, Andrei Alexandrescu said: My suggestion is that we deprecate TypeTuple and we call it AliasTuple because that's really what it is - it's a tuple of stuff that can be passed in as an alias parameter. Personally, I like D

Re: Tuple literal syntax + Tuple assignment

2010-10-07 Thread retard
Thu, 07 Oct 2010 13:45:16 -0400, Michel Fortin wrote: > On 2010-10-07 12:34:33 -0400, Andrei Alexandrescu > said: > >> My suggestion is that we deprecate TypeTuple and we call it AliasTuple >> because that's really what it is - it's a tuple of stuff that can be >> passed in as an alias parameter

Re: Tuple literal syntax + Tuple assignment

2010-10-07 Thread Michel Fortin
On 2010-10-07 12:34:33 -0400, Andrei Alexandrescu said: My suggestion is that we deprecate TypeTuple and we call it AliasTuple because that's really what it is - it's a tuple of stuff that can be passed in as an alias parameter. Personally, I like D built-in tuples; they're so simple. At th

Re: Tuple literal syntax + Tuple assignment

2010-10-07 Thread kenji hara
2010年10月8日1:34 Andrei Alexandrescu : > On 10/7/10 11:11 CDT, kenji hara wrote: >> 2010/10/7 bearophile: >>> Another design decision is if tuples have a nominative or structural type, >>> this problem comes out in this bug report: >>> http://d.puremagic.com/issues/show_bug.cgi?id=4128 >> >>> Anothe

Re: Tuple literal syntax + Tuple assignment

2010-10-07 Thread Andrei Alexandrescu
On 10/7/10 11:11 CDT, kenji hara wrote: > 2010/10/7 bearophile: >> Another design decision is if tuples have a nominative or structural type, >> this problem comes out in this bug report: >> http://d.puremagic.com/issues/show_bug.cgi?id=4128 > >> Another significant problem is about naming things

Re: Tuple literal syntax + Tuple assignment

2010-10-07 Thread kenji hara
2010/10/7 bearophile : > Another design decision is if tuples have a nominative or structural type, > this problem comes out in this bug report: > http://d.puremagic.com/issues/show_bug.cgi?id=4128 > Another significant problem is about naming things, currently the situation > is a mess: > http:

Re: Tuple assignment

2010-10-07 Thread Leandro Lucarella
t;> > >> float[3] xyz; > >> auto (x, y, z) = xyz; > >> > >>The Lithpers among you will notice that this essentially provides a handy > >>car,cdr shortcut for tuples and arrays: > >> > >> auto (car, cdr) = expr; > >

Re: Tuple literal syntax + Tuple assignment

2010-10-07 Thread Andrei Alexandrescu
On 10/7/10 7:09 CDT, bearophile wrote: In the two threads (that are a single thread) most of the things I've seen are bad/wrong. I have discussed about Tuples several times in the D newsgroup and in Bugzilla. Please don't ignore all my work. Before designing tuple syntax you must decide what

Re: Tuple literal syntax + Tuple assignment

2010-10-07 Thread Simen kjaeraas
bearophile wrote: In my opinion it's good for a built-in D tuple to be a structural type. This also means you are allowed to perform an == among two tuples of different length (the result is known statically to be always false). I understand (and agree to) the opinion that tuples should be

Re: Tuple assignment

2010-10-07 Thread Andrei Alexandrescu
On 10/7/10 3:55 CDT, Pelle wrote: On 10/07/2010 08:08 AM, Walter Bright wrote: If expr represents a tuple, we (Andrei and I) were thinking about the syntax: auto (a, b, c, d) = expr; being equivalent to: auto t = expr; auto a = t[0]; auto b = t[1]; auto c = t[2 .. $]; You can also do this wi

Re: Tuple assignment

2010-10-07 Thread Juanjo Alvarez
Denis Koroskin Wrote: > That's because Python is not a strictly typed language. With proper type > propagation compiler helps you writing code the way in meant to be. E.g. > the following: > > (a, b, c, d) = ('tuple', 'of', 'three') > > could be statically disabled, but there is nothing wro

Re: Tuple literal syntax + Tuple assignment

2010-10-07 Thread bearophile
In the two threads (that are a single thread) most of the things I've seen are bad/wrong. I have discussed about Tuples several times in the D newsgroup and in Bugzilla. Please don't ignore all my work. Before designing tuple syntax you must decide what the purpose of D tuples is. Then you hav

Re: Tuple assignment

2010-10-07 Thread Pelle
On 10/07/2010 08:08 AM, Walter Bright wrote: If expr represents a tuple, we (Andrei and I) were thinking about the syntax: auto (a, b, c, d) = expr; being equivalent to: auto t = expr; auto a = t[0]; auto b = t[1]; auto c = t[2 .. $]; You can also do this with arrays, such that: float[3] xyz

Re: Tuple assignment

2010-10-07 Thread Pelle
On 10/07/2010 09:03 AM, Walter Bright wrote: Russel Winder wrote: Python may be the best base to compare things to as tuple assignment has been in there for years. Too segue this into the previous thread, how does Python treat (1)? Is it a floor wax or a dessert topping? http://www.nbc.com

Re: Tuple assignment

2010-10-07 Thread Andrei Alexandrescu
as tuple assignment has been in there for years. Pythons choice is not a car/cdr approach but an exact match approach. So then we'd have the proposed notation not work with dynamic arrays - only with static arrays and tuples. Andrei

Re: Tuple assignment

2010-10-07 Thread Denis Koroskin
On Thu, 07 Oct 2010 11:42:06 +0400, Brad Roberts wrote: On 10/6/2010 11:58 PM, Walter Bright wrote: Russel Winder wrote: Python may be the best base to compare things to as tuple assignment has been in there for years. Pythons choice is not a car/cdr approach but an exact match approach

Re: Tuple assignment

2010-10-07 Thread Brad Roberts
On 10/6/2010 11:58 PM, Walter Bright wrote: > Russel Winder wrote: >> Python may be the best base to compare things to as tuple assignment has >> been in there for years. >> >> Pythons choice is not a car/cdr approach but an exact match approach. >> so if t repre

Re: Tuple assignment

2010-10-07 Thread Denis Koroskin
to compare things to as tuple assignment has been in there for years. Pythons choice is not a car/cdr approach but an exact match approach. so if t represents a tuple datum or a function returning a tuple: x = t then x is a tuple -- remembering that variables are all just references to

Re: Tuple assignment

2010-10-07 Thread Walter Bright
Russel Winder wrote: Python may be the best base to compare things to as tuple assignment has been in there for years. Too segue this into the previous thread, how does Python treat (1)? Is it a floor wax or a dessert topping? http://www.nbc.com/saturday-night-live/video/shimmer-floor-wax

Re: Tuple assignment

2010-10-07 Thread Walter Bright
Russel Winder wrote: Python may be the best base to compare things to as tuple assignment has been in there for years. Pythons choice is not a car/cdr approach but an exact match approach. so if t represents a tuple datum or a function returning a tuple: x = t then x is a tuple

Re: Tuple assignment

2010-10-06 Thread Russel Winder
ust references to objects implemented via keys in a dictionary, and: a , b , c = t or ( a , b , c ) = t is tuple assignment where now t is required to be a tuple of length 3. cf. |> python Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41) [GCC 4.4.3] on

Tuple assignment

2010-10-06 Thread Walter Bright
If expr represents a tuple, we (Andrei and I) were thinking about the syntax: auto (a, b, c, d) = expr; being equivalent to: auto t = expr; auto a = t[0]; auto b = t[1]; auto c = t[2 .. $]; You can also do this with arrays, such that: float[3] xyz; auto (x, y, z) = xyz; The L