View this PageEdit this PageAttachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide
Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007

Questions on Fall2001 P1 Milestone

Ask about P1 here...

I think that there can be ambiguous cases for 3 of the 4 match types. I'll use ? as an example. It can match 1 or 0 words. So lets say there is a rule along the lines of "Strange ?foo Girls". For this example I'll refer to ?foo as the identifier. So, "Strange Little Girls" and "Strange Girls" should both match. The most obvious logic to implement this would be that when you detect the identifier, see if the word after the identifier in the rule (=A) matches the next word in the query (=B). If so, then assume that they didn't put a variable for ?foo. If "A" does not match "B", check the word after "B" in the query (=C). If "A" matches "C", then "B" is the variable for the indentifier and we continue the check. Else, the match fails overall.

Now, here comes the problem. If we check the rule against "Strange Girls Girls" then it becomes ambiguous. ?foo could evaulate to getting 0 words, in which case the match would fail because there is an extra "Girls" at the end. Or, ?foo could eat the first "Girls" and put it in Dictionary with the key foo, in which case the string would match overall. Either solution seems equally valid under given ruleset. So basically, in the case of the ? match type, the problem occurs when the word used to fill the variable it the same as the word after it. Ugh.. Am I missing something? -DR

If there are extra things, the test doesn't match. Mark Guzdial
Sorry, let me answer that better. If there's a POSSIBLE match, take it. If there's a way of making it true, take it. Mark Guzdial

Could someone please verify that my intrepretation of the project requirements is correct. Is it correct that we supposed to create a class (aka WordMatcher) which has the ability to add rules (strings with variable options based on the matching symbols), as well as the ablity to match a string which is passed into the method to see if it matches any of the possibilities for the rules. Then the "matching function" will return true, false, or a dictionary with the variables depending on what is appropriate. This project will not require us to do any input from the transcript or a terminal? Have I missed any requirements or does this pretty much cover everything? Sorry to have to ask I was just a little confused.

That is my understanding of the assignment also. -DR
Folks, the reason why I had you make Who's Who pages was so that you could sign your messages. Please do so! There's a fudge factor in the grading scheme based on participation. How do I figure out participation if you don't sign your notes?
Your interpretation is mostly correct, except for a vocabulary problem. You're going to create a class WordMatcher. The INSTANCES of WordMatcher will accept rules and strings and do a match returning true, false, or a Dictionary. No, there's no transcript or "terminal" interaction here. Mark Guzdial

The following two lines appear in the assignment definition: "You should always convert input to lowercase literals for the tokens that match. Leave the matched elements in mixed case." What does this mean? Are we to convert to lowercase or not? A couple of examples would help greatly. Thanks in advance, Jonathan D'Andries

There are examples there. If your rule has "I am" then you should match "I AM" or "i am" – simply lowercase the matching tokens. But if your rule has "!name" in it, then you should match either "Mark" or "eric" or "WhATeVeR" and retun the variable's value mixed-case. Mark Guzdial
My guess is that it's just saying to compare against the rule case insensitively, but when we add words to our dictionary we should preserve the case that the user passed in. That was just my interpretation though.

Thanks, that makes much more sense. By the way, please sign your posts so I know who to thank. Here is my next question. Do we have to worry about multiple variable declarations in a single rule?
Jonathan D'Andries

Yes, there may be multiple variable declarations in a single rule. That will be necessary to handle indirect objects, such as "put the sword into the troll." Mark Guzdial

this may seem like a stupid questions, but i just need to confirm. The rules that are passed in thru the addRule: method have to be stored somewhere. So i am assuming that since we have not been told of a data structure, can we use whatever we like, or am i totally on the wrong track. Any suggestions will be greatly appreciated ...
Mohammad Z Khan

You can use whatever you want inside the instances. Remember that this is a class on Design – we're not going to specify the problems as much as in past classes, leaving it up to you to figure it out. (Mohammad, please reference your Who's Who page by putting your names in asterisks) Mark Guzdial

I'm trying to implement the block option, but I'm not sure how your example works. I'd assume you would store the block and then pass in '39' into the block via value:. But since 39 is part of the match string how did you guys get a true result and bind the variable? '39' isNumber returns false. I don't see how you can get a number 39 out of the string. Are we supposed to do some conversions or something (that could get complex)? Thanks in advance. Alfred Park

