Re: Error Trapping
- Posted by "Boehme, Gabriel" <gboehme at POBOXB1.HQ.MSMAIL.MUSICLAND.COM> May 13, 1999
- 445 views
Ralf Nieuwenhuijsen wrote: >if v[i] = "" then > >.. and .. > >if v[i] = '' then > >Are both as incorrect as hell. Yes, because the original post you seem to be responding to ["Rob questions"] had a space between the quotes. (And BTW, there's no such thing as a '' char in Euphoria -- you'll get a "single-quote char is empty" error.) >The problem is the recursive nature of all mathimatical and relational >operators, I suggest Robert wrote a seperate 'mini' - tutorial on the >subject. This might not be a bad idea. Almost every other language allows the use of "=" comparisons between strings in "if" statements, and remembering *not* to do so in Euphoria can be difficult. Perhaps a "new Euphoria programmer's list of tips" might be helpful -- brief overviews of Euphoria's major differences from other languages, with links or references to the appropriate section(s) of the manual for further explanation. Of course, as with the current Euphoria docs, the person has to actually *read* this new document, which doesn't always happen... >somebody asks "why isn't this working" and half of the people are like >"let me do it for you" .. the list-server community is really great and >helpfull to many people, but it wouldn't hurt any one if we would give >it some thought and what exactly would and would not be helpfull. For the most part, I think the people answering questions here on the list do a good job of giving *some* reasoning behind their solutions. As far as "what exactly would and would not be helpful," replies are only helpful when they are at least factually correct. >object m, n >m = { 1, 2, 3 } > >[snip] > >n = m * { 1, 2, 3, 4 } >? n -- { { 1, 2, 3 }, { 2, 4, 6 }, { 3, 6, 9 } } If you had actually executed the above code segment, you would quickly have discovered the following error message: "sequence lengths are not the same (3 != 4)" You can only do arithmetic operations on two atoms, an atom and a sequence, or two sequences of the exact same length (these rules apply recursively to every element of a sequence). From REFMAN.DOC, section 2.2.4 (Operations on sequences), paragraph three: "If a binary (two-operand) operator has operands which are both sequences THEN THE TWO SEQUENCES *MUST* BE OF THE SAME LENGTH." [emphasis mine -- perhaps this should also be emphasized in the manual, since I skipped right over it the first time through] And, from this very ListServ: ---------- From: Boehme, Gabriel Subject: Re: each keyword Date: Thursday, April 22, 1999 7:33PM Ralf Nieuwenhuijsen wrote: > [snip] Try print (1, {1,2,3} * {1,2,3}) >Euphoria, as an exception, or to be consistent (choose), will do the >following, because the two sequence are of the same length. > >{1, 4, 9} It's not the exception -- it's the rule. >But what when they are not of the same length ? > >print (1, {1,2,3} * {1,2,3,4}) The program abends with a "sequence lengths are not the same" error message. ---------- As I, too, have learned the hard way: it's always a good idea to actually check your examples before you post them. :) Be seeing you, Gabriel Boehme ------ None of the modern machines, none of the modern paraphernalia... have any power except over the people who choose to use them. G.K. Chesterton ------