My understanding is as follows:

There is a stack containing an entry for each entity that is running. 
This stack represents the chain of calls from entity to entity.  The 
stack entry for an entity includes a locale, which initially is the 
locale that the entity started in.  When the entity completes, it resets 
the current locale to this saved locale, which usually means it sets the 
locale back to what it started at, so that when it returns to the caller 
the caller sees that the current locale is unchanged.

18!:4 y   stores y into this stacked locale, as well as setting the 
current locale to y.  When 18!:4 is used in cocurrent, the stack entry 
we are talking about is the stack entry for the cocurrent verb itself, 
with the result that the locale changes for the verb that called cocurrent.

When 18!:4 is used bare, as it would be when you execute (cocurrent f.) 
in goof, the stack entry that is modified is the entry for goof, with 
the result that the locale changes when 18!:4 is executed and stays 
changed when goof returns.

Henry Rich

david alis wrote:
>  I think this came up a few months ago.. but can someone remind me why
> switching locales works the way it does?
> 
>       foo =: 3 : ('cocurrent''FOO''';'1+2')
>       NB. resets the locale to base
> 
>       foof =: 3 : ('cocurrent f.''FOO''';'1+2')
>       NB. leaves the locale set to FOO
> 
>       goo =: 3 : ('cocurrent''GOO''';'1+2';'empty 3')
>       NB. resets the locale to base (empty is defined in z)
> 
>       goof =: 3 : ('cocurrent f.''GOO''';'1+2';'empty 3')
>       NB. resets the locale to base (this result is unexpected)
> 
>   coname''
> +----+
> |base|
> +----+
>   foo 1
> 3
>   coname''
> +----+
> |base|
> +----+
>   foof 1
> 3
>   coname''
> +---+
> |FOO|
> +---+
>   cocurrent'base'
>   goo 1
>   coname''
> +----+
> |base|
> +----+
>   goof 1
>   coname ''
> +----+
> |base|
> +----+
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
> 
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to