Newsgroups: comp.lang.apl
Path: watmath!watserv2.uwaterloo.ca!torn!cs.utexas.edu!zaphod.mps.ohio-state.edu!wupost!csus.edu!sfsuvax1.sfsu.edu!emclean
From: emclean@sfsuvax1.sfsu.edu (Emmett McLean)
Subject: Re: are all members in a list atomic?
Message-ID: <1992Dec4.193716.4358@csus.edu>
Sender: news@csus.edu
Organization: San Francisco State University
References: <ByqoGB.B55@news.cso.uiuc.edu>
Date: Fri, 4 Dec 1992 19:37:16 GMT
Lines: 54

   I posted "lat" in a spirit of literal translation
   of the Scheme program. Upon rereading I see
   that a cond-less solution was requested. Since
   cond is implemented as J's Agenda, "@." , I did not
   really address the question. A solution more in
   sprit of the original request is shown below, but
   first :
 
   Here is the 

   Literal J translation of the mathematica program
   "atomicList = (And@@(AtomQ/@#))&" 
   
   isatom =. 0&=@#@$
   atomicList =. (*./)@:>@:(isatom&.>) 

   atomicList, broken down from right to left does the following:
   (isatom&.>) discloses each box, applies isatom to each
   element, and then re-boxes the result.

   ">" opens the result providing a boolean vector consisting of
   1's for atoms and 0's for lists.

	   ] t =. 2 ; 3 4 5 ; 6
	+-+-----+-+
	|2|3 4 5|6|
	+-+-----+-+
	   (isatom&.>) t
	+-+-+-+
	|1|0|1|
	+-+-+-+
	   >(isatom&.>) t
	1 0 1
	   
   Then "*./" andscans the result.

   A cond-less solution not using andscan more in spirit of the
   original post is:

   isatom =. 0&=@#@$
   mylat =. -.@:(0&e.)@:>@:(isatom&.>) 

   This verb, works much like "atomicList" except it applies
   the verb "e.", called "Member(In)",
   which is curried to a zero, to return a 1 if 0 is
   an element of the list. Then "-." ("not")
   returns the complement of the result.

   By all this I wanted to demonstrate that control constructs
   in J are flexible enough to provide programmers the capability
   of translating program written in Scheme or LISP without
   having to use control constructs unique to J. 

   Emmett emclean@sfsuvax1.sfsu.edu