'39' asNumber – not too complex. But you're right that the variables should be Strings, so I'll update the problem. Mark Guzdial

(Copied from Questions and Discussions)
Ok so I was playing with squeak and I made my own class WordMacther and then I made a method called new and had it define the variables that were in WordMatcher...but when I made a new WordMatcher and then ran new and then tried to inspect it Squeak crashed! Why did this happen? and how do you go about rewriting new so that when your new class is made with a delcaraion such as nameMatcher:=WordMatcher new. you actually use your new and not that of object?

First, don't change the title of the Questions and Discussions page! Second, ask questions about assignments on assignment pages, e.g. Questions on Fall2001 P1 Milestone Please, sign your messages. We'll explain "new" tomorrow (Tuesday). You need to give me some idea of what "Squeak crashed" means. Did you get an error notifier? What was the error? Mark Guzdial

Is the block option only valid for the "exactly one" wildcard? Or should it function for the other wildcards, and how? -Graham Coleman

If you assume that the input is a string of whatever matched, and that the input string could contain spaces and other tokens, then it could work for others, too. Mark Guzdial

Just to clarify: there can be more than one token with special matching characters per rule, right? Ryan Dawe

Yes – that can be more than one token with special matching characters per rule. And yes, there may be cases, then, when it can be ambiguous, e.g., where you have two match-more-than-one next to one another. Resolve the ambiguity best you can. We don't plan to test you on ambiguous cases, but you need to make your matcher work for the rest of the assignments. Mark Guzdial

In rules containing consecutive variables, will there be a defined matching behavior, or will any valid match do?
For example rule: 'Guz &foo ?bar' string: 'Guz banana grapes apple'
could return either:
"Dictionary, foo->'banana grapes apple' bar->''"
"Dictionary, foo->'banana grapes' bar->'apple'" -Graham Coleman

In the returned Dictionary what is the behavior for multiple or zero matched variables? Should a collection be mapped to a variable names key? -Graham Coleman

See above, Graham – resolve it as you'd like it to work for the rest of your milestones. For multiple or zero matched variables, separate by space and toss them into a single string. (Think about how you're going to use this: "Take the blue key" vs. "Take the red key" You're going to want a single string with "blue key" or "red key" in it.) Mark Guzdial

Should we have error checking for adding rules and stuff, or should we assume we are getting a String and let other cases crash? -Graham Coleman

Assume that you're getting a String as input and let other cases generate message not understood errors. Mark Guzdial

Are we to use a parser generator (aka Tgen) or should we write the parser by hand? -Graham Coleman

I strongly suggest NOT to use TGEN. This is much closer to a regular expression matcher than to a parser. Mark Guzdial

Another question about blocks :) In the example, numbersOnly addRule: 'I am !age[:input | input asNumber isNumber] years old'. Since the rule is passed in as a string, if we were to extract the [:input | input asNumber isNumber] out of the rule, this would still be a string. How are we supposed to convert strings into blocks? (Or am I approaching this wrong)? Alfred Park

Unfortunately there is no "asBlock" message for String, nor is there a "BlockContext fromString:" available either! So, what the heck, how come you can just "do-it" on the block in the workspace? its okay - you can invoke the compiler from workspace anyway, so think about passing your string of a block off to the compiler (Compiler evaluate: —).Webb

Final question on blocks. numbersOnly match: 'I am thirty-nine years old'. "false" How do we generate a false return when a pink-error message box pops up when using Compiler evaluate:? Can you suppress the message box and return false somehow, or is it fine to leave the message box to pop up? Thanks for the help Webb. Alfred Park

Like Webb says. Only call the Compiler evaluate: when you know that you have a block inside the string. "thirty-nine" isn't a number from Squeak's perspective. If you want to support that, you can, but it's not necessary. Mark Guzdial

I am having the same problem as Alfred here while using Compiler evaluate:. Say you have already matched the block, but when the value is passed in at runtime generates an error, for example: Try do-it on [:i| i asNumber isNumber]value: $a. It generates a Message-not-understood, since the character does not understand the asNumber message. What I want to know is how to return false instead of having the compiler pop up the error message. It looks like
Compiler evaluate: textOrStream in: aContext to: receiver notifying: aRequestor ifFail: failBlock shows some promise, but Im not quite sure what to enter for some of the fields, like what to use for aRequester and aContext. Alan Ferguson
yeah - it certainly is a problem - I didn't see it at first, sorry. Okay the Compiler evaluate: part is not screwing up - its when you actually test the block with whatever junk comes through match:, right? (i hope i'm on the same page) – okay so you need to wrap this failing part in another block — see p.106 for a way to prevent that pink box from popping up! working yet? Webb

Hang on – I wouldn't pass in the "value:" into the Compiler evaluate:. Instead, only use Compiler evaluate: to create the block, e.g., b := Compiler evaluate: '[:x|x asNumber]'. . Now, you can call b value: someInput. Yes, you do need to test if someInput is a string before you pass it in. In general, we're only going to test your code with blocks that will work with Strings. BTW, there is a way to capture the notifiers – see ifError: in Chapter 2. Mark Guzdial

Is there any method that will test if two strings are equal and return a boolean. I am having a tough time finding one in the system browser Robert Schierholz

String -> ArrayedCollection -> SequenceableCollection Eureka! all three answer (xCollection = yCollection)-Webb

Are there any classes in Squeak which support state machines, NFA->DFA and so forth? -Graham Coleman

Not that I'm aware of. There might be something there that could be used for that, but nothing obvious springs to mind. Mark Guzdial

I am still confused as to when I should return 'true' and when I should return a dictionary. Am I right in saying that rules containing '#' and '&' should return dictionaries and rules containing '?' and '!' should return 'true'?

Return true if there's a match but there are no variables. Return a dictionary if there are variables. Mark Guzdial

I have read a couple of posts about blocks and how to implement them above. But i still do not understand why do we need to use Compiler evaluate: , and how does it help us in our project?. Mohammad Z Khan

See my answer above – Compiler evaluate: '[some block]' will return a BlockContext object. Mark Guzdial

Thanks Webb I was playing around with = and it wasn't working, I guess I had the paranthesis wrong or something. Anyway as long as I am asking questions how about else if chaining there didn't seem to be anything like that in the Boolean class, so I am assuming there is none, but on the off chance that someone knows of one, I would appreciate it if they could point it out to me. -Robert Schierholz
Booleans understand and: and or:. They also understand ampersand and pipe (and and or) but without short-circuiting. This is in Chapter 2. (Please do sign your messages.)
Mark Guzdial|

How much error handling do we need to worry about putting in to this? can we assume that when rules are added, that they are valid and do not contain errors? (like a block not behind a variable, etc) – Jason Fulghum
Yup – we plan on only testing with valid rules. Mark Guzdial

Answering a good question in class: '#name' allButFirst gives you 'name'. Mark Guzdial

In class, the last part was changed back from [:input | input asNumber isNumber] to [:input | input isNumber]. I don't think this is correct. When you call match: it accepts a string, so when you parse the string, the object you are comparing against the block is a string. So you need asNumber to convert '39' into 39. Yes it will error on 'thirty-nine' but you can capture the error-message and return false (as mentioned above). So if the block stays as [:input | input isNumber] it will fail for the example given. Just my $0.02. Alfred Park
Christopher sent me a nice piece of code that always works, and that's currently what's up there. Mark Guzdial

I may be a little behind, but I am still stuck trying to figure out how to parse out for example, !name, from 'Hello, my name is !name'. I know how to find out where the ! is located within the string (indexOf), and I could do size minus that index, but you would also get more characters than wanted in an example like 'Hi, my name is !name, nice to meet you'. Any suggestions?

Just wondering if a pool dictionay is basically a dictionary that is accessable class wide or am I totally off in this assumption
Matty Clain
Basically. It can also be shared between classes. Don't use them. Mark Guzdial

In part of the grading description it says 10% of our grade is "good reuse of existing code" could someone explain this too me alittle more. I can see intrepreting this in many different ways. Thanks, Robert Schierholz
Good question, Robert! Here's the point: There are GOBS of cool String/Array methods already implemented. Use those, don't write your own. Use detect:/collect:/reject:. Use first/allButFirst. Don't do everything with for loops and at:put: I'm trying to get you to dig around and find things to use. Mark Guzdial

