Re: Another Error
- Posted by CChris <christian.cuvier at agriculture.gouv.fr> Feb 01, 2007
- 654 views
Derek Parnell wrote: > > don cole wrote: > > Back to the origtinal question > > true/false condition must be an ATOM > > if Correct = 'y' or Correct = 'Y' then(line24) > > sequence FactionName, FactionPassword, Correct > > > > Correct here is definately not an atom but a sequence. > > Agreed, but the statement in question is not > > if Correct then > > also the expression 'equal(Correct, "Y")' is also not an atom but it works > because > it is evaluated and returns an atom. > > My problem is that > > Correct = "Y" > > evaluates to a sequence rather than to an atom, in the context of an IF > statement. > If the rules were changed so that it did what it looks like its trying to do, > no existing code would be broken and future code would be easier to write and > read. > > -- > Derek Parnell > Melbourne, Australia > Skype name: derek.j.parnell Then let's just solve the problem. When you perform string comparison, you, the coder, know that you are doing so, and the semantics of this operation won't likely change often. And it is desirable that ayone reading the code understands it at first sight. So, if you don't like
if compare(you,me) then -- ...
to test whether you and me are different sequences, perhaps would it help to be able to write
if_sequence you != me then -- ...
This is just syntactic sugar. It would toggle a flag that tells rexpr() to map relational operators to relations with compare() results. Otherwise, it would behave exactly like an ordinary if statement. You'd need an elsif_sequence too, and the two brands could be freely interleaved. Perhaps allow end if_sequence, but it would be an exact equivalent of end if. I don't come fom Basic (haven't used it for 25 years), but from Pascal, which, like Basic, knows about string comparison, since it knows about strings. Yet I think the current way of doing things is more intuitive and consistent: extend atomic operaions to sequences, and use specific methods to deal with sequences as atomic objects. Perhaps my being familiar with the 6-letter word oriented programming ways (gotta be careful on this list). But if if_sequence, or whatever you call it, is supposed to alleviate some newbie confusion, it would be easy to tuck it in the front end. One thing which I find missing in Eu is the ability to perform element wise operations that might apply to sequences as a whole. I'd like to be able to write
s=atom(`x)
(or anything just as little obstrusive), in order to get a sequence of true and false values which tell which, if any, of the elements of the sequence x are atoms. Of course, you can do this
function has_atoms(sequence s) object x for i=1 to length(s) do x=s[i] s[i]=atom(x) end for return s end function
and use s=has_atoms(x). Fine, you have to define one such helper finction for each function you'd like to use in this way. A real pain. In a nutshell, functional operators are missing. CChris