Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

Submitted, for your approval.

 [1/12] from: edanaii::cox::net at: 26-May-2002 15:15


Greetings all, Attached is a small game I created in my continuing effort to understand REBOL. It is another guessing game, slightly more sophisticated than the one I submitted previously. Please look it over and feel free to criticize, but do be gentle, as this is my second attempt at a REBOL program. ;) -- Sincerely, | We're Human Beings, with the blood of a million Ed Dana | savage years on our hands! But we can stop it! We Software Developer | can admit we're killers, but we're not going to 1Ghz Athlon Amiga | kill today. That's all it takes! Knowing that we're | not going to kill... Today! -- Star Trek. =========== http://members.cox.net/edanaii/Home/Default.html =========== -- Attached file included as plaintext by Listar -- -- File: Symbols.r REBOL [ Title: "Deduce the Symbols chosen by the computer." Date: 26-May-2002 Version: 1.0 To-do: { 1. Further use of Parameters. 2. Enhance based on further REBOL knowledge. 3. Better method of scoring. 4. GUI. 5. Variable Symbol and Guess sets. } File: %Symbols.r Author: "A guy with too much time on his hands." Gategory: "Game" Purpose: "An excersize in using and understanding REBOL." ] Symbols: Func[ ;=============================================================================== {This is a guessing game in which the player must guess five Symbols from among a set of eight. Each of the five are chosen randomly from the following set "~" "!" "@" "#" "$" "%" "&" "*" The game ends when the player correctly guesses all five symbols and their positions. The only clues offered are the number of symbols that match the computer's set and the number of symbols that are placed correctly inside the computers set. I.e. if the computer has chosen $#@#! and the player guesses *##~* the computer will respond with Matched: 1 Placed: 1. This is because the player's # matches the two chosen by the computer, one of which happens to be in the correct place. } ;=============================================================================== /Ask_Another {Asks player "another game?"} /Begin "Initializes the game." /Compare "Compares the player's choices to the computer's." /Deduce "Plays the game" /Indicate_Bad {Displays message "choices are bad."} /Indicate_Only_5 {Displays message "Only 5 symbols may be chosen."} /Indicate_Success {Displays message "You guessed them."} /New_Set "Creates a new set of choices" /Valid "Determines if the player's choices made are valid" ] [ If Ask_Another [ if (uppercase to-string first at (Ask "Would you like to play again? ") 1) = "N" [ Playing: False ] ] If Begin [ Symbol_Set: [ "~" "!" "@" "#" "$" "%" "&" "*" ] Random/seed Now ] If Deduce [ Symbols/Begin Playing: True While [ Playing ] [ Choices: Symbols/New_Set Turns: 0 While [ Choices <> Guess_Set: Ask "What is your guess? " ] [ Turns: Turns + 1 Either ( ( length? Guess_Set ) <> 5 ) [ Indicate_Only_5 ] [ Either Symbols/Valid [ Symbols/Compare ] [ Symbols/Indicate_Bad ] ] ] Symbols/Indicate_Success Symbols/Ask_Another ] ] If Compare [ Placed: 0 Matched: 0 For a 1 5 1 [ Either ( ( first at Guess_Set a ) = ( first at Choices a ) ) [ Placed: Placed + 1 ] [ If find Guess_Set to-string ( first at Choices a ) [ Matched: Matched + 1 ] ] ] Prin "Matched: " Prin Matched Prin " Placed: " Print Placed Print " " ] If Indicate_Bad [ Print "Not all the choices you've made are valid." Prin "Please make your choices from the following Symbols: " Print Symbol_Set ] If Indicate_Only_5 [ Print "Please enter only five choices" ] If Indicate_Success [ Print "That was it!" Prin "And you did it in only " Prin Turns Print " Turns." Print " " ] If New_Set [ Choices: "" Clear Choices loop 5 [ Insert Choices pick Symbol_Set random 8 ] Return Choices ] If Valid [ For a 1 5 1 [ Either ( find Symbol_Set to-string ( first at Guess_Set a ) ) [ Return True ] [ Return False ] ] ] ] Symbols/Deduce

 [2/12] from: carl:cybercraft at: 27-May-2002 21:35


