Newsgroups: comp.lang.apl
Path: watmath!watserv2.uwaterloo.ca!torn!cs.utexas.edu!uwm.edu!ux1.cso.uiuc.edu!news.cso.uiuc.edu!mm-mac25.mse.uiuc.edu!gaylord
From: Richard J. Gaylord <gaylord@ux1.cso.uiuc.edu>
Subject: are all members in a list atomic?
Message-ID: <ByqoGB.B55@news.cso.uiuc.edu>
X-Xxdate: Fri, 4 Dec 92 08:35:32 GMT
Sender: usenet@news.cso.uiuc.edu (Net Noise owner)
X-Useragent: Nuntius v1.1.1d13
Organization: University of Illinois
Date: Fri, 4 Dec 1992 14:33:46 GMT
X-Xxmessage-Id: <A744C8D41B029B19@mm-mac25.mse.uiuc.edu>
Lines: 58

in a recent pair of postings the following was sought and answered:

returns  true if the input is a list of atoms, and returns
false otherwise:

isatom =. -.@#@$@>@{.
   isnull =.   (0&=)@#
   lat =. ((0:)`(lat@}.) @. isatom)`(1:) @. isnull
   
   s =. 2 ; 3 ; 4 ; 5
   t =. 2 ; 3 ; 5 6 ; 7

   lat s  .NB returns 1 for a variable having only boxed atoms

  lat t  .NB returns 0 for a noun having at least one list


==============

this is an important function to have when dealing with a language that
is not strongly typed. Mathematica (which has much in common with APL and
 J) is such a language  and it is of some value to see how this function
might be written in Mathematica:

atomicList = (And@@(AtomQ/@#))&

we can demonstrate this function using the lists given above: 

s = {2, 3, 4, 5}
t = {2, 3, {5, 6}, 7}

atomicList[t]
False

atomicList[s]
True

the anonymous function atomicList can be dissected and put in more
readable form:

atomicList[x_List] := Apply[And, Map[AtomQ, x]

working to the outside, Map[AtomQ,x] applies the predicate AtomQ to each
element in 
the list x thereby creating a list of True and False entries. Apply then
applies the logical And function to all of elements in the list
immediately returning False if any of them are False and returning True
otherwise.

It is possible to go beyond the question of atomic types and ask if all
of the elements in a list have the type . This is done easiest using a
rule-based or transformational approach.

This sort of thing  will be discussed at the half-day tutorial:

"Mathematica Programming Programming for APl'ers"

at the APL93 meeting in August.
