More D newb questions.

Me Here p9e883002 at sneakemail.com
Thu May 8 15:53:13 PDT 2008


BCS wrote:

> Reply to Me,
> 
> 
> > That depends upon the order (precedence) the transformation rules are
> > applied.
> > With the ordering shown above, your second example matched the first
> > rule
> > shown,
> >and so is processed before it ever gets to the T ~ T -> T[].
> > The first example fails to match on the first three rules and is
> > processed
> > according to the 4th
> > and the result is consistant results.
> > b.
> > 
> 
> You have just describe exactly why that code (from the programers's
> standpoint) is somewhat inconstant
> 
> "T ~ T" can  be of type T or T[] depending on what exactly T is. from the
> programers standpoint this is inconstant. Template code becomes hard to
> working with if the type of an expression starts having this type of
> dependency.

Sorry, but I just don't buy that. Programmers are well used to the concept that
aggregates are composed of elements. Whether arrays of ints and ints... or list
sof a head and a tail. Indeed, Rules 2 & 3 use that very notion.

	2) T ~ T[]: 
	char[] prepended  = 'a' ~ "some string"; 
	char[] prepended  = someChar ~ someCharArray;

	3) T[] ~ T
	creal[] appended = 2+3i ~ [ 1+2i, -5+4i ]; // I hope those compex constants
make sense?
	creal[] appended ~= 2+1i;

D already allows these and no one is confused by it. Even kids wouldn't be
confused. They pick up two short stacks of Lego bricks and press them together
and the get a longer stack of Lego bricks. They pick up another single brick
and press it on one one end and the stack gets bigger still. Another single
pressed on the other end and same again. They pick up two single Lego bricks
and press them together and they have a small stack of Lego bricks.

One person waiting at a checkout is just one person. Another joins, you've got
a queue. If the till next door closes and its queue joins the back of that two
person queue and you get a longer queue. Not a queue of queues.

Two playing cards on top of each other and you have the start of a pack. Put to
packs together and you have a bigger pack.

No one is surprised by any of these. There is nothing inconsistant.

b.
-- 




More information about the Digitalmars-d mailing list