1. true/false atoms?
- Posted by Kat <KSMiTH at PELL.NET> Aug 12, 1999
- 569 views
Hi all, I am having a dense week here, and i don't understand something. I am trying to stop writing code that uses "goto"s.... porting some pascal to Eu.. So this code gives me an error: datafound is an object set to "false". data and datatofind are sequences, datatofind is a legit sequence. dctstrfile is set to 3 by a previous "open" function at this point. while datafound = "false" or data != -1 do data = gets(dctstrfile) if ( find(datatofind,data) != 0 ) then datafound = "true" end if end while Error: true/false condition must be an atom. Data can't be an atom, because i am reading strings into it, and when i made datafound into an atom, i couldn't set it to "false". I also tried putting the two boolean tests in parentheses, and got the same error. I like parentheses as much as i like "goto". A "goto EndOfProc" or "goto GetTheRestOfTheData" in the read loop would eliminate several boolean tests after this code loop and several levels of nested "if"s. I am using win95, with the code as a text icon on the desktop, with a shortcut to Exw below it, to run the program, i just drag the text icon to the Exw icon. Is that fully ok? Thanks, Kat
2. Re: true/false atoms?
- Posted by David Cuny <dcuny at LANSET.COM> Aug 11, 1999
- 532 views
- Last edited Aug 12, 1999
Kat wrote: >while datafound = "false" or data != -1 do The '=' operator can't be used here. Try instead: while equal( datafound, "false" ) or data != -1 do or (ick): while compare( datafound, "false" ) = 0 or data != -1 do or (shudder): while not compare( datafound, "false" ) or data != -1 do Thanks again, Rob, for adding the 'equal' function! -- David Cuny
3. Re: true/false atoms?
- Posted by Pete Eberlein <xseal at HARBORSIDE.COM> Aug 11, 1999
- 520 views
- Last edited Aug 12, 1999
> >while datafound = "false" or data != -1 do > > The '=' operator can't be used here. Try instead: > > while equal( datafound, "false" ) or data != -1 do While this solves the first "Error: true/false condition must be an atom", the second test "data != -1" will cause the same error. You must declare data as an "object" because the gets function will return -1 when it reaches end-of-file. "But that's I'm testing for!!!" you say, but remember all the while data will be a sequence of text read from the file... for instance say data holds {1,1,2,3,5,8}. The result of "data != -1" will be "{1,1,2,3,5,8} != -1" whose result is the same as "{1 != -1, 1 != -1, 2 != -1, 3 != -1, 5 != -1, 8 != -1}" or "{1,1,1,1,1,1}". When an sequence is applied to an atom using an arithmetic operator, the atom is applied to each element of the sequence. So the result is still a sequence and the "true/false condition must be an atom" error will be reported. The solution: declare data as an object and use the sequence() function to test data to make sure it is a sequence. while equal( datafound, "false" ) or sequence( data ) do Since the only time gets() returns an atom is when it returns -1, it is safe to use the sequence() test to check for end-of-file. Later, _______ ______ _______ ______ [ _ \[ _ ][ _ _ ][ _ ] [/| [_] |[/| [_\][/ | | \][/| [_\] | ___/ | _] | | | _] [\| [/] [\| [_/] [\| |/] [\| [_/] [_____] [______] [_____] [______] xseal at harborside.com ICQ:13466657 http://www.harborside.com/home/x/xseal/euphoria/
4. Re: true/false atoms?
- Posted by Kat <KSMiTH at PELL.NET> Aug 12, 1999
- 529 views
----- Original Message ----- From: Pete Eberlein <xseal at HARBORSIDE.COM> To: <EUPHORIA at LISTSERV.MUOHIO.EDU> Sent: Thursday, August 12, 1999 1:50 AM Subject: Re: true/false atoms? > > >while datafound = "false" or data != -1 do > > > > The '=' operator can't be used here. Try instead: > > > > while equal( datafound, "false" ) or data != -1 do > > While this solves the first "Error: true/false condition must be an atom", > the second test "data != -1" will cause the same error. You must declare > data as an "object" because the gets function will return -1 when it > reaches end-of-file. "But that's I'm testing for!!!" you say, but > remember all the while data will be a sequence of text read from the > file... for instance say data holds {1,1,2,3,5,8}. The result of "data != > -1" will be "{1,1,2,3,5,8} != -1" whose result is the same as "{1 != -1, 1 > != -1, 2 != -1, 3 != -1, 5 != -1, 8 != -1}" or "{1,1,1,1,1,1}". When an > sequence is applied to an atom using an arithmetic operator, the atom is > applied to each element of the sequence. So the result is still a > sequence and the "true/false condition must be an atom" error will be > reported. > > The solution: declare data as an object and use the sequence() function to > test data to make sure it is a sequence. > > while equal( datafound, "false" ) or sequence( data ) do > > Since the only time gets() returns an atom is when it returns -1, it is > safe to use the sequence() test to check for end-of-file. The newer code, with David's and Pete's code: while equal( datafound, "false" ) or sequence( data ) do data = gets(dctstrfile) if ( find(datatofind,data) != 0 ) then datafound = "true" end if end while It still faults at the find() when data is set to -1 ( which i must say, happens extremely fast compared to the pascal compiled code! ) , so i must set yet another if test.... while equal( datafound, "false" ) or sequence( data ) do data = gets(dctstrfile) if sequence(data) and ( find(datatofind,data) != 0 ) then datafound = "true" end if end while Now it misses the end of file, and keeps on running, doing nothing..... no errors, nothing, it never leaves the while loop. I put a printf, gets , and abort after the while, to see if it was leaving the while loop,, and the printf never is hit,, so i told it to print out the file in the while loop, it got to the end of the file and printed blank lines. I had opened the file as "rb" (i have non-char tokens in it) , and changed it to "r", to no effect. Any ideas? Please? Kat
5. Re: true/false atoms?
- Posted by David Cuny <dcuny at LANSET.COM> Aug 12, 1999
- 526 views
Pete Eberlein wrote: >While this solves the first "Error: true/false > condition must be an atom", the second test > "data != -1" will cause the same error Nice save. I should learn to actually read these things all the way through before replying to them. -- David Cuny
6. Re: true/false atoms?
- Posted by Irv Mullins <irv at ELLIJAY.COM> Aug 12, 1999
- 527 views
On Thu, 12 Aug 1999, you wrote: > Hi all, > I am having a dense week here, and i don't understand something. I am trying > to stop writing code that uses "goto"s.... porting some pascal to Eu.. So > this code gives me an error: > > datafound is an object set to "false". > data and datatofind are sequences, datatofind is a legit sequence. > dctstrfile is set to 3 by a previous "open" function at this point. > > while datafound = "false" or data != -1 do > data = gets(dctstrfile) > if ( find(datatofind,data) != 0 ) > then datafound = "true" > end if > end while I would write it like this: object data integer found found = 0 -- open the file while 1 do data = gets(dctstrfile) if atom(data) then exit -- EOF elsif find(datatofind,data) > 0 then found = 1 exit end if end while It's a real waste (and poor programming practice) to use "strings" as boolean values. If you want to print the results later, it's faster and easier to do it like this: if found = 1 then puts(1,"found the data") else puts(1,"couldn't find anything here!") end if Irv
7. Re: true/false atoms?
- Posted by Kat <KSMiTH at PELL.NET> Aug 12, 1999
- 516 views
----- Original Message ----- From: Irv Mullins <irv at ELLIJAY.COM> To: <EUPHORIA at LISTSERV.MUOHIO.EDU> Sent: Thursday, August 12, 1999 8:06 AM Subject: Re: true/false atoms? > It's a real waste (and poor programming practice) to use "strings" as boolean > values. Ok, how do *you* do a flag in eu that can be 5 values when you are protyping in a new language and are stressing easy readability over speed and compactness? Kat
8. Re: true/false atoms?
- Posted by Roderick Jackson <rjackson at CSIWEB.COM> Aug 12, 1999
- 508 views
Kat wrote: >> It's a real waste (and poor programming practice) to use "strings" as >boolean >> values. > >Ok, how do *you* do a flag in eu that can be 5 values when you are protyping >in a new language and are stressing easy readability over speed and >compactness? Well, here's the way I would do it: -- the set of values for my special user-defined type constant FALSE = 0 constant TRUE = 1 constant SPECIAL = 2 constant ERROR = 3 constant OTHER = 4 -- this type declaration isn't necessary, but if you prefer -- tighter error checking, this helps type MyType (object x) if (integer (x)) then if (x <= FALSE) and (x >= OTHER) then return 1 end if end if return 0 end type MyType Flag -- or, just "integer Flag" works if (Flag = ERROR) then ...and so on... Key rule when converting user-defined types from a language like Pascal: use integer constants. Works exactly the same, and is just as readable. Most Euphoria programs, at the very least, define FALSE and TRUE to be 0 and 1. Rod
9. Re: true/false atoms?
- Posted by Irv Mullins <irv at ELLIJAY.COM> Aug 12, 1999
- 532 views
On Thu, 12 Aug 1999, you wrote: > ----- Original Message ----- > From: Irv Mullins <irv at ELLIJAY.COM> > To: <EUPHORIA at LISTSERV.MUOHIO.EDU> > Sent: Thursday, August 12, 1999 8:06 AM > Subject: Re: true/false atoms? > > It's a real waste (and poor programming practice) to use "strings" as > boolean values. > > Ok, how do *you* do a flag in eu that can be 5 values when you are protyping > in a new language and are stressing easy readability over speed and > compactness? constants Irv
10. Re: true/false atoms?
- Posted by Kat <KSMiTH at PELL.NET> Aug 12, 1999
- 496 views
----- Original Message ----- From: Roderick Jackson <rjackson at CSIWEB.COM> To: <EUPHORIA at LISTSERV.MUOHIO.EDU> Sent: Thursday, August 12, 1999 3:04 PM Subject: Re: true/false atoms? > Kat wrote: > >> It's a real waste (and poor programming practice) to use "strings" as > >boolean > >> values. > > > >Ok, how do *you* do a flag in eu that can be 5 values when you are protyping > >in a new language and are stressing easy readability over speed and > >compactness? > > Well, here's the way I would do it: > > -- the set of values for my special user-defined type > constant FALSE = 0 > constant TRUE = 1 > constant SPECIAL = 2 > constant ERROR = 3 > constant OTHER = 4 > > -- this type declaration isn't necessary, but if you prefer > -- tighter error checking, this helps > type MyType (object x) > if (integer (x)) then > if (x <= FALSE) and (x >= OTHER) then > return 1 > end if > end if > return 0 > end type > > MyType Flag -- or, just "integer Flag" works > > if (Flag = ERROR) then > > ...and so on... > > Key rule when converting user-defined types from a language like > Pascal: use integer constants. Works exactly the same, and is just > as readable. Most Euphoria programs, at the very least, define > FALSE and TRUE to be 0 and 1. Ok, all that's nice, but all that stuff is just why i was trying out Euphoria, to get away from restrictions in pascal, etc. I have written more code than actual program to do type translations, mapping one var on top of another and other tricks so i could use the var how i wanted to, making sure if i deallocated the one var that all those others mapped onto it were also not used again, etc etc. I figure the puter is here to make my life easier and do what i want, it's not here so i can learn new programming methods or tricks and put restrictions on what i can do. If i want to have the flag accessed by another program or passed to another procedure/function, strings (or sequences) are the least likely to trigger a type error (just type everything as a string(oops, sequence)) , and i can set them to anything, and parse what i want out of them as needed. Of course, the parsing was easier in pascal with the goto or case statements (when the case statement didn't choke on a type error, anyhow). With faster processors than the 6502 and memory cheaper than the $125 i once paid for 64K, i am not so concerned about waste anymore,, once the program runs like i want it to, the "proof of concept" is done, i'll optimise it for *speed* more than anything else. Kat noting that everything she does to get around compiler deficits is poor programming practice.
11. Re: true/false atoms?
- Posted by Irv Mullins <irv at ELLIJAY.COM> Aug 12, 1999
- 521 views
On Thu, 12 Aug 1999, you wrote: > > Kat > noting that everything she does to get around compiler deficits is poor > programming practice. I know what you mean. I bought a new power saw from Sears, and it just won't drive nails worth a darn. Poor design, I think. Irv
12. Re: true/false atoms?
- Posted by "Matt Z. Nunyabidness" <Prog_Matt at YAHOO.COM> Aug 12, 1999
- 518 views
- Last edited Aug 13, 1999
The problem here is Euphoria can't use the >, <, =, or != operators on sequences. You must either, A. Change the code to use TRUE and FALSE numberic constants, or B. Use equal() on your string.
13. Re: true/false atoms?
- Posted by Bernie Ryan <bwryan at PCOM.NET> Aug 12, 1999
- 506 views
- Last edited Aug 13, 1999
On Thu, 12 Aug 1999 19:50:39 -0400, Irv Mullins <irv at ELLIJAY.COM> wrote: >I know what you mean. I bought a new power saw from Sears, and it just won't >drive nails worth a darn. Poor design, I think. > >Irv Irv are you sure that you're not using bent nails.
14. Re: true/false atoms?
- Posted by Irv Mullins <irv at ELLIJAY.COM> Aug 12, 1999
- 511 views
- Last edited Aug 13, 1999
On Thu, 12 Aug 1999, you wrote: > On Thu, 12 Aug 1999 19:50:39 -0400, Irv Mullins <irv at ELLIJAY.COM> wrote: > > >I know what you mean. I bought a new power saw from Sears, and it just > won't > >drive nails worth a darn. Poor design, I think. > > > >Irv > > Irv are you sure that you're not using bent nails. It says "circular saw" on the box. Don't the nails need to be bent into circles? Irv
15. Re: true/false atoms?
- Posted by "Lucius L. Hilley III" <lhilley at CDC.NET> Aug 12, 1999
- 530 views
- Last edited Aug 13, 1999
What follows is my coding preference. data = gets(dctstrfile) while equal( datafound, "false" ) or sequence( data ) do if ( find(datatofind,data) != 0 ) then datafound = "true" end if data = gets(dctstrfile) end while Lucius L. Hilley III lhilley at cdc.net lucius at ComputerCafeUSA.com +----------+--------------+--------------+----------+ | Hollow | ICQ: 9638898 | AIM: LLHIII | Computer | | Horse +--------------+--------------+ Cafe' | | Software | http://www.cdc.net/~lhilley | USA | +----------+-------+---------------------+----------+ | http://www.ComputerCafeUSA.com | +--------------------------------+
16. Re: true/false atoms?
- Posted by Kat <KSMiTH at PELL.NET> Aug 13, 1999
- 521 views
----- Original Message ----- From: Irv Mullins <irv at ELLIJAY.COM> To: <EUPHORIA at LISTSERV.MUOHIO.EDU> Sent: Thursday, August 12, 1999 6:50 PM Subject: Re: true/false atoms? > On Thu, 12 Aug 1999, you wrote: > > > > Kat > > noting that everything she does to get around compiler deficits is poor > > programming practice. > > I know what you mean. I bought a new power saw from Sears, and it just won't > drive nails worth a darn. Poor design, I think. Prolly so, lol! Maybe if you had the source code to the saw, you could rebuild it? lol. Kat
17. Re: true/false atoms?
- Posted by Kat <KSMiTH at PELL.NET> Aug 13, 1999
- 521 views
----- Original Message ----- From: Irv Mullins <irv at ELLIJAY.COM> To: <EUPHORIA at LISTSERV.MUOHIO.EDU> Sent: Thursday, August 12, 1999 8:53 PM Subject: Re: true/false atoms? > On Thu, 12 Aug 1999, you wrote: > > On Thu, 12 Aug 1999 19:50:39 -0400, Irv Mullins <irv at ELLIJAY.COM> wrote: > > > > >I know what you mean. I bought a new power saw from Sears, and it just > > won't > > >drive nails worth a darn. Poor design, I think. > > > > > >Irv > > > > Irv are you sure that you're not using bent nails. > > It says "circular saw" on the box. Don't the nails need to be bent into circles? No, that refers to the boards. Kat
18. Re: true/false atoms?
- Posted by Kat <KSMiTH at PELL.NET> Aug 13, 1999
- 609 views
Ok, for those of you following my foray into Eu, i did get this to finally work properly, and i am still amazed by the speed, even running it in a dos box in win95: while 1 do data = gets(dctstrfile) if sequence(data) then if ( match(datatofind,data) != 0 ) then datafound = "true" printf(1,"%s\n", {data} ) exit end if else exit end if end while Thanks for all your helps, Kat
19. Re: true/false atoms?
- Posted by Roderick Jackson <rjackson at CSIWEB.COM> Aug 13, 1999
- 545 views
Kat wrote: >Ok, all that's nice, but all that stuff is just why i was trying out >Euphoria, to get away from restrictions in pascal, etc. I have written more >code than actual program to do type translations, mapping one var on top of >another and other tricks so i could use the var how i wanted to, making sure >if i deallocated the one var that all those others mapped onto it were also >not used again, etc etc. I figure the puter is here to make my life easier >and do what i want, it's not here so i can learn new programming methods or >tricks and put restrictions on what i can do. If i want to have the flag >accessed by another program or passed to another procedure/function, strings >(or sequences) are the least likely to trigger a type error (just type >everything as a string(oops, sequence)) , and i can set them to anything, >and parse what i want out of them as needed. If that's what you're looking for, why not just use the "object" type? Define all of your parameters and variables as type object, then you can send in strings, integers, or anything else you want. You would really have no trouble defining every routine in your program like: function TheFunction (object Param) object RetValue -- use Param anyway you want... return RetObject end function A single parameter of type object, that can be anything you want... an integer, a sequence of several values, a string expression, etc. Then just leave out all type declarations, and you're pretty close to a typeless program. You'll still need specific types for a lot of Euphoria functions, but many of them work just as well on sequences as on atoms. Rod
20. Re: true/false atoms?
- Posted by "Kenneth L. Roger" <kennethroger at PRODIGY.NET> Aug 13, 1999
- 532 views
You wrote-- "I am trying to stop writing code that uses 'goto'...." Hang in there. I never understood why spaghetti code with 'goto' was bad while macaroni code with recursion was ok. The students who ingored their professors on this went on to become programmers with Intel, IBM, and Sun, where the base languages all have goto (jmp) instructions. I don't think it's the vocabulary that makes code hard to maintain-- it's the 'features' such as object-orientation that demand wordiness and encourage code bloat.
21. Re: true/false atoms?
- Posted by l <ngrace at BRI.NET.AU> Aug 20, 1999
- 514 views
--------------2027F04DCF1AF9F80DF020AA COULD SOMEONE PLEASE FIX THE E-MAIL ADDRESS. ALL THESE MESSAGES ARE COMING TO GRAFTON CITY LIBRARY !!!!! WE HAVE HUNDREDS OF MESSAGES!!!!!!!!! THANKS - I HOPE Kat wrote: > ----- Original Message ----- > From: Roderick Jackson <rjackson at CSIWEB.COM> > To: <EUPHORIA at LISTSERV.MUOHIO.EDU> > Sent: Thursday, August 12, 1999 3:04 PM > Subject: Re: true/false atoms? > > > Kat wrote: > > >> It's a real waste (and poor programming practice) to use "strings" as > > >boolean > > >> values. > > > > > >Ok, how do *you* do a flag in eu that can be 5 values when you are > protyping > > >in a new language and are stressing easy readability over speed and > > >compactness? > > > > Well, here's the way I would do it: > > > > -- the set of values for my special user-defined type > > constant FALSE = 0 > > constant TRUE = 1 > > constant SPECIAL = 2 > > constant ERROR = 3 > > constant OTHER = 4 > > > > -- this type declaration isn't necessary, but if you prefer > > -- tighter error checking, this helps > > type MyType (object x) > > if (integer (x)) then > > if (x <= FALSE) and (x >= OTHER) then > > return 1 > > end if > > end if > > return 0 > > end type > > > > MyType Flag -- or, just "integer Flag" works > > > > if (Flag = ERROR) then > > > > ...and so on... > > > > Key rule when converting user-defined types from a language like > > Pascal: use integer constants. Works exactly the same, and is just > > as readable. Most Euphoria programs, at the very least, define > > FALSE and TRUE to be 0 and 1. > > Ok, all that's nice, but all that stuff is just why i was trying out > Euphoria, to get away from restrictions in pascal, etc. I have written more > code than actual program to do type translations, mapping one var on top of > another and other tricks so i could use the var how i wanted to, making sure > if i deallocated the one var that all those others mapped onto it were also > not used again, etc etc. I figure the puter is here to make my life easier > and do what i want, it's not here so i can learn new programming methods or > tricks and put restrictions on what i can do. If i want to have the flag > accessed by another program or passed to another procedure/function, strings > (or sequences) are the least likely to trigger a type error (just type > everything as a string(oops, sequence)) , and i can set them to anything, > and parse what i want out of them as needed. Of course, the parsing was > easier in pascal with the goto or case statements (when the case statement > didn't choke on a type error, anyhow). With faster processors than the 6502 > and memory cheaper than the $125 i once paid for 64K, i am not so concerned > about waste anymore,, once the program runs like i want it to, the "proof of > concept" is done, i'll optimise it for *speed* more than anything else. > > Kat > noting that everything she does to get around compiler deficits is poor > programming practice. --------------2027F04DCF1AF9F80DF020AA <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <B>COULD SOMEONE PLEASE FIX THE E-MAIL ADDRESS. ALL THESE MESSAGES ARE COMING TO GRAFTON CITY LIBRARY !!!!! WE HAVE HUNDREDS OF MESSAGES!!!!!!!!!</B> <BR><B>THANKS - I HOPE</B> <BR><B></B> <B></B> <P>Kat wrote: <BLOCKQUOTE TYPE=CITE>----- Original Message ----- <BR>From: Roderick Jackson <rjackson at CSIWEB.COM> <BR>To: <EUPHORIA at LISTSERV.MUOHIO.EDU> <BR>Sent: Thursday, August 12, 1999 3:04 PM <BR>Subject: Re: true/false atoms? <P>> Kat wrote: <BR>> >> It's a real waste (and poor programming practice) to use "strings" as <BR>> >boolean <BR>> >> values. <BR>> > <BR>> >Ok, how do *you* do a flag in eu that can be 5 values when you are <BR>protyping <BR>> >in a new language and are stressing easy readability over speed and <BR>> >compactness? <BR>> <BR>> Well, here's the way I would do it: <BR>> <BR>> -- the set of values for my special user-defined type <BR>> constant FALSE = 0 <BR>> constant TRUE = 1 <BR>> constant SPECIAL = 2 <BR>> constant ERROR = 3 <BR>> constant OTHER = 4 <BR>> <BR>> -- this type declaration isn't necessary, but if you prefer <BR>> -- tighter error checking, this helps <BR>> type MyType (object x) <BR>> if (integer (x)) then <BR>> if (x <= FALSE) and (x >= OTHER) then return 1 <BR>> end if <BR>> end if <BR>> return 0 <BR>> end type <BR>> <BR>> MyType Flag -- or, just "integer Flag" works <BR>> <BR>> if (Flag = ERROR) then <BR>> <BR>> ...and so on... <BR>> <BR>> Key rule when converting user-defined types from a language like <BR>> Pascal: use integer constants. Works exactly the same, and is just <BR>> as readable. Most Euphoria programs, at the very least, define <BR>> FALSE and TRUE to be 0 and 1. <P>Ok, all that's nice, but all that stuff is just why i was trying out <BR>Euphoria, to get away from restrictions in pascal, etc. I have written more <BR>code than actual program to do type translations, mapping one var on top of <BR>another and other tricks so i could use the var how i wanted to, making sure <BR>if i deallocated the one var that all those others mapped onto it were also <BR>not used again, etc etc. I figure the puter is here to make my life easier <BR>and do what i want, it's not here so i can learn new programming methods or <BR>tricks and put restrictions on what i can do. If i want to have the flag <BR>accessed by another program or passed to another procedure/function, strings <BR>(or sequences) are the least likely to trigger a type error (just type <BR>everything as a string(oops, sequence)) , and i can set them to anything, <BR>and parse what i want out of them as needed. Of course, the parsing was <BR>easier in pascal with the goto or case statements (when the case statement <BR>didn't choke on a type error, anyhow). With faster processors than the 6502 <BR>and memory cheaper than the $125 i once paid for 64K, i am not so concerned <BR>about waste anymore,, once the program runs like i want it to, the "proof of <BR>concept" is done, i'll optimise it for *speed* more than anything else. <P>Kat <BR>noting that everything she does to get around compiler deficits is poor <BR>programming practice.</BLOCKQUOTE> </HTML> --------------2027F04DCF1AF9F80DF020AA--