to gifts :today if :today = 0 [op []] op fput thing thing :today gifts :today - 1 endBy using the expression thing thing :today, each clone of gifts has direct access to just one of the gifts. For example, if :today is 1, then, given the way in which the variables are inter-nested, thing :today is "first and thing thing :today outputs [a partridge in a pear tree]. What the each clone must ensure, therefore, is that the particular gift which it (alone) is able to retrieve in this way becomes part of the full list of gifts to which its team-mates all contribute.
The order of the gifts in the verse matters, of course. The first of the gifts which is listed in any verse is always the new gift of the current day and it is followed by the full list of gifts offered on the previous day or, putting it differently, by the gifts for each preceding day in turn down to the gift for the very first day. If gifts is called with :today set at 7, it must ensure, therefore, that it ouputs the gift which it retrieves, at the head of a list which corresponds to the gifts which are output when :today is set at 6.
But, clearly, this is only barely disguised Logo-speak:
output firstput today's gift gifts yesterday
Today's gift, we know, is thing thing :today and yesterday is undoubtedly :today -1. If we simply replace the italicised phrases by the corresponding Logo expressions we have immediately the final instruction of gifts.
op fput thing thing :today gifts :today - 1
You can see clearly now why we are calling such a pattern an indirect call to a clone? Gifts(n+1) is not called on by op directly to provide an object for immediate output. Instead, the parent procedure, Gifts(n), uses fput to hold onto the latest gift (as its first input) until gifts(n+1) (the recursive call) comes up with the second input and thus provides the list into which the first input is then placed. Only at that stage is the newly expanded list passed to op (and the outside world).
You can also see that, although the recursive call is contained within the last instruction of gifts, Logo needs to ensure that control is handed back to the caller - who has fput waiting with a first input at the ready - so that the necessary processing can be completed. This procedure is therefore not tail recursive. Fortunately, with only twelve verses to handle, there is little depth to the recursion and the dreaded OUT OF STACK SPACE won't be seen.
E-mail: ron.brasington@rdg.ac.uk