On 27-May-02, Ed Dana wrote:
> Greetings all, > Attached is a small game I created in my continuing effort to > understand REBOL. It is another guessing game, slightly more > sophisticated than the one I submitted previously. > Please look it over and feel free to criticize, but do be gentle, as > this is my second attempt at a REBOL program. ;)
Hi Ed, It works fine, though I was a bit confused by the Matched and Placed numbering to begin with, not realizing that once something was placed it was no longer recorded as matched. "Misplaced" might've been a better term. (; As to your code: Well you've got me wondering whether having a function call it's own refinements like that instead of having seperate functions for those routines is a good or bad thing... I think it probably is bad, (mainly due to a performance issue with the amount of code you have to get through to get to the last "if whatever..."), but as you've found out, it does work. Note however that it only works because the words you create in the function are global, not local. If you'd tried to make Symbol_Set local by having... /local Symbol_Set in the function's first block you'd get an error when calling the function with any refinement other than /begin. With REBOL functions, words defined in the body of the function are made global by default, not local. This is because "it's better for beginners" apparently. (: An alternative approach to using refinements would've been to have them as functions within your function. ie, just change... If Begin [ Symbol_Set: [ "~" "!" "@" "#" "$" "%" "&" "*" ] Random/seed Now ] to... Begin: does [ Symbol_Set: [ "~" "!" "@" "#" "$" "%" "&" "*" ] Random/seed Now ] and you can then call that with just "Begin" instead of Symbols/Begin . ('does is for functions without any arguments.) Otherwise though, you're learning fast! It's good and tidy code on the whole. -- Carl Read

 [3/12] from: anton:lexicon at: 27-May-2002 19:44


Well, instead of this:
> Prin "Matched: " > Prin Matched > Prin " Placed: " > Print Placed > Print " "
you could write print ["Matched:" Matched "Placed:" Placed] I also suggest following Rebol Tech's style-guide. Anton.

 [4/12] from: ingo:2b1 at: 27-May-2002 13:38


Hi Ed, maybe it would be better (at least better looking) if you turned your function/refinements design into an object/funcs design, wouldn't take much I guess. And you can give 'print a block, like this: print [ "Matched: " Matched " Placed: " Placed newline] 'newline adds, you'll guess it, a newline (you could use "^/", too). From the usability view-point: - You should display a list of the symbols on startup. - and an error on less than 5 symbols - help on wrong symbols Kind regards, Ingo Ed Dana wrote:

 [5/12] from: edanaii:cox at: 27-May-2002 8:11


Carl Read wrote:
> Hi Ed, > It works fine, though I was a bit confused by the Matched and Placed
<<quoted lines omitted: 11>>
> having... > /local Symbol_Set
Yep. I realize that. Next revision will likely include passing and returning parameters.
> in the function's first block you'd get an error when calling the > function with any refinement other than /begin. With REBOL
<<quoted lines omitted: 12>>
> Random/seed Now > ]
It was a good excursive in using refinements and testing the document functionality that is built in to REBOL.
> and you can then call that with just "Begin" instead of > "Symbols/Begin". ('does is for functions without any arguments.) >
Yes, I thought about that, but noticed that there was no way to prefix the subroutine with the parent one, at least not that I could see. But then, I'm only on Chapter 7 of the official guide. :) My preferred style would have been to call the subroutine as Symbol.Begin. Which is one of the reasons I settled for using refinements. As I said, this is a learning excursive for me. Sometimes the best way to learn is to make all the mistakes you can up front. Saves time by not making them later. :) I'll continue to revise things as I learn more.
> Otherwise though, you're learning fast! It's good and tidy code on > the whole. >
Thanks. After programming for 26 years, I sure hope my code is tidy. :) -- Sincerely, | Ed Dana | Life's but a knife's edge, anyway. Sooner or later Software Developer | people slip and get cut. 1Ghz Athlon Amiga | -- Larry McMurtry, Streets of Laredo

 [6/12] from: edanaii:cox at: 27-May-2002 10:34


Ed Dana wrote:
> As I said, this is a learning excursive for me. Sometimes the best way
^^^^^^^^^
> to learn is to make all the mistakes you can up front. Saves time by not > making them later. :)
DOH! Stupid spell-checker! Make that exercise, not excursive! -- Sincerely, | Ed Dana | Life's but a knife's edge, anyway. Sooner or later Software Developer | people slip and get cut. 1Ghz Athlon Amiga | -- Larry McMurtry, Streets of Laredo

 [7/12] from: ammon:rcslv at: 25-May-2002 22:18


Hmm... Some things that i found: Does this confuse anyone else? What is your guess? *@#%& Matched: 2 Placed: 3 What is your guess? &@#%* Matched: 2 Placed: 3 I also noticed this: What is your guess? ^@#&* Not all the choices you've made are valid. Please make your choices from the following Symbols: ~ ! @ # $ % & * now watch what happens here: What is your guess? @#&*^ Matched: 4 Placed: 1 You might also consider asking the user if he/she would like instructions at the first of the game, I was rather confused to start with so I read the source code. It would be much more intuitive to have it inform you of too many or too few symbols. HTH Ammon A short time ago, Ed Dana, sent an email stating:

 [8/12] from: edanaii:cox at: 27-May-2002 19:01


