1. Re: [If/then and sequences...]

From: Dan B Moyer <DANMOYER at PRODIGY.NET>
> Hawke,
> *Very* interesting.  I was *going* to ask:
thankee :) i DO try to help on occassion, glad i could :)

> In
> >    return (data >=13) and (data <=19)
> why don't you have to *build* a sequence from a series of logical ands
> working on each element of the data sequence in order to have that boolean
> data returned in a sequence??  It certainly works, but how?
*cough* you DONT wanna know the answer to that ;)
well, not unless u got a BIGASS bottle of asprin handy ;)

u can look in my other email at that convoluted function i had to write as
an example tho (and btw, i THINK its actually -wrong- too)

---original function and wrong HEH it was 4am when i wrote it ;)
function IsTeenager(object data)
   -----doh what was i thinking with this line?
   if atom(data) then return data end if

   for i = 1 to length(data) do
      if sequence(data[i]) then
          data[i] = IsTeenager(data[i])
      end if
   ----and DOH again, these tests belong at the start
   ----of the function where the atomic test is
      if (data[i] >= 13) and (data[i]<=19) then
             data[i] = 1
      else data[i] = 0
      end if
   end for
   return data
end function

basically, what u have to do, is examine every single element of the data
and determine its nesting...then you can apply your testing once you have
the nesting stripped down to a singular atom...recursion works well here
but i botched my function and since im lazy, i never test nuffin ;)

function IsTeenager(object data)
   if atom(data) then
      if (data>=13) and (data<=19) then
             return 1
      else return 0
      end if
   else
      for i = 1 to length(data) do
           data[i] = IsTeenager(data[i])
      end for
   end if
   return data
end function

there, that should be correct...and should illustrate what unary operators
do
to sequences and answers your "how does it do that" question...
except rob does it in the core of the language and likely a lot
faster then the above function...

the data sets matter a lot when you begin benchmarking the hard code
above against a oneliner...a long string of long sequences, all deeply
nested
will have faster results usually with a one liner, and shorter stuff can
see speed improvements with hard coding...also, im calling a recursive
pop of my function for every element of the sequence, but if u know
ahead of time that its a long line of atoms, u can save a lot of function
calling by tuning for long strings of single nested atoms...
shrug, all depends on your data...

> but then I read the manual (!) & saw that:
> "When applied to a sequence, a unary (one operand) operator is actually
> applied to each element in the sequence to yield a sequence of results of
> the same length. "
> Nifty.
WELCOME to Euphoria, and WELCOME to the OneLiner club ;)
u just graduated ;)
now go code some one liners ;)

> Dan
> wearing a dunce cap
naw, takes a while to appreciate EU's grace...took me a long long time...
those that bash EU are the ones that usually havent had the lightbulb
click like u just did :)
stick around, it only gets better from this point =]

--Hawke'

_______________________________________________
Why pay for something you could get for free?
NetZero provides FREE Internet Access and Email
http://www.netzero.net/download/index.html

new topic     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu