1. Quickest way to find out if a sequence is/isn't empty?
- Posted by ZNorQ Oct 14, 2013
- 1402 views
What would be the quickest way to verify if a sequence is/isn't empty? This especially applies to sequences of considerable sizes.
What I'm trying to explain, is that if a sequence contains data, I don't want the code to iterate through the whole sequence to verify that it ISN'T empty.. I'm guessing not length(mySequence) (or length(mySequence)=0) wouldn't be the quickest one, as it would presumably count through the whole sequence and THEN find out that it isn't empty.
I've also used equal({}, mySequence), but I'm kind of guessing that that also would run through the whole sequence before finding out that it isn't empty.
Regards, ZNorQ aka Kenneth
2. Re: Quickest way to find out if a sequence is/isn't empty?
- Posted by jimcbrown (admin) Oct 14, 2013
- 1410 views
What would be the quickest way to verify if a sequence is/isn't empty? This especially applies to sequences of considerable sizes.
What I'm trying to explain, is that if a sequence contains data, I don't want the code to iterate through the whole sequence to verify that it ISN'T empty.. I'm guessing not length(mySequence) (or length(mySequence)=0) wouldn't be the quickest one, as it would presumably count through the whole sequence and THEN find out that it isn't empty.
I've also used equal({}, mySequence), but I'm kind of guessing that that also would run through the whole sequence before finding out that it isn't empty.
Regards, ZNorQ aka Kenneth
length(mySequence) is the fastest. length() doesn't count the elements, it just references the existing count (so it's like accessing mySequence[0] where mySequence[0] is always an integer).
3. Re: Quickest way to find out if a sequence is/isn't empty?
- Posted by ZNorQ Oct 14, 2013
- 1334 views
Ah, wasn't aware of that. Thanks.
4. Re: Quickest way to find out if a sequence is/isn't empty?
- Posted by ArthurCrump Oct 14, 2013
- 1387 views
length(mySequence) is the fastest. length() doesn't count the elements, it just references the existing count (so it's like accessing mySequence[0] where mySequence[0] is always an integer).
This can be extended to general objects; if you want to know whether an object is an empty sequence.
The manual states that the length of an atom is always 1, so:
length(myObject) is zero only when myObject is an empty sequence.
Arthur