Re: Error Trapping
- Posted by Ralf Nieuwenhuijsen <nieuwen at XS4ALL.NL> May 13, 1999
- 366 views
> [ADDITIONAL NITPICKY POINTS: Your "if" statement would result in the > "true/false condition must be an ATOM" error. It should read "if equal(Obj, > {})" or "if compare(Obj, {}) = 0" instead. Also, My_Procedure can't return a > -1, because it's a procedure -- not a function.] Finally, at least, a correct reply after so many "you should use single qoutes" .. if v[i] = "" then .. and .. if v[i] = '' then Are both as incorrect as hell. The problem is the recursive nature of all mathimatical and relational operators, I suggest Robert wrote a seperate 'mini' - tutorial on the subject. Most of all newcomers to Euphoria have problems with this, and explenations such as: -- "you should use single qoutes" -- "you should use equal" etc. First of all, both replies assume some algorimic meaning of the program (and thus take the programming part out of the hands of the programmer), and lack the explenation *why* .. The problem isn't in the syntax of the program, its in the understanding of the programmer. And that will remain a problem until somebody explains how this works .. 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. This way all our good intentions can have the effect we want it to have. At the end of this mail is a post I made on the newsgroup on the very same topic. It should explain this stuff for now (in my lousy Engish), but I suggest Robert adds a couple of mini-tutorials to the Euphoria packagae, that explain these kind of things. Topics I had in mind: -- Atom VS sequence (In appending, slicing, concationation) -- Recursive nature of mathimatical & relational operators -- Simple file I/O -- How to time a certain routine/technique -- Windows: a simple how-to do win32 (list of resources, a quick intro to win32lib or the new Liama) -- Data management (client/server) The last topic I will explain a bit futher: I meant the flow of data. Use local variables to store everything ? Return all information ? Return a handle. In other words, a quick how-to setup store information handle-based, etc. (basic techniques used by almost all libraries managing some kind of data) Off course, some one else could make such tutorials, but I at least suggest to pack such tutorials with the standard Euphoria package. Now here's the post about the recursive stuff, in my own lacking English.. Michael Dauth <mdauth at bigfoot.com> wrote in message news:7GNTflH8WwB at mdauth.bigfoot.com... > Hi, > > after banging my head for hours I found out that the "=" > operator does not work with sequences, but the equal functions > does. Am I wrong and if what am I doing if the following code > does not work: Indeed, totally correct. If-statements use any legal euphoria express to represent the TRUE / FALSE value, however Euphoria's rules about expression (the recursive operator 'theme') allow it in some occasions to generate a sequence rather than an atom value. Sequence is not clearly TRUE or FALSE, therefor the if-statement generates an error message in such case. So how do the Euphoria evaluation does work ? atom a, b, c a = 1 b = 0 c = not a ? c -- 0 c = a or b ? c -- 1 c = a and b ? c -- 0 sequence d, e, f d = { 1, 0, 1 } e = { 0, 1, 1 } f = not d ? f -- { 0, 1, 0 } f = d or e ? f -- { 1, 1, 1 } f = d and e ? f -- { 0, 0, 1 } object g, h, i g = 1 h = { 0, 1, 0 } i = not g ? i -- 0 i = not h ? i -- { 1, 0, 1 } i = g or h ? i -- { 1, 1, 1 } i = g and h ? i -- { 0, 1, 0 } sequence j, k, l j = { 1, 0, 0 } k = { 0, 1 } l = j or k ? l -- { { 1, 1 }, { 0, 1 }, { 0, 1} } l = j and k ? l -- { { 0, 1 }, { 0, 0 }, { 0, 0 } } -- What applies to the boolean operators also applies to the mathematical operators. -- Example: object m, n m = { 1, 2, 3 } n = m * 2 ? n -- { 2, 4, 6 } n = m * m ? n -- { 1, 4, 9 } n = m * { 1, 2, 3, 4 } ? n -- { { 1, 2, 3 }, { 2, 4, 6 }, { 3, 6, 9 } } -- In short terminology: -- Operators recurse whenever the either one of the two values is an atom or when the two sequences are of different length. So, since a string / qouted-sequence is handled just like any other sequence, the 'equal' _operator_ will recurse the equal-operation. You could write a recursive function like this to deal with it: global function equal (object x, object y) if atom (x) then if atom (y) then return x = y else return 0 end if elsif atom (y) then return 0 elsif length(x) != length(y) then return 0 else for index = 1 to length(x) do if not equal (x[index], y[index]) then return 0 end if end for return 1 end if end function But, guess what ? Its already built-in, and called precisely the same. You also have compare, but unlike the equal function which will only return an atom true / false value, compare returns either zero, minus one and plus one. Example: atom o, p o = 1 p = 2 ? compare (o, p) --- 1 ? compare (p, o) --- -1 ? compare (o, o) --- 0 ? compare (p, p) --- 1 I hope this was helpful, I always feel examples show more than words alone, nevertheless, feel free to ask for more explanation if any part is unclear. Good luck learning Euphoria .. Ralf Nieuwenhuijsen ... mailto://nieuwen at xs4all.nl ... mailto://ralf_n at email.com ... http://www.xs4all.nl/~nieuwen ... uin: 9389920