02:04:40
##forth
<vms14>
pgimeno I convert the recursive word into a loop
02:05:04
##forth
<vms14>
recurse is immediate and makes a marker for ; to know it's recursive
02:05:30
##forth
<vms14>
then ; creates a special function that will have a loop
02:05:37
##forth
<vms14>
: oh recurse ;
02:07:26
##forth
<vms14>
recurse marks oh as recursive, then ; sees that oh is recursive, it generates a loop with a flag like while ($recursive{$word_name}) { $recursive{$word_name} = 0; for my $code (@code) { $code->(); if ($recursive{$word_name}) { last } }
02:08:00
##forth
<vms14>
the recurse word when executed sets $recursive{$word_name} = 1
02:09:03
##forth
<vms14>
I did not test it properly, but what I tried seems to work
02:10:02
##forth
<vms14>
that's the code for ;
02:10:53
##forth
<vms14>
now I have to add does> and I guess ; will grow more than I would like to
02:10:54
##forth
<vms14>
the does> code should be also recursive?
02:11:20
##forth
<vms14>
the standard seems to say does> cannot be used in conditionals or loops
02:17:04
##forth
<vms14>
: WEIRD: CREATE DOES> 1 + DOES> 2 + ;
02:17:42
##forth
<vms14>
I have to implement it so it can do that too
02:17:56
##forth
<vms14>
I guess I will try tomorrow
02:18:19
##forth
<vms14>
the rest of today I will read a forth book and implement what I see there
10:16:04
##forth
<pgimeno>
vms14: a jump for RECURSE only works for tail recursion. If the recursion is not a tail call, you can't return to where it was called from.
10:21:58
##forth
<pgimeno>
for example, this returns 2*(argument - 1): : test 1- dup 0= if exit then recurse 1+ 1+ ;
10:22:24
##forth
<pgimeno>
7 test . 12 ok
10:22:24
##forth
<pgimeno>
13 test . 24 ok
12:57:10
##forth
<vms14>
1+ 1+ never get executed
12:57:36
##forth
<vms14>
: test 1- dup 0= if exit then .s recurse 1+ 1+ ;
12:57:48
##forth
<vms14>
goes from 7 to 0
13:00:00
##forth
<vms14>
you can test yourself if you want to and see whether it works fine
13:00:19
##forth
<vms14>
actually I need to test that the words I have work like in forth
13:00:27
##forth
<vms14>
so some feedback would be appreciated
13:01:05
##forth
<vms14>
if you give that file to perl will launch a repl
13:01:13
##forth
<vms14>
although I recommend rlwrap
13:01:50
##forth
<vms14>
but it's missing a lot of words, those are the ones that I have right now
13:01:54
##forth
<vms14>
.( ; colors rot tb :noname ." exit newline edit create here if @ ps k dup spaces .cr [char] swap defer /mod drop , ?dup .s 2drop recurse char tab 2over prompt is emit + i ' 1+ ] . mod .sp ins do f / wipe over ['] cursor : rr " blank j ( 1- allot - space sp no.colors 2+ variable * t cr color .words 2dup 0= ! [ r 2- 2swap ..
13:02:59
##forth
<vms14>
create is not working properly because I was thinking about its behavior yesterday
13:04:39
##forth
<GeDaMo>
vms14: do you have something to tell you the last word added to the dictionary?
13:04:45
##forth
<vms14>
do also behaves a. bit different
13:04:49
##forth
<vms14>
GeDaMo yeah
13:05:03
##forth
<vms14>
that's how ; knows what entry to create
13:05:39
##forth
<vms14>
it's just a global variable that : will set with the name it reads
13:06:33
##forth
<GeDaMo>
create also adds words to the dictionary
13:07:01
##forth
<GeDaMo>
: should be doing the equivalent of calling create
13:09:20
##forth
<GeDaMo>
Do you have a single memory spaceor separate areas for each word?
13:10:52
##forth
<vms14>
the dictionary is a hash table and words are perl functions
13:10:52
##forth
<vms14>
I do have an array for memory as an additional thing
13:11:11
##forth
<GeDaMo>
So the data space is a memory array?
13:11:20
##forth
<vms14>
yes :/
13:12:07
##forth
<vms14>
$dictionary{$name} = sub { put $pointer };
13:12:14
##forth
<vms14>
that's what create does
13:12:28
##forth
<vms14>
$pointer is a local copy of $here to retain its value
13:12:41
##forth
<GeDaMo>
Sounds reasonable