🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.misc
Article #3196

Re: CHALLENGE: heterogeneous collections

#3196
From: Darren New
Date: Tue, 26 Mar 1991 17:32
127 lines
7010 bytes
In article <25MAR91.22422777@uc780.umd.edu> cs450a03@uc780.umd.edu writes:
>Darren New writes:
>>Hmm...  How about a window with a hetrogeneous collection of buttons,
>>sliders, text displays, etc, all of which respond to "redraw" and "is
>>the mouse over you"?
>
>The way I look at things, I'd probably think of that as a homogenous
>collection.  It's only when you get to taking the things apart that
>you can really see any distinction between them.  (Or maybe, when you
>try to pass a paragraph of text through a slider.)

Hmm... a homogenous collection that when you take it apart yields things
with different types. Somehow, I think we are confused over terminology.
Either that, or you are reaching for straws :-) The whole point of
a hetrogeneous collection is that sometimes you treat everything
the same and sometimes you treat each thing differently.

Let's call a "hetrogeneous collection" something that holds
multiple values of multiple types and over which some code iterates
(hence the "collection" part) and over which other code applies
different functions depending on the type (hence the "hetrogeneous"
part). 

If this isn't a good enough definition, then all I can say is
"When you drive screws with a hammer, *nothing* looks like a
screwdriver."

In the above case, the routine to refresh the screen will iterate over
the entire collection, while the routine to actually do the redrawing
(which clearly must be dynamically bound) will do different things
based on the type (slider, button, ...) of the object. Looks like a
hetrogeneous collection to me.

Note that this definition rules out a bunch of things which I might
call hetrogeneous collections.  For example, the arguments to a C
function, which I've never iterated over in spite of it being a
collection and of hetro types. The same goes for argv[] in "cp -i a.out
/bin", in which argv[0] is an executable, argv[1] is a control flag,
argv[2] is a file, and argv[3] is a directory.  This is kind of iffy,
because some programs iterate over some or all of argv[] (like "echo")
and others never iterate over argv[].  However, in AmigaDOS under the
Workbench (i.e., the icon-based command interpreter), all four of these
parameters would be passed separately and in different places (not
argv[]); this leads me to believe that argv should be considered a
hetro collection. (Note that in AmigaDOS, there is another type for
argv[], namely file wildcard. This goes back to the globbing thread.  :-)

Take, for another example, PostScript procedures:
{ /moveit { 2 0.5 moveto } def }

This is a procedure array (procedures are arrays in ps) containing
a literal name, an array, and an executable name. The inner array
contains an integer, a float, and an executable name. If bound, the
executable names become operators. The "inner interpreter" iterates
over the elements of the array and either pushes or calls, based on
the type of the object. Looks like a hetrogeneous collection to me.

What about the heap in C? Malloc iterates over the allocated blocks
while seeking a free one, while other code indexes different blocks
differently. Looks like a hetro collection to me.

Memory itself is a hetrogeneous collection of integers, floats,
pointers to code, pointers to data, etc. Block moves iterate
over it, other instructions treat it differently depending on
the instruction. If you pass the wrong type of value to an
instruction, you get garbage out.

!file /bin/a*
/bin/acctcom:	mc68020 demand paged dynamically linked executable
/bin/adb:	mc68020 demand paged dynamically linked executable
/bin/addbib:	mc68020 demand paged dynamically linked executable
/bin/adjacentscreens:	symbolic link to sunview1/adjacentscreens
/bin/aedplot:	mc68020 demand paged dynamically linked executable
/bin/align_equals:	symbolic link to sunview1/align_equals
/bin/ar:	mc68020 demand paged dynamically linked executable
/bin/arch:	executable shell script
/bin/as:	mc68020 demand paged dynamically linked executable
/bin/at:	mc68020 demand paged dynamically linked set-uid executable
/bin/atoplot:	mc68020 demand paged dynamically linked executable
/bin/atq:	mc68020 demand paged dynamically linked set-uid executable
/bin/atrm:	mc68020 demand paged dynamically linked set-uid executable
/bin/awk:	mc68020 demand paged dynamically linked executable

Sure looks like "file" (or the shell) iterated over /bin. Sure looks
like execv() is going to do different things depending on what element
of the collection is passed to it. Before you convince me that
directories are not hetrogeneous, you'll have to explain what EISDIR
and ENOTDIR mean other than "dynamic type mismatch error".

!cc -O2 main.c special.s prev.o lib.a 
Sure looks to me like a hetro list of file types passed as argv[].
The first is an integer parameter, the second is a C source, etc.
Here, the "inner interpreter" selects based on first and last
characters of argv[] to determine what to do.

!ls ~new/tex/thesis
biblio.bib darren.bst figures makeheads makeps outline.txt psfig.aux
thesis.aux thesis.bbl thesis.blg thesis.dvi thesis.loe thesis.lof
thesis.log thesis.ps thesis.tex thesis.toc

Hmmm.... Looks like that directory has a hetrogeneous collection of
bibliography files, bibliography styles, DVI files, lists of figures,
log file, postscript files, tex files, etc. If I passed them all to
lpr, do you think the same filter would be applied to each?

printf("line %d percent complete %f file %s", ii, ff, ss);
Sure looks like printf iterates over its arguments. Sure looks
like the arguments are not all the same type. Isn't there an
entire standard header file to handle hetrogeneous argument lists?

C'mon people.  I can't believe that you never used a hetrogeneous
collection.  I can't believe Dan B even tried to think of where he
might have used a hetrogeneous list; he's too smart to have missed all
these examples.

Dynamic binding goes hand-in-hand with hetrogeneous collections. 
Any time you use or implement dynamic binding, you probably have
a hetrogeneous collection in there somewhere, or you could
have used static binding.    

		  -- Darren

-- 
--- Darren New --- Grad Student --- CIS --- Univ. of Delaware ---
----- Network Protocols, Graphics, Programming Languages, 
      Formal Description Techniques (esp. Estelle), Coffee, Amigas -----
  +=+=+ My time is very valuable, but unfortunately only to me +=+=+
Technical Details
Message-ID: <48913@nigel.ee.udel.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!udel!ee.udel.edu
References: <pallas.669923769@red-dwarf> <48805@nigel.ee.udel.edu> <25MAR91.22422777@uc780.umd.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!udel!ee.udel.edu
From: new@ee.udel.edu (Darren New)
Newsgroups: comp.lang.misc
Subject: Re: CHALLENGE: heterogeneous collections
Message-ID: <48913@nigel.ee.udel.edu>
Date: 26 Mar 91 17:32:39 GMT
References: <pallas.669923769@red-dwarf> <48805@nigel.ee.udel.edu> <25MAR91.22422777@uc780.umd.edu>
Sender: usenet@ee.udel.edu
Organization: University of Delaware
Lines: 127
Nntp-Posting-Host: estelle.ee.udel.edu