1. Routine redefinition
This occurred to me when I recently re-read the whole "keyboard help" thread
from last week. Here's my revision of Ralf's excellent solution:
-----------------------------------------
sequence buffer
buffer = {}
function old_get_key()
return get_key()
end function
function get_key()
integer char
if length(buffer) then
char = buffer[1]
buffer = buffer[2..length(buffer)]
return char
else
return old_get_key()
end if
end function
procedure put_key(object x)
buffer &= x
end procedure
------------------------------------------
This works perfectly fine as long as you only use get_key() in your program.
However, if you use wait_key, you're stuck. Sure, you can write a "new"
wait_key() function to make use of your internal buffer, but then you have
to either:
1) Use machine_func() and avoid including get.e in your program, or
2) Call your new function WaitKey() or something, and change all
references to wait_key() in your program to your new name.
As long as Rob is working on the "namespace issue," I would like to propose
a third option in addition to the above two:
3) Be able to redefine *any* Euphoria routine. (Not just the built-ins.)
This way, I could add *this* to the code above:
-----------------------------------------
include get.e
..
function old_wait_key()
return wait_key()
end function
function wait_key() -- redefinition
integer char
if length(buffer) then
char = buffer[1]
buffer = buffer[2..length(buffer)]
return char
else
return old_wait_key()
end if
end function
------------------------------------------
It fits in very nicely with the get_key() redefinition, making use of the
existing internal buffer and put_key() procedure, without any jury-rigging,
machine-level poking, or any other such weirdness. IMHO, this re-definition
ability should be a part of the upcoming namespace solutions.
Anyone else agree/disagree?
Be seeing you,
Gabriel Boehme