On 09/06/2010 7:50 PM, James Paige wrote:
I have noticed that sometimes new users misunderstand how the "if"
command works. I see someone write code like:
if(condition) then(action)
but this code only runs once in their "new game" script, and they wonder
why "action" fails to happen each and every time that "condition" comes
true
This smells like a PEBCAK problem. At no point in my time programming
have I ever assumed that an if will keep "trying" after the program
moves on. If they want it to loop, they should let someone (i.e., the
compiler) know!
This wouldn't work until script multitasking was supported, but what if
there was a flow control command like:
script, my script, begin
whenever(condition) do(action)
end
This would be shorthand for writing:
script, my script, begin
whenever loop
end
script, whenever loop, begin
while(true) do(
if(condition) then(action)
wait(1)
)
end
Does that seem like a thing that would be worth having? It seems pretty
cool to me... but I can't think of any other language* with a similar
flow control structure, which makes me wonder if it has already been
tried and declared harmful by older wiser minds.
This idea is basically closures
(http://en.wikipedia.org/wiki/Closure_%28computer_science%29). In a
nutshell, a closure is a function that has the following properties:
1. It's a first class data type (i.e, you can store it in a variable,
pass it to other functions, etc).
2. It has access to the enclosing scope. For example, this would be
possible:
script, my script, begin
variable(i)
whenever(condition) do (i += 1)
end
This is the tricky part. But, many languages have similar constructs.
See Ruby, Lua, C#, Javascript, etc. They don't work with exactly these
semantics (i.e., they're not automatically loops), but they're close enough.
(* actually, I can think of one language that has something like this.
The machine language for the ancient Daytronics System-10 mainframe has
the EXU command which executes code any time a logic bit changes state.
This is also the one and ONLY flow control of any kind that the language
supports. All other flow control patterns have to be painstakingly
cobbled together with a series of EXU commands and bit flips)
That sounds insane. I can't imagine trying to make that work.
---
James
PS: I have read the other emails in the thread, I just didn't want to
get sidetracked by the other, IMO, un-related stuff.
--
Mike
_______________________________________________
Ohrrpgce mailing list
[email protected]
http://lists.motherhamster.org/listinfo.cgi/ohrrpgce-motherhamster.org