Discussions in support of the LOLCODE.com wiki
You are not logged in.
I've put up a proposal for loop structures which I believe is flexible and works well with what we have already.
What do you think?
http://lolcode.com/proposals/1.3/loop
Offline
I agree with most of the amendments, but have some issues with it:
- There's no reason to eliminate the option for any unary function to be used as the operation. Just because increment and decrement are most common doesn't mean that no other operation is useful. For example, a loop where the index is doubled each time could be useful for iterating through powers of two. And, of course, anyone can define their own unary function that does whatever they want it to.
- There's also no reason to make the loop variable read only. While messing with it is unsightly, I don't see any reason to prohibit it.
- On the other hand, _encouraging_ messing with it by having a STEPPIN operator also seems like a dumb idea to me.
Offline
A couple of things. First, labeled GTFOs. I think they are useful, but they are also being used in WTFs, aren't they? What if I have a switch in a loop and use the labeled GTFO inside the switch? I assume it drops out of everything, but I'm worried it might be difficult to implement.
Second, I don't like the way that normal loops and counting loops are different, when they don't have to be. The simple addition of a "FROM" allows the ability to assign a starting value. There are other issues with it as well:
- The <label> doesn't have to match the <variable>.
- It doesn't address the coming need for a 'for each'.
- In one loop structure, the <label> is only a label, in the other it has a value, even though the structures are on the surface the same. I think these are simple enough that we can use the same syntax in each.
- It doesn't make sense to be IN YR <variable> UPPIN YR 2. The 2 isn't uppin, at least not after the first iteration. You are actually uppin the variable and the language should say so. It is worse if your start value is an expression: IM IN YR VAR NERFIN YR PRODUKT OF MASS AN PRODUKT OF SPEED_OF_LIGHT AN SPEED_OF_LIGHT TIL 0. Even IM IN YR LOOP UPPIN YR START TIL 10 looks like it's uppin START, not LOOP. I think this is an issue.
- What happens with STEPPIN in a nested loop? Will it always step the inner-most loop variable?
- STEPPIN is interesting, in that it's the increment and the test all in one, and that you can put it in different places and give it different values. However, I think most 'for' loops have the evaluation first, then the code, then the incrementation at the end, before the next evaluation. Combining the two together can result in unexpected behavior. For example:
I HAS A STRING
GIMMEH STRING
IM IN YR VAR UPPIN YR 0 TIL LENGTH OF STRING
VISIBLE "GIMMEE A " STRING!!VAR
STEPPIN
IM OUTTA YR VARYeah, I had to reach back in the archives to invent a way to pull chars out of strings, but you get what I mean, I hope. In any case, this fails for empty string, whereas if I were writing it in Java:
for (int i = 0; i < s.length(); i++)
System.out.println("GIMMEE A " + s.charat(i));does. Because the check is done before the loop starts, the actual loop statements aren't executed. There's no way to do that with the STEPPIN construct, I think.
Actually, with STEPPIN, even this doesn't work as expected:
IM IN YR LOOP UPPIN YR 1 TIL 10 VISIBILE LOOP STEPPIN IM OUTTA YR LOOP
This actually prints 1 through 9, not 10 as one would expect.
Last edited by risser (2007-07-12 20:16:09)
Offline
risser wrote:
A couple of things. First, labeled GTFOs. I think they are useful, but they are also being used in WTFs, aren't they? What if I have a switch in a loop and use the labeled GTFO inside the switch? I assume it drops out of everything, but I'm worried it might be difficult to implement.
Sorry for being so long replying. I got distracted by your own proposal. The more I read it, the more I realised I was carrying over some habits from my Forth days. LOLCode is very different, as i'm slowly starting to appreciate.
I don't see how you could exit a loop with an unlabeled GTFO, since it has to be enclosed by a conditional terminated by OIC. At that point, because of the label, the compiler already knows just what structures have to be dropped by the run-time jump.
Example:
IM IN YR HUNTIN
GOT ANIMAL, WTF?
OMG “Hedgehog�
VISIBLE “Prickly!!� GTFO
OMG “Dog�
VISIBLE “Halp!!!� GTFO HUNTIN
OMG “Maus�
VISIBLE “NOM NOM NOM� GTFO
OMGWTF
VISIBLE “Wat iz Dat?�
OIC
VISIBLE “Still Huntin!!�
IM OUTA YR HUNTINSecond, I don't like the way that normal loops and counting loops are different, when they don't have to be. The simple addition of a "FROM" allows the ability to assign a starting value. There are other issues with it as well:
i've addressed most of these issues, but you have also addressed the difficulty I had with your version, and I've understood it better. I'm particularly glad you got rid of the need for a boolean termination test - LOLCode comparisons are soo verbose!
- What happens with STEPPIN in a nested loop? Will it always step the inner-most loop variable?
Yes, trust me. ![]()
- STEPPIN is interesting, in that it's the increment and the test all in one, and that you can put it in different places and give it different values. However...
I've fixed it now. It makes more sense as a continuation than as a break. Interesting, yes, but i have been unable to come up with a convincing use for it.
In short, I can't think of any reason now to reccommend my proposal above yours.
Offline
I have a random idea, what if loops check the value in IT for WIN before continuing (always).
Example:
I HAS A FLEA ITZ 1
IM IN YR BED
GIMMEH bedfellow
WTF?
OMG "mouse"
VISIBLE "nom nom nom"
GTFO
OMG "lice"
LICE R SUM OF LICE AN 1
GTFO
OMGWTF
VISIBLE "WTF?"
OIC
BOTH SAEM LICE AN BIGGR OF LICE AN 10
IM OUTA YR BEDThis loops until there are 10 LICE in the bed.
Offline
Not that example, because the 'exit loop value' is raised by 1 for every 1 lice, this means that it will loop ad infinitive.
another way to write it is: keep ageing until you are older than your dad.
Also, you didn't use IT anywhere... wtf?
Offline
Abadon wrote:
Not that example, because the 'exit loop value' is raised by 1 for every 1 lice, this means that it will loop ad infinitive.
another way to write it is: keep ageing until you are older than your dad.
Also, you didn't use IT anywhere... wtf?
IT is the latest evaluated statement (as I understand it). Kind of like $_ in perl. By having a boolean experession at the bottom of the loop, I'm setting IT to the value before the loop repeats. The loop would check IT before repeating.
Offline
JoshSuereth wrote:
I have a random idea, what if loops check the value in IT for WIN before continuing (always).
Example:Code:
I HAS A LICE ITZ 1 IM IN YR BED GIMMEH bedfellow WTF? OMG "mouse" VISIBLE "nom nom nom" GTFO OMG "lice" LICE R SUM OF LICE AN 1 GTFO OMGWTF VISIBLE "WTF?" OIC BOTH SAEM LICE AN BIGGR OF LICE AN 10 IM OUTA YR BEDThis loops until there are 10 LICE in the bed.
That's Java's DO-WHILE which is probably the least common looping construct, because he whole of the loop has to be executed before it can exit. Using my WILE it's the same as:
OIC WILE DIFFRNT LICE AN 10 BTW I think you meant IM OUTA YR BED
not
OMG "lice"
LICE R SUM OF LICE AN 1
WILE DIFFRNT LICE AN 10
GTFO
OMGWTF
VISIBLE "WTF?"
OIC
BTW code here is skipped on 10 lice
IM OUTA YR BEDBut there's something odd about the first construction. I reads like I'm coming out of the bed while lice<>10, because that's the next statement. I don't get that with the more complex counted loop, because there I've already clearly stated that I'm repeating the block.
The trouble is, a bare IM IN YR <label> ... IM OUTTA YR <label> just doesn't read like an infinite loop.
On the good basi of telling folks what you're going to do before you do it, I'd prefer "IM IN YR <label> FOREVA", knowing that cats are fickle creatures, and are bound to GTFO somewhere. This corresponds with what I've often heard said when teaching beginners - "Ah, but there your in your ... you need to"
What other uses are there for IM IN YR and IM OUTTA YR as named scope markers?
Offline
Proposal for a FOR EACH loop
IM IN UR <label> PLAYIN WIV UR <var1> <var2>
as equivalent to
for <var1> in <var2>
Offline
Heliomance wrote:
Proposal for a FOR EACH loop
Code:
IM IN UR <label> PLAYIN WIV UR <var1> <var2>as equivalent to
Code:
for <var1> in <var2>
I'm not sure that the spec for bukkits is developed well enough to decide yet how to implement a FOR EACH, but I've done some more work on my idea of letting the loop identifier be more than a label. See the re-written proposal http://lolcode.com/proposals/1.3/loop
In this scheme the syntax would probably be "IM IN YR <var1> WATCHIN <var2>"
Offline
JennyB wrote:
Heliomance wrote:
Proposal for a FOR EACH loop
Code:
IM IN UR <label> PLAYIN WIV UR <var1> <var2>as equivalent to
Code:
for <var1> in <var2>I'm not sure that the spec for bukkits is developed well enough to decide yet how to implement a FOR EACH, but I've done some more work on my idea of letting the loop identifier be more than a label. See the re-written proposal http://lolcode.com/proposals/1.3/loop
In this scheme the syntax would probably be "IM IN YR <var1> WATCHIN <var2>"
Massive +1 to the new LOOP proposal, except:
a) there's a few typos that need to be fixed ("indentifer"??!!)
b) the "Exiting a Scope" example has a few lines that contain multiple statements not separated by commas
c) calling loops "Named Scopes" is just downright confusing, especially when all "Named Scopes" are loops
d) the second example in "Conditional Exits" seems to use the loop iterator as some kind of implied default object - this is lame.
Offline
memodude wrote:
a) there's a few typos that need to be fixed ("indentifer"??!!)
b) the "Exiting a Scope" example has a few lines that contain multiple statements not separated by commas
c) calling loops "Named Scopes" is just downright confusing, especially when all "Named Scopes" are loops
I've fixed these now. Much of what I was thinking could be done with named scopes could perhaps be done better with "O HAI" or in some other way. We'll see.
d) the second example in "Conditional Exits" seems to use the loop iterator as some kind of implied default object - this is lame.
I was thinking that with objects we're going to get many!!deeply!!nested!!calls, and there should be some like VB's
WITH deeply.nested.object
.doThis
.doThat
.doTotherBut I forgot I'd have to end with "IM OUTTA DEEPLY!!NESTED!!OBJECT". Not good ![]()
The alterative I've given now should work, I think. It seems right that the "value" of a object is a pointer to the object.
Offline
The ANIMAL example used in this proposal has a couple errors in it (use of GOT and misspelling of GIMME).
It probably wants changing from
IM IN YR HUNTIN
GOT ANIMAL, WTF?
OMG "Hedgehog"
VISIBLE "Prickly!!", GTFO
OMG "Dog"
VISIBLE "Halp!!!", GTFO HUNTIN
OMG "Maus"
VISIBLE "NOM NOM NOM", GTFO
OMGWTF
VISIBLE "Wat iz Dat?"
OIC
VISIBLE "Still Huntin!!"
IM OUTA YR HUNTINto
IM IN YR HUNTIN
GIMMEH ANIMAL
ANIMAL, WTF?
OMG "Hedgehog"
VISIBLE "Prickly!!", GTFO
OMG "Dog"
VISIBLE "Halp!!!", GTFO HUNTIN
OMG "Maus"
VISIBLE "NOM NOM NOM", GTFO
OMGWTF
VISIBLE "Wat iz Dat?"
OIC
VISIBLE "Still Huntin!!"
IM OUTTA YR HUNTINOffline
Norgg wrote:
The ANIMAL example used in this proposal has a couple errors in it (use of GOT and misspelling of GIMME).
Thanks for pointing that out. Changed now.
Offline