[Date Prev] [Date Next] [Thread Prev] [Thread Next] Date Index Thread Index Search archive:
Date:Mon Jun 25 16:32:27 1993 
Subject:Re: BUG in POP11 
From:Julian Clinton 
Volume-ID:930625.07 

Helen

>section $-banana
>    =>
>    TAIL
>;
>    define TAIL(L) -> RESULT;
>        L --> [= ??RESULT] ;
>    enddefine;
>
>endsection;

This doesn't work because the --> matcher looks up variable names
at runtime rather than compile time.

At compile time, RESULT is declared within section $-banana. At runtime
the code is being executed from the top-level section so when
the matcher reads the pattern on the right side of the match arrow,
it tries to access a variable called RESULT in the top-level section.
As there isn't one, a new one gets declared and the matcher assigns
the result to that. When TAIL exits, it simply returns the value
of RESULT within section $-banana i.e. <undef RESULT>. If you print the
value of RESULT at the top-level prompt, you'll see it has had the
correct match list assigned to it.

If you try executing the call of TAIL within section $-banana,
the result is correct:

Setpop
: section $-banana;
: TAIL([a b c d])=>
** [b c d]
: endsection;

It'll also work if you export RESULT from section $-banana.

If you don't want to change the pattern you're matching against
at runtime, use LIB *FMATCHES (described in HELP *FMATCHES) as
this creates references at compile time and so works with sections.

Julian