In the !name examples, is there a reason one is totally enclosed in single quotes and the other is not? Here is what I'm talking about:
"Dictionary, 'name'->'Mark'"
"Dictionary, 'name->Mark'"
Just wanted to see if that is intentional or a type-o. Thanks, Matt Miller

typo I believe a Dictionary('name'->'Mark') Webb
Typo, like the WebbMan said. Mark Guzdial

How should we choose our key values to store in the Dictionary. I'm not really sure if the example in the book really gives the purpose of the Dictionary class very well. Thanks Jason Ergle
Then look for uses of the Dictionary in the image, in order to get examples. That's why I did that shtick in class on how to take an example and generalize it. See if you can figure out where Dictionaries are used for examples. Mark Guzdial

Does anyone have any suggestions on how we are to keep track of how many variables are allowed in each rule?
Tim Hardcastle
Aren't there any number of variables allowed in a rule? Andy Foster

I understand that there are different number of variables depending on what is entered... but I was curious if there were any suggestions as how to handle those variables when creating the rules.
Tim Hardcastle
Oh, my suggestion is to keep the handling very simple and don't waste much time trying to be elegant or clever - memory and processors are cheap and Squeak cleans up after us. Andy Foster
Like Andy said, and remember "Dictionaries are your friends" Mark Guzdial

I have read the turnin instructions and one point is bugging me. How can we do the equivalant of a getback for the coweb? Jared Parsons
good question, because I don't think its possible right now, but you can at least look at the version history of the page and see what files have been uploaded. Right now there is no downloading because other students could come along and take your completed work! Webb

Is there a way to tell if something is a dictionary?
Jennifer Roper
Every class understands the "class" message so you could do something like this. ( ( var class) = "Dictionary") ifTrue: [.... ]. Jared Parsons
Everything also understand isKindOf:, e.g., var isKindOf: Dictionary Be sure not to use double quotes as in Jared's example, but otherwise, sending class is a darn good idea. Mark Guzdial

If you use ordered collection to store the tokens in your rule, how do u just create one orderedCollection for the instance of the class u create. Meaning...if i do, a := WordMatcher new, then how will it create one orderedCollection, so I can just keep on adding rules to the same orderedCollection for a. I asked a TA, and he said to use super new initialize, but I don't understand how to use that, if that is the right way? Thanks. Bharti Agarwal
Page 71 in the Squeak book has a very good explination of how alter the "new" class message Jared Parsons

How would you write a function that required a list of parameters?
Jennifer Roper

I am not a TA. But one way to do this would be something like :
sumTheNumbersWithMultiplesOf: x startingAt: argument2 until: argument3
as your header, where startingAt: until: and sumTheNumbersWithMultiplesOf: can have whatever names you want. Look in the browser at any method with more than one : Ahmed El-Helw|

Ahmed is right. Jennifer, if what you wanted to write was something like "match: 'fred', 'ginger', 3" – well, you can't in Squeak. Parameters must be separated by methodname/selector markers, each ending with ":". Mark Guzdial

I tried using super new initialize .. and read page 71. But the problem i am having is that now.. even if i create a new WordMatcher it still keeps adding to the same old ordered collection. All i did was in my "new" method i super new initialized.. and then in my initialize method i just delcared it as a new ordered collection. So now if i had ten rules to foo := WordMatcher new. And then i make bar := WordMatcher new. and then try to add a rule to it... it adds the rule to the end of the 10 things that i added in foo. This doesn't make sense to me. I thought everytime i would make a new WordMatcher, it would make a new OrderedCollection. Is it because i declared it as a class variable?? But i dont think it will work with out it! Shehzad Ashfaq

Each time you create an instance of WordMatcher, the new instance should have its own copy of OrderedCollection. If you declear your OrderedCollection as class variable, all instances will end up sharing one OrderedCollection. Why would you want do that? What won't work w/out it? Donghan Li
Well said, Donghan! Mark Guzdial

