Roelef wrote:

> Further than that I wanted a verb for finding all locations ( not just one)
> in a list where another shorter list appears. 

Try  E.  as in: 

           a=.  '"hello", said he and "hello, " I replied; "a fine day for 
`hello`s"!'

           _13 ]\ 'hello' E. a
        0 1 0 0 0 0 0 0 0 0 0 0 0
        0 0 0 0 0 0 0 0 0 1 0 0 0
        0 0 0 0 0 0 0 0 0 0 0 0 0
        0 0 0 0 0 0 0 0 0 0 0 0 0
        0 0 0 0 0 1 0 0 0 0 0 0 0

> I am still curious about the strange result that I got. 

This is in line with the definition of  $:  ,  which refers to the verb which 
contains it.   In your case,  $:  refers to the sub-function  b  , not the 
overall function   partition_list  .  

The small piece of explicit code is a trick to get  $:  to refer to  b  without 
using names, which is required because  f.  promises its result will contain no 
names (that is its primary function).

In previous versions of J,  f.  treated  $:  differently.  For example, in J5, 
it refused to fix any part of a verb which contained self-reference:

           9!:14''
        j504/2005-03-30/13:35
           
           a  =:  $@:0:
           b  =:  ({.);( $: }.@:])
           c  =:  <:#@:]
           
           ([EMAIL PROTECTED]) f.
        $@:0:[EMAIL PROTECTED](<: #@:])
           
           
And in J4, it made  $:  refer to the overall verb:

           9!:14''
        4.06/2001-07-10/14:00
           
           a  =:  $@:0:
           b  =:  ({.);( $: }.@:])
           c  =:  <:#@:]
           
           ([EMAIL PROTECTED]) f.
        $@:0:`({. ; ($: }.@:]))@.(<: #@:])
           


Both these treatments are incorrect; the former, because it does not honor the 
definition of  f.  ; the latter because it does not honor the definition of  $: 
 .

However, the J4 treatment is useful, especially in cases like yours, where you 
want to build an large definition from several smaller ones, then fix the 
result.  I have created a utility adverb to support that use case.  It is known 
as  fl  (for "fix locals"), and is like  f.  except in its treatment of local 
names. 

You may read about it here:  

   http://www.jsoftware.com/jwiki/DanBron/Temp/Fix_Locals

(note especially the caveats at the end, which document where  fl  differs from 
 f.  .)

And you may download the script here:

   http://www.jsoftware.com/svn/DanBron/trunk/environment/namescope.ijs

Now, if you replace your global assignments (the  =:  ) with local assignments  
(  =.  ) you'll get the behavior you expected.  

NOTE:  you must use  fl  from within a script;  you cannot use it in the 
execution window, because  fl  only fixes local names, and all names assigned 
in immex are global, regardless of the copula used in the assignment.

-Dan
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to