Ammon Johnson wrote:
> Hmm... Some things that i found: > > Does this confuse anyone else? > > What is your guess? *@#%& > Matched: 2 Placed: 3 > > What is your guess? &@#%* > Matched: 2 Placed: 3 >
Hmmm... Without knowing the details of what the computer had chosen, it's hard to say, but this is a possible scenario. It is possible to move symbols around and still get the same results. Remember, it is only reporting on the symbols that match and place, but it is not telling you which have matched and placed. So it's possible when you switch them around that symbols go from placed to matched and back again and still total the same.
> I also noticed this: > > What is your guess? ^@#&* > Not all the choices you've made are valid. > Please make your choices from the following Symbols: ~ ! @ # $ % & * >
This is because the ^ is not legal. I tried using it in REBOL and it gave me the following grief: ** Syntax Error: Invalid string -- " ] ** Near: (line 54) Symbol_Set: [ "~" "!" "@" "#" "$" "%" "^" "&" ] It doesn't like the ^ symbol, for whatever reason...
> now watch what happens here: > > What is your guess? @#&*^ > Matched: 4 Placed: 1 >
What??? Bugs in my code! No way! OK, OK, I guess I gotta fix it! That one is definitely a bug in my code.
> You might also consider asking the user if he/she would like instructions at > the first of the game, I was rather confused to start with so I read the > source code. It would be much more intuitive to have it inform you of too > many or too few symbols. >
Well, since this was more an attempt to learn REBOL than it was to create a serious game, I just wasn't focused on complete instructions, that's why I used the document feature rather than making it accessible while running. As to the "too many or too few" issue. It does tell the user that. This appears to be a bug in REBOL. As it turns out, since I wrote my sub-routines as refinements, if I call the refinement with it's proper prefix (i.e. Symbols/Indicate_only_5), the script runs as expected. If, OTOH, I forget to prefix it, which was my mistake (i.e. Indicate_only_5), the script runs, but the refinement does not execute. Curious... -- Sincerely, | Ed Dana | Courage is fear holding on a minute longer. Software Developer | -- General George S. Patton 1Ghz Athlon Amiga |

 [9/12] from: ingo:2b1 at: 28-May-2002 9:00


Hi Ed, Ed Dana wrote: <...>
> This is because the ^ is not legal. I tried using it in REBOL and it > gave me the following grief: > > ** Syntax Error: Invalid string -- " ] > ** Near: (line 54) Symbol_Set: [ "~" "!" "@" "#" "$" "%" "^" "&" ] > > It doesn't like the ^ symbol, for whatever reason...
The reason is, that ^ is Rebols escape character: ^/ = return ^- = tab ^(41) = ascii character 65 ^^ = a literal ^ Kind regards, Ingo

 [10/12] from: carl:cybercraft at: 28-May-2002 20:23


