Re: append() tip

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

Chris Bensler writes:
> x = append(x,y) <-- does eu type check x for a sequence in both instances?
>
> x &= y <-- only once?
>
> Besides preference, should there be any difference between the two forms?

Appending an atom, y, onto the end of a sequence, x, 
can be done using:
     x = append(x, y)
or:
     x &= y 
or:
     x = x & y

The speed should be virtually identical in all three cases,
as almost exactly the same code is executed internally.
Not just similar code - the *same* code.

Note that if y is not an atom, but rather a sequence,
then append() and & are *not* interchangeable operations.

Regarding timings:
Don't leap to conclusions based on one short timing
of some code. You should time something for several seconds at least,
with all other apps shut down, and you should repeat the timing
3 times at least, to see if there is significant variation from one
run to the next - there often is. Also, if you try version 1 of some code,
followed by version 2, in the same program, it can sometimes make
a difference which version you execute first, as the second version
might be charged with the cost of deallocating all the storage used
by the first version.

Regards,
   Rob Craig
   Rapid Deployment Software
   http://www.RapidEuphoria.com

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

Search



Quick Links

User menu

Not signed in.

Misc Menu