Tuesday, March 18, 2008

Happy Easter-2008


I never did find the lovely panoramic egg postcard, but here's some mean looking rabbits with rifles from around 100 years ago. The military imagery is fairly common in Easter cards of the time. I think I printed one last year too.



These are the eggs I'm talking about. (from ebay) They used to have little cardboard worlds inside. Now if you get one the figures are made of poured sugar and don't have that fantasy feeling, as if you could walk around inside if you could just get small enough.

While driving to an awful Thai restaurant in Northridge today, I suddenly remembered a song I used to sing with my grandmother:

"Bring Them in,
Bring Them in,
Bring Them in from the Fields of Sin."

(Her parents died when she was little and was raised by her uncle, a Methodist minister.)

The fields of sin? You mean like this?



Whinsey and Anita in an alternate universe!

Meanwhile I'm struggling with this code:

var tester:RegExp = /lunch/i
var testline:String = "It is time for lunch";
var rg1:RegExp=/goomba/i
var rg2:RegExp=/It is/i
var rg3:RegExp=/fun/i
//trace(testline.match(rg2)[0])//works!
tester=rg2
//if(testline.search(tester)!=-1){trace("YOU DUMB CluucK")}//true
function medumb(){
testline.match(tester[0])
switch (tester[0]) {

case rg1:
trace("rg1");
break;
case rg2:
trace("correct");
break;
case rg3:
trace("rg3");
break;
default:
trace(testline);// that's what comes up.
break;
}
}
medumb();

Sometimes code is not fun at all.

8 comments:

sal said...

At first I thought you were looking for a card of a panorama painted on an actual egg....

Namowal said...

When I was a kid I wanted to shrink and explore the inside of sugar eggs too.
I can understand maybe 10% of what's going on with that code. I recently got myself a book about basic (not BASIC) coding to get up to speed about this stuff. I have a ways to go!

Sally said...

Namowal, which book did you get?

Namowal said...

Sally,
Don't laugh, but it's the most simple one I could find*- something like Code For Teens. It's more of an into to codes (Java, C++, etc) in general: concepts, how they work and so on. I figured I need to get familiar with the basics before I start fooling around with ActionScript.
(Of course, I'm open to any book recommendations of the latter.)

Jesse said...

Mmm.. rexexp..

Are we sure:
testline.match(tester[0])
switch (tester[0]) {

shouldn't be:
switch (testline.match(tester)[0])
{

At the first line of your function "tester" is a simple rexexp, I don't know if it's advisable to dereference into it with [0]. You were doing that with the match cases to get out the results though.

I'm going to prop open an environment on this end to test the code and make sure it's doing what I think though. :]

Jesse said...

Ok, test environment made and there's still one more obstacle.

In the switch statement clause, you have "tester[0]" (and I naively modified that to "testline.match(tester)[0]") but what are we really comparing against here?

The result of testline.match(tester)[0] is a string (in this case "It is") and rg2 is a regexp (/It is/i). Those things aren't equal.

If rg2 were more complicated like .. /It (is|was)/i .. then that gets even tougher.

My best guess is that you want to hit the default switch block if the testline does not match, and if it does match you want to know which rg == tester at the time of the match?

If that is so you could do this:

switch (testline.search(tester)>=0 && tester) {

which is an evil shorthand for saying this:


var result:Regexp;
if(testline.search(tester)>=0)
{ result = tester; }
else
{ result = /not matchable/; }

switch(result) {



Or...... when I read the code from a getting-things-done standpoint, it feels like you want to match the testline against all the regexps and know which one matched? For that I would recommend something more like:



var tests:Object = {
rg1:/goomba/i,
rg2:/It is/i,
rg3:/fun/i // I want a comma here but would AS3 let me?
};
var testline:String = "Whatever sounds fun";
var result:MatchThingy; // I don't remember what AS3 calls the result of a regexp match :]

for(i in tests) {
if( !(result = testline.match(tests[i])) )
{ continue; } // don't get farther than this until we have a match

alert(testline +' matched against '+ tests[i] +' resulting in "'+ result[0] +'"');
break;
}




(My test environment is simple JavaScript, which should be nearly identical to AS3 for our goals here except I don't have to declare type on variables, so I hope this works right for u :)

Sally said...

Hey, Jesse- tomorrow I'll get back into it and look closely at your post. I'd thought that a switch/case method of coding might be better than my old if/ for loop set up because the break would be clean and I wouldn't have to enumerate each possibility. But later today I did have a few break throughs which made me think my old system might be better for what I was trying to do.

I GREATLY GREATLY appreciate the code advice you've posted in the last couple of days. Because of the various things I'm trying to pull together in the next 24 hours I may not respond much until next week. Meantime, thanks so much!

ps namowal, because of my tech editing past, I have a lot of brand new code books for Flash MX which I would happily give you. again, wait till next week when brain is better attached!

Namowal said...

That's very generous of you, Sally.
I owe you big time!