Hi Ed, On 28-May-02, Ed Dana wrote:
>> If Begin [ >> Symbol_Set: [ "~" "!" "@" "#" "$" "%" "&" "*" ]
<<quoted lines omitted: 12>>
> prefix the subroutine with the parent one, at least not that I could > see. But then, I'm only on Chapter 7 of the official guide. :)
Well, you wouldn't have to prefix it if calling it from within the main function, or from outside for that matter if you hadn't made the internal functions local.
> My preferred style would have been to call the subroutine as > Symbol.Begin. Which is one of the reasons I settled for using > refinements.
My approach would be something like this... symbol: func [ "Demo function" /local begin this that and-the-other ][ begin: does [ print "Beginning..." this that and-the-other ] this: does [print "this..."] that: does [print "that..."] and-the-other: does [print "and that's all folks!"] begin ; Here's where the program starts doing something... print "The End." ] That at the console gives...
>> ? symbol
USAGE: SYMBOL DESCRIPTION: Demo function SYMBOL is a function value. And...
>> symbol
Beginning... this... that... and that's all folks! The End. Perhaps more in keeping with your style though would be to make it an object... symbol: make object! [ help: does [print "Demo object."] begin: does [ print "Beginning..." this that and-the-other end ] this: does [print "this..."] that: does [print "that..."] and-the-other: does [print "and that's all folks!"] end: does [print "The End."] ] Usage for that is...
>> symbol/help
Demo object.
>> symbol/begin
Beginning... this... that... and that's all folks! The End. and as with symbol/help and beginyou can access all the other functions within 'symbol...
>> symbol/this
this... but the functions themselves don't need the prefix to call eachother - see 'begin. Hmmm. I hope that's enlightened you and not just confused you. (: As you'll gather, REBOL's quite flexible. Not to mention fun. (; -- Carl Read

 [11/12] from: edanaii:cox at: 28-May-2002 18:25


Carl Read wrote:
> Hmmm. I hope that's enlightened you and not just confused you. (: As > you'll gather, REBOL's quite flexible. Not to mention fun. (; >
It did. As I mentioned, I'm only on Chap 7 of the official guide. Object Oriented shtuff is a mere 4 chapters away. I guess I'll gets to it, when I gets to it. :) When I get there, I'll convert the game into object code. But it may be a couple of weeks before I can get there. Thanks. Everyone's input has been helpful. -- Sincerely, | For long you live and high you fly. Ed Dana | And smiles you'll give and tears you'll cry. Software Developer | And all you touch and all you see, 1Ghz Athlon Amiga | Is all your life will ever be. | -- Pink Floyd, Breathe.

 [12/12] from: edanaii:cox at: 5-Aug-2002 18:57


All, Here's a REBOL program I've been working on. It's almost complete, but I still have a few things to do to it. Since this is my first *serious* REBOL program, I'm submitting here for you to critique. Please feel free to tear it apart. One of the things I have not added is error handling. I'd also like advice on that, like what can go wrong. I know for example that when I try to open the mailbox, it may not be there. Naturally, I need to trap that. What other events do I need to keep an eye on in order to manage the mailbox? Thanks in advance... ====================================================================== REBOL [ Title: "Remailer for mailbox" File: %Mail.r Date: 01-Jun-2002 Purpose: { Processes the mailbox and distributes emails based on the Subject Line found. Will route to multiple emails and pagers depending on need. } Note: { Will remove all emails it finds from the specified mailbox and store them in a text document. } Category: [email] ] Mail: Make Object! [ End: Func [ MBX [Port!] ] [ Close MBX ] Format: Func [ LTR [Object!] ] [ ;> Temp fix, whitespace in 66 all [ LTR/Header/subject/66 = #" " remove at LTR/subject 66 ] LTR/Body: Join Mail_Body_Pre LTR/Header/Content LTR/Body: Join LTR/Body Mail_Body_Post Return LTR ] Process: Func [ MBX [File!] ] [ { This function starts the entire mail process. It requires a mailbox to open, scans the mailbox, and then wraps up the program. } Inbox: Mail/Start MBX Mail/Scan Inbox Mail/End Inbox ] Rules: Func [ LTR [Object!] ] [ "Performs the rule-based processing of the specified mailbox." ; Are we ready to send this email? Send_It: False ; Get latest Rules and Contacts. Do %Contact_List.r Do %Mail_Rules.r ; Compare the Subject Line of the eMail with our Rules ; When the Subject Line matches what is in the Rule Book ; Then perform the action identified there. ForEach Rule Rule_Book/List [ If find LTR/Header/Subject Rule/Subject_Text [ Do Rule/Action Print [ "=" Rule/Subject_Text ">" Rule/Action ] ; Compare the Escalation level of the email with our Rule. ; If the Escalation level is greater than/equal to our Rule. ; Perform the necessary Action to escalate the message. If Rule/Escalation [ ForEach Response Response_Group/List [ If Response/Level >= Rule/Escalation/Level [ Do Rule/Escalation_Action Break ] ] ] ] ] ] Scan: Func [ MBX [Port!] ] [ "Scans the mailbox and processes, sends, and logs the processed emails." ; For each Mail in the Mailbox ; Format the email with the appropriate informations ; Process the email based on the appropriate rules. ; Send it when it is ready to go. while[not empty? MBX] [ Letter: Mail/Format Make eMail.Obj [ Self/New First MBX ] Print Letter/Header/Subject Mail/Rules Letter Write/Append %Processed.txt First MBX If Send_It [ Write/Append %Sent.txt Mold Letter Letter/Deliver ] Remove MBX ] ] Start: Func [ MBX [File!] ] [ Return Open Load MBX ] ] ====================================================================== -- Sincerely, | Ed Dana | Life's but a knife's edge, anyway. Sooner or later Software Developer | people slip and get cut. 1Ghz Athlon Amiga | -- Larry McMurtry, Streets of Laredo

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted