Page 1 of 1

Loops

Posted: Thu Sep 08, 2005 11:00 am
by ateb9025
I would be inerested to know if loops violate the concept of context free language. In some ways, because you need to impose a limit so that the loop isn't infinite, i guess that it isn't completely context free, the execution depends on the loop condition.

But approaching the situation from another viewpoint, loops are basically a shorthand for writing a repetitive set if individual processes.

I wanted to make a rectangle, so i did this

startshape RECTANGLE

rule RECTANGLE {
SQUARE{ }
SQUARE { x 1 }
}

If I wanted to make a long rectangle, I would just have to keep typing

SQUARE { x 1 }
SQUARE { x 1 }
SQUARE { x 1 }

ect until I had the desired lenght. A simple loop control structure would simplify the process greatly. Approaching a loop from this context makes it seem like a logical inclusion. It would certainly aid in the construction of primitive shapes, and results could quickly be generated that would be incredibly tedious to hand code.

I understand the importance of remaining context free, but it seems to me that context is a relative concept. The location of each new shape is dependant on that of the previous one. I could be wrong, but it seems to me like the previous shape could be considered a context for every shape (the first shape is the only one truly without a context). Where is the line drawn?

Using loops to automate mundane entry may increase creativity, not stifle it. The reason computers are so powerful to us is their ability to do many repetitive operations quickly, so it seems that adding loop structures could possibly increase the power of the program. Interested to hear your responses.

Loops & limits

Posted: Thu Sep 08, 2005 5:19 pm
by Bargonaut
There is a thread here which never resolved the question you raise.

Personally, I'd appreciate the optimization, but you can always write a program to generate the tedious bits for you.

-Brad

Isn't that a different issue?

Posted: Fri Sep 09, 2005 12:11 am
by ateb9025
I've read that thread, and I didn't see where the issue of loops is ever raised. That thread was discussing the addition of a parameter to control the depth of recursion. I'm not sure that these two issues are the same. The inclusion of loops would allow a shorter form of writing operations, and i'm just wondering how such an in clusion would violate the principles of being context free.

Posted: Fri Sep 09, 2005 12:32 pm
by MtnViewJohn
Just a nit, but to make a 4x1 rectangle you do this:

Code: Select all

rule Rectangle {
    SQUARE { size 4 1 }
}
But moving on to your main point, loops and recursion depth are the same thing in Context Free because loops would be implemented in the design grammar using tail recursion. We wouldn't define a for-loop control syntax. Context Free/CFDG has no control syntax at all and I see no reason to add one for looping when recursion will do it for us.

I think that looping/recursion depth control should be added to Context Free, but we should probably refrain from adding the other feature of branching out of the end of the loop. Even though it would be very cool.

But the thing I want to work on next is writing real documentation.

I see.

Posted: Fri Sep 09, 2005 11:55 pm
by ateb9025
Yeah, I see what you mean. You could easily write a recursive rule that would preform any operation a loop would. I've only just started using the program, so I'm still getting my head around it's philosophy.

Anyway, i enjoy using it, and with some documentation i'm sure many more people will be able to enjoy it, which is the important thing :-)

Thanks for the reply.