I'm not sure if this is the "correct" forum or not, but of all four fora/forums 
this seemed the closest.  (Please point me to the proper forum for future 
messages if this is NOT the correct forum for these kinds of queries.)

In a number of messages over the past year or so, I've noticed that the 
solution to some of the difficulties that people were having was that the kind 
of data that *actually* resulted from some series of data manipulations was not 
what people *thought* was resulting.  As a beginner, I thought this issue was 
something I needed a practical tool for, as I experimented and investigated 
various kinds of things (such as piece-by-piece analyses of scripts and 
programs written by others as well as debugging my own first attempts at 
writing J code).  And so I came up with a verb/function named "about" that 
tells me basic information about data: a brief description of the data, the 
shape of the data, and the type of data in the leading element.  The syntax is, 
for example, "about data1" (no quotes, of course).  I intended this utility for 
use by beginners like myself.  By the way, since the documentation has a 
preferred terminology (atom, list, table) as well as an alternate terminology 
(scalar, vector, matrix), I included both (separated by a slash) in the 
"description" information.

Here's the function I wrote:

==================================================
about =: 3 : 0
NB. by Harvey E. Hahn -- 5 Mar 2008
shape =. $y
rank =. [EMAIL PROTECTED] y
if. 1<rank do.
  value =. 'TABLE/MATRIX'
elseif. 1=rank do.
  value =. 'LIST/VECTOR'
elseif. do.
  value =. 'ATOM/SCALAR'
end.
typval =. 3!:0 y
if. (32=typval) do.
  value =. 'BOXED ',value
  typval =. 3!:0 >(0{y)    NB. leading item of y
end.
select. typval
  case. 1 do. typ =. 'integer/boolean'
  case. 2 do. typ =. 'literal'
  case. 4 do. typ =. 'integer'
  case. 8 do. typ =. 'floating point'
  case. 16 do. typ =. 'complex'
  case. 32 do. typ =. 'boxed'
  case. 64 do. typ =. 'extended integer'
  case. 128 do. typ =. 'rational'
  case. 1024 do. typ =. 'sparse boolean'
  case. 2048 do. typ =. 'sparse literal'
  case. 4096 do. typ =. 'sparse integer'
  case. 8192 do. typ =. 'sparse floating point'
  case. 16384 do. typ =. 'sparse complex'
  case. 32768 do. typ =. 'sparse boxed'
  case. 65536 do. typ =. 'symbol'
  case. 131072 do. typ =. 'unicode'
end.
value;shape;typ
)
==================================================

My question to the group:

This is my first version of a rather elementary level function, and so are 
there any huge holes for beginner use that I've forgotten to account for?

I'm also thinking of the possibility of making the function dyadic, so that a 
left value of 0 (default, if no value given) makes the function operate as 
above, but a left value of 1 (or perhaps nonzero) adds a row of boxes above the 
current information with descriptors of the three pieces of information (such 
as "description", "shape", and "datatype").

On the other hand, maybe this function already exists, buried somewhere in the 
J documentation.  If that's the case, I won't say that I guess I did this work 
for nothing, because I've learned a lot in the process!

Thanks for your assistance!

Harvey
 
--
===========================================
Harvey E. Hahn, Manager, Technical Services Department
Arlington Heights (Illinois) Memorial Library
847/506-2644 - FX: 847/506-2650 - Email: hhahn(at)ahml(dot)info
OML & Scripts web pages: http://www.ahml.info/oml/
Personal web pages: http://users.anet.com/~packrat

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

Reply via email to