1. Help Please with numbers
- Posted by "Rangel, Hebert Rogelio" <hrangel at demet.com.mx> Aug 01, 2005
- 667 views
hello, when i try to do any mathematical operation it gives a letter as answer, li if i say <eu> global constant EditText20 = create( EditText, "", Window1, 356, 8, 32, 20, 0 ) global constant EditText21 = create( EditText, "", Window1, 396, 8, 88, 20, 0 ) global constant Button1 = create( PushButton, "ok", Window1, 20, 36, 56, 24, 0 ) object r1 object r2 object r3 object r4 r1 = getText(EditText20) r2 = getText(Edittext21) r3 = r1 + r2 r4 = message_box(r1 & "/" & r2,"OK", 0) </eu> it gives a letter as result i know i have to change the r1 and r2 to number but how?! thanks 4 u help
2. Re: Help Please with numbers
- Posted by CoJaBo <CoJaBo_7th_EUforum_Address at CJBN.net> Aug 01, 2005
- 618 views
Rangel, Hebert Rogelio wrote: > > hello, when i try to do any mathematical operation it gives a letter as > answer, li This is one of the basics of Euphoria atoms: http://www.rapideuphoria.com/refman_2.htm#11 Please read the manual, either in the EUPHORIA\HTML folder, or online at http://www.rapideuphoria.com/manual.htm > if i say > > <eu> > > global constant EditText20 = create( EditText, "", Window1, 356, 8, 32, 20, 0 > ) > global constant EditText21 = create( EditText, "", Window1, 396, 8, 88, 20, 0 > ) > global constant Button1 = create( PushButton, "ok", Window1, 20, 36, 56, 24, 0 > ) > > object r1 > object r2 > object r3 > object r4 > > r1 = getText(EditText20) > r2 = getText(Edittext21) > r3 = r1 + r2 > r4 = message_box(r1 & "/" & r2,"OK", 0) That should be somthing like message_box(sprint(r1) & "/" & sprint(r2),"OK", 0) > > </eu> > > it gives a letter as result i know i have to change the r1 and r2 to number > but how?! > thanks 4 u help > >
3. Re: Help Please with numbers
- Posted by cklester <cklester at yahoo.com> Aug 01, 2005
- 616 views
Rangel, Hebert Rogelio wrote: > > object r1 > object r2 > object r3 > object r4 > > r1 = getText(EditText20) > r2 = getText(Edittext21) > r3 = r1 + r2 This is an argument for ESL's sum() function being able to handle all types... sequence r1, r2 integer r3, r4 atom total r1 = getText(EditText20) r2 = getText(Edittext21) r3 = 34 r4 = 15 total = sum({r1,r2}) total += sum({r3,r4}) -=ck "Programming in a state of EUPHORIA." http://www.cklester.com/euphoria/
4. Re: Help Please with numbers
- Posted by Jason Gade <jaygade at yahoo.com> Aug 01, 2005
- 626 views
cklester wrote: > > Rangel, Hebert Rogelio wrote: > > > > object r1 > > object r2 > > object r3 > > object r4 > > > > r1 = getText(EditText20) > > r2 = getText(Edittext21) > > r3 = r1 + r2 > > This is an argument for ESL's sum() function being able to handle all types... > > sequence r1, r2 > integer r3, r4 > atom total > > r1 = getText(EditText20) > r2 = getText(Edittext21) > r3 = 34 > r4 = 15 > total = sum({r1,r2}) > total += sum({r3,r4}) > > -=ck > "Programming in a state of EUPHORIA." > <a > href="http://www.cklester.com/euphoria/">http://www.cklester.com/euphoria/</a> > or just total = sum({r1, r2, r3, r4}) I first came up with the need for a sum() function when I was playing around with making a die-roller.===================================== Too many freaks, not enough circuses. j.
5. Re: Help Please with numbers
- Posted by Jason Gade <jaygade at yahoo.com> Aug 01, 2005
- 600 views
Jason Gade wrote: > > cklester wrote: > > > > Rangel, Hebert Rogelio wrote: > > > > > > object r1 > > > object r2 > > > object r3 > > > object r4 > > > > > > r1 = getText(EditText20) > > > r2 = getText(Edittext21) > > > r3 = r1 + r2 > > > > This is an argument for ESL's sum() function being able to handle all > > types... > > > > sequence r1, r2 > > integer r3, r4 > > atom total > > > > r1 = getText(EditText20) > > r2 = getText(Edittext21) > > r3 = 34 > > r4 = 15 > > total = sum({r1,r2}) > > total += sum({r3,r4}) > > > > -=ck > > "Programming in a state of EUPHORIA." > > <a > > href="http://www.cklester.com/euphoria/">http://www.cklester.com/euphoria/</a> > > > or just > total = sum({r1, r2, r3, r4}) Oops, sorry. I guess that you meant that r1 and r2 are text representations of numbers. How would sum know that? > > ===================================== > Too many freaks, not enough circuses. > > j. > ===================================== Too many freaks, not enough circuses. j.
6. Re: Help Please with numbers
- Posted by cklester <cklester at yahoo.com> Aug 01, 2005
- 597 views
Jason Gade wrote: > Jason Gade wrote: > > cklester wrote: > > > This is an argument for ESL's sum() function being able to handle all > > > types... > > > sequence r1, r2 > > > integer r3, r4 > > > atom total > > > r1 = getText(EditText20) > > > r2 = getText(Edittext21) > > > r3 = 34 > > > r4 = 15 > > > total = sum({r1,r2}) > > > total += sum({r3,r4}) > > Oops, sorry. I guess that you meant that r1 and r2 are text representations > of numbers. > How would sum know that? It's gonna hafta be smart about it! r1 = "123" r2 = 456 total = sum({r1,r2}) -- can work since element 1 is a sequence, use value() -=ck "Programming in a state of EUPHORIA." http://www.cklester.com/euphoria/
7. Re: Help Please with numbers
- Posted by Jason Gade <jaygade at yahoo.com> Aug 01, 2005
- 592 views
cklester wrote: > > Jason Gade wrote: > > Jason Gade wrote: > > > cklester wrote: > > > > This is an argument for ESL's sum() function being able to handle all > > > > types... > > > > sequence r1, r2 > > > > integer r3, r4 > > > > atom total > > > > r1 = getText(EditText20) > > > > r2 = getText(Edittext21) > > > > r3 = 34 > > > > r4 = 15 > > > > total = sum({r1,r2}) > > > > total += sum({r3,r4}) > > > > Oops, sorry. I guess that you meant that r1 and r2 are text representations > > of numbers. > > How would sum know that? > > It's gonna hafta be smart about it! > > r1 = "123" > r2 = 456 > total = sum({r1,r2}) -- can work since element 1 is a sequence, use value() > > -=ck > "Programming in a state of EUPHORIA." > <a > href="http://www.cklester.com/euphoria/">http://www.cklester.com/euphoria/</a> > Duh! sorry, I can be pretty dense sometimes!===================================== Too many freaks, not enough circuses. j.
8. Re: Help Please with numbers
- Posted by Jason Gade <jaygade at yahoo.com> Aug 01, 2005
- 598 views
Jason Gade wrote: > > cklester wrote: > > > > Jason Gade wrote: > > > Jason Gade wrote: > > > > cklester wrote: > > > > > This is an argument for ESL's sum() function being able to handle all > > > > > types... > > > > > sequence r1, r2 > > > > > integer r3, r4 > > > > > atom total > > > > > r1 = getText(EditText20) > > > > > r2 = getText(Edittext21) > > > > > r3 = 34 > > > > > r4 = 15 > > > > > total = sum({r1,r2}) > > > > > total += sum({r3,r4}) > > > > > > Oops, sorry. I guess that you meant that r1 and r2 are text > > > representations of numbers. > > > How would sum know that? > > > > It's gonna hafta be smart about it! > > > > r1 = "123" > > r2 = 456 > > total = sum({r1,r2}) -- can work since element 1 is a sequence, use value() > > > > -=ck > > "Programming in a state of EUPHORIA." So I'm trying to think of a reason why this would be a bad idea, and I can't do it. The only valid reason I could come up with is that no other Euphoria routine acts this way (that I know of). That isn't really a valid argument though. Since sum shouldn't be infinitely recursive (maybe recursive_sum() could be a different function...) keying on whether top-level elements are sequences is a good idea. Even if we make s string library like I propose that has packed strings and Unicode strings, an ESL version of value() should be able to differentiate. Hmmm. ===================================== Too many freaks, not enough circuses. j.
9. Re: Help Please with numbers
- Posted by cklester <cklester at yahoo.com> Aug 01, 2005
- 602 views
- Last edited Aug 02, 2005
Jason Gade wrote: > Jason Gade wrote: > > cklester wrote: > > > > > > r1 = "123" > > > r2 = 456 > > > total = sum({r1,r2}) -- can work since element 1 is a sequence, use > > > value() > > > > > So I'm trying to think of a reason why this would be a bad idea, and I can't > do it. > The only valid reason I could come up with is that no other Euphoria routine > acts this > way (that I know of). That isn't really a valid argument though. All it is is shorthand for the programmer doing the value()s himself. You could also make type-specific sums like sum_i(list_of_integers) sum_a(list_of_atoms) -- or sumi() and suma() depending on naming convention These would simply be faster (no sequence check or value() conversion) and used when the programmer has no string numbers. -=ck "Programming in a state of EUPHORIA." http://www.cklester.com/euphoria/
10. Re: Help Please with numbers
- Posted by Dave Probert <zingo at purpletiger.com> Aug 01, 2005
- 613 views
- Last edited Aug 02, 2005
>From the example you give you are using Win32Lib, and there is a simple way to >get a numerical value from a textfield - use getNumber(...) instead of getText(). Or else use get() - a Euphoria core function - read the manual for details. Please note the documentation with Euphoria about the use of atoms and sequences - some aspects that every new user should be aware of. > Rangel, Hebert Rogelio wrote: > > > > object r1 > > object r2 > > object r3 > > > > r1 = getText(EditText20) > > r2 = getText(Edittext21) > > r3 = r1 + r2 > <snip> Cheers, Dave . .. : :: = == == = :: : .. . Server-Side DB driven web sites, Software Development (and part-time games developer) contact dave_p at purpletiger dot com or probert.dave at gmail dot com . .. : :: = == == = :: : .. .
11. Re: Help Please with numbers
- Posted by Pete Lomax <petelomax at blueyonder.co.uk> Aug 01, 2005
- 610 views
- Last edited Aug 02, 2005
On Mon, 01 Aug 2005 13:00:19 -0700, Jason Gade <guest at RapidEuphoria.com> wrote: >So I'm trying to think of a reason why this would be a bad idea, and I can't do >it. The only valid reason I can come up with is performance. If, for example, a test case or two proves that abs(atom a) is a shed load faster than abs(object x), then we should have say abs() and abso(). Otherwise I agree that most routines should be as flexible as can be sensibly designed and documented. Regards, Pete
12. Re: Help Please with numbers
- Posted by Pete Lomax <petelomax at blueyonder.co.uk> Aug 01, 2005
- 601 views
- Last edited Aug 02, 2005
On Mon, 01 Aug 2005 11:33:31 -0700, cklester <guest at RapidEuphoria.com> wrote: >This is an argument for ESL's sum() function being able to handle all types... Write some documentation for it & we'll see. Holes in this example aside, there is a clear difference between expectation of sum({49,50,51}) and sum("123"). That is deliberately not a damning argument against, but I hope it is a clear argument for the need for agreed documentation before the first line of code is cut, or as near as possible to that. Regards, Pete
13. Re: Help Please with numbers
- Posted by don cole <doncole at pacbell.net> Aug 02, 2005
- 602 views
Rangel, Hebert Rogelio wrote: > > hello, when i try to do any mathematical operation it gives a letter as > answer, li > if i say > > <eu> > > global constant EditText20 = create( EditText, "", Window1, 356, 8, 32, 20, 0 > ) > global constant EditText21 = create( EditText, "", Window1, 396, 8, 88, 20, 0 > ) > global constant Button1 = create( PushButton, "ok", Window1, 20, 36, 56, 24, 0 > ) > > object r1 > object r2 > object r3 > object r4 > > r1 = getText(EditText20) > r2 = getText(Edittext21) > r3 = r1 + r2 > r4 = message_box(r1 & "/" & r2,"OK", 0) > > </eu> > > it gives a letter as result i know i have to change the r1 and r2 to number > but how?! > thanks 4 u help > > r1=getNumber(EditText20) r2=getNumber(EditText21) Don Cole, SF
14. Re: Help Please with numbers
- Posted by cklester <cklester at yahoo.com> Aug 02, 2005
- 609 views
Pete Lomax wrote: > > On Mon, 01 Aug 2005 11:33:31 -0700, cklester <guest at RapidEuphoria.com> > wrote: > > >This is an argument for ESL's sum() function being able to handle all > >types... > > Holes in this example aside, there is a clear difference between > expectation of sum({49,50,51}) and sum("123"). Good catch. ;) -=ck "Programming in a state of EUPHORIA." http://www.cklester.com/euphoria/
15. Re: Help Please with numbers
- Posted by Jason Gade <jaygade at yahoo.com> Aug 02, 2005
- 596 views
cklester wrote: > > Pete Lomax wrote: > > > > On Mon, 01 Aug 2005 11:33:31 -0700, cklester <guest at RapidEuphoria.com> > > wrote: > > > > >This is an argument for ESL's sum() function being able to handle all > > >types... > > > > Holes in this example aside, there is a clear difference between > > expectation of sum({49,50,51}) and sum("123"). > > Good catch. ;) > > -=ck > "Programming in a state of EUPHORIA." > <a > href="http://www.cklester.com/euphoria/">http://www.cklester.com/euphoria/</a> > I had thought about this case. I think that the programmer would just have to be clear in what he or she wants. sum(1) makes as much sense as sum("123"). sum("123", 0) should work correctly. sum("123") would produce 150 because it is ambiguous. I still wonder whether it would be a useful feature. How often is implicit conversion from string to number needed? ===================================== Too many freaks, not enough circuses. j.
16. Re: Help Please with numbers
- Posted by cklester <cklester at yahoo.com> Aug 02, 2005
- 611 views
Jason Gade wrote: > > I had thought about this case. I think that the programmer would just have to > be clear > in what he or she wants. sum(1) makes as much sense as sum("123"). > > sum("123", 0) should work correctly. sum("123") would produce 150 because it > is ambiguous. > > I still wonder whether it would be a useful feature. How often is implicit > conversion > from string to number needed? You could just provide the base functionality of summing only integers/atoms in a sequence, and if the user wanted more they could wrap it themselves. sumi() -- sum a list of integers suma() -- sum a list of atoms sum() -- sum a list of atoms and/or integers -=ck "Programming in a state of EUPHORIA." http://www.cklester.com/euphoria/
17. Re: Help Please with numbers
- Posted by Jason Gade <jaygade at yahoo.com> Aug 02, 2005
- 618 views
cklester wrote: > > Jason Gade wrote: > > > > I had thought about this case. I think that the programmer would just have > > to be clear > > in what he or she wants. sum(1) makes as much sense as sum("123"). > > > > sum("123", 0) should work correctly. sum("123") would produce 150 because it > > is ambiguous. > > > > I still wonder whether it would be a useful feature. How often is implicit > > conversion > > from string to number needed? > > You could just provide the base functionality of summing only integers/atoms > in a sequence, and if the user wanted more they could wrap it themselves. > > sumi() -- sum a list of integers > suma() -- sum a list of atoms > sum() -- sum a list of atoms and/or integers > > -=ck > "Programming in a state of EUPHORIA." > <a > href="http://www.cklester.com/euphoria/">http://www.cklester.com/euphoria/</a> > For me, atoms and integers should be the same and should be the default case. If adding a sum() function that took strings as input, it would be the one with a different name because it is the exceptional case. One of my favorite features of Euphoria is its value-based semantics. A large set of numbers can be represented by atoms. Every value in Euphoria is either an atom or a sequence, therefore a number or a list of numbers. It is up to the programmer to interpret them. ===================================== Too many freaks, not enough circuses. j.
18. Re: Help Please with numbers
- Posted by cklester <cklester at yahoo.com> Aug 02, 2005
- 609 views
Jason Gade wrote: > cklester wrote: > > > > You could just provide the base functionality of summing only integers/atoms > > in a sequence, and if the user wanted more they could wrap it themselves. > > > > sumi() -- sum a list of integers > > suma() -- sum a list of atoms > > sum() -- sum a list of atoms and/or integers > > For me, atoms and integers should be the same and should be the default case. > If adding > a sum() function that took strings as input, it would be the one with a > different name > because it is the exceptional case. I agree that sum() should receive a sequence of numbers (that is, atoms and/or integers), and the user is responsible for everything else (for example, conversion of data before/after using sum()). -=ck "Programming in a state of EUPHORIA." http://www.cklester.com/euphoria/
19. Re: Help Please with numbers
- Posted by Pete Lomax <petelomax at blueyonder.co.uk> Aug 02, 2005
- 574 views
On Tue, 02 Aug 2005 06:27:35 -0700, Jason Gade <guest at RapidEuphoria.com> wrote: >I think that the programmer would just have to be clear in what he or she >wants. I take it you mean the person who designs, documents, and codes sum(), rather than the person that uses it. > sum(1) makes as much sense as sum("123"). I did say "Holes in this example aside". > >sum("123", 0) should work correctly. So, is the result {49,50,51}, as in {49+0,50+0,51+0}, or 123? The answer is obvious once the statement "sum returns a single atomic value" has been made, but thus far I did not see such. Recall that in Euphoria {1,2,3}+{4,5,6} yields {5,7,9}. >sum("123") would produce 150 because it is ambiguous. The point I was trying to make was that the design and documentation of the sum() function should remove any such ambiguity. If sum("123") compiles cleanly and does not trigger a run-time error, then any result must be valid, unequivocal, and documented. > >I still wonder whether it would be a useful feature. How often is implicit >conversion from string to number needed? It depends where the data came from, and to some extent how useful you would consider a sum function in the first place. If we assume that the main reason anyone would use a sum function rather than inline +'s is because they are in a [nested] sequence of unknown length, then you have to ask what is the most likely source? Personally I suspect text files or web pages will be more common than say results from dir(). Regards, Pete
20. Re: Help Please with numbers
- Posted by Jason Gade <jaygade at yahoo.com> Aug 02, 2005
- 614 views
- Last edited Aug 03, 2005
Pete Lomax wrote: > > On Tue, 02 Aug 2005 06:27:35 -0700, Jason Gade > <guest at RapidEuphoria.com> wrote: > > >I think that the programmer would just have to be clear in what he or she > >wants. > I take it you mean the person who designs, documents, and codes sum(), > rather than the person that uses it. Okay, assuming the programmer who uses sum understands the design and documentation of sum then he or she will just have to be clear in what he or she wants. > > sum(1) makes as much sense as sum("123"). > I did say "Holes in this example aside". > > > >sum("123", 0) should work correctly. > So, is the result {49,50,51}, as in {49+0,50+0,51+0}, or 123? The > answer is obvious once the statement "sum returns a single atomic > value" has been made, but thus far I did not see such. Recall that in > Euphoria {1,2,3}+{4,5,6} yields {5,7,9}. > >sum("123") would produce 150 because it is ambiguous. > The point I was trying to make was that the design and documentation > of the sum() function should remove any such ambiguity. If sum("123") > compiles cleanly and does not trigger a run-time error, then any > result must be valid, unequivocal, and documented. > > > >I still wonder whether it would be a useful feature. How often is implicit > >conversion from string > to number needed?</font></i> > It depends where the data came from, and to some extent how useful you > would consider a sum function in the first place. If we assume that > the main reason anyone would use a sum function rather than inline +'s > is because they are in a [nested] sequence of unknown length, then you > have to ask what is the most likely source? Personally I suspect text > files or web pages will be more common than say results from dir(). > > Regards, > Pete > > sum Syntax: x2 = sum(x1) Description: Calculate the sum of all top-level elements of x1. Comments: This function may be applied to a single level sequence or a multi-level sequence. In the case of a mult-level sequence, all elements must be atoms or sequences with the same length. This function is useful for adding up a list of numbers of unknown length. Example 1:}}} <eucode>x = sum({1, 3, 5, 7, 9}) -- x is 25</eucode> {{{ Example 2:}}} <eucode>x = sum({1, 2, 3}, 4, {5, 6, 7}) -- x is {10, 12, 14}</eucode> {{{ Example 3:}}} <eucode>x = sum({49, 50, 51}, {52, 53}) -- yields an error</eucode> {{{ See Also: rsum (recursive sum) Anyway, at first ck's suggestion seemed reasonable and I could'nt *completely* poke a hole in it. I considered your example and I considered ways around it. I just think that it shouldn't implicitly convert strings to values because 1. The programmer can explicitly do it with value() 2. It could lead to ambiguity 3. It's just not the way things are done. ===================================== Too many freaks, not enough circuses. j.
21. Re: Help Please with numbers
- Posted by cklester <cklester at yahoo.com> Aug 02, 2005
- 607 views
- Last edited Aug 03, 2005
Jason, I agree with the definition you've provided below... with some notes: > sum > > Syntax: x2 = sum(x1) Can we use 's'-prefixed variables to indicate sequences? Otherwise, you'll have to explicity state what types of parameters the function receives/returns. s2 = sum(s1) a1 = 1.2 * 6.5 i1 = 3 + 8 for c=1 to 10 -- 'c' is a 'counter' > Comments: This function may be applied to a single level sequence or a > multi-level > sequence. In the case of a mult-level sequence, all elements must be atoms or > sequences > with the same length. > > This function is useful for adding up a list of numbers of unknown length. > > Example 1:}}} <eucode>x = sum({1, 3, 5, 7, 9}) > > Example 2:}}} <eucode>x = sum({1, 2, 3}, 4, {5, 6, 7}) > Example 3:}}} <eucode>x = sum({49, 50, 51}, {52, 53}) You probably meant Example 2: x = sum({{1, 2, 3}, 4, {5, 6, 7}}) Example 3: x = sum({{49, 50, 51}, {52, 53}}) unless Euphoria has variable parameters now!!! :) > Anyway, at first ck's suggestion seemed reasonable and I could'nt *completely* > poke > a hole in it. It's not reasonable for a "standard Euphoria" library, but maybe for the sum.e include file. :) -=ck "Programming in a state of EUPHORIA." http://www.cklester.com/euphoria/
22. Re: Help Please with numbers
- Posted by Jason Gade <jaygade at yahoo.com> Aug 02, 2005
- 579 views
- Last edited Aug 03, 2005
cklester wrote: > > Jason, I agree with the definition you've provided below... with some notes: > > > sum > > > > Syntax: x2 = sum(x1) > > Can we use 's'-prefixed variables to indicate sequences? Otherwise, you'll > have to explicity state what types of parameters the function > receives/returns. Actually I was referring the Euphoria documentation and used RDS style straight from sqrt(). I know we agreed to at least do this differently but I was just responding quickly. > > s2 = sum(s1) > a1 = 1.2 * 6.5 > i1 = 3 + 8 > for c=1 to 10 -- 'c' is a 'counter' > > > Comments: This function may be applied to a single level sequence or a > > multi-level > > sequence. In the case of a mult-level sequence, all elements must be atoms > > or sequences > > with the same length. > > > > This function is useful for adding up a list of numbers of unknown length. > > > > Example 1:}}} <eucode>x = sum({1, 3, 5, 7, 9}) > > > > Example 2:}}} <eucode>x = sum({1, 2, 3}, 4, {5, 6, 7}) > > Example 3:}}} <eucode>x = sum({49, 50, 51}, {52, 53}) > > You probably meant > > Example 2: x = sum({{1, 2, 3}, 4, {5, 6, 7}}) > Example 3: x = sum({{49, 50, 51}, {52, 53}}) > > unless Euphoria has variable parameters now!!! :) Yes, that is why specifications should be proofread *before* actually writing code> > > Anyway, at first ck's suggestion seemed reasonable and I could'nt > > *completely* poke > > a hole in it. > > It's not reasonable for a "standard Euphoria" library, but maybe for the > sum.e include file. :) > > -=ck > "Programming in a state of EUPHORIA." > http://www.cklester.com/euphoria/ > ===================================== Too many freaks, not enough circuses. j.
23. Re: Help Please with numbers
- Posted by Jason Gade <jaygade at yahoo.com> Aug 02, 2005
- 605 views
- Last edited Aug 03, 2005
Oh, and sum() would take an object and return an object. If it received an atom it would just return the same atom. ===================================== Too many freaks, not enough circuses. j.