RE: Syntax of &-operator

new topic     » goto parent     » topic index » view thread      » older message » newer message

> As I said, I don't like the behaviour of "&". This seems
> strange to me:
>
> > a & b = append({a}, b)
>
> > a & b = append(a, b)
>
> being valid at the same time!

Is the strangeness due it allowing both atoms and sequences in the operands?

> > It could be coded like this:
> >
> > {a} & {b} & {c} & {d}
>
> DP>or like this ...
> DP>  {a,b,c,d}
>
> Nope! That would eliminate the option of "&=".

How so?
   sequence x
   atom a,b,c,d

   x = {1,2,3,4}
   a = 91
   b = 92
   c = 93
   d = 94
   x &= {a,b,c,d}
   -- leaves x to be {1,2,3,4,90,91,92,93}

> DP>the "old" way? What is the "new" way then? How have things changed?
>
> Replace "old" with "current". Then replace "new" with "an
> alternative", and
> you've got it! Things haven't changed, and they won't ever
> with so many
> programs and libraries up and running.

I suspect that if enough advocacy is used on things that won't break
existing code, RDS just might be bothered with it. Its always worth a try.

> DP>Are you advocating that a new function be included in
> Euphoria called
> DP>'concat' and that it should work the same as '&' operation?
>
> Not the same, of course (nothing would be gained by that!),
> and its name
> doesn't matter. In fact, it should be a single character like
> "@". Nobody
> *has* to use it but it would be faster by assuming operands
> to be *always*
> sequences. And debugging would be easier in many cases where
> "&" ignores
> the difference between atoms and sequences...

And yet, I'm glad of the way that '&' uses both datatypes. Otherwise I'd
have to code ugly things like this all the time ...

   if atom(a) or atom(b) then
           x = a & b
   else
	     x = a @ b
   end if

If you really want a function to do this I suppose you could create ...

   function concat(sequence a, sequence b)
      return a & b
   end function

which would force type checking on the operands.

I imagine that the '&' operation was born, primarily, out of the desire to
join strings together.

   a = "Derek"
   b = "Parnell"
   x = a & " " & b

but to make life simplier and faster for both coder and interpreter, atoms
could be used too.

   delim = ' '
   a = "Derek"
   b = "Parnell"
   x = a & delim & b


-----------
cheers,
Derek Parnell
Senior Design Engineer
Global Technology Australasia Ltd
dparnell at glotec.com.au

---------------------

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu