Re: Better Way to Do This
- Posted by euphoric (admin) Aug 06, 2009
- 1114 views
DerekParnell said...
euphoric said...
Is there a standard lib or more efficient function that could replace this? I'm using this for a type definition. The variable needs to be all sequences.
function no_atoms( sequence s ) integer i = 1 for t=1 to length(s) do if atom(i) then return 0 end if end for return 1 end function
There is a Eu v4 library routine for this. It's in std/types.e ... By the way, your code above wouldn't work as you don't update the 'i' variable.
Thanks Derek. I figured there was something already available. I also modified the code in browser before I submitted it, so it wasn't the original... just something I thought would be faster but didn't verify.
It was originally this:
function no_atoms( sequence s ) integer i = 1 for t=1 to length(s) do i = i and sequence(s[t]) end for return i end function
But I figured that would go through the entire sequence, so if there was an atom at s[1], why waste all that time? Of course, if the atom was at s[$], then no algorithm will get there faster. Right?