I realize this is a class on design, and we are supposed to be designing our own method of attacking this problem, but I'm really struggling to come up with a clean method of parsing out and matching the strings. In CS2130 (sorry to remind everyone) we often spoke about the "lookahead" of a particular parser, i.e. how many tokens ahead it can see in order to match the current rule. Now, it seems to me that this parser we are coding would need infinite (or very large) lookahead because of the "[zero|one] or more" rules. For example, if I'm trying to parse a match, and I come across a # variable, I have to continue looking all the way to the end of the string to determine where the cut off is for that particular variable. Otherwise, there is no way of knowing which words are included for that variable. I guess one option would be to start parsing at the end after hitting a variable, and working backwards until we match the next literal in the rule (and of course, if that literal is not found, the rule will fail and you should return false). On the other hand, if the next token in the rule is NOT a literal, then it starts getting very complex. My apologies for stating all of the obvious problems here, but I'm hoping to strike up some discussion on design ideas for our parsers (in general terms of course). I'm assuming that this type of discussion is okay for the message board, but if not, please let me know.
Sorry, last post was made by Rocky Dunlap.

yeah, I think your point is valid about the infinite lookahead - but you can weasel out of the problem. For the 0,1, or more tokens I just include everything following - no "determine where the cut off is for that particular variable". I'm sure people are doing this to save themselves.
addRule: '#claim forever looking for an !answer'
match: 'i spent forever looking for an answer!'

Dictionary ('claim' -> 'i spent forever looking for an answer!' 'answer' -> 'answer!'). I don't know if this is a good suggestion or not. Yes, its ugly, but it really doesn't have to be perfect. Webb|

I'm just another student, but I think that that is an invalid match, Webb. in the rule you had "forever looking for an" that you did not match with the matching text. I'd interpret a valid match here to be only Dictionary ('claim' -> 'i spent' 'answer' -> 'answer!'). Correct me if I'm wrong though Chris Church
That is the exact point I mean. Why should "one or more" stop with just 'i spent'? Its much easier to just take more more more all the way to the end of the matched input. You aren't "wrong" though because it is entirely up to your interpretation to resolve the ambiguous variables the way you wish- make sense? Webb
Actually, it is wrong to match this way in this case because the match would fail. And as Guzdial mentioned above (very first post), if there's a possible way to avoid returning false, you cannot choose the case that would return false. if #claim ate the entire sentence, than the rest of the rule ("forever looking..") would not match the query, and so it would return false. However, As Chris mentioned above, there is a way to match it without returning false, so that's what your parser would have to do. I'm not a TA or anything, but I'm pretty sure about that. -DR
I disagree - this is parallel processing. It matches BOTH acceptable final states. You refer to: "if there's a possible match, take it". Ok, well if you can match it then what is to prevent the machine from entering an accept all state for that variable token (i'd really like to know a formal reason if you know -cause i'm just learning theory myself)? And then the other symbols proceed with their corresponding rules as well. It may not be the formally correct solution to an NFA - but I don't think the match is "wrong", especially under the leisure that is allowed in personal design. Webb
Actually, I think our discrepancy is simpiler than that. I agree that the # operator can consume the entire sentence.. however, that would cause it to return false. Lets look at the example again..
addRule: '#claim forever looking for an !answer'
match: 'i spent forever looking for an answer!'

Now "claim" can eat 0 or more words and "answer" has to eat exactly one word. Between those two, the words "forever looking for an" must appear unmatched. In otherwords, if they are matched in a dictionary then they cannot be used to fulfill the rest of the rule. Of course I might be wrong, but that at least is my understanding.. It'd be really great to have an official response to this.. *wink wink nudge nudge* -DR
Like David said: Find a match if one exists and return true. Ambiguity is up to you how you want to handle it. Mark Guzdial

So are we suppose to be able to match things like:

'I am called !name and I am the Greatest!' ?? because in all the examples it has the variable in the last position in which case you can just take everything after the !....but in the case I have mentioned you have to worry about both I making this too complicated

David Norvell

Although I'm just a student, my understanding is that you should be able to handle that rule or any combination of variables and strings, despite positioning. Aaron Drew
"I am the Greatest!" doesn't have a variable or match token in it. "I am the Greatest !" (note the space) does, and it would match "I am the Greatest Butterfly!" Mark Guzdial
'I am called !name and I am the Greatest!' does have a variable name, and name should be matched. If you look through the assignment, you'll see example with variables in the middle of strings (the block one is an example of it, but there are others too). Just a sample of what would match is 'I am called Steve and I am the Greatest!'. Aaron Drew

When is this project due by?? What time on Tuesday? Thanks. Shehzad Ashfaq

