I've implemented a new feature 'nametabs'. The changes are on the
'nametab' branch on dropboxhub.
Now the old separation between 'functrie', 'operatortrie', 'variabletrie'
has disappeared. All the builtin functions such as 'print', 'add'
etc. have now gone into a 'builtins' nametab.
A nametab is a container of name->object mappings, and a reference to
a 'parent nametab'. When a block is run, it's run in a new nametab
whose parent is the nametab it was run in. For now, programs are run
in the builtins nametab so that they inherit the builtin variables.
So basically, you get local variables with Java 7-ish scope rules. See
'test/nametab.ns' and 'test/ownops.ns' on the new branch for examples.
I've also pasted them here with some editing:-
#A simplistic function that prints '1', '2' and '3' in three separate print
#calls.
{ 3 2 1 &print 3 repeat } $print123
{
#Redefine 'print' locally, keep old print in _print. The new print
#function will print "Printing: <value>, "
&print $_print
{ ', ' rot 'Printing: ' &_print 3 repeat } $print
#Here, print123 will use the new 'print'.
print123
} 1 repeat
#Here, print123 will use the normal 'print'.
print123
#There's no difference between operators and normal execuspacele
#variables. Operators just have funky names. Here we create an exponent
#operator.
{
$p $n
#Put n on the stack p times, then multiply p times. We also put a 1 on
#the stack to allow for p = 0.
1
{ n } p repeat
&* p repeat
} $^
2 3 ^ print
#Here we assign a number to the variable !^&.
42 $!^&
!^& print
#Here we assign &print to + temporarily within a block to make + print
#instead of adding numbers. Outside the block it's back to normal.
{
&print $+
#Prints '3'.
3 +
} 1 repeat #TODO: Add an 'exec' function to just run a block?
2 3 + print #Here it prints '5'.
-- Nikhilesh S http://www.nikhilesh.infoReceived on Fri Aug 27 2010 - 03:26:12 CEST
This archive was generated by hypermail 2.2.0 : Fri Aug 27 2010 - 02:36:02 CEST