The LOLCODE forum

Discussions in support of the LOLCODE.com wiki

You are not logged in.

Announcement

New registrations are disabled. Please see this announcement.

#1 2007-07-12 17:07:57

JennyB
Member
From: Co Fermanagh, N. Ireland
Registered: 2007-07-04
Posts: 27

Discussion: 1.3 Loop proposal

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


Test all things - hold fast to that which is good.

Offline

 

#2 2007-07-12 18:41:01

atl
BDFL
From: lolcode.com
Registered: 2007-05-31
Posts: 324
Website

Re: Discussion: 1.3 Loop proposal

AWSUM.
Well, I couldn't ask anything more from the form of it, at least...

Offline

 

#3 2007-07-12 19:58:10

Arachnid
Member
Registered: 2007-06-02
Posts: 271

Re: Discussion: 1.3 Loop proposal

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.


lolcode.net - .NET LOLCode compiler.

Offline

 

#4 2007-07-12 20:15:31

risser
Moderator
Registered: 2007-06-01
Posts: 469

Re: Discussion: 1.3 Loop proposal

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:

Code:

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 VAR

Yeah, 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:

Code:

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:

Code:

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

 

#5 2007-07-14 18:17:46

JennyB
Member
From: Co Fermanagh, N. Ireland
Registered: 2007-07-04
Posts: 27

Re: Discussion: 1.3 Loop proposal

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:

Code:

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 HUNTIN

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:

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. wink

- 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.


Test all things - hold fast to that which is good.

Offline

 

#6 2007-07-15 01:16:08

JoshSuereth
Moderator
Registered: 2007-07-14
Posts: 221

Re: Discussion: 1.3 Loop proposal

I have a random idea, what if loops check the value in IT for WIN before continuing (always).


Example:

Code:

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 BED

This loops until there are 10 LICE in the bed.


-------------------------------------------
-Josh

"To hurry through one's leisure is the most unbusiness-like of actions." - G.K. Chesterton

Offline

 

#7 2007-07-15 08:53:13

Abadon
Member
From: Denmark
Registered: 2007-06-05
Posts: 12

Re: Discussion: 1.3 Loop proposal

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

 

#8 2007-07-15 14:25:22

JoshSuereth
Moderator
Registered: 2007-07-14
Posts: 221

Re: Discussion: 1.3 Loop proposal

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.


-------------------------------------------
-Josh

"To hurry through one's leisure is the most unbusiness-like of actions." - G.K. Chesterton

Offline

 

#9 2007-07-16 15:30:51

JennyB
Member
From: Co Fermanagh, N. Ireland
Registered: 2007-07-04
Posts: 27

Re: Discussion: 1.3 Loop proposal

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 BED

This 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:

Code:

   OIC
   WILE DIFFRNT LICE AN 10     BTW I think you meant
IM OUTA YR BED

not

Code:

    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 BED

But 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?


Test all things - hold fast to that which is good.

Offline

 

#10 2007-07-18 10:47:55

Heliomance
Member
Registered: 2007-06-06
Posts: 99

Re: Discussion: 1.3 Loop proposal

Proposal for a FOR EACH loop

Code:

IM IN UR <label> PLAYIN WIV UR <var1> <var2>

as equivalent to

Code:

for <var1> in <var2>

BASIC don't need no prefix

Offline

 

#11 2007-07-24 22:18:33

JennyB
Member
From: Co Fermanagh, N. Ireland
Registered: 2007-07-04
Posts: 27

Re: Discussion: 1.3 Loop proposal

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>"


Test all things - hold fast to that which is good.

Offline

 

#12 2007-07-25 02:05:02

memodude
Member
Registered: 2007-06-16
Posts: 108

Re: Discussion: 1.3 Loop proposal

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

 

#13 2007-07-25 10:25:45

JennyB
Member
From: Co Fermanagh, N. Ireland
Registered: 2007-07-04
Posts: 27

Re: Discussion: 1.3 Loop proposal

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

Code:

WITH deeply.nested.object
        .doThis
        .doThat
        .doTother

But I forgot I'd have to end with "IM OUTTA DEEPLY!!NESTED!!OBJECT". Not good sad

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.


Test all things - hold fast to that which is good.

Offline

 

#14 2007-10-01 13:39:27

Norgg
New member
Registered: 2007-10-01
Posts: 4

Re: Discussion: 1.3 Loop proposal

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

Code:

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 HUNTIN

to

Code:

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 HUNTIN

Offline

 

#15 2007-10-01 17:20:13

JennyB
Member
From: Co Fermanagh, N. Ireland
Registered: 2007-07-04
Posts: 27

Re: Discussion: 1.3 Loop proposal

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.


Test all things - hold fast to that which is good.

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson