On 30 Aug 2003 eas-lab@absamail.co.za wrote:
> define :ved_runtime_action;
> .......
> vedsetkey('\^[[24~', ved_add_for());
> enddefine;
Almost right, apart from '()'.
After a procedure expression '()' means run the procedure, and use its
results (if any) in that context.
It's equivalent to '.' before the procedure expression.
This procedure has no results, hence your STACK EMPTY message when
vedsetkey tries to take two things off the stack and finds only the
string.
If you remove '()' that says, give vedsetkey the string and the
procedure, without running the procedure:
> vedsetkey('\^[[24~', ved_add_for);
(Sometimes you need to provide a procedure and some arguments, in which
case partial application can be used, e.g. We can give vedsetkey the
procedure veddo and the string 'add_for' as an argument to be used
later:
> vedsetkey('\^[[24~', veddo(%'add_for'%) );
This partially applies veddo to the string 'add_for' to create
a closure (a kind of procedure with attached data). When the
closure is run veddo takes the string and does the same thing
as ved would do if you gave the command
ENTER add_for
So a frequently used ENTER command can be attached to a key or short key
sequence. (In this case it's spurious complexity, just to illustrate
a technique, because there are two ways of running ved_add_for.)
> And compile/run, gives me:-
>
> 1. mishap - ste STACK EMPTY
> line <after the modified line>
> 2. The "for" structue is written at the cursor !!?
Because ved_add_for is invoked instead of merely being referred to,
as explained above.
(Some programming languages don't allow you to refer to a procedure
except by invoking it : some people summarise this and other things by
saying such languages don't treat procedures as first-class objects.
Pop-11 and Common lisp are among the few that do.)
Aaron
Aaron Sloman, ( http://www.cs.bham.ac.uk/~axs/ )
|