I think it depends on when you have class. As copied from the assignment page: "In class, please turn-in well-documented, hardcopy source code (at least two lines of comments for each non-accessor method, in-line comments at significant portions) with your name and student number on it. In addition, before class time, turn-in your code using the Fall 2001 Turnin Information with the code 'P1'." Hope that helps. Aaron Drew

Like Aaron said. (Gee, Aaron, you want a job? :-) Mark Guzdial

How do i get a method to take in multiple arguments?
Tim Hardcastle

methodName: firstParam descriptorForSecond: secondParam descriptorForThird: thirdParam and so on. For example, to draw a point that needed a color, x coordinate, and y coordinate you could do drawPoint: color xCoordinate: x yCoordinate: y, and the variables in the method would be x, y, and color. Aaron Drew

Accutally in answer to my question and posing another one...can that be true giving the example I gave because that should return false actually...because 'my name is Mark Guzdial' returns false i fail to see the difference in that and in otherwords no I don't
David Norvell

The reason 'my name is Mark Guzdial' returns false is because the rule is 'my name is !name'. !name can only store one word, so there's nothing to store or match the Guzdial. Since it isn't stored or matched, the whole strng can't be match and is therefore false. Aaron Drew

When adding to a Dictionary, is one key supposed to hold more than one value. For example if i had rules:
'My name is !name.'
And then i matched it twice with:
'My name is John.'
'My name is Doe.'
So does dictionary return:
"Dictionary, 'name' -> 'Doe'" Or does it return
"Dictionary, 'name' -> 'John' 'Doe'" ??
Thanks a lot! Shehzad Ashfaq

I'm pretty sure each time you call match: you are returning a different Dictionary. When you did match: 'My name is John.', name should be John in the returned Dictionary. When you match: 'My name is Doe', the returned Dictionary has name with Doe. The two Dictionaries you return are unrelated to each other. Aaron Drew

Is this what you are saying. That everytime i add something to a dictionary it is a different dictionary. That would not make sense. The impression that i got was that everytime you make a new WordMatcher, you have one dictionary where everything is stored. So any matches that you get are entered in one dictionary. As far as i know, we are trying to build a game. So i would think within the game the dictionary would hold any information we want it to hold. And so only one dictionary would exist for each wordMatcher. If everytime we matched something and put it into a new dictionary, thus in the game.. we would have like hundreds of dictionary's. Is my thinking correct on this? So the question remains.. would it be "John", "Doe" or just "Doe". Thanks again. Shehzad Ashfaq

I agree with Aaron Drew's view, that each time you run match you are returning a new instance of a Dictionary. Otherwise, if you had multiple rules that had identifiers with the same name, when your dictionary instance is returned you don't necessarily know whether the keys contained in it are there from THAT "match:" method call, or from a previous "match:" method call, so you wouldn't really know whether the call succeeded. Furthermore, it wouldn't be difficult to merge small dictionaries into a bigger game dictionary, if you decided you needed to do that in the future. -DR

when i call matchRule: i store my match in an OrderedCollection. right now i am trying to convert the variables inside the collection back to a string to enter into the dictionary. any tips on how to do this?
Tim Hardcastle

If you're using findTokens to get the OrderedCollection, each Token in the OrderedCollection is a string by default. Aaron Drew

i understand that but i am trying to take a few strings out of that collection and combine them back into one... with spaces in separating them.
Tim Hardcastle

You could use the , operator strings have to add them together. Just add a ' ' to them too and it should work fine. That help at all? Aaron Drew

How are we supposed to match &? I've been trying $& and beginsWith: '&', but both give me a "non boolean reciever" error... I can match # with both &# and beginsWith: '#'... any ideas?

Mike Rosack

Try using the at: message in String. 'string' at: 3 would return $r.
Chris Church |
beginsWith: takes a character, not a string. Also, Strings understand "first" Mark Guzdial

Thanks for the help, Chris, but it's still not working... maybe I'm going crazy. :) Here's a snippet of my code:

