next up previous contents
Next: The COPY DQF Up: Jumping and Copying Previous: The JUMP* DQFs   Contents

Looping with GET_LINK and JUMP*

The loop described above was possible because MCVX_BACKTRACK is a very unusual DQF in that it can update a link word that was defined earlier in the n-tuple. The GET_LINK DQF can also update a link word if it is supplied as the second, optional argument. For example, if _my_pmt is a link to a PMT bank, then:-

 
' _             get_link       _my_pmt-0, _my_pmt;       '
will follow the 0 link (i.e. next PMT) and store it back in _my_pmt. When using GET_LINK like this you probably won't want its primary output, so the dummy name _ comes in handy again. Being able to define links and then update them allows you to build loops and even nest them within other loops to wander anywhere over the data structure! Having built a loop, you also need a way to escape, if fact you will need two: one if you find what you want, and another if you don't. This is where JUMP_UNDEFINED comes in handy as this little loop example demonstrates:-

 
' _my_vx        get_link        MC-$KMC_MCVX;                    '
' _test_link    jump_undefined  -999., _my_vx;                   '
#.
#.    Do some tests on the current MCVX pointed to by _mv_vx
#.    Store results in n-tuple including test _good_vx which is
#.    set non-zero when a satisfactory MCVX is found.
#.
' _             jump_true       +999., -good_vx;                 '
' _             get_link        _my_vx-0, _my_vx;                '
' _             jump_true       _test_link, 1.                   '
The first line gets the very first MCVX in the chain supported by MC. The next line tests to see if the word pointed to by _my_vx is defined, which is the same as saying that the link isn't zero. Don't fall into the trap of thinking you need to use JUMP_FALSE, this tests to see if _my_vx points to a word that holds a zero! If the link is undefined the loop aborts by jumping beyond the first entry. The value -999. is a recommended style to make it clear that you are aborting. Next come the meat of the n-tuple where data is collected and test made to see if this is a suitable vertex. The loop ends by seeing if _good_vx is true. If it is the jump of +999. jumps off the end of the n-tuple, but this time it is kept. Again the value of +999. is a recommended style. If the current vertex is unsatisfactory, the MCVX link is moved on and an unconditional jump (1. is always true) is made back to test if the end of the loop over MCVXs has been reached.


next up previous contents
Next: The COPY DQF Up: Jumping and Copying Previous: The JUMP* DQFs   Contents
sno Guest Acct 2009-09-09