Hints & Tips
Since I may lose my net access in about a month's time, I thought I'd
start a worthwhile thread for those of us Euphorians who just like hobby
programming with Euphoria.
Maybe Rob "I *am* Euphoria" Craig could include everybody's entries on
the fairly unused Programming Tips page...
1) These two lines are legal in Euphoria:
if a = 7 and b = 7 then ...
if a = 7 or b = 7 then ...
but this isn't:
if a = 7 xor b = 7 then ... -- a = 7 or b = 7, but *not* both!
^^^
You could get round this by coding:
if a = 7 or b = 7 and a != b then ...
but there's a shorter way:
if (a = 7) != (b = 7) then ... -- Trust me, this works!
2) Ever coded something like this?:
flag = 0
for i = 1 to length(seq)
if seq[i] = 'a' or seq[i] = 'b' or seq[i] = 'z' then
flag = 1
--exit --maybe
end if
end for
if flag then ... etc.
But if 'seq' was an atom you'd do this:
if seq = 'a' or seq = 'b' or seq = 'z' then ...
So combine the two!:
if find(1, (seq = 'a' or seq = 'b' or seq = 'z')) then ... etc.
-- The find(1,... represents finding a truth value
-- don't confuse it with puts(1,...!
This method, however, does have a *small* problem. If there would have
been (or is) an 'exit' in the for-loop, the for-loop may actually be
quicker than Euphoria checking the whole of the sequence.
[For 'a's 'b's and 'z's in this case].
3) If you really *have* to use the for-loop-with-exit above (for speed),
try changing the if statement to:
flag = 0
for i = ...
if find(seq[i], "abz") then ... etc.
4) Expanding from the above:
If you have to code a loop that runs through a sequence an element
at a time, there's probably a way of getting Euphoria to do the hard
work for you by using a function that treats sequences like atoms.
Happy coding!
Carl
--
Carl R White
E-mail...: cyrek- at -bigfoot.com -- Remove the hyphens before mailing. Ta :)
Url......: http://www.bigfoot.com/~cyrek/
In my last few days on the net, I have room for a witty quote. Irony. :S
|
Not Categorized, Please Help
|
|