[curRule at: 1 = $#] ifTrue:
[curRule at: 1 = $&] ifTrue:

I have two other ifTrues, but you get the point. The second ifTrue always bombs out with "Error: Nonboolean receiver - proceed for truth" and the "= $&" highlighted.
Mike Rosack
ok, obvious answer... parenthesis instead of brackets. duh.
Mike Rosack
It's one of the classic Smalltalk gotchas. "The other one being fighting a land war in Asia." (Never mind...:-) Mark Guzdial

Alright, here are some test cases I whipped up that I decided to share. I was careful to make sure none of these are ambiguous– I believe each match call has exactly one correct answer. The correct answer (what I think the corrct answer is) is inlined and in italics. Obviously this is far from comprehensive, and the usual NATA warning applies..

wm := WordMatcher new.
wm addRule: 'my name is #name schmoe'.
wm addRule: 'blah &stuff blah ?blah'.

Question: I decleared several instance variables for WordMatcher, however, I can only use the 1st one, when I use the rest in my instance methods, squeak complains about not knowing them and ask if I want to declear them as temp... Does anyone know what's going on? Thanks in advance! Donghan Li

never mind, please disregard my previous question... cannot type... Donghan Li

I might have missed then in early questions but how do we return our values from the dictionary. Do we return one value from the Dictionary
"a Dictionary('stuff'->'blah')"
or do we return the entire dictionary if multiple matches have been made
"a Dictionary ('blah'->'humbug' 'stuff'->'blah')"
Tim Hardcastle

I was of the impression that each call to match returned a new instance of a dictionary, but at least one other person had your perspective too. There's a small discussion about that a bit up from here, but there's no response from a TA or Guzdial yet. -DR

Folks, COME TO CLASS! This was asked explicitly in class last Thursday, and I answered it there as well. You return ONE Dictionary with all the matches in it. Mark Guzdial

Based on how a Dictionary works, I would think you should put every variable matched during one call to the match: string method into one Dictionary, then return that as the result. On top of just how the Dictionary works, it wouldn't be possible for one call to match: string to return multiple Dictionaries (unless you stuffed them into a Collection, but that's not returning a Dictionary then). As a side note, if you call match twice, each call should return it's own Dictionary or boolean value independent of the other calls made to match. Not a TA, but that's how I interpret it. Aaron Drew

Just to clarify: when we match something and we say it returns "true" we're talking about an actual return statement and no output via the transcript or anything like that right? Matt Miller
Yes Matt, I'm pretty sure that you return (^) true, false, dictionary with no output to the transcript like you said since the assignment uses the word 'return' all over the place and says no word about the transcript. [Not a TA] Glenn Calvert
Like Glenn says. Mark Guzdial [Not a TA]

Where should I put Dictionary into?

In the WordMatcher? Then how do you deal with same varibles in different rules? Yongjun Huang

overwrite them. At least that's what i did...Ryan Dawe

Do blocks have to be handled with any symbol in front besides '!'?
is addRule: 'my name is @var[blah]' a possibility?
Chris Church

Went ahead and to be safe implemented it so it deals with blocks with any type of symbol in front. But another Question has come up. We're supposed to bring a pretty looking hardcopy print out (pretty because it talks about comment style). I opened up my fileout file with vi and noticed it is 1 line long. Am I doing something wrong or will our hardcopies be pretty ugly?
Chris Church

Returning to the above conversation about multiple Dictionaries vs. one Dictionary, I didn't understand the answer. If we call match 3 times, 3 separate unrelated Dictionaries should be returned, one for each time (assuming the rule matched and some variable was assigned). Each Dictionary should have everything that call to match found, but nothing from the other calls. Is that the correct interpretation? Aaron Drew
That's the way I understood it to work. However - I think once you have a Dictionary matched it should be preserved until its replaced - so false matches won't wipe out your old one (false matches to a Block condition). Webb

