1. RE: if statement not working
- Posted by Andy Serpa <renegade at earthling.net> Mar 21, 2002
- 476 views
xxmyt at yahoo.com wrote: > hello everyone. > > the code i pasted down works properly. however, it doesnt work in the > second way. > > my code: > include dos32lib.e > without warning > > constant > Win = create( Window, "PASSWORD REQUIRED", 0, Default, Default, > 400, 200, 0 ), > > Sle1 = create( EditText, "", Win, 10, 40, 120, 20, 0 ), > Button1 = create( PushButton, "OK", Win, 180, 40, 120, 20, 0 ) > > > procedure onClick_Button1() > > if equal(getText(Sle1),"YES") then > closeWindow(Win) > end if > > end procedure > > onClick[Button1] = routine_id("onClick_Button1") > > WinMain( Win ) > > but if i change the if statement this way, i get an error message: > > if getText(Sle1) = "YES" then > closeWindow(Win) > end if > > error message says, the result of the if statemnt should be an atom. > > so whats it all about? > It means to compare sequences, and therefore any string, you have to use the "equal" or "compare" statements, not = < > !=. Using the latter operators on a sequence is for expressions, and compares each element of a sequence to its counterpart in another sequence of equal length. For instance, s = {8,9,10} = {8,4,10} Now s is {1,0,1}. This facility is very useful, but can make if statements involving sequences a bit non-intuitive. Anyway, you gotta use equal & compare..
2. RE: if statement not working
- Posted by bensler at mail.com Mar 21, 2002
- 468 views
xxmyt at yahoo.com wrote: > hello everyone. > > the code i pasted down works properly. however, it doesnt work in the > second way. > > my code: > include dos32lib.e > without warning > > constant > Win = create( Window, "PASSWORD REQUIRED", 0, Default, Default, > 400, 200, 0 ), > > Sle1 = create( EditText, "", Win, 10, 40, 120, 20, 0 ), > Button1 = create( PushButton, "OK", Win, 180, 40, 120, 20, 0 ) > > > procedure onClick_Button1() > > if equal(getText(Sle1),"YES") then > closeWindow(Win) > end if > > end procedure > > onClick[Button1] = routine_id("onClick_Button1") > > WinMain( Win ) > > but if i change the if statement this way, i get an error message: > > if getText(Sle1) = "YES" then > closeWindow(Win) > end if > > error message says, the result of the if statemnt should be an atom. > > so whats it all about? In oder to compare two objects, which are not both atoms, you must use equal(). if equal(getText(Sle1),"YES") then closeWindow(Win) end if Chris
3. RE: if statement not working
- Posted by bensler at mail.com Mar 21, 2002
- 470 views
Sorry, I misunderstood the question. :P I like the fact that = only works for numeric comparison. I'd like to see == for object comparisons though, instead of equal() Chris xxmyt at yahoo.com wrote: > hello everyone. > > the code i pasted down works properly. however, it doesnt work in the > second way. > > my code: > include dos32lib.e > without warning > > constant > Win = create( Window, "PASSWORD REQUIRED", 0, Default, Default, > 400, 200, 0 ), > > Sle1 = create( EditText, "", Win, 10, 40, 120, 20, 0 ), > Button1 = create( PushButton, "OK", Win, 180, 40, 120, 20, 0 ) > > > procedure onClick_Button1() > > if equal(getText(Sle1),"YES") then > closeWindow(Win) > end if > > end procedure > > onClick[Button1] = routine_id("onClick_Button1") > > WinMain( Win ) > > but if i change the if statement this way, i get an error message: > > if getText(Sle1) = "YES" then > closeWindow(Win) > end if > > error message says, the result of the if statemnt should be an atom. > > so whats it all about? > > >
4. RE: if statement not working
- Posted by bensler at mail.com Mar 21, 2002
- 456 views
Andy Serpa wrote: > > xxmyt at yahoo.com wrote: > > hello everyone. > > > > the code i pasted down works properly. however, it doesnt work in the > > second way. > > > > my code: > > include dos32lib.e > > without warning > > > > constant > > Win = create( Window, "PASSWORD REQUIRED", 0, Default, Default, > > 400, 200, 0 ), > > > > Sle1 = create( EditText, "", Win, 10, 40, 120, 20, 0 ), > > Button1 = create( PushButton, "OK", Win, 180, 40, 120, 20, 0 ) > > > > > > procedure onClick_Button1() > > > > if equal(getText(Sle1),"YES") then > > closeWindow(Win) > > end if > > > > end procedure > > > > onClick[Button1] = routine_id("onClick_Button1") > > > > WinMain( Win ) > > > > but if i change the if statement this way, i get an error message: > > > > if getText(Sle1) = "YES" then > > closeWindow(Win) > > end if > > > > error message says, the result of the if statemnt should be an atom. > > > > so whats it all about? > > > > It means to compare sequences, and therefore any string, you have to use > > the "equal" or "compare" statements, not = < > !=. > > Using the latter operators on a sequence is for expressions, and > compares each element of a sequence to its counterpart in another > sequence of equal length. For instance, > > s = {8,9,10} = {8,4,10} > > Now s is {1,0,1}. > > This facility is very useful, but can make if statements involving > sequences a bit non-intuitive. Anyway, you gotta use equal & compare.. > Could you give an example of how that might be useful? I understand the concept, but I can't wrap my brain around how I could use it. btw: That assignment statement is easier to understand if written: s = ({8,9,10} = {8,4,10}) Chris
5. RE: if statement not working
- Posted by bensler at mail.com Mar 21, 2002
- 460 views
Good point. I have never found the need to use compare, so I was thinking in a narrower spectrum when I mentioned ==. I see two benefits to the current syntax. 1. comparing equal length sequences (does the entire structure of the sequence need to match, or just the length?) 2. to visually define the difference between a numeric compare, and an object compare. See: "justifying compare" posted by David Cuny in 1998 Chris Derek Parnell wrote: > > This, in my not so humble opinion, is one of RDS's lesser decisions. > > For some reason, not quiet explained yet, RDS decided that sequences > must not allowed to be compared > using the normal comparision operators. For sequences you are forced > into calling a function to > compare them. The two main functions are 'compare()' and 'equal()'. > > compare(s1,s2) returns one of three values: > -1 if s1 is less than s2 > 0 if s1 equals s2 > 1 if s1 is greater than s2 > > equal(s1,s2) returns one of two values: > 0 if s1 is not equal to s2 > 1 if s1 is equal to s2 > > Go figure! Many people have been try to get RDS to see sense in using > the standard comparision > operators with sequences but to no avail yet. > > ------- > Derek. > > 22/03/2002 11:04:33 AM, xxmyt at yahoo.com wrote: > > > > >hello everyone. > > > >the code i pasted down works properly. however, it doesnt work in the > >second way. > > > >my code: > >include dos32lib.e > >without warning > > > >constant > > Win = create( Window, "PASSWORD REQUIRED", 0, Default, Default, > >400, 200, 0 ), > > > > Sle1 = create( EditText, "", Win, 10, 40, 120, 20, 0 ), > > Button1 = create( PushButton, "OK", Win, 180, 40, 120, 20, 0 ) > > > > > >procedure onClick_Button1() > > > > if equal(getText(Sle1),"YES") then > > closeWindow(Win) > > end if > > > >end procedure > > > >onClick[Button1] = routine_id("onClick_Button1") > > > >WinMain( Win ) > > > > but if i change the if statement this way, i get an error message: > > > > if getText(Sle1) = "YES" then > > closeWindow(Win) > > end if > > > >error message says, the result of the if statemnt should be an atom. > > > >so whats it all about? > > > > > --------- > Cheers, > Derek Parnell > ICQ# 7647806 > >
6. RE: if statement not working
- Posted by Andy Serpa <renegade at earthling.net> Mar 21, 2002
- 447 views
bensler at mail.com wrote: > Andy Serpa wrote: > > <snip> > > > > s = {8,9,10} = {8,4,10} > > > > Now s is {1,0,1}. > > > > This facility is very useful, but can make if statements involving > > sequences a bit non-intuitive. Anyway, you gotta use equal & compare.. > > > > Could you give an example of how that might be useful? > I understand the concept, but I can't wrap my brain around how I could > use it. > I use it mainly in AI stuff where I need to work on binary strings in an explicit manner. I also use it a lot for stuff like this: x = {10,20,30,40,50,60} y = {30,10,25,40,60,65} z = (x < y)*x + (y <= x)*y z is now: {10,10,25,40,50,60} (taking the smaller element from each sequence -- the "=" is in the second half but not the first so equal elements will only be taken once) Yep, it's useful.
7. Re: RE: if statement not working
- Posted by Derek Parnell <ddparnell at bigpond.com> Mar 21, 2002
- 431 views
22/03/2002 12:43:00 PM, bensler at mail.com wrote: > >I like the fact that = only works for numeric comparison. >I'd like to see == for object comparisons though, instead of equal() > >Chris Why? What problem is having two sets of comparitors solve? Are you suggesting for numbers we use: = > < != <= >= and for sequences we use: == >> << !== <== >== If want to know if one sequence has the same value as another, why is it better that I use "==" instead of "="? It even introduces another issue that the current Euphoria doesn't have. Currently I can write: atom x sequence s if equal(x,s) then ... but your suggestion I'd use: if x == s then ... but what happens if I later change my mind and 's' is now an integer. I have to go and update all my comparitor references to use '=' etc... Is this a better idea? I think not. --------- Derek.
8. RE: if statement not working
- Posted by bensler at mail.com Mar 21, 2002
- 431 views
Refer to the "[If/then and sequences...]" thread from Aug 2000 or the "Comparing Sequences" thread from Oct 2000 Chris Derek Parnell wrote: > > This, in my not so humble opinion, is one of RDS's lesser decisions. > > For some reason, not quiet explained yet, RDS decided that sequences > must not allowed to be compared > using the normal comparision operators. For sequences you are forced > into calling a function to > compare them. The two main functions are 'compare()' and 'equal()'. > > compare(s1,s2) returns one of three values: > -1 if s1 is less than s2 > 0 if s1 equals s2 > 1 if s1 is greater than s2 > > equal(s1,s2) returns one of two values: > 0 if s1 is not equal to s2 > 1 if s1 is equal to s2 > > Go figure! Many people have been try to get RDS to see sense in using > the standard comparision > operators with sequences but to no avail yet. > > ------- > Derek. > > 22/03/2002 11:04:33 AM, xxmyt at yahoo.com wrote: > > > > >hello everyone. > > > >the code i pasted down works properly. however, it doesnt work in the > >second way. > > > >my code: > >include dos32lib.e > >without warning > > > >constant > > Win = create( Window, "PASSWORD REQUIRED", 0, Default, Default, > >400, 200, 0 ), > > > > Sle1 = create( EditText, "", Win, 10, 40, 120, 20, 0 ), > > Button1 = create( PushButton, "OK", Win, 180, 40, 120, 20, 0 ) > > > > > >procedure onClick_Button1() > > > > if equal(getText(Sle1),"YES") then > > closeWindow(Win) > > end if > > > >end procedure > > > >onClick[Button1] = routine_id("onClick_Button1") > > > >WinMain( Win ) > > > > but if i change the if statement this way, i get an error message: > > > > if getText(Sle1) = "YES" then > > closeWindow(Win) > > end if > > > >error message says, the result of the if statemnt should be an atom. > > > >so whats it all about? > > > > > --------- > Cheers, > Derek Parnell > ICQ# 7647806 > >
9. Re: RE: if statement not working
- Posted by Derek Parnell <ddparnell at bigpond.com> Mar 21, 2002
- 454 views
22/03/2002 2:19:34 PM, bensler at mail.com wrote: > >Good point. > >I have never found the need to use compare, so I was thinking in a >narrower spectrum when I mentioned ==. > >I see two benefits to the current syntax. > >1. comparing equal length sequences (does the entire structure of the >sequence need to match, or just the length?) > I am talking about language syntax, not implementation tactics. Is there any reason that the interpreter cannot compare lengths if it sees '=' instead of 'compare()'? >2. to visually define the difference between a numeric compare, and an >object compare. Have you actually needed to do this? Anyone? >See: "justifying compare" posted by David Cuny in 1998 I will. David is very good, but I'm not convinced yet. Keep trying --------- Cheers, Derek Parnell ICQ# 7647806
10. RE: if statement not working
- Posted by Kat <gertie at PELL.NET> Mar 21, 2002
- 454 views
On 22 Mar 2002, at 4:10, bensler at mail.com wrote: > > Refer to the "[If/then and sequences...]" thread from Aug 2000 > or the "Comparing Sequences" thread from Oct 2000 How about it, Karl, a fall-thru the "=" to the equal()? Kat > Chris > > Derek Parnell wrote: > > > > This, in my not so humble opinion, is one of RDS's lesser decisions. > > > > For some reason, not quiet explained yet, RDS decided that sequences > > must not allowed to be compared > > using the normal comparision operators. For sequences you are forced > > into calling a function to > > compare them. The two main functions are 'compare()' and 'equal()'. > > > > compare(s1,s2) returns one of three values: > > -1 if s1 is less than s2 > > 0 if s1 equals s2 > > 1 if s1 is greater than s2 > > > > equal(s1,s2) returns one of two values: > > 0 if s1 is not equal to s2 > > 1 if s1 is equal to s2 > > > > Go figure! Many people have been try to get RDS to see sense in using > > the standard comparision > > operators with sequences but to no avail yet. > > > > ------- > > Derek. > > > > 22/03/2002 11:04:33 AM, xxmyt at yahoo.com wrote: > > > > > > > >hello everyone. > > > > > >the code i pasted down works properly. however, it doesnt work in the > > >second way. > > > > > >my code: > > >include dos32lib.e > > >without warning > > > > > >constant > > > Win = create( Window, "PASSWORD REQUIRED", 0, Default, Default, > > >400, 200, 0 ), > > > > > > Sle1 = create( EditText, "", Win, 10, 40, 120, 20, 0 ), > > > Button1 = create( PushButton, "OK", Win, 180, 40, 120, 20, 0 ) > > > > > > > > >procedure onClick_Button1() > > > > > > if equal(getText(Sle1),"YES") then > > > closeWindow(Win) > > > end if > > > > > >end procedure > > > > > >onClick[Button1] = routine_id("onClick_Button1") > > > > > >WinMain( Win ) > > > > > > but if i change the if statement this way, i get an error message: > > > > > > if getText(Sle1) = "YES" then > > > closeWindow(Win) > > > end if > > > > > >error message says, the result of the if statemnt should be an atom. > > > > > >so whats it all about? > > > > > > > > --------- > > Cheers, > > Derek Parnell > > ICQ# 7647806 > > > > > > > > >
11. RE: if statement not working
- Posted by bensler at mail.com Mar 21, 2002
- 442 views
equal() us just a derivitive of compare() function equal(object a, object b) return not compare(a,b) end function every relational operator can be mapped directly to compare(). a =b : compare(a,b) =0 a!=b : compare(a,b) !=0 a <b : compare(a,b) <0 a>=b : compare(a,b) >=0 etc... refer specifically to Derek Parnell's post "Re:[If/then and sequences...]" Chris Kat wrote: > On 22 Mar 2002, at 4:10, bensler at mail.com wrote: > > > > > Refer to the "[If/then and sequences...]" thread from Aug 2000 > > or the "Comparing Sequences" thread from Oct 2000 > > How about it, Karl, a fall-thru the "=" to the equal()? > > Kat > > > Chris > > > > Derek Parnell wrote: > > > > > > This, in my not so humble opinion, is one of RDS's lesser decisions. > > > > > > For some reason, not quiet explained yet, RDS decided that sequences > > > must not allowed to be compared > > > using the normal comparision operators. For sequences you are forced > > > into calling a function to > > > compare them. The two main functions are 'compare()' and 'equal()'. > > > > > > compare(s1,s2) returns one of three values: > > > -1 if s1 is less than s2 > > > 0 if s1 equals s2 > > > 1 if s1 is greater than s2 > > > > > > equal(s1,s2) returns one of two values: > > > 0 if s1 is not equal to s2 > > > 1 if s1 is equal to s2 > > > > > > Go figure! Many people have been try to get RDS to see sense in using > > > the standard comparision > > > operators with sequences but to no avail yet. > > > > > > ------- > > > Derek. > > > > > > 22/03/2002 11:04:33 AM, xxmyt at yahoo.com wrote: > > > > > > > > > > >hello everyone. > > > > > > > >the code i pasted down works properly. however, it doesnt work in the > > > >second way. > > > > > > > >my code: > > > >include dos32lib.e > > > >without warning > > > > > > > >constant > > > > Win = create( Window, "PASSWORD REQUIRED", 0, Default, Default, > > > >400, 200, 0 ), > > > > > > > > Sle1 = create( EditText, "", Win, 10, 40, 120, 20, 0 ), > > > > Button1 = create( PushButton, "OK", Win, 180, 40, 120, 20, 0 ) > > > > > > > > > > > >procedure onClick_Button1() > > > > > > > > if equal(getText(Sle1),"YES") then > > > > closeWindow(Win) > > > > end if > > > > > > > >end procedure > > > > > > > >onClick[Button1] = routine_id("onClick_Button1") > > > > > > > >WinMain( Win ) > > > > > > > > but if i change the if statement this way, i get an error message: > > > > > > > > if getText(Sle1) = "YES" then > > > > closeWindow(Win) > > > > end if > > > > > > > >error message says, the result of the if statemnt should be an atom. > > > > > > > >so whats it all about? > > > > > > > > > > > --------- > > > Cheers, > > > Derek Parnell > > > ICQ# 7647806 > > > > > >
12. RE: if statement not working
- Posted by bensler at mail.com Mar 22, 2002
- 479 views
Graeme wrote: > > >I just tripped against this stupid restriction again last night. I've > written a function called > >begins() to help me out, but it ain't pretty. > > > > if begins(s, t) then ... > > > >I originally wrote: > > > > if equal(s[1..length(t)], t) then ... > > > >but this fails whenever s is shorter than t. > > > Yeah, and I hate having to press enter at the end of the > line, it really annoys me. Rob can you fix this or I want my > money back..... > > > But seriously, having the interpreter return a valid result > from accessing non-existant data is just way stupid. > > > Graeme I agree with Graeme on this one :P Here is a function that I sometimes use for formatting sequences. function format(sequence s, sequence form) if length(s) < length(form) then return s & form[length(s)+1..length(form)] elsif length(s) > length(form) then return s[1..length(form)] end if return s end function Dereks problem would be written: if equal(format(s,t),t) then ... (I'd much rather write: if format(s,t) = t then ... ) In particular, I find it handy for declaring my routines like this: procedure foo(sequence args) args = format(args,{1,0,{},"none"}) etc... end procedure This allows the routine to be called with a dynamic number of arguments. If some of the trailing arguments are omitted, they are appended using the defaults. This also lends to expandability, and a bunch of other convenient things. Chris
13. RE: if statement not working
- Posted by bensler at mail.com Mar 22, 2002
- 457 views
Graeme wrote: > > >I just tripped against this stupid restriction again last night. I've > written a function called > >begins() to help me out, but it ain't pretty. > > > > if begins(s, t) then ... > > > >I originally wrote: > > > > if equal(s[1..length(t)], t) then ... > > > >but this fails whenever s is shorter than t. > > > Yeah, and I hate having to press enter at the end of the > line, it really annoys me. Rob can you fix this or I want my > money back..... If yer gonna ask for something silly, it should at least NOT be implemented already :P The only reason you have to press enter is because your editor limits you. Euphoria will accept any file regardless of line feeds and carriage returns, as long as each statement is separated with whitespace. I compacted my minesweeper source code (@ 15,000 bytes) into a single line, and executed it. Chris
14. RE: if statement not working
- Posted by bensler at mail.com Mar 22, 2002
- 455 views
Kat wrote: > On 22 Mar 2002, at 23:24, Derek Parnell wrote: > > > > > ----- Original Message ----- > > From: "Graeme" <graemeburke at hotmail.com> > > To: "EUforum" <EUforum at topica.com> > > Sent: Friday, March 22, 2002 7:20 PM > > Subject: Re: if statement not working > > > > > > > >I just tripped against this stupid restriction again last night. I've > > > written a function called > > > >begins() to help me out, but it ain't pretty. > > > > > > > > if begins(s, t) then ... > > > > > > > >I originally wrote: > > > > > > > > if equal(s[1..length(t)], t) then ... > > > > > > > >but this fails whenever s is shorter than t. > > > > > > > > > Yeah, and I hate having to press enter at the end of the > > > line, it really annoys me. Rob can you fix this or I want my > > > money back..... > > > > > > > Thanks for those encouraging words. I feel much better now that I > > realise I must > > not desecrate the temple of Euphoria. > > > > > But seriously, having the interpreter return a valid result > > > from accessing non-existant data is just way stupid. > > > > > > > Graeme, you are absolutely correct. > > So if i were to ask you to return all 100K bytes of this email, you'd > land in a > mental institution? Eu would, figuratively speaking. > > Kat > That's not natural behaviour. When you tell me to to return 100kb of this file, I'll tell you it's not 100kb. I won't give you the file padded with.. what SHOULD it be padded with? If you told me to give you 100kb of this file, or whatever I can if it's not that big, then I would give you about 10kb of data. If you told me I MUST return 100kb from this file, I would then proceed to ask what I should append to the data. Chris
15. RE: if statement not working
- Posted by Rod Jackson <rodjackson_x at hotmail.com> Mar 23, 2002
- 435 views
David Cuny wrote: > rforno wrote: > > > if s[1..2] = "/*" then ... > > could never work fine. It gives an error message telling conditions must > > be > > atoms. > > Yes, and that's perhaps the most suprising bit of all. You'd sort of > expect > that with an emphasis on being orthagonal, the 'if' would accept {0, 0} > as > false, and { 0, 1 } as true. Well, I'm kinda late into this thread, but I have to ask: Why would {0,1} be logically assumed to be true? I can't think of any reason for it to be seen as such that's obviously superior to all the reasons why it should be seen as false, or as invalid. (Serious question there. If there's some reason I'm missing, I'd be interested in hearing it, as the concept might have value in several places.) As of right now, I think having a sequence not be accepted as a statement of truth or falsehood makes sense; that being the case, a function like 'equal' becomes required to compare slices/strings. With THAT being the case, a large portion of this thread becomes moot, yes? Rod Jackson
16. RE: if statement not working
- Posted by Rod Jackson <rodjackson_x at hotmail.com> Mar 23, 2002
- 452 views
Graeme wrote: > At 06:10 PM 3/22/02 -0600, Kat wrote: > > > > >So stop with the padding already! When can i expect that $30? > > > > so if s="hello" > > s[2..4] is "ell" > s[-1..2] is "he" > s[5..6] is "o" > and s[34..39] is {} > > > interesting idea. > I still dont like it that much... Ditto. I think many are forgetting that we're not really talking just about the 'if' statement here, but rather how subscripting operates as an expression. Euphoria spends, I would imagine, a bit of time during runtime making sure you don't try to access an invalid index. The safety of that implementation is supposed to be a selling point. Now, suddenly, ALL indices should be valid for EVERY sequence? Is that *really* what we want? Rod Jackson