I'm having a lot of trouble actually getting the block out of the string. Any help? Also, can we assume that the '[' will always be directly after the variable name? That is there is no space in between? i.e. !age[...] not !age [...]
Jesse Shieh

Since the project is not due until 5:00 when do we turn in the Hardcopy of the code since that time is after class? John Matson
Do we really have to worry about multiple rules in one match? cause I can do all the matches if they are with selfs or others like them...but trying to match up things like ! and # in the same rule is just hard...any Idea on how to do multipe things like with ! # and ? all in the same rule?? do we really have to worry about that?

David Norvell
if you can't get multiple rules don't panic. Webb
For getting the block out of the string, they way I did it was first to break the string down to tokens (findToken:), then combine the tokens between '[' and ']'. now you have your block. If the '[' is not directly after the variable name, I think you just need to consider it as regular literal/tokens. Donghan Li
is there a way to do a switch statement in Squeak...or do I really have to use a ton of ifTrue statements?

David Norvell
Error: A block compiles more than 1K bytes of code
Did I write too much code in one method? is there away around this error? HELP! Rob Boots

Concerning Blocks:
If I have:
addRule: 'I am ?age[:input | (input at: 1) isDigit and: [input asNumber isNumber]] years older than you'.
match: 'I am years older than you'.
Does the match fail because the string '' does not cause the block to evaluate to true, or should it pass and not evaluate the block with an empty string?
Dawn Padula
I'm not a TA, but it seems most logical for that to be true. The ? signified that there could be nothing there, so you shouldn't have to evaluate the block at all Jesse Shieh
I agree with Jesse. While it seems like an ambiguous case (are symbols are blocks evaluated first?), think about using this to code a game. If you used ? instead of ! you obviously wanted it to be able to pass in the event there is no word there. If the block caused it to always fail because an empty string does not evaluate correctly that ruins the usefulness of ? here. Looking at it the other way allows you the power to say "only match this if it meets these requirements or it doesn't exist." My interpretation could be wrong, it's merely my evaluation based upon usefulness, and since we're using this code in later Milestones, that should be a deciding factor.Chris Church

Squeak froze on me when I executed a 'DoIt' and inorder to get it unlock it, I had to kill the process. I thought that I had been saving all my work, but when I loaded squeak again, it appears that all of my changes are gone. Anyone know how to get them back? Thanks.

ok. i got the block. i evaluate the block. but I evaluate the block passing in a String as input (right...?). any string object recieving the message isNumber will return false. any string object which is not a number, but recieves the message asNumber will crash. am i goofy? Ryan Dawe
you're not goofy - see above posts for how to avoid this crash Webb

Anyone know how to catch an error? David Norvell
catch the error by enclosing it with a block, [...] and then pass it the ifError: message - see the text for details :) Webb

I tryed catching the error like that already...
[ stuff ] ifError: [do this] is how I wanted it to work how is it suppose to work? David Norvell

ok so we have #, !, &, ? do only ! and & return dictionarys? or are we suppose to return for all or what...I am un sure of this..
or is it like if the symbol is followed by a name then return !name -> dictionary... ! -> don't return dictionary..for all cases? Because this could become a pain real fast
can you make this more clear? David Norvell

Seeing as how america is under attack as the media puts it and Tech has been shut down, how are we supposed to turn in our hardcopy to the GVU? What should we do?
Jesse Shieh

How are we suppose to evaluate the block when we're suppose to be making everything lowercase? i can't evaluate isnumber, it has to be isNumber...any ideas? Rob Boots
I like the string method called match! it works great....David Norvell
The only answer I see is to set everything to lowercase EXCEPT the block Jesse Shieh
don't set everything to lowercase. The examples store 'my name is Mark' Dictionary, 'name'->'Mark' — you just need to lowercase the string when you are comparing the tokens for a match. I wouldn't lowercase the input for the block and certainly not the block itself. Webb

You can also just use match: to see if the tokens are the same becuase it ignorace case and leaves the text unaltared which is perfered in my opinoin David Norvell

Is there away to have (anObject instanceOf: Object) -> there a method for this? And is there a way to do Switch statements?
And is there an escape character? What is not equal to '/=' '\=' ?? David Norvell
you can always say '=' ifFalse or whileFalse if you want the negation Webb

I am also confused on the block part is it guarented to be in the format !age[:input | (input at: 1) isDigit and: [input asNumber isNumber]] or can it have other forms if so is it only the symbol in fron that changes or what's in the block as well? David Norvell

I am having serious problems overloading the new method for my WordMatcher class. When I 'do it' on say "frustration := WordMatcher new." , my overloaded method is not executed. What is going on? Andy Foster
OK I have found it now. For others with this problem – I had created new as an instance method instead of a class method. Andy Foster
Silly Question...what should our hard copy consist of?
Shoul we just copy and paste every method we made to a text file and print it? or does squeak have a special way of doing that like the file out stuff..I was going to print my .cs file, but its not really legible

I am not supposed to be on here lol but I just want to say hi David this is Drew your bro

Links to this Page