home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group91c.txt < prev    next >
Internet Message Format  |  1991-10-25  |  456KB

  1. From ralph  Thu Jun 13 12:10:02 1991
  2. Date: Thu, 13 Jun 91 12:10:02 MST
  3. From: "Ralph Griswold" <ralph>
  4. Message-Id: <9106131910.AA20178@cheltenham.cs.arizona.edu>
  5. Received: by cheltenham.cs.arizona.edu; Thu, 13 Jun 91 12:10:02 MST
  6. To: uunet!luvthang.aquin.ori-cal.com!talmage
  7. Subject: Re:  Increasing the number of concurrently open files
  8. Cc: icon-group
  9.  
  10. The number of files you can have open at the same time is determined
  11. by your operating system, not by Icon.  On some operating systems,
  12. you can specify the number.  The method varies with the operating
  13. system. On other systems, it's "hardwired" and there's nothing
  14. you can do about it.
  15.  
  16.   Ralph Griswold / Dept of Computer Science / Univ of Arizona / Tucson, AZ 85721
  17.   +1 602 621 6609   ralph@cs.arizona.edu  uunet!arizona!ralph
  18.  
  19. From isidev!nowlin@uunet.uu.net  Fri Jun 14 15:44:24 1991
  20. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Fri, 14 Jun 91 15:44:24 MST
  21. Received: from relay2.UU.NET by optima.cs.arizona.edu (4.1/15)
  22.     id AA24767; Fri, 14 Jun 91 15:44:21 MST
  23. Received: from uunet.uu.net (via LOCALHOST.UU.NET) by relay2.UU.NET with SMTP 
  24.     (5.61/UUNET-internet-primary) id AA22433; Fri, 14 Jun 91 18:44:26 -0400
  25. Date: Fri, 14 Jun 91 18:44:26 -0400
  26. From: isidev!nowlin@uunet.uu.net
  27. Message-Id: <9106142244.AA22433@relay2.UU.NET>
  28. Received: from isidev.UUCP by uunet.uu.net with UUCP/RMAIL
  29.     (queueing-rmail) id 184343.9427; Fri, 14 Jun 1991 18:43:43 EDT
  30. To: uunet!cs.arizona.edu!icon-group@uunet.uu.net
  31. Subject: Re: ansi routines
  32.  
  33.  > From: Richard L. Goerwitz
  34.  > 
  35.  > shafto@EOS.ARC.NASA.GOV (Michael Shafto) writes:
  36.  > 
  37.  > > Yes, and I would be interested in testing your new improved version.
  38.  >
  39.  > I wasn't clear enough: My version is expanded (in the sense that the ANSI
  40.  > interface can be applied to non-ANSI terminals).  I'm not sure that it
  41.  > really constitutes an improvement.  Anyway, I haven't had enough requests
  42.  > to consider posting, so I reiterate the offer of sending them to anyone who
  43.  > wants to use them.
  44.  
  45. We (ISI) would like to see the expanded ansi routines to compare with the
  46. beta version of our Enhanced Character Interface (ECI).  This is a
  47. character based windowing interface implemented in Icon at the C level.  We
  48. demonstrated a prototype at the last ICEBOL conference.
  49.  
  50.  > It's really a good idea to used generalized I/O for any programs written in
  51.  > Icon, since Icon runs on so many platforms.  These new ANSI routines have
  52.  > ... 
  53.  > The idea is to have a generalized library of screen functions that DOS
  54.  > users can blindly use, which take up minimal space, are fairly fast, and
  55.  > which can be augmented for Unix without having to change a single line of
  56.  > ...
  57.  > You know, speaking of screen control, I wrote a set of Icon-based windowing
  58.  > routines some time ago.  They let you open up virtual screens, move them
  59.  > ... 
  60.  > The reason I didn't post them is quite simple: Although they were fast
  61.  > enough for most purposes, they ate up way, way too much memory.
  62.  > ...
  63.  > I guess I wish that Icon had some sort of explicit pointer data type.
  64.  
  65. ISI's Icon for 386 UNIX will provide an interesting interface to the
  66. standard curses/eti (Extended Terminal Interface) functionality introduced
  67. to UNIX with SVR3.2.  We think many programs can benefit from a screen
  68. oriented user interface so we came up with ECI.  It has the ability to open
  69. multiple "text", "menu", or "form" windows.  Window borders, titles, sizes,
  70. etc. all have defaults but can be explicitly specified by the user.
  71. Everything happens at the C level so it's fast and pointers aren't needed.
  72.  
  73. Programming with ECI is done at the appropriate level in Icon.  For
  74. example, the code to create a menu looks something like this:
  75.  
  76.    choices := ["bank","savings and loan","mattress"]
  77.    smenu   := wcreate("menu","Choose a Savings Plan",choices)
  78.    choice  := post_menu(smenu) # displays the menu window and
  79.                                # returns the user's choice
  80.    unpost_menu(smenu)          # erases the menu
  81.  
  82. We're interested in feedback on whether this functionality should be made a
  83. standard part of our Icon or an add-on.  The reason for making it an add-on
  84. is because all this doesn't come for free.  The size of iconx at least
  85. doubles.  Any and all comments are appreciated.  Thanks.
  86.  
  87.   --- ---
  88.    | S | Iconic Software, Inc.  -  Jerry Nowlin  -  uunet!isidev!nowlin
  89.   --- ---
  90.  
  91.  
  92. From icon-group-request@arizona.edu  Fri Jun 14 19:43:50 1991
  93. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Fri, 14 Jun 91 19:43:50 MST
  94. Resent-From: icon-group-request@arizona.edu
  95. Received: from Arizona.edu (Merlin.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  96.     id AA00938; Fri, 14 Jun 91 19:43:47 MST
  97. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Fri, 14 Jun
  98.  1991 19:43 MST
  99. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA15793; Fri, 14 Jun 91
  100.  19:36:27 -0700
  101. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  102.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  103.  usenet@ucbvax.Berkeley.EDU if you have questions)
  104. Resent-Date: Fri, 14 Jun 1991 19:43 MST
  105. Date: 15 Jun 91 01:40:43 GMT
  106. From: cis.ohio-state.edu!pacific.mps.ohio-state.edu!linac!midway!ellis.uchicago.edu!goer@ucbvax.berkeley.edu (Richard L.
  107.  Goerwitz)
  108. Subject: RE: ansi routines
  109. Sender: icon-group-request@arizona.edu
  110. Resent-To: icon-group@cs.arizona.edu
  111. To: icon-group@arizona.edu
  112. Resent-Message-Id: <088BCD8B5E200B2B@Arizona.edu>
  113. Message-Id: <1991Jun15.014043.20745@midway.uchicago.edu>
  114. X-Envelope-To: icon-group@CS.Arizona.EDU
  115. X-Vms-To: icon-group@Arizona.edu
  116. Organization: University of Chicago
  117. References: <9106142244.AA22433@relay2.UU.NET>
  118.  
  119. In article <9106142244.AA22433@relay2.UU.NET> nowlin@isidev.UUCP writes:
  120.  
  121. >We (ISI) would like to see the expanded ansi routines to compare with the
  122. >beta version of our Enhanced Character Interface (ECI).  This is a
  123. >character based windowing interface implemented in Icon at the C level.  We
  124. >demonstrated a prototype at the last ICEBOL conference.
  125.  
  126. They are very minimal ANSI routines, and in fact are completely compatible
  127. with the ansi.icn file included in the IPL.  I've been accumulating enough
  128. requests that I've decided to post the routines.  They are appended below.
  129.  
  130. >[Stuff on ECI - a great idea - deleted, as also some examples illustrating
  131. >high-level, generalized screen control.]
  132. >
  133. >We're interested in feedback on whether this functionality should be made a
  134. >standard part of our Icon or an add-on.  The reason for making it an add-on
  135. >is because all this doesn't come for free.  The size of iconx at least
  136. >doubles.  Any and all comments are appreciated.  Thanks.
  137.  
  138. I'd vote that that you not include it as part of the standard package.
  139. First of all, is it OS-specific (only for systems with SysVr3 curses)?
  140. If so, then it definitely needs to be separated out.  I hear of inter-
  141. faces being built for X, and perhaps for other visual environments, in
  142. addition to ECI.  I guess I'd like to see them all built as add-ons.
  143. What would be really nice is if everyone kept in touch, and attempted
  144. to use a similar approach.
  145.  
  146. -Richard
  147.  
  148.  
  149. ----------------------------- ansi2.icn ------------------------------
  150. ############################################################################ 
  151. #    Name:    ansi2.icn
  152. #    Title:    ANSI-based terminal control library
  153. #    Author: Ralph E. Griswold and Richard Goerwitz
  154. #    Version: 1.1 (pretty much untested)
  155. ############################################################################ 
  156. #     This package of procedures implements a subset of the ANSI terminal
  157. #  control sequences.  The names of the procedures are taken directly from
  158. #  the ANSI names.  If it is necessary to use these routines with non-ANSI
  159. #  devices, link in iolib.icn, and (optionally) iscreen.icn as well.  Use
  160. #  will be made of whatever routines are made available via either of these
  161. #  libraries.  Be careful of naming conflicts if you link in iscreen.icn.
  162. #  It contains procedures like "clear" and "boldface."
  163. #
  164. #     CUB(i)        Moves the cursor left i columns
  165. #     CUD(i)        Moves the cursor down i rows
  166. #     CUF(i)        Moves the cursor right i columns
  167. #     CUP(i,j)    Moves the cursor to row i, column j
  168. #     CUU(i)        Moves the cursor up i rows
  169. #     ED(i)        Erases screen: i = 0, cursor to end; i = 1,
  170. #               beginning to cursor; i = 2, all (default 2)
  171. #     EL(i)        Erases data in cursor row: i = 0, cursor to
  172. #               end; i = 1, beginning to cursor; i = 2, all
  173. #               (default 0)
  174. #     SGR(i)        Sets video attributes: 0 = off; 1 = bold; 4 =
  175. #               underscore; 5 = blink; 7 = reverse (default
  176. #               0)    
  177. #
  178. #     Note that not all so-called ANSI terminals support every ANSI
  179. #  screen control sequence - not even the limited subset included in
  180. #  this file.
  181. #
  182. #     If you plan on using these routines with non-ANSI magic-cookie
  183. #  terminals (e.g. a Wyse-50) then it is strongly recommended that you
  184. #  link in iolib or itlib *and* iscreen (not just iolib or itlib by
  185. #  itself).  The routines WILL WORK with most magic cookie terminals;
  186. #  they just don't always get all the modes displayed (because they
  187. #  are basically too busy erasing the cookies).
  188. #
  189. ############################################################################ 
  190. #
  191. # links: iolib or itlib, iscreen (all optional)
  192. #
  193. # see also: ansi.icn
  194. #
  195. ############################################################################ 
  196.  
  197. # For DOS, or any system using ANSI-conformant output devices, there
  198. # is no need to link any routines in.
  199.  
  200. # For Unix systems, you may choose to link in itlib or iolib, and (if
  201. # desired) iscreen as well.  Some of these may be in the IPL.  You can
  202. # get any that aren't from Richard Goerwitz (goer@sophist.uchicago.edu).
  203.  
  204. # link iolib, iscreen
  205.  
  206. procedure _isANSI()
  207.     static isANSI
  208.     initial {
  209.     if find("MS-DOS",&features) then {
  210.         isANSI := 1
  211.     } else {
  212.         if type(getname) == "procedure" then {
  213.         if find("ansi",map(getname())) | getname() == "li"
  214.         then isANSI := 1
  215.         else isANSI := &null
  216.         } else {
  217.         # We'll take a chance on the user knowing what he/she
  218.         # is doing.
  219.         isANSI := 1
  220.         # If you're not so confident, comment out the following
  221.         # line:
  222.         # stop("_isANSI:  you need to link itlib or iolib")
  223.         }
  224.     }
  225.     }
  226.     return \isANSI
  227. end
  228.  
  229. procedure CUD(i)
  230.     if _isANSI()
  231.     then writes("\^[[",i,"B")
  232.     else {
  233.     iputs(igoto(getval("DO"),i)) | {
  234.         every 1 to i do
  235.         iputs(getval("do")) | stop("CUD:  no do capability")
  236.     }
  237.     }
  238.     return
  239. end
  240.  
  241. procedure CUB(i)
  242.     if _isANSI()
  243.     then writes("\^[[",i,"D")
  244.     else {
  245.     iputs(igoto(getval("LE"),i)) | {
  246.         every 1 to i do
  247.         iputs(getval("le")) | stop("CUB:  no le capability")
  248.     }
  249.     }
  250.     return
  251. end
  252.  
  253. procedure CUF(i)
  254.     if _isANSI()
  255.     then writes("\^[[",i,"C")
  256.     else {
  257.     iputs(igoto(getval("RI"),i)) | {
  258.         every 1 to i do
  259.         iputs(getval("nd")) | stop("CUF:  no nd capability")
  260.     }
  261.     }
  262.     return
  263. end
  264.  
  265. procedure CUP(i,j)
  266.     if _isANSI()
  267.     then writes("\^[[",i,";",j,"H")
  268.     else iputs(igoto(getval("cm"), j, i)) | stop("CUP:  no cm capability")
  269.     return
  270. end
  271.  
  272. procedure CUU(i)
  273.     if _isANSI()
  274.     then writes("\^[[",i,"A")
  275.     else {
  276.     iputs(igoto(getval("UP"),i)) | {
  277.         every 1 to i do
  278.         iputs(getval("up")) | stop("CUU:  no up capability")
  279.     }
  280.     }
  281.     return
  282. end
  283.  
  284. procedure ED(i)
  285.     /i := 2
  286.     if _isANSI() then {
  287.     writes("\^[[",i,"J")
  288.     } else {
  289.     case i of {
  290.         0:  iputs(getval("cd")) | stop("ED:  no cd capability")
  291.         1:  stop("ED:  termcap doesn't specify capability")
  292.         2:  {
  293.         if type(emphasize) == "procedure" then clear()
  294.         else iputs(getval("cl")) | stop("ED:  no cl capability")
  295.         }
  296.         default:  stop("ED:  unknown clear code, ",i)
  297.     }
  298.     }
  299.    return
  300. end
  301.  
  302. procedure EL(i)
  303.     /i := 0
  304.     if _isANSI() then {
  305.     if i = 0
  306.     then writes("\^[[K")
  307.     else writes("\^[[",i,"K")
  308.     } else {
  309.     case i of {
  310.         0:  iputs(getval("ce")) | stop("EL:  no ce capability")
  311.         1:  stop("EL:  termcap doesn't specify capability")
  312.         2:  stop("EL:  try using CUP to go to col 1, then EL(0)")
  313.         default:  stop("EL:  unknown line clear code, ",i)
  314.     }
  315.     }
  316.    return
  317. end
  318.  
  319. procedure SGR(i)
  320.  
  321.     static isISCR
  322.     initial {
  323.     if type(emphasize) == "procedure"
  324.     then isISCR := 1
  325.     }
  326.  
  327.     /i := 0
  328.     if _isANSI() then {
  329.     writes("\^[[",i,"m")
  330.     } else {
  331.     case i of {
  332.         0: (\isISCR, normal()) | {
  333.         every iputs(getval("me"|"so"|"ue"))
  334.         }
  335.         1: (\isISCR, boldface()) | {
  336.         iputs(getval("md"|"so"|"us"))
  337.         }
  338.         4: (\isISCR, underline()) | {
  339.         iputs(getval("us"|"md"|"so"))
  340.         }
  341.         5: (\isISCR, blink()) | {
  342.         iputs(getval("mb"|"us"|"me"|"so"))
  343.         }
  344.         7: (\isISCR, emphasize()) | {
  345.         iputs(getval("so"|"me"|"ue"))
  346.         }
  347.         default:  stop("SGR:  unknown mode, ",i)
  348.     }
  349.     }
  350.    return
  351. end
  352. -- 
  353.  
  354.    -Richard L. Goerwitz              goer%sophist@uchicago.bitnet
  355.    goer@sophist.uchicago.edu         rutgers!oddjob!gide!sophist!goer
  356.  
  357. From uunet!men2a!aquin!luvthang!talmage  Wed Jun 19 11:02:15 1991
  358. Received: from univers.cs.arizona.edu by cheltenham.cs.arizona.edu; Wed, 19 Jun 91 11:02:15 MST
  359. Received: from uunet.UUCP by univers.cs.arizona.edu; Wed, 19 Jun 91 11:02:11 MST
  360. Received: from uunet.uu.net (via LOCALHOST.UU.NET) by relay1.UU.NET with SMTP 
  361.     (5.61/UUNET-internet-primary) id AA13263; Wed, 19 Jun 91 11:30:08 -0400
  362. Received: from men2a.UUCP by uunet.uu.net with UUCP/RMAIL
  363.     (queueing-rmail) id 112857.16672; Wed, 19 Jun 1991 11:28:57 EDT
  364. Received: by men2a.ori-cal.com (smail2.5)
  365.     id AA15669; 19 Jun 91 05:13:55 EDT (Wed)
  366. Received: by aquin.ORI-CAL.COM (smail2.5)
  367.     id AA19638; 19 Jun 91 04:42:58 EDT (Wed)
  368. Received: by luvthang.aquin.ori-cal.com (1.05D/Amiga)
  369.     id AA02459; Tue, 18 Jun 91 22:24:07 EST
  370. Date: Tue, 18 Jun 91 22:24:07 EST
  371. Message-Id: <9106190324.AA02459@luvthang.aquin.ori-cal.com>
  372. From: uunet!luvthang.aquin.ori-cal.com!talmage (David W. Talmage)
  373. To: uunet!icon-group
  374. Subject: FileManager class
  375.  
  376. I've been thinking about that max open files problem I asked the
  377. Icon-Group about.  One way to fix my problem is to recompile icont and
  378. iconx with a larger number of available file handles.  I don't like
  379. that solution because it might involve a lot of compiler-specific work.
  380.  
  381. Maybe there's a better way using Idol.  Suppose there is a File class,
  382. a FileManager class, and at most one FileManager object per program.
  383. The FileManager guarantees there are no more than MaxOpenFiles
  384. (whatever that is) open at one time.  Each File object registers
  385. itself with the FileManager, who keeps a table of files and their
  386. state (opened or closed).  Before any File method can actually touch
  387. the file, that method must inform the FileManager object who ensures
  388. the file is opened by closing some other open file if necessary.
  389. Similarly, the FileManager object reopens temporarily closed files and
  390. positions their pointers to where ever they were when last closed. 
  391.  
  392. I like this solution because I can do it entirely in Idol and Icon.  I
  393. dislike it because I'm now doing stuff the operating system should
  394. handle for me.
  395.  
  396. -----------------------------------------------------------------------------
  397. David W. Talmage (talmage@luvthang.aquin.ori-cal.com)
  398. "I need fifty dollars to make you hollar.  I get paid to run this luvthang."
  399.  
  400. From icon-group-request@arizona.edu  Sun Jun 23 12:45:34 1991
  401. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Sun, 23 Jun 91 12:45:34 MST
  402. Resent-From: icon-group-request@arizona.edu
  403. Received: from Arizona.edu (Merlin.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  404.     id AA00638; Sun, 23 Jun 91 12:45:30 MST
  405. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Sun, 23 Jun
  406.  1991 12:44 MST
  407. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA07687; Sun, 23 Jun 91
  408.  12:43:30 -0700
  409. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  410.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  411.  usenet@ucbvax.Berkeley.EDU if you have questions)
  412. Resent-Date: Sun, 23 Jun 1991 12:45 MST
  413. Date: 23 Jun 91 17:42:41 GMT
  414. From: midway!ellis.uchicago.edu!goer@uunet.uu.net (Richard L. Goerwitz)
  415. Subject: Icon text-database
  416. Sender: icon-group-request@arizona.edu
  417. Resent-To: icon-group@cs.arizona.edu
  418. To: icon-group@arizona.edu
  419. Resent-Message-Id: <E0973FC608202EC0@Arizona.edu>
  420. Message-Id: <1991Jun23.174241.10359@midway.uchicago.edu>
  421. X-Envelope-To: icon-group@CS.Arizona.EDU
  422. X-Vms-To: icon-group@Arizona.edu
  423. Organization: University of Chicago
  424.  
  425. This is the README file from a package I've been using now, on and off,
  426. for about a year.  Some parts are better tested than others.  I'll be
  427. happy to mail a shell archive of the whole package to anyone who asks.
  428. This is not a finished product, but rather a collection of tools that
  429. I'd enjoy having a few people play with, if they are so inclined.
  430.  
  431. -Richard
  432.  
  433. ________________________________________________________________________
  434.  
  435.  
  436. Name: retrieve
  437. Language: Icon
  438. Contents: tools for word-based, indexed access to text files
  439. Requires: up-to-date Icon Program Library, up-to-date iconc/icont, UNIX
  440.  
  441.  
  442. --------
  443.  
  444.  
  445. Overview:
  446.  
  447.     Scholars have traditionally split so-called "Classics," the
  448. Quran, the Bible, and generally any closely studied literary or
  449. religious text, into hierarchically arranged divisions (in the case of
  450. the Bible, these are books, chapters, and verses).  Such divisions
  451. drastically simplify the process of citation and reference.
  452. Fortunately for those of us who need electronic access to these files,
  453. this hierarchical system of divisions permits easy representation
  454. using bit-fields, i.e. fixed-width series' of binary digits.  Such
  455. representations are compact, and allow the programmer to implement
  456. high-level boolean operations and range-based searches using simple
  457. shifts, additions, and subtractions.
  458.     The package in which this README file comes - "retrieve" -
  459. offers a naive, but generalized and fairly high-level tool for
  460. indexing texts which are divided up in the manner just described, and
  461. for performing word-based searches on them.  These word-based searches
  462. offer wildcard-based access to word patterns (e.g. "give me every
  463. passage containing a word with the letters 'NIX'").  The search
  464. facilities also permit boolean and range-based specifications (e.g.
  465. "give me every instance of word X occurring within eleven sections of
  466. the word Y").  One can also access passages by both absolute (e.g.
  467. "give me book 1, chapter 3, verse 4"), and relative, location (e.g.
  468. "give me the passage occurring before/after the one I just looked
  469. at").
  470.     Retrieve does no compression of any kind, and is written
  471. entirely in Icon.  As a result it is something of a disk hog, and
  472. takes a long time to index files.  Surprisingly, though, once set up,
  473. files incorporated into the retrieve package can be accessed quite
  474. rapidly.  After a brief initialization process (takes 2-4 seconds on a
  475. Sun4), absolute locations can be retrieved with no perceptible delay.
  476. The same is true of relative locations (again, after a lag on first
  477. invocation).  Regular expression-based searches appear instantaneous
  478. on a fast machine (there is a just perceptible delay on a Sun4 for a
  479. four megabyte indexed file, five to ten seconds on a Xenix/386 box
  480. with a relatively slow disk).  Boolean and range-based searches take
  481. the longest, varying widely according to their complexity and the
  482. number of "hits."
  483.  
  484.  
  485. --------
  486.  
  487.  
  488. Installation:
  489.  
  490.     Retrieve is really not a program as such.  It is a set of
  491. routines for indexing, and accessing indexed, files.  Installation
  492. consists of four basic steps:
  493.  
  494.     1) creating an indexable file
  495.     2) indexing that file
  496.     3) writing a program using the retrieve interface
  497.     4) compiling and running what you wrote in (3)
  498.  
  499. These steps are discussed in detail in the following sections.
  500.  
  501.  
  502. --------
  503.  
  504.  
  505. Step 1:  Creating an Indexable File
  506.  
  507.     The format for indexable files must conform to a simple, but
  508. strict, set of guidelines.  Basically, it must interleave a series of
  509. location designators (internally represented by so-called "bitmaps")
  510. with actual text:
  511.  
  512.     ::001:001:001
  513.     This is text.
  514.     ::001:001:002
  515.     This is more text.
  516.  
  517. The initial :: (double colon) delimits lines containing the location
  518. designators.  These designators translate into integers dividable
  519. internally into (in this case) three bit-fields of length 10 (enough
  520. to handle 999:999:999), which serve as a location markers for the text
  521. that goes with them.  Note that the translation process is invisible.
  522. All you need to do is make sure,
  523.  
  524.     a) that the location designators are correctly paired with
  525.        blocks of text, and
  526.     b) that the fields are numbered consistently, beginning with
  527.        the same low value (usually 1 or 0), and continuing in
  528.        ascending order until they roll over again to their low
  529.        value
  530.  
  531.     Rather than speak merely in the abstract about the format, let
  532. me offer a simple illustration taken from the King James Bible.  The
  533. first verse in the Bible is Genesis chapter 1 verse 1.  This passage
  534. might be designated 1:1:1.  Verses in Genesis chapter 1 would continue
  535. in ascending order to verse 31 (1:1:31), after which chapter 2 would
  536. begin (i.e. 1:2:1).  The resulting text would look like:
  537.  
  538.     ::1:1:1
  539.     In the beginning God created the heaven and the earth.
  540.     ::1:1:2
  541.     And the earth was without form, and void; and darkness was
  542.     upon the face of the deep. And the Spirit of God moved upon
  543.     the face of the waters.
  544.     ::1:1:3
  545.     And God said, Let there be light: and there was light.
  546.     ::1:1:4
  547.     And God saw the light, that it was good: and God divided the
  548.     light from the darkness.
  549.     ::1:1:5
  550.     And God called the light Day, and the darkness he called
  551.     Night. And the evening and the morning were the first day.
  552.     ...
  553.     ::1:2:1
  554.     Thus the heavens and the earth were finished, and all the host
  555.     of them.
  556.  
  557. Although you can use any number of fields you want or need, and can
  558. use any nonnumeric separator (e.g. 01-01-01-05-03), lines containing
  559. location designators *must* begin with "::," and must be ordered
  560. sequentially throughout the input file, paired with the correct text
  561. block in each instance.
  562.         
  563.  
  564. --------
  565.  
  566.  
  567. Step 2:  Indexing the File
  568.  
  569.     Indexing the file created in step (1) entails compiling and
  570. invoking a program called "makeind."  The compilation end of this
  571. process would typically be achieved by typing:
  572.  
  573.     icont -o makeind makeind.icn gettokens.icn indexutl.icn
  574.  
  575. One of the files listed just above, gettokens.icn is of particular
  576. interest.  It contains the tokenizing routine to be used in creating
  577. the main word index.  Should this routine prove unsatisfactory for one
  578. reason or another, you are free to replace it with something more to
  579. your liking.  Just comment out the old gettokens() routine, and insert
  580. the new one in its place.  Then recompile.
  581.     Once you have compiled makeind, you must invoke it for the
  582. text file you created in step (1).  Invoking makeind involves
  583. specifying a file to be indexed, the number of fields in location
  584. markers for that file, and the maximum value for fields.  If you plan
  585. on invoking passages by relative location, you must also use the -l
  586. option, which tells makeind to build a .LIM file, which records the
  587. high values for a specific field throughout the file being indexed.
  588. Let us say you have examined Genesis 1:31 in the Bible, and want to
  589. look at the next verse.  The only easy way the the procedure which
  590. handles this particular chore can know the maximum verse value for
  591. Genesis chapter 1 (31) is to store this maximum value in a file.  By
  592. supplying makeind with an -l argument, you are telling it to create
  593. such a file.
  594.     Just for illustration's sake, let us suppose you want to index
  595. the King James Bible.  How might you invoke makeind to accomplish
  596. this?  First you would need to determine the maximum field value for
  597. your text.  In the case of the Christian English Bible, this is 176.
  598. The English Bible (including Apocrypha) contains 73 books.  The
  599. Protestant KJV contains 66.  The maximum number of chapters in any
  600. book is 150 (Psalms).  The maximum number of verses in any one chapter
  601. in any one book is 176 (Psalm 119).  176 would therefore be the
  602. maximum value any field would have to contain.  You would pass this
  603. information to makeind via the -m option.  The total number of fields
  604. is three, naturally (book, chapter, and verse).  This value would be
  605. passed using the -n option.  As noted above, in order to use relative
  606. locations you would need to tell makeind what field to record max
  607. values for.  In our hypothesized scenario, you would want makeind to
  608. store the max value for the verse field for every chapter of every
  609. book in the input file.  The verse field (field #3), in other words,
  610. is your "rollover" field, and would be passed to makeind using the -l
  611. option.  Assuming "kjv" to be the name of your input file, this set of
  612. circumstances would imply the following invocation for makeind:
  613.  
  614.     makeind -f kjv -m 176 -n 3 -l 3
  615.  
  616. If you were to want a case-sensitive index (not a good idea), you
  617. would add "-s" to the argument list above.
  618.     Actual English Bible texts usually take up 4-5 megabytes.
  619. Indexing one would require at least twice that much core memory, and
  620. would take at least an hour on a fast machine.  The end result would
  621. be a set of data files occupying about 2 megabytes plus the 4-5
  622. megabytes of the original file.  Once these data files were created,
  623. they could be moved, along with the original source file, to any
  624. platform you desired.
  625.     Having indexed, and having moved the files to wherever you
  626. wanted them, you would then be ready for step 3.
  627.  
  628.  
  629. --------
  630.  
  631.  
  632. Step 3:  Writing a Program to Access Indexed Files
  633.  
  634.     When accessing text files such as the Bible, the most useful
  635. unit for searches is normally the word.  Let us suppose you are a
  636. zealous lay-speaker preparing a talk on fire imagery and divine wrath
  637. in the Bible.  You would probably want to look for every passage in
  638. the text that contained words like
  639.  
  640.     fire, firy
  641.     burn
  642.     furnace
  643.     etc.
  644.  
  645. To refine the search, let us say that you want every instance of one
  646. of these fire words that occurs within one verse of a biblical title
  647. for God:
  648.  
  649.     God
  650.     LORD
  651.     etc.
  652.  
  653. The searches for fire, firy, burn, etc. would be accomplished by
  654. calling a routine called retrieve().  Retrieve takes three arguments:
  655.  
  656.     retrieve(pattern, filename, invert_search)
  657.  
  658. The first argument should be a string containing a regular expression
  659. based pattern, such as
  660.  
  661.     fir(y|e|iness)|flam(e|ing)|burn.*?
  662.  
  663. Note that the pattern must match words IN THEIR ENTIRETY.  So, for
  664. instance, "fir[ie]" would not catch "firiness," but rather only
  665. "fire."  Likewise, if you want every string beginning with the
  666. sequence "burn," the string "burn" will not work.  Use "burn.*"
  667. instead.  The filename argument supplies retrieve() with the name of
  668. the original text file.  The last argument, if nonnull, inverts the
  669. sense of the search (a la egrep -v).  In the case of the fire words
  670. mentioned above, one would invoke retrieve() as follows:
  671.  
  672.     hits1 := retrieve("fir(y|e|iness)|flam(e|ing)|burn.*?", "kjv")
  673.  
  674. For the divine names, one would do something along these lines:
  675.  
  676.     hits2 := retrieve("god|lord", "kjv")
  677.  
  678.     Having finished the basic word searches, one would then
  679. perform a set intersection on them.  If we are looking for fire words
  680. which occur at most one verse away from a divine name, then we would
  681. specify 1 as our range (as opposed to, say, zero), and the verse as
  682. our unit.  The utility you would use to carry out the search is
  683. r_and().  R_and() would be invoked as follows:
  684.  
  685.     hits3 := r_and(hits1, hits2, "kjv", 3, 1)
  686.  
  687. The last two arguments, 3 and 1, specify field three (the "verse"
  688. field) and field 1 (the range).
  689.     To display the text for your "hit list" (hits3 above), you
  690. would call bitmap_2_text():
  691.  
  692.     every write(!bitmap_2_text(hits3, "kjv"))
  693.  
  694. Bitmap_2_text converts the location designators contained in hits3
  695. into actual text.
  696.     The three basic functions mentioned above - retrieve(),
  697. r_and(), and bitmap_2_text() - are contained in the three files
  698. retrieve.icn, retrops.icn, and bmp2text.icn, respectively.  Other
  699. useful routines are included in these files, and also in whatnext.icn.
  700. If you are planning on writing a retrieval engine for serious work of
  701. some kind, you would probably want to construct a mini interpreter,
  702. which would convert strings typed in by the user at run-time into
  703. internal search and retrieval operations.
  704.     Note that I have included no routine to parse or expand
  705. human-readable input (the nature of which will naturally vary from
  706. text to text).  For instance, it would be very useful to be able to
  707. ask for every passage in, say, Genesis chapters 2 through 4 in a
  708. biblical text, and to be able to print these to the screen.  Doing
  709. this would require a parsing routine to break down the references, and
  710. map them to retrieve-internal format.  The routine would then have to
  711. generate all valid locations from the minimum value in chapter 2 above
  712. to the max in chapter 4.  See the file whatnext.icn for an
  713. illustration of how to generate location designators in a suitably
  714. step-like fashion.
  715.  
  716.  
  717. --------
  718.  
  719.  
  720. Step 4:  Compiling and Running Your Program
  721.  
  722.     Assuming you have written a search/retrieval program using the
  723. routines contained in retrieve.icn, retrops.icn, bmp2text.icn, and
  724. whatnext.icn, you would now be ready to compile it.  In order to
  725. function properly, these routines would need to be linked with
  726. initfile.icn and indexutl.icn.  Specific dependencies are noted in the
  727. individual files in case there is any confusion.
  728.     If you have made significant use of this package, you probably
  729. should not worry about the exact dependencies, though.  Just link
  730. everything in together, and worry about what isn't needed after you
  731. have fully tested your program:
  732.  
  733.     icont -o yourprog yourprog.icn initfile.icn indexutl.icn \
  734.         retrieve.icn retrops.icn bmp2text.icn binsrch.icn
  735.  
  736. --------
  737.  
  738.  
  739. Problems, bugs:
  740.  
  741.     This is really an alpha release of the retrieve package.  I
  742. use it for various things.  For instance, I recently retrieved a text
  743. file containing informal reviews of a number of Science Fiction works.
  744. My father likes SciFi, and it was close to Fathers' Day, so I indexed
  745. the file, and performed cross-referenced searches for words like "very
  746. good," "brilliant," and "excellent," omitting authors my father has
  747. certainly read (e.g. Herbert, Azimov, etc.).  I also had occasion to
  748. write a retrieval engine for the King James Bible (hence the many
  749. examples from this text), and to construct a retrieval package for the
  750. Hebrew Bible, which I am now using to gather data for various chapters
  751. of my dissertation.
  752.     If anyone else finds these routines useful, then great.
  753. Obviously, they could be written/maintained in C or something that
  754. might offer much better performance.  They would, however, lose a lot
  755. of flexibility, and would have taken much, much longer to write.
  756. Right now, they occupy about 60k of basic source files, probably most
  757. of which consists of comments.  When compiled together with a
  758. moderate-size user interface, the total package typically comes to
  759. about 120k.  In core size typically runs about 350k on my home machine
  760. here (a Xenix/386 box), with the basic run-time interpreter taking up
  761. a good chunk of that space all on its own.  It's not a small package,
  762. but I've found it a nice base for rapid prototyping and development of
  763. small search and retrieval engines.
  764.  
  765. -- 
  766.  
  767.    -Richard L. Goerwitz              goer%sophist@uchicago.bitnet
  768.    goer@sophist.uchicago.edu         rutgers!oddjob!gide!sophist!goer
  769.  
  770. From icon-group-request@arizona.edu  Wed Jun 26 22:51:17 1991
  771. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Wed, 26 Jun 91 22:51:17 MST
  772. Resent-From: icon-group-request@arizona.edu
  773. Received: from Arizona.edu (Merlin.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  774.     id AA08451; Wed, 26 Jun 91 22:51:14 MST
  775. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Wed, 26 Jun
  776.  1991 22:50 MST
  777. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA16039; Wed, 26 Jun 91
  778.  22:42:14 -0700
  779. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  780.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  781.  usenet@ucbvax.Berkeley.EDU if you have questions)
  782. Resent-Date: Wed, 26 Jun 1991 22:51 MST
  783. Date: 27 Jun 91 04:15:03 GMT
  784. From: cis.ohio-state.edu!pacific.mps.ohio-state.edu!linac!midway!ellis.uchicago.edu!goer@ucbvax.berkeley.edu (Richard L.
  785.  Goerwitz)
  786. Subject: gettext text retrieval routines
  787. Sender: icon-group-request@arizona.edu
  788. Resent-To: icon-group@cs.arizona.edu
  789. To: icon-group@arizona.edu
  790. Resent-Message-Id: <90B96666E4203D31@Arizona.edu>
  791. Message-Id: <1991Jun27.041503.4700@midway.uchicago.edu>
  792. X-Envelope-To: icon-group@CS.Arizona.EDU
  793. X-Vms-To: icon-group@Arizona.edu
  794. Organization: University of Chicago
  795.  
  796. I posted some simple table-like access routines for files a while
  797. ago.  If anyone cares, I used them in a package posted to comp.
  798. sources.misc called "jargon."  They are a simple example of how
  799. these routines might be used.
  800.  
  801. What I'm really posting for now is to see whether anyone has tried
  802. these routines out under anything but UNIX (say MS-DOS).  I've not
  803. really tested them on anything but UNIX, and I just wonder whether
  804. anyone has beaten them around enough on another platform to know
  805. whether they work there.
  806.  
  807. -- 
  808.  
  809.    -Richard L. Goerwitz              goer%sophist@uchicago.bitnet
  810.    goer@sophist.uchicago.edu         rutgers!oddjob!gide!sophist!goer
  811.  
  812. From pearce@sce.carleton.ca  Fri Jun 28 09:08:53 1991
  813. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Fri, 28 Jun 91 09:08:53 MST
  814. Received: from cygnus.sce.carleton.ca by optima.cs.arizona.edu (4.1/15)
  815.     id AA13239; Fri, 28 Jun 91 09:08:48 MST
  816. Received: from terminus.sce.carleton.ca by cygnus.sce.carleton.ca (4.1/SMI-4.0)
  817.     id AA04370; Fri, 28 Jun 91 12:10:19 EDT
  818. From: pearce@sce.carleton.ca (Trevor Pearce)
  819. Received: by terminus.sce.carleton.ca (4.1/Sun-Client)
  820.     id AA14293; Fri, 28 Jun 91 12:10:17 EDT
  821. Message-Id: <9106281610.AA14293@terminus.sce.carleton.ca>
  822. Subject: ICON theorem prover?
  823. To: icon-group@cs.arizona.edu (ICON news group)
  824. Date: Fri, 28 Jun 91 12:10:16 EDT
  825. X-Mailer: ELM [version 2.3 PL11]
  826.  
  827.  
  828. Hello,
  829.  
  830. I am new to the news group and I am a "beginner" with ICON.  My
  831. research involves a string-oriented software specification technique
  832. and I am interested in experimenting with support tools programmed in
  833. ICON. 
  834.  
  835. More ambitiously, I am interested in the suitability of ICON for
  836. constructing a first-order logic theorem prover.  (As an introduction
  837. to ICON I programmed a "toy" theorem prover that uses the tableau
  838. method to try to find counter-examples of propositional logic
  839. "theorems". The code is not pretty -- typical of a novice -- but it
  840. seems to work on simple examples.)
  841.  
  842. I would be glad to communicate with anyone who has experience with (or
  843. is interested in) using ICON to construct a theorem prover.
  844.  
  845. Regards,
  846.  
  847. Trevor Pearce
  848.  
  849. Department of Systems and Computer Engineering
  850. Carleton University
  851. Ottawa, Canada
  852. K1S 5B6
  853.  
  854. email:   pearce@sce.carleton.ca
  855.  
  856.  
  857. From icon-group-request@arizona.edu  Sun Jun 30 08:41:37 1991
  858. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Sun, 30 Jun 91 08:41:37 MST
  859. Resent-From: icon-group-request@arizona.edu
  860. Received: from Arizona.edu (Merlin.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  861.     id AA04073; Sun, 30 Jun 91 08:41:35 MST
  862. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Sun, 30 Jun
  863.  1991 08:41 MST
  864. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA04303; Sun, 30 Jun 91
  865.  08:40:31 -0700
  866. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  867.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  868.  usenet@ucbvax.Berkeley.EDU if you have questions)
  869. Resent-Date: Sun, 30 Jun 1991 08:41 MST
  870. Date: 30 Jun 91 09:00:41 GMT
  871. From: coyote!jmh@noao.edu (John Hughes)
  872. Subject: A Strange/Dumb SNOBOL/SPITBOL Question...
  873. Sender: icon-group-request@arizona.edu
  874. Resent-To: icon-group@cs.arizona.edu
  875. To: icon-group@arizona.edu
  876. Resent-Message-Id: <3EB11B66DC800DA8@Arizona.edu>
  877. Message-Id: <1991Jun30.090041.23568@coyote.datalog.com>
  878. X-Envelope-To: icon-group@CS.Arizona.EDU
  879. X-Vms-To: icon-group@Arizona.edu
  880. Organization: Datalog Consulting, Tucson, AZ
  881.  
  882. Please pardon what might seem like an odd question, but...
  883.  
  884. I am currently looking about for a Unix version of SPITBOL. I've seen some
  885. references to something called SPITBOL-68 (which would be just right for me,
  886. since the machine of intent happens to be a 68000-based box). Does anyone
  887. have information about such a thing?
  888.  
  889. Many thanks in advance.
  890.  
  891.  
  892. -- 
  893. |     John M. Hughes      | "...unfolding in consciousness at the            |
  894. | datalog.com!moondog!jmh | deliberate speed of pondering."  - Daniel Dennet |
  895. | jmh%coyote@noao.edu     |--------------------------------------------------|
  896. | jmh%moondog@datalog.com | P.O.Box 43305, Tucson, AZ 85733    602-624-8008  |
  897.  
  898. From icon-group-request@arizona.edu  Sun Jun 30 10:58:01 1991
  899. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Sun, 30 Jun 91 10:58:01 MST
  900. Resent-From: icon-group-request@arizona.edu
  901. Received: from Arizona.edu (Merlin.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  902.     id AA06347; Sun, 30 Jun 91 10:58:00 MST
  903. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Sun, 30 Jun
  904.  1991 10:57 MST
  905. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA06575; Sun, 30 Jun 91
  906.  10:43:11 -0700
  907. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  908.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  909.  usenet@ucbvax.Berkeley.EDU if you have questions)
  910. Resent-Date: Sun, 30 Jun 1991 10:57 MST
  911. Date: 30 Jun 91 17:38:18 GMT
  912. From: cis.ohio-state.edu!zaphod.mps.ohio-state.edu!caen!hellgate.utah.edu!basset.utah.edu!hollaar@ucbvax.berkeley.edu (Lee
  913.  Hollaar)
  914. Subject: RE: A Strange/Dumb SNOBOL/SPITBOL Question...
  915. Sender: icon-group-request@arizona.edu
  916. Resent-To: icon-group@cs.arizona.edu
  917. To: icon-group@arizona.edu
  918. Resent-Message-Id: <51BF7B62828009C5@Arizona.edu>
  919. Message-Id: <1991Jun30.113818.16300@hellgate.utah.edu>
  920. X-Envelope-To: icon-group@CS.Arizona.EDU
  921. X-Vms-To: icon-group@Arizona.edu
  922. Organization: University of Utah CS Dept
  923. References: <1991Jun30.090041.23568@coyote.datalog.com>
  924.  
  925. In article <1991Jun30.090041.23568@coyote.datalog.com> jmh@coyote.datalog.com (John Hughes) writes:
  926. >I am currently looking about for a Unix version of SPITBOL. I've seen some
  927. >references to something called SPITBOL-68 (which would be just right for me,
  928. >since the machine of intent happens to be a 68000-based box). Does anyone
  929. >have information about such a thing?
  930.  
  931. SPITBOL-68000 is available from:
  932.     Catspaw, Inc.
  933.     Post Office Box 1123
  934.     Salida CO  81201
  935.     719/539-3384
  936.  
  937. It runs on a variety of 68000-based machines, including Sun-3's, Apollos, and
  938. HP's.  There is also Sparc SPITBOL for Sun-4's.
  939.  
  940. From uunet!men2a!aquin!luvthang!talmage  Tue Jul  2 08:56:17 1991
  941. Received: from univers.cs.arizona.edu by cheltenham.cs.arizona.edu; Tue, 2 Jul 91 08:56:17 MST
  942. Received: from uunet.UUCP by univers.cs.arizona.edu; Tue, 2 Jul 91 08:56:16 MST
  943. Received: from uunet.uu.net (via LOCALHOST.UU.NET) by relay1.UU.NET with SMTP 
  944.     (5.61/UUNET-internet-primary) id AA12230; Tue, 2 Jul 91 11:05:12 -0400
  945. Received: from men2a.UUCP by uunet.uu.net with UUCP/RMAIL
  946.     (queueing-rmail) id 110445.6814; Tue, 2 Jul 1991 11:04:45 EDT
  947. Received: by men2a.ori-cal.com (smail2.5)
  948.     id AA28645; 2 Jul 91 11:08:46 EDT (Tue)
  949. Received: by aquin.ORI-CAL.COM (smail2.5)
  950.     id AA11489; 2 Jul 91 10:56:16 EDT (Tue)
  951. Received: by luvthang.aquin.ori-cal.com (1.05D/Amiga)
  952.     id AA02475; Tue, 2 Jul 91 07:19:14 EST
  953. Date: Tue, 2 Jul 91 07:19:14 EST
  954. Message-Id: <9107021219.AA02475@luvthang.aquin.ori-cal.com>
  955. From: uunet!luvthang.aquin.ori-cal.com!talmage (David W. Talmage)
  956. To: arizona!icon-group
  957. Subject: Re: gettext text retrieval routines
  958.  
  959. Richard L. Goerwitz (goer%sophist@uchicago.bitnet) writes:
  960. :What I'm really posting for now is to see whether anyone has tried
  961. :these routines out under anything but UNIX (say MS-DOS).  I've not
  962.  
  963. I've made them work under AmigaDOS on my Amiga 2000.  They worked
  964. nearly without change.  I've even used them with Clint Jeffery's Idol
  965. langauge to construct a class called IndexedFile.
  966.  
  967. -----------------------------------------------------------------------------
  968. David W. Talmage (talmage@luvthang.aquin.ori-cal.com)
  969. "I need fifty dollars to make you hollar.  I get paid to run this luvthang."
  970.  
  971. From icon-group-request@arizona.edu  Tue Jul  2 11:36:53 1991
  972. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Tue, 2 Jul 91 11:36:53 MST
  973. Resent-From: icon-group-request@arizona.edu
  974. Received: from Arizona.edu (Merlin.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  975.     id AA08030; Tue, 2 Jul 91 11:36:50 MST
  976. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Tue, 2 Jul
  977.  1991 11:36 MST
  978. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA18430; Tue, 2 Jul 91 11:28:58
  979.  -0700
  980. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  981.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  982.  usenet@ucbvax.Berkeley.EDU if you have questions)
  983. Resent-Date: Tue, 2 Jul 1991 11:36 MST
  984. Date: 2 Jul 91 17:54:35 GMT
  985. From: cis.ohio-state.edu!pacific.mps.ohio-state.edu!linac!midway!ellis.uchicago.edu!goer@ucbvax.berkeley.edu (Richard L.
  986.  Goerwitz)
  987. Subject: king james bible browser
  988. Sender: icon-group-request@arizona.edu
  989. Resent-To: icon-group@cs.arizona.edu
  990. To: icon-group@arizona.edu
  991. Resent-Message-Id: <E9800F2ACC801412@Arizona.edu>
  992. Message-Id: <1991Jul2.175435.4687@midway.uchicago.edu>
  993. X-Envelope-To: icon-group@CS.Arizona.EDU
  994. X-Vms-To: icon-group@Arizona.edu
  995. Organization: University of Chicago
  996.  
  997. As a base for testing some other software I have around, I've written
  998. a King James Bible browser, which offers full and quick access to any
  999. passage in the Bible, as well as word and word-pattern based searches,
  1000. and also boolean and range-based operations.  Even though it's writ-
  1001. ten in Icon, it's still very fast.  For example, finding every passage
  1002. which contains the word "love" takes a fraction of a second on my home
  1003. machine (a Xenix/386 box with a slow disk).  Finding every passage that
  1004. contains the words sackcloth and ashes takes about half a second.
  1005. Finding every passage that contains the word patterns "cry.*" and
  1006. "weep.*" takes five seconds.  A killer search, such as one for every
  1007. passage that contains "lord" and "god," takes 25 seconds.  On a Sun4,
  1008. the times are cut down to as little as 1/10 of what they are for me
  1009. at home.
  1010.  
  1011. The real disadvantage to the package is that it is a memory hog, both
  1012. in terms of mass and main storage.  The King James Bible is a 5 mega-
  1013. byte text, and the indexes for it take up another 2 megs.  Creating the
  1014. indexes takes up to 14 meg core memory, and will bring many workstations
  1015. to their knees.  Sorry.  I wrote the blasted thing just on a whim, so
  1016. don't send me hate male while your machine swaps itself into oblivion.
  1017. It's a useful package once you've gotten past the hump.
  1018.  
  1019. The program requires an Icon Program Library, and will probably work
  1020. under Icon version 7 or 8 (haven't tried 7, actually).  It also needs
  1021. a Unix box to run efficiently.
  1022.  
  1023. Anyone interested, please let me know.  I'll mail you a shell archive.
  1024.  
  1025. -- 
  1026.  
  1027.    -Richard L. Goerwitz              goer%sophist@uchicago.bitnet
  1028.    goer@sophist.uchicago.edu         rutgers!oddjob!gide!sophist!goer
  1029.  
  1030. From icon-group-request@arizona.edu  Tue Jul  2 14:35:22 1991
  1031. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Tue, 2 Jul 91 14:35:22 MST
  1032. Resent-From: icon-group-request@arizona.edu
  1033. Received: from Arizona.edu (Merlin.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  1034.     id AA15584; Tue, 2 Jul 91 14:35:20 MST
  1035. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Tue, 2 Jul
  1036.  1991 14:34 MST
  1037. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA24399; Tue, 2 Jul 91 14:26:48
  1038.  -0700
  1039. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  1040.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  1041.  usenet@ucbvax.Berkeley.EDU if you have questions)
  1042. Resent-Date: Tue, 2 Jul 1991 14:35 MST
  1043. Date: 2 Jul 91 20:44:39 GMT
  1044. From: usc!elroy.jpl.nasa.gov!sdd.hp.com!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!pacific.mps.ohio-state.edu!linac!midway!ellis.uchicago.edu!goer@ucsd.edu
  1045.  (Richard L. Goerwitz)
  1046. Subject: RE: king james bible browser
  1047. Sender: icon-group-request@arizona.edu
  1048. Resent-To: icon-group@cs.arizona.edu
  1049. To: icon-group@arizona.edu
  1050. Resent-Message-Id: <0270BF4CDC8014B3@Arizona.edu>
  1051. Message-Id: <1991Jul2.204439.9692@midway.uchicago.edu>
  1052. X-Envelope-To: icon-group@CS.Arizona.EDU
  1053. X-Vms-To: icon-group@Arizona.edu
  1054. Organization: University of Chicago
  1055. References: <1991Jul2.175435.4687@midway.uchicago.edu>
  1056.  
  1057. I, goer@ellis.uchicago.edu (Richard L. Goerwitz), write (regarding a
  1058. simple King James Bible viewer):
  1059.  
  1060. >Anyone interested, please let me know.  I'll mail you a shell archive.
  1061.  
  1062. I had no idea that there were so many religious (or just plain curious)
  1063. people on this newsgroup.  My mailbox is suddenly full - and this right
  1064. before the 4th.
  1065.  
  1066. Anyway, I think it's going to make sense to post the program to comp.
  1067. sources.misc or alt.sources.  Perhaps here.  Suggestions?
  1068.  
  1069. Two people asked me whether the King James Bible text was included with
  1070. the package.  For space reasons (5 meg or so), no.  You can get it from
  1071. simtel, or from a number of other places.  There exist versions which
  1072. will not work.  I see one here on midway.uchicago.edu.
  1073.  
  1074. Two other people asked whether they had to use the KJV, and not some
  1075. other version.  The answer is:  If you *have* another version, and can
  1076. write a small program to put it into indexable format, then yes, you
  1077. can use any biblical text you want.  The program is really very gen-
  1078. eral in design.  In fact, the reason I wrote it was to test a program
  1079. package I wrote as a set of generalized search/retrieval utilities.
  1080. The KJV browser is just a simple front-end for this more basic pack-
  1081. age.
  1082.  
  1083. Anyway, the bottom line is:  I'm looking for a sensible way to dis-
  1084. tribute the program, without necessitating mailing out shell archives
  1085. to everyone.  Ideas?
  1086.  
  1087. -- 
  1088.  
  1089.    -Richard L. Goerwitz              goer%sophist@uchicago.bitnet
  1090.    goer@sophist.uchicago.edu         rutgers!oddjob!gide!sophist!goer
  1091.  
  1092. From nowlin@iwtqg.att.com  Tue Jul  2 16:34:18 1991
  1093. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Tue, 2 Jul 91 16:34:18 MST
  1094. Message-Id: <9107022334.AA20011@optima.cs.arizona.edu>
  1095. Received: from att.att.com by optima.cs.arizona.edu (4.1/15)
  1096.     id AA20011; Tue, 2 Jul 91 16:34:16 MST
  1097. From: nowlin@iwtqg.att.com
  1098. Date: Tue, 2 Jul 91 15:02 CDT
  1099. Original-From: iwtqg!nowlin (Jerry D Nowlin +1 312 979 7268)
  1100. To: icon-group@cs.arizona.edu
  1101. Subject: Re: king james bible browser
  1102.  
  1103. > The program requires an Icon Program Library, and will probably work
  1104. > under Icon version 7 or 8 (haven't tried 7, actually).  It also needs
  1105. > a Unix box to run efficiently.
  1106.  
  1107. You left out the most crucial requirement.  It also requires an on-line
  1108. King James Bible.  That'll be too big to post unless you limit it to the
  1109. parts everyone agrees on.  To save time I included those at the end of
  1110. this message :-)
  1111.  
  1112. Jerry Nowlin
  1113. ...!att!iwtqg!nowlin
  1114.  
  1115. From icon-group-request@arizona.edu  Tue Jul  2 22:03:45 1991
  1116. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Tue, 2 Jul 91 22:03:45 MST
  1117. Resent-From: icon-group-request@arizona.edu
  1118. Received: from Arizona.edu (Merlin.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  1119.     id AA29763; Tue, 2 Jul 91 22:03:40 MST
  1120. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Tue, 2 Jul
  1121.  1991 22:03 MST
  1122. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA08291; Tue, 2 Jul 91 21:49:20
  1123.  -0700
  1124. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  1125.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  1126.  usenet@ucbvax.Berkeley.EDU if you have questions)
  1127. Resent-Date: Tue, 2 Jul 1991 22:03 MST
  1128. Date: 3 Jul 91 04:15:13 GMT
  1129. From: midway!ellis.uchicago.edu!goer@uunet.uu.net (Richard L. Goerwitz)
  1130. Subject: RE: king james bible browser
  1131. Sender: icon-group-request@arizona.edu
  1132. Resent-To: icon-group@cs.arizona.edu
  1133. To: icon-group@arizona.edu
  1134. Resent-Message-Id: <41102FEA2C801984@Arizona.edu>
  1135. Message-Id: <1991Jul3.041513.21190@midway.uchicago.edu>
  1136. X-Envelope-To: icon-group@CS.Arizona.EDU
  1137. X-Vms-To: icon-group@Arizona.edu
  1138. Organization: University of Chicago
  1139. References: <9107022334.AA20011@optima.cs.arizona.edu>
  1140.  
  1141. Jerry Nowlin (nowlin@iwtqg.att.com) writes, regarding my lapse (forget-
  1142. ting to tell people they need a KJV text to run my browser):
  1143.  
  1144. >You left out the most crucial requirement.  It also requires an on-line
  1145. >King James Bible.  That'll be too big to post unless you limit it to the
  1146. >parts everyone agrees on.  To save time I included those at the end of
  1147. >this message :-)
  1148.  
  1149. You can get the original PC-SIG KJV distribution (19 disks) from the
  1150. Simtel archive.  You can also get it from helens.stanford.edu, and from
  1151. several other places (check the anonymous ftp listings).  Note that not
  1152. all of these texts will work with the browser.  Many have been mangled
  1153. in various ways.  If anyone has another version, please send me a sam-
  1154. ple, and I'll code up a program to "fix" it for use with the browser.
  1155.  
  1156. BTW:  Jerry, I figured I could count on some sarcastic comment from 
  1157. someone - if not about using the archaic King James version, then about
  1158. posting a Bible browser at all.  I guess I didn't figure you for the
  1159. perpetrator.
  1160.  
  1161. Let me just send the browser to those who are interested, and we can
  1162. discuss its deeper ramifications over a beer some day.  The decision
  1163. has been made to post to alt.sources for the first round.  I'll then
  1164. post it to comp.sources.misc if there's demand.  Those who don't get
  1165. the alt hierarchy, please ask me for a shell archive.  This time
  1166. around the requests should be few enough that I'll be able to handle
  1167. them all individually.
  1168.  
  1169. Thanks to everyone who wrote.  It's nice to feel like some of this
  1170. software I write for other purposes can be made useful to a broader
  1171. sector (in this case, simply by putting a visual wrapper around it,
  1172. and setting it up for the KJV).
  1173.  
  1174. -- 
  1175.  
  1176.    -Richard L. Goerwitz              goer%sophist@uchicago.bitnet
  1177.    goer@sophist.uchicago.edu         rutgers!oddjob!gide!sophist!goer
  1178.  
  1179. From icon-group-request@arizona.edu  Wed Jul  3 08:20:53 1991
  1180. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Wed, 3 Jul 91 08:20:53 MST
  1181. Resent-From: icon-group-request@arizona.edu
  1182. Received: from Arizona.edu (Merlin.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  1183.     id AA19834; Wed, 3 Jul 91 08:20:51 MST
  1184. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Wed, 3 Jul
  1185.  1991 08:20 MST
  1186. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA21175; Wed, 3 Jul 91 08:08:50
  1187.  -0700
  1188. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  1189.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  1190.  usenet@ucbvax.Berkeley.EDU if you have questions)
  1191. Resent-Date: Wed, 3 Jul 1991 08:20 MST
  1192. Date: 3 Jul 91 14:18:06 GMT
  1193. From: cis.ohio-state.edu!zaphod.mps.ohio-state.edu!rpi!news-server.csri.toronto.edu!utgpu!cunews!bnrgate!bwdls58!bcarh172!channen@ucbvax.berkeley.edu (Peter Channen)
  1194. Subject: source code for icon
  1195. Sender: icon-group-request@arizona.edu
  1196. Resent-To: icon-group@cs.arizona.edu
  1197. To: icon-group@arizona.edu
  1198. Resent-Message-Id: <974A27E38C80173F@Arizona.edu>
  1199. Message-Id: <7191@bwdls58.bnr.ca>
  1200. X-Envelope-To: icon-group@CS.Arizona.EDU
  1201. X-Vms-To: icon-group@Arizona.edu
  1202. Organization: Bell-Northern Research Ltd.
  1203.  
  1204. Hi,
  1205.  
  1206. I recently acquired Richard Goerwitz's jargon program (posted
  1207. to comp.sources.misc), but don't have icon to compile it.  Is there
  1208. an anonymous ftp site that I can ftp the source for icon to run under
  1209. HP-UX 7.05?
  1210.  
  1211. Thanks in advance,
  1212.  
  1213. Peter Channen
  1214. channen@bnr.ca
  1215.  
  1216. From icon-group-request@arizona.edu  Thu Jul 11 13:16:59 1991
  1217. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Thu, 11 Jul 91 13:16:59 MST
  1218. Resent-From: icon-group-request@arizona.edu
  1219. Received: from Arizona.edu (Merlin.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  1220.     id AA00198; Thu, 11 Jul 91 13:16:57 MST
  1221. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Thu, 11 Jul
  1222.  1991 13:16 MST
  1223. Received: by ucbvax.berkeley.edu (5.63/1.42) id AA12577; Thu, 11 Jul 91
  1224.  13:01:47 -0700
  1225. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  1226.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  1227.  usenet@ucbvax.Berkeley.EDU if you have questions)
  1228. Resent-Date: Thu, 11 Jul 1991 13:16 MST
  1229. Date: 11 Jul 91 17:37:16 GMT
  1230. From: agate!spool.mu.edu!sol.ctr.columbia.edu!ira.uka.de!ira.uka.de@ucbvax.berkeley.edu (Angelo
  1231.  Schneider Betr.Prechelt)
  1232. Subject: How to call a generator from everywhere
  1233. Sender: icon-group-request@arizona.edu
  1234. Resent-To: icon-group@cs.arizona.edu
  1235. To: icon-group@arizona.edu
  1236. Resent-Message-Id: <09FAADBF2E80373D@Arizona.edu>
  1237. Message-Id: <k7p5qcINNs2f@iraun1.ira.uka.de>
  1238. X-Envelope-To: icon-group@CS.Arizona.EDU
  1239. X-Vms-To: icon-group@Arizona.edu
  1240. Organization: University of Karlsruhe, FRG
  1241.  
  1242.  
  1243. Well, I hope my Problem is simple!
  1244.  
  1245. I have a generator which gives me every word from the inputstream.
  1246.  
  1247. So I can write:
  1248.  
  1249.      every write(GetWord())
  1250.  
  1251. But I want something like this:
  1252.  
  1253. procedure main()
  1254.  
  1255. ...
  1256.  
  1257.     if GetWord() == "KEYWORD" then DoKeyword();
  1258.  
  1259. ...
  1260.  
  1261. end #main;
  1262.  
  1263.  
  1264.  
  1265. procedure DoKeyword()
  1266. ...
  1267.  
  1268.    if GetWord() == "anything" then do anything;
  1269.    ^^^^^^^^^^^^
  1270.  
  1271. end #DoKeyword;
  1272.  
  1273. ^^^here I want GetWord to continue ( resume ) at that state it suspended
  1274.    in main.
  1275.  
  1276.    Is this possible? 
  1277.  
  1278. thanx angelo
  1279.  
  1280. From icon-group-request@arizona.edu  Thu Jul 11 17:16:43 1991
  1281. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Thu, 11 Jul 91 17:16:43 MST
  1282. Resent-From: icon-group-request@arizona.edu
  1283. Received: from Arizona.edu (Merlin.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  1284.     id AA09335; Thu, 11 Jul 91 17:16:40 MST
  1285. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Thu, 11 Jul
  1286.  1991 17:15 MST
  1287. Received: by ucbvax.berkeley.edu (5.63/1.42) id AA21155; Thu, 11 Jul 91
  1288.  17:04:45 -0700
  1289. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  1290.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  1291.  usenet@ucbvax.Berkeley.EDU if you have questions)
  1292. Resent-Date: Thu, 11 Jul 1991 17:16 MST
  1293. Date: 11 Jul 91 20:09:29 GMT
  1294. From: att!linac!midway!ellis.uchicago.edu!goer@ucbvax.berkeley.edu (Richard L.
  1295.  Goerwitz)
  1296. Subject: RE: How to call a generator from everywhere
  1297. Sender: icon-group-request@arizona.edu
  1298. Resent-To: icon-group@cs.arizona.edu
  1299. To: icon-group@arizona.edu
  1300. Resent-Message-Id: <2B753D509E803520@Arizona.edu>
  1301. Message-Id: <1991Jul11.200929.23411@midway.uchicago.edu>
  1302. X-Envelope-To: icon-group@CS.Arizona.EDU
  1303. X-Vms-To: icon-group@Arizona.edu
  1304. Organization: University of Chicago
  1305. References: <k7p5qcINNs2f@iraun1.ira.uka.de>
  1306.  
  1307. Angelo rites:
  1308.  
  1309. >I have a generator which gives me every word from the input stream,
  1310. >so I can write:
  1311. >
  1312. >     every write(GetWord())
  1313. >
  1314. >But I want something like this:
  1315. >
  1316. >procedure main()
  1317. >...
  1318. >    if GetWord() == "KEYWORD" then DoKeyword();
  1319. >...
  1320. >end #main;
  1321. >
  1322. >procedure DoKeyword()
  1323. >...
  1324. >   if GetWord() == "anything" then do anything;
  1325. >end #DoKeyword;
  1326. >
  1327. >^^^here I want GetWord to continue ( resume ) at that state it suspended
  1328. >   in main.
  1329. >
  1330. >   Is this possible? 
  1331.  
  1332. It looks to me as though you want to do this,
  1333.  
  1334.     every word := GetWord() do {
  1335.         case word of {
  1336.             pattern1 : action1()
  1337.             pattern2 : action2()
  1338.             etc.
  1339.             default  : write(word)
  1340.         }
  1341.     }
  1342.  
  1343. where pattern1, pattern2 etc. are keywords, and action1, action2, etc. are
  1344. procedures which do something when their corresponding keywords are encoun-
  1345. tered.
  1346.  
  1347. If you want to get really clever, you could write procedures that are the
  1348. same as the keywords, yielding:
  1349.  
  1350. procedure main()
  1351.  
  1352.     every word := GetWord() do
  1353.         write(proc(word)() | word)
  1354.  
  1355. end
  1356.  
  1357. procedure KEYWORD()
  1358.     return "Wow, a keyword."
  1359. end
  1360.  
  1361. procedure anything()
  1362.     return "did anything"
  1363. end
  1364.  
  1365. This way, if word == "KEYWORD" or "anything" the procedure corresponding
  1366. to these strings will get invoked.  If no such procedure exists, proc()
  1367. will fail, and word will get written.
  1368.  
  1369. I expect this won't be altogether clear, so try playing around with it
  1370. a bit.
  1371.  
  1372. -- 
  1373.  
  1374.    -Richard L. Goerwitz              goer%sophist@uchicago.bitnet
  1375.    goer@sophist.uchicago.edu         rutgers!oddjob!gide!sophist!goer
  1376.  
  1377. From icon-group-request@arizona.edu  Sat Jul 13 11:49:29 1991
  1378. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Sat, 13 Jul 91 11:49:29 MST
  1379. Resent-From: icon-group-request@arizona.edu
  1380. Received: from Arizona.edu (Merlin.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  1381.     id AA17622; Sat, 13 Jul 91 11:49:27 MST
  1382. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Sat, 13 Jul
  1383.  1991 11:48 MST
  1384. Received: by ucbvax.berkeley.edu (5.63/1.42) id AA23815; Sat, 13 Jul 91
  1385.  11:36:08 -0700
  1386. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  1387.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  1388.  usenet@ucbvax.Berkeley.EDU if you have questions)
  1389. Resent-Date: Sat, 13 Jul 1991 11:49 MST
  1390. Date: 13 Jul 91 18:20:22 GMT
  1391. From: mcsun!unido!ira.uka.de!ira.uka.de@uunet.uu.net (Angelo Schneider
  1392.  Betr.Prechelt)
  1393. Subject: RE: How to call a generator from everywhere
  1394. Sender: icon-group-request@arizona.edu
  1395. Resent-To: icon-group@cs.arizona.edu
  1396. To: icon-group@arizona.edu
  1397. Resent-Message-Id: <9015FEC44E8014B6@Arizona.edu>
  1398. Message-Id: <k7uh36INNi8u@iraun1.ira.uka.de>
  1399. X-Envelope-To: icon-group@CS.Arizona.EDU
  1400. X-Vms-To: icon-group@Arizona.edu
  1401. Organization: University of Karlsruhe, FRG
  1402. References: <k7p5qcINNs2f@iraun1.ira.uka.de>,
  1403.  <1991Jul11.200929.23411@midway.uchicago.edu>
  1404.  
  1405.  
  1406.  
  1407. [ My earlier posting deleted ]
  1408.  
  1409. In article <1991Jul11.200929.23411@midway.uchicago.edu|,
  1410. goer@ellis.uchicago.edu (Richard L. Goerwitz) writes:
  1411.  
  1412.  
  1413.  
  1414. | It looks to me as though you want to do this,
  1415. |     every word := GetWord() do {
  1416. |         case word of {
  1417. |             pattern1 : action1()
  1418. |             pattern2 : action2()
  1419. |             etc.
  1420. |             default  : write(word)
  1421. |         }
  1422. |     }
  1423.  
  1424.    [ some stuff deleted here ]
  1425.  
  1426. | If you want to get really clever, you could write procedures that are the
  1427. | same as the keywords, yielding:
  1428. | procedure main()
  1429.  
  1430. From icon-group-request@arizona.edu  Mon Jul 15 08:56:10 1991
  1431. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Mon, 15 Jul 91 08:56:10 MST
  1432. Resent-From: icon-group-request@arizona.edu
  1433. Received: from Arizona.edu (Merlin.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  1434.     id AA25846; Mon, 15 Jul 91 08:55:47 MST
  1435. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Mon, 15 Jul
  1436.  1991 08:52 MST
  1437. Received: by ucbvax.berkeley.edu (5.63/1.42) id AA16509; Mon, 15 Jul 91
  1438.  08:50:58 -0700
  1439. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  1440.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  1441.  usenet@ucbvax.Berkeley.EDU if you have questions)
  1442. Resent-Date: Mon, 15 Jul 1991 08:54 MST
  1443. Date: 15 Jul 91 15:49:38 GMT
  1444. From: cis.ohio-state.edu!zaphod.mps.ohio-state.edu!qt.cs.utexas.edu!cs.utexas.edu!uwm.edu!convex.csd.uwm.edu!corre@ucbvax.berkeley.edu (Alan D
  1445.  Corre)
  1446. Subject: getch(e)()
  1447. Sender: icon-group-request@arizona.edu
  1448. Resent-To: icon-group@cs.arizona.edu
  1449. To: icon-group@arizona.edu
  1450. Resent-Message-Id: <0A016E5D3E804228@Arizona.edu>
  1451. Message-Id: <14078@uwm.edu>
  1452. X-Envelope-To: icon-group@CS.Arizona.EDU
  1453. X-Vms-To: icon-group@Arizona.edu
  1454. Organization: University of Wisconsin - Milwaukee
  1455.  
  1456.  
  1457. In the kind of programming I do, I find it useful to allow the user to
  1458. view or not view input at will. Typically, the input may be processed
  1459. a character at a time, possibly appearing in a different font. The
  1460. following procedure initially behaves exactly like getche(). If it is
  1461. called with an argument it subsequently behaves like getch() and will
  1462. continue to do so until toggled by another call with an argument. The
  1463. user can precipitate this by entering some predetermined character, e.g.
  1464.   if char == "~" then {getc(1); next}
  1465.  
  1466. procedure getc(a)
  1467. static g,other
  1468. local ch
  1469.  
  1470. initial g := ((other := "getch")  || "e")
  1471.     if \a then g :=: other else
  1472.         ch := g()
  1473. return ch
  1474. end
  1475.  
  1476. From icon-group-request@arizona.edu  Fri Jul 19 13:18:20 1991
  1477. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Fri, 19 Jul 91 13:18:20 MST
  1478. Resent-From: icon-group-request@arizona.edu
  1479. Received: from Arizona.edu (Merlin.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  1480.     id AA23299; Fri, 19 Jul 91 13:17:14 MST
  1481. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Thu, 18 Jul
  1482.  1991 16:17 MST
  1483. Received: by ucbvax.berkeley.edu (5.63/1.42) id AA02482; Thu, 18 Jul 91
  1484.  16:05:34 -0700
  1485. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  1486.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  1487.  usenet@ucbvax.Berkeley.EDU if you have questions)
  1488. Resent-Date: Thu, 18 Jul 1991 16:17 MST
  1489. Date: 18 Jul 91 21:08:45 GMT
  1490. From: midway!ellis.uchicago.edu!goer@uunet.uu.net (Richard L. Goerwitz)
  1491. Subject: KJV program posted to comp.sources.misc
  1492. Sender: icon-group-request@arizona.edu
  1493. Resent-To: icon-group@cs.arizona.edu
  1494. To: icon-group@arizona.edu
  1495. Resent-Message-Id: <A374EBC40E804602@Arizona.edu>
  1496. Message-Id: <1991Jul18.210845.1956@midway.uchicago.edu>
  1497. X-Envelope-To: icon-group@CS.Arizona.EDU
  1498. X-Vms-To: icon-group@Arizona.edu
  1499. Organization: University of Chicago
  1500.  
  1501. Due to a somewhat higher than expected demand for the Bible browser
  1502. I've mentioned here, I eventually ended up posting to comp.sources.
  1503. misc.  Just not enough sites got alt.sources, and I kept having lots
  1504. of people write, saying stuff like "I heard about your KJV program,
  1505. but the original alt.sources posting has since expired, and...."  Now
  1506. it's in the comp.sources.misc archives, and can be ftp'd by anyone
  1507. who ends up deciding to give it a test drive.
  1508.  
  1509. Note:  It's not anything very complicated, and the real meat of the
  1510. package is really not meant for Bible work - it's just a generalized
  1511. interface for text retrieval.
  1512.  
  1513. Anyone with a CCAT RSV online, please drop me a line, and I will send
  1514. you patches relative to the comp.sources.misc posting (version 1.0)
  1515. that might actually make installation automatic for you as well (I do
  1516. not have the disk space to test the installation for the RSV here).
  1517. Please don't send me mail asking for the CCAT RSV, by the way.  It's
  1518. a huge text, and I can't put it up for ftp (still less keep in online
  1519. here).  There's a certain amount of red tape involved in getting it,
  1520. and you're best off just sending a note to:
  1521.  
  1522.     CCAT
  1523.     Box 36 College Hall
  1524.     University of Pennsylvania
  1525.     Philadelphia (my home town!), PA  19104
  1526.     USA
  1527.  
  1528. -- 
  1529.  
  1530.    -Richard L. Goerwitz              goer%sophist@uchicago.bitnet
  1531.    goer@sophist.uchicago.edu         rutgers!oddjob!gide!sophist!goer
  1532.  
  1533. From icon-group-request@arizona.edu  Sat Jul 20 02:16:10 1991
  1534. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Sat, 20 Jul 91 02:16:10 MST
  1535. Resent-From: icon-group-request@arizona.edu
  1536. Received: from Arizona.edu (Osprey.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  1537.     id AA22991; Sat, 20 Jul 91 02:16:07 MST
  1538. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Sat, 20 Jul
  1539.  1991 02:15 MST
  1540. Received: by ucbvax.berkeley.edu (5.63/1.42) id AA29016; Sat, 20 Jul 91
  1541.  02:05:53 -0700
  1542. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  1543.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  1544.  usenet@ucbvax.Berkeley.EDU if you have questions)
  1545. Resent-Date: Sat, 20 Jul 1991 02:15 MST
  1546. Date: 19 Jul 91 05:44:13 GMT
  1547. From: agate!usenet.ins.cwru.edu!magnus.acs.ohio-state.edu!zaphod.mps.ohio-state.edu!usc!orion.oac.uci.edu!unogate!unocal!genisco!arcturus!felix!ka%felix.UUCP@ucbvax.berkeley.edu
  1548.  (Kenneth Almquist)
  1549. Subject: RE: How to call a generator from everywhere
  1550. Sender: icon-group-request@arizona.edu
  1551. Resent-To: icon-group@cs.arizona.edu
  1552. To: icon-group@arizona.edu
  1553. Resent-Message-Id: <C02455424060CE3A@Arizona.edu>
  1554. Message-Id: <167724@felix.UUCP>
  1555. X-Envelope-To: icon-group@CS.Arizona.EDU
  1556. X-Vms-To: icon-group@Arizona.edu
  1557. References: <k7p5qcINNs2f@iraun1.ira.uka.de>
  1558.  
  1559. angelo@i43s3.ira.uka.de (Angelo Schneider Betr.Prechelt) writes:
  1560. > I have a generator which gives me every word from the inputstream.
  1561. > [But I want to invoke the generator from multiple locations without
  1562. > restarting it.]
  1563.  
  1564. To do this you need a co-expression.  The GetNextWord procedure below
  1565. illustrates how this is done.  Simply replace your calls to GetWord
  1566. with calls to GetNextWord.  (Of course GetNextWord is sufficiently
  1567. simple that you might want to simply substitute the code in line
  1568. rather than use a this procedure.)  Note that a given call to
  1569. GetNextWord will only return a single result.
  1570.  
  1571. The GetWord procedure which appears below illustrates how to perform
  1572. the opposite conversion.  The first time GetWord is invoked, it loops
  1573. calling ReadWord (a routine which has the same semantics as
  1574. GetNextWord, but which doesn't call GetWord), and suspends with each
  1575. word read.  It also stores the words in the list "l", so that
  1576. subsequent invocations of GetWord will start at the beginning of the
  1577. input.
  1578.  
  1579. By the way, can anyone suggest something thats better than "while 1"
  1580. for infinite loops?
  1581.                 Kenneth Almquist
  1582.  
  1583.  
  1584. ---------------------------------
  1585. procedure main()    # Perform a simple test of GetNextWord and GetWord.
  1586.     local word
  1587.  
  1588.     # Write all input words, two per line
  1589.     while word := GetNextWord() do {
  1590.     writes(word)
  1591.     if word := GetNextWord() then
  1592.         writes(" ", word)
  1593.     write()
  1594.     }
  1595.     # Write all input words, one per line
  1596.     every write(GetWord())
  1597. end
  1598.  
  1599. procedure GetNextWord()
  1600.     static coexpr            # The coexpression
  1601.  
  1602.     initial coexpr := create GetWord()    # Create coexpression on first call
  1603.     return @coexpr            # Return next value of coexpression
  1604. end
  1605.  
  1606. procedure GetWord()
  1607.     static l                # list of words read
  1608.     local word                # the word just read
  1609.  
  1610.     initial l := []
  1611.     suspend !l                # Return any words read previously
  1612.     while word := ReadWord() do {    # Read the next word of input
  1613.     put(l, word)            # Remember word (for subsequent calls)
  1614.     suspend word            # Pass word back to caller
  1615.     }
  1616. end
  1617.  
  1618. procedure ReadWord()
  1619.     static line, loc, wordset, eofflag
  1620.     local start
  1621.  
  1622.     initial wordset := &lcase ++ &ucase
  1623.     if \eofflag then fail
  1624.     while 1 do {
  1625.     if /line then {
  1626.         line := read() | break
  1627.         loc := 1
  1628.     }
  1629.     if start := upto(wordset, line, loc, 0) then {
  1630.         loc := many(wordset, line, start, 0)
  1631.         return line[start : loc]
  1632.     }
  1633.     line := &null
  1634.     }
  1635.     eofflag := 1
  1636.     fail
  1637. end
  1638.  
  1639. From icon-group-request@arizona.edu  Sat Jul 20 03:18:23 1991
  1640. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Sat, 20 Jul 91 03:18:23 MST
  1641. Resent-From: icon-group-request@arizona.edu
  1642. Received: from Arizona.edu (Osprey.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  1643.     id AA26164; Sat, 20 Jul 91 03:18:15 MST
  1644. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Sat, 20 Jul
  1645.  1991 03:17 MST
  1646. Received: by ucbvax.berkeley.edu (5.63/1.42) id AA01571; Sat, 20 Jul 91
  1647.  03:03:59 -0700
  1648. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  1649.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  1650.  usenet@ucbvax.Berkeley.EDU if you have questions)
  1651. Resent-Date: Sat, 20 Jul 1991 03:17 MST
  1652. Date: 20 Jul 91 08:02:44 GMT
  1653. From: agate!usenet.ins.cwru.edu!magnus.acs.ohio-state.edu!zaphod.mps.ohio-state.edu!uwm.edu!linac!mp.cs.niu.edu!ux1.cso.uiuc.edu!midway!ellis.uchicago.edu!goer@ucbvax.berkeley.edu
  1654.  (Richard L. Goerwitz)
  1655. Subject: Huffman encoding tools
  1656. Sender: icon-group-request@arizona.edu
  1657. Resent-To: icon-group@cs.arizona.edu
  1658. To: icon-group@arizona.edu
  1659. Resent-Message-Id: <C8CD9AB80060D283@Arizona.edu>
  1660. Message-Id: <1991Jul20.080244.10740@midway.uchicago.edu>
  1661. X-Envelope-To: icon-group@CS.Arizona.EDU
  1662. X-Vms-To: icon-group@Arizona.edu
  1663. Organization: University of Chicago
  1664.  
  1665. A long time ago, I asked whether anyone had written compression programs
  1666. for Icon.  I received a pointer to one program - press.icn (in the Icon
  1667. Program Library).  It's basically a dictionary-inspired method that's re-
  1668. flected in press (LZW), and it has the advantage of being adaptive.  For
  1669. reasons which I don't want to burden anyone with, I found that for some
  1670. projects I'm working on, I had to be able to encode and decode blocks at
  1671. random locations within a file, so LZW was out.  Here are some Huffman
  1672. encoding tools that do the trick.  This post is in fulfillment of several
  1673. promises I made to summarize anything useful I found out.
  1674.  
  1675. -Richard
  1676.  
  1677. ---- Cut Here and feed the following to sh ----
  1678. #!/bin/sh
  1679. # This is a shell archive (produced by shar 3.49)
  1680. # To extract the files from this archive, save it to a file, remove
  1681. # everything above the "!/bin/sh" line above, and type "sh file_name".
  1682. #
  1683. # made 07/20/1991 08:38 UTC by goer@sophist.uchicago.edu
  1684. # Source directory /u/richard/Huffstuf
  1685. #
  1686. # existing files will NOT be overwritten unless -c is specified
  1687. # This format requires very little intelligence at unshar time.
  1688. # "if test", "cat", "rm", "echo", "true", and "sed" may be needed.
  1689. #
  1690. #                                                                          
  1691. #                                                                          
  1692. #
  1693. # This shar contains:
  1694. # length  mode       name
  1695. # ------ ---------- ------------------------------------------
  1696. #   9663 -r--r--r-- huffstuf.icn
  1697. #   1205 -r--r--r-- inbits.icn
  1698. #   3067 -r--r--r-- outbits.icn
  1699. #
  1700. if test -r _shar_seq_.tmp; then
  1701.     echo 'Must unpack archives in sequence!'
  1702.     echo Please unpack part `cat _shar_seq_.tmp` next
  1703.     exit 1
  1704. fi
  1705. # ============= huffstuf.icn ==============
  1706. if test -f 'huffstuf.icn' -a X"$1" != X"-c"; then
  1707.     echo 'x - skipping huffstuf.icn (File already exists)'
  1708.     rm -f _shar_wnt_.tmp
  1709. else
  1710. > _shar_wnt_.tmp
  1711. echo 'x - extracting huffstuf.icn (Text)'
  1712. sed 's/^X//' << 'SHAR_EOF' > 'huffstuf.icn' &&
  1713. X############################################################################
  1714. X#
  1715. X#    Name:     huffstuf.icn
  1716. X#
  1717. X#    Title:     huffman coding tools
  1718. X#
  1719. X#    Author:     Richard L. Goerwitz
  1720. X#
  1721. X#    Version: 1.2
  1722. X#
  1723. X############################################################################
  1724. X#  
  1725. X#  An odd assortment of tools that lets me compress text using an
  1726. X#  Iconish version of a generic Huffman algorithm.
  1727. X#
  1728. X############################################################################
  1729. X#
  1730. X#  Links: codeobj ./outbits.icn ./inbits.icn
  1731. X#
  1732. X#  See also: hufftab.icn, press.icn
  1733. X#
  1734. X############################################################################
  1735. X
  1736. X# From the IPL.
  1737. Xlink codeobj
  1738. X
  1739. X# Necessary records.
  1740. Xrecord nodE(l,r,n)
  1741. Xrecord _ND(l,r)
  1742. Xrecord leaF(c,n)
  1743. Xrecord huffcode(c,i,len)
  1744. X
  1745. X# For debugging purposes.
  1746. X# link ximage
  1747. X
  1748. X# Count of chars in input file.
  1749. Xglobal count_of_all_chars
  1750. X
  1751. X
  1752. Xprocedure main(a)
  1753. X
  1754. X    local direction, usage, size, char_tbl, heap, tree, h_tbl
  1755. X    usage := "huffcode -i|o filename1"
  1756. X
  1757. X    direction := pop(a) | stop(usage)
  1758. X    direction ?:= { ="-"; tab(any('oi')) } | stop(usage)
  1759. X    *a = 1 | stop(usage)
  1760. X
  1761. X    intext := open(a[1]) | quitprog("huffcode", "can't open "||a[1], 1)
  1762. X    size   := 80
  1763. X
  1764. X    if direction == "o" then {
  1765. X
  1766. X    char_tbl := table()
  1767. X    while count_chars_in_s(reads(intext), char_tbl)
  1768. X    heap     := initialize_heap(char_tbl)
  1769. X    tree     := heap_2_tree(heap)
  1770. X    h_tbl    := hash_codes(tree)
  1771. X
  1772. X    put_tree(&output, tree)
  1773. X    seek(intext, 1)
  1774. X    every writes(&output, encode_string(|reads(intext, size), h_tbl))
  1775. X
  1776. X    }
  1777. X    else {
  1778. X    tree := get_tree(intext)
  1779. X    every writes(&output, decode_rest_of_file(intext, size, tree))
  1780. X    }
  1781. X
  1782. Xend
  1783. X
  1784. X
  1785. Xprocedure count_chars_in_s(s, char_tbl)
  1786. X
  1787. X    #
  1788. X    # Count chars in s, placing stats in char_tbl (keys = chars in
  1789. X    # s, values = leaF records, with the counts for each chr in s
  1790. X    # contained in char_tbl[chr].n).
  1791. X    #
  1792. X    local chr
  1793. X    initial {
  1794. X    /char_tbl &
  1795. X        quitprog("count_chars_in_s", "need 2 args - 1 string, 2 table", 9)
  1796. X    *char_tbl ~= 0 &
  1797. X        quitprog("count_chars_in_s","start me with an empty table",8)
  1798. X    count_of_all_chars := 0
  1799. X    }
  1800. X
  1801. X    # Reset character count on no-arg invocation.
  1802. X    /s & /char_tbl & {
  1803. X    count_of_all_chars := 0
  1804. X    return
  1805. X    }
  1806. X
  1807. X    # Insert counts for characters into char_tbl.  Note that we don't
  1808. X    # just put them into the table as-is.  Rather, we put them into
  1809. X    # a record which contains the character associated with the count.
  1810. X    # These records are later used by the Huffman encoding algorithm.
  1811. X    s ? {
  1812. X    while chr := move(1) do {
  1813. X        count_of_all_chars +:= 1
  1814. X        /char_tbl[chr]   := leaF(chr,0)
  1815. X        char_tbl[chr].n +:= 1
  1816. X    }
  1817. X    }
  1818. X    return *char_tbl        # for lack of anything better
  1819. X
  1820. Xend
  1821. X
  1822. X
  1823. Xprocedure initialize_heap(char_tbl)
  1824. X
  1825. X    #
  1826. X    # Create heap data structure out of the table filled out by
  1827. X    # successive calls to count_chars_in_s(s,t).  The heap is just a
  1828. X    # list.  Naturally, it's size can be obtained via *heap.
  1829. X    #
  1830. X    local heap
  1831. X
  1832. X    heap := list()
  1833. X    every push(heap, !char_tbl) do
  1834. X    reshuffle_heap(heap, 1)
  1835. X    return heap
  1836. X
  1837. Xend
  1838. X
  1839. X
  1840. Xprocedure reshuffle_heap(h, k)
  1841. X
  1842. X    #
  1843. X    # Based loosely on Sedgewick (2nd. ed., 1988), p. 160.  Take k-th
  1844. X    # node on the heap, and walk down the heap, switching this node
  1845. X    # along the way with the child whose value is the least AND whose
  1846. X    # value is less than this node's.  Stop when you find no children
  1847. X    # whose value is less than that of the original node.  Elements on
  1848. X    # heap are records of type leaF, with the values contained in the
  1849. X    # "n" field.
  1850. X    #
  1851. X    local j
  1852. X
  1853. X    # While we haven't spilled off the end of the heap (the size of the
  1854. X    # heap is *h; *h / 2 is the biggest k we need to look at)...
  1855. X    while k <= (*h / 2) do {
  1856. X
  1857. X    # ...double k, assign the result to j.
  1858. X    j := k+k
  1859. X
  1860. X    # If we aren't at the end of the heap...
  1861. X    if j < *h then {
  1862. X        # ...check to see which of h[k]'s children is the smallest,
  1863. X        # and make j point to it.
  1864. X        if h[j].n > h[j+1].n then
  1865. X        # h[j] :=: h[j+1]
  1866. X        j +:= 1
  1867. X    }
  1868. X
  1869. X    # If the current parent (h[k]) has a value less than those of its
  1870. X    # children, then break; we're done.
  1871. X    if h[k].n <= h[j].n then break
  1872. X
  1873. X    # Otherwise, switch the parent for the child, and loop around
  1874. X        # again, with k (the pointer to the parent) now pointing to the
  1875. X    # new offset of the element we have been working on.
  1876. X    h[k] :=: h[j]
  1877. X    k := j
  1878. X
  1879. X    }
  1880. X
  1881. X    return k
  1882. X    
  1883. Xend
  1884. X
  1885. X
  1886. Xprocedure heap_2_tree(h)
  1887. X
  1888. X    #
  1889. X    # Construct the Huffman tree out of heap h.  Find the smallest
  1890. X    # element, pop it off the heap, then reshuffle the heap.  After
  1891. X    # reshuffling, replace the top record on the stack with a nodE()
  1892. X    # record whose n field equal to the sum of the n fields for the
  1893. X    # element popped off the stack originally, and the one that is
  1894. X    # now about to be replaced.  Link the new nodE record to the 2
  1895. X    # elements on the heap it is now replacing.  Reshuffle the heap
  1896. X    # again, then repeat.  You're done when the size of the heap is
  1897. X    # 1.  That one element remaining (h[1]) is your Huffman tree.
  1898. X    #
  1899. X    # Based loosely on Sedgewick (2nd ed., 1988), p. 328-9.
  1900. X    #
  1901. X    local frst, scnd, count
  1902. X
  1903. X    until *h = 1 do {
  1904. X
  1905. X    h[1] :=: h[*h]        # Reverse first and last elements.
  1906. X    frst := pull(h)        # Pop last elem off & save it.
  1907. X    reshuffle_heap(h, 1)    # Resettle the heap.
  1908. X    scnd := !h        # Save (but don't clobber) top element.
  1909. X
  1910. X    count := frst.n + scnd.n
  1911. X    frst := { if *frst = 2 then frst.c else _ND(frst.l, frst.r) }
  1912. X    scnd := { if *scnd = 2 then scnd.c else _ND(scnd.l, scnd.r) }
  1913. X
  1914. X    h[1] := nodE(frst, scnd, count) # Create new nodE().
  1915. X    reshuffle_heap(h, 1)    # Resettle once again.
  1916. X    }
  1917. X
  1918. X    # H is no longer a stack.  It's single element - the root of a
  1919. X    # Huffman tree made up of nodE()s and leaF()s.  Put the l and r
  1920. X    # fields of that element into an _ND record, and return the new
  1921. X    # record.
  1922. X    return _ND(h[1].l, h[1].r)
  1923. X
  1924. Xend
  1925. X
  1926. X
  1927. Xprocedure hash_codes(tr)
  1928. X
  1929. X    #
  1930. X    # Hash Huffman codes.  Tr (arg 1) is a Huffman tree created by
  1931. X    # heap_2_tree(heap).  Output is a table, with the keys
  1932. X    # representing characters, and the values being records of type
  1933. X    # huffcode(i,len), where i is the Huffcode (an integer) and len is
  1934. X    # the number of bits it occupies.
  1935. X    #
  1936. X    local code
  1937. X
  1938. X    huff_tbl := table()
  1939. X    every code := collect_bits(tr) do
  1940. X    insert(huff_tbl, code.c, code)
  1941. X    return huff_tbl
  1942. X
  1943. Xend
  1944. X    
  1945. X
  1946. Xprocedure collect_bits(tr, i, len)
  1947. X
  1948. X    #
  1949. X    # Decompose Huffman tree tr into huffcode() records which contain
  1950. X    # 3 fields:  c (the character encoded), i (its integer code),
  1951. X    # and len (the number of bytes the integer code occupies).  Sus-
  1952. X    # pend one such record for each character encoded in tree tr.
  1953. X    #
  1954. X
  1955. X    if type(tr) == "string" then
  1956. X    return huffcode(tr, i, len)
  1957. X    else {
  1958. X    (/len := 1) | (len +:= 1)
  1959. X    (/i   := 0) | (i   *:= 2)
  1960. X    suspend collect_bits(tr.l, i, len)
  1961. X    i   +:= 1
  1962. X    suspend collect_bits(tr.r, i, len)
  1963. X    }
  1964. X
  1965. Xend
  1966. X
  1967. X
  1968. Xprocedure put_tree(f, tr)
  1969. X
  1970. X    #
  1971. X    # Writes Huffman tree tr to file f.  Uses first two bits to store
  1972. X    # the size of the tree.
  1973. X    #
  1974. X    local stringized_tr
  1975. X    # global count_of_all_chars
  1976. X
  1977. X    /f | /tr & quitprog("put_tree","I need two nonnull arguments",7)
  1978. X
  1979. X    stringized_tr := encode(tr)
  1980. X    every writes(f, outbits(*stringized_tr, 16))     # use two bytes
  1981. X    outbits()                         # just in case
  1982. X    writes(f, stringized_tr)
  1983. X    # How many characters are there in the input file?
  1984. X    every writes(f, outbits(count_of_all_chars, 32))
  1985. X    outbits()
  1986. X
  1987. Xend
  1988. X
  1989. X
  1990. Xprocedure get_tree(f)
  1991. X
  1992. X    #
  1993. X    # Reads in Huffman tree from file f, sets pointer to the first
  1994. X    # encoded bit (as opposed to the bits which form the tree des-
  1995. X    # cription) in file f.
  1996. X    #
  1997. X    local stringized_tr_size, tr
  1998. X    # global count_of_all_chars
  1999. X
  2000. X    stringized_tr_size := inbits(f, 16)
  2001. X    tr := decode(reads(f, stringized_tr_size)) |
  2002. X    quitprog("get_tree", "can't decode tree", 6)
  2003. X    count_of_all_chars := inbits(f, 32) |
  2004. X    quitprog("get_tree", "garbled input file", 10)
  2005. X    return tr
  2006. X
  2007. Xend
  2008. X
  2009. X
  2010. Xprocedure encode_string(s, huffman_table)
  2011. X
  2012. X    #
  2013. X    # Encode string s using the codes in huffman_table (created by
  2014. X    # hash_codes, which in turns uses the Huffman tree created by
  2015. X    # heap_2_tree).
  2016. X    #
  2017. X    # Make sure you are using reads() and not read, unless you don't
  2018. X    # want to preserve newlines.
  2019. X    #
  2020. X    local s2, chr, hcode    # hcode stores huffcode records
  2021. X    static chars_written
  2022. X    initial chars_written := 0
  2023. X
  2024. X    s2 := ""
  2025. X    s ? {
  2026. X    while chr := move(1) do {
  2027. X        chars_written +:= 1
  2028. X        hcode := \huffman_table[chr] |
  2029. X        quitprog("encode_string", "unexpected char, "||image(chr), 11)
  2030. X        every s2 ||:= outbits(hcode.i, hcode.len)
  2031. X    }
  2032. X    # If at end of output stream, then flush outbits buffer.
  2033. X    if chars_written = count_of_all_chars then {
  2034. X        chars_written := 0
  2035. X        s2 ||:= outbits()
  2036. X    } else {
  2037. X        if chars_written > count_of_all_chars then {
  2038. X        chars_written := 0
  2039. X        quitprog("encode_string", "you're trying to write _
  2040. X            more chars than you originally tabulated", 12)
  2041. X        }
  2042. X    }
  2043. X    }
  2044. X    return s2
  2045. X
  2046. Xend
  2047. X
  2048. X
  2049. Xprocedure decode_rest_of_file(f, size, huffman_tree)
  2050. X
  2051. X    local s2, line, E, chr, bit
  2052. X    static chars_decoded
  2053. X    initial chars_decoded := 0
  2054. X
  2055. X    E := huffman_tree
  2056. X    while line := reads(f, size) do {
  2057. X    line ? {
  2058. X        s2 := ""
  2059. X        while chr := move(1) do {
  2060. X        every bit := iand(1, ishift(ord(chr), -7 to 0)) do {
  2061. X            E := { if bit = 0 then E.l else E.r }
  2062. X            if s2 ||:= string(E) then {
  2063. X            chars_decoded +:= 1
  2064. X            if chars_decoded = count_of_all_chars then {
  2065. X                chars_decoded := 0
  2066. X                break { break break }
  2067. X            }
  2068. X            else E := huffman_tree
  2069. X            }
  2070. X        }
  2071. X        }
  2072. X        suspend s2
  2073. X    }
  2074. X    }
  2075. X    suspend s2
  2076. X
  2077. Xend
  2078. X
  2079. X
  2080. Xprocedure quitprog(p, m, c)
  2081. X
  2082. X    /m := "program error"
  2083. X    write(&errout, p, ":  ", m)
  2084. X    exit(\c | 1)
  2085. X
  2086. Xend
  2087. SHAR_EOF
  2088. true || echo 'restore of huffstuf.icn failed'
  2089. rm -f _shar_wnt_.tmp
  2090. fi
  2091. # ============= inbits.icn ==============
  2092. if test -f 'inbits.icn' -a X"$1" != X"-c"; then
  2093.     echo 'x - skipping inbits.icn (File already exists)'
  2094.     rm -f _shar_wnt_.tmp
  2095. else
  2096. > _shar_wnt_.tmp
  2097. echo 'x - extracting inbits.icn (Text)'
  2098. sed 's/^X//' << 'SHAR_EOF' > 'inbits.icn' &&
  2099. X############################################################################
  2100. X#
  2101. X#    Name:     inbits.icn
  2102. X#
  2103. X#    Title:     read in variable length characters from a file
  2104. X#
  2105. X#    Author:     Richard L. Goerwitz
  2106. X#
  2107. X#    Version: 1.2
  2108. X#
  2109. X############################################################################
  2110. X#  
  2111. X#  This procedure, inbits(), re-imports data converted into writable
  2112. X#  form by outbits().  See the file outbits.icn for all the whys and
  2113. X#  hows.
  2114. X#
  2115. X############################################################################
  2116. X#
  2117. X#  Links: none
  2118. X#
  2119. X#  See also: outbits.icn
  2120. X#
  2121. X############################################################################
  2122. X
  2123. X
  2124. Xprocedure inbits(f, len)
  2125. X
  2126. X    local i, byte, old_byte_mask
  2127. X    static old_byte, old_len, byte_length
  2128. X    initial {
  2129. X    old_byte := old_len := 0
  2130. X    byte_length := 8
  2131. X    }
  2132. X
  2133. X    old_byte_mask := (0 < 2^old_len - 1) | 0
  2134. X    old_byte := iand(old_byte, old_byte_mask)
  2135. X    i := ishift(old_byte, len-old_len)
  2136. X
  2137. X    len -:= (len > old_len) | {
  2138. X    old_len -:= len
  2139. X    return i
  2140. X    }
  2141. X    
  2142. X    while byte := ord(reads(f)) do {
  2143. X    i := ior(i, ishift(byte, len-byte_length))
  2144. X    len -:= (len > byte_length) | {
  2145. X        old_len := byte_length-len
  2146. X        old_byte := byte
  2147. X        return i
  2148. X    }
  2149. X    }
  2150. X
  2151. Xend
  2152. SHAR_EOF
  2153. true || echo 'restore of inbits.icn failed'
  2154. rm -f _shar_wnt_.tmp
  2155. fi
  2156. # ============= outbits.icn ==============
  2157. if test -f 'outbits.icn' -a X"$1" != X"-c"; then
  2158.     echo 'x - skipping outbits.icn (File already exists)'
  2159.     rm -f _shar_wnt_.tmp
  2160. else
  2161. > _shar_wnt_.tmp
  2162. echo 'x - extracting outbits.icn (Text)'
  2163. sed 's/^X//' << 'SHAR_EOF' > 'outbits.icn' &&
  2164. X############################################################################
  2165. X#
  2166. X#    Name:     outbits.icn
  2167. X#
  2168. X#    Title:     output variable-length characters in byte-size chunks
  2169. X#
  2170. X#    Author:     Richard L. Goerwitz
  2171. X#
  2172. X#    Version: 1.5
  2173. X#
  2174. X############################################################################
  2175. X#
  2176. X#  In any number of instances (e.g. when outputting variable-length
  2177. X#  characters or fixed-length encoded strings), the programmer must
  2178. X#  fit variable and/or non-byte-sized blocks into standard 8-bit
  2179. X#  bytes.  Outbits() performs this task.
  2180. X#
  2181. X#  Pass to outbits(i, len) an integer i, and a length parameter (len),
  2182. X#  and outbits will suspend byte-sized chunks of i converted to
  2183. X#  characters (most significant bits first) until there is not enough
  2184. X#  left of i to fill up an 8-bit character.  The remaining portion is
  2185. X#  stored in a buffer until outbits() is called again, at which point
  2186. X#  the buffer is combined with the new i and then output in the same
  2187. X#  manner as before.  The buffer is flushed by calling outbits() with
  2188. X#  a null i argument.  Note that len gives the number of bits there
  2189. X#  are in i (or at least the number of bits you want preserved; those
  2190. X#  that are discarded are the most significant ones). 
  2191. X#
  2192. X#  A trivial example of how outbits() might be used:
  2193. X#
  2194. X#      outtext := open("some.file.name","w")
  2195. X#      l := [1,2,3,4]
  2196. X#      every writes(outtext, outbits(!l,3))
  2197. X#      writes(outtext, outbits(&null,3))           # flush buffer
  2198. X#
  2199. X#  List l may be reconstructed with inbits() (see inbits.icn):
  2200. X#
  2201. X#      intext := open("some.file.name")
  2202. X#      l := []
  2203. X#      while put(l, inbits(intext, 3))
  2204. X#
  2205. X#  Note that outbits() is a generator, while inbits() is not.
  2206. X#
  2207. X############################################################################
  2208. X#
  2209. X#  Links: none
  2210. X#  See also: inbits.icn
  2211. X#
  2212. X############################################################################
  2213. X
  2214. X
  2215. Xprocedure outbits(i, len)
  2216. X
  2217. X    local old_part, new_part, window, old_byte_mask
  2218. X    static old_i, old_len, byte_length, byte_mask
  2219. X    initial {
  2220. X    old_i := old_len := 0
  2221. X    byte_length := 8
  2222. X    byte_mask := (2^byte_length)-1
  2223. X    }
  2224. X
  2225. X    old_byte_mask := (0 < 2^old_len - 1) | 0
  2226. X    window := byte_length - old_len
  2227. X    old_part := ishift(iand(old_i, old_byte_mask), window)
  2228. X
  2229. X    # If we have a no-arg invocation, then flush buffer (old_i).
  2230. X    if /i then {
  2231. X    if old_len > 0 then {
  2232. X        old_i := old_len := 0
  2233. X        return char(old_part)
  2234. X    } else {
  2235. X        old_i := old_len := 0
  2236. X        fail
  2237. X    }
  2238. X    } else {
  2239. X    new_part := ishift(i, window-len)
  2240. X    len -:= (len >= window) | {
  2241. X        old_len +:= len
  2242. X        old_i := ior(ishift(old_part, len-window), i)
  2243. X        fail
  2244. X    }
  2245. X#    For debugging purposes.
  2246. X#    write("old_byte_mask = ", old_byte_mask)
  2247. X#    write("window = ", image(window))
  2248. X#    write("old_part = ", image(old_part))
  2249. X#    write("new_part = ", image(new_part))
  2250. X#    write("outputting ", image(ior(old_part, new_part)))
  2251. X    suspend char(ior(old_part, new_part))
  2252. X    }
  2253. X
  2254. X    until len < byte_length do {
  2255. X    suspend char(iand(ishift(i, byte_length-len), byte_mask))
  2256. X    len -:= byte_length
  2257. X    }
  2258. X
  2259. X    old_len := len
  2260. X    old_i := i
  2261. X    fail
  2262. X
  2263. Xend
  2264. SHAR_EOF
  2265. true || echo 'restore of outbits.icn failed'
  2266. rm -f _shar_wnt_.tmp
  2267. fi
  2268. exit 0
  2269. -- 
  2270.  
  2271.    -Richard L. Goerwitz              goer%sophist@uchicago.bitnet
  2272.    goer@sophist.uchicago.edu         rutgers!oddjob!gide!sophist!goer
  2273.  
  2274. From isidev!nowlin@uunet.uu.net  Sat Jul 20 06:10:10 1991
  2275. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Sat, 20 Jul 91 06:10:10 MST
  2276. Received: from relay1.UU.NET by optima.cs.arizona.edu (4.1/15)
  2277.     id AA29080; Sat, 20 Jul 91 06:10:07 MST
  2278. Received: from uunet.uu.net (via LOCALHOST.UU.NET) by relay1.UU.NET with SMTP 
  2279.     (5.61/UUNET-internet-primary) id AA25593; Sat, 20 Jul 91 09:10:05 -0400
  2280. Date: Sat, 20 Jul 91 09:10:05 -0400
  2281. From: isidev!nowlin@uunet.uu.net
  2282. Message-Id: <9107201310.AA25593@relay1.UU.NET>
  2283. Received: from isidev.UUCP by uunet.uu.net with UUCP/RMAIL
  2284.     (queueing-rmail) id 090958.24960; Sat, 20 Jul 1991 09:09:58 EDT
  2285. To: uunet!cs.arizona.edu!icon-group@uunet.uu.net
  2286. Subject: Re: ...generator from everywhere
  2287.  
  2288.  > Kenneth Almquist writes:
  2289.  > > angelo@i43s3.ira.uka.de (Angelo Schneider Betr.Prechelt) writes:
  2290.  > > I have a generator which gives me every word from the inputstream.
  2291.  > > [But I want to invoke the generator from multiple locations without
  2292.  > > restarting it.]
  2293.  > 
  2294.  > To do this you need a co-expression...
  2295.  
  2296. This is an excellent example of a use for co-expressions.  Good response. 
  2297.  
  2298.  > By the way, can anyone suggest something thats better than "while 1"
  2299.  > for infinite loops?
  2300.  
  2301. Icon has a built in infinite loop control structure called repeat.  You
  2302. just do this:
  2303.  
  2304.     repeat {
  2305.  
  2306.         other stuff
  2307.  
  2308.     }
  2309.  
  2310. The only way out of this loop is a return or break.
  2311.  
  2312. --- ---
  2313.  | S | Iconic Software, Inc.  -  Jerry Nowlin  -  uunet!isidev!nowlin
  2314. --- ---
  2315.  
  2316.  
  2317. From icon-group-request@arizona.edu  Sat Jul 20 21:46:20 1991
  2318. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Sat, 20 Jul 91 21:46:20 MST
  2319. Resent-From: icon-group-request@arizona.edu
  2320. Received: from Arizona.edu (Osprey.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  2321.     id AA17051; Sat, 20 Jul 91 21:46:18 MST
  2322. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Sat, 20 Jul
  2323.  1991 21:45 MST
  2324. Received: by ucbvax.berkeley.edu (5.63/1.42) id AA02420; Sat, 20 Jul 91
  2325.  21:38:52 -0700
  2326. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  2327.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  2328.  usenet@ucbvax.Berkeley.EDU if you have questions)
  2329. Resent-Date: Sat, 20 Jul 1991 21:46 MST
  2330. Date: 13 Jul 91 18:20:22 GMT
  2331. From: bloom-picayune.mit.edu!snorkelwacker.mit.edu!ira.uka.de!ira.uka.de@bloom-beacon.mit.edu (Angelo
  2332.  Schneider Betr.Prechelt)
  2333. Subject: RE: How to call a generator from everywhere
  2334. Sender: icon-group-request@arizona.edu
  2335. Resent-To: icon-group@cs.arizona.edu
  2336. To: icon-group@arizona.edu
  2337. Resent-Message-Id: <63A0FDCE9060C8B8@Arizona.edu>
  2338. Message-Id: <k7uh36INNi8u@iraun1.ira.uka.de>
  2339. X-Envelope-To: icon-group@CS.Arizona.EDU
  2340. X-Vms-To: icon-group@Arizona.edu
  2341. Organization: University of Karlsruhe, FRG
  2342. References: <k7p5qcINNs2f@iraun1.ira.uka.de>,
  2343.  <1991Jul11.200929.23411@midway.uchicago.edu>
  2344.  
  2345.  
  2346.  
  2347. [ My earlier posting deleted ]
  2348.  
  2349. In article <1991Jul11.200929.23411@midway.uchicago.edu|,
  2350. goer@ellis.uchicago.edu (Richard L. Goerwitz) writes:
  2351.  
  2352.  
  2353.  
  2354. | It looks to me as though you want to do this,
  2355. |     every word := GetWord() do {
  2356. |         case word of {
  2357. |             pattern1 : action1()
  2358. |             pattern2 : action2()
  2359. |             etc.
  2360. |             default  : write(word)
  2361. |         }
  2362. |     }
  2363.  
  2364.    [ some stuff deleted here ]
  2365.  
  2366. | If you want to get really clever, you could write procedures that are the
  2367. | same as the keywords, yielding:
  2368. | procedure main()
  2369.  
  2370. From uunet!men2a!aquin!luvthang!talmage  Mon Jul 22 15:17:20 1991
  2371. Received: from univers.cs.arizona.edu by cheltenham.cs.arizona.edu; Mon, 22 Jul 91 15:17:20 MST
  2372. Received: from uunet.UUCP by univers.cs.arizona.edu; Mon, 22 Jul 91 15:17:19 MST
  2373. Received: from uunet.uu.net (via LOCALHOST.UU.NET) by relay2.UU.NET with SMTP 
  2374.     (5.61/UUNET-internet-primary) id AA22855; Mon, 22 Jul 91 13:22:15 -0400
  2375. Received: from men2a.UUCP by uunet.uu.net with UUCP/RMAIL
  2376.     (queueing-rmail) id 132118.16539; Mon, 22 Jul 1991 13:21:18 EDT
  2377. Received: by men2a.ori-cal.com (smail2.5)
  2378.     id AA17051; 22 Jul 91 13:16:20 EDT (Mon)
  2379. Received: by aquin.ORI-CAL.COM (smail2.5)
  2380.     id AA11868; 22 Jul 91 13:04:22 EDT (Mon)
  2381. Received: by luvthang.aquin.ori-cal.com (1.05D/Amiga)
  2382.     id AA02575; Mon, 22 Jul 91 11:48:39 EST
  2383. Date: Mon, 22 Jul 91 11:48:39 EST
  2384. Message-Id: <9107221648.AA02575@luvthang.aquin.ori-cal.com>
  2385. From: uunet!luvthang.aquin.ori-cal.com!talmage (David W. Talmage)
  2386. To: uunet!icon-group
  2387. Subject: Looking for Idol users
  2388.  
  2389. Over the past seven months, I've been using Clint Jeffery's Idol
  2390. lanagage.  I find it a useful and well-designed language.
  2391.  
  2392. I'd like to other Idol users about starting a mailing list, tentatively
  2393. called idol-group.  Its purpose will be similar to that of the
  2394. icon-group: to further discussion about Idol and to provide a forum
  2395. for exchanging useful code.  I volunteer to maintain the list for now.
  2396.  
  2397. If you're interested, even vaguely, please contact me by e-mail.
  2398.  
  2399. David W. Talmage 
  2400. uunet!luvthang!talmage
  2401. talmage@luvthang.aquin.ori-cal.com
  2402.  
  2403. From R.J.Hare@edinburgh.ac.uk  Tue Jul 23 17:58:19 1991
  2404. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Tue, 23 Jul 91 17:58:19 MST
  2405. Received: from Arizona.edu (Osprey.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  2406.     id AA07122; Tue, 23 Jul 91 17:57:48 MST
  2407. Received: from UKACRL.BITNET (MAILER@UKACRL) by Arizona.edu with PMDF#10282;
  2408.  Tue, 23 Jul 1991 17:36 MST
  2409. Received: from RL.IB by UKACRL.BITNET (Mailer R2.07) with BSMTP id 5948; Tue,
  2410.  23 Jul 91 16:46:01 BST
  2411. Received: from RL.IB by UK.AC.RL.IB (Mailer R2.07) with BSMTP id 1006; Tue, 23
  2412.  Jul 91 16:46:00 BST
  2413. Date: 23 Jul 91  16:46:50 bst
  2414. From: R.J.Hare@edinburgh.ac.uk
  2415. Subject: comparing one file to another
  2416. To: icon-group@cs.arizona.edu
  2417. Message-Id: <23 Jul 91  16:46:50 bst  060328@EMAS-A>
  2418. X-Envelope-To: icon-group@cs.arizona.edu
  2419. Via:        UK.AC.ED.EMAS-A; 23 JUL 91 16:45:57 BST
  2420.  
  2421.  
  2422. I have at last persuaded some colleagues to use Icon, and they are
  2423. getting pretty enthusiastic. They have an application involving the
  2424. searching of large files containing postcodes (plus other information)
  2425. for matches with postcodes contained in smaller files, and displaying
  2426. the whole record from the larger file when a match is made.
  2427.  
  2428. I can see several ways of doing this, but don't have a feel for which is
  2429. the 'best'
  2430.  
  2431. For example, should we read the postcodes being searched for into a list
  2432. or set and then compare every member of the list or set with the
  2433. postcode portion of the record from the main file?
  2434.  
  2435. Any advice would be appreciated.
  2436.  
  2437. Thanks.
  2438.  
  2439. Roger Hare.
  2440.  
  2441. PS: A postcode is the UK equivalent of a zip code, I guess.
  2442.  
  2443. From wgg@cs.washington.edu  Wed Jul 24 08:52:08 1991
  2444. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Wed, 24 Jul 91 08:52:08 MST
  2445. Received: from june.cs.washington.edu by optima.cs.arizona.edu (4.1/15)
  2446.     id AA06722; Wed, 24 Jul 91 08:52:04 MST
  2447. Received: by june.cs.washington.edu (5.64a/7.1ju)
  2448.     id AA21779; Wed, 24 Jul 91 08:51:47 -0700
  2449. Date: Wed, 24 Jul 91 08:51:47 -0700
  2450. From: wgg@cs.washington.edu (William Griswold)
  2451. Return-Path: <wgg@cs.washington.edu>
  2452. Message-Id: <9107241551.AA21779@june.cs.washington.edu>
  2453. To: R.J.Hare@edinburgh.ac.uk, icon-group@cs.arizona.edu
  2454. Subject: Re:  comparing one file to another
  2455.  
  2456. >From: R.J.Hare@edinburgh.ac.uk
  2457. >Subject: comparing one file to another
  2458.  
  2459. >...
  2460. >searching of large files containing postcodes (plus other information)
  2461. >for matches with postcodes contained in smaller files, and displaying
  2462. >the whole record from the larger file when a match is made.
  2463. >...
  2464. >For example, should we read the postcodes being searched for into a list
  2465. >or set and then compare every member of the list or set with the
  2466. >postcode portion of the record from the main file?
  2467. >...
  2468.  
  2469. I would consider translating the smaller file into a set of postal codes,
  2470. and then the following would be possible:
  2471.  
  2472.     postalcodes := set()
  2473.     while insert(postalcodes,read(postalcode_file))
  2474.  
  2475.     while entry := get_entry(big_address_file) do
  2476.       if member(postalcodes, entry.postalcode) then
  2477.     display_entry(entry)
  2478.  
  2479. As written, this requires defining an address record type and some functions
  2480. for manipulating addresses, which wouldn't be a bad idea if you ever planned
  2481. on doing anything else with the addresses.  However, if you preferred, you
  2482. could just code string parsing operations in-line.
  2483.  
  2484. I'm sure that there are cleverer solutions, but this should be fine.
  2485.  
  2486.                     Bill Griswold
  2487.  
  2488. From uunet!men2a!aquin!luvthang!talmage  Wed Jul 24 15:09:44 1991
  2489. Received: from univers.cs.arizona.edu by cheltenham.cs.arizona.edu; Wed, 24 Jul 91 15:09:44 MST
  2490. Received: from uunet.UUCP by univers.cs.arizona.edu; Wed, 24 Jul 91 15:09:45 MST
  2491. Received: from uunet.uu.net (via LOCALHOST.UU.NET) by relay1.UU.NET with SMTP 
  2492.     (5.61/UUNET-internet-primary) id AA10220; Wed, 24 Jul 91 15:06:32 -0400
  2493. Received: from men2a.UUCP by uunet.uu.net with UUCP/RMAIL
  2494.     (queueing-rmail) id 150514.21326; Wed, 24 Jul 1991 15:05:14 EDT
  2495. Received: by men2a.ori-cal.com (smail2.5)
  2496.     id AA28667; 24 Jul 91 15:04:52 EDT (Wed)
  2497. Received: by aquin.ORI-CAL.COM (smail2.5)
  2498.     id AA08065; 24 Jul 91 15:00:59 EDT (Wed)
  2499. Received: by luvthang.aquin.ori-cal.com (1.05D/Amiga)
  2500.     id AA02699; Wed, 24 Jul 91 13:28:51 EST
  2501. Date: Wed, 24 Jul 91 13:28:51 EST
  2502. Message-Id: <9107241828.AA02699@luvthang.aquin.ori-cal.com>
  2503. From: uunet!luvthang.aquin.ori-cal.com!talmage (David W. Talmage)
  2504. To: uunet!icon-group
  2505. Subject: Icon version of reopen()?
  2506.  
  2507. Does anyone have an Icon version of the file function reopen()?  It's
  2508. supposed to reopen a new file using an existing file handle, closing
  2509. the old file before reusing the handle.
  2510.  
  2511. I've written one in Idol for a file manager I wrote, but I don't have
  2512. one for Icon that works exactly as I've described.
  2513.  
  2514. -----------------------------------------------------------------------------
  2515. David W. Talmage (talmage@luvthang.aquin.ori-cal.com)
  2516. "I need fifty dollars to make you hollar.  I get paid to run this luvthang."
  2517.  
  2518. From R.J.Hare@edinburgh.ac.uk  Thu Jul 25 15:52:12 1991
  2519. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Thu, 25 Jul 91 15:52:12 MST
  2520. Received: from Arizona.edu (Hopey.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  2521.     id AA10777; Thu, 25 Jul 91 15:52:07 MST
  2522. Received: from UKACRL.BITNET (MAILER@UKACRL) by Arizona.edu with PMDF#10282;
  2523.  Thu, 25 Jul 1991 15:51 MST
  2524. Received: from RL.IB by UKACRL.BITNET (Mailer R2.07) with BSMTP id 9592; Thu,
  2525.  25 Jul 91 09:35:56 BST
  2526. Received: from RL.IB by UK.AC.RL.IB (Mailer R2.07) with BSMTP id 2266; Thu, 25
  2527.  Jul 91 09:35:56 BST
  2528. Date: 25 Jul 91  09:36:48 bst
  2529. From: R.J.Hare@edinburgh.ac.uk
  2530. Subject: File comparing
  2531. To: icon-group@cs.arizona.edu
  2532. Message-Id: <25 Jul 91  09:36:48 bst  060620@EMAS-A>
  2533. X-Envelope-To: icon-group@cs.arizona.edu
  2534. Via:        UK.AC.ED.EMAS-A; 25 JUL 91  9:35:54 BST
  2535.  
  2536. Thanks to all who replied to my query about matching lines in a query file
  2537. with thos in a master file for UK Postcodes. Several approaches, all look good
  2538. in different circumstances. What I have done is provide a short deomnstration
  2539. program (all that is needed at this stage) using sets to prove that Icon can
  2540. handle the large(ish) amounts of data being processed.
  2541.  
  2542. A simple postcode search program (about 9 lines) gets through the 5Mb Scottish
  2543. postcode file in about 90 seconds. Good enough, I am told.
  2544.  
  2545. Once again, thanks to all who responded - I think I replied to
  2546. each message individually - if I didn't please accept this message
  2547. as my thanks.
  2548.  
  2549. Roger Hare.
  2550.  
  2551. From uunet!men2a!aquin!luvthang!talmage  Fri Jul 26 10:46:29 1991
  2552. Received: from univers.cs.arizona.edu by cheltenham.cs.arizona.edu; Fri, 26 Jul 91 10:46:29 MST
  2553. Received: from uunet.UUCP by univers.cs.arizona.edu; Fri, 26 Jul 91 10:46:27 MST
  2554. Received: from uunet.uu.net (via LOCALHOST.UU.NET) by relay1.UU.NET with SMTP 
  2555.     (5.61/UUNET-internet-primary) id AA21563; Fri, 26 Jul 91 13:11:24 -0400
  2556. Received: from men2a.UUCP by uunet.uu.net with UUCP/RMAIL
  2557.     (queueing-rmail) id 131034.24374; Fri, 26 Jul 1991 13:10:34 EDT
  2558. Received: by men2a.ori-cal.com (smail2.5)
  2559.     id AA04229; 26 Jul 91 13:09:43 EDT (Fri)
  2560. Received: by aquin.ORI-CAL.COM (smail2.5)
  2561.     id AA06835; 26 Jul 91 13:03:45 EDT (Fri)
  2562. Received: by luvthang.aquin.ori-cal.com (1.05D/Amiga)
  2563.     id AA02771; Fri, 26 Jul 91 07:52:39 EST
  2564. Date: Fri, 26 Jul 91 07:52:39 EST
  2565. Message-Id: <9107261252.AA02771@luvthang.aquin.ori-cal.com>
  2566. From: uunet!luvthang.aquin.ori-cal.com!talmage (David W. Talmage)
  2567. To: uunet!idol-group
  2568. Cc: uunet!icon-group
  2569. Subject: Idol-group charter
  2570.  
  2571. About a week ago, I solicited interest in forming an Idol mailing
  2572. list.  Here my proposal for the mailing list charter, it's statement
  2573. of purpose.  Please send comments, if any, to
  2574. uunet!luvthang!idol-group or idol-group@luvthang.aquin.ori-cal.com.
  2575.  
  2576. David W. Talmage
  2577. uunet!luvthang!talmage
  2578. talmage@luvthang.aquin.ori-cal.com
  2579. ----------
  2580. This is the proposed charter of the idol-group.
  2581.  
  2582. The idol-group is an unmoderated mailing list for people interested in
  2583. the Idol language.  Idol, an "Icon-derived object language"[1], is "an
  2584. object-oriented extension and environment for the Icon programming
  2585. language."[2]  The idol-group will be a forum for discussing Idol
  2586. programming, object-oriented programming, and Idol implementation
  2587. issues.  It will also be a place to exchange Idol classes and
  2588. programs, contributing to the library of useful Idol code. 
  2589.  
  2590. To submit something to the idol-group, send e-mail to
  2591. uunet!luvthang!idol-group or idol-group-request@luvthang.aquin.ori-cal.com.
  2592.  
  2593. For idol-group administrivia, including subscribing and unsubscribing,
  2594. send e-mail to uunet!luvthang!idol-group-request or
  2595. idol-group-request@luvthang.aquin.ori-cal.com.  If you want to
  2596. subscribe, please give your name, your e-mail address, and an optional
  2597. summary of your interest in Idol.  These introductions will be
  2598. forwarded to the idol-group at your request.
  2599.  
  2600. To unsubscribe, send an e-mail request to uunet!luvthang!idol-group-request
  2601. or idol-group-request@luvthang.aquin.ori-cal.com.  Ask to be removed
  2602. from the list.  Please include your name and e-mail address.
  2603.  
  2604. David Talmage, idol-group coordinator
  2605. uunet!luvthang!talmage
  2606. talmage@luvthang.aquin.ori-cal.com
  2607.  
  2608. [1], [2]: Jeffery, Clinton L., "TR90-10", Dept. of Computer Science,
  2609. University of Arizona.  May 8, 1991.
  2610.  
  2611. From iphase!!chuck@uunet.uu.net  Tue Jul 30 12:47:55 1991
  2612. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Tue, 30 Jul 91 12:47:55 MST
  2613. Resent-From: iphase!!chuck@uunet.uu.net
  2614. Received: from Arizona.edu (Merlin.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  2615.     id AA11598; Tue, 30 Jul 91 12:47:52 MST
  2616. Received: from relay2.UU.NET by Arizona.edu with PMDF#10282; Tue, 30 Jul 1991
  2617.  12:47 MST
  2618. Received: from uunet.uu.net (via LOCALHOST.UU.NET) by relay2.UU.NET with SMTP
  2619.  (5.61/UUNET-internet-primary) id AA22093; Tue, 30 Jul 91 15:47:20 -0400
  2620. Received: from iphase.UUCP by uunet.uu.net with UUCP/RMAIL (queueing-rmail) id
  2621.  154636.22767; Tue, 30 Jul 1991 15:46:36 EDT
  2622. Received: by iphase (4.0/SMI-4.0) id AA07743; Tue, 30 Jul 91 14:14:11 CDT
  2623. Resent-Date: Tue, 30 Jul 1991 12:47 MST
  2624. Date: Tue, 30 Jul 91 14:14:10 CDT
  2625. From: chuck%@@uunet.uu.net (Chuck Diehl COMM)
  2626. Subject: SUBSCRIBE
  2627. Resent-To: icon-group@cs.arizona.edu
  2628. To: icon-group@arizona.edu
  2629. Resent-Message-Id: <F41042AF4A80A0B1@Arizona.edu>
  2630. Message-Id: <9107301914.AA07743@iphase>
  2631. X-Envelope-To: icon-group@CS.Arizona.EDU
  2632. X-Vms-To: icon-group@Arizona.edu
  2633. X-Mailer: ELM [version 2.3 PL0]
  2634.  
  2635.  
  2636.  
  2637. From ksr!ksr.com!tim@uunet.uu.net  Fri Aug  2 22:56:47 1991
  2638. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Fri, 2 Aug 91 22:56:47 MST
  2639. Received: from relay2.UU.NET by optima.cs.arizona.edu (4.1/15)
  2640.     id AA17896; Fri, 2 Aug 91 22:56:34 MST
  2641. Received: from uunet.uu.net (via LOCALHOST.UU.NET) by relay2.UU.NET with SMTP 
  2642.     (5.61/UUNET-internet-primary) id AA08875; Sat, 3 Aug 91 01:56:31 -0400
  2643. Received: from ksr.UUCP by uunet.uu.net with UUCP/RMAIL
  2644.     (queueing-rmail) id 015519.11903; Sat, 3 Aug 1991 01:55:19 EDT
  2645. Received: from kaos.ksr.com by ksr.com (4.0/SMI-3.2)
  2646.     id AA21869; Sat, 3 Aug 91 01:30:24 EDT
  2647. Received: by kaos.ksr.com (4.0/SMI-3.2)
  2648.     id AA26526; Sat, 3 Aug 91 01:30:23 EDT
  2649. Message-Id: <9108030530.AA26526@kaos.ksr.com>
  2650. To: icon-group@cs.arizona.edu
  2651. Subject: Coexp memory leak in Icon V8 (UNIX, SPARC)?; i^0 bug
  2652. Date: Sat, 03 Aug 91 01:30:21 -0400
  2653. From: Tim Peters <tim@ksr.com>
  2654.  
  2655. Apologies in advance if this isn't the right place to report suspected
  2656. Icon problems.
  2657.  
  2658. Have a rather large Icon program that's crawling over linked graph
  2659. structures (dags, really -- but it doesn't matter).  Wrote the graph
  2660. traversal algorithms to be invoked as coexpressions, as in
  2661.  
  2662.     posttrav := create traverse_postorder( root_of_graph )
  2663.     while next_vertex := @posttrav do ...
  2664.  
  2665. Inside the graph-crawlers, "the next" vertex is returned to the caller
  2666. via
  2667.  
  2668.     next_vertex @ &source
  2669.  
  2670. The graph-crawlers are highly recursive, and the real point of doing a
  2671. coexp switch instead of a suspend inside them (coupled with an "every"
  2672. in the caller) was to avoid the overhead of suspending & resuming thru
  2673. many recursive levels each time.  Timing in fact showed that this *did*
  2674. save a good chunk of time over the more-straightforward coding via
  2675. every/suspend.
  2676.  
  2677. But when the problem instances started getting bigger, very large
  2678. slowdowns (factors of 10-50) started showing up, and memory use went
  2679. thru the roof.  The simple program below reproduces what I think the
  2680. culprit to be:  the used-up coexp memory is apparently never being
  2681. reclaimed, so garbage collection keeps uselessly thrashing over larger &
  2682. larger regions of "lost" memory (or, if that isn't the case, it's a
  2683. darned good imitation of the truth <grin>).
  2684.  
  2685. Here's the program:
  2686.  
  2687. >>> BEGIN TEST CASE
  2688.  
  2689. record vertex( a, b, c, d, e, f, g )
  2690.  
  2691. procedure main( args )
  2692.    local i, limit, coexp
  2693.  
  2694.    limit := integer(get(args)) | 100
  2695.  
  2696.    write( "Host: ", &host )
  2697.    write( "Version: ", &version )
  2698.    write( "Features:" )
  2699.    every write( "   ", &features )
  2700.  
  2701.    every i := 1 to limit do {
  2702.       (i < 5 | i = limit) & dumpstats(i)
  2703.       coexp := create inner()
  2704.       while @coexp
  2705.    }
  2706.  
  2707. end  # procedure main
  2708.  
  2709. procedure inner()
  2710.    vertex() @ &source
  2711.    fail
  2712. end  # procedure inner
  2713.  
  2714. procedure dumpstats( i )
  2715.    local c
  2716.    c := create &collections # gimmick to skip the first return value
  2717.    write( "iter ", i )
  2718.    writes(r("collections")); @c; every writes(r(|@c)); write()
  2719.    writes(r("regions")); every writes(r(®ions)); write()
  2720.    writes(r("storage")); every writes(r(&storage)); write()
  2721. end  # procedure dumpstats
  2722.  
  2723. procedure r( s )
  2724.    return right( s, 12 )
  2725. end  # procedure r
  2726.  
  2727. >>> END TEST CASE
  2728.  
  2729. And here's the output:
  2730.  
  2731. >>> BEGIN OUTPUT
  2732.  
  2733. Host: kaos
  2734. Version: Icon Version 8.0.  May 7, 1990
  2735. Features:
  2736.    UNIX
  2737.    ASCII
  2738.    co-expressions
  2739.    direct execution
  2740.    environment variables
  2741.    error trace back
  2742.    executable images
  2743.    expandable regions
  2744.    external functions
  2745.    large integers
  2746.    math functions
  2747.    memory monitoring
  2748.    pipes
  2749.    string invocation
  2750.    system function
  2751. iter 1
  2752.  collections           0           0           0
  2753.      regions       20000       65024       65024
  2754.      storage       20000         124         192
  2755. iter 2
  2756.  collections           1           0           0
  2757.      regions       30000       65024       65024
  2758.      storage       30000         120         288
  2759. iter 3
  2760.  collections           2           0           0
  2761.      regions       30000       65024       65024
  2762.      storage       30000         120         384
  2763. iter 4
  2764.  collections           4           0           0
  2765.      regions       40000       65024       65024
  2766.      storage       40000         120         480
  2767. iter 100
  2768.  collections         101           0           0
  2769.      regions     1000000       65024       65024
  2770.      storage     1000000         120        9696
  2771.  
  2772. >>> END OUTPUT
  2773.  
  2774. This was run on a SPARC (Solbourne) -- know a way around it?  Some
  2775. notes:
  2776.  
  2777.   - It does *not* make any difference to add the lines
  2778.  
  2779.       coexp := &null
  2780.  
  2781.     or
  2782.  
  2783.       coexp := &null; collect()
  2784.  
  2785.     after the "while @coexp" line.
  2786.  
  2787.   - The coexpression in dumpstats() has no effect on this one way or the
  2788.     other; just used it here because it was convenient; the problem
  2789.     remains if dumpstats is purged of coexpressions.
  2790.  
  2791.   - The output above shows that the static region just grows & grows.
  2792.     It's also true (although the output above does not show this (at
  2793.     least not clearly)) that the block region grows & grows too; I think
  2794.     because the block stuff created by the coexpressions isn't reclaimed
  2795.     because the coexps themselves aren't reclaimed.
  2796.  
  2797.   - The exact output above is "almost always" reproducible.  But once in
  2798.     a blue moon it dies with the baffling runtime error 302 (system
  2799.     stack overflow).  This makes me wonder whether it might not be a
  2800.     local installation problem, or that maybe the coexp switch code
  2801.     isn't saving & restoring all that it should be ... ?  The coexp
  2802.     code for a machine with register windows must be a real pain!
  2803.  
  2804.  
  2805. Might as well clean out my bug list here <grin>.  I get burned by this
  2806. one a couple times each month:
  2807.  
  2808. procedure main()
  2809.    write( 3^0 )
  2810. end  # procedure main
  2811.  
  2812. This prints "0".  I realize that the proper value (if any) of "0^0" is
  2813. the subject of intense religious debate, but far as I know *everyone*
  2814. agrees that "i^0" is 1 whenever i ~= 0 (e.g., try "pow" in C or "**" in
  2815. Fortran or an HP calculator or any number of textbooks ...).  E.g., 543
  2816. = 5*10^2 + 4*10^1 + 3*10^0 = 5*100 + 4*10 + 3*1, and that hints at why
  2817. the i^0=1 convention is helpful.  Maybe a more Iconish way is to
  2818. consider that
  2819.  
  2820.     ishift(1,i) = 2^i
  2821.  
  2822. isn't an identity for i=0 unless the i^0=1 convention is followed (and
  2823. if that convention is followed, it's an identity for all integer i).
  2824. Maybe the most compelling way is to note that the basic recurrence
  2825. (arguably the *definition* of "^" for integers)
  2826.  
  2827.     x^n = x * x^(n-1)
  2828.  
  2829. doesn't hold for n=1 unless x^0=1.
  2830.  
  2831. More rabid arguments on request <grin>.
  2832.  
  2833. iconingly y'rs  - tim
  2834.  
  2835. Tim Peters   Kendall Square Research Corp
  2836. tim@ksr.com,         ksr!tim@uunet.uu.net
  2837.  
  2838. From icon-group-request@arizona.edu  Sat Aug  3 02:12:50 1991
  2839. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Sat, 3 Aug 91 02:12:50 MST
  2840. Resent-From: icon-group-request@arizona.edu
  2841. Received: from Arizona.edu (Osprey.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  2842.     id AA27055; Sat, 3 Aug 91 02:12:47 MST
  2843. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Sat, 3 Aug
  2844.  1991 02:12 MST
  2845. Received: by ucbvax.berkeley.edu (5.63/1.42) id AA11501; Sat, 3 Aug 91 02:07:09
  2846.  -0700
  2847. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  2848.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  2849.  usenet@ucbvax.Berkeley.EDU if you have questions)
  2850. Resent-Date: Sat, 3 Aug 1991 02:12 MST
  2851. Date: 3 Aug 91 08:22:24 GMT
  2852. From: cis.ohio-state.edu!pacific.mps.ohio-state.edu!linac!midway!quads.uchicago.edu!goer@ucbvax.berkeley.edu (Richard L.
  2853.  Goerwitz)
  2854. Subject: RE: Coexp memory leak in Icon V8 (UNIX, SPARC)?; i^0 bug
  2855. Sender: icon-group-request@arizona.edu
  2856. Resent-To: icon-group@cs.arizona.edu
  2857. To: icon-group@arizona.edu
  2858. Resent-Message-Id: <BFFCBF5ADA200AB9@Arizona.edu>
  2859. Message-Id: <1991Aug3.082224.12971@midway.uchicago.edu>
  2860. X-Envelope-To: icon-group@CS.Arizona.EDU
  2861. X-Vms-To: icon-group@Arizona.edu
  2862. Organization: University of Chicago
  2863. References: <9108030530.AA26526@kaos.ksr.com>
  2864.  
  2865. In article <9108030530.AA26526@kaos.ksr.com> tim@ksr.com (Tim Peters) writes:
  2866. >
  2867. >   every i := 1 to limit do {
  2868. >      (i < 5 | i = limit) & dumpstats(i)
  2869. >      coexp := create inner()
  2870. >      while @coexp
  2871. >   }
  2872.  
  2873. Eek, you've been bitten by the "unreachable coexpressions" bug.  Make
  2874. coexp global, and the problem *should* go away quite magically.
  2875.  
  2876. -- 
  2877.  
  2878.    -Richard L. Goerwitz              goer%sophist@uchicago.bitnet
  2879.    goer@sophist.uchicago.edu         rutgers!oddjob!gide!sophist!goer
  2880.  
  2881. From icon-group-request@arizona.edu  Sat Aug  3 19:14:05 1991
  2882. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Sat, 3 Aug 91 19:14:05 MST
  2883. Resent-From: icon-group-request@arizona.edu
  2884. Received: from Arizona.edu (Hopey.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  2885.     id AA18973; Sat, 3 Aug 91 19:14:02 MST
  2886. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Sat, 3 Aug
  2887.  1991 19:13 MST
  2888. Received: by ucbvax.berkeley.edu (5.63/1.42) id AA29415; Sat, 3 Aug 91 19:00:51
  2889.  -0700
  2890. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  2891.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  2892.  usenet@ucbvax.Berkeley.EDU if you have questions)
  2893. Resent-Date: Sat, 3 Aug 1991 19:13 MST
  2894. Date: 4 Aug 91 01:53:29 GMT
  2895. From: ksr!tim@uunet.uu.net (Tim Peters)
  2896. Subject: RE: Coexp memory leak in Icon V8 (UNIX, SPARC)?; i^0 bug
  2897. Sender: icon-group-request@arizona.edu
  2898. Resent-To: icon-group@cs.arizona.edu
  2899. To: icon-group@arizona.edu
  2900. Resent-Message-Id: <4EAB8F3B8C001430@Arizona.edu>
  2901. Message-Id: <4891@ksr.com>
  2902. X-Envelope-To: icon-group@CS.Arizona.EDU
  2903. X-Vms-To: icon-group@Arizona.edu
  2904. Organization: Kendall Square Research Corp.
  2905. References: <9108030530.AA26526@kaos.ksr.com>,
  2906.  <1991Aug3.082224.12971@midway.uchicago.edu>
  2907.  
  2908. In article <1991Aug3.082224.12971@midway.uchicago.edu> goer@quads.uchicago.edu (Richard L. Goerwitz) writes:
  2909. >In article <9108030530.AA26526@kaos.ksr.com> tim@ksr.com (Tim Peters) writes:
  2910. >>
  2911. >>   every i := 1 to limit do {
  2912. >>      (i < 5 | i = limit) & dumpstats(i)
  2913. >>      coexp := create inner()
  2914. >>      while @coexp
  2915. >>   }
  2916. >
  2917. >Eek, you've been bitten by the "unreachable coexpressions" bug.  Make
  2918. >coexp global, and the problem *should* go away quite magically.
  2919.  
  2920. Excellent suggestion, Richard!  Steve Wampler tried to explain what's
  2921. "really" going on here in E-Mail, and suggested a similar trick.
  2922.  
  2923. Alas, turns out nothing (so far) makes a real difference.  Making coexp
  2924. global slightly slows the growth of the block region, but doesn't affect
  2925. the growth of the static region (which is sucking up another 10K per
  2926. iteration) at all.  I'll attach the current version of the test case in
  2927. case you'd like to play with it -- still don't know whether this is a
  2928. local glitch or unique to SPARC or ...
  2929.  
  2930. But thanks for the idea!  It's clever & appreciated, and I certainly
  2931. agree it *"should"* have worked.
  2932.  
  2933. exploring-icon's-dark-side<grin>-ly y'rs  - tim
  2934.  
  2935. Tim Peters   Kendall Square Research Corp
  2936. tim@ksr.com,         ksr!tim@uunet.uu.net
  2937.  
  2938.  
  2939. Terminal session with current version; output is identical to that of
  2940. the original version, except that the block region is growing a little
  2941. bit slower now:
  2942.  
  2943. kaos 38= cat leak2.icn
  2944. record vertex( a, b, c, d, e, f, g )
  2945.  
  2946. global coexp  # get rid of all the local pointers to the "create"
  2947.  
  2948. procedure main( args )
  2949.    local i, limit   # removed coexp from this list
  2950.  
  2951.    limit := integer(get(args)) | 100
  2952.  
  2953.    write( "Host: ", &host )
  2954.    write( "Version: ", &version )
  2955.    write( "Features:" )
  2956.    every write( "   ", &features )
  2957.  
  2958.    every i := 1 to limit do {
  2959.  
  2960.       (i < 5 | i = limit) & dumpstats(i)
  2961.  
  2962.       coexp := &null    # paranoia
  2963.       coexp := create inner()
  2964.       while @coexp
  2965.    }
  2966.  
  2967. end  # procedure main
  2968.  
  2969. procedure inner()
  2970.    vertex() @ &source  # switching to &main doesn't help either
  2971.    fail
  2972. end  # procedure inner
  2973.  
  2974. procedure dumpstats( i )
  2975.    local c
  2976.    c := create &collections # gimmick to skip the first return value
  2977.    write( "iter ", i )
  2978.    writes(r("collections")); @c; every writes(r(|@c)); write()
  2979.    writes(r("regions")); every writes(r(®ions)); write()
  2980.    writes(r("storage")); every writes(r(&storage)); write()
  2981. end  # procedure dumpstats
  2982.  
  2983. procedure r( s )
  2984.    return right( s, 12 )
  2985. end  # procedure r
  2986. kaos 39= /usr/local/lib/icon/v8/bin/icont -u leak2 -x
  2987. Translating:
  2988. leak2.icn:
  2989.   main (823/15000)
  2990.   inner (123/15000)
  2991.   dumpstats (728/15000)
  2992.   r (109/15000)
  2993. No errors
  2994. Linking:
  2995. Executing:
  2996. Host: kaos
  2997. Version: Icon Version 8.0.  May 7, 1990
  2998. Features:
  2999.    UNIX
  3000.    ASCII
  3001.    co-expressions
  3002.    direct execution
  3003.    environment variables
  3004.    error trace back
  3005.    executable images
  3006.    expandable regions
  3007.    external functions
  3008.    large integers
  3009.    math functions
  3010.    memory monitoring
  3011.    pipes
  3012.    string invocation
  3013.    system function
  3014. iter 1
  3015.  collections           0           0           0
  3016.      regions       20000       65024       65024
  3017.      storage       20000         124         192
  3018. iter 2
  3019.  collections           1           0           0
  3020.      regions       30000       65024       65024
  3021.      storage       30000         120         280
  3022. iter 3
  3023.  collections           2           0           0
  3024.      regions       30000       65024       65024
  3025.      storage       30000         120         368
  3026. iter 4
  3027.  collections           4           0           0
  3028.      regions       40000       65024       65024
  3029.      storage       40000         120         456
  3030. iter 100
  3031.  collections         101           0           0
  3032.      regions     1000000       65024       65024
  3033.      storage     1000000         120        8904
  3034. kaos 40=
  3035.  
  3036. >>> END OF MSG
  3037.  
  3038. From icon-group-request@arizona.edu  Sun Aug  4 23:45:07 1991
  3039. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Sun, 4 Aug 91 23:45:07 MST
  3040. Resent-From: icon-group-request@arizona.edu
  3041. Received: from Arizona.edu (Hopey.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  3042.     id AA29230; Sun, 4 Aug 91 23:45:05 MST
  3043. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Sun, 4 Aug
  3044.  1991 23:44 MST
  3045. Received: by ucbvax.berkeley.edu (5.63/1.42) id AA29642; Sun, 4 Aug 91 23:30:47
  3046.  -0700
  3047. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  3048.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  3049.  usenet@ucbvax.Berkeley.EDU if you have questions)
  3050. Resent-Date: Sun, 4 Aug 1991 23:44 MST
  3051. Date: 5 Aug 91 06:18:59 GMT
  3052. From: ksr!tim@uunet.uu.net (Tim Peters)
  3053. Subject: A pretty use of co-expressions
  3054. Sender: icon-group-request@arizona.edu
  3055. Resent-To: icon-group@cs.arizona.edu
  3056. To: icon-group@arizona.edu
  3057. Resent-Message-Id: <3DB3AAC044001725@Arizona.edu>
  3058. Message-Id: <4894@ksr.com>
  3059. X-Envelope-To: icon-group@CS.Arizona.EDU
  3060. X-Vms-To: icon-group@Arizona.edu
  3061. Organization: Kendall Square Research Corp.
  3062.  
  3063. "Primes" below generates the sequence of prime integers (2, 3, 5, 7, 11,
  3064. 13, ...) via a devious co-expression implementation of the old Sieve of
  3065. Eratosthenes (start with the list (2,3,4,5,...); then repeatedly pick
  3066. the first integer off the list and remove all its multiples).
  3067.  
  3068. I think it's pretty enough that other Icon fanatics might enjoy it, but
  3069. it's definitely *not* a practical method for generating lots of primes.
  3070. Each new prime has to wind its way through a chain of co-expressions of
  3071. depth equal to the number of primes previously generated, so time &
  3072. space use grow fast.  As written, "main" prints the first 100 primes,
  3073. and that takes a megabyte of memory on my UNIX(tm)-on-SPARC(tm) Icon;
  3074. it's also prone to flaky run-time errors (bus errors, system stack
  3075. overflow), the frequency of which I can reduce but not eliminate by
  3076. setting COEXPSIZE to larger & larger values.  Would be interested to
  3077. hear whether other folks experience flaky errors too!
  3078.  
  3079. started-life-as-a-mean-coexp-test-but-it-deserves-a-better-fate-than-
  3080.    that<grin>-ly y'rs  - tim
  3081.  
  3082. Tim Peters   Kendall Square Research Corp
  3083. tim@ksr.com,         ksr!tim@uunet.uu.net
  3084.  
  3085. procedure main()
  3086.    every write( Primes()\100 )
  3087. end
  3088.  
  3089. procedure Primes()
  3090.    local first, sequence, val
  3091.  
  3092.    sequence := create seq(2)
  3093.    repeat {
  3094.       suspend first := @sequence
  3095.       sequence := create | if (val := @sequence) % first ~= 0
  3096.                then val else @sequence
  3097.    }
  3098.  
  3099. end
  3100.  
  3101. >>> END OF MSG
  3102.  
  3103. From gmt  Mon Aug  5 10:13:47 1991
  3104. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Mon, 5 Aug 91 10:13:47 MST
  3105. Resent-From: "Gregg Townsend" <gmt>
  3106. Received: from Arizona.edu (Merlin.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  3107.     id AA19865; Mon, 5 Aug 91 10:13:45 MST
  3108. Received: from optima.cs.arizona.edu by Arizona.edu with PMDF#10282; Mon, 5 Aug
  3109.  1991 10:13 MST
  3110. Received: from owl.cs.arizona.edu by optima.cs.arizona.edu (4.1/15) id AA19852;
  3111.  Mon, 5 Aug 91 10:12:56 MST
  3112. Received: by owl.cs.arizona.edu; Mon, 5 Aug 91 10:12:55 MST
  3113. Resent-Date: Mon, 5 Aug 1991 10:13 MST
  3114. Date: Mon, 5 Aug 91 10:12:55 MST
  3115. From: Gregg Townsend <gmt@cs.arizona.edu>
  3116. Subject: RE:  A pretty use of co-expressions
  3117. Resent-To: icon-group@cs.arizona.edu
  3118. To: icon-group@arizona.edu, ksr!tim@uunet.uu.net
  3119. Resent-Message-Id: <958472EF9220102A@Arizona.edu>
  3120. Message-Id: <9108051712.AA18033@owl.cs.arizona.edu>
  3121. X-Envelope-To: icon-group@CS.Arizona.EDU
  3122. X-Vms-To: icon-group@Arizona.edu, ksr!tim@uunet.uu.net
  3123.  
  3124. Here's another Icon generator of prime numbers.  It doesn't use
  3125. coexpressions; it doesn't even use any arithmetic!
  3126.  
  3127.  
  3128. ##  primes(): a generator returning the successive prime numbers
  3129. #
  3130. #   Gregg Townsend
  3131. #   University of Arizona
  3132. #   October, 1987
  3133. #
  3134. #   How it works:  let n be the last odd integer considered.  n is not actually
  3135. #   recorded but reflects the size of the list lf, which contains factors of the
  3136. #   next n odd integers beyond n (n+2 to 3*n).  Every odd prime less than or
  3137. #   equal to n appears exactly once, in the list of its next multiple beyond n.
  3138. #
  3139. #   Each time around the loop, the first entry in lf is popped.  If this sublist
  3140. #   is empty, the new n is prime and its value is produced.  Then all factors
  3141. #   on the popped sublist, or the new prime, are re-entered in their correct new
  3142. #   positions.
  3143. #
  3144. #   lf needs to be size n whenever a new prime is inserted, and is grown 
  3145. #   constantly to maintain that size.
  3146.  
  3147.  
  3148. procedure primes()
  3149.     suspend 2            # do this once, then forget the even numbers
  3150.     lf := [[]]
  3151.     repeat {            # at each iteration:
  3152.     f := get(lf)        # get sublist of factors
  3153.     put(lf,[])        # grow the list
  3154.     put(lf,[])
  3155.     put(lf,f)        # reuse the list we popped in position lf[n]
  3156.     if *f = 0 then {    # if empty, no smaller factors, so it's prime!
  3157.         put(f,*lf)        # add n as a factor (remember, list was reused)
  3158.         suspend *lf        # pass back the prime
  3159.     } else
  3160.         while v := get(f) do  # take each popped factor
  3161.         put(lf[v],v)      # and add to the list at its next multiple
  3162.     }
  3163.     end
  3164.  
  3165. From icon-group-request@arizona.edu  Mon Aug  5 22:20:17 1991
  3166. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Mon, 5 Aug 91 22:20:17 MST
  3167. Resent-From: icon-group-request@arizona.edu
  3168. Received: from Arizona.edu (Hopey.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  3169.     id AA01535; Mon, 5 Aug 91 22:20:14 MST
  3170. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Mon, 5 Aug
  3171.  1991 22:19 MST
  3172. Received: by ucbvax.berkeley.edu (5.63/1.42) id AA15233; Mon, 5 Aug 91 22:02:04
  3173.  -0700
  3174. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  3175.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  3176.  usenet@ucbvax.Berkeley.EDU if you have questions)
  3177. Resent-Date: Mon, 5 Aug 1991 22:19 MST
  3178. Date: 5 Aug 91 19:58:34 GMT
  3179. From: mcsun!ukc!slxsys!ibmpcug!demon!news@uunet.uu.net (Paul Moore)
  3180. Subject: RE: Coexp memory leak in Icon
  3181. Sender: icon-group-request@arizona.edu
  3182. Resent-To: icon-group@cs.arizona.edu
  3183. To: icon-group@arizona.edu
  3184. Resent-Message-Id: <FB0209F044001EA7@Arizona.edu>
  3185. Message-Id: <1991Aug05.195834.8933@demon.co.uk>
  3186. X-Envelope-To: icon-group@CS.Arizona.EDU
  3187. X-Vms-To: icon-group@Arizona.edu
  3188. Organization: Gated to News by demon.co.uk
  3189.  
  3190.  
  3191. From tim@ksr.com (Tim Peters)
  3192. > I'll attach the current version of the test case in case you'd like to
  3193. > play with it -- still don't know whether this is a local glitch or
  3194. > unique to SPARC or ...
  3195.  
  3196. I tried your test program on Archimedes Icon (the Archimedes is a
  3197. non-Unix personal computer made by Acorn in the UK - the Icon port is my
  3198. own). I got the same type of result. Output follows. Don't know if this
  3199. helps at all... It's a fixed-regions version where yours is expandable
  3200. regions, though.
  3201.  
  3202. Gustav.
  3203.  
  3204. >>> Output from test routine
  3205.  
  3206. Host: Acorn Archimedes (RISC OS 2.00)
  3207. Version: Icon Version 8.0.  April 1, 1990
  3208. Features:
  3209.    Acorn Archimedes
  3210.    ASCII
  3211.    co-expressions
  3212.    environment variables
  3213.    error trace back
  3214.    external functions
  3215.    fixed regions
  3216.    keyboard functions
  3217.    large integers
  3218.    math functions
  3219.    memory monitoring
  3220.    pipes
  3221.    string invocation
  3222.    system function
  3223.    Archimedes extensions
  3224. iter 1
  3225.  collections           0           0           0
  3226.      regions           0       65000       65000
  3227.      storage           0         151         192
  3228. iter 2
  3229.  collections           0           0           0
  3230.      regions           0       65000       65000
  3231.      storage           0         295         432
  3232. iter 3
  3233.  collections           0           0           0
  3234.      regions           0       65000       65000
  3235.      storage           0         439         672
  3236. iter 4
  3237.  collections           0           0           0
  3238.      regions           0       65000       65000
  3239.      storage           0         583         912
  3240. iter 100
  3241.  collections           0           0           0
  3242.      regions           0       65000       65000
  3243.      storage           0         120       10704
  3244.  
  3245. ---------------------------------------------------------------------------
  3246. Paul Moore                  | "If you could have any amount of money...
  3247. pmoore@cix.compulink.co.uk  |  any amount of money at all...
  3248. gustav@tharr.UUCP           |  how much would you want?"
  3249. ----------------------------| "All of it."
  3250. Opinions? Not me, surely?   | Cerebus, Church & State.
  3251. ---------------------------------------------------------------------------
  3252.  
  3253. From icon-group-request@arizona.edu  Mon Aug  5 23:45:17 1991
  3254. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Mon, 5 Aug 91 23:45:17 MST
  3255. Resent-From: icon-group-request@arizona.edu
  3256. Received: from Arizona.edu (Osprey.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  3257.     id AA03413; Mon, 5 Aug 91 23:45:14 MST
  3258. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Mon, 5 Aug
  3259.  1991 23:44 MST
  3260. Received: by ucbvax.berkeley.edu (5.63/1.42) id AA19539; Mon, 5 Aug 91 23:27:28
  3261.  -0700
  3262. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  3263.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  3264.  usenet@ucbvax.Berkeley.EDU if you have questions)
  3265. Resent-Date: Mon, 5 Aug 1991 23:44 MST
  3266. Date: 6 Aug 91 06:14:18 GMT
  3267. From: world!ksr!tim@decwrl.dec.com (Tim Peters)
  3268. Subject: RE: Coexp memory leak in Icon
  3269. Sender: icon-group-request@arizona.edu
  3270. Resent-To: icon-group@cs.arizona.edu
  3271. To: icon-group@arizona.edu
  3272. Resent-Message-Id: <06E07D9104001F0E@Arizona.edu>
  3273. Message-Id: <4913@ksr.com>
  3274. X-Envelope-To: icon-group@CS.Arizona.EDU
  3275. X-Vms-To: icon-group@Arizona.edu
  3276. Organization: Kendall Square Research Corp.
  3277. References: <1991Aug05.195834.8933@demon.co.uk>
  3278.  
  3279. In article <1991Aug05.195834.8933@demon.co.uk> Paul Moore <pmoore@cix.compulink.co.uk> writes:
  3280. > ...
  3281. >I tried your test program on Archimedes Icon (the Archimedes is a
  3282. >non-Unix personal computer made by Acorn in the UK - the Icon port is my
  3283. >own). I got the same type of result. Output follows. Don't know if this
  3284. >helps at all... It's a fixed-regions version where yours is expandable
  3285. >regions, though.
  3286. > ... [output for last iteration follows] ...
  3287. >iter 100
  3288. > collections           0           0           0
  3289. >     regions           0       65000       65000
  3290. >     storage           0         120       10704
  3291.  
  3292. Thanks for giving it a try, Paul!  I'm not sure whether it shows
  3293. anything either -- the test case doesn't generate enough stuff to
  3294. trigger any collections in the string or block regions, so the "10704"
  3295. used in the block region at the end may well be there just because no
  3296. attempt was ever made at collection.  Would be interesting to see what
  3297. happens if you put a "collect()" before the "dumpstats(i)" to try to
  3298. force the issue.
  3299.  
  3300.  
  3301. After playing around some more I found different ways to write the test
  3302. that did & didn't leak; a summary follows, & it's quite baffling.  In
  3303. all cases "coexp" is a global (I understand now why the memory leaked
  3304. when coexp was local, and happy to post an explanation if it's not the
  3305. universally-known folklore it appears to be <grin>):
  3306.  
  3307. 1) The original "inner":
  3308.  
  3309.     procedure inner()
  3310.        vertex() @ &source
  3311.     end
  3312.  
  3313.    The coexp & block memory doesn't get reclaimed.
  3314.  
  3315. 2) Neither is the memory reclaimed if the guts of inner are changed to
  3316.  
  3317.        vertex() @ &main
  3318.  
  3319. 3) Two variations where the memory *is* reclaimed, by replacing the guts
  3320.    of "inner" with either
  3321.  
  3322.        suspend vertex()
  3323.    or
  3324.        return vertex()
  3325.  
  3326. 4) The real baffler (considered along with variations #1 and #2):  The
  3327.    memory leak also goes away if the "create" is changed to
  3328.  
  3329.        coexp := create inner(¤t)
  3330.  
  3331.    and "inner" is changed to
  3332.  
  3333.     procedure inner( source )
  3334.        vertex() @ source
  3335.     end
  3336.  
  3337. Far as I know, variation #4 "should be" semantically equivalent in every
  3338. respect to variation #1, so why the latter leaks while the former
  3339. doesn't is beyond me.  Seems to be triggered specifically by using the
  3340. keywords "&source" or "&main" as explicit targets of a coexp switch ...
  3341. but that's too odd to believe <grin>.
  3342.  
  3343. clues-confirmations-&-denials-still-solicited-ly y'rs  - tim
  3344.  
  3345. Tim Peters   Kendall Square Research Corp
  3346. tim@ksr.com,         ksr!tim@uunet.uu.net
  3347.  
  3348. From kwalker  Wed Aug  7 20:14:40 1991
  3349. Received: from gacham.cs.arizona.edu by cheltenham.cs.arizona.edu; Wed, 7 Aug 91 20:14:40 MST
  3350. Date: Wed, 7 Aug 91 14:37:40 MST
  3351. From: "Kenneth Walker" <kwalker>
  3352. Message-Id: <9108072137.AA09526@gacham.cs.arizona.edu>
  3353. Received: by gacham.cs.arizona.edu; Wed, 7 Aug 91 14:37:40 MST
  3354. In-Reply-To: <9108070806.AA25327@kaos.ksr.com>
  3355. To: tim@ksr.com
  3356. Subject: Re: Coexp memory leak in Icon
  3357. Cc: icon-group
  3358.  
  3359. > Date: Wed, 07 Aug 91 04:06:42 -0400
  3360. > From: Tim Peters <tim@ksr.com>
  3361. >...
  3362. > 2) That explained the behavior of the most-recent version of "the test
  3363. >    case".  But in trying to exploit that knowledge, I keep hitting
  3364. >    snags.  E.g.,
  3365. > global drive, coexp
  3366. > procedure main()
  3367. >    coexp := create ("OK" @ &source)
  3368. >    drive := create @coexp
  3369. >    write( @drive | "failed?" )
  3370. >    collect()
  3371. > end
  3372. >    That prints "failed?".  I expected "OK", but I think I know why it's
  3373. >    happening (basically that "drive" returns to "coexp" instead of to
  3374. >    &main -- drive's original "fall off the end" return point is altered
  3375. >    *by* the "@ &source" in coexp -- a real head-twister!).
  3376. >
  3377. >...
  3378. > [a vague suggestion by me for tackling the problem]
  3379. > Sorry, but this was the one paragraph I didn't think I could follow.  An
  3380. > example would sure help.  As the other little test case above showed, I
  3381. > think I'm missing something basic here.
  3382.  
  3383. Actually my suggestion was what you tried in the above example. Obviously
  3384. I didn't attempt it before making the suggestion, sorry.
  3385.  
  3386. The bus error problem does not seem to exist in our working copy of the
  3387. interpreter (however, this will not be available to the public for a
  3388. while).
  3389.  
  3390. Your point about a co-expression not needing its activation stack
  3391. once it starts to fail is a good one. I wonder if there are other
  3392. rules like that which could be used to improve the implementation.
  3393. It would be nice to have a simple useful description of the possible
  3394. paths through a set of co-expressions taking into account activation,
  3395. and returning and failing by falling off the end. As you mentioned,
  3396. the subtlies of coexpression activation are hard to understand.
  3397.  
  3398.   Ken Walker / Computer Science Dept / Univ of Arizona / Tucson, AZ 85721
  3399.   +1 602 621-4252  kwalker@cs.arizona.edu {uunet|allegra|noao}!arizona!kwalker
  3400.  
  3401. From kwalker  Wed Aug  7 20:14:41 1991
  3402. Received: from gacham.cs.arizona.edu by cheltenham.cs.arizona.edu; Wed, 7 Aug 91 20:14:41 MST
  3403. Date: Tue, 6 Aug 91 11:25:10 MST
  3404. From: "Kenneth Walker" <kwalker>
  3405. Message-Id: <9108061825.AA08780@gacham.cs.arizona.edu>
  3406. Received: by gacham.cs.arizona.edu; Tue, 6 Aug 91 11:25:10 MST
  3407. In-Reply-To: <4913@ksr.com>
  3408. To: icon-group, world!ksr!tim@decwrl.dec.com
  3409. Subject: RE: Coexp memory leak in Icon
  3410.  
  3411. > Date: Sat, 03 Aug 91 01:30:21 -0400
  3412. > From: Tim Peters <tim@ksr.com>
  3413. > Inside the graph-crawlers, "the next" vertex is returned to the caller
  3414. > via
  3415. >     next_vertex @ &source
  3416. > The graph-crawlers are highly recursive, and the real point of doing a
  3417. > coexp switch instead of a suspend inside them (coupled with an "every"
  3418. > in the caller) was to avoid the overhead of suspending & resuming thru
  3419. > many recursive levels each time.  Timing in fact showed that this *did*
  3420. > save a good chunk of time over the more-straightforward coding via
  3421. > every/suspend.
  3422.  
  3423. I think the optimizing compiler should be able to dynamically collapse
  3424. the suspend chain and eliminate the performance hit of suspending
  3425. through all those recurse calls (somewhat similar to the "tail recursion"
  3426. optimization done for Lisp). It will take some thought to work through
  3427. the details. Thanks for the bit of research! Now back to the real
  3428. problem...
  3429.  
  3430. The problem you have with coexpression build-up (once you get rid of
  3431. the unreachable co-expression problems using the global variable) relates
  3432. to the fact that co-expressions can "fall off the end" and return to their
  3433. last activator. Co-expression keep a stack of their activators. They can
  3434. be recursively activated a number of times and then repeatedly fall off
  3435. the end on the way back down the recursive activation chain. (I think
  3436. I explained this right. The possible paths of transfer of control
  3437. through co-expressions is a little confusing.)
  3438.  
  3439. If they are activated repeatedly and never fall off the end, the stack
  3440. can get large. The stack is implementated in such a way as to often avoid
  3441. that problem: sections of the stack consisting of the same activator
  3442. are represented as the activator and a count of number of times it
  3443. appears in a row. However, this "trick" doesn't always work. In this
  3444. example, &main is repeated activated by different co-expressions. It
  3445. keeps all of them on its activation stack, even when they can be
  3446. reached no other way. (This is maybe a little bogus as &main can
  3447. never fall off the end, but this same thing can be happen in another
  3448. co-exprssion, so it is a real problem.)
  3449.  
  3450. I don't know of any fix to the general problem. There have been long
  3451. and complicated debates about the correct behavior of co-expressions
  3452. when recursive activations and "ruturns" are done; maybe some other
  3453. semantics would allow us to do away with the stack.
  3454.  
  3455. As for your specific problem, can you set up a dyamically created
  3456. co-expression, have the value passed directly to it,then have
  3457. it "return" the value to the main co-expression by falling off the
  3458. end? In this way, &main has no references to the intermediate
  3459. co-expression and garbage collection can dispose of it and the
  3460. the co-expression that does the real work? I have to admit that
  3461. this is a rather gross solution, but I think it will work.
  3462.  
  3463. > Date: 6 Aug 91 06:14:18 GMT
  3464. > From: world!ksr!tim@decwrl.dec.com (Tim Peters)
  3465. >
  3466. >...
  3467. > 4) The real baffler (considered along with variations #1 and #2):  The
  3468. >    memory leak also goes away if the "create" is changed to
  3469. >        coexp := create inner(¤t)
  3470. >    and "inner" is changed to
  3471. >     procedure inner( source )
  3472. >        vertex() @ source
  3473. >     end
  3474.  
  3475. Note that ¤t is evaluated within the coexpression; it is not
  3476. &main and you might think at first.
  3477.  
  3478.   Ken Walker / Computer Science Dept / Univ of Arizona / Tucson, AZ 85721
  3479.   +1 602 621-4252  kwalker@cs.arizona.edu {uunet|allegra|noao}!arizona!kwalker
  3480.  
  3481. From ksr!ksr.com!tim@uunet.uu.net  Wed Aug  7 20:18:09 1991
  3482. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Wed, 7 Aug 91 20:18:09 MST
  3483. Received: from relay2.UU.NET by optima.cs.arizona.edu (4.1/15)
  3484.     id AA03775; Wed, 7 Aug 91 01:26:12 MST
  3485. Received: from uunet.uu.net (via LOCALHOST.UU.NET) by relay2.UU.NET with SMTP 
  3486.     (5.61/UUNET-internet-primary) id AA24815; Wed, 7 Aug 91 04:26:09 -0400
  3487. Received: from ksr.UUCP by uunet.uu.net with UUCP/RMAIL
  3488.     (queueing-rmail) id 042508.20773; Wed, 7 Aug 1991 04:25:08 EDT
  3489. Received: from kaos.ksr.com by ksr.com (4.0/SMI-3.2)
  3490.     id AA03514; Wed, 7 Aug 91 04:06:46 EDT
  3491. Received: by kaos.ksr.com (4.0/SMI-3.2)
  3492.     id AA25327; Wed, 7 Aug 91 04:06:44 EDT
  3493. Message-Id: <9108070806.AA25327@kaos.ksr.com>
  3494. To: kwalker@cs.arizona.edu
  3495. Subject: Re: Coexp memory leak in Icon
  3496. Cc: icon-group@cs.arizona.edu
  3497. Date: Wed, 07 Aug 91 04:06:42 -0400
  3498. From: Tim Peters <tim@ksr.com>
  3499.  
  3500. Ken, many thanks for taking the time to explain the Deeper Mysteries!
  3501. Everything makes sense so far, but I think I must still be missing a key
  3502. piece of the puzzle.  A few E-Mail msgs suggested that others are
  3503. finding this educational too, so I'm keeping "the group" on the
  3504. distribution list -- but if more people find this public flaunting of my
  3505. ignorance just irritating, please let me know & I'll take it offline and
  3506. summarize later.
  3507.  
  3508. Easy one first:
  3509.  
  3510. >  > [me]
  3511. >  > 4) The real baffler (considered along with variations #1 and #2):  The
  3512. >  >    memory leak also goes away if the "create" is changed to
  3513. >  >        coexp := create inner(¤t)
  3514. >  >    and "inner" is changed to
  3515. >  >        procedure inner( source )
  3516. >  >           vertex() @ source
  3517. >  >        end
  3518. >  [ken]
  3519. >  Note that ¤t is evaluated within the coexpression; it is not
  3520. >  &main [as] you might think at first.
  3521.  
  3522. I stand gratefully corrected.  Changing the "create" to (e.g.)
  3523.     me := ¤t; coexp := create inner( me )
  3524. does what I mistakenly thought the above would do, and suffers the same
  3525. "memory leak" as the #1 and #2 variations.  So the behavior is
  3526. consistent after all.  Thanks!
  3527.  
  3528.  
  3529. Next the explanation (& please hit me if I botch the paraphrase at the
  3530. start -- I'm paraphrasing it precisely so that if I do misunderstand it,
  3531. that will be obvious early on):
  3532.  
  3533. > [Ken explains that each coexp maintains a stack of its activators, so
  3534. >  that in the test program the "vertex @ &source" line (which activates
  3535. >  &main) causes each of the many "coexp" coexps to be placed on &main's
  3536. >  stack-of-activators; & because they *are* on that stack, garbage
  3537. >  collection can't reclaim them.
  3538. >  Ken continues ...
  3539. > ]
  3540. >  In this example, &main is repeatedly activated by different
  3541. >  co-expressions. It keeps all of them on its activation stack, even
  3542. >  when they can be reached no other way. (This is maybe a little bogus
  3543. >  as &main can never fall off the end, but this same thing can be
  3544. >  happen in another co-expression, so it is a real problem.)
  3545.  
  3546. Two things:
  3547.  
  3548. 1) It's certainly tempting to suggest that &main's stack-of-activators
  3549.    be ignored (as a special case) in the marking phase, but I can see
  3550.    that it's a more general problem.  A twist on that coming later.
  3551.  
  3552. 2) That explained the behavior of the most-recent version of "the test
  3553.    case".  But in trying to exploit that knowledge, I keep hitting
  3554.    snags.  E.g.,
  3555.  
  3556. global drive, coexp
  3557.  
  3558. procedure main()
  3559.    coexp := create ("OK" @ &source)
  3560.    drive := create @coexp
  3561.    write( @drive | "failed?" )
  3562.    collect()
  3563. end
  3564.  
  3565.    That prints "failed?".  I expected "OK", but I think I know why it's
  3566.    happening (basically that "drive" returns to "coexp" instead of to
  3567.    &main -- drive's original "fall off the end" return point is altered
  3568.    *by* the "@ &source" in coexp -- a real head-twister!).
  3569.  
  3570.    I can live with that, but then it *always* crashes with a system "Bus
  3571.    error" msg (which goes away if the "collect()" is removed).
  3572.  
  3573.    Of course this was part of an attempt to fill a throw-away coexp's
  3574.    ("drive"'s) stack-of-activators with "coexp" (instead of filling
  3575.    &main's stack).  Not having much luck getting that to work, though.
  3576.  
  3577. >  I don't know of any fix to the general problem. There have been long
  3578. >  and complicated debates about the correct behavior of co-expressions
  3579. >  when recursive activations and "ruturns" are done; maybe some other
  3580. >  semantics would allow us to do away with the stack.
  3581.  
  3582. The semantics are sure subtler than I thought, but I don't have a
  3583. problem with that.  One of the things I admire about Icon (& SNOBOL4
  3584. before it ...) is the willingness to *try* grand new ideas, even when
  3585. all the implications are known to be unknown <grin> in advance.  And I
  3586. think the Icon Project has a remarkable track record for doing "almost
  3587. everything just right" amidst such uncertainties.
  3588.  
  3589. But *offhand* (I'm completely ignorant of Icon's implementation), and
  3590. stipulating that Icon's coexp semantics are reasonable (although the
  3591. test case above has me wondering <grin>), perhaps the current
  3592. *implementation* of those semantics could be optimized in some safe
  3593. ways.  E.g., suppose some coexp C fails.  As I understand it, in the
  3594. current implementation C's stack of activators stays around.  But it's
  3595. useless -- because, since C *has* failed, any future activation must
  3596. immediately return failure to the direct activator.
  3597.  
  3598. Closer to home <grin>, suppose coexp A activates coexp B, B re-activates
  3599. A, A re-activates B (& carry this on more levels if you like; I think I
  3600. *need* this many, though), and then B fails.  E.g., if A === &main, and
  3601. B === coexp, we pretty much have my test case.  B can never be junked so
  3602. long as A is alive, because B is on A's stack of activators.  But
  3603. there's something fishy about this:  namely that B *did* fail, so
  3604. although the entire range of its future behavior can be modeled by a
  3605. simple "repeat &fail", all the space it occupies, and (I presume) all
  3606. the space occupied by all the coexps on *its* stack of activators (& so
  3607. on), sticks around uselessly.  The irksome thing about my test case is
  3608. that the huge amount of memory that stuck around was in support of
  3609. coexps that couldn't possibly do anything but fail even if they *were*
  3610. reachable -- happy to lose a couple hundred bytes to that, but not a
  3611. couple dozen meg <grin>.
  3612.  
  3613. I'm think I'm groping-- in both of those --at saying that "coexp
  3614. failure" has massive (& known!) effects on that coexp's future prospects
  3615. in life <grin>, and that the implementation could take better advantage
  3616. of this drastic change in its status.  Once a coexp has failed, it's not
  3617. "really" a coexp any more (via any observable behavior), so perhaps the
  3618. implementation could strip it of all the coexp overhead at the time it
  3619. first does fail?  It's "just" an optimization, of course, and I don't
  3620. know how widely useful it would be -- but it would help the stuff I've
  3621. been doing lately <grin>.
  3622.  
  3623. >  As for your specific problem, can you set up a dyamically created
  3624. >  co-expression, have the value passed directly to it,then have
  3625. >  it "return" the value to the main co-expression by falling off the
  3626. >  end? In this way, &main has no references to the intermediate
  3627. >  co-expression and garbage collection can dispose of it and the
  3628. >  the co-expression that does the real work? I have to admit that
  3629. >  this is a rather gross solution, but I think it will work.
  3630.  
  3631. Sorry, but this was the one paragraph I didn't think I could follow.  An
  3632. example would sure help.  As the other little test case above showed, I
  3633. think I'm missing something basic here.
  3634.  
  3635. >  ...
  3636. >  I think the optimizing compiler should be able to dynamically collapse
  3637. >  the suspend chain and eliminate the performance hit of suspending
  3638. >  through all those recurse calls (somewhat similar to the "tail recursion"
  3639. >  optimization done for Lisp). It will take some thought to work through
  3640. >  the details.
  3641.  
  3642. Fascinating idea, Ken!  I'm a compiler jockey by trade, and for what
  3643. it's worth I suspect you're right about this.  Bet you're having fun
  3644. with the compiler -- when it's not driving you crazy <smile> ...
  3645.  
  3646. takes-one-to-know-one-ly y'rs  - tim
  3647.  
  3648. Tim Peters   Kendall Square Research Corp
  3649. tim@ksr.com,         ksr!tim@uunet.uu.net
  3650.  
  3651.  
  3652. ps:  this collect()-free variation of the test case above gets a "Bus
  3653.      error" crash every time, apparently at the "@drive" line:
  3654.  
  3655. global drive, coexp
  3656.  
  3657. procedure main()
  3658.    coexp := create ("OK" @ &source)
  3659.    drive := create |@coexp
  3660.    @drive
  3661. end
  3662.  
  3663. From TELLEFSENGW@HIRAMB.BITNET  Wed Aug  7 20:20:18 1991
  3664. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Wed, 7 Aug 91 20:20:18 MST
  3665. Received: from Arizona.edu (Hopey.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  3666.     id AA02157; Tue, 6 Aug 91 11:26:22 MST
  3667. Received: from HIRAMB (TELLEFSE@HIRAMB) by Arizona.edu with PMDF#10282; Tue, 6
  3668.  Aug 1991 11:26 MST
  3669. Date: Tue, 6 Aug 1991 14:25 EST
  3670. From: TELLEFSENGW@HIRAMB.BITNET
  3671. Subject: Automatic seeding for &random
  3672. To: icon-group@cs.arizona.edu
  3673. Message-Id: <81EB4403E0E0153D@HIRAMB>
  3674. X-Envelope-To: icon-group@cs.arizona.edu
  3675. X-Vms-To: IN%"icon-group@cs.arizona.edu"
  3676.  
  3677.         I'm new to Icon, so you may all have seen a procedure like this
  3678. before, but I thought I'd take a chance and send it to you all.
  3679.  
  3680.         This is a little procedure that will set the random seed, &random,
  3681. to a different value each time you run a program. It is based on the clock, and
  3682. will only repeat seed values once per decade (and then only if you run your
  3683. program at the exact same second you did a decade ago). To use it, just put
  3684. "randomize()" at the beginning of the procedure "main." You might want to put
  3685. in a "write(&random)" so you can record the seed in case it produces
  3686. interesting results.
  3687.  
  3688.         If anyone can suggest improvements or possible problems, let me know...
  3689. it seemed to work fine on my Amiga.
  3690.  
  3691. procedure randomize()
  3692.         source:=map("defghijklmn", "abcd/ef/ghij:kl:mn",
  3693.                 &date || &clock)
  3694.         source ? {
  3695.                 &random:= (move(1) * 32140800 +
  3696.                         (move(2) - 1) * 2678400 +
  3697.                         (move(2) - 1) * 86400 +
  3698.                         move(2) * 3600 +
  3699.                         move(2) * 60 +
  3700.                         move(2))
  3701.                 }
  3702.         end
  3703.  
  3704.                                                 Guy Tellefsen
  3705.                                                 TELLEFSENGW@HIRAMB
  3706.  
  3707. From icon-group-request@arizona.edu  Wed Aug  7 20:21:51 1991
  3708. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Wed, 7 Aug 91 20:21:51 MST
  3709. Resent-From: icon-group-request@arizona.edu
  3710. Received: from Arizona.edu (Merlin.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  3711.     id AA25339; Tue, 6 Aug 91 09:33:25 MST
  3712. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Tue, 6 Aug
  3713.  1991 09:32 MST
  3714. Received: by ucbvax.berkeley.edu (5.63/1.42) id AA14111; Tue, 6 Aug 91 09:25:23
  3715.  -0700
  3716. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  3717.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  3718.  usenet@ucbvax.Berkeley.EDU if you have questions)
  3719. Resent-Date: Tue, 6 Aug 1991 09:33 MST
  3720. Date: 6 Aug 91 15:06:10 GMT
  3721. From: mcsun!cernvax!chx400!bernina!neptune!inf.ethz.ch!santas@uunet.uu.net
  3722.  (Filippos Santas)
  3723. Subject: RE: comparing one file to another
  3724. Sender: icon-group-request@arizona.edu
  3725. Resent-To: icon-group@cs.arizona.edu
  3726. To: icon-group@arizona.edu
  3727. Resent-Message-Id: <590D753462201891@Arizona.edu>
  3728. Message-Id: <30358@neptune.inf.ethz.ch>
  3729. X-Envelope-To: icon-group@CS.Arizona.EDU
  3730. X-Vms-To: icon-group@Arizona.edu
  3731. Organization: Departement Informatik, ETH, Zurich
  3732. References: <23.Jul.91..16:46:50.bst..060328@EMAS-A>
  3733.  
  3734.  
  3735. This a test.
  3736. Please ignore!
  3737.  
  3738. From sbw@turing.cse.nau.edu  Wed Aug  7 20:21:57 1991
  3739. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Wed, 7 Aug 91 20:21:57 MST
  3740. Received: from turing.cse.nau.edu by optima.cs.arizona.edu (4.1/15)
  3741.     id AA24564; Tue, 6 Aug 91 09:16:18 MST
  3742. Received: by turing.cse.nau.edu (5.64/1.5-nau)
  3743.     id AA08816; Tue, 6 Aug 91 09:11:35 -0700
  3744. Message-Id: <9108061611.AA08816@turing.cse.nau.edu>
  3745. From: sbw@turing.cse.nau.edu (Steve Wampler)
  3746. Date: Tue, 6 Aug 1991 09:11:34 MST
  3747. In-Reply-To: Tim Peters's mail message of Aug  5, 23:42.
  3748. X-Mailer: Mail User's Shell (7.2.0 10/31/90)
  3749. To: icon-group@cs.arizona.edu
  3750. Subject: RE: Coexp memory leak in Icon
  3751.  
  3752. On Aug 5 at 23:42, Tim Peters writes:
  3753. } 4) The real baffler (considered along with variations #1 and #2):  The
  3754. }    memory leak also goes away if the "create" is changed to
  3755. }        coexp := create inner(¤t)
  3756. }    and "inner" is changed to
  3757. }     procedure inner( source )
  3758. }        vertex() @ source
  3759. }     end
  3760. } Far as I know, variation #4 "should be" semantically equivalent in every
  3761. } respect to variation #1, so why the latter leaks while the former
  3762. } doesn't is beyond me.  Seems to be triggered specifically by using the
  3763. } keywords "&source" or "&main" as explicit targets of a coexp switch ...
  3764. } but that's too odd to believe <grin>.
  3765.  
  3766. Time: Someone up on the current implementation of coexpressions will
  3767.     likely correct this, but here's a rough description of
  3768.     what is *most likely going on*:
  3769.  
  3770.     ¤t is the current co-expression (i.e. apointer to
  3771.     itself..)  So, it doesn't contribute to any chains of
  3772.     coexpressions.
  3773.  
  3774.     &source is a reference to the *previously* activated
  3775.     coexpression (a link back to it).
  3776.  
  3777.     Now the fun stuff:  Guess what happens when you activate @source?
  3778.     The coexpression you go to has &source set to point *back* to
  3779.     the coexpression you just left.  This begins to build up a stack
  3780.     of coexpressions (I *think* this stack is the chain of coexpressions
  3781.     causing the problem - but there are some details I've forgotten
  3782.     now...)  Similary, activating &main sets &source in &main to point
  3783.     back to the just exitted co-expression.
  3784.  
  3785.     Hoep this helps.
  3786.  
  3787.     (sorry for the typos I have about a 40 character typeahed on
  3788.     this connection!)
  3789.  
  3790. -- 
  3791.     Steve Wampler
  3792.     {....!arizona!naucse!sbw}
  3793.     {sbw@turing.cse.nau.edu}
  3794.  
  3795. From icon-group-request@arizona.edu  Thu Aug  8 09:08:02 1991
  3796. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Thu, 8 Aug 91 09:08:02 MST
  3797. Resent-From: icon-group-request@arizona.edu
  3798. Received: from Arizona.edu (Merlin.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  3799.     id AA02471; Thu, 8 Aug 91 09:08:00 MST
  3800. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Thu, 8 Aug
  3801.  1991 09:07 MST
  3802. Received: by ucbvax.berkeley.edu (5.63/1.42) id AA06570; Thu, 8 Aug 91 08:56:51
  3803.  -0700
  3804. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  3805.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  3806.  usenet@ucbvax.Berkeley.EDU if you have questions)
  3807. Resent-Date: Thu, 8 Aug 1991 09:07 MST
  3808. Date: 8 Aug 91 15:05:39 GMT
  3809. From: midway!quads.uchicago.edu!goer@uunet.uu.net (Richard L. Goerwitz)
  3810. Subject: RE: Automatic seeding for &random
  3811. Sender: icon-group-request@arizona.edu
  3812. Resent-To: icon-group@cs.arizona.edu
  3813. To: icon-group@arizona.edu
  3814. Resent-Message-Id: <E7D4885BBCC00213@Arizona.edu>
  3815. Message-Id: <1991Aug8.150539.1668@midway.uchicago.edu>
  3816. X-Envelope-To: icon-group@CS.Arizona.EDU
  3817. X-Vms-To: icon-group@Arizona.edu
  3818. Organization: University of Chicago
  3819. References: <81EB4403E0E0153D@HIRAMB>
  3820.  
  3821. In article <81EB4403E0E0153D@HIRAMB> TELLEFSENGW@HIRAMB.BITNET writes:
  3822. >
  3823. >        I'm new to Icon, so you may all have seen a procedure like this
  3824. >before, but I thought I'd take a chance and send it to you all.
  3825. >procedure randomize()
  3826. >        source:=map("defghijklmn", "abcd/ef/ghij:kl:mn",
  3827. >                &date || &clock)
  3828. >        source ? {
  3829. >                &random:= (move(1) * 32140800 +
  3830. >                        (move(2) - 1) * 2678400 +
  3831. >                        (move(2) - 1) * 86400 +
  3832. >                        move(2) * 3600 +
  3833. >                        move(2) * 60 +
  3834. >                        move(2))
  3835. >                }
  3836. >        end
  3837.  
  3838. It's great to see people post useful code like this.  There's actually a
  3839. procedure in the Icon Program Library that does the same thing (written
  3840. by Bob Alexander).  Not to say that his is better (though it is quite a
  3841. bit shorter).  I just like to point out that the IPL exists, and provides
  3842. a lot of really useful material (my favorite right now is codeobj.icn, 
  3843. followed closely by ximage.icn).
  3844.  
  3845. -- 
  3846.  
  3847.    -Richard L. Goerwitz              goer%sophist@uchicago.bitnet
  3848.    goer@sophist.uchicago.edu         rutgers!oddjob!gide!sophist!goer
  3849.  
  3850. From icon-group-request@arizona.edu  Thu Aug  8 15:23:35 1991
  3851. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Thu, 8 Aug 91 15:23:35 MST
  3852. Resent-From: icon-group-request@arizona.edu
  3853. Received: from Arizona.edu (Merlin.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  3854.     id AA23294; Thu, 8 Aug 91 15:23:32 MST
  3855. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Thu, 8 Aug
  3856.  1991 15:22 MST
  3857. Received: by ucbvax.berkeley.edu (5.63/1.42) id AA20140; Thu, 8 Aug 91 15:15:18
  3858.  -0700
  3859. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  3860.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  3861.  usenet@ucbvax.Berkeley.EDU if you have questions)
  3862. Resent-Date: Thu, 8 Aug 1991 15:23 MST
  3863. Date: 8 Aug 91 21:00:42 GMT
  3864. From: midway!quads.uchicago.edu!goer@mimsy.umd.edu (Richard L. Goerwitz)
  3865. Subject: Bible reference program
  3866. Sender: icon-group-request@arizona.edu
  3867. Resent-To: icon-group@cs.arizona.edu
  3868. To: icon-group@arizona.edu
  3869. Resent-Message-Id: <1C4C9F2A66A004C2@Arizona.edu>
  3870. Message-Id: <1991Aug8.210042.13539@midway.uchicago.edu>
  3871. X-Envelope-To: icon-group@CS.Arizona.EDU
  3872. X-Vms-To: icon-group@Arizona.edu
  3873. Organization: University of Chicago
  3874.  
  3875. Once again, I'd like to post a tidbit on bibleref - the Bible study
  3876. aid I have mentioned several times.  There's a new version now, with
  3877. pre-indexed files and with the KJV included, on cs.arizona.edu.  The
  3878. Icon Project kindly consented to let me occupy a whopping 2 or 3
  3879. meg chunk of space in icon/contrib/bibleref.tar.Z.
  3880.  
  3881. This version should install in minutes, assuming that the Icon run-
  3882. time system and Icon Program Library on your system are current.
  3883.  
  3884. No restrictions of any kind (shareware licenses, copyrights, etc.)
  3885. come with the package.
  3886.  
  3887. -- 
  3888.  
  3889.    -Richard L. Goerwitz              goer%sophist@uchicago.bitnet
  3890.    goer@sophist.uchicago.edu         rutgers!oddjob!gide!sophist!goer
  3891.  
  3892. From ksr!ksr.com!tim@uunet.uu.net  Thu Aug  8 21:58:23 1991
  3893. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Thu, 8 Aug 91 21:58:23 MST
  3894. Received: from relay1.UU.NET by optima.cs.arizona.edu (4.1/15)
  3895.     id AA05747; Thu, 8 Aug 91 21:58:19 MST
  3896. Received: from uunet.uu.net (via LOCALHOST.UU.NET) by relay1.UU.NET with SMTP 
  3897.     (5.61/UUNET-internet-primary) id AA10022; Fri, 9 Aug 91 00:58:16 -0400
  3898. Received: from ksr.UUCP by uunet.uu.net with UUCP/RMAIL
  3899.     (queueing-rmail) id 005717.10532; Fri, 9 Aug 1991 00:57:17 EDT
  3900. Received: from kaos.ksr.com by ksr.com (4.0/SMI-3.2)
  3901.     id AA24801; Fri, 9 Aug 91 00:26:27 EDT
  3902. Received: by kaos.ksr.com (4.0/SMI-3.2)
  3903.     id AA21189; Fri, 9 Aug 91 00:26:26 EDT
  3904. Message-Id: <9108090426.AA21189@kaos.ksr.com>
  3905. To: icon-group@cs.arizona.edu
  3906. Subject: Summary, re:  Coexp memory leak in Icon
  3907. Date: Fri, 09 Aug 91 00:26:25 -0400
  3908. From: Tim Peters <tim@ksr.com>
  3909.  
  3910. Many thanks to Richard Goerwitz, Paul Moore, Steve Wampler and Ken
  3911. Walker for their help and explanations!  Summary follows; any errors are
  3912. solely mine:
  3913.  
  3914. First problem:  Had a "dag traversal" program, along the lines of
  3915.  
  3916.    record thing( info, subthing1, subthing2, ..., mark )
  3917.  
  3918.    every info := recurse( thing ).info do ...
  3919.  
  3920.    procedure recurse( thing )
  3921.       thing.mark := 1 - thing.mark
  3922.       if (\thing.subthing1).mark ~= thing.mark then
  3923.          suspend recurse( thing.subthing1 )
  3924.       if (\thing.subthing2).mark ~= thing.mark then
  3925.          suspend recurse( thing.subthing2 )
  3926.       ...
  3927.       suspend thing
  3928.    end
  3929.  
  3930. (Visiting the nodes of a graph in postorder; "mark" is a "have I been
  3931. seen yet?" flag that cycles between all 0's and all 1's from one
  3932. traversal to the next)
  3933.  
  3934. This actually works fine.  The only "problem" was that when the graphs
  3935. were very "deep", the recursion was very deep, so lots of time was
  3936. burned just suspending our way up long chains of nested invocations to
  3937. get back to the "every" (and resuming our way back down the long chains
  3938. to get back to the next piece of real work within "recurse").
  3939.  
  3940. It occurred to me (a little knowledge *is* a dangerous thing <grin>)
  3941. that co-expressions could be used to avoid this overhead, along the
  3942. lines of:
  3943.  
  3944.  
  3945.    coexp := create recurse( thing )
  3946.    while info := (@coexp).info do ...
  3947.  
  3948.    procedure recurse( thing )
  3949.       thing.mark := 1 - thing.mark
  3950.       if (\thing.subthing1).mark ~= thing.mark then
  3951.          recurse( thing.subthing1 )
  3952.       if (\thing.subthing2).mark ~= thing.mark then
  3953.          recurse( thing.subthing2 )
  3954.       ...
  3955.       thing @ &source
  3956.    end
  3957.  
  3958. Idea being that this way "recurse" sends each value *directly* back to
  3959. the "while".  This works fine too, and did save significant time in my
  3960. particular application.  But ...
  3961.  
  3962. Second problem:  When run for a long time, enormous slowdowns occurred,
  3963. and memory use routinely exceeded a dozen megabytes (despite having only
  3964. a few hundred K of "real data").  Turns out that was due to old co-
  3965. expression space never being reclaimed.
  3966.  
  3967. Cause #1:  This appears to be widely known, and was actually an artifact
  3968. in the first test case I posted (it wasn't actually happening in my
  3969. "real" program).  When a coexp is created into a dynamic local variable
  3970. in a loop:
  3971.  
  3972.     local c
  3973.     while ... do {
  3974.        c := create something
  3975.        ...
  3976.     }
  3977.  
  3978. the "old" co-expressions don't get reclaimed.  The reason is that a
  3979. coexp gets a copy of the dynamic local variables, so each time around
  3980. the "old" value of c (c is a dynamic local variable!) gets copied into
  3981. the new value of c, so each coexp is linked to the preceding one, so
  3982. garbage collection thinks they're all potentially active.  Indeed, the
  3983. elegant little "primes" generator I posted a few days back *relied* on
  3984. this behavior.  In *most* applications I bet "the old" value is in fact
  3985. unreachable, but Icon cannot in general know that.
  3986.  
  3987. Workarounds:  Take "c" out of the "dynamic local variable" class.  E.g.,
  3988. make it a static local, or (in my judgement, better) make it global, or
  3989. (IMJ, best) assign a non-coexp value to it right before the "create".
  3990. E.g.,
  3991.  
  3992.     c := &null   # so new coexp doesn't have a pointer to old coexp
  3993.     c := create something
  3994.  
  3995. Prospects:  Didn't hear that anyone has plans to "fix this", but of
  3996. course it's really not "a bug".  I'm in the optimizing compiler biz, so
  3997. naturally I think a lot could be done to avoid the problem in "the
  3998. usual" cases, but the general case is clearly intractable (e.g., the
  3999. "create" expression might contain "@variable(read())" -- you really
  4000. can't tell for sure whether the "old" coexp *might* be referenced inside
  4001. the new one, but given the right kind of analysis I bet you "almost
  4002. always" could ...).
  4003.  
  4004. Cause #2:  This one appears to be less widely known, a bit harder to
  4005. understand, and apparently much harder to work around.  Turns out that,
  4006. in order to support arbitrary patterns of invocation as co-routines,
  4007. each Icon co-expression maintains a full-blown stack of all the co-
  4008. expressions that have activated it.  If garbage collection thinks a
  4009. particular co-expression C is potentially live, it also thinks all the
  4010. co-expressions on C's stack-of-activators are potentially live.  So when
  4011. my rewritten program does
  4012.  
  4013.     thing @ &source
  4014.  
  4015. it puts the traversal co-expression ("coexp" in the driver) on &source's
  4016. stack of activators, &source happened to be &main, and &main never
  4017. popped anything off its stack-of-activators.  Therefore, each time I
  4018. created a new "coexp" traversal co-exp (& I did a lot of that!), it
  4019. wound up on &main's stack-of-activators and never got off -- hence all
  4020. of the traversal co-exp's were considered potentially live forever
  4021. after.
  4022.  
  4023. Workarounds:  Haven't found one!  It's overwhelmingly tempting to put a
  4024. co-exp "between" &main and "coexp", so that the "thing @ &source" inside
  4025. "recurse" returns its answers to the intermediate co-exp (and so fills
  4026. up *its* stack-of-activators, which can presumably be thrown away by
  4027. throwing away the intermediate co-exp itself).  However, the difficulty
  4028. appears to be in convincing the intermediate co-exp to return its result
  4029. to &main:  the "thing @ &source" (=== "thing @ intermediate_co-exp")
  4030. doesn't just cause "thing" to be transmitted to &source, it also tells
  4031. &source to deliver its next result (whether via "return" or "suspend" or
  4032. "falling off the end") straight back to the "thing @ &source" line.  In
  4033. a sense, the problem is that I'm trying to use transmission as a goto or
  4034. return, but Icon is treating it as a call.
  4035.  
  4036. The following scheme "works" so long as we know recurse's result
  4037. sequence is finite:
  4038.  
  4039.    global answers
  4040.  
  4041.    intermediate := drive( thing )
  4042.    @intermediate
  4043.    every info := (!answers).info do ...
  4044.  
  4045.    procedure drive( thing )
  4046.       local coexp
  4047.       answers := []
  4048.       coexp := create recurse( thing )
  4049.       while put( answers, @coexp )
  4050.    end
  4051.  
  4052.    procedure recurse # exactly as above
  4053.  
  4054. It "works" in the sense that it gets the right results, and all the
  4055. coexp memory gets reclaimed, but before you think it's "the answer" (or
  4056. even "an answer" <grin>), do a trace of the control flow:  "intermediate"
  4057. and "coexp" take turns "falling off the end" to each other a number of
  4058. times proportional to the number of results produced (or something like
  4059. that -- not sure that's exactly right).
  4060.  
  4061. Prospects:  "Returns" from co-expressions are very involved (as reflected
  4062. in the involved stack-of-activators implementation), and it's not clear
  4063. (to me, since the Icon book doesn't really address it) *exactly* what
  4064. semantics were intended.  In any case, seems like there's room for
  4065. significant optimizations in the most-common cases, but the issues are
  4066. clearly subtle enough that out-thinking it would be A Project.  In the
  4067. meantime, this particular use for (abuse of?) co-expressions should be
  4068. avoided.
  4069.  
  4070.  
  4071. Epilogue:  I actually rewrote "the real" program to get rid of the
  4072. co-exps (and the recursion) anyway, so I no longer have a practical
  4073. problem here.  Exploring the co-exp approach was great fun, though, and
  4074. thanks again to all for the invaluable help ...
  4075.  
  4076. back-to-the-shadows-ly y'rs  - tim
  4077.  
  4078. Tim Peters   Kendall Square Research Corp
  4079. tim@ksr.com,         ksr!tim@uunet.uu.net
  4080.  
  4081. From ksr!ksr.com!tim@uunet.uu.net  Thu Aug  8 22:10:12 1991
  4082. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Thu, 8 Aug 91 22:10:12 MST
  4083. Received: from relay1.UU.NET by optima.cs.arizona.edu (4.1/15)
  4084.     id AA06151; Thu, 8 Aug 91 22:10:09 MST
  4085. Received: from uunet.uu.net (via LOCALHOST.UU.NET) by relay1.UU.NET with SMTP 
  4086.     (5.61/UUNET-internet-primary) id AA11565; Fri, 9 Aug 91 01:10:06 -0400
  4087. Received: from ksr.UUCP by uunet.uu.net with UUCP/RMAIL
  4088.     (queueing-rmail) id 010952.12572; Fri, 9 Aug 1991 01:09:52 EDT
  4089. Received: from kaos.ksr.com by ksr.com (4.0/SMI-3.2)
  4090.     id AA25472; Fri, 9 Aug 91 01:08:16 EDT
  4091. Received: by kaos.ksr.com (4.0/SMI-3.2)
  4092.     id AA21750; Fri, 9 Aug 91 01:08:13 EDT
  4093. Message-Id: <9108090508.AA21750@kaos.ksr.com>
  4094. To: icon-group@cs.arizona.edu
  4095. Subject: Correction to Re: Summary, re:  Coexp memory leak in Icon
  4096. Date: Fri, 09 Aug 91 01:08:13 -0400
  4097. From: Tim Peters <tim@ksr.com>
  4098.  
  4099. >  [me]
  4100. >  ...
  4101. >  The following scheme "works" so long as we know recurse's result
  4102. >  sequence is finite:
  4103. >
  4104. >     global answers
  4105. >
  4106. >     intermediate := drive( thing )
  4107. >     @intermediate
  4108. >     every info := (!answers).info do ...
  4109. >  ...
  4110.  
  4111. Sorry, that should have been
  4112.  
  4113.         intermediate := create drive( thing )
  4114.                         ^^^^^^
  4115.  
  4116. darned-mailer-errors<grin>-ly y'rs  - tim
  4117.  
  4118. Tim Peters   Kendall Square Research Corp
  4119. tim@ksr.com,         ksr!tim@uunet.uu.net
  4120.  
  4121. From LSADENIEMI@cc.helsinki.fi  Wed Aug 14 01:11:21 1991
  4122. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Wed, 14 Aug 91 01:11:21 MST
  4123. Received: from cc.Helsinki.FI (hylka.Helsinki.FI) by optima.cs.arizona.edu (4.1/15)
  4124.     id AA05964; Wed, 14 Aug 91 01:11:11 MST
  4125. Date: Wed, 14 Aug 1991 11:12 EET
  4126. From: LEENA SADENIEMI HYLK <LSADENIEMI@cc.helsinki.fi>
  4127. Subject: Icon Version 8 for VMS
  4128. To: icon-group@cs.arizona.edu, LSADENIE@kruuna.helsinki.fi
  4129. Message-Id: <B051EE544028AE45@hylk.Helsinki.FI>
  4130. X-Envelope-To: icon-group@cs.arizona.edu
  4131. X-Vms-To: IN%"icon-group@cs.arizona.edu"
  4132. X-Vms-Cc: LSADENIEMI
  4133.  
  4134. Icon group,
  4135.  
  4136. I sent an order form for Icon version 8 for VMS for the Computer Center
  4137. of Helsinki Unversity last May and I got back my order form and a 
  4138. description of the contents of the installation tape. The date of the
  4139. letter was May 30, 1991. The only problem is that a have not recieved
  4140. a tape at all. I have tried to find it here but without results. So, it
  4141. seems that I need another tape - or perhaps detailed advice how to
  4142. get all I need via FTP, in which directories the VMS files are.
  4143.  
  4144.                     Yours
  4145.                     Leena Sadeniemi
  4146.                     Computer Centre
  4147.                     of Helsinki University
  4148.                     Teollisuuskatu 23
  4149.                     005100 Helsinki
  4150.                     Finland
  4151.                     
  4152.  
  4153.  
  4154. From R.J.Hare@edinburgh.ac.uk  Wed Aug 14 07:47:41 1991
  4155. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Wed, 14 Aug 91 07:47:41 MST
  4156. Received: from Arizona.edu (Merlin.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  4157.     id AA16949; Wed, 14 Aug 91 07:47:11 MST
  4158. Received: from UKACRL.BITNET (MAILER@UKACRL) by Arizona.edu with PMDF#10282;
  4159.  Wed, 14 Aug 1991 07:46 MST
  4160. Received: from RL.IB by UKACRL.BITNET (Mailer R2.07) with BSMTP id 0597; Wed,
  4161.  14 Aug 91 15:46:44 BST
  4162. Received: from RL.IB by UK.AC.RL.IB (Mailer R2.07) with BSMTP id 2536; Wed, 14
  4163.  Aug 91 15:45:50 BST
  4164. Date: 14 Aug 91  15:44:14 bst
  4165. From: R.J.Hare@edinburgh.ac.uk
  4166. Subject: Document formatting programs
  4167. To: icon-group@cs.arizona.edu
  4168. Message-Id: <14 Aug 91  15:44:14 bst  060387@EMAS-A>
  4169. X-Envelope-To: icon-group@cs.arizona.edu
  4170. Via:        UK.AC.ED.EMAS-A; 14 AUG 91 15:44:25 BST
  4171.  
  4172.  
  4173. Some time ago, somone said they would put a simple (?) Icon text formatting
  4174. program up on this board. I don't remember it ever appearing - is there any
  4175. chance of the author re-posting the code, in case I missed it?
  4176.  
  4177. Also, is anyone aware of any translation programs written in Icon?
  4178.  
  4179. Thanks.
  4180.  
  4181. Roger Hare.
  4182.  
  4183. From icon-group-request@arizona.edu  Fri Aug 16 16:21:40 1991
  4184. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Fri, 16 Aug 91 16:21:40 MST
  4185. Resent-From: icon-group-request@arizona.edu
  4186. Received: from Arizona.edu (Merlin.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  4187.     id AA03392; Fri, 16 Aug 91 16:21:37 MST
  4188. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Fri, 16 Aug
  4189.  1991 16:21 MST
  4190. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA15820; Fri, 16 Aug 91
  4191.  16:02:58 -0700
  4192. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  4193.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  4194.  usenet@ucbvax.Berkeley.EDU if you have questions)
  4195. Resent-Date: Fri, 16 Aug 1991 16:21 MST
  4196. Date: 16 Aug 91 22:11:05 GMT
  4197. From: midway!quads.uchicago.edu!goer@handies.ucar.edu (Richard L. Goerwitz)
  4198. Subject: snapshot
  4199. Sender: icon-group-request@arizona.edu
  4200. Resent-To: icon-group@cs.arizona.edu
  4201. To: icon-group@arizona.edu
  4202. Resent-Message-Id: <6DBCC25316A03B16@Arizona.edu>
  4203. Message-Id: <1991Aug16.221105.27902@midway.uchicago.edu>
  4204. X-Envelope-To: icon-group@CS.Arizona.EDU
  4205. X-Vms-To: icon-group@Arizona.edu
  4206. Organization: University of Chicago
  4207.  
  4208. I've posted something like this before.  Could someone who uses the
  4209. IPL routine snapshot() a lot try this out, and see how it works.  I
  4210. have always had trouble with how the supplied procedure only works
  4211. well with lines that don't exceed the width of the terminal or the
  4212. window you're in.  This version is supposed to rectify the problem,
  4213. but like I said, I'd like someone who uses snapshot() a lot try it
  4214. out.
  4215.  
  4216. -Richard
  4217.  
  4218. ============================ latest version ===========================
  4219.  
  4220. ############################################################################
  4221. #
  4222. #    Name:    snapshot.icn
  4223. #
  4224. #    Title:    Show snapshot of Icon string scanning
  4225. #
  4226. #    Author: Ralph E. Griswold and Randal L. Schwartz, modified by
  4227. #       Cheyenne Wills and Richard Goerwitz
  4228. #
  4229. #       Date:    July 19, 1991
  4230. #
  4231. ############################################################################
  4232. #
  4233. #     The procedure snapshot(title,len) writes a snapshot of the state
  4234. #  of string scanning, showing the value of &subject and &pos, an
  4235. #  optional title (arg 1), and (again optionally) wrapping the display
  4236. #  for a terminal of len (arg 2) columns.
  4237. #
  4238. #  For example,
  4239. #
  4240. #     "((a+b)-delta)/(c*d))" ? {
  4241. #     tab(bal('+-/*'))
  4242. #     snapshot("example")
  4243. #     }
  4244. #
  4245. #  produces
  4246. #
  4247. #    ---example---------------------------
  4248. #    |                    |
  4249. #    |                    |
  4250. #    | &subject = "((a+b)-delta)/(c*d))" |
  4251. #    |               |        |
  4252. #    |                        |
  4253. #    -------------------------------------
  4254. #
  4255. #     Note that the bar showing the &pos is positioned under the &posth
  4256. #  character (actual positions are between characters).  If &pos is
  4257. #  at the end of &subject, the bar is positioned under the quotation
  4258. #  mark delimiting the subject. For example,
  4259. #
  4260. #     "abcdefgh" ? (tab(0) & snapshot())
  4261. #
  4262. #  produces
  4263. #
  4264. #    -------------------------
  4265. #    |            |
  4266. #    |            |
  4267. #    | &subject = "abcdefgh" |
  4268. #    |              | |
  4269. #    |            |
  4270. #    -------------------------
  4271. #
  4272. #     Escape sequences are handled properly. For example,
  4273. #
  4274. #     "abc\tdef\nghi" ? (tab(upto('\n')) & snapshot())
  4275. #
  4276. #  produces
  4277. #
  4278. #    ------------------------------
  4279. #    |                 |
  4280. #    |                 |
  4281. #    | &subject = "abc\tdef\nghi" |
  4282. #    |              |      |
  4283. #    |                 |
  4284. #    ------------------------------
  4285. #
  4286. #  The title argument places a title into the top bar, as in
  4287. #
  4288. #    "abc\tdef\nghi" ? (tab(upto('\n')) & snapshot("upto('\n')")
  4289. #
  4290. #  which produces
  4291. #
  4292. #      --upto('\n')-------------------
  4293. #      |                             |
  4294. #      |                             |
  4295. #      | &subject = "abc\tdef\nghi"  |
  4296. #      |                     |       |
  4297. #      |                             |
  4298. #      -------------------------------
  4299. #
  4300. #  The len argument rewraps the display for a screen of len width.
  4301. #
  4302. ############################################################################
  4303.  
  4304.  
  4305. procedure snapshot(title,len)
  4306.  
  4307.    local bar1, bar2, bar3, is, is0, prefix, titlel, placement, POS
  4308.  
  4309.    /title := ""            # no meaningful default
  4310.    \len <:= 20            # any less is really not useful
  4311.    prefix := "&subject = "
  4312.    is := image(&subject)
  4313.    is0 := *image(&subject[1:&pos]) | fail
  4314.  
  4315.    #
  4316.    # Set up top and bottom bars (not exceeding len width, if
  4317.    # len is nonnull).  Fit title into top bar (bar1).
  4318.    #
  4319.    bar1 := bar3 := repl("-", *is + *prefix + 4)[1:\len-4|0]
  4320.    # in *is + *prefix + 4, the 4 is for two vbars/two spaces
  4321.    titlel := (*title > *bar3-4) | *title[1:\len-4|0]
  4322.    bar1 ?:= move(3) || (tab(4+titlel), title) || tab(0)
  4323.  
  4324.    #
  4325.    # Write bar1, then spacers (bar2).  Then write out len-size chunks
  4326.    # of &subject, with the | pointer-line, where appropriate. Finally,
  4327.    # write out bar3 (like bar1, but with no title).
  4328.    #
  4329.    write(bar1)
  4330.    bar2 := "|" || repl(" ", *bar3 - 2) || "|"
  4331.    write(bar2, "\n", bar2)
  4332.    placement := *prefix + is0
  4333.    (prefix || is) ? {
  4334.        until pos(0) do {
  4335.        POS := &pos - 1
  4336.        write("| ", move(*bar3-4) | left(tab(0), *bar3-4), " |")
  4337.        if POS < placement < &pos then {
  4338.            writes("| ")
  4339.            writes(left(repl(" ", placement - POS - 1) || "|", *bar3-4))
  4340.            write(" |\n", bar2)
  4341.        }
  4342.        else write(bar2, "\n", bar2)
  4343.        }
  4344.    }
  4345.    write(bar3)
  4346.    return            # nothing useful to return
  4347.  
  4348. end
  4349. -- 
  4350.  
  4351.    -Richard L. Goerwitz              goer%sophist@uchicago.bitnet
  4352.    goer@sophist.uchicago.edu         rutgers!oddjob!gide!sophist!goer
  4353.  
  4354. From icon-group-request@arizona.edu  Mon Aug 26 23:34:53 1991
  4355. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Mon, 26 Aug 91 23:34:53 MST
  4356. Resent-From: icon-group-request@arizona.edu
  4357. Received: from Arizona.edu (Hopey.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  4358.     id AA22339; Mon, 26 Aug 91 23:34:51 MST
  4359. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Mon, 26 Aug
  4360.  1991 23:34 MST
  4361. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA25592; Mon, 26 Aug 91
  4362.  23:24:32 -0700
  4363. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  4364.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  4365.  usenet@ucbvax.Berkeley.EDU if you have questions)
  4366. Resent-Date: Mon, 26 Aug 1991 23:34 MST
  4367. Date: 27 Aug 91 06:10:17 GMT
  4368. From: usc!cs.utexas.edu!cse!utarlg.uta.edu!b912dieg@apple.com (DOUG WITMER)
  4369. Subject: Machine Translation Program
  4370. Sender: icon-group-request@arizona.edu
  4371. Resent-To: icon-group@cs.arizona.edu
  4372. To: icon-group@arizona.edu
  4373. Resent-Message-Id: <85EC0E989EA05311@Arizona.edu>
  4374. Message-Id: <1991Aug27.041259.14004@cse.uta.edu>
  4375. X-Envelope-To: icon-group@CS.Arizona.EDU
  4376. X-Vms-To: icon-group@Arizona.edu
  4377. Organization: The University of Texas at Arlington
  4378.  
  4379.  
  4380. 08/26/91
  4381.  
  4382. Dear Fellow ICON Enthusiasts:
  4383.  
  4384. I have just placed a pre-release version of my machine translation 
  4385. program in the icon/contrib subdirectory at cs.arizona.edu.  It 
  4386. can be down loaded via anonymous FTP, and then unzipped using the 
  4387. command: pkunzip -d -o -JHSR TRAN1 .  It is my hope that a few of 
  4388. you will down load a copy of the program, and give me your 
  4389. comments on it.  Of particular interest are questions like: 
  4390.  
  4391.   1) Can anything be done more efficiently?
  4392.   2) Can anything be done in a more Iconish manner?
  4393.   3) Have any standards of good programming practice been violated?
  4394.   4) Do you see any obvious flaws or opportunities for improvement?
  4395.  
  4396. Please send any comments to:
  4397.  
  4398. Doug Witmer                    Internet: b912dieg@utarlg.uta.edu
  4399. 1102 Enterprise Drive #149     Bitnet:   b912dieg@utarlg
  4400. Grand Prairie, Texas  75051
  4401.  
  4402. From pbewig@netcom.netcom.com  Tue Aug 27 08:13:33 1991
  4403. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Tue, 27 Aug 91 08:13:33 MST
  4404. Received: from netcomsv.netcom.com by optima.cs.arizona.edu (4.1/15)
  4405.     id AA12177; Tue, 27 Aug 91 08:13:31 MST
  4406. Received: from netcom.netcom.com by netcomsv.netcom.com (4.1/SMI-4.1)
  4407.     id AA25502; Tue, 27 Aug 91 08:12:58 PDT
  4408. Received: by netcom.netcom.com (4.1/SMI-4.1)
  4409.     id AA16740; Tue, 27 Aug 91 08:12:58 PDT
  4410. Date: Tue, 27 Aug 91 08:12:58 PDT
  4411. From: pbewig@netcom.com (Phil Bewig)
  4412. Message-Id: <9108271512.AA16740@netcom.netcom.com>
  4413. X-Mailer: Mail User's Shell (7.2.3 5/22/91)
  4414. To: icon-group@cs.arizona.edu
  4415. Subject: limiting generation
  4416.  
  4417. In a program which I am writing, I have a line
  4418.  
  4419.     while put(items, @getnext) \ maxitems
  4420.  
  4421. which is an attempt to load initial values into a list, up to the
  4422. specified maximum.  However, the program doesn't work the way I
  4423. expect; the maxitems limit is ignored.  I have two questions:
  4424.  
  4425.     1)  Is it correct that the "\" limitation operator only
  4426.         applies to generators?  Is while a control expression,
  4427.         not a generator, so limitation doesn't apply?
  4428.  
  4429.     2)  I solved the problem by rewriting as follows:
  4430.  
  4431.             while put(items, @getnext) do
  4432.                 if *items > maxitems then break
  4433.  
  4434.         Is there a better way?
  4435.  
  4436. Thanks for any help.
  4437.  
  4438. Phil
  4439.  
  4440. From icon-group-request@arizona.edu  Wed Aug 28 05:39:48 1991
  4441. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Wed, 28 Aug 91 05:39:48 MST
  4442. Resent-From: icon-group-request@arizona.edu
  4443. Received: from Arizona.edu (Osprey.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  4444.     id AA10743; Wed, 28 Aug 91 05:39:46 MST
  4445. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Wed, 28 Aug
  4446.  1991 05:39 MST
  4447. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA18792; Wed, 28 Aug 91
  4448.  05:22:15 -0700
  4449. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  4450.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  4451.  usenet@ucbvax.Berkeley.EDU if you have questions)
  4452. Resent-Date: Wed, 28 Aug 1991 05:39 MST
  4453. Date: 28 Aug 91 07:15:34 GMT
  4454. From: world!ksr!tim@uunet.uu.net (Tim Peters)
  4455. Subject: RE: limiting generation
  4456. Sender: icon-group-request@arizona.edu
  4457. Resent-To: icon-group@cs.arizona.edu
  4458. To: icon-group@arizona.edu
  4459. Resent-Message-Id: <82105E459EC0893E@Arizona.edu>
  4460. Message-Id: <5228@ksr.com>
  4461. X-Envelope-To: icon-group@CS.Arizona.EDU
  4462. X-Vms-To: icon-group@Arizona.edu
  4463. Organization: Kendall Square Research Corp.
  4464. References: <9108271512.AA16740@netcom.netcom.com>
  4465.  
  4466. In article <9108271512.AA16740@netcom.netcom.com> pbewig@NETCOM.COM (Phil Bewig) writes:
  4467. > In a program which I am writing, I have a line
  4468. >
  4469. >     while put(items, @getnext) \ maxitems
  4470. >
  4471. > which is an attempt to load initial values into a list, up to the
  4472. > specified maximum.
  4473.  
  4474. Think you'll be happiest with something equivalent to
  4475.  
  4476.     every put( items, (|@getnext)\maxitems )
  4477.  
  4478. Sticking "|" (repeated alternation) in front of a coexp invocation is a
  4479. slick trick that's generally effective for problems "like this".  Also
  4480. works to move the limitation expression outside, yielding something
  4481. closer to your original:
  4482.  
  4483.     every put( items, |@getnext ) \ maxitems
  4484.  
  4485. Matter of taste; I think the first way is clearer because I think I'm
  4486. "really" trying to limit the "getnext", not the "put".  If you're not
  4487. comfortable with repeated alternation, you might like this better:
  4488.  
  4489.     every 1 to maxitems & put( items, @getnext )
  4490.  
  4491. I suspect this will be less efficient if @getnext fails early, though
  4492. (because the "1 to maxitems" part will go thru its whole range
  4493. regardless of how early @getnext first fails).
  4494.  
  4495. > However, the program doesn't work the way I expect; the maxitems limit
  4496. > is ignored.
  4497.  
  4498. Well, if you set maxitems to 0 you'll see that it's not really ignored
  4499. -- it just doesn't do what you wanted <grin>.  So long as maxitems is >=
  4500. 1, it will *appear* to be "ignored" in the sense you intend.  What's
  4501. really going on is along these lines:
  4502.  
  4503.     while put(items, @getnext) \ maxitems
  4504.  
  4505. 1. put( items, @getnext ) \ maxitems
  4506.    is evaluated.  Assuming the "@getnext" produces a result and maxitems
  4507.    is >= 1, the put succeeds and produces "items".
  4508.  
  4509. 2. Since the "put" produced a result ("items"), the "while" goes back to
  4510.    step 1 (and note particularly that maxitems and the limitation will
  4511.    be evaluated fresh each time you do go back to step 1).
  4512.  
  4513. In short, you've got the makings of an infinite loop here; it won't stop
  4514. until (unless, really) "@getnext" fails.
  4515.  
  4516. >  ...
  4517. >     1)  Is it correct that the "\" limitation operator only
  4518. >         applies to generators?
  4519.  
  4520. I think not precisely, or "yes" but in a trivial sense:  every
  4521. expression in Icon may be a generator, and expressions are really all
  4522. Icon has, so limitation can really be applied to anything.  E.g.,
  4523.  
  4524.     (write\9\3)((2\77) + (3\8))\(205\12)
  4525.  
  4526. prints "5" (same as "write(2+3)").  Confused <grin>?  Hang in there --
  4527. it took me a long time to understand what role generators really play in
  4528. Icon, but after a "Eureka!" experience or two it will seem both simple
  4529. and natural.  Darned convenient, too, so it's worth the effort.
  4530.  
  4531. >  Is while a control expression, not a generator, so limitation doesn't
  4532. >  apply?
  4533.  
  4534. Limitation does apply, but in a degenerate way.  If you have _The Icon
  4535. Progamming Language_ book (2nd ed), reread the section on "Bounded
  4536. Expressions" in chapter 7 (pg 85).  The "while" expression is a bounded
  4537. expression, meaning it cannot generate a sequence of results -- I guess
  4538. I'd like that explanation better if it said it *can* generate a sequence
  4539. of results but of length at most one.  Alas, getting the reasons to
  4540. "click" in your head requires grasping such subtleties.
  4541.  
  4542. >     2)  I solved the problem by rewriting as follows:
  4543. >
  4544. >             while put(items, @getnext) do
  4545. >                 if *items > maxitems then break
  4546. >
  4547. >         Is there a better way?
  4548.  
  4549. I think that way actually allows the list to grow one larger than you
  4550. wanted (replace ">" by ">="), but the idea is certainly sound.  "Better"
  4551. depends on what you like; here are some similar alternatives you may or
  4552. may not like better:
  4553.  
  4554.     while *put(items, @getnext) < maxitems
  4555.  
  4556.     while put(items, @getnext) & *items < maxitems
  4557.  
  4558.     while *items < maxitems do put(items, @getnext) | break
  4559.  
  4560.     every 1 to maxitems do put(items, @getnext)
  4561.  
  4562.     every 1 to maxitems do put(items, @getnext) | break
  4563.  
  4564. there-are-a-hundred-ways-to-do-it-ly y'rs  - tim
  4565.  
  4566. Tim Peters   Kendall Square Research Corp
  4567. tim@ksr.com,         ksr!tim@uunet.uu.net
  4568.  
  4569. From icon-group-request@arizona.edu  Wed Aug 28 11:26:16 1991
  4570. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Wed, 28 Aug 91 11:26:16 MST
  4571. Resent-From: icon-group-request@arizona.edu
  4572. Received: from Arizona.edu (Maggie.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  4573.     id AA25920; Wed, 28 Aug 91 11:26:10 MST
  4574. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Wed, 28 Aug
  4575.  1991 11:25 MST
  4576. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA02206; Wed, 28 Aug 91
  4577.  11:07:18 -0700
  4578. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  4579.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  4580.  usenet@ucbvax.Berkeley.EDU if you have questions)
  4581. Resent-Date: Wed, 28 Aug 1991 11:25 MST
  4582. Date: 28 Aug 91 18:02:49 GMT
  4583. From: cis.ohio-state.edu!zaphod.mps.ohio-state.edu!qt.cs.utexas.edu!cs.utexas.edu!utgpu!news-server.ecf!generic.physics.utoronto.ca!ists!newshub.ccs.yorku.ca!newshub.ccs.yorku.ca!haroldt@ucbvax.  (Harold
  4584.  Tomlinson)
  4585. Subject: Problems compiling Icon on a DecStation 2100.
  4586. Sender: icon-group-request@arizona.edu
  4587. Resent-To: icon-group@cs.arizona.edu
  4588. To: icon-group@arizona.edu
  4589. Resent-Message-Id: <B2714998064050A3@Arizona.edu>
  4590. Message-Id: <HAROLDT.91Aug28130249@paralandra.yorku.ca>
  4591. X-Envelope-To: icon-group@CS.Arizona.EDU
  4592. X-Vms-To: icon-group@Arizona.edu
  4593. Organization: York Computing Services
  4594.  
  4595.  
  4596.  Greetings...
  4597.  
  4598.   I'm attempting to compile Icon on my DS2100 using the configuration for 
  4599. a DS3100.  I have two problems.  (Life should be so simple.)
  4600.  
  4601.   The first problem to hit me is the use of the 'if' in the Makefiles.  When
  4602. make runs, for example, an 
  4603.     'if (grep -s NoRanlib define.h) then touch ../../../NoRanlib;...' 
  4604. the grep returns an error code (string is not found) and the Makefile exits.
  4605. Since there are only two files with 'if's in them, I edited them manually.
  4606. (src/runtime/Makefile and config/unix/Generic/Makefile.)
  4607.  
  4608.   The second problem is that, with the runtime Makefile, it tries to do the 
  4609. following:
  4610. CheckFile: rswitch.o
  4611.     cd ../common; make
  4612.     if (test -f rt.a)\
  4613.            then make -f rt.mke HDRS="$(HDRS)" Library;\
  4614.            else ../rtt/rtt -i; fi
  4615.  
  4616.   Even manually this fails...
  4617.  
  4618. paralandra> ../rtt/rtt -i
  4619. rtt: File fstruct.rtt; Line 32: too few arguments for macro call to SElemPtrPtr
  4620.  
  4621. paralandra> make -f rt.mke HDRS="../h/define.h ../h/config.h ../h/typedefs.h ../h/proto.h ../h/cstructs.h ../h/cpuconf.h ../h/rmacros.h ../h/rexterns.h ../h/rstructs.h ../h/rproto.h ../h/cproto.h" Library
  4622. ../rtt/rtt -d rt ../common/long.o
  4623. ar r rt.a  ../common/long.o
  4624. ar: Warning: creating rt.a
  4625. ../rtt/rtt -d rt ../common/memory.o
  4626. ar r rt.a  ../common/memory.o
  4627. ../rtt/rtt -d rt ../common/time.o
  4628. ar r rt.a  ../common/time.o
  4629. ../rtt/rtt -d rt cnv.rtt
  4630. rtt: File cnv.rtt; Line 424: too few arguments for macro call to TElemPtrPtr
  4631. *** Error code 1
  4632.  
  4633.  
  4634. These are defined in src/h/inmacros.h to have trhee parameters.
  4635.  
  4636.   Why is it that the file src/runtime/Makefile does not include ../h/inmacros.h
  4637. in it's list of HDRS?
  4638.  
  4639.   Has someone compiled this successfully on a DS2100 or DS3100.  Could I pick
  4640. up a tar'd&compress'd copy someplace to ensure that I've got everything?
  4641.  
  4642. --
  4643. # Harold Tomlinson            ##    haroldt@paralandra.yorku.ca #
  4644. # Computing & Communications Services    ##    (416)736-5257-33802         #
  4645. # YORK UNIVERSITY, Ont, CANADA        ##    ########################### #
  4646.  
  4647. From TENAGLIA@mis.mcw.edu  Thu Aug 29 09:17:39 1991
  4648. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Thu, 29 Aug 91 09:17:39 MST
  4649. Received: from mis3.mis.mcw.edu by optima.cs.arizona.edu (4.1/15)
  4650.     id AA28735; Thu, 29 Aug 91 09:17:35 MST
  4651. Date: Thu, 29 Aug 1991 11:18 CST
  4652. From: Chris Tenaglia - 257-8765 <TENAGLIA@mis.mcw.edu>
  4653. Subject: Holiday Tidbit
  4654. To: icon-group@cs.arizona.edu
  4655. Message-Id: <7AA6AECFC04003EF@mis.mcw.edu>
  4656. X-Organization: Medical College of Wisconsin MIS Department (Milwaukee, WI)
  4657. X-Vms-To: IN%"icon-group@cs.arizona.edu"
  4658.  
  4659.  
  4660. Labor day will soon be upon us and I thought it fitting to submit a code
  4661. fragment as food for thought over the long long weekend. This one is
  4662. called SOUNDEX. I recently read about it in a trade rag as being an
  4663. algorhythm for cataloguing things. Credit houses use to file names and
  4664. I thought it lended itself well to icon. Perhaps as a means of database
  4665. key generation. Oh well, look at it, play with it, and maybe someone will
  4666. find a cool application of it.
  4667.  
  4668. Yours truly,
  4669.  
  4670. Chris Tenaglia (System Manager) | Medical College of Wisconsin
  4671. 8701 W. Watertown Plank Rd.     | Milwaukee, WI 53226
  4672. (414)257-8765                   | tenaglia@mis.mcw.edu, mcwmis!tenaglia
  4673.  
  4674. #
  4675. # SOUNDEX.ICN          8/28/91          TENAGLIA
  4676. #
  4677. # THIS ICON PROGRAM IMPLEMENTS A SOUNDEX CATALOGUING
  4678. # KEY COMPRESSOR.
  4679. #
  4680. procedure main()
  4681.   while map(line := input("Str:")) ~== "quit" do write(soundex(line))
  4682.   end
  4683.  
  4684. #
  4685. # STR IS A STRING (USUALLY A LAST NAME) PHONETICALLY SPELLED.
  4686. # NUMBER IS RETURNED WHICH IS A CATALOGUE LOOK UP KEY MADE FROM IT.
  4687. # THE STEPS ARE AS FOLLOWS :
  4688. #          1. SAVE THE FIRST CHARACTER FOR LATER USE
  4689. #          2. REMOVE W AND H                                 
  4690. #          3. REMOVE ALL VOWELS EXCEPT WHEN IN FIRST POSITION
  4691. #          4. MAP LEFTOVER STRING WITH A NUMBER TABLE
  4692. #          5. DELETE DUPLICATE ADJACENT DIGITS
  4693. #          6. MAKE NUMBER 6 CHARACTERS LONG (TRUNCATE OR PAD WITH 0S)
  4694. #          7. REPLACE FIRST DIGIT WITH SAVED FIRST CHARACTER
  4695. #
  4696. procedure soundex(str)
  4697.   static vowels, tbl
  4698.   initial
  4699.     {
  4700.     vowels := 'aeiouy'
  4701.     tbl    := "0123012 02245501262301 202"
  4702.     }
  4703.   str := map(str)
  4704.   first := str[1] ; tmp := first ; tmp2 := ""
  4705.   while i := find("w"|"h",str) do str[i] := ""
  4706.   every i := 2 to *str do tmp ||:= if any(vowels,str,i) then "" else str[i]
  4707.   str2 := map(tmp,&lcase,tbl) || "?"
  4708.   every i := 1 to *str2-1 do
  4709.     if str2[i] ~== str2[i+1] then tmp2 ||:= str2[i]
  4710.   number := if *tmp2 < 6 then left(tmp2,6,"0") else tmp2[1+:6]
  4711.   number[1] := first
  4712.   return number
  4713.   end
  4714.   
  4715. #
  4716. # GET A STRING OF INPUT FROM THE KEYBOARD
  4717. #
  4718.  
  4719. procedure input(prompt)
  4720.   writes(prompt)
  4721.   return read()
  4722.   end
  4723.  
  4724.  
  4725.  
  4726. From cheyenne  Fri Aug 30 19:26:37 1991
  4727. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Fri, 30 Aug 91 19:26:37 MST
  4728. Date: Fri, 30 Aug 91 19:26:36 MST
  4729. From: "Cheyenne Wills" <cheyenne>
  4730. Message-Id: <9108310226.AA02456@optima.cs.arizona.edu>
  4731. Received: by optima.cs.arizona.edu (4.1/15)
  4732.     id AA02456; Fri, 30 Aug 91 19:26:36 MST
  4733. To: icon-group
  4734. Subject: SOUNDEX revisited
  4735.  
  4736. Several years ago I wrote a soundex program (found the algorithm in
  4737. one of Knuths books).  Anyway here it is:
  4738. -----
  4739. procedure soundex(name)
  4740.    name := map(name,string(&lcase),string(&ucase)) # Convert to uppercase..
  4741.    first := name[1]
  4742. # Retain the first letter of the name, and convert all
  4743. # occurrences of A,E,H,I,O,U,W,Y in other positions to "."
  4744. #
  4745. # Assign the following numbers to the remaining letters
  4746. # after the first:
  4747. #
  4748. # B,F,P,V => 1             L => 4
  4749. # C,G,J,K,Q,S,X,Z => 2     M,N => 5
  4750. # D,T => 3                 R => 6
  4751.  
  4752.    name := map(name,"ABCDEFGHIJKLMNOPQRSTUVWXYZ",
  4753.                     ".123.12..22455.12623.1.2.2")
  4754.  
  4755. # If two or more letters with the same code were adjacent
  4756. # in the original name, omit all but the first
  4757.  
  4758.    every c := !"123456" do
  4759.        while i := find(c||c,name) do
  4760.            name[i+:2] := c
  4761.    name[1] := first
  4762.  
  4763. # Now delete our place holder ('.')
  4764.    while i := upto('.',name) do name[i] := ""
  4765.  
  4766.    return left(name,4,"0")
  4767. end
  4768. ------
  4769.  
  4770. Cheyenne Wills
  4771.  
  4772. From @um.cc.umich.edu:Paul_Abrahams@MTS.cc.Wayne.edu  Mon Sep  2 20:59:47 1991
  4773. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Mon, 2 Sep 91 20:59:47 MST
  4774. Received: from mailrus.cc.umich.edu by optima.cs.arizona.edu (4.1/15)
  4775.     id AA14882; Mon, 2 Sep 91 20:59:43 MST
  4776. Received: from um.cc.umich.edu by mailrus.cc.umich.edu (5.61/1123-1.0)
  4777.     id AA09313; Mon, 2 Sep 91 23:56:03 -0400
  4778. Received: from MTS.cc.Wayne.edu by um.cc.umich.edu via MTS-Net; Mon, 2 Sep 91 23:58:01 EDT
  4779. Date: Mon, 2 Sep 91 23:57:10 EDT
  4780. From: Paul_Abrahams@mts.cc.wayne.edu
  4781. To: icon-group@cs.arizona.edu
  4782. Message-Id: <356668@MTS.cc.Wayne.edu>
  4783. Subject: Editing Icon under Emacs
  4784.  
  4785.  
  4786. Does anyone happen to have a set of Emacs mode definitions that's
  4787. appropriate to editing Icon under Emacs?  (I'm using Emacs 18.57.1,
  4788. should that matter.)
  4789.  
  4790. Paul Abrahams
  4791. abrahams@mts.cc.wayne.edu
  4792.  
  4793. From icon-group-request@arizona.edu  Sun Sep  8 14:02:55 1991
  4794. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Sun, 8 Sep 91 14:02:55 MST
  4795. Resent-From: icon-group-request@arizona.edu
  4796. Received: from Arizona.edu (Hopey.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  4797.     id AA01315; Sun, 8 Sep 91 14:02:53 MST
  4798. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Sun, 8 Sep
  4799.  1991 14:02 MST
  4800. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA13653; Sun, 8 Sep 91 14:01:05
  4801.  -0700
  4802. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  4803.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  4804.  usenet@ucbvax.Berkeley.EDU if you have questions)
  4805. Resent-Date: Sun, 8 Sep 1991 14:02 MST
  4806. Date: 8 Sep 91 20:41:09 GMT
  4807. From: cis.ohio-state.edu!zaphod.mps.ohio-state.edu!mips!news.cs.indiana.edu!msi.umn.edu!math.fu-berlin.de!ira.uka.de!ira.uka.de!news@ucbvax.berkeley.edu
  4808. Subject: ! How to call a generator from everywhere
  4809. Sender: icon-group-request@arizona.edu
  4810. Resent-To: icon-group@cs.arizona.edu
  4811. To: icon-group@arizona.edu
  4812. Resent-Message-Id: <6D2C528A5AC0BF1C@Arizona.edu>
  4813. Message-Id: <kcl2n5INNb47@iraun1.ira.uka.de>
  4814. X-Envelope-To: icon-group@CS.Arizona.EDU
  4815. X-Vms-To: icon-group@Arizona.edu
  4816. Organization: University of Karlsruhe, FRG
  4817.  
  4818. Thanx to all who answered me here and
  4819. -- of cource -- who mailed me.
  4820.  
  4821. With coexpressions it workes fine!
  4822.  
  4823. Well, I'm trying to write a Modula2 to C
  4824. Translator in Icon. Any ideas or suggestions?
  4825.  
  4826. angelo
  4827.  
  4828. P.S. it matches now Procedure Headers, Procedure Bodys and
  4829. Const Declarations.
  4830. Now I work on Var Declarations
  4831.  
  4832. From ralph  Wed Sep 11 06:43:45 1991
  4833. Date: Wed, 11 Sep 91 06:43:45 MST
  4834. From: "Ralph Griswold" <ralph>
  4835. Message-Id: <9109111343.AA07716@cheltenham.cs.arizona.edu>
  4836. Received: by cheltenham.cs.arizona.edu; Wed, 11 Sep 91 06:43:45 MST
  4837. To: icon-group
  4838. Subject: Icon applications
  4839.  
  4840. Occasionally we're asked what "major" applications have been written in
  4841. Icon.  We know of some, but we obviously have no way of knowing everything
  4842. for which Icon has been used.
  4843.  
  4844. If you have large applications written in Icon that get a significant
  4845. amount of use, we'd appreciate hearing about them.  A couple of lines
  4846. indicating their nature and use are all we need.
  4847.  
  4848. We'll keep names/organizations confidential unless you indicate otherwise. 
  4849.  
  4850. Please send the information directly to me.
  4851.     
  4852.     Ralph Griswold / Department of Computer Science 
  4853.     The University of Arizona / Tucson, AZ 85721
  4854.     
  4855.     ralph@cs.arizona.edu / uunet!arizona!ralph
  4856.     
  4857.     voice: 602-621-6609 / fax: 602-621-9618
  4858.  
  4859. From icon-group-request@arizona.edu  Thu Sep 12 22:25:04 1991
  4860. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Thu, 12 Sep 91 22:25:04 MST
  4861. Resent-From: icon-group-request@arizona.edu
  4862. Received: from Arizona.edu (Hopey.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  4863.     id AA05509; Thu, 12 Sep 91 22:25:06 MST
  4864. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Thu, 12 Sep
  4865.  1991 22:24 MST
  4866. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA10336; Thu, 12 Sep 91
  4867.  22:12:06 -0700
  4868. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  4869.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  4870.  usenet@ucbvax.Berkeley.EDU if you have questions)
  4871. Resent-Date: Thu, 12 Sep 1991 22:24 MST
  4872. Date: 13 Sep 91 03:13:47 GMT
  4873. From: csus.edu!wupost!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!pacific.mps.ohio-state.edu!linac!midway!ellis!goer@ucdavis.ucdavis.edu
  4874.  (Richard L. Goerwitz)
  4875. Subject: text retrieval tools
  4876. Sender: icon-group-request@arizona.edu
  4877. Resent-To: icon-group@cs.arizona.edu
  4878. To: icon-group@arizona.edu
  4879. Resent-Message-Id: <D7FD9FD442C002B1@Arizona.edu>
  4880. Message-Id: <1991Sep13.031347.15378@midway.uchicago.edu>
  4881. X-Envelope-To: icon-group@CS.Arizona.EDU
  4882. X-Vms-To: icon-group@Arizona.edu
  4883. Organization: University of Chicago
  4884.  
  4885. Some months ago, I mentioned the existence of a text retrieval library
  4886. I'd developed.  What it essentially did (does) is to enable the user to
  4887. index texts like the Quran, the Bible, and in general anything that is
  4888. arranged into neat divisions, and to perform word-based retrievals on
  4889. that text.  I have a new version on-hand, and I'd be happy to mail it
  4890. out to anyone who wants it.
  4891.  
  4892. If there is a lot of demand, I'll post it to alt.sources.
  4893.  
  4894. The package has been tested quite thoroughly by being incorporated into
  4895. a biblical text retrieval package that I posted to comp.sources.misc.
  4896. This package (after some improvements) was placed on cs.arizona.edu (icon/
  4897. contrib/bibleref.tar.Z).  It's still there, and if you don't want to bo-
  4898. ther asking me to send the software directly to you, you can get it in
  4899. this form via anonymous ftp to cs.arizona.edu.
  4900.  
  4901. -- 
  4902.  
  4903.    -Richard L. Goerwitz              goer%sophist@uchicago.bitnet
  4904.    goer@sophist.uchicago.edu         rutgers!oddjob!gide!sophist!goer
  4905.  
  4906. From icon-group-request@arizona.edu  Mon Sep 16 11:57:32 1991
  4907. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Mon, 16 Sep 91 11:57:32 MST
  4908. Resent-From: icon-group-request@arizona.edu
  4909. Received: from Arizona.edu (Merlin.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  4910.     id AA21691; Mon, 16 Sep 91 11:57:30 MST
  4911. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Mon, 16 Sep
  4912.  1991 11:56 MST
  4913. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA05206; Mon, 16 Sep 91
  4914.  11:48:28 -0700
  4915. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  4916.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  4917.  usenet@ucbvax.Berkeley.EDU if you have questions)
  4918. Resent-Date: Mon, 16 Sep 1991 11:57 MST
  4919. Date: 16 Sep 91 16:11:29 GMT
  4920. From: mcsun!news.funet.fi!fuug!demos!news-server@uunet.uu.net
  4921. Subject: What is Icon
  4922. Sender: icon-group-request@arizona.edu
  4923. Resent-To: icon-group@cs.arizona.edu
  4924. To: icon-group@arizona.edu
  4925. Resent-Message-Id: <A4FBB11ED2A01AC0@Arizona.edu>
  4926. Message-Id: <829D488211@srcc.msu.su>
  4927. X-Envelope-To: icon-group@CS.Arizona.EDU
  4928. X-Vms-To: icon-group@Arizona.edu
  4929. Organization: Research Computing Center, Moscow State University
  4930.  
  4931. Hi, all out there!
  4932.  
  4933. What is the Icon programming language?
  4934. Is it a text processing one like SNOBOL?
  4935. Any references to description will be appreciated.
  4936.  
  4937. Valentine.
  4938.  
  4939. From icon-group-request@arizona.edu  Wed Sep 18 19:20:31 1991
  4940. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Wed, 18 Sep 91 19:20:31 MST
  4941. Resent-From: icon-group-request@arizona.edu
  4942. Received: from Arizona.edu (Merlin.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  4943.     id AA05407; Wed, 18 Sep 91 18:37:18 MST
  4944. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Wed, 18 Sep
  4945.  1991 18:36 MST
  4946. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA12355; Wed, 18 Sep 91
  4947.  18:24:46 -0700
  4948. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  4949.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  4950.  usenet@ucbvax.Berkeley.EDU if you have questions)
  4951. Resent-Date: Wed, 18 Sep 1991 18:37 MST
  4952. Date: 18 Sep 91 23:57:06 GMT
  4953. From: agate!spool.mu.edu!cs.umn.edu!lynx!nmsu!opus!pannaiya@ucbvax.berkeley.edu
  4954.  (Pradeepkumar Annaiyappa)
  4955. Subject: icon compiler error
  4956. Sender: icon-group-request@arizona.edu
  4957. Resent-To: icon-group@cs.arizona.edu
  4958. To: icon-group@arizona.edu
  4959. Resent-Message-Id: <6F29B70492A03BB4@Arizona.edu>
  4960. Message-Id: <PANNAIYA.91Sep18175706@chama.nmsu.edu>
  4961. X-Envelope-To: icon-group@CS.Arizona.EDU
  4962. X-Vms-To: icon-group@Arizona.edu
  4963. Organization: NMSU Computer Science
  4964.  
  4965. I down loaded the sources for the icon compiler and am
  4966. trying to compile it on an RS6000 AIX 3.1.6.  The
  4967. compilation went through without any major errors.
  4968. On trying to test the samples I get an 'out of memory'
  4969. error.  Has anyone faced this problem?  Is there a
  4970. solution.
  4971.  
  4972. Thanks,
  4973.  
  4974. pk
  4975.  
  4976. PradeepKumar Annaiyappa,
  4977. Computing Research Laboratory,
  4978. Las Cruces, NM 88001
  4979. (505)-646-1482
  4980. pk@nmsu.edu
  4981.  
  4982. From ralph  Wed Sep 18 19:39:06 1991
  4983. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Wed, 18 Sep 91 19:39:06 MST
  4984. Resent-From: "Ralph Griswold" <ralph>
  4985. Received: from Arizona.edu (Hopey.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  4986.     id AA06977; Wed, 18 Sep 91 19:39:05 MST
  4987. Received: from optima.cs.arizona.edu by Arizona.edu with PMDF#10282; Wed, 18
  4988.  Sep 1991 19:38 MST
  4989. Received: from cheltenham.cs.arizona.edu by optima.cs.arizona.edu (4.1/15) id
  4990.  AA06971; Wed, 18 Sep 91 19:38:28 MST
  4991. Received: by cheltenham.cs.arizona.edu; Wed, 18 Sep 91 19:38:27 MST
  4992. Resent-Date: Wed, 18 Sep 1991 19:38 MST
  4993. Date: Wed, 18 Sep 91 19:38:27 MST
  4994. From: Ralph Griswold <ralph@cs.arizona.edu>
  4995. Subject: RE:  icon compiler error
  4996. Resent-To: icon-group@cs.arizona.edu
  4997. To: agate!spool.mu.edu!cs.umn.edu!lynx!nmsu!opus!pannaiya@ucbvax.berkeley.edu,
  4998.         icon-group@arizona.edu
  4999. Resent-Message-Id: <77CC6AA772A030BD@Arizona.edu>
  5000. Message-Id: <9109190238.AA00670@cheltenham.cs.arizona.edu>
  5001. X-Envelope-To: icon-group@CS.Arizona.EDU
  5002. X-Vms-To: 
  5003.  agate!spool.mu.edu!cs.umn.edu!lynx!nmsu!opus!pannaiya@ucbvax.berkeley.edu,
  5004.  icon-group@Arizona.edu
  5005.  
  5006. What was the exact error message?  If you tell us that, we probably
  5007. can tell you what the problem is and how to fix it.
  5008.     
  5009.     Ralph Griswold / Department of Computer Science 
  5010.     The University of Arizona / Tucson, AZ 85721
  5011.     
  5012.     ralph@cs.arizona.edu / uunet!arizona!ralph
  5013.     
  5014.     voice: 602-621-6609 / fax: 602-621-9618
  5015.  
  5016. From icon-group-request@arizona.edu  Wed Sep 18 22:07:31 1991
  5017. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Wed, 18 Sep 91 22:07:31 MST
  5018. Resent-From: icon-group-request@arizona.edu
  5019. Received: from Arizona.edu (Hopey.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  5020.     id AA11699; Wed, 18 Sep 91 22:07:30 MST
  5021. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Wed, 18 Sep
  5022.  1991 22:06 MST
  5023. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA18650; Wed, 18 Sep 91
  5024.  22:05:41 -0700
  5025. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  5026.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  5027.  usenet@ucbvax.Berkeley.EDU if you have questions)
  5028. Resent-Date: Wed, 18 Sep 1991 22:07 MST
  5029. Date: 19 Sep 91 04:13:51 GMT
  5030. From: midway!ellis!goer@uunet.uu.net (Richard L. Goerwitz)
  5031. Subject: RE: icon compiler error
  5032. Sender: icon-group-request@arizona.edu
  5033. Resent-To: icon-group@cs.arizona.edu
  5034. To: icon-group@arizona.edu
  5035. Resent-Message-Id: <8C8780D9D2A03725@Arizona.edu>
  5036. Message-Id: <1991Sep19.041351.2372@midway.uchicago.edu>
  5037. X-Envelope-To: icon-group@CS.Arizona.EDU
  5038. X-Vms-To: icon-group@Arizona.edu
  5039. Organization: University of Chicago
  5040. References: <PANNAIYA.91Sep18175706@chama.nmsu.edu>
  5041.  
  5042. pannaiya@nmsu.edu (Pradeepkumar Annaiyappa) writes:
  5043. >I down loaded the sources for the icon compiler and am
  5044. >trying to compile it on an RS6000 AIX 3.1.6.  The
  5045. >compilation went through without any major errors.
  5046. >On trying to test the samples I get an 'out of memory'
  5047. >error.  Has anyone faced this problem?  Is there a
  5048. >solution.
  5049.  
  5050. I responded privately, but now that I think about it it might be a
  5051. good idea to post a note here as well.  In general, it's better to
  5052. start with the interpreter if you're installing Icon for the first
  5053. time, or if you aren't trying to do some big-time development work.
  5054. From the user's standpoint, executables produced by the interpreter
  5055. will look and feel pretty much like their compiled equivalents, only
  5056. slower and using much smaller executable files.
  5057.  
  5058. My guess is that people are loggin into cs.arizona.edu, browsing,
  5059. seeing both the compiler and the interpreter, and naturally thinking
  5060. they want the compiler.  This may, in fact, be the correct choice.
  5061. For a first installation, though, it's probably not.
  5062.  
  5063. I hope this helps save some people some frustration.  Pradeepkumar
  5064. may have already installed the interpreter, so perhaps this is all
  5065. superfluous.  If so, I apologize for dragging him into this :-).
  5066.  
  5067. -- 
  5068.  
  5069.    -Richard L. Goerwitz              goer%sophist@uchicago.bitnet
  5070.    goer@sophist.uchicago.edu         rutgers!oddjob!gide!sophist!goer
  5071.  
  5072. From uunet!men2a!aquin!luvthang!talmage  Fri Sep 20 19:55:32 1991
  5073. Received: from univers.cs.arizona.edu by cheltenham.cs.arizona.edu; Fri, 20 Sep 91 19:55:32 MST
  5074. Received: from uunet.UUCP by univers.cs.arizona.edu; Fri, 20 Sep 91 19:55:31 MST
  5075. Received: from uunet.uu.net (via LOCALHOST.UU.NET) by relay2.UU.NET with SMTP 
  5076.     (5.61/UUNET-internet-primary) id AA13735; Fri, 20 Sep 91 13:33:14 -0400
  5077. Received: from men2a.UUCP by uunet.uu.net with UUCP/RMAIL
  5078.     (queueing-rmail) id 133239.18719; Fri, 20 Sep 1991 13:32:39 EDT
  5079. Received: by men2a.ori-cal.com (smail2.5)
  5080.     id AA26119; 20 Sep 91 13:29:28 EDT (Fri)
  5081. Received: by aquin.ORI-CAL.COM (smail2.5)
  5082.     id AA14463; 20 Sep 91 13:25:55 EDT (Fri)
  5083. Received: by luvthang.aquin.ori-cal.com (V1.13/Amiga)
  5084.     id AA03360; Thu, 19 Sep 91 12:32:21 EST
  5085. Date: Thu, 19 Sep 91 12:32:21 EST
  5086. Message-Id: <9109191732.AA03360@luvthang.aquin.ori-cal.com>
  5087. From: uunet!luvthang.aquin.ori-cal.com!talmage (David W. Talmage)
  5088. To: icon-group@cs.arizona.edu
  5089. Subject: Patterns -> Icon code
  5090.  
  5091. The current wisdom in Natural Language Processing is to write a
  5092. description of some part of a language and use a program which
  5093. interprets the description to process the language.  This is a
  5094. flexible way to separate the data from the program code.  Sometimes,
  5095. though, this isn't especially quick.  In that case, a program which
  5096. generates other another program that can process the langauge directly
  5097. is desirable. 
  5098.  
  5099. With that in mind, who can point me to a procedure that turns patterns
  5100. (e.g. the UNIX-style *?{}[] patterns) into Icon code?  The Icon
  5101. Program Library includes the procedure wildcard(), but that one only
  5102. finds patterns; it does not produce code.
  5103.  
  5104. Thanks to those who can help.  I'll summarize the replies if necessary.
  5105.  
  5106. -----------------------------------------------------------------------------
  5107. David W. Talmage (talmage@luvthang.aquin.ori-cal.com)
  5108. "Great big Idol with the golden head"
  5109.  
  5110. From icon-group-request@arizona.edu  Sat Sep 21 09:56:49 1991
  5111. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Sat, 21 Sep 91 09:56:49 MST
  5112. Resent-From: icon-group-request@arizona.edu
  5113. Received: from Arizona.edu (Hopey.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  5114.     id AA16605; Sat, 21 Sep 91 09:56:47 MST
  5115. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Sat, 21 Sep
  5116.  1991 09:56 MST
  5117. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA10066; Sat, 21 Sep 91
  5118.  09:46:04 -0700
  5119. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  5120.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  5121.  usenet@ucbvax.Berkeley.EDU if you have questions)
  5122. Resent-Date: Sat, 21 Sep 1991 09:56 MST
  5123. Date: 21 Sep 91 15:09:06 GMT
  5124. From: cis.ohio-state.edu!zaphod.mps.ohio-state.edu!wupost!uwm.edu!linac!midway!ellis!goer@ucbvax.berkeley.edu (Richard L.
  5125.  Goerwitz)
  5126. Subject: RE: Re: Patterns -> Icon code
  5127. Sender: icon-group-request@arizona.edu
  5128. Resent-To: icon-group@cs.arizona.edu
  5129. To: icon-group@arizona.edu
  5130. Resent-Message-Id: <81F18B73E0A0450E@Arizona.edu>
  5131. Message-Id: <1991Sep21.150906.20881@midway.uchicago.edu>
  5132. X-Envelope-To: icon-group@CS.Arizona.EDU
  5133. X-Vms-To: icon-group@Arizona.edu
  5134. Organization: University of Chicago
  5135. References: <9109191732.AA03360@luvthang.aquin.ori-cal.com>
  5136.  
  5137. talmage@luvthang.aquin.ori-cal.COM (David W. Talmage) writes:
  5138. >
  5139. >With that in mind, who can point me to a procedure that turns patterns
  5140. >(e.g. the UNIX-style *?{}[] patterns) into Icon code?
  5141.  
  5142. Whoops.  I didn't really answer your specific request.  A while back I
  5143. tried to write a program that took a set of regular expressions (the
  5144. egrep []()*+.^$ patterns), and create a deterministic finite state auto-
  5145. maton that would recognize strings matching the pattern.  It was slow.
  5146. I just couldn't figure out a way of doing it fast in Icon.
  5147.  
  5148. So I backtracked :-), and wrote a program that produces a much smaller
  5149. nondeterministic pushdown automaton.  That program made it into one or
  5150. another of the IPL updates (number 1?).  It's called findre.icn, and
  5151. although the IPL version works fine, you can always get the latest ver-
  5152. sion from me (assuming you want it).
  5153.  
  5154. A lot of us have been asking about regexp support in Icon, but after
  5155. all, regular expressions don't really fit into the language nicely, and
  5156. no one can really agree on how they should be implemented.  In retro-
  5157. spect, I think I should have written matchre() before findre(), but I
  5158. am onto other things now, and probably won't go back and do things
  5159. over.  If you have any ideas about how regular expression capability
  5160. should be added to Icon, please post.  Maybe I'll get back to findre,
  5161. and rewrite it in the image of what people really want (if it's not
  5162. OK right now).
  5163.  
  5164. -- 
  5165.  
  5166.    -Richard L. Goerwitz              goer%sophist@uchicago.bitnet
  5167.    goer@sophist.uchicago.edu         rutgers!oddjob!gide!sophist!goer
  5168.  
  5169. From icon-group-request@arizona.edu  Sat Sep 21 09:57:05 1991
  5170. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Sat, 21 Sep 91 09:57:05 MST
  5171. Resent-From: icon-group-request@arizona.edu
  5172. Received: from Arizona.edu (Osprey.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  5173.     id AA16616; Sat, 21 Sep 91 09:57:03 MST
  5174. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Sat, 21 Sep
  5175.  1991 09:56 MST
  5176. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA10153; Sat, 21 Sep 91
  5177.  09:48:11 -0700
  5178. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  5179.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  5180.  usenet@ucbvax.Berkeley.EDU if you have questions)
  5181. Resent-Date: Sat, 21 Sep 1991 09:56 MST
  5182. Date: 21 Sep 91 16:01:28 GMT
  5183. From: cis.ohio-state.edu!pacific.mps.ohio-state.edu!linac!midway!ellis!goer@ucbvax.berkeley.edu (Richard
  5184.  L. Goerwitz)
  5185. Subject: Bible browser; another update
  5186. Sender: icon-group-request@arizona.edu
  5187. Resent-To: icon-group@cs.arizona.edu
  5188. To: icon-group@arizona.edu
  5189. Resent-Message-Id: <81FB40BA62C0491E@Arizona.edu>
  5190. Message-Id: <1991Sep21.160128.21823@midway.uchicago.edu>
  5191. X-Envelope-To: icon-group@CS.Arizona.EDU
  5192. X-Vms-To: icon-group@Arizona.edu
  5193. Organization: University of Chicago
  5194.  
  5195. I'm feeling verbose today.
  5196.  
  5197. The Bible browser I keep saying I'm done with (but then go on tweaking) is
  5198. now on cs.arizona.edu (icon/contrib/bibleref-2.1.tar.Z) in updated form.
  5199. The Huffman encoding algorithm is tighter (making for smaller files in some
  5200. cases), and fewer disk seeks are required in order to retrieve text.  Many
  5201. ops still require further optimization, but the package is quite usable as-
  5202. is.
  5203.  
  5204. Note that I'm not posting patches.  The patches would affect mainly the data
  5205. files, and, since the data files are pre-built in the cs.arizona.edu archive,
  5206. there isn't any point in sending out patches to everyone.  Just ftp the whole
  5207. (4 meg) affair from arizona, and (assuming your Icon interpreter is installed
  5208. OK, and the IPL is there too) you should be in business within, say, a half
  5209. hour (five or ten minutes, if you've installed Bibleref before).
  5210.  
  5211. People who feel masochistic, and have a Bible text online already (KJV or
  5212. RSV only, so far), can build the data files for themselves.  Just write to
  5213. me and ask for the shar files.  Beware, though:  Indexing, compressing, and
  5214. optimizing the interface took our Sun4 here at the U of Chicago overnight,
  5215. and at up a good 18 meg of core memory.  (That's why I distribute the thing
  5216. with pre-built data files!)  The process is automatic, if that's any com-
  5217. fort.  If you have the choice, though, take the cs.arizona.edu tar distrib-
  5218. ution.
  5219.  
  5220. Note:  This program is geared for UNIX.  I suspect it would not function on
  5221. a smaller system (the icode file is too big for MS-DOS, for instance).
  5222.  
  5223. -- 
  5224.  
  5225.    -Richard L. Goerwitz              goer%sophist@uchicago.bitnet
  5226.    goer@sophist.uchicago.edu         rutgers!oddjob!gide!sophist!goer
  5227.  
  5228. From icon-group-request@arizona.edu  Sat Sep 21 09:57:51 1991
  5229. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Sat, 21 Sep 91 09:57:51 MST
  5230. Resent-From: icon-group-request@arizona.edu
  5231. Received: from Arizona.edu (Merlin.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  5232.     id AA16661; Sat, 21 Sep 91 09:57:49 MST
  5233. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Sat, 21 Sep
  5234.  1991 09:57 MST
  5235. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA10032; Sat, 21 Sep 91
  5236.  09:45:28 -0700
  5237. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  5238.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  5239.  usenet@ucbvax.Berkeley.EDU if you have questions)
  5240. Resent-Date: Sat, 21 Sep 1991 09:57 MST
  5241. Date: 21 Sep 91 14:56:21 GMT
  5242. From: uwm.edu!linac!midway!ellis!goer@rutgers.edu (Richard L. Goerwitz)
  5243. Subject: RE: Patterns -> Icon code
  5244. Sender: icon-group-request@arizona.edu
  5245. Resent-To: icon-group@cs.arizona.edu
  5246. To: icon-group@arizona.edu
  5247. Resent-Message-Id: <8216816D80A05711@Arizona.edu>
  5248. Message-Id: <1991Sep21.145621.20677@midway.uchicago.edu>
  5249. X-Envelope-To: icon-group@CS.Arizona.EDU
  5250. X-Vms-To: icon-group@Arizona.edu
  5251. Organization: University of Chicago
  5252. References: <9109191732.AA03360@luvthang.aquin.ori-cal.com>
  5253.  
  5254. talmage@luvthang.aquin.ori-cal.COM (David W. Talmage) writes:
  5255.  
  5256. >The current wisdom in Natural Language Processing is to write a
  5257. >description of some part of a language and use a program which
  5258. >interprets the description to process the language.  This is a
  5259. >flexible way to separate the data from the program code.  Sometimes,
  5260. >though, this isn't especially quick.  In that case, a program which
  5261. >generates other another program that can process the langauge directly
  5262. >is desirable. 
  5263. >
  5264. >With that in mind, who can point me to a procedure that turns patterns
  5265. >(e.g. the UNIX-style *?{}[] patterns) into Icon code?  The Icon
  5266. >Program Library includes the procedure wildcard(), but that one only
  5267. >finds patterns; it does not produce code.
  5268.  
  5269. What you want is something I've been wanting as well for some time.
  5270. You want a parser generator.  C programmers have long had yacc, which
  5271. generates a deterministic pushdown automaton - a LALR(1) parser, to
  5272. be exact.  It recognizes only a limited subset of context free lang-
  5273. uages, and requires what seem to a person like me to be very complex
  5274. lookahead sets and state transition networks.  Recently Tomita pub-
  5275. lished an article on efficient parsing of the entire range of context
  5276. free languages.  His system, though, suffered from some faults, which
  5277. are apparently being rectified in a dissertation (in progress) by
  5278. Jan Rekers (and others) at Amsterdam.  Their parser generators work
  5279. by creating parallel parsing streams, which multiply and join, as
  5280. needed, in order to remain deterministic (and still take into account
  5281. all possible parses).  The algorithm is surprisingly efficient, and
  5282. handles the full range of context free languages, unlike yacc.
  5283.  
  5284. When the Rekers is done, I've been toying with the idea of taking his
  5285. ideas and using them to write an Icon parser generator.  I have some
  5286. code right here, but it was written in a LISP dialect that uses dynamic
  5287. variables, and I have little hope of finding the time to try to figure
  5288. out what is going on, and re-coding it in Icon or C.
  5289.  
  5290. If anyone is thinking of creating a parser generator that outputs Icon
  5291. code, please let us all know about it!  Maybe we can knock heads to-
  5292. gether and come up with something.
  5293.  
  5294. For now, if you can stand writing grammars that aren't left recursive,
  5295. you can use an IPL program called recgen (yes, there's the IPL I keep
  5296. reminding people about).  It essentially takes a set of BNFs and uses
  5297. them to create a recursive-descent backtracking recognizer.  It does
  5298. not actually parse or take any actions (a la yacc's action fields), but
  5299. it will let you prototype certain types of specifications.  Watch out,
  5300. though, for those left-recursive rules (in English we don't have many
  5301. of these [e.g. the 's rule], but programming languages make heavy use
  5302. of them in their specs).
  5303.  
  5304. Good luck, and please offer a summary of anything you find out!
  5305.  
  5306. -- 
  5307.  
  5308.    -Richard L. Goerwitz              goer%sophist@uchicago.bitnet
  5309.    goer@sophist.uchicago.edu         rutgers!oddjob!gide!sophist!goer
  5310.  
  5311. From icon-group-request@arizona.edu  Thu Oct  3 03:45:36 1991
  5312. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Thu, 3 Oct 91 03:45:36 MST
  5313. Resent-From: icon-group-request@arizona.edu
  5314. Received: from Arizona.edu (Merlin.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  5315.     id AA00944; Thu, 3 Oct 91 03:45:31 MST
  5316. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Thu, 3 Oct
  5317.  1991 03:44 MST
  5318. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA03470; Thu, 3 Oct 91 03:36:51
  5319.  -0700
  5320. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  5321.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  5322.  usenet@ucbvax.Berkeley.EDU if you have questions)
  5323. Resent-Date: Thu, 3 Oct 1991 03:45 MST
  5324. Date: 2 Oct 91 21:10:41 GMT
  5325. From: hsi!mlfarm!rosie!ron@uunet.uu.net (Ronald Florence)
  5326. Subject: post.icn (v1.5)
  5327. Sender: icon-group-request@arizona.edu
  5328. Resent-To: icon-group@cs.arizona.edu
  5329. To: icon-group@arizona.edu
  5330. Resent-Message-Id: <BC1012F4C6A0BEB7@Arizona.edu>
  5331. Message-Id: <1991Oct2.211041.226@mlfarm.com>
  5332. X-Envelope-To: icon-group@CS.Arizona.EDU
  5333. X-Vms-To: icon-group@Arizona.edu
  5334. Organization: Maple Lawn Farm, Stonington, CT
  5335.  
  5336. I posted an early version of this newsposter a year ago.  Since then
  5337. it has gotten new features, had a few bugs exterminated, and allowed
  5338. me to learn a bit of Icon.  The current version has been tested on
  5339. Unix and ms-dos systems running C-news, B-news, and bsnews.  The trn
  5340. and rn users here prefer it to Pnews.
  5341.  
  5342. The user-configuration is isolated and commented at the top of the
  5343. code.  The Makefile may need hacking if options.icn from the IPL isn't
  5344. in the default directory, to change the installation directories
  5345. for the executable and the man page, or for ms-dos.
  5346.  
  5347.                 Ronald Florence
  5348.                 ron@mlfarm.com
  5349.  
  5350.  
  5351. #! /bin/sh
  5352. # This is a shell archive, meaning:
  5353. # 1. Remove everything above the #! /bin/sh line.
  5354. # 2. Save the resulting text in a file.
  5355. # 3. Execute the file with /bin/sh (not csh) to create:
  5356. #    post.icn
  5357. #    Makefile
  5358. #    post.1
  5359. # This archive created: Wed Oct  2 17:01:50 1991
  5360. # By:    Ronald Florence (Maple Lawn Farm, Stonington, CT )
  5361. export PATH; PATH=/bin:/usr/bin:$PATH
  5362. if test -f 'post.icn'
  5363. then
  5364.     echo shar: "will not over-write existing file 'post.icn'"
  5365. else
  5366. cat << \SHAR_EOF > 'post.icn'
  5367. ############################################################################
  5368. #
  5369. #    Name:    post.icn
  5370. #
  5371. #    Title:    News Poster
  5372. #
  5373. #    Author:    Ronald Florence (ron@mlfarm.com)
  5374. #
  5375. #    Date:    2 October 1991
  5376. #
  5377. #    Version: 1.5
  5378. #
  5379. ############################################################################
  5380. #  This program posts a news article to Usenet.  Given an optional
  5381. #  argument of the name of a file containing a news article, or an
  5382. #  argument of "-" and a news article via stdin, post creates a
  5383. #  follow-up article, with an attribution and quoted text.  The
  5384. #  newsgroups, subject, distribution, follow-up, and quote-prefix can
  5385. #  optionally be specified on the command line.
  5386. #
  5387. #      usage: post [options] [article | -]
  5388. #        -n newsgroups
  5389. #        -s subject
  5390. #        -d distribution
  5391. #        -f followup-to
  5392. #        -p quote-prefix (default ` > ')
  5393. #
  5394. #  See the site & system configuration options below.  On systems
  5395. #  posting via inews, post validates newsgroups and distributions in
  5396. #  the `active' and `distributions' files in the news library directory.
  5397. #
  5398. ############################################################################
  5399. #
  5400. #  Link: options
  5401. #  Bugs: Newsgroup validation assumes the `active' file is sorted.
  5402. #        Non-Unix sites need hardcoded system information.
  5403. #
  5404. ############################################################################
  5405.  
  5406. link options
  5407. global mode, sysname, domain, tz, tmpfile, opts, console, newslib, org
  5408.  
  5409. procedure main(arg)
  5410.  
  5411.   usage := ["usage: post [options] [article]",
  5412.             "\t-n newsgroups",
  5413.             "\t-s subject",
  5414.             "\t-d distribution",
  5415.             "\t-f followup-to",
  5416.             "\t-p quote-prefix (default ` > ')",
  5417.             "\t-  read article from stdin"]
  5418.  
  5419.     # Site configuration.   Mode can be
  5420.     #   "local" (post via inews),
  5421.     #   "uux" (post via rnews to an upstream host),
  5422.     #   "mail" (post via mail to an upstream host).
  5423.     # For either uux or mail mode,
  5424.     #   smarthost := the uucp nodename of the upstream news feed.
  5425.       # Use generic_from to force a generic address instead
  5426.         #   of the hostname provided by system commands.
  5427.  
  5428.   mode := "local"        
  5429.   smarthost := ""
  5430.   editor := "vi"
  5431.   domain := ".UUCP"
  5432.   default_distribution := "world" 
  5433.   generic_from := &null
  5434.  
  5435.     # For Unix, the rest of the configuration is automatic.
  5436.  
  5437.   if find("UNIX", &features) then {
  5438.     console := "/dev/tty"
  5439.     newslib := "/usr/lib/news/"
  5440.     tz := "unix"
  5441.     tmpdir := "/tmp/"
  5442.     logname := pipe("logname")
  5443.     sysname := trim(pipe("hostname", "uname -n", "uuname -l"))
  5444.     # BSD  passwd: `:fullname[,...]:'
  5445.     # SysV passwd: `-fullname(' 
  5446.     \logname & every lookup("/etc/passwd") ? {
  5447.       =(logname) & {
  5448.     every tab(upto(':')+1) \4 
  5449.     fullname := (tab(upto('-')+1), tab(upto('(:'))) | tab(upto(',:'))
  5450.     break
  5451.       }    
  5452.     }
  5453.     sigfile := getenv("HOME") || "/.signature"
  5454.   }
  5455.  
  5456.     # For non-Unix systems, we need hard coded configuration:
  5457.     # console := the system's name for the user's terminal.
  5458.     # libdir := the directory for news configuration files, like 
  5459.     #           an `organization' file.
  5460.     # tmpdir := optional directory for temporary files; terminated 
  5461.     #        with the appropriate path separator: `/' or `\\'.
  5462.     # logname := user's login name.
  5463.     # tz := local time zone (e.g., EST).
  5464.         # fullname := user's full name.
  5465.         # sigfile := full path of file with user's email signature.
  5466.  
  5467.   else {
  5468.     console := "CON"
  5469.     newslib := ""
  5470.     tmpdir := ""
  5471.     logname := &null
  5472.     tz := &null
  5473.     fullname := &null 
  5474.     sigfile := &null
  5475.     sysname := getenv("HOST") | &host
  5476.   }
  5477.  
  5478.     # End of user configuration.
  5479.  
  5480.   (\logname & \sysname & \tz & (mode == "local" | *smarthost > 0)) |
  5481.     stop("post: missing system information")
  5482.   opts := options(arg, "n:s:d:f:p:h?") 
  5483.   \opts["h"] | \opts["?"] | arg[1] == "?" & { 
  5484.     every write(!usage)
  5485.     exit(-1) 
  5486.   }
  5487.   org := getenv("ORGANIZATION") | lookup(newslib || "organization")
  5488.   article := open(tmpfile := tempname(tmpdir), "w") | 
  5489.     stop("post: cannot write temp file")
  5490.   write(article, "Path: ",  sysname, "!", logname)
  5491.   writes(article, "From: ", logname, "@", \generic_from | sysname, domain)
  5492.   \fullname & writes(article, " (", fullname, ")")
  5493.   write(article)
  5494.  
  5495.     # For a follow-up article, reply_headers() does the work. 
  5496.  
  5497.   if \arg[1] then {
  5498.     inf := (arg[1] == "-" & &input) | 
  5499.       open(arg[1]) | (remove(tmpfile) & stop("post: cannot read " || arg[1]))
  5500.     reply_headers(inf, article)
  5501.     every write(article, \opts["p"] | " > ", !inf)
  5502.     close(inf)
  5503.   }
  5504.  
  5505.     # Query if newsgroups, subject, and distribution have
  5506.         # not been specified on the command line.
  5507.  
  5508.   else {
  5509.     write(article, "Newsgroups: ", 
  5510.       validate(\opts["n"] | query("Newsgroups: "), "active"))
  5511.     write(article, "Subject: ", \opts["s"] | query("Subject: "))
  5512.     write(article, "Distribution: ", 
  5513.       validate(\opts["d"] | query("Distribution: ", default_distribution), 
  5514.            "distributions"))
  5515.     every write(article, req_headers())
  5516.     write(article, "\n")
  5517.   }
  5518.   close(article)
  5519.   edstr := (getenv("EDITOR") | editor) || " " || tmpfile || " < " || console
  5520.   system(edstr)
  5521.   upto('nN', query("Are you sure you want to post this to Usenet y/n? ")) & {
  5522.     if upto('yY', query("Save your draft article y/n? ")) then 
  5523.       stop("Your article is saved in ", tmpfile)
  5524.     else {
  5525.       remove(tmpfile)
  5526.       stop("Posting aborted.") 
  5527.     }
  5528.   }
  5529.     # For inews, we supply the headers, inews supplies the .signature.
  5530.  
  5531.   if mode == "local" then mode := newslib || "inews -h"
  5532.   else {
  5533.     \sigfile & {
  5534.       article := open(tmpfile, "a")
  5535.       write(article, "--")  
  5536.       every write(article, lookup(sigfile))
  5537.     }
  5538.     # To post via sendnews (mail), we prefix lines with 'N'.
  5539.     # For rnews, don't force an immediate poll.
  5540.  
  5541.     case mode of {
  5542.       "mail": {
  5543.              mode ||:= " " || smarthost || "!rnews" 
  5544.          outf := open(tmp2 := tempname(tmpdir), "w")
  5545.          every write(outf, "N", lookup(tmpfile))
  5546.          remove(tmpfile)
  5547.          rename(tmp2, tmpfile)
  5548.        }
  5549.       "uux": mode ||:= " - -r " || smarthost || "!rnews"
  5550.     }
  5551.   }
  5552.   mode ||:= " < " || tmpfile
  5553.   (system(mode) = 0) & write("Article posted!")
  5554.   remove(tmpfile)
  5555. end
  5556.  
  5557.     # To parse the original article, we use case-insensitive
  5558.     # matches on the headers.  The Reply-to and Followup-To
  5559.     # headers usually appear later than From and Newsgroups, so
  5560.     # they take precedence.  By usenet convention, we query
  5561.     # the user if Followup-To on the original is `poster'.
  5562.  
  5563. procedure reply_headers(infile, art)
  5564.  
  5565.   every !infile ? {
  5566.     tab(match("from: " | "reply-to: ", map(&subject))) & {
  5567.       if find("<") then {
  5568.     fullname := (trim(tab(upto('<'))) ~== "")
  5569.     address := (move(1), tab(find(">")))
  5570.       }
  5571.       else {
  5572.     address := trim(tab(upto('(') | 0))
  5573.     fullname := (move(1), tab(find(")")))
  5574.       }
  5575.       quoter := (\fullname | address)
  5576.     }
  5577.     tab(match("date: ", map(&subject))) & date := tab(0)
  5578.     tab(match("message-id: ", map(&subject))) & id := tab(0)
  5579.     tab(match("subject: ", map(&subject))) & subject := tab(0)
  5580.     tab(match("distribution: ", map(&subject))) & distribution := tab(0)
  5581.     tab(match("newsgroups: " | "followup-to: ", map(&subject))) & 
  5582.       group := tab(0)
  5583.     tab(match("references: ", map(&subject))) & refs := tab(0)
  5584.     (\quoter & *&subject = 0) & {
  5585.       find("poster", group) & {
  5586.     write(quoter, " has requested followups by email.")
  5587.     upto('yY', query("Do you want to abort this posting y/n? ")) & {
  5588.       remove(tmpfile)
  5589.       stop("Posting aborted.")
  5590.     }
  5591.     group := &null
  5592.       }
  5593.       write(art, "Newsgroups: ", \group | 
  5594.     validate(\opts["n"] | query("Newsgroups: "), "active"))
  5595.       write(art, "Subject: ", \opts["s"] | \subject | query("Subject: "))
  5596.       \distribution | distribution := validate(\opts["d"], "distributions") &
  5597.         write(art, "Distribution: ", distribution)
  5598.       write(art, "References: ", (\refs ||:= " ") | "", id)
  5599.       every write(art, req_headers())
  5600.       write(art, "In-reply-to: ", quoter, "'s message of ", date)
  5601.       write(art, "\nIn ", id, ", ", quoter, " writes:\n")
  5602.       return 
  5603.     }
  5604.   }
  5605. end
  5606.  
  5607.     # We need a unique message-id, and a date in RFC822 format.
  5608.     # Easy with Unix systems that support `date -u'; with the
  5609.     # others, we leave the local timezone.  The first inews site
  5610.     # will correct it.
  5611.  
  5612. procedure req_headers()
  5613.  
  5614.   uniq := "<"
  5615.   &date || &clock ? while tab(upto(&digits)) do uniq ||:= tab(many(&digits))
  5616.   uniq ||:= "@" || sysname || domain || ">"
  5617.   if tz == "unix" then {
  5618.     date := pipe("date -u", "date")
  5619.     date ? {
  5620.      month := (tab(find(" ") + 1), tab(many(&letters)))
  5621.      day := (tab(upto(&digits)), tab(many(&digits)))
  5622.      time := (tab(upto(&digits++':')), tab(many(&digits++':')))
  5623.      zone := (tab(upto(&ucase)), tab(many(&ucase)))
  5624.      year := (tab(upto(&digits)+ 2), tab(0))
  5625.     }
  5626.     date := day || " " || month || " " || year ||  " " || time || " " || zone
  5627.   }
  5628.   else {
  5629.     &dateline ? {
  5630.       month := left((tab(find(" ")+1), tab(many(&letters))), 3) || " "
  5631.       date := (tab(upto(&digits)), tab(many(&digits))) || " " || month
  5632.       date ||:= (tab(upto(&digits)), right(tab(many(&digits)), 2))
  5633.     }
  5634.     date ||:= " " || &clock || " " || tz
  5635.   }
  5636.   mode ~== "local" & suspend "Message-ID: " || uniq
  5637.   suspend "Date: " || date 
  5638.   \org & suspend "Organization: " || org
  5639.   \opts["f"] & return "Followup-To: " || ((opts["f"] == "poster") | 
  5640.     validate(opts["f"], "active"))
  5641. end
  5642.  
  5643.     # Richard Goerwitz's generator.
  5644.  
  5645. procedure tempname(dir)
  5646.  
  5647.   every temp_name := dir || "article." || right(1 to 999,3,"0") do {
  5648.     close(open(temp_name)) & next
  5649.     suspend \temp_name
  5650.   }
  5651. end
  5652.  
  5653.     # On systems with pipes, pipe() will read from the first
  5654.     # successful command of the list given as arguments.
  5655.  
  5656. procedure pipe(cmd[])
  5657.  
  5658.   initial find("pipes" | "compiled", &features) | stop("No pipes.")
  5659.   while inf := open("(" || pop(cmd) || ") 2>&1", "pr") do {
  5660.     got := []
  5661.     every put(got, !inf)
  5662.     close(inf) = 0 & {
  5663.       suspend !got 
  5664.       break
  5665.     }
  5666.   }
  5667. end
  5668.  
  5669.     # The dirty work of reading from a file.
  5670.  
  5671. procedure lookup(what)
  5672.  
  5673.   inf := open(what, "r") | fail
  5674.   suspend !inf 
  5675.   close(inf)
  5676. end
  5677.  
  5678.     # Query opens stdin because the system call to the editor
  5679.     # redirects input.  The optional parameter is a default
  5680.     # response if the user answers with <return>.
  5681.  
  5682. procedure query(prompt, def)
  5683.   static stdin
  5684.  
  5685.   initial stdin := open(console)
  5686.   writes(prompt)
  5687.   ans := read(stdin)
  5688.   return (*ans = 0 & \def) | ans
  5689. end
  5690.  
  5691.     # A quick and dirty kludge.  Validate() builds a sorted list.
  5692.     # When an element is found, it is popped and the search moves
  5693.     # to the next item.  The procedure assumes the file is also
  5694.     # sorted.
  5695.  
  5696. procedure validate(what, where)
  5697.  
  5698.   mode ~== "local" & return what
  5699.   valid := &letters ++ '.-' ++ &digits
  5700.   stuff := []
  5701.   what ? while tab(upto(valid)) do put(stuff,tab(many(valid))) 
  5702.   sf := open(newslib || where) | {
  5703.     remove(tmpfile)
  5704.     stop("post: cannot open ", newslib || where)
  5705.   }
  5706.   stuff := sort(stuff)
  5707.   a := pop(stuff)
  5708.   every !sf ? match(a) & (a := pop(stuff)) | return what
  5709.   remove(tmpfile)
  5710.   stop("`", a, "' is not in ", newslib || where)
  5711. end
  5712. SHAR_EOF
  5713. if test 10945 -ne "`wc -c < 'post.icn'`"
  5714. then
  5715.     echo shar: "error transmitting 'post.icn'" '(should have been 10945 characters)'
  5716. fi
  5717. fi
  5718. if test -f 'Makefile'
  5719. then
  5720.     echo shar: "will not over-write existing file 'Makefile'"
  5721. else
  5722. cat << \SHAR_EOF > 'Makefile'
  5723. # Makefile for post
  5724.  
  5725. BINDIR= /usr/local/bin
  5726. MANDIR= /usr/man/manl
  5727. MANEXT= l
  5728.  
  5729. .SUFFIXES: .icn .u1
  5730.  
  5731. .icn.u1:
  5732.     icont -c $<
  5733.  
  5734. .icn:
  5735.     icont $@
  5736.  
  5737. #options.u1:
  5738. #    icont -c ../lib/options.icn
  5739.  
  5740. post:    post.icn options.u1
  5741.     icont $@
  5742.  
  5743. install: post post.1
  5744.     cp post $(BINDIR)
  5745.     cp post.1 $(MANDIR)/post.$(MANEXT)
  5746.  
  5747. clean:
  5748.     rm -f *.u[12]
  5749. SHAR_EOF
  5750. if test 318 -ne "`wc -c < 'Makefile'`"
  5751. then
  5752.     echo shar: "error transmitting 'Makefile'" '(should have been 318 characters)'
  5753. fi
  5754. fi
  5755. if test -f 'post.1'
  5756. then
  5757.     echo shar: "will not over-write existing file 'post.1'"
  5758. else
  5759. cat << \SHAR_EOF > 'post.1'
  5760. .\" post.man version 1.5
  5761. .\" copyright 1991 Ronald Florence
  5762. .TH POST LOCAL "2 Oct 1991"
  5763. .SH NAME
  5764. post \- news poster
  5765. .SH SYNOPSIS
  5766. .B post
  5767. [
  5768. .BI \-n\  newsgroups
  5769. ] [
  5770. .BI \-s\  subject
  5771. ] [
  5772. .BI \-d\  distribution
  5773. ] [
  5774. .BI \-f\  followup-to
  5775. ] [
  5776. .BI \-p\  quote-prefix
  5777. ] [
  5778. .B \- 
  5779. |
  5780. .I news-article
  5781. .SH DESCRIPTION
  5782. .I Post 
  5783. posts a news article to Usenet via inews, uux, or mail.  Given an
  5784. optional argument of the name of a file containing a news article, or
  5785. an argument of `\-' and a news article via stdin,
  5786. .I post
  5787. creates a follow-up article, with an attribution and quoted text.
  5788. .I Post
  5789. can be invoked as a filter from a newsreader:
  5790. .RB ` "|post \-" '
  5791. would create a followup article to the current article in the
  5792. newsreader.  The newsgroups, subject, distribution, follow-up, and
  5793. quote-prefix (the default is ` > ') can be specified on the command
  5794. line.
  5795. .PP
  5796. .I Post
  5797. is compatible with C-News, B-news, and bsnews (Bootstrap News).  On
  5798. systems with inews, the newsgroups and distribution are validated in
  5799. the appropriate news system files.
  5800. .SH ENVIRONMENT
  5801. The environment variable
  5802. .SM EDITOR 
  5803. overrides the default editor.
  5804. .SM ORGANIZATION
  5805. overrides the file /usr/lib/news/organization to specify an optional
  5806. Organization header.  On non-Unix\u\s-3TM\s0\d systems, the
  5807. environment variable
  5808. .SM HOST
  5809. may be used to override the Icon keyword
  5810. .I &host
  5811. as the sitename.
  5812. .SH BUGS
  5813. The code to validate newsgroups assumes the file
  5814. /usr/lib/news/active
  5815. is sorted.
  5816. .SH AUTHOR
  5817. Ronald Florence (ron\s-2@\s0mlfarm.com).  The code to generate a
  5818. temporary file name is from Richard Goerwitz
  5819. (goer\s-2@\s0sophist.uchicago.edu).  Options.icn is from the Icon
  5820. Program Library.
  5821. SHAR_EOF
  5822. if test 1660 -ne "`wc -c < 'post.1'`"
  5823. then
  5824.     echo shar: "error transmitting 'post.1'" '(should have been 1660 characters)'
  5825. fi
  5826. fi
  5827. exit 0
  5828. #    End of shell archive
  5829. -- 
  5830.  
  5831.                 Ronald Florence
  5832.                 ron@mlfarm.com
  5833.  
  5834. From mlfarm!ron@hsi.hsi.com  Thu Oct 10 06:09:42 1991
  5835. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Thu, 10 Oct 91 06:09:42 MST
  5836. Received: from hsi.hsi.com by optima.cs.arizona.edu (4.1/15)
  5837.     id AA28687; Thu, 10 Oct 91 06:09:35 MST
  5838. Received: by hsi.hsi.com (5.61+++/1.34)
  5839.     id AA06909; Thu, 10 Oct 91 09:07:26 -0400
  5840. Received: by rosie.mlfarm.com (4.1/SMI-4.1)
  5841.     id AA06230; Thu, 10 Oct 91 09:06:16 EDT
  5842. Date: Thu, 10 Oct 91 09:06:16 EDT
  5843. Message-Id: <9110101306.AA06230@rosie.mlfarm.com>
  5844. From: mlfarm!ron@hsi.hsi.com (Ronald Florence)
  5845. To: icon-group@cs.arizona.edu
  5846. Subject: icon-group <-> comp.lang.icon 
  5847.  
  5848. We receive both the icon-group mailing list and the comp.lang.icon
  5849. newsgroup.  We feed the newsgroup to another site.  Our own newsfeed
  5850. gets the newsgroup directly from uunet.
  5851.  
  5852. Although there has been no traffic on either the mailing list or the
  5853. newsgroup recently, I've noticed in the past that some material posted
  5854. to icon-group does not crossover to the newsgroup, although material
  5855. posted to the newsgroup makes it to the mailing list.  If anyone else
  5856. has had this experience, I'd welcome hearing from you.
  5857.  
  5858. I miss news from both.  Is Richard Goerwitz too busy for Icon these
  5859. days?  ;-)
  5860.  
  5861.                 Ronald Florence
  5862.                 ron@mlfarm.com
  5863.  
  5864. From icon-group-request@arizona.edu  Fri Oct 11 00:13:35 1991
  5865. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Fri, 11 Oct 91 00:13:35 MST
  5866. Resent-From: icon-group-request@arizona.edu
  5867. Received: from Arizona.edu (Hopey.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  5868.     id AA12682; Fri, 11 Oct 91 00:13:32 MST
  5869. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Fri, 11 Oct
  5870.  1991 00:12 MST
  5871. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA00323; Thu, 10 Oct 91
  5872.  23:58:40 -0700
  5873. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  5874.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  5875.  usenet@ucbvax.Berkeley.EDU if you have questions)
  5876. Resent-Date: Fri, 11 Oct 1991 00:13 MST
  5877. Date: 10 Oct 91 23:25:28 GMT
  5878. From: midway!ellis!goer@uunet.uu.net (Richard L. Goerwitz)
  5879. Subject: RE: icon-group <-> comp.lang.icon
  5880. Sender: icon-group-request@arizona.edu
  5881. Resent-To: icon-group@cs.arizona.edu
  5882. To: icon-group@arizona.edu
  5883. Resent-Message-Id: <E7C7EFD02EC0E391@Arizona.edu>
  5884. Message-Id: <1991Oct10.232528.16542@midway.uchicago.edu>
  5885. X-Envelope-To: icon-group@CS.Arizona.EDU
  5886. X-Vms-To: icon-group@Arizona.edu
  5887. Organization: University of Chicago
  5888. References: <9110101306.AA06230@rosie.mlfarm.com>
  5889.  
  5890. Ron@mlfarm (Ronald Florence) writes:
  5891. >
  5892. >Although there has been no traffic on either the mailing list or the
  5893. >newsgroup recently, I've noticed in the past that some material posted
  5894. >to icon-group does not crossover to the newsgroup, although material
  5895. >posted to the newsgroup makes it to the mailing list.  If anyone else
  5896. >has had this experience, I'd welcome hearing from you.
  5897. >
  5898. >I miss news from both.  Is Richard Goerwitz too busy for Icon these
  5899. >days?  ;-)
  5900.  
  5901. Never too busy to cut code, but often too busy to clean it up for
  5902. posting :o).
  5903.  
  5904. -- 
  5905.  
  5906.    -Richard L. Goerwitz              goer%sophist@uchicago.bitnet
  5907.    goer@sophist.uchicago.edu         rutgers!oddjob!gide!sophist!goer
  5908.  
  5909. From icon-group-request@arizona.edu  Sat Oct 12 15:11:11 1991
  5910. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Sat, 12 Oct 91 15:11:11 MST
  5911. Resent-From: icon-group-request@arizona.edu
  5912. Received: from Arizona.edu (Merlin.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  5913.     id AA06196; Sat, 12 Oct 91 15:11:08 MST
  5914. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Sat, 12 Oct
  5915.  1991 15:10 MST
  5916. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA09244; Sat, 12 Oct 91
  5917.  14:53:21 -0700
  5918. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  5919.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  5920.  usenet@ucbvax.Berkeley.EDU if you have questions)
  5921. Resent-Date: Sat, 12 Oct 1991 15:10 MST
  5922. Date: 12 Oct 91 18:28:46 GMT
  5923. From: midway!ellis!goer@uunet.uu.net (Richard L. Goerwitz)
  5924. Subject: windowing; an exercize
  5925. Sender: icon-group-request@arizona.edu
  5926. Resent-To: icon-group@cs.arizona.edu
  5927. To: icon-group@arizona.edu
  5928. Resent-Message-Id: <2E55FA85C0A10496@Arizona.edu>
  5929. Message-Id: <1991Oct12.182846.10147@midway.uchicago.edu>
  5930. X-Envelope-To: icon-group@CS.Arizona.EDU
  5931. X-Vms-To: icon-group@Arizona.edu
  5932. Organization: University of Chicago
  5933.  
  5934. I wrote the following code partly as an exercize, and partly as a
  5935. sub-part of a project I'm working on.  Ron had lamented the dearth
  5936. of material that's been coming in lately.  Here's something to
  5937. mull over.
  5938.  
  5939. -Richard
  5940.  
  5941. ------
  5942.  
  5943. ############################################################################
  5944. #
  5945. #    Name:     iwinds.icn
  5946. #
  5947. #    Title:     windowing routines
  5948. #
  5949. #    Author:     Richard L. Goerwitz
  5950. #
  5951. #    Version: 1.4 (a very preliminary version)
  5952. #
  5953. ############################################################################
  5954. #
  5955. #  This file contains a relatively small windowing package for use on
  5956. #  UNIX systems with an installed (and updated) Icon Program Library.
  5957. #  It will probably work under MS-DOS and other such systems as well,
  5958. #  although you'll need to read the docs for iolib.icn and iscreen.icn
  5959. #  in the IPL.  Note that some systems have problems with getchlib in
  5960. #  the IPL.  The last SunOS version did (in NFS environments).
  5961. #
  5962. #  Note:  This is not a curses clone, and it is very slow.  I was just
  5963. #  trying to decide how a windowing interface might possibly be done
  5964. #  in Icon (which has no pointers, and hence forces me to use things
  5965. #  like records and global variables where I'd like to use explicit
  5966. #  pointers to smaller data types).  It's an exercize, and I'd really
  5967. #  appreciate any advice on how to speed it up.
  5968. #
  5969. #  For those seriously interested in character-based I/O that will work
  5970. #  using stock terminals, check out the work being done by Iconic Soft-
  5971. #  ware Inc.  They have a curses interface for their Icon interpreter
  5972. #  that is terminfo based, and runs on most i386 UNIX versions.  As of
  5973. #  this writing, it's in the end stages of beta testing.
  5974. #
  5975. ############################################################################
  5976. #
  5977. #  This file contains the following routines:
  5978. #
  5979. #      createw(begy, begx, lines, cols, wmode, wchar, border, bmode)
  5980. #      exit_prog(procname, message, exit_code)
  5981. #      hidew(w)
  5982. #      movew(w, begy, begx)
  5983. #      redraw()
  5984. #      readw(w, ypos, xpos, mode)
  5985. #      getchw(w, ypos, xpos, mode)  - for no-echo, just use getch()
  5986. #      window(mode)
  5987. #      writew(w, s, pos, xpos, mode)
  5988. #
  5989. #  To initiate windowing mode one must call window() with the argu-
  5990. #  ment "on".  To end it, one must call it with the argument "off".
  5991. #  To "stop" a program while in windowing mode, call exit_prog(),
  5992. #  using the current function name as arg 1, a diagnostic message as
  5993. #  arg 2, and an exit code as arg 3.  If you don't follow this
  5994. #  protocol under UNIX, you'll find your terminal locked up in raw
  5995. #  mode.
  5996. #
  5997. #  To create a window, call createw() with the following arguments, in
  5998. #  order: 1) the beginning line and 2) the beginning column for the
  5999. #  upper left-hand square of the window; 3) the number of lines and 4)
  6000. #  columns the window occupies; if desired, you can specify a default
  6001. #  mode (5 - where 0 = normal, 1 = reverse video, 2 = underline, and 3
  6002. #  = boldface), and a default character (6).  You can, also specify
  6003. #  border (7) and a default mode for the border (8).  Note that the
  6004. #  border argument must be a string or list with 8 members,
  6005. #  corresponding to the top left, top, top right, right, bottom right,
  6006. #  bottom, bottom left, and left characters used to form the border
  6007. #  (e.g. "+-+|+-+|").
  6008. #
  6009. #  To hide a window on the screen, call hidew(w).  If you want to free
  6010. #  up the storage occupied by a window, hide it, and then set variables
  6011. #  that point to it to &null.  If you are anal-retentive, you can call
  6012. #  collect().  Hidew() fails if you try to hide _mainw, or try to hide
  6013. #  an already-hidden window.
  6014. #
  6015. #  The redraw() procedure (no arguments) redraws the entire physical
  6016. #  screen.  Movew(w, y, x) moves window w so that its upper left-hand
  6017. #  corner is at line y and column x.
  6018. #
  6019. #  Writew(w, s, y, x, mode) writes string s to window w beginning at
  6020. #  position y,x using mode as the default mode.  There is no scroll or
  6021. #  wordwrap, although writes to the bottom right corner will come back
  6022. #  around to the upper left corner.  I forget why I did things this
  6023. #  way.
  6024. #
  6025. #  Readw(w, y, x, mode) reads and returns a string, echoing it, while
  6026. #  it is being typed, to window w, starting at position y,x using mode
  6027. #  as the default mode.  If you want to do non-echoing reads, just use
  6028. #  getch().  In general, don't read &input using read(), reads(), or
  6029. #  getche() while in windowing mode.  It will look silly on the screen,
  6030. #  and if you're running under UNIX, the read functions may not work as
  6031. #  expected (remember, you're in raw mode).
  6032. #
  6033. ############################################################################
  6034. #
  6035. #  Here's a brief example of how to use this library to do pretty things
  6036. #  on the screen.  It's nothing very complicated - just some simple window
  6037. #  drawing and moving exercizes, with one window being used for a message.
  6038. #
  6039. #  # for UNIX - make sure your IPL is fully updated!
  6040. #  link iwinds, iolib, iscreen, getchlib
  6041. #
  6042. #  # non-UNIX
  6043. #  # link iwinds, iolib, iscreen (make sure you have getch())
  6044. #
  6045. #  procedure main()
  6046. #
  6047. #      # global LINES, COLS (defined in iwinds.icn)
  6048. #      local w, w2, w3, y, x
  6049. #
  6050. #      # Initiate windowing mode.
  6051. #      window("on")
  6052. #
  6053. #      # Display a 10x30 window in the upper left corner of the screen.
  6054. #      # Give it a border of spaces in reverse video mode.  Fill the box
  6055. #      # with "x" characters in normal mode.
  6056. #      w := createw(1, 1, 10, 30, 0, "x", "        ", 1)
  6057. #
  6058. #      # Now for fun, move the window just created diagonally down, until
  6059. #      # it gets to the bottom of the screen.  Be sure not to overrun the
  6060. #      # screen.
  6061. #      x := 1
  6062. #      every y := 3 to LINES - 10 by 3 do
  6063. #      movew(w, y, x +:= 6)
  6064. #
  6065. #      # Lay down a small window.
  6066. #      w2 := createw(8, 20, 3, 10, 1)
  6067. #      # Print the word "hello" in it.
  6068. #      writew(w2, "hello", 1, 1)
  6069. #
  6070. #      # Lay down a window over top of the first one.
  6071. #      w3 := createw(14, 50, 9, 30, 0, ".", "        ",1)
  6072. #
  6073. #      # Move the small window down on top of the other two.
  6074. #      x := 20
  6075. #      every y := 11 to LINES - 7 by 3 do
  6076. #      movew(w2, y, x +:= 7)
  6077. #
  6078. #      # Change the message in the little window.
  6079. #      writew(w2, "done!!  ", 1, 1, 3)
  6080. #      # Erase the two big windows.
  6081. #      hidew(w3)
  6082. #      hidew(w)
  6083. #
  6084. #      # Move the little window back up to where it started.
  6085. #      every y := y to 3 by -3 do
  6086. #        movew(w2, y, x -:= 7)
  6087. #  
  6088. #      # Quit.
  6089. #      window("off")
  6090. #      exit_prog()
  6091. #
  6092. #  end
  6093. #
  6094. ############################################################################
  6095. #
  6096. #  Links: itlib or iolib, iscreen, and some implementation of getche()
  6097. #
  6098. ############################################################################
  6099.  
  6100. # UNIX - link itlib, iscreen, getchlib
  6101.  
  6102. # for debugging purposes
  6103. # link ximage, radcon
  6104.  
  6105. global _stdscr, _mainw, isUNIX, COLS, LINES
  6106. record _square(val, over, under)
  6107. record _window(wlist, begy,begx, lines,cols, ypos,xpos, border)
  6108.  
  6109.  
  6110. procedure window(mode)
  6111.  
  6112.     #
  6113.     # Initiates/ends windowing mode.  If arg1 == "on", then windowing
  6114.     # mode is turned on; "off" does the opposite.  Returns a string
  6115.     # containing the current mode.  No arg invocation works the same,
  6116.     # except that no change occurs in the current mode.
  6117.     #
  6118.     static wmode
  6119.     #global isUNIX
  6120.     initial {
  6121.     wmode := "off"
  6122.     find("UNIX", &features) & isUNIX := "yes"
  6123.     }
  6124.  
  6125.     if /mode | (wmode === mode)
  6126.     then return wmode
  6127.     else {
  6128.     case mode of {
  6129.         "off"  : {
  6130.         \isUNIX & reset_tty()
  6131.         normal()
  6132.         iputs(igoto(getval("cm"), 1, LINES))
  6133.         }
  6134.         "on"   : {
  6135.         \isUNIX & setup_tty()
  6136.         initscr()
  6137.         }
  6138.         default: {
  6139.         exit_prog("window", "mode arg must be \"on\" or \"off\"", 11)
  6140.         }
  6141.     }
  6142.     }
  6143.  
  6144.     return wmode := mode
  6145.  
  6146. end
  6147.  
  6148.  
  6149. procedure initscr(wmode, wchar, border)
  6150.  
  6151.     #
  6152.     # Creates _stdscr, and the main window which covers the terminal
  6153.     # screen (unless TERM has am capability, i.e. won't let us write
  6154.     # to the last column without wrapping; in which case make _stdscr
  6155.     # one column narrower than the physical screen).
  6156.     #
  6157.  
  6158.     local begy, begx, ypos, xpos, default_cell, wlist, wlist2, r, c, tmp
  6159.     # global _stdscr, _mainw, COLS, LINES, isUNIX
  6160.  
  6161.     \isUNIX & setup_tty()    # initializes raw mode (see getchlib.icn)
  6162.  
  6163.     #
  6164.     # Set up default size, position, etc.
  6165.     #
  6166.     begy    := 1        # initialize variables for a single, blank
  6167.     begx    := 1        # normal-mode window starting at 1,1 that
  6168.  
  6169.     LINES   := getval("li")    # covers the entire screen
  6170.     COLS    := getval("co")
  6171.     if getval("am") then    # don't use last col if wordwrap will
  6172.     COLS -:= 1        # occur
  6173.     ypos    := 1
  6174.     xpos    := 1
  6175.    /border  := &null        # main window normally doesn't get a border
  6176.  
  6177.    /wmode   := 0        # default mode for _mainw is always 0
  6178.    /wchar   := " "        # default char for _mainw is always " "
  6179.     if 0 < *wchar < 2
  6180.     # then default_cell := -(ishift(wmode,16) + ord(wchar))
  6181.     then default_cell := -((wmode * 65536) + ord(wchar))
  6182.     else exit_prog("initscr", "wchar must be a single char or &null", 41)
  6183.  
  6184.     #
  6185.     # Create a LINES X COLS array of _square() records.
  6186.     #
  6187.     every !(wlist := list(LINES)) := list(COLS)
  6188.     every !(wlist2 := list(LINES)) := list(COLS)
  6189.     #
  6190.     # If blank spaces aren't the default, then flag each square for update.
  6191.     if wmode = 0 & wchar == " " then {
  6192.     default_cell := abs(default_cell)
  6193.     clear()
  6194.     }
  6195.     #
  6196.     every r := 1 to LINES do {
  6197.     every c := 1 to COLS do {
  6198.         tmp := _square(default_cell, &null, &null)
  6199.         wlist[r][c] := tmp
  6200.         wlist2[r][c] := tmp
  6201.     }
  6202.     }
  6203.     _mainw := _window(wlist, begy,begx, LINES,COLS, ypos,xpos, border)
  6204.     _stdscr := _window(wlist, begy,begx, LINES,COLS, ypos,xpos)
  6205.     if not (wmode = 0 & wchar == " " & /border) then
  6206.     refreshw(_mainw)
  6207.  
  6208.     return _mainw
  6209.  
  6210. end
  6211.  
  6212.  
  6213. procedure refreshw(w)
  6214.  
  6215.     #
  6216.     # Foregrounds & redraws window w on the screen.
  6217.     #
  6218.     local y, x, stdscr_y, stdscr_x, stdscr_square, window_square, oldval
  6219.  
  6220.     /w := _mainw        # _mainw is the default (covers whole screen)
  6221.  
  6222.     every y := 1 to w.lines do {
  6223.     every x := 1 to w.cols do {
  6224.  
  6225.         # Create a handle for manipulating the current square in w.
  6226.         window_square := w.wlist[y][x]
  6227.  
  6228.         # If the window isn't to be foregrounded, and the square isn't
  6229.         # visible, then skip this square.  Go right to the next one.
  6230.         if \dont_foreground then if \window_square.over then next
  6231.  
  6232.         # Calculate this square's position on _stdscr.
  6233.         stdscr_y := y + w.begy - 1
  6234.         stdscr_x := x + w.begx - 1
  6235.  
  6236.         # Create a handle for manipulating the square which previously
  6237.         # occupied the spot we're about to put the current window square
  6238.         # into.  Drop new square into the old one's spot.
  6239.         stdscr_square := _stdscr.wlist[stdscr_y][stdscr_x]
  6240.         _stdscr.wlist[stdscr_y][stdscr_x] := window_square
  6241.  
  6242.         # If window w already occupies this square in _stdscr, then
  6243.         # there's no need to reshuffle the _stdscr structure.  If w
  6244.         # does not occupy this square, though...
  6245.         if window_square ~=== stdscr_square then {
  6246.  
  6247.         # ...check to see if the window is farther down the _stdscr
  6248.         # stacks; if so, then remove it from the stack...
  6249.         if \window_square.over then {
  6250.             (\window_square.under).over := window_square.over
  6251.             window_square.over.under := window_square.under
  6252.         }
  6253.  
  6254.         # ...then push the old topmost square "down" the stack, and
  6255.         # finally place the current square on top.
  6256.         window_square.under := stdscr_square
  6257.         window_square.over := stdscr_square.over
  6258.         stdscr_square.over := window_square
  6259.         # The old square will need to be updated when it's
  6260.         # uncovered.
  6261.         oldval := stdscr_square.val
  6262.         stdscr_square.val := -abs(oldval)
  6263.         
  6264.         # Paranoid check.  The topmost member of the stack should
  6265.         # always have &null as its "over" pointer.
  6266.         # /window_square.over | {
  6267.         #    # write(&errout, "window:\n", (\ximage)(window_square))
  6268.         #    exit_prog("refreshw", "bizarre stack malformation", 21)
  6269.         # }
  6270.         }
  6271.  
  6272.         # Update the current square on the screen.  Don't bother
  6273.         # drawing it if the previous one had the same val, and it
  6274.         # wasn't flagged for update.
  6275.         if stdscr_square.val ~= window_square.val |
  6276.         ((\oldval | stdscr_square.val) \ 1) < 0
  6277.         then draw_it(window_square, stdscr_y, stdscr_x)
  6278.         else window_square.val := abs(window_square.val)
  6279.         oldval := &null
  6280.     }
  6281.     }
  6282.  
  6283.     return
  6284.  
  6285. end
  6286.  
  6287.  
  6288. procedure draw_it(sq, y, x)
  6289.  
  6290.     #
  6291.     # Draws square sq on the physical screen at y,x.
  6292.     #
  6293.     local mode
  6294.     static cm, last_mode, last_y, last_x
  6295.     # global COLS (number of columns in _stdscr)
  6296.     initial {
  6297.     cm := getval("cm")
  6298.     # initialize to impossible values
  6299.     last_mode := last_y := last_x := -1
  6300.     }
  6301.  
  6302.     # mask out update flag so this square doesn't get updated again
  6303.     sq.val := abs(sq.val)
  6304.  
  6305.     # If we aren't at the right position already, then reposition the
  6306.     # cursor manually.
  6307.     if not (y = last_y & x = (last_x + 1)) then {
  6308.         # termlib routines put x before y.
  6309.     iputs(igoto(cm, x, y))
  6310.     # If we have to reposition the cursor, reset the mode as well.
  6311.     # This may not be necessary for most terminals.  We'll see.
  6312.     # last_mode := -1
  6313.     }
  6314.     # record the position we're at
  6315.     last_y := y; last_x := x
  6316.  
  6317.     # mode is recorded in bits 16-31 of sq.val
  6318.     # mode := iand(ishift(sq.val, -16), 32767)
  6319.     mode := sq.val / 65536
  6320.     # If there's been a mode change since the last square was written,
  6321.     # or if the cursor's been repositioned, or if we're at the start
  6322.     # of a line, then reset the mode.
  6323.     if (last_mode ~=:= mode) | (y = 1) then {
  6324.     case mode of {
  6325.         0 : normal()
  6326.         1 : emphasize()
  6327.         2 : underline()
  6328.         3 : boldface()
  6329.         4 : blink()
  6330.         default : {
  6331.         # write(&errout, "mode for ", y, ",", x, " = ", mode)
  6332.         normal()
  6333.         }
  6334.     }
  6335.     }
  6336.  
  6337.     # Turn lower 16 bits of sq.val into a character.  8 bits is
  6338.     # the usual now, but soon it'll be 16 bits for characters (I
  6339.     # hope).
  6340.     return writes(char(iand(sq.val, 65535)))
  6341.  
  6342. end
  6343.  
  6344.  
  6345. procedure hidew(w)
  6346.  
  6347.     #
  6348.     # Foregrounds & redraws window w on the screen.
  6349.     #
  6350.     local y, x, stdscr_y, stdscr_x, window_square
  6351.  
  6352.     w === _mainw & fail        # can't hide main window
  6353.     # window is already hidden if over and under pointers are null
  6354.     /w.wlist[1][1].over & /w.wlist[1][1].under & fail
  6355.  
  6356.     every y := 1 to w.lines do {
  6357.     every x := 1 to w.cols do {
  6358.  
  6359.         # Create a handle for manipulating the current square in w.
  6360.         window_square := w.wlist[y][x]
  6361.  
  6362.         # If the over pointer is nonnull, then we're not on top
  6363.         # of the stack for position y,x.
  6364.         if \window_square.over then {
  6365.         # So link the record underneath (if there is one) to
  6366.         # the one on top; link the one on top to the one
  6367.         # underneath (to &null if there isn't one underneath).
  6368.         (\window_square.under).over := window_square.over
  6369.         window_square.over.under := window_square.under
  6370.         }
  6371.  
  6372.         # Over pointer is null, but under pointer is not, so the
  6373.         # square is on-screen at _stdscr.wlist[stdscr_y][stdscr_x].
  6374.         # Remove it; make _stdscr.wlist[stdscr_y][stdscr_x] point
  6375.         # to window_square.under.  Set window_square.under.over to
  6376.         # &null to indicate that it is now on the top of the stack.
  6377.         else {
  6378.         window_square.under.over := &null
  6379.         stdscr_y := y + w.begy - 1
  6380.         stdscr_x := x + w.begx - 1
  6381.         _stdscr.wlist[stdscr_y][stdscr_x] := window_square.under
  6382.         if window_square.val ~= window_square.under.val |
  6383.             window_square.val < 0
  6384.         then draw_it(window_square.under, stdscr_y, stdscr_x)
  6385.         else window_square.val := abs(window_square.val)
  6386.         }
  6387.         window_square.over := &null
  6388.         window_square.under := &null
  6389.  
  6390.         # Paranoid check.  The topmost member of the stack should
  6391.         # always have &null as its "over" pointer.
  6392.         # /(((_stdscr.wlist)[stdscr_y][stdscr_x]).over) | {
  6393.         #    write(&errout,"window:\n",
  6394.         #          (\ximage)(_stdscr.wlist[stdscr_y][stdscr_x].over))
  6395.         #    exit_prog("hidew", "bizarre stack malformation", 21)
  6396.         # }
  6397.     }
  6398.     }
  6399.  
  6400.     return
  6401.  
  6402. end
  6403.  
  6404.  
  6405. procedure createw(begy, begx, lines, cols, wmode, wchar, border, bmode)
  6406.  
  6407.     #
  6408.     # Creates a new window with the upper left corner at begy,begx, and
  6409.     # a size of lines,cols, a default mode of wmode, and a default fill
  6410.     # char of wchar; a border is drawn if border is nonnull.
  6411.     #
  6412.     local default_cell, wlist, r, c, w
  6413.  
  6414.     if /(begy | begx | lines | cols) then
  6415.     exit_prog("createw", "first four arguments must all be nonnull", 31)
  6416.  
  6417.    /wmode   := 0        # default mode is 0 (normal)
  6418.    /wchar   := " "        # default char is a space
  6419.     # default_cell := -(ishift(wmode,16) + ord(wchar))
  6420.     default_cell := -((wmode * 65536) + ord(wchar))
  6421.    /border  := &null
  6422.  
  6423.     #
  6424.     # Create a lines X cols array of _square() records.
  6425.     #
  6426.     every !(wlist := list(LINES)) := list(COLS)
  6427.     every !(wlist2 := list(LINES)) := list(COLS)
  6428.     #
  6429.     every r := 1 to lines do
  6430.     every c := 1 to cols do
  6431.         wlist[r][c] := _square(default_cell, &null, &null)
  6432.  
  6433.     w := _window(wlist, begy,begx, lines, cols, ypos,xpos, border)
  6434.     make_border(w, \border, \bmode | wmode)
  6435.     refreshw(w)
  6436.  
  6437.     return w
  6438.  
  6439. end
  6440.  
  6441.  
  6442. procedure redraw()
  6443.  
  6444.     #
  6445.     # Simple redraw of the entire screen.
  6446.     #
  6447.     local r, c
  6448.     #global LINES, COLS
  6449.  
  6450.     # clear()
  6451.     every r := _stdscr.begy to LINES do {
  6452.     every c := _stdscr.begx to COLS do {
  6453.         draw_it(_stdscr.wlist[r][c], r, c)
  6454.     }
  6455.     }
  6456.  
  6457.     return "screen redrawn"
  6458.  
  6459. end
  6460.  
  6461.  
  6462. procedure movew(w, begy, begx)
  6463.  
  6464.     local wlist, wlist2, y, x, w2, window_square
  6465.  
  6466.     w === _mainw & fail        # can't move main window
  6467.  
  6468.     /begy | /begx &
  6469.     exit_prog("movew","null argument 2 and/or 3!",61)
  6470.     wlist  := w.wlist
  6471.     wlist2 := list(w.lines)
  6472.     every (!wlist2) := list(w.cols)
  6473.  
  6474.     every y := 1 to w.lines do {
  6475.     every x := 1 to w.cols do {
  6476.         window_square := (wlist2[y][x] := copy(wlist[y][x]))
  6477.         window_square.val := -abs(window_square.val)
  6478.         window_square.over := &null
  6479.         window_square.under := &null
  6480.     }
  6481.     }
  6482.     w2 := copy(w)
  6483.     w2.wlist := wlist2
  6484.     w2.begy := begy
  6485.     w2.begx := begx
  6486.     refreshw(w2)
  6487.  
  6488.     hidew(w)
  6489.     w.wlist := wlist2
  6490.     w.begy := begy
  6491.     w.begx := begx
  6492.  
  6493.     return
  6494.  
  6495. end
  6496.  
  6497.  
  6498. procedure make_border(w, border, mode)
  6499.  
  6500.     local ulc, uc, urc, rc, brc, bc, blc, lc
  6501.  
  6502.     # mode := ishift(\mode, 16) | 0
  6503.     mode := (\mode * 65536) | 0
  6504.  
  6505.     if type(border) === ("list"|"string") then {
  6506.     *border = 8 | exit_prog("make_border", "*border must be 8", 41)
  6507.     ulc := -(mode + ord(border[1]))
  6508.     uc  := -(mode + ord(border[2]))
  6509.     urc := -(mode + ord(border[3]))
  6510.     rc  := -(mode + ord(border[4]))
  6511.     brc := -(mode + ord(border[5]))
  6512.     bc  := -(mode + ord(border[6]))
  6513.     blc := -(mode + ord(border[7]))
  6514.     lc  := -(mode + ord(border[8]))
  6515.     }
  6516.     else {
  6517.     ulc := -(mode + ord("+"))
  6518.     uc  := -(mode + ord("-"))
  6519.     urc := -(mode + ord("+"))
  6520.     rc  := -(mode + ord("|"))
  6521.     brc := -(mode + ord("+"))
  6522.     bc  := -(mode + ord("-"))
  6523.     blc := -(mode + ord("+"))
  6524.     lc  := -(mode + ord("|"))
  6525.     }
  6526.     w.border := [ulc, uc, urc, rc, brc, bc, blc, lc]
  6527.  
  6528.     # Now draw in all the appropriate charcters.  Be sure to check
  6529.     # whether the window is big enough!
  6530.     w.wlist[1][1].val := ulc
  6531.     every x := 2 to w.cols-1 do {
  6532.     w.wlist[1][x].val := uc
  6533.     w.wlist[w.lines][x].val := bc
  6534.     }
  6535.     w.wlist[1][w.cols].val := urc
  6536.     w.wlist[w.lines][w.cols].val := brc
  6537.     every y := 2 to w.lines-1 do {
  6538.     w.wlist[y][w.cols].val := rc
  6539.     w.wlist[y][1].val := lc
  6540.     }
  6541.     w.wlist[w.lines][1].val := blc
  6542.  
  6543.     return w.border
  6544.  
  6545. end
  6546.     
  6547.  
  6548. procedure writew(w, s, y, x, mode)
  6549.  
  6550.     local begy, begx, maxy, maxx, stdscr_square, newval
  6551.     static controls, spaces
  6552.     initial {
  6553.     controls := ""
  6554.     every controls ||:= char((0 to 7) | 9 | 11 | 12 | (14 to 31))
  6555.     spaces := repl(" ", *controls)
  6556.     # write(&errout, image(controls))
  6557.     }
  6558.  
  6559.     begy := 1
  6560.     begx := 1
  6561.     maxy := w.lines
  6562.     maxx := w.cols
  6563.     ypos := \y | w.ypos
  6564.     xpos := \x | w.xpos
  6565.     # see below on mode
  6566.  
  6567.     if \w.border then {
  6568.     # just in case it's forgotten that there's a border, and an
  6569.     # attempt is made to write to spaces occupied by the border
  6570.     ypos <= begy & ypos := 2
  6571.     ypos >= maxy & ypos := 2 & xpos := 2
  6572.     xpos <= begx | xpos >= maxx & xpos := 2
  6573.     # reset boundaries to account for the smaller available space
  6574.     begy +:= 1
  6575.     begx +:= 1
  6576.     maxy -:= 1
  6577.     maxx -:= 1
  6578.     }
  6579.  
  6580.     begy <= ypos <= maxy | begx <= xpos <= maxx |
  6581.     exit_prog("writew", "coordinate out of range: "||ypos||","||xpos, 51)
  6582.     # Reposition the cursor.
  6583.     iputs(igoto(getval("cm"), xpos + w.begx - 1, ypos + w.begy - 1))
  6584.  
  6585.     s := map(s, controls, spaces)
  6586.     # write(&errout, image(s))
  6587.     # mode := ishift(\mode, 16)
  6588.     mode := (\mode * 65536)
  6589.     every c := !s do {
  6590.  
  6591.     # write(&errout, image(c))
  6592.     if any('\n\r', c) then {
  6593.         ypos +:= 1
  6594.         xpos := begx - 1
  6595.     } else {
  6596.         if c == "\b" then {
  6597.         (begx <= (xpos <- (xpos - 1))) | next
  6598.         writew(w, " ", ypos, xpos, mode, "immediate")
  6599.         iputs(igoto(getval("cm"), xpos + w.begx - 1, ypos + w.begy- 1))
  6600.         next
  6601.         }
  6602.         # write(&errout,
  6603.         #      "old char cell ",radcon(w.wlist[ypos][xpos].val,10,2))
  6604.         stdscr_square := w.wlist[ypos][xpos]
  6605.         newval :=
  6606.         (\mode | iand(abs(w.wlist[ypos][xpos].val),2147418112))+ ord(c)
  6607.         if stdscr_square.val < 0 | stdscr_square.val ~= newval then {
  6608.         stdscr_square.val := -newval
  6609.         if /stdscr_square.over then
  6610.             draw_it(stdscr_square, ypos+w.begy - 1, xpos+w.begx - 1)
  6611.         }
  6612.         else stdscr_square.val := newval
  6613.         # write(&errout, "mode = ", radcon(\mode,10,2))
  6614.         # write(&errout,
  6615.         #      "char cell = ", radcon(w.wlist[ypos][xpos].val, 10, 2))
  6616.     }
  6617.     ypos > maxy & ypos := begy & xpos := begx
  6618.     xpos < maxx & xpos +:= 1
  6619.     }
  6620.  
  6621.     w.ypos := ypos
  6622.     w.xpos := xpos
  6623.  
  6624.     return
  6625.  
  6626. end
  6627.  
  6628.  
  6629. procedure readw(w, y, x, mode)
  6630.  
  6631.     #
  6632.     # Reads a string from window w, at pos y,x within that window,
  6633.     # echoing the string to the screen.  Characters get echoed as
  6634.     # they are typed.  Terminates on a CR or LF & returns the string
  6635.     # just read (minus the CR/LF).
  6636.     #
  6637.     local chr, s
  6638.  
  6639.     # Move the cursor to the spot we're to start reading at.
  6640.     writew(w, "", y, x, mode)
  6641.     # Check to be sure this square is visible on the screen.
  6642.     /_stdscr.wlist[y + w.begy - 1][x + w.begx - 1].over | {
  6643.     write(&errout, "error (readw):  square isn't visible")
  6644.     fail
  6645.     }
  6646.  
  6647.     s := ""
  6648.     repeat {
  6649.     case chr := getch() | fail of {
  6650.         "\r"|"\n" : return s
  6651.         (\c_cc).vkill : {
  6652.         if *s < 1 then next
  6653.         every 1 to *s do writew(w,"\b",,,mode)
  6654.         s := ""
  6655.         }
  6656.         "\b" : {
  6657.         if *s < 1 then next
  6658.         writew(w,"\b",,,mode)
  6659.         s := s[1:-1]
  6660.         }
  6661.         default : {
  6662.         writew(w,chr,,,mode)
  6663.         s ||:= chr
  6664.         }
  6665.     }
  6666.     }
  6667.  
  6668.  
  6669. end
  6670.  
  6671.  
  6672. procedure getchw(w, y, x, mode)
  6673.  
  6674.     #
  6675.     # Reads a string from window w, at pos y,x within that window,
  6676.     # echoing the string to the screen.  Characters get echoed as
  6677.     # they are typed.  Terminates on a CR or LF & returns the string
  6678.     # just read (minus the CR/LF).
  6679.     #
  6680.     local chr, s
  6681.  
  6682.     # Move the cursor to the spot we're to start reading at.
  6683.     writew(w, "", y, x, mode)
  6684.  
  6685.     # Check to be sure this square is visible on the screen.
  6686.     /_stdscr.wlist[y + w.begy - 1][x + w.begx - 1].over | {
  6687.     write(&errout, "error (getchw):  square isn't visible")
  6688.     fail
  6689.     }
  6690.     chr := getch() | fail
  6691.     writew(w,chr,,,mode)
  6692.     return chr
  6693.  
  6694. end
  6695.  
  6696.  
  6697. procedure exit_prog(func, msg, errcode)
  6698.  
  6699.     #
  6700.     # Program termination utility.  Prints error message "msg" for
  6701.     # function "func," resets the terminal, then aborts with exit code
  6702.     # "errcode."  For normal exits, call exit_prog() without any args.
  6703.     #
  6704.     # global LINES
  6705.  
  6706.     func := " (" || (trim(\func, ': ') || "):  ") | ":  "
  6707.     write(&errout, "error", func, \msg)
  6708.     window("off")
  6709.     normal(); clear()
  6710.     iputs(igoto(getval("cm"), 1, LINES-1))
  6711.     exit(errcode)        # abort program with exit code errcode
  6712.  
  6713. end
  6714. -- 
  6715.  
  6716.    -Richard L. Goerwitz              goer%sophist@uchicago.bitnet
  6717.    goer@sophist.uchicago.edu         rutgers!oddjob!gide!sophist!goer
  6718.  
  6719. From icon-group-request@arizona.edu  Sat Oct 12 22:24:12 1991
  6720. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Sat, 12 Oct 91 22:24:12 MST
  6721. Resent-From: icon-group-request@arizona.edu
  6722. Received: from Arizona.edu (Hopey.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  6723.     id AA14839; Sat, 12 Oct 91 22:24:10 MST
  6724. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Sat, 12 Oct
  6725.  1991 22:23 MST
  6726. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA26112; Sat, 12 Oct 91
  6727.  22:10:01 -0700
  6728. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  6729.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  6730.  usenet@ucbvax.Berkeley.EDU if you have questions)
  6731. Resent-Date: Sat, 12 Oct 1991 22:23 MST
  6732. Date: 13 Oct 91 03:53:54 GMT
  6733. From: cis.ohio-state.edu!zaphod.mps.ohio-state.edu!mips!atha!aunro!ersys!arktik@ucbvax.berkeley.edu
  6734.  (Ryan Daum)
  6735. Subject: Icon sources.
  6736. Sender: icon-group-request@arizona.edu
  6737. Resent-To: icon-group@cs.arizona.edu
  6738. To: icon-group@arizona.edu
  6739. Resent-Message-Id: <6AD47F174EC0D8B8@Arizona.edu>
  6740. Message-Id: <J1Lq02w164w@ersys.edmonton.ab.ca>
  6741. X-Envelope-To: icon-group@CS.Arizona.EDU
  6742. X-Vms-To: icon-group@Arizona.edu
  6743. Organization: Edmonton Remote Systems, Edmonton, AB, Canada
  6744.  
  6745. Where are Icon sources available?  What about tutorials, libraries, etc?
  6746.  
  6747.  
  6748. --------------------------------------------------------------------------
  6749.   arktik@ersys.edmonton.ab.ca -- Ryan Werner Daum -- "A man leaves his
  6750. ----------------------------------------------------  impress on life and
  6751.  Opiate on LambdaMOO ... Epicurus on DikuMUD      --  outside of that 
  6752.  Citadels, TinyMUCKS                              --  there is nothing."
  6753. ---------------------------------------------------- Jean-Paul Satre
  6754.  
  6755. From icon-group-request@arizona.edu  Mon Oct 14 11:45:22 1991
  6756. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Mon, 14 Oct 91 11:45:22 MST
  6757. Resent-From: icon-group-request@arizona.edu
  6758. Received: from Arizona.edu (Merlin.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  6759.     id AA08438; Mon, 14 Oct 91 11:45:20 MST
  6760. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Mon, 14 Oct
  6761.  1991 11:44 MST
  6762. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA16171; Mon, 14 Oct 91
  6763.  11:41:02 -0700
  6764. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  6765.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  6766.  usenet@ucbvax.Berkeley.EDU if you have questions)
  6767. Resent-Date: Mon, 14 Oct 1991 11:45 MST
  6768. Date: 14 Oct 91 15:37:12 GMT
  6769. From: midway!quads!goer@handies.ucar.edu (Richard L. Goerwitz)
  6770. Subject: RE: windowing; an exercize
  6771. Sender: icon-group-request@arizona.edu
  6772. Resent-To: icon-group@cs.arizona.edu
  6773. To: icon-group@arizona.edu
  6774. Resent-Message-Id: <A3EA97D95AA09C1A@Arizona.edu>
  6775. Message-Id: <1991Oct14.153712.15751@midway.uchicago.edu>
  6776. X-Envelope-To: icon-group@CS.Arizona.EDU
  6777. X-Vms-To: icon-group@Arizona.edu
  6778. Organization: University of Chicago
  6779. References: <1991Oct12.182846.10147@midway.uchicago.edu>,
  6780.  <1991Oct14.001550.21718@mlfarm.com>
  6781.  
  6782. In <1991Oct14.001550.21718@mlfarm.com> ron@mlfarm.com (Ronald Florence) writes:
  6783. >Richard L. Goerwitz writes:
  6784. >
  6785. >   #  Note:  This is not a curses clone, and it is very slow.  I was just
  6786. >   #  trying to decide how a windowing interface might possibly be done
  6787. >   #  in Icon (which has no pointers, and hence forces me to use things
  6788. >   #  like records and global variables where I'd like to use explicit
  6789. >   #  pointers to smaller data types).  It's an exercize, and I'd really
  6790. >   #  appreciate any advice on how to speed it up.
  6791. >
  6792. >My hunch is that the speed cannot be increased appreciably by refinements
  6793. >of the code; the slowness is a necessary consequence of character-based
  6794. >output and an interpreted language.
  6795. >
  6796. >I wonder whether there isn't a way to accomplish this kind of
  6797. >windowing through external bitblit functions called from Icon.
  6798. >Linking the Icon to X-windows functions for Unix systems, or a
  6799. >comparable interface (I confess ignorance) for ms-dos, might provide a
  6800. >quick and versatile screen display, while allowing the coder to write
  6801. >with the economy of Icon.  Is this possible?  Is anyone working on
  6802. >this sort of approach?
  6803.  
  6804. Oh, yes.  I'm not the one doing it, but the work is happening.  A company
  6805. called Iconic Software Inc. is working on (actually, almost done) a SYSV
  6806. r{3,4}/{3,4}86-based system which provides Icon programmers high-level ac-
  6807. cess functions to curses and ETI functions.  There have also been several
  6808. individuals who have expressed interest in setting up an X interface, and
  6809. I understand that substantial work has been done in this area already (not
  6810. ready for release, though).  Of course, ProIcon has a set of windowing
  6811. tools built into it (ProIcon is a commercial Mac implementation of Icon).
  6812.  
  6813. About the speed of the package:  I note that the character-based I/O is
  6814. not the worst bottleneck.  Actually, the sample file I posted does a lot
  6815. of internal optimization (e.g. when a window is [re]drawn, only those
  6816. squares that need to be updated are actually placed on the screen).  The
  6817. odd thing is that it's the internal machinations that take the time, and
  6818. not so much the actual interaction with the terminal.  I gather you under-
  6819. stood this, Ron.  So I'd just modify your statement that the problem is
  6820. one of character-based I/O in an interpreted system to say merely that the
  6821. problem is simply one inherent in interpreted systems.  LISP programmers
  6822. have the same problems when writing systems like emacs (the code for which
  6823. has to be done largely in C).
  6824.  
  6825. I tried compiling the program, incidentally, using the experimental com-
  6826. piler available on cs.arizona.edu.  I was unable to get it compiled with
  6827. the optimizations (I waited 10 minutes, and when no C code got generated,
  6828. I gave up).  With all the optimizations turned off, iolib (from the IPL)
  6829. did not work correctly.  What I wanted to do was see how much of a per-
  6830. formance difference I could get with the compiler.  I'd guess it would be
  6831. significant.  Would it be significant enough to make the performance ac-
  6832. ceptable?  I don't know.
  6833.  
  6834. One other big problem is the space that gets used.  As I noted in the
  6835. paragraph you quoted above, I had to coopt much larger data types than I
  6836. wanted to, and access them in clumsy ways.  This is not to say that Icon
  6837. should have explicit pointer semantics - which would create all kinds of com-
  6838. plications.  My guess is that most of what is needed could be accomplished
  6839. by using a call-by-reference mechanism - say some sort of mechanism like the
  6840. "var" parameters of Pascal.
  6841.  
  6842. If a language is going to be able to be used as a production system, I'd
  6843. say it needs some way of presenting a user interface, and that the interface
  6844. should be well integrated into the rest of the language.  The demo I posted
  6845. was just a primitive attempt on my part to see what opinions other people
  6846. had about things like interfaces, interface types, interpreted languages,
  6847. pointer semantics, and what not.
  6848.  
  6849. One thing I want to avoid doing is making this into a kind of "what's wrong
  6850. with Icon" discussion, because Icon (as it is) is a very clean and useful
  6851. language.  And it's PD.  And the distribution is relatively bug-free.  I'd
  6852. just be curious what people think about what a reasonable Iconish interface
  6853. would look like.  In my case, an X interface is totally uninteresting, be-
  6854. cause it's single-platform, and X itself is *huge*.  Just huge.  Unless a
  6855. fairy from heaven comes down and doubles my mass storage resources, I can't
  6856. reasonably talk about anything other than character-based I/O.
  6857.  
  6858. -- 
  6859.  
  6860.    -Richard L. Goerwitz              goer%sophist@uchicago.bitnet
  6861.    goer@sophist.uchicago.edu         rutgers!oddjob!gide!sophist!goer
  6862.  
  6863. From cjeffery  Mon Oct 14 13:05:30 1991
  6864. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Mon, 14 Oct 91 13:05:30 MST
  6865. Resent-From: "Clinton Jeffery" <cjeffery>
  6866. Received: from Arizona.edu (Hopey.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  6867.     id AA16549; Mon, 14 Oct 91 13:05:28 MST
  6868. Received: from optima.cs.arizona.edu by Arizona.edu with PMDF#10282; Mon, 14
  6869.  Oct 1991 13:04 MST
  6870. Received: from cheltenham.cs.arizona.edu by optima.cs.arizona.edu (4.1/15) id
  6871.  AA16426; Mon, 14 Oct 91 13:04:30 MST
  6872. Received: by cheltenham.cs.arizona.edu; Mon, 14 Oct 91 13:04:28 MST
  6873. Resent-Date: Mon, 14 Oct 1991 13:05 MST
  6874. Date: Mon, 14 Oct 91 13:04:28 MST
  6875. From: "Clinton L. Jeffery" <cjeffery@cs.arizona.edu>
  6876. Subject: windowing; an exercize
  6877. In-Reply-To: Richard L. Goerwitz's message of 14 Oct 91 15:37:12 GMT
  6878.  <1991Oct14.153712.15751@midway.uchicago.edu>
  6879. Resent-To: icon-group@cs.arizona.edu
  6880. To: icon-group@arizona.edu
  6881. Resent-Message-Id: <AF1AD8990022361F@Arizona.edu>
  6882. Message-Id: <9110142004.AA20060@cheltenham.cs.arizona.edu>
  6883. X-Envelope-To: icon-group@CS.Arizona.EDU
  6884. X-Vms-To: icon-group@Arizona.edu
  6885.  
  6886. ****>>Ronald Florence by Richard Goerwitz as saying:
  6887. >>Linking the Icon to X-windows functions for Unix systems, or a
  6888. >>comparable interface (I confess ignorance) for ms-dos, might provide a
  6889. >>quick and versatile screen display, while allowing the coder to write
  6890. >>with the economy of Icon.  Is this possible?  Is anyone working on
  6891. >>this sort of approach?
  6892.  
  6893. ****>To which Richard replied to all of us:
  6894. >There have also been several
  6895. >individuals who have expressed interest in setting up an X interface, and
  6896. >I understand that substantial work has been done in this area already (not
  6897. >ready for release, though).  Of course, ProIcon has a set of windowing
  6898. >tools built into it (ProIcon is a commercial Mac implementation of Icon).
  6899.  
  6900. An X interface for Icon has been described in the '91 ICEBOL Proceedings and
  6901. in UA Department of CS Technical Report #91-1.  Unlike the other "windowing"
  6902. tools mentioned in the current discussion, X-Icon allows easy access to
  6903. graphics, colors, fonts, and mouse input.  Icon adds quite a bit of leverage
  6904. in writing X applications and thanks to the Icon interpreter, X-Icon binaries
  6905. are incredibly tiny compared to C-based X applications.
  6906.  
  6907. >In my case, an X interface is totally uninteresting, be-
  6908. >cause it's single-platform, and X itself is *huge*.
  6909.  
  6910. Richard is right that X is huge; one generally needs a UNIX system with a
  6911. spare 20 megabytes as a bare minimum, and this will exclude some people for
  6912. another few years as disk prices continue to drop.
  6913.  
  6914. But in discussing language designs to support user-interface programming I
  6915. don't see why a character-based interface can't be a compatible subset of a
  6916. graphical interface--allowing character-based applications to run in either
  6917. context.  For this reason I hope people writing user interface libraries
  6918. will be interested in each other's designs and I think discussion would be
  6919. fruitful.
  6920.  
  6921. From icon-group-request@arizona.edu  Tue Oct 15 01:49:52 1991
  6922. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Tue, 15 Oct 91 01:49:52 MST
  6923. Resent-From: icon-group-request@arizona.edu
  6924. Received: from Arizona.edu (Hopey.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  6925.     id AA02327; Tue, 15 Oct 91 01:49:47 MST
  6926. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Tue, 15 Oct
  6927.  1991 01:49 MST
  6928. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA11967; Tue, 15 Oct 91
  6929.  01:43:14 -0700
  6930. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  6931.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  6932.  usenet@ucbvax.Berkeley.EDU if you have questions)
  6933. Resent-Date: Tue, 15 Oct 1991 01:49 MST
  6934. Date: 15 Oct 91 07:36:36 GMT
  6935. From: midway!quads!goer@handies.ucar.edu (Richard L. Goerwitz)
  6936. Subject: iwinds, part 4 of 4
  6937. Sender: icon-group-request@arizona.edu
  6938. Resent-To: icon-group@cs.arizona.edu
  6939. To: icon-group@arizona.edu
  6940. Resent-Message-Id: <19E109C648A11996@Arizona.edu>
  6941. Message-Id: <1991Oct15.073636.24919@midway.uchicago.edu>
  6942. X-Envelope-To: icon-group@CS.Arizona.EDU
  6943. X-Vms-To: icon-group@Arizona.edu
  6944. Organization: University of Chicago
  6945. References: <1991Oct15.073456.24722@midway.uchicago.edu>
  6946.  
  6947.  
  6948. ---- Cut Here and feed the following to sh ----
  6949. #!/bin/sh
  6950. # this is iwinds.04 (part 4 of a multipart archive)
  6951. # do not concatenate these parts, unpack them in order with /bin/sh
  6952. # file getchlib.icn continued
  6953. #
  6954. if test ! -r _shar_seq_.tmp; then
  6955.     echo 'Please unpack part 1 first!'
  6956.     exit 1
  6957. fi
  6958. (read Scheck
  6959.  if test "$Scheck" != 4; then
  6960.     echo Please unpack part "$Scheck" next!
  6961.     exit 1
  6962.  else
  6963.     exit 0
  6964.  fi
  6965. ) < _shar_seq_.tmp || exit 1
  6966. if test ! -f _shar_wnt_.tmp; then
  6967.     echo 'x - still skipping getchlib.icn'
  6968. else
  6969. echo 'x - continuing file getchlib.icn'
  6970. sed 's/^X//' << 'SHAR_EOF' >> 'getchlib.icn' &&
  6971. X#  than it is under, say, MS-DOS.  This library represents one,
  6972. X#  solution to the problem - one which can be run as a library, and
  6973. X#  need not be compiled into the run-time system.  Note that it will
  6974. X#  not work on all systems.  In particular, certain Suns (with a
  6975. X#  screwy stty command) and the NeXT 1.0 OS (lacking the -g option for
  6976. X#  stty) do not run getchlib properly.  See the bugs section below for
  6977. X#  workarounds.
  6978. X#
  6979. X#  Four basic utilities are included here:
  6980. X#
  6981. X#    getch()        - waits until a keystroke is available &
  6982. X#        returns it without displaying it on the screen
  6983. X#    getche()    - same as getch() only with echo
  6984. X#    getse(s)    - like getche() only for strings.  The optional
  6985. X#        argument s gives getse() something to start with.  Use this
  6986. X#           if, say, you want to read single characters in cbreak mode,
  6987. X#           but get more input if the character read is the first part
  6988. X#           of a longer command.  If the user backspaces over everything
  6989. X#           that has been input, getse() fails.  Returns on \r or \n.
  6990. X#    reset_tty()    - absolutely vital routine for putting the cur-
  6991. X#           rent tty line back into cooked mode; call it before exiting
  6992. X#           or you will find yourself with a locked-up terminal; use it
  6993. X#           also if you must temporarily restore the terminal to cooked
  6994. X#           mode
  6995. X#
  6996. X#  Note that getse() *must* be used in place of read(&input) if you
  6997. X#  are planning on using getch() or getche(), since read(&input)
  6998. X#  assumes a tty with "sane" settings.
  6999. X#
  7000. X#  Warning:  The routines below do not do any sophisticated output
  7001. X#  processing.  As noted above, they also put your tty line in raw
  7002. X#  mode.  I know, I know:  "Raw is overkill - use cbreak."  But in
  7003. X#  a world that includes SysV, one must pick a lowest common denomi-
  7004. X#  nator.  And no, icanon != cbreak.
  7005. X#
  7006. X#  BUGS: These routines will not work on systems that do not imple-
  7007. X#  ment the -g option for the stty command.  The NeXT workstation is
  7008. X#  an example of such a system.  Tisk, tisk.  If you are on a BSD
  7009. X#  system where the network configuration makes stty | more impossible,
  7010. X#  then substitute /usr/5bin/stty (or whatever your system calls the
  7011. X#  System V stty command) for /bin/stty in this file.  If you have no
  7012. X#  SysV stty command online, then you can try replacing every instance
  7013. X#  of "stty -g 2>&1" below with "stty -g 2>&1 1> /dev/tty" or
  7014. X#  something similar.
  7015. X#
  7016. X############################################################################
  7017. X#
  7018. X#  Example program:
  7019. X#
  7020. X#      The following program is a simple file viewer.  To run, it
  7021. X#  needs to be linked with itlib.icn, iscreen.icn, and this file
  7022. X#  (getchlib.icn).
  7023. X#
  7024. X#  procedure main(a)
  7025. X#
  7026. X#      # Simple pager/file searcher for Unix systems.  Must be linked
  7027. X#      # with itlib.icn and iscreen.icn.
  7028. X#  
  7029. X#      local intext, c, s
  7030. X#  
  7031. X#      # Open input file
  7032. X#      intext := open(a[1],"r") | {
  7033. X#      write(&errout,"Can't open input file.")
  7034. X#      exit(1)
  7035. X#      }
  7036. X#  
  7037. X#      # Initialize screen
  7038. X#      clear()
  7039. X#      print_screen(intext) | exit(0)
  7040. X#  
  7041. X#      # Prompt & read input
  7042. X#      repeat {
  7043. X#      iputs(igoto(getval("cm"), 1, getval("li")))
  7044. X#      emphasize()
  7045. X#      writes("More? (y/n or /search):")
  7046. X#      write_ce(" ")
  7047. X#      case c := getche() of {
  7048. X#          "y" : print_screen(intext) | break
  7049. X#          " " : print_screen(intext) | break
  7050. X#          "n" : break
  7051. X#          "q" : break
  7052. X#          "/" : {
  7053. X#          iputs(igoto(getval("cm"), 1, getval("li")))
  7054. X#          emphasize()
  7055. X#          writes("Enter search string:")
  7056. X#          write_ce(" ")
  7057. X#          pattern := GetMoreInput()
  7058. X#          /pattern | "" == pattern & next
  7059. X#          # For more complex patterns, use findre() (IPL findre.icn)
  7060. X#          if not find(pattern, s := !intext) then {
  7061. X#              iputs(igoto(getval("cm"), 1, getval("li")))
  7062. X#              emphasize()
  7063. X#              write_ce("String not found.")
  7064. X#              break
  7065. X#          }
  7066. X#          else print_screen(intext, s) | break
  7067. X#          }
  7068. X#      }
  7069. X#      }
  7070. X#  
  7071. X#      reset_tty()
  7072. X#      write()
  7073. X#      exit(0)
  7074. X#
  7075. X#  end
  7076. X#  
  7077. X#  procedure GetMoreInput(c)
  7078. X#  
  7079. X#      local input_string
  7080. X#      static BS
  7081. X#      initial BS := getval("bc") | "\b"
  7082. X#  
  7083. X#      /c := ""
  7084. X#      if any('\n\r', chr := getch())
  7085. X#      then return c
  7086. X#      else {
  7087. X#      chr == BS & fail
  7088. X#      writes(chr)
  7089. X#      input_string := getse(c || chr) | fail
  7090. X#      if any('\n\r', input_string)
  7091. X#      then fail else (return input_string)
  7092. X#      }
  7093. X#  
  7094. X#  end
  7095. X#  
  7096. X#  procedure print_screen(f,s)
  7097. X#  
  7098. X#      if /s then
  7099. X#      begin := 1
  7100. X#      # Print top line, if one is supplied
  7101. X#      else {
  7102. X#      iputs(igoto(getval("cm"), 1, 1))
  7103. X#      write_ce(s ? tab(getval("co") | 0))
  7104. X#      begin := 2
  7105. X#      }
  7106. X#  
  7107. X#      # Fill the screen with lines from f; clear and fail on EOF.
  7108. X#      every i := begin to getval("li") - 1 do {
  7109. X#      iputs(igoto(getval("cm"), 1, i))
  7110. X#      if not write_ce(read(f) ? tab(getval("co") | 0)) then {
  7111. X#          # Clear remaining lines on the screen.
  7112. X#          every j := i to getval("li") do {
  7113. X#          iputs(igoto(getval("cm"), 1, j))
  7114. X#          iputs(getval("ce"))
  7115. X#          }
  7116. X#          iputs(igoto(getval("cm"), 1, i))
  7117. X#          fail
  7118. X#      }
  7119. X#      }
  7120. X#      return
  7121. X#  
  7122. X#  end
  7123. X#  
  7124. X#  procedure write_ce(s)
  7125. X#  
  7126. X#      normal()
  7127. X#      iputs(getval("ce")) |
  7128. X#      writes(repl(" ",getval("co") - *s))
  7129. X#      writes(s)
  7130. X#      return
  7131. X#
  7132. X#  end
  7133. X#
  7134. X############################################################################
  7135. X#
  7136. X#  Requires: UNIX
  7137. X#
  7138. X#  Links: itlib.icn
  7139. X#
  7140. X############################################################################
  7141. X
  7142. X
  7143. Xglobal c_cc, current_mode        # what mode are we in, raw or cooked?
  7144. Xrecord termio_struct(vintr,vquit,verase,vkill)
  7145. X
  7146. Xprocedure getse(s)
  7147. X
  7148. X    # getse() - like getche, only for strings instead of single chars
  7149. X    #
  7150. X    # This procedure *must* be used instead of read(&input) if getch
  7151. X    # and/or getche are to be used, since these put the current tty
  7152. X    # line in raw mode.
  7153. X    #
  7154. X    # Note that the buffer can be initialized by calling getse with a
  7155. X    # string argument.  Note also that, as getse now stands, it will
  7156. X    # fail if the user backspaces over everything that has been input.
  7157. X    # This change does not coincide with its behavior in previous ver-
  7158. X    # sions.  It can be changed by commenting out the line "if *s < 1
  7159. X    # then fail" below, and uncommenting the line "if *s < 1 then
  7160. X    # next."
  7161. X
  7162. X    local chr
  7163. X    static BS
  7164. X    initial {
  7165. X    BS := getval("bc") | "\b"
  7166. X    if not getval("bs") then {
  7167. X        reset_tty()
  7168. X        stop("Your terminal can't backspace!")
  7169. X    }
  7170. X    }
  7171. X
  7172. X    /s := ""
  7173. X    repeat {
  7174. X    case chr := getch() | fail of {
  7175. X        "\r"|"\n"    : return s
  7176. X        c_cc.vkill   : {
  7177. X        if *s < 1 then next
  7178. X        every 1 to *s do writes(BS)
  7179. X        s := ""
  7180. X        }
  7181. X        c_cc.verase   : {
  7182. X        # if *s < 1 then next
  7183. X        writes(BS) & s := s[1:-1]
  7184. X        if *s < 1 then fail
  7185. X        }
  7186. X        default: writes(chr) & s ||:= chr
  7187. X    }
  7188. X    }
  7189. X
  7190. Xend
  7191. X
  7192. X
  7193. X
  7194. Xprocedure setup_tty()
  7195. X    change_tty_mode("setup")
  7196. X    return
  7197. Xend
  7198. X
  7199. X
  7200. X
  7201. Xprocedure reset_tty()
  7202. X
  7203. X    # Reset (global) mode switch to &null to show we're in cooked mode.
  7204. X    current_mode := &null
  7205. X    change_tty_mode("reset")
  7206. X    return
  7207. X
  7208. Xend
  7209. X
  7210. X
  7211. X
  7212. Xprocedure getch()
  7213. X
  7214. X    local chr
  7215. X
  7216. X    # If the global variable current_mode is null, then we have to
  7217. X    # reset the terminal to raw mode.
  7218. X    if /current_mode := 1 then
  7219. X    setup_tty()
  7220. X
  7221. X    chr := reads(&input)
  7222. X    case chr of {
  7223. X    c_cc.vintr : reset_tty() & stop()  # shouldn't hard code this in
  7224. X    c_cc.vquit  : reset_tty() & stop()
  7225. X    default : return chr
  7226. X    }
  7227. X
  7228. Xend
  7229. X
  7230. X
  7231. X
  7232. Xprocedure getche()
  7233. X
  7234. X    local chr
  7235. X
  7236. X    # If the global variable current_mode is null, then we have to
  7237. X    # reset the terminal to raw mode.
  7238. X    if /current_mode := 1 then
  7239. X    setup_tty()
  7240. X
  7241. X    chr := reads(&input)
  7242. X    case chr of {
  7243. X    c_cc.vintr  : reset_tty() & stop()
  7244. X    c_cc.vquit  : reset_tty() & stop()
  7245. X    default : writes(chr) & return chr
  7246. X    }
  7247. X
  7248. Xend
  7249. X
  7250. X
  7251. X
  7252. Xprocedure change_tty_mode(switch)
  7253. X
  7254. X    # global c_cc   (global record containing values for kill, etc. chars)
  7255. X    local get_term_params, i
  7256. X    static reset_string
  7257. X    initial {
  7258. X    getval("li")    # check to be sure itlib is set up
  7259. X    find("unix",map(&features)) |
  7260. X        stop("change_tty_mode:  These routines must run under Unix.")
  7261. X    get_term_params := open("/bin/stty -g 2>&1","pr")
  7262. X    reset_string := !get_term_params
  7263. X    close(get_term_params)
  7264. X    reset_string ? {
  7265. X        # tab upto the fifth field of the output of the stty -g cmd
  7266. X        # fields of stty -g seem to be the same as those of the
  7267. X        # termio struct, except that the c_line field is missing
  7268. X        every 1 to 4 do tab(find(":")+1)
  7269. X        c_cc := termio_struct("\x03","\x1C","\x08","\x15")
  7270. X        every i := 1 to 3 do {
  7271. X        c_cc[i] := char(integer("16r"||tab(find(":"))))
  7272. X        move(1)
  7273. X        }
  7274. X        c_cc[i+1] := char(integer("16r"||tab(0)))
  7275. X    }
  7276. X    }
  7277. X
  7278. X    if switch == "setup"
  7279. X    then system("/bin/stty -echo raw")
  7280. X    else system("/bin/stty "||reset_string)
  7281. X
  7282. X    return
  7283. X
  7284. Xend
  7285. SHAR_EOF
  7286. echo 'File getchlib.icn is complete' &&
  7287. true || echo 'restore of getchlib.icn failed'
  7288. rm -f _shar_wnt_.tmp
  7289. fi
  7290. # ============= complete.icn ==============
  7291. if test -f 'complete.icn' -a X"$1" != X"-c"; then
  7292.     echo 'x - skipping complete.icn (File already exists)'
  7293.     rm -f _shar_wnt_.tmp
  7294. else
  7295. > _shar_wnt_.tmp
  7296. echo 'x - extracting complete.icn (Text)'
  7297. sed 's/^X//' << 'SHAR_EOF' > 'complete.icn' &&
  7298. X############################################################################
  7299. X#
  7300. X#    Name:     complete.icn
  7301. X#
  7302. X#    Title:     complete partial input string
  7303. X#
  7304. X#    Author:     Richard L. Goerwitz
  7305. X#
  7306. X#    Version: 1.7
  7307. X#
  7308. X############################################################################
  7309. X#
  7310. X#  This file contains a single procedure, complete(s,st), which
  7311. X#  completes a string (s) relative to a set or list of strings (st).
  7312. X#  Put differently, complete() lets you supply a partial string, s,
  7313. X#  and get back those strings in st that s is either equal to or a
  7314. X#  substring of.
  7315. X#
  7316. X#  Lots of command interfaces allow completion of partial input.
  7317. X#  Complete() simply represents my personal sentiments about how this
  7318. X#  might best be done in Icon.  If you strip away the profuse comments
  7319. X#  below, you end up with only about thirty lines of actual source
  7320. X#  code.
  7321. X#
  7322. X#  I have arranged things so that only that portion of an automaton
  7323. X#  which is needed to complete a given string is actually created and
  7324. X#  stored.  Storing automata for later use naturally makes complete()
  7325. X#  eat up more memory.  The performance gains can make it worth the
  7326. X#  trouble, though.  If, for some reason, there comes a time when it
  7327. X#  is advisable to reclaim the space occupied by complete's static
  7328. X#  structures, you can just call it without arguments.  This
  7329. X#  "resets" complete() and forces an immediate garbage collection.
  7330. X#  
  7331. X# Example code:
  7332. X#
  7333. X#      commands := ["run","stop","quit","save","load","continue"]
  7334. X#      while line := read(&input) do {
  7335. X#          cmds := list()
  7336. X#          every put(cmds, complete(line, commands))
  7337. X#          case *cmds of {
  7338. X#              0 : input_error(line)
  7339. X#              1 : do_command(cmds[1])
  7340. X#              default : display_possible_completions(cmds)
  7341. X#          }
  7342. X#          etc...
  7343. X#
  7344. X#  More Iconish methods might include displaying successive
  7345. X#  alternatives each time the user presses the tab key (this would,
  7346. X#  however, require using the nonportable getch() routine).  Another
  7347. X#  method might be to use the first string suspended by complete().
  7348. X#
  7349. X#  NOTE: This entire shebang could be replaced with a slightly slower
  7350. X#  and much smaller program suggested to me by Jerry Nowlin and Bob
  7351. X#  Alexander.
  7352. X#
  7353. X#      procedure terscompl(s, st)
  7354. X#          suspend match(s, p := !st) & p
  7355. X#      end
  7356. X#
  7357. X#  This program will work fine for lists with just a few members, and
  7358. X#  also for cases where s is fairly large.  It will also use much less
  7359. X#  memory.
  7360. X#
  7361. X############################################################################
  7362. X#
  7363. X#  Links: none
  7364. X#
  7365. X############################################################################
  7366. X
  7367. X
  7368. X
  7369. Xprocedure complete(s,st)
  7370. X
  7371. X    local dfstn, c, l, old_chr, chr, newtbl, str, strset
  7372. X    static t
  7373. X    initial t := table()
  7374. X
  7375. X    # No-arg invocation wipes out static structures & causes an
  7376. X    # immediate garbage collection.
  7377. X    if /s & /st then {
  7378. X    t := table()
  7379. X    collect()        # do it NOW
  7380. X    fail
  7381. X    }
  7382. X    type(st) == ("list"|"set") |
  7383. X    stop("error (complete):  list or set expected for arg2")
  7384. X
  7385. X    # Seriously, all that's being done here is that possible states
  7386. X    # are being represented by sets containing possible completions of
  7387. X    # s relative to st.  Each time a character is snarfed from s, we
  7388. X    # check to see what strings in st might represent possible
  7389. X    # completions, and store these in yet another set.  At some
  7390. X    # point, we either run into a character in s that makes comple-
  7391. X    # tion impossible (fail), or we run out of characters in s (in
  7392. X    # which case we succeed, & suspend each of the possible
  7393. X    # completions).
  7394. X
  7395. X    # Store any sets we have to create in a static structure for later
  7396. X    # re-use.
  7397. X    /t[st] := table()
  7398. X
  7399. X    # We'll call the table entry for the current set dfstn.  (It really
  7400. X    # does enable us to do things deterministically.)
  7401. X    dfstn := t[st]
  7402. X
  7403. X    # Snarf one character at a time from s.
  7404. X    every c := !s do {
  7405. X
  7406. X    # The state we're in is represented by the set of all possible
  7407. X    # completions before c was read.  If we haven't yet seen char
  7408. X    # c in this state, run through the current-possible-completion
  7409. X    # set, popping off the first character of each possible
  7410. X    # completion, and then construct a table which uses these
  7411. X    # initial chars as keys, and makes the completions that are
  7412. X    # possible for each of these characters into the values for
  7413. X    # those keys.
  7414. X    if /dfstn[st] then {
  7415. X
  7416. X        # To get strings that start with the same char together,
  7417. X        # sort the current string set (st).
  7418. X        l := sort(st)
  7419. X        newtbl := table()
  7420. X        old_chr := ""
  7421. X        # Now pop off each member of the sorted string set.  Use
  7422. X        # first characters as keys, and then divvy up the full strings
  7423. X        # into sets of strings having the same initial letter.
  7424. X        every str := !l do {
  7425. X        str ? { chr := move(1) | next; str := tab(0) }
  7426. X        if old_chr ~==:= chr then {
  7427. X            strset := set([str])
  7428. X            insert(newtbl, chr, strset)
  7429. X        }
  7430. X        else insert(strset, str)
  7431. X        }
  7432. X        insert(dfstn, st, newtbl)
  7433. X    }
  7434. X
  7435. X    # What we've done essentially is to create a table in which
  7436. X    # the keys represent labeled arcs out of the current state,
  7437. X    # and the values represent possible completion sets for those
  7438. X    # paths.  What we need to do now is store that table in dfstn
  7439. X    # as the value of the current state-set (i.e. the current
  7440. X    # range of possible completions).  Once stored, we can then
  7441. X    # see if there is any arc from the current state (dfstn[st])
  7442. X    # with the label c (dfstn[st][c]).  If so, its value becomes
  7443. X    # the new current state (st), and we cycle around again for
  7444. X    # yet another c.
  7445. X    st := \dfstn[st][c] | fail
  7446. X    if *st = 1 & match(s,!st)
  7447. X    then break
  7448. X    }
  7449. X
  7450. X    # Eventually we run out of characters in c.  The current state
  7451. X    # (i.e. the set of possible completions) can simply be suspended
  7452. X    # one element at a time, with s prefixed to each element.  If, for
  7453. X    # instance, st had contained ["hello","help","hear"] at the outset
  7454. X    # and s was equal to "hel", we would now be suspending "hel" ||
  7455. X    # !set(["lo","p"]).
  7456. X    suspend s || !st
  7457. X
  7458. Xend
  7459. SHAR_EOF
  7460. true || echo 'restore of complete.icn failed'
  7461. rm -f _shar_wnt_.tmp
  7462. fi
  7463. # ============= Makefile.dist ==============
  7464. if test -f 'Makefile.dist' -a X"$1" != X"-c"; then
  7465.     echo 'x - skipping Makefile.dist (File already exists)'
  7466.     rm -f _shar_wnt_.tmp
  7467. else
  7468. > _shar_wnt_.tmp
  7469. echo 'x - extracting Makefile.dist (Text)'
  7470. sed 's/^X//' << 'SHAR_EOF' > 'Makefile.dist' &&
  7471. X#
  7472. X# Makefile for iwinds demos
  7473. X#
  7474. X
  7475. XSHELL = /bin/sh
  7476. XMAKE = /usr/local/bin/gnumake
  7477. X
  7478. X# You may need to change this.
  7479. XICONC = /usr/icon/v8/bin/icont -u
  7480. X
  7481. XSRC = iwinds.icn iolib.icn iscreen.icn getchlib.icn
  7482. X
  7483. Xall: demo1 demo2
  7484. X
  7485. Xdemo1: main.icn $(SRC)
  7486. X    $(ICONC) -o demo1 main.icn $(SRC)
  7487. X
  7488. Xdemo2: main2.icn $(SRC)
  7489. X    $(ICONC) -o demo2 main2.icn $(SRC) complete.icn
  7490. X
  7491. Xclean:
  7492. X    -rm -f demo1 demo2 *~
  7493. SHAR_EOF
  7494. true || echo 'restore of Makefile.dist failed'
  7495. rm -f _shar_wnt_.tmp
  7496. fi
  7497. # ============= README ==============
  7498. if test -f 'README' -a X"$1" != X"-c"; then
  7499.     echo 'x - skipping README (File already exists)'
  7500.     rm -f _shar_wnt_.tmp
  7501. else
  7502. > _shar_wnt_.tmp
  7503. echo 'x - extracting README (Text)'
  7504. sed 's/^X//' << 'SHAR_EOF' > 'README' &&
  7505. XThis archive contains a simple windowing package, along with two
  7506. Xdemos.  The first demo (demo1) just draws and manipulates some simple
  7507. Xwindows.  The second demo (demo2) draws a little box in the center of
  7508. Xthe screen that can be moved around the screen using arrow or vi keys.
  7509. XIf you want to look at the source code for the demos, look at the
  7510. Xfiles main.icn and main2.icn.  The windowing library is in iwinds.icn.
  7511. XGeneral termcap interface routines are in iscreen.icn, iolib.icn, and
  7512. Xgetchlib.icn.
  7513. X
  7514. XIf you want to take a look at the demos, just "make -f Makefile.dist".
  7515. XThen type "./demo1; ./demo2".  Make "clean" when you're done.
  7516. X
  7517. XSee the docs prepended to iwinds.icn for a description of the whats
  7518. Xand whys.  This very preliminary hack will doubtless contain bugs.
  7519. XSend reports of them, or any general comments you feel like voicing,
  7520. Xto me, Richard Goerwitz, at goer@sophist.uchicago.edu.
  7521. X
  7522. X-Richard
  7523. SHAR_EOF
  7524. true || echo 'restore of README failed'
  7525. rm -f _shar_wnt_.tmp
  7526. fi
  7527. rm -f _shar_seq_.tmp
  7528. echo You have unpacked the last part
  7529. exit 0
  7530. -- 
  7531.  
  7532.    -Richard L. Goerwitz              goer%sophist@uchicago.bitnet
  7533.    goer@sophist.uchicago.edu         rutgers!oddjob!gide!sophist!goer
  7534.  
  7535. From icon-group-request@arizona.edu  Tue Oct 15 01:50:24 1991
  7536. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Tue, 15 Oct 91 01:50:24 MST
  7537. Resent-From: icon-group-request@arizona.edu
  7538. Received: from Arizona.edu (Hopey.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  7539.     id AA02392; Tue, 15 Oct 91 01:50:13 MST
  7540. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Tue, 15 Oct
  7541.  1991 01:49 MST
  7542. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA11918; Tue, 15 Oct 91
  7543.  01:42:10 -0700
  7544. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  7545.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  7546.  usenet@ucbvax.Berkeley.EDU if you have questions)
  7547. Resent-Date: Tue, 15 Oct 1991 01:49 MST
  7548. Date: 15 Oct 91 07:35:22 GMT
  7549. From: midway!quads!goer@handies.ucar.edu (Richard L. Goerwitz)
  7550. Subject: iwinds, part 2 of 4
  7551. Sender: icon-group-request@arizona.edu
  7552. Resent-To: icon-group@cs.arizona.edu
  7553. To: icon-group@arizona.edu
  7554. Resent-Message-Id: <19F0A70B38C1071F@Arizona.edu>
  7555. Message-Id: <1991Oct15.073522.24789@midway.uchicago.edu>
  7556. X-Envelope-To: icon-group@CS.Arizona.EDU
  7557. X-Vms-To: icon-group@Arizona.edu
  7558. Organization: University of Chicago
  7559.  
  7560. ---- Cut Here and feed the following to sh ----
  7561. #!/bin/sh
  7562. # this is iwinds.02 (part 2 of a multipart archive)
  7563. # do not concatenate these parts, unpack them in order with /bin/sh
  7564. # file iwinds.icn continued
  7565. #
  7566. if test ! -r _shar_seq_.tmp; then
  7567.     echo 'Please unpack part 1 first!'
  7568.     exit 1
  7569. fi
  7570. (read Scheck
  7571.  if test "$Scheck" != 2; then
  7572.     echo Please unpack part "$Scheck" next!
  7573.     exit 1
  7574.  else
  7575.     exit 0
  7576.  fi
  7577. ) < _shar_seq_.tmp || exit 1
  7578. if test ! -f _shar_wnt_.tmp; then
  7579.     echo 'x - still skipping iwinds.icn'
  7580. else
  7581. echo 'x - continuing file iwinds.icn'
  7582. sed 's/^X//' << 'SHAR_EOF' >> 'iwinds.icn' &&
  7583. X        1 : emphasize()
  7584. X        2 : underline()
  7585. X        3 : boldface()
  7586. X        4 : blink()
  7587. X        default : {
  7588. X        # write(&errout, "mode for ", y, ",", x, " = ", mode)
  7589. X        normal()
  7590. X        }
  7591. X    }
  7592. X    }
  7593. X
  7594. X    # Turn lower 16 bits of sq.val into a character.  8 bits is
  7595. X    # the usual now, but soon it'll be 16 bits for characters (I
  7596. X    # hope).
  7597. X    return writes(char(iand(sq.val, 65535)))
  7598. X
  7599. Xend
  7600. X
  7601. X
  7602. Xprocedure hidew(w)
  7603. X
  7604. X    #
  7605. X    # Hides window w.
  7606. X    #
  7607. X    local y, x, stdscr_y, stdscr_x, window_square
  7608. X
  7609. X    w === _mainw & fail        # can't hide main window
  7610. X    # window is already hidden if over and under pointers are null
  7611. X    /w.wlist[1][1].over & /w.wlist[1][1].under & fail
  7612. X
  7613. X    every y := 1 to w.lines do {
  7614. X    every x := 1 to w.cols do {
  7615. X
  7616. X        # Create a handle for manipulating the current square in w.
  7617. X        window_square := w.wlist[y][x]
  7618. X
  7619. X        # If the over pointer is nonnull, then we're not on top
  7620. X        # of the stack for position y,x.
  7621. X        if \window_square.over then {
  7622. X        # So link the record underneath (if there is one) to
  7623. X        # the one on top; link the one on top to the one
  7624. X        # underneath (to &null if there isn't one underneath).
  7625. X        (\window_square.under).over := window_square.over
  7626. X        window_square.over.under := window_square.under
  7627. X        }
  7628. X
  7629. X        # Over pointer is null, but under pointer is not, so the
  7630. X        # square is on-screen at _stdscr.wlist[stdscr_y][stdscr_x].
  7631. X        # Remove it; make _stdscr.wlist[stdscr_y][stdscr_x] point
  7632. X        # to window_square.under.  Set window_square.under.over to
  7633. X        # &null to indicate that it is now on the top of the stack.
  7634. X        else {
  7635. X        window_square.under.over := &null
  7636. X        stdscr_y := y + w.begy - 1
  7637. X        stdscr_x := x + w.begx - 1
  7638. X        _stdscr.wlist[stdscr_y][stdscr_x] := window_square.under
  7639. X        if window_square.val ~= window_square.under.val |
  7640. X            window_square.val < 0
  7641. X        then draw_it(window_square.under, stdscr_y, stdscr_x)
  7642. X        else window_square.val := abs(window_square.val)
  7643. X        }
  7644. X        window_square.over := &null
  7645. X        window_square.under := &null
  7646. X
  7647. X        # Paranoid check.  The topmost member of the stack should
  7648. X        # always have &null as its "over" pointer.
  7649. X        # /(((_stdscr.wlist)[stdscr_y][stdscr_x]).over) | {
  7650. X        #    write(&errout,"window:\n",
  7651. X        #          (\ximage)(_stdscr.wlist[stdscr_y][stdscr_x].over))
  7652. X        #    exit_prog("hidew", "bizarre stack malformation", 21)
  7653. X        # }
  7654. X    }
  7655. X    }
  7656. X
  7657. X    return
  7658. X
  7659. Xend
  7660. X
  7661. X
  7662. Xprocedure createw(begy, begx, lines, cols, wmode, wchar, border, bmode)
  7663. X
  7664. X    #
  7665. X    # Creates a new window with the upper left corner at begy,begx, and
  7666. X    # a size of lines,cols, a default mode of wmode, and a default fill
  7667. X    # char of wchar; a border is drawn if border is nonnull.
  7668. X    #
  7669. X    local default_cell, wlist, wlist2, r, c, w, ypos, xpos
  7670. X
  7671. X    if /(begy | begx | lines | cols) then
  7672. X    exit_prog("createw", "first four arguments must all be nonnull", 31)
  7673. X
  7674. X   /wmode   := 0        # default mode is 0 (normal)
  7675. X   /wchar   := " "        # default char is a space
  7676. X    # default_cell := -(ishift(wmode,16) + ord(wchar))
  7677. X    default_cell := -((wmode * 65536) + ord(wchar))
  7678. X   /border  := &null
  7679. X
  7680. X    #
  7681. X    # Create a lines X cols array of _square() records.
  7682. X    #
  7683. X    every !(wlist := list(lines)) := list(cols)
  7684. X    every !(wlist2 := list(lines)) := list(cols)
  7685. X    #
  7686. X    every r := 1 to lines do
  7687. X    every c := 1 to cols do
  7688. X        wlist[r][c] := _square(default_cell, &null, &null)
  7689. X
  7690. X    if \border then ypos := xpos := 2 else ypos := xpos := 1
  7691. X    w := _window(wlist, begy,begx, lines, cols, ypos, xpos, border)
  7692. X    make_border(w, \border, \bmode | wmode)
  7693. X    refreshw(w)
  7694. X
  7695. X    return w
  7696. X
  7697. Xend
  7698. X
  7699. X
  7700. Xprocedure redraw()
  7701. X
  7702. X    #
  7703. X    # Simple redraw of the entire screen.
  7704. X    #
  7705. X    local r, c
  7706. X    #global LINES, COLS
  7707. X
  7708. X    # clear()
  7709. X    every r := _stdscr.begy to LINES do {
  7710. X    every c := _stdscr.begx to COLS do {
  7711. X        draw_it(_stdscr.wlist[r][c], r, c)
  7712. X    }
  7713. X    }
  7714. X
  7715. X    return "screen redrawn"
  7716. X
  7717. Xend
  7718. X
  7719. X
  7720. Xprocedure movew(w, begy, begx)
  7721. X
  7722. X    #
  7723. X    # Moves window w from wherever it is on the screen to begy,begx.
  7724. X    # This routine is slow.  Much too slow.  There are, I'm sure, a
  7725. X    # lot faster ways (even within Icon), but I didn't happen to think
  7726. X    # of any as I wrote this.
  7727. X    #
  7728. X
  7729. X    local wlist, wlist2, y, x, w2, window_square
  7730. X
  7731. X    w === _mainw & fail        # can't move main window
  7732. X
  7733. X    /begy | /begx &
  7734. X    exit_prog("movew","null argument 2 and/or 3!",61)
  7735. X    wlist  := w.wlist
  7736. X    wlist2 := list(w.lines)
  7737. X    every (!wlist2) := list(w.cols)
  7738. X
  7739. X    every y := 1 to w.lines do {
  7740. X    every x := 1 to w.cols do {
  7741. X        window_square := (wlist2[y][x] := copy(wlist[y][x]))
  7742. X        window_square.val := -abs(window_square.val)
  7743. X        window_square.over := &null
  7744. X        window_square.under := &null
  7745. X    }
  7746. X    }
  7747. X    w2 := copy(w)
  7748. X    w2.wlist := wlist2
  7749. X    w2.begy := begy
  7750. X    w2.begx := begx
  7751. X    refreshw(w2)
  7752. X
  7753. X    hidew(w)
  7754. X    w.wlist := wlist2
  7755. X    w.begy := begy
  7756. X    w.begx := begx
  7757. X
  7758. X    return
  7759. X
  7760. Xend
  7761. X
  7762. X
  7763. Xprocedure make_border(w, border, mode)
  7764. X
  7765. X    local ulc, uc, urc, rc, brc, bc, blc, lc, y, x
  7766. X
  7767. X    # mode := ishift(\mode, 16) | 0
  7768. X    mode := (\mode * 65536) | 0
  7769. X
  7770. X    if type(border) === ("list"|"string") then {
  7771. X    *border = 8 | exit_prog("make_border", "*border must be 8", 41)
  7772. X    ulc := -(mode + ord(border[1]))
  7773. X    uc  := -(mode + ord(border[2]))
  7774. X    urc := -(mode + ord(border[3]))
  7775. X    rc  := -(mode + ord(border[4]))
  7776. X    brc := -(mode + ord(border[5]))
  7777. X    bc  := -(mode + ord(border[6]))
  7778. X    blc := -(mode + ord(border[7]))
  7779. X    lc  := -(mode + ord(border[8]))
  7780. X    }
  7781. X    else {
  7782. X    ulc := -(mode + ord("+"))
  7783. X    uc  := -(mode + ord("-"))
  7784. X    urc := -(mode + ord("+"))
  7785. X    rc  := -(mode + ord("|"))
  7786. X    brc := -(mode + ord("+"))
  7787. X    bc  := -(mode + ord("-"))
  7788. X    blc := -(mode + ord("+"))
  7789. X    lc  := -(mode + ord("|"))
  7790. X    }
  7791. X    w.border := [ulc, uc, urc, rc, brc, bc, blc, lc]
  7792. X
  7793. X    # Now draw in all the appropriate charcters.  Be sure to check
  7794. X    # whether the window is big enough!
  7795. X    w.wlist[1][1].val := ulc
  7796. X    every x := 2 to w.cols-1 do {
  7797. X    w.wlist[1][x].val := uc
  7798. X    w.wlist[w.lines][x].val := bc
  7799. X    }
  7800. X    w.wlist[1][w.cols].val := urc
  7801. X    w.wlist[w.lines][w.cols].val := brc
  7802. X    every y := 2 to w.lines-1 do {
  7803. X    w.wlist[y][w.cols].val := rc
  7804. X    w.wlist[y][1].val := lc
  7805. X    }
  7806. X    w.wlist[w.lines][1].val := blc
  7807. X
  7808. X    return w.border
  7809. X
  7810. Xend
  7811. X    
  7812. X
  7813. Xprocedure writew(w, s, y, x, mode)
  7814. X
  7815. X    local begy, begx, maxy, maxx, ypos, xpos, c, stdscr_square, newval
  7816. X    static controls, spaces
  7817. X    initial {
  7818. X    controls := ""
  7819. X    every controls ||:= char((0 to 7) | 9 | 11 | 12 | (14 to 31))
  7820. X    spaces := repl(" ", *controls)
  7821. X    # write(&errout, image(controls))
  7822. X    }
  7823. X
  7824. X    begy := 1
  7825. X    begx := 1
  7826. X    maxy := w.lines
  7827. X    maxx := w.cols
  7828. X    ypos := \y | w.ypos
  7829. X    xpos := \x | w.xpos
  7830. X    # see below on mode
  7831. X
  7832. X    if \w.border then {
  7833. X    # just in case it's forgotten that there's a border, and an
  7834. X    # attempt is made to write to spaces occupied by the border
  7835. X    ypos <= begy & ypos := 2
  7836. X    ypos >= maxy & ypos := 2 & xpos := 2
  7837. X    xpos <= begx | xpos >= maxx & xpos := 2
  7838. X    # reset boundaries to account for the smaller available space
  7839. X    begy +:= 1
  7840. X    begx +:= 1
  7841. X    maxy -:= 1
  7842. X    maxx -:= 1
  7843. X    }
  7844. X
  7845. X    begy <= ypos <= maxy | begx <= xpos <= maxx |
  7846. X    exit_prog("writew", "coordinate out of range: "||ypos||","||xpos, 51)
  7847. X    # Reposition the cursor.
  7848. X    iputs(igoto(getval("cm"), xpos + w.begx - 1, ypos + w.begy - 1))
  7849. X
  7850. X    s := map(s, controls, spaces)
  7851. X    # write(&errout, image(s))
  7852. X    # mode := ishift(\mode, 16)
  7853. X    mode := (\mode * 65536)
  7854. X    every c := !s do {
  7855. X
  7856. X    # write(&errout, image(c))
  7857. X    if any('\n\r', c) then {
  7858. X        ypos +:= 1
  7859. X        xpos := begx - 1
  7860. X    } else {
  7861. X        if c == "\b" then {
  7862. X        (begx <= (xpos <- (xpos - 1))) | next
  7863. X        writew(w, " ", ypos, xpos, mode, "immediate")
  7864. X        iputs(igoto(getval("cm"), xpos + w.begx - 1, ypos + w.begy- 1))
  7865. X        next
  7866. X        }
  7867. X        # write(&errout,
  7868. X        #      "old char cell ",radcon(w.wlist[ypos][xpos].val,10,2))
  7869. X        stdscr_square := w.wlist[ypos][xpos]
  7870. X        newval :=
  7871. X        (\mode | iand(abs(w.wlist[ypos][xpos].val),2147418112))+ ord(c)
  7872. X        if stdscr_square.val < 0 | stdscr_square.val ~= newval then {
  7873. X        stdscr_square.val := -newval
  7874. X        if /stdscr_square.over then
  7875. X            draw_it(stdscr_square, ypos+w.begy - 1, xpos+w.begx - 1)
  7876. X        }
  7877. X        else stdscr_square.val := newval
  7878. X        # write(&errout, "mode = ", radcon(\mode,10,2))
  7879. X        # write(&errout,
  7880. X        #      "char cell = ", radcon(w.wlist[ypos][xpos].val, 10, 2))
  7881. X    }
  7882. X    ypos > maxy & ypos := begy & xpos := begx
  7883. X    xpos < maxx & xpos +:= 1
  7884. X    }
  7885. X
  7886. X    w.ypos := ypos
  7887. X    w.xpos := xpos
  7888. X
  7889. X    return
  7890. X
  7891. Xend
  7892. X
  7893. X
  7894. Xprocedure readw(w, y, x, mode)
  7895. X
  7896. X    #
  7897. X    # Reads a string from window w, at pos y,x within that window,
  7898. X    # echoing the string to the screen.  Characters get echoed as
  7899. X    # they are typed.  Terminates on a CR or LF & returns the string
  7900. X    # just read (minus the CR/LF).
  7901. X    #
  7902. X    local chr, s
  7903. X
  7904. X    # Move the cursor to the spot we're to start reading at.
  7905. X    writew(w, "", y, x, mode)
  7906. X    # Check to be sure this square is visible on the screen.
  7907. X    /_stdscr.wlist[y + w.begy - 1][x + w.begx - 1].over | {
  7908. X    write(&errout, "error (readw):  square isn't visible")
  7909. X    fail
  7910. X    }
  7911. X
  7912. X    s := ""
  7913. X    repeat {
  7914. X    case chr := getch() | fail of {
  7915. X        "\r"|"\n" : return s
  7916. X#        c_cc.vkill : {
  7917. X#        if *s < 1 then next
  7918. X#        every 1 to *s do writew(w,"\b",,,mode)
  7919. X#        s := ""
  7920. X#        }
  7921. X        "\b" : {
  7922. X        if *s < 1 then next
  7923. X        writew(w,"\b",,,mode)
  7924. X        s := s[1:-1]
  7925. X        }
  7926. X        default : {
  7927. X        writew(w,chr,,,mode)
  7928. X        s ||:= chr
  7929. X        }
  7930. X    }
  7931. X    }
  7932. X
  7933. X
  7934. Xend
  7935. X
  7936. X
  7937. Xprocedure getchw(w, y, x, mode)
  7938. X
  7939. X    #
  7940. X    # Reads a character from window w, at pos y,x within that window,
  7941. X    # echoing the character to the screen.
  7942. X    #
  7943. X    local chr, s
  7944. X
  7945. X    # Move the cursor to the spot we're to start reading at.
  7946. X    writew(w, "", y, x, mode)
  7947. X
  7948. X    # Check to be sure this square is visible on the screen.
  7949. X    /_stdscr.wlist[y + w.begy - 1][x + w.begx - 1].over | {
  7950. X    write(&errout, "error (getchw):  square isn't visible")
  7951. X    fail
  7952. X    }
  7953. X    chr := getch() | fail
  7954. X    writew(w,chr,,,mode)
  7955. X    return chr
  7956. X
  7957. Xend
  7958. X
  7959. X
  7960. Xprocedure exit_prog(func, msg, errcode)
  7961. X
  7962. X    #
  7963. X    # Program termination utility.  Prints error message "msg" for
  7964. X    # function "func," resets the terminal, then aborts with exit code
  7965. X    # "errcode."  For normal exits, call exit_prog() without any args.
  7966. X    #
  7967. X    # global LINES
  7968. X
  7969. X    func := " (" || (trim(\func, ': ') || "):  ") | ":  "
  7970. X    write(&errout, "error", func, \msg)
  7971. X    window("off")
  7972. X    normal(); clear()
  7973. X    iputs(igoto(getval("cm"), 1, LINES-1))
  7974. X    exit(errcode)        # abort program with exit code errcode
  7975. X
  7976. Xend
  7977. SHAR_EOF
  7978. echo 'File iwinds.icn is complete' &&
  7979. true || echo 'restore of iwinds.icn failed'
  7980. rm -f _shar_wnt_.tmp
  7981. fi
  7982. # ============= iolib.icn ==============
  7983. if test -f 'iolib.icn' -a X"$1" != X"-c"; then
  7984.     echo 'x - skipping iolib.icn (File already exists)'
  7985.     rm -f _shar_wnt_.tmp
  7986. else
  7987. > _shar_wnt_.tmp
  7988. echo 'x - extracting iolib.icn (Text)'
  7989. sed 's/^X//' << 'SHAR_EOF' > 'iolib.icn' &&
  7990. X########################################################################
  7991. X#    
  7992. X#    Name:    iolib.icn
  7993. X#    
  7994. X#    Title:    Icon termlib-type tools for MS-DOS and UNIX
  7995. X#    
  7996. X#    Author:    Richard L. Goerwitz (with help from Norman Azadian)
  7997. X#
  7998. X#    Version: 1.13
  7999. X#
  8000. X#########################################################################
  8001. X#
  8002. X#  The authors place this and future versions of iolib in the public
  8003. X#  domain.
  8004. X#
  8005. X#########################################################################
  8006. X#
  8007. X#  The following library represents a series of rough functional
  8008. X#  equivalents to the standard Unix low-level termcap routines.  It is
  8009. X#  not meant as an exact termlib clone.  Nor is it enhanced to take
  8010. X#  care of magic cookie terminals, terminals that use \D in their
  8011. X#  termcap entries, or archaic terminals that require padding.  This
  8012. X#  library is geared mainly for use with ANSI and VT-100 devices.
  8013. X#  Note that this file may, in most instances, be used in place of the
  8014. X#  older UNIX-only itlib.icn file.  It essentially replaces the DOS-
  8015. X#  only itlibdos routines.  For DOS users not familiar with the whole
  8016. X#  notion of generalized screen I/O, I've included extra documentation
  8017. X#  below.  Please read it.
  8018. X#
  8019. X#  The sole disadvantage of this over the old itlib routines is that
  8020. X#  iolib.icn cannot deal with archaic or arcane UNIX terminals and/or
  8021. X#  odd system file arrangements.  Note that because these routines
  8022. X#  ignore padding, they can (unlike itlib.icn) be run on the NeXT and
  8023. X#  other systems which fail to implement the -g option of the stty
  8024. X#  command.  Iolib.icn is also simpler and faster than itlib.icn.
  8025. X#
  8026. X#  I want to thank Norman Azadian for suggesting the whole idea of
  8027. X#  combining itlib.icn and itlibdos.icn into one distribution, for
  8028. X#  suggesting things like letting drive specifications appear in DOS
  8029. X#  TERMCAP environment variables, and for finding several bugs (e.g.
  8030. X#  the lack of support for %2 and %3 in cm).  Although he is loathe
  8031. X#  to accept this credit, I think he deserves it.
  8032. X#
  8033. X#########################################################################
  8034. X#
  8035. X#  Contents:
  8036. X#
  8037. X#  setname(term)
  8038. X#    Use only if you wish to initialize itermlib for a terminal
  8039. X#  other than what your current environment specifies.  "Term" is the
  8040. X#  name of the termcap entry to use.  Normally this initialization is
  8041. X#  done automatically, and need not concern the user.
  8042. X#
  8043. X#  getval(id)
  8044. X#    Works something like tgetnum, tgetflag, and tgetstr.  In the
  8045. X#  spirit of Icon, all three have been collapsed into one routine.
  8046. X#  Integer valued caps are returned as integers, strings as strings,
  8047. X#  and flags as records (if a flag is set, then type(flag) will return
  8048. X#  "true").  Absence of a given capability is signalled by procedure
  8049. X#  failure.
  8050. X#
  8051. X#  igoto(cm,destcol,destline) - NB:  default 1 offset (*not* zero)!
  8052. X#    Analogous to tgoto.  "Cm" is the cursor movement command for
  8053. X#  the current terminal, as obtained via getval("cm").  Igoto()
  8054. X#  returns a string which, when output via iputs, will cause the
  8055. X#  cursor to move to column "destcol" and line "destline."  Column and
  8056. X#  line are always calculated using a *one* offset.  This is far more
  8057. X#  Iconish than the normal zero offset used by tgoto.  If you want to
  8058. X#  go to the first square on your screen, then include in your program
  8059. X#  "iputs(igoto(getval("cm"),1,1))."
  8060. X#
  8061. X#  iputs(cp,affcnt)
  8062. X#    Equivalent to tputs.  "Cp" is a string obtained via getval(),
  8063. X#  or, in the case of "cm," via igoto(getval("cm"),x,y).  Affcnt is a
  8064. X#  count of affected lines.  It is completely irrelevant for most
  8065. X#  modern terminals, and is supplied here merely for the sake of
  8066. X#  backward compatibility with itlib, a UNIX-only version of these
  8067. X#  routines (one which handles padding on archaic terminals).
  8068. X#
  8069. X##########################################################################
  8070. X#
  8071. X#  Notes for MS-DOS users:
  8072. X#
  8073. X#    There are two basic reasons for using the I/O routines
  8074. X#  contained in this package.  First, by using a set of generalized
  8075. X#  routines, your code will become much more readable.  Secondly, by
  8076. X#  using a high level interface, you can avoid the cardinal
  8077. X#  programming error of hard coding things like screen length and
  8078. X#  escape codes into your programs.
  8079. X#
  8080. X#    To use this collection of programs, you must do two things.
  8081. X#  First, you must add the line "device=ansi.sys" (or the name of some
  8082. X#  other driver, like zansi.sys, nansi.sys, or nnansi.sys [=new
  8083. X#  nansi.sys]) to your config.sys file.  Secondly, you must add two
  8084. X#  lines to your autoexec.bat file: 1) "set TERM=ansi-mono" and 2)
  8085. X#  "set TERMCAP=\location\termcap."  The purpose of setting the TERM
  8086. X#  variable is to tell this program what driver you are using.  If you
  8087. X#  have a color system, you could use "ansi-color" instead of
  8088. X#  "ansi-mono," although for compatibility with a broader range of
  8089. X#  users, it would perhaps be better to stick with mono.  The purpose
  8090. X#  of setting TERMCAP is to make it possible to determine where the
  8091. X#  termcap database file is located.  The termcap file (which should
  8092. X#  have been packed with this library as termcap.dos) is a short
  8093. X#  database of all the escape sequences used by the various terminal
  8094. X#  drivers.  Set TERMCAP so that it reflects the location of this file
  8095. X#  (which should be renamed as termcap, for the sake of consistency
  8096. X#  across UNIX and MS-DOS spectra).  If desired, you can also try
  8097. X#  using termcap2.dos.  Certain games work a lot better using this
  8098. X#  alternate file.  To try it out, rename it to termcap, and set
  8099. X#  the environment variable TERMCAP to its location.
  8100. X#
  8101. X#    Although the authors make no pretense of providing here a
  8102. X#  complete introduction to the format of the termcap database file,
  8103. X#  it will be useful, we believe, to explain a few basic facts about
  8104. X#  how to use this program in conjunction with it.  If, say, you want
  8105. X#  to clear the screen, add the line,
  8106. X#
  8107. X#    iputs(getval("cl"))
  8108. X#
  8109. X#  to your program.  The function iputs() outputs screen control
  8110. X#  sequences.  Getval retrieves a specific sequence from the termcap
  8111. X#  file.  The string "cl" is the symbol used in the termcap file to
  8112. X#  mark the code used to clear the screen.  By executing the
  8113. X#  expression "iputs(getval("cl"))," you are 1) looking up the "cl"
  8114. X#  (clear) code in the termcap database entry for your terminal, and
  8115. X#  the 2) outputting that sequence to the screen.
  8116. X#
  8117. X#    Some other useful termcap symbols are "ce" (clear to end of
  8118. X#  line), "ho" (go to the top left square on the screen), "so" (begin
  8119. X#  standout mode), and "se" (end standout mode).  To output a
  8120. X#  boldfaced string, str, to the screen, you would write -
  8121. X#
  8122. X#    iputs(getval("so"))
  8123. X#    writes(str)
  8124. X#    iputs(getval("se"))
  8125. X#
  8126. X#  You can also write "writes(getval("so") || str || getval("se")),
  8127. X#  but this would make reimplementation for UNIX terminals that
  8128. X#  require padding rather difficult.
  8129. X#
  8130. X#    It is also heartily to be recommended that MS-DOS programmers
  8131. X#  try not to assume that everyone will be using a 25-line screen.
  8132. X#  Most terminals are 24-line.  Some 43.  Some have variable window
  8133. X#  sizes.  If you want to put a status line on, say, the 2nd-to-last
  8134. X#  line of the screen, then determine what that line is by executing
  8135. X#  "getval("li")."  The termcap database holds not only string-valued
  8136. X#  sequences, but numeric ones as well.  The value of "li" tells you
  8137. X#  how many lines the terminal has (compare "co," which will tell you
  8138. X#  how many columns).  To go to the beginning of the second-to-last
  8139. X#  line on the screen, type in:
  8140. X#
  8141. X#    iputs(igoto(getval("cm"), 1, getval("li")-1))
  8142. X#
  8143. X#  The "cm" capability is a special capability, and needs to be output
  8144. X#  via igoto(cm,x,y), where cm is the sequence telling your computer
  8145. X#  to move the cursor to a specified spot, x is the column, and y is
  8146. X#  the row.  The expression "getval("li")-1" will return the number of
  8147. X#  the second-to-last line on your screen.
  8148. X#
  8149. X##########################################################################
  8150. X#
  8151. X#  Requires: UNIX or MS-DOS, co-expressions
  8152. X#
  8153. SHAR_EOF
  8154. true || echo 'restore of iolib.icn failed'
  8155. fi
  8156. echo 'End of  part 2'
  8157. echo 'File iolib.icn is continued in part 3'
  8158. echo 3 > _shar_seq_.tmp
  8159. exit 0
  8160. -- 
  8161.  
  8162.    -Richard L. Goerwitz              goer%sophist@uchicago.bitnet
  8163.    goer@sophist.uchicago.edu         rutgers!oddjob!gide!sophist!goer
  8164.  
  8165. From icon-group-request@arizona.edu  Tue Oct 15 01:50:36 1991
  8166. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Tue, 15 Oct 91 01:50:36 MST
  8167. Resent-From: icon-group-request@arizona.edu
  8168. Received: from Arizona.edu (Merlin.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  8169.     id AA02416; Tue, 15 Oct 91 01:50:24 MST
  8170. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Tue, 15 Oct
  8171.  1991 01:49 MST
  8172. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA11949; Tue, 15 Oct 91
  8173.  01:42:46 -0700
  8174. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  8175.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  8176.  usenet@ucbvax.Berkeley.EDU if you have questions)
  8177. Resent-Date: Tue, 15 Oct 1991 01:50 MST
  8178. Date: 15 Oct 91 07:35:57 GMT
  8179. From: midway!quads!goer@handies.ucar.edu (Richard L. Goerwitz)
  8180. Subject: iwinds, part 3 of 4
  8181. Sender: icon-group-request@arizona.edu
  8182. Resent-To: icon-group@cs.arizona.edu
  8183. To: icon-group@arizona.edu
  8184. Resent-Message-Id: <19F705ACA0223435@Arizona.edu>
  8185. Message-Id: <1991Oct15.073557.24849@midway.uchicago.edu>
  8186. X-Envelope-To: icon-group@CS.Arizona.EDU
  8187. X-Vms-To: icon-group@Arizona.edu
  8188. Organization: University of Chicago
  8189. References: <1991Oct15.073456.24722@midway.uchicago.edu>
  8190.  
  8191. ---- Cut Here and feed the following to sh ----
  8192. #!/bin/sh
  8193. # this is iwinds.03 (part 3 of a multipart archive)
  8194. # do not concatenate these parts, unpack them in order with /bin/sh
  8195. # file iolib.icn continued
  8196. #
  8197. if test ! -r _shar_seq_.tmp; then
  8198.     echo 'Please unpack part 1 first!'
  8199.     exit 1
  8200. fi
  8201. (read Scheck
  8202.  if test "$Scheck" != 3; then
  8203.     echo Please unpack part "$Scheck" next!
  8204.     exit 1
  8205.  else
  8206.     exit 0
  8207.  fi
  8208. ) < _shar_seq_.tmp || exit 1
  8209. if test ! -f _shar_wnt_.tmp; then
  8210.     echo 'x - still skipping iolib.icn'
  8211. else
  8212. echo 'x - continuing file iolib.icn'
  8213. sed 's/^X//' << 'SHAR_EOF' >> 'iolib.icn' &&
  8214. X#  See also: itlib.icn, iscreen.icn
  8215. X#
  8216. X##########################################################################
  8217. X
  8218. X
  8219. Xglobal tc_table, isDOS
  8220. Xrecord true()
  8221. X
  8222. X
  8223. Xprocedure check_features()
  8224. X
  8225. X    initial {
  8226. X
  8227. X    if find("UNIX",&features) then
  8228. X        isDOS := &null
  8229. X    else if find("MS-DOS", &features) then
  8230. X        isDOS := 1
  8231. X    else stop("check_features:  OS not (yet?) supported.")
  8232. X
  8233. X    find("expressi",&features) |
  8234. X        er("check_features","co-expressions not implemented - &$#!",1)
  8235. X    }
  8236. X
  8237. X    return
  8238. X
  8239. Xend
  8240. X
  8241. X
  8242. X
  8243. Xprocedure setname(name)
  8244. X
  8245. X    # Sets current terminal type to "name" and builds a new termcap
  8246. X    # capability database (residing in tc_table).  Fails if unable to
  8247. X    # find a termcap entry for terminal type "name."  If you want it
  8248. X    # to terminate with an error message under these circumstances,
  8249. X    # comment out "| fail" below, and uncomment the er() line.
  8250. X
  8251. X    #tc_table is global
  8252. X    
  8253. X    check_features()
  8254. X
  8255. X    tc_table := table()
  8256. X    tc_table := maketc_table(getentry(name)) | fail
  8257. X    # er("setname","no termcap entry found for "||name,3)
  8258. X    return "successfully reset for terminal " || name
  8259. X
  8260. Xend
  8261. X
  8262. X
  8263. X
  8264. Xprocedure getname()
  8265. X
  8266. X    # Getname() first checks to be sure we're running under DOS or
  8267. X    # UNIX, and, if so, tries to figure out what the current terminal
  8268. X    # type is, checking successively the value of the environment
  8269. X    # variable TERM, and then (under UNIX) the output of "tset -".
  8270. X    # Terminates with an error message if the terminal type cannot be
  8271. X    # ascertained.  DOS defaults to "mono."
  8272. X
  8273. X    local term, tset_output
  8274. X
  8275. X    check_features()
  8276. X
  8277. X    if \isDOS then {
  8278. X        term := getenv("TERM") | "mono"
  8279. X    }
  8280. X    else {
  8281. X    if not (term := getenv("TERM")) then {
  8282. X        tset_output := open("/bin/tset -","pr") |
  8283. X        er("getname","can't find tset command",1)
  8284. X        term := !tset_output
  8285. X        close(tset_output)
  8286. X    }
  8287. X    }
  8288. X
  8289. X    return \term |
  8290. X    er("getname","can't seem to determine your terminal type",1)
  8291. X
  8292. Xend
  8293. X
  8294. X
  8295. X
  8296. Xprocedure er(func,msg,errnum)
  8297. X
  8298. X    # short error processing utility
  8299. X    write(&errout,func,":  ",msg)
  8300. X    exit(errnum)
  8301. X
  8302. Xend
  8303. X
  8304. X
  8305. X
  8306. Xprocedure getentry(name, termcap_string)
  8307. X
  8308. X    # "Name" designates the current terminal type.  Getentry() scans
  8309. X    # the current environment for the variable TERMCAP.  If the
  8310. X    # TERMCAP string represents a termcap entry for a terminal of type
  8311. X    # "name," then getentry() returns the TERMCAP string.  Otherwise,
  8312. X    # getentry() will check to see if TERMCAP is a file name.  If so,
  8313. X    # getentry() will scan that file for an entry corresponding to
  8314. X    # "name."  If the TERMCAP string does not designate a filename,
  8315. X    # getentry() will scan the termcap file for the correct entry.
  8316. X    # Whatever the input file, if an entry for terminal "name" is
  8317. X    # found, getentry() returns that entry.  Otherwise, getentry()
  8318. X    # fails.
  8319. X
  8320. X    local isFILE, f, getline, line, nm, ent1, ent2, entry
  8321. X    static slash, termcap_names
  8322. X    initial {
  8323. X    if \isDOS then {
  8324. X        slash := "\\"
  8325. X        termcap_names := ["termcap","termcap.dos","termcap2.dos"]
  8326. X    }
  8327. X    else {
  8328. X        slash := "/"
  8329. X        termcap_names := ["/etc/termcap"]
  8330. X    }
  8331. X    }
  8332. X
  8333. X
  8334. X    # You can force getentry() to use a specific termcap file by cal-
  8335. X    # ling it with a second argument - the name of the termcap file
  8336. X    # to use instead of the regular one, or the one specified in the
  8337. X    # termcap environment variable.
  8338. X    /termcap_string := getenv("TERMCAP")
  8339. X
  8340. X    if \isDOS then {
  8341. X    if \termcap_string then {
  8342. X        if termcap_string ? (
  8343. X         not ((tab(any(&letters)), match(":")) | match(slash)),
  8344. X         pos(1) | tab(find("|")+1), =name)
  8345. X        then {
  8346. X        # if entry ends in tc= then add in the named tc entry
  8347. X        termcap_string ?:= tab(find("tc=")) ||
  8348. X            # Recursively fetch the new termcap entry w/ name trimmed.
  8349. X            # Note that on the next time through name won't match the
  8350. X            # termcap environment variable, so getentry() will look for
  8351. X            # a termcap file.
  8352. X            (move(3), getentry(tab(find(":"))) ?
  8353. X             (tab(find(":")+1), tab(0)))
  8354. X        return termcap_string
  8355. X        }
  8356. X        else isFILE := 1
  8357. X    }
  8358. X    }
  8359. X    else {
  8360. X    if \termcap_string then {
  8361. X        if termcap_string ? (
  8362. X            not match(slash), pos(1) | tab(find("|")+1), =name)
  8363. X        then {
  8364. X        # if entry ends in tc= then add in the named tc entry
  8365. X        termcap_string ?:= tab(find("tc=")) ||
  8366. X            # Recursively fetch the new termcap entry w/ name trimmed.
  8367. X            (move(3), getentry(tab(find(":")), "/etc/termcap") ?
  8368. X             (tab(find(":")+1), tab(0)))
  8369. X        return termcap_string
  8370. X        }
  8371. X        else isFILE := 1
  8372. X    }
  8373. X    }
  8374. X
  8375. X    # The logic here probably isn't clear.  The idea is to try to use
  8376. X    # the termcap environment variable successively as 1) a termcap en-
  8377. X    # try and then 2) as a termcap file.  If neither works, 3) go to
  8378. X    # the /etc/termcap file.  The else clause here does 2 and, if ne-
  8379. X    # cessary, 3.  The "\termcap_string ? (not match..." expression
  8380. X    # handles 1.
  8381. X
  8382. X    if \isFILE            # if find(slash, \termcap_string)
  8383. X    then f := open(\termcap_string)
  8384. X    /f := open(!termcap_names) |
  8385. X    er("getentry","I can't access your termcap file.  Read iolib.icn.",1)
  8386. X    
  8387. X    getline := create read_file(f)
  8388. X    
  8389. X    while line := @getline do {
  8390. X    if line ? (pos(1) | tab(find("|")+1), =name, any(':|')) then {
  8391. X        entry := ""
  8392. X        while (\line | @getline) ? {
  8393. X        if entry ||:= 1(tab(find(":")+1), pos(0))
  8394. X        then {
  8395. X            close(f)
  8396. X            # if entry ends in tc= then add in the named tc entry
  8397. X            entry ?:= tab(find("tc=")) ||
  8398. X            # recursively fetch the new termcap entry
  8399. X            (move(3), getentry(tab(find(":"))) ?
  8400. X             # remove the name field from the new entry
  8401. X             (tab(find(":")+1), tab(0)))
  8402. X            return entry
  8403. X        }
  8404. X        else {
  8405. X            \line := &null # must precede the next line
  8406. X            entry ||:= trim(trim(tab(0),'\\'),':')
  8407. X        }
  8408. X        }
  8409. X    }
  8410. X    }
  8411. X
  8412. X    close(f)
  8413. X    er("getentry","can't find and/or process your termcap entry",3)
  8414. Xend
  8415. X
  8416. X
  8417. X
  8418. Xprocedure read_file(f)
  8419. X
  8420. X    # Suspends all non #-initial lines in the file f.
  8421. X    # Removes leading tabs and spaces from lines before suspending
  8422. X    # them.
  8423. X
  8424. X    local line
  8425. X
  8426. X    \f | er("read_tcap_file","no valid termcap file found",3)
  8427. X    while line := read(f) do {
  8428. X    match("#",line) & next
  8429. X    line ?:= (tab(many('\t ')) | &null, tab(0))
  8430. X    suspend line
  8431. X    }
  8432. X
  8433. X    fail
  8434. X
  8435. Xend
  8436. X
  8437. X
  8438. X
  8439. Xprocedure maketc_table(entry)
  8440. X
  8441. X    # Maketc_table(s) (where s is a valid termcap entry for some
  8442. X    # terminal-type): Returns a table in which the keys are termcap
  8443. X    # capability designators, and the values are the entries in
  8444. X    # "entry" for those designators.
  8445. X
  8446. X    local k, v, str, decoded_value
  8447. X
  8448. X    /entry & er("maketc_table","no entry given",8)
  8449. X    if entry[-1] ~== ":" then entry ||:= ":"
  8450. X    
  8451. X    /tc_table := table()
  8452. X
  8453. X    entry ? {
  8454. X
  8455. X    tab(find(":")+1)    # tab past initial (name) field
  8456. X
  8457. X    while tab((find(":")+1) \ 1) ? {
  8458. X        &subject == "" & next
  8459. X        if k := 1(move(2), ="=") then {
  8460. X        # Get rid of null padding information.  Iolib can't
  8461. X        # handle it (unlike itlib.icn).  Leave star in.  It
  8462. X        # indicates a real dinosaur terminal, and will later
  8463. X        # prompt an abort.
  8464. X        str := ="*" | ""; tab(many(&digits))
  8465. X        decoded_value := Decode(str || tab(find(":")))
  8466. X        }
  8467. X        else if k := 1(move(2), ="#")
  8468. X        then decoded_value := integer(tab(find(":")))
  8469. X        else if k := 1(tab(find(":")), pos(-1))
  8470. X        then decoded_value := true()
  8471. X        else er("maketc_table", "your termcap file has a bad entry",3)
  8472. X        /tc_table[k] := decoded_value
  8473. X        &null
  8474. X    }
  8475. X    }
  8476. X
  8477. X    return tc_table
  8478. X
  8479. Xend
  8480. X
  8481. X
  8482. X
  8483. Xprocedure getval(id)
  8484. X
  8485. X    /tc_table := maketc_table(getentry(getname())) |
  8486. X    er("getval","can't make a table for your terminal",4)
  8487. X
  8488. X    return \tc_table[id] | fail
  8489. X    # er("getval","the current terminal doesn't support "||id,7)
  8490. X
  8491. Xend
  8492. X
  8493. X
  8494. X
  8495. Xprocedure Decode(s)
  8496. X
  8497. X    # Does things like turn ^ plus a letter into a genuine control
  8498. X    # character.
  8499. X
  8500. X    local new_s, chr, chr2
  8501. X
  8502. X    new_s := ""
  8503. X
  8504. X    s ? {
  8505. X
  8506. X    while new_s ||:= tab(upto('\\^')) do {
  8507. X        chr := move(1)
  8508. X        if chr == "\\" then {
  8509. X        new_s ||:= {
  8510. X            case chr2 := move(1) of {
  8511. X            "\\" : "\\"
  8512. X            "^"  : "^"
  8513. X            "E"  : "\e"
  8514. X            "b"  : "\b"
  8515. X            "f"  : "\f"
  8516. X            "n"  : "\n"
  8517. X            "r"  : "\r"
  8518. X            "t"  : "\t"
  8519. X            default : {
  8520. X                if any(&digits,chr2) then {
  8521. X                char(integer("8r"||chr2||move(2 to 0 by -1))) |
  8522. X                    er("Decode","bad termcap entry",3)
  8523. X                }
  8524. X               else chr2
  8525. X            }
  8526. X            }
  8527. X        }
  8528. X        }
  8529. X        else new_s ||:= char(ord(map(move(1),&lcase,&ucase)) - 64)
  8530. X    }
  8531. X    new_s ||:= tab(0)
  8532. X    }
  8533. X
  8534. X    return new_s
  8535. X
  8536. Xend
  8537. X
  8538. X
  8539. X
  8540. Xprocedure igoto(cm,col,line)
  8541. X
  8542. X    local colline, range, increment, padding, str, outstr, chr, x, y
  8543. X
  8544. X    if \col > (tc_table["co"]) | \line > (tc_table["li"]) then {
  8545. X    colline := string(\col) || "," || string(\line) | string(\col|line)
  8546. X    range := "(" || tc_table["co"]-1 || "," || tc_table["li"]-1 || ")"
  8547. X    er("igoto",colline || " out of range " || (\range|""),9)
  8548. X    } 
  8549. X
  8550. X    # Use the Iconish 1;1 upper left corner & not the C-ish 0 offsets
  8551. X    increment := -1
  8552. X    outstr := ""
  8553. X    
  8554. X    cm ? {
  8555. X    while outstr ||:= tab(find("%")) do {
  8556. X        tab(match("%"))
  8557. X        if padding := integer(tab(any('23')))
  8558. X        then chr := (="d" | "d")
  8559. X        else chr := move(1)
  8560. X        if case \chr of {
  8561. X        "." :  outstr ||:= char(line + increment)
  8562. X        "+" :  outstr ||:= char(line + ord(move(1)) + increment)
  8563. X        "d" :  {
  8564. X            str := string(line + increment)
  8565. X            outstr ||:= right(str, \padding, "0") | str
  8566. X        }
  8567. X        }
  8568. X        then line :=: col
  8569. X        else {
  8570. X        case chr of {
  8571. X            "n" :  line := ixor(line,96) & col := ixor(col,96)
  8572. X            "i" :  increment := 0
  8573. X            "r" :  line :=: col
  8574. X            "%" :  outstr ||:= "%"
  8575. X            "B" :  line := ior(ishift(line / 10, 4), line % 10)
  8576. X            ">" :  {
  8577. X            x := move(1); y := move(1)
  8578. X            line > ord(x) & line +:= ord(y)
  8579. X            &null
  8580. X            }
  8581. X        } | er("goto","bad termcap entry",5)
  8582. X        }
  8583. X    }
  8584. X    return outstr || tab(0)
  8585. X    }
  8586. X
  8587. Xend
  8588. X
  8589. X
  8590. X
  8591. Xprocedure iputs(cp, affcnt)
  8592. X
  8593. X    # Writes cp to the screen.  Use this instead of writes() for
  8594. X    # compatibility with itlib (a UNIX-only version which can handle
  8595. X    # albeit inelegantly) terminals that need padding.
  8596. X
  8597. X    static num_chars
  8598. X    initial num_chars := &digits ++ '.'
  8599. X
  8600. X    type(cp) == "string" |
  8601. X    er("iputs","you can't iputs() a non-string value!",10)
  8602. X
  8603. X    cp ? {
  8604. X    if tab(many(num_chars)) & ="*" then
  8605. X        stop("iputs:  iolib can't use terminals that require padding.")
  8606. X    writes(tab(0))
  8607. X    }
  8608. X
  8609. X    return
  8610. X
  8611. Xend
  8612. SHAR_EOF
  8613. echo 'File iolib.icn is complete' &&
  8614. true || echo 'restore of iolib.icn failed'
  8615. rm -f _shar_wnt_.tmp
  8616. fi
  8617. # ============= iscreen.icn ==============
  8618. if test -f 'iscreen.icn' -a X"$1" != X"-c"; then
  8619.     echo 'x - skipping iscreen.icn (File already exists)'
  8620.     rm -f _shar_wnt_.tmp
  8621. else
  8622. > _shar_wnt_.tmp
  8623. echo 'x - extracting iscreen.icn (Text)'
  8624. sed 's/^X//' << 'SHAR_EOF' > 'iscreen.icn' &&
  8625. X############################################################################
  8626. X#
  8627. X#    Name:     iscreen.icn
  8628. X#
  8629. X#    Title:     Icon screen functions
  8630. X#
  8631. X#    Author:     Richard L. Goerwitz
  8632. X#
  8633. X#    Version: 1.27
  8634. X#
  8635. X############################################################################
  8636. X#
  8637. X#  This and future version of iscreen are placed in the public domain - RLG
  8638. X#
  8639. X############################################################################
  8640. X#  
  8641. X#      This file contains some rudimentary screen functions for use with
  8642. X#  itlib.icn (termlib-like routines for Icon).
  8643. X#
  8644. X#      clear()              - clears the screen (tries several methods)
  8645. X#      emphasize()          - initiates emphasized (usu. = reverse) mode
  8646. X#      boldface()           - initiates bold mode
  8647. X#      blink()              - initiates blinking mode
  8648. X#      normal()             - resets to normal mode
  8649. X#      message(s)           - displays message s on 2nd-to-last line
  8650. X#      underline()          - initiates underline mode
  8651. X#      status_line(s,s2,p)  - draws status line s on the 3rd-to-last
  8652. X#        screen line; if s is too short for the terminal, s2 is used;
  8653. X#        if p is nonnull then it either centers, left-, or right-justi-
  8654. X#        fies, depending on the value, "c," "l," or "r."
  8655. X#      clear_emphasize()    - horrible way of clearing the screen to all-
  8656. X#        emphasize mode; necessary for many terminals
  8657. X#
  8658. X############################################################################
  8659. X#
  8660. X#  Requires: UNIX
  8661. X#
  8662. X#  Links: itlib.icn (or your OS-specific port of itlib)
  8663. X#
  8664. X#  See also: boldface.icn
  8665. X#
  8666. X############################################################################
  8667. X
  8668. X
  8669. Xprocedure clear()
  8670. X
  8671. X    # Clears the screen.  Tries several methods.
  8672. X    local i
  8673. X
  8674. X    normal()
  8675. X    if not iputs(getval("cl"))
  8676. X    then iputs(igoto(getval("cm"),1,1) | getval("ho"))
  8677. X    if not iputs(getval("cd"))
  8678. X    then {
  8679. X    every i := 1 to getval("li") do {
  8680. X        iputs(igoto(getval("cm"),1,i))
  8681. X        iputs(getval("ce"))
  8682. X    }
  8683. X    iputs(igoto(getval("cm"),1,1))
  8684. X    }
  8685. X    return
  8686. X
  8687. Xend
  8688. X
  8689. X
  8690. X
  8691. Xprocedure boldface()
  8692. X    
  8693. X    static bold_str, cookie_str
  8694. X    initial {
  8695. X    if bold_str := getval("md")
  8696. X    then cookie_str := repl(getval("le"|"bc") | "\b", getval("mg"))
  8697. X    else {
  8698. X        # One global procedure value substituted for another.
  8699. X        boldface := emphasize
  8700. X        return emphasize()
  8701. X    }
  8702. X    }        
  8703. X    normal()
  8704. X    iputs(\bold_str)
  8705. X    iputs(\cookie_str)
  8706. X    return
  8707. X
  8708. Xend
  8709. X
  8710. X
  8711. X
  8712. Xprocedure blink()
  8713. X    
  8714. X    static blink_str, cookie_str
  8715. X    initial {
  8716. X    if blink_str := getval("mb")
  8717. X    then cookie_str :=
  8718. X         repl(getval("le"|"bc") | "\b", getval("mg"))
  8719. X    else {
  8720. X        # One global procedure value substituted for another.
  8721. X        blink := emphasize
  8722. X        return emphasize()
  8723. X    }
  8724. X    }        
  8725. X    normal()
  8726. X    iputs(\blink_str)
  8727. X    iputs(\cookie_str)
  8728. X    return
  8729. X
  8730. Xend
  8731. X
  8732. X
  8733. X
  8734. Xprocedure emphasize()
  8735. X    
  8736. X    static emph_str, cookie_str
  8737. X    initial {
  8738. X    if emph_str := getval("so")
  8739. X    then cookie_str := repl(getval("le"|"bc") | "\b", getval("sg"))
  8740. X    else {
  8741. X        if emph_str := getval("mr")
  8742. X        then cookie_str := repl(getval("le"|"bc") | "\b", getval("mg"))
  8743. X        else if emph_str := getval("us")
  8744. X        then cookie_str := repl(getval("le"|"bc") | "\b", getval("ug"))
  8745. X    }
  8746. X    }        
  8747. X    normal()
  8748. X    iputs(\emph_str)
  8749. X    iputs(\cookie_str)
  8750. X    return
  8751. X
  8752. Xend
  8753. X
  8754. X
  8755. X
  8756. Xprocedure underline()
  8757. X    
  8758. X    static underline_str, cookie_str
  8759. X    initial {
  8760. X    if underline_str := getval("us")
  8761. X    then cookie_str := repl(getval("le"|"bc") | "\b", getval("ug"))
  8762. X    }
  8763. X
  8764. X    normal()
  8765. X    iputs(\underline_str)
  8766. X    iputs(\cookie_str)
  8767. X    return
  8768. X
  8769. Xend
  8770. X
  8771. X
  8772. X
  8773. Xprocedure normal(mode)
  8774. X
  8775. X    static UN_emph_str, emph_cookie_str,
  8776. X    UN_underline_str, underline_cookie_str,
  8777. X    UN_bold_str, bold_cookie_str
  8778. X
  8779. X    initial {
  8780. X
  8781. X    # Find out code to turn off emphasize (reverse video) mode.
  8782. X    if UN_emph_str := getval("se") then
  8783. X        # Figure out how many backspaces we need to erase cookies.
  8784. X        emph_cookie_str := repl(getval("le"|"bc") | "\b", getval("sg"))
  8785. X
  8786. X    # Finally, figure out how to turn off underline mode.
  8787. X    if UN_underline_str := (UN_emph_str ~== getval("ue")) then
  8788. X        underline_cookie_str := repl(getval("le"|"bc")|"\b", getval("ug"))
  8789. X
  8790. X    # Figure out how to turn off boldface mode.
  8791. X    if UN_bold_str := 
  8792. X        (UN_underline_str ~== (UN_emph_str ~== getval("me"))) then
  8793. X        # Figure out how many backspaces we need to erase cookies.
  8794. X        bold_cookie_str := repl(getval("le"|"bc") | "\b", getval("mg"))
  8795. X
  8796. X    }        
  8797. X    
  8798. X    iputs(\UN_emph_str) &
  8799. X    iputs(\emph_cookie_str)
  8800. X
  8801. X    iputs(\UN_underline_str) &
  8802. X    iputs(\underline_cookie_str)
  8803. X
  8804. X    iputs(\UN_bold_str) &
  8805. X    iputs(\bold_cookie_str)
  8806. X
  8807. X    return
  8808. X
  8809. Xend
  8810. X
  8811. X
  8812. X
  8813. Xprocedure status_line(s,s2,p)
  8814. X
  8815. X    # Writes a status line on the terminal's third-to-last line
  8816. X    # The only necessary argument is s.  S2 (optional) is used
  8817. X    # for extra narrow screens.  In other words, by specifying
  8818. X    # s2 you give status_line an alternate, shorter status string
  8819. X    # to display, in case the terminal isn't wide enough to sup-
  8820. X    # port s.  If p is nonnull, then the status line is either
  8821. X    # centered (if equal to "c"), left justified ("l"), or right
  8822. X    # justified ("r").
  8823. X
  8824. X    local width
  8825. X
  8826. X    /s := ""; /s2 := ""; /p := "c"
  8827. X    width := getval("co")
  8828. X    if *s > width then {
  8829. X    (*s2 < width, s := s2) |
  8830. X        er("status_line","Your terminal is too narrow.",4)
  8831. X    }
  8832. X
  8833. X    case p of {
  8834. X    "c"    : s := center(s,width)
  8835. X    "l"    : s := left(s,width)
  8836. X    "r"    : s := right(s,width)
  8837. X    default: stop("status_line:  Unknown option "||string(p),4)
  8838. X    }
  8839. X
  8840. X    iputs(igoto(getval("cm"), 1, getval("li")-2))
  8841. X    emphasize(); writes(s)
  8842. X    normal()
  8843. X    return
  8844. X
  8845. Xend
  8846. X
  8847. X
  8848. X
  8849. Xprocedure message(s)
  8850. X
  8851. X    # Display prompt s on the second-to-last line of the screen.
  8852. X    # I hate to use the last line, due to all the problems with
  8853. X    # automatic scrolling.
  8854. X
  8855. X    /s := ""
  8856. X    normal()
  8857. X    iputs(igoto(getval("cm"), 1, getval("li")))
  8858. X    iputs(getval("ce"))
  8859. X    normal()
  8860. X    iputs(igoto(getval("cm"), 1, getval("li")-1))
  8861. X    iputs(getval("ce"))
  8862. X    writes(s[1:getval("co")] | s)
  8863. X    return
  8864. X
  8865. Xend
  8866. X
  8867. X
  8868. X
  8869. Xprocedure clear_underline()
  8870. X
  8871. X    # Horrible way of clearing the screen to all underline mode, but
  8872. X    # the only apparent way we can do it "portably" using the termcap
  8873. X    # capability database.
  8874. X
  8875. X    local i
  8876. X
  8877. X    underline()
  8878. X    iputs(igoto(getval("cm"),1,1))
  8879. X    if getval("am") then {
  8880. X    underline()
  8881. X        every 1 to (getval("li")-1) * getval("co") do
  8882. X        writes(" ")
  8883. X    }
  8884. X    else {
  8885. X    every i := 1 to getval("li")-1 do {
  8886. X        iputs(igoto(getval("cm"), 1, i))
  8887. X        underline()
  8888. X        writes(repl(" ",getval("co")))
  8889. X    }
  8890. X    }
  8891. X    iputs(igoto(getval("cm"),1,1))
  8892. X
  8893. Xend
  8894. X
  8895. X
  8896. X
  8897. Xprocedure clear_emphasize()
  8898. X
  8899. X    # Horrible way of clearing the screen to all reverse-video, but
  8900. X    # the only apparent way we can do it "portably" using the termcap
  8901. X    # capability database.
  8902. X
  8903. X    local i
  8904. X
  8905. X    emphasize()
  8906. X    iputs(igoto(getval("cm"),1,1))
  8907. X    if getval("am") then {
  8908. X    emphasize()
  8909. X        every 1 to (getval("li")-1) * getval("co") do
  8910. X        writes(" ")
  8911. X    }
  8912. X    else {
  8913. X    every i := 1 to getval("li")-1 do {
  8914. X        iputs(igoto(getval("cm"), 1, i))
  8915. X        emphasize()
  8916. X        writes(repl(" ",getval("co")))
  8917. X    }
  8918. X    }
  8919. X    iputs(igoto(getval("cm"),1,1))
  8920. X
  8921. Xend
  8922. SHAR_EOF
  8923. true || echo 'restore of iscreen.icn failed'
  8924. rm -f _shar_wnt_.tmp
  8925. fi
  8926. # ============= getchlib.icn ==============
  8927. if test -f 'getchlib.icn' -a X"$1" != X"-c"; then
  8928.     echo 'x - skipping getchlib.icn (File already exists)'
  8929.     rm -f _shar_wnt_.tmp
  8930. else
  8931. > _shar_wnt_.tmp
  8932. echo 'x - extracting getchlib.icn (Text)'
  8933. sed 's/^X//' << 'SHAR_EOF' > 'getchlib.icn' &&
  8934. X############################################################################
  8935. X#
  8936. X#    Name:     getchlib.icn
  8937. X#
  8938. X#    Title:     Implementation of getch() for Unix (and more)
  8939. X#
  8940. X#    Author:     Richard L. Goerwitz
  8941. X#
  8942. X#    Version: 1.14
  8943. X#
  8944. X############################################################################
  8945. X#
  8946. X#  I place this and future versions of getchlib in the public domain - RLG
  8947. X#
  8948. X############################################################################
  8949. X#
  8950. X#  Implementing getch() is a much, much more complex affair under Unix
  8951. SHAR_EOF
  8952. true || echo 'restore of getchlib.icn failed'
  8953. fi
  8954. echo 'End of  part 3'
  8955. echo 'File getchlib.icn is continued in part 4'
  8956. echo 4 > _shar_seq_.tmp
  8957. exit 0
  8958. -- 
  8959.  
  8960.    -Richard L. Goerwitz              goer%sophist@uchicago.bitnet
  8961.    goer@sophist.uchicago.edu         rutgers!oddjob!gide!sophist!goer
  8962.  
  8963. From icon-group-request@arizona.edu  Tue Oct 15 01:50:51 1991
  8964. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Tue, 15 Oct 91 01:50:51 MST
  8965. Resent-From: icon-group-request@arizona.edu
  8966. Received: from Arizona.edu (Maggie.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  8967.     id AA02442; Tue, 15 Oct 91 01:50:39 MST
  8968. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Tue, 15 Oct
  8969.  1991 01:49 MST
  8970. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA11903; Tue, 15 Oct 91
  8971.  01:41:50 -0700
  8972. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  8973.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  8974.  usenet@ucbvax.Berkeley.EDU if you have questions)
  8975. Resent-Date: Tue, 15 Oct 1991 01:50 MST
  8976. Date: 15 Oct 91 07:34:56 GMT
  8977. From: midway!quads!goer@handies.ucar.edu (Richard L. Goerwitz)
  8978. Subject: iwinds, part 1 of 4
  8979. Sender: icon-group-request@arizona.edu
  8980. Resent-To: icon-group@cs.arizona.edu
  8981. To: icon-group@arizona.edu
  8982. Resent-Message-Id: <19FE5725D8A13A98@Arizona.edu>
  8983. Message-Id: <1991Oct15.073456.24722@midway.uchicago.edu>
  8984. X-Envelope-To: icon-group@CS.Arizona.EDU
  8985. X-Vms-To: icon-group@Arizona.edu
  8986. Organization: University of Chicago
  8987.  
  8988. I got some interesting comments on the windowing routines, fixed some
  8989. bugs, and what not.  I got several requests for some of the routines
  8990. these windowing routines need to be linked with.  Wrote another little
  8991. demo (this one showing how the arrow keys can be used).  All of this
  8992. added up to my deciding just to post the entire shell archive.
  8993.  
  8994. -Richard
  8995.  
  8996.  
  8997. ---- Cut Here and feed the following to sh ----
  8998. #!/bin/sh
  8999. # This is a shell archive (produced by shar 3.49)
  9000. # To extract the files from this archive, save it to a file, remove
  9001. # everything above the "!/bin/sh" line above, and type "sh file_name".
  9002. #
  9003. # made 10/15/1991 07:10 UTC by goer@sophist.uchicago.edu
  9004. # Source directory /u/richard/Iwinds
  9005. #
  9006. # existing files will NOT be overwritten unless -c is specified
  9007. # This format requires very little intelligence at unshar time.
  9008. # "if test", "cat", "rm", "echo", "true", and "sed" may be needed.
  9009. #
  9010. # This is part 1 of a multipart archive                                    
  9011. # do not concatenate these parts, unpack them in order with /bin/sh        
  9012. #
  9013. # This shar contains:
  9014. # length  mode       name
  9015. # ------ ---------- ------------------------------------------
  9016. #   1451 -rw-r--r-- main.icn
  9017. #   2255 -rw-r--r-- main2.icn
  9018. #  23574 -r--r--r-- iwinds.icn
  9019. #  18055 -r--r--r-- iolib.icn
  9020. #   7069 -r--r--r-- iscreen.icn
  9021. #   9166 -r--r--r-- getchlib.icn
  9022. #   5988 -r--r--r-- complete.icn
  9023. #    380 -rw-r--r-- Makefile.dist
  9024. #    901 -rw-r--r-- README
  9025. #
  9026. if test -r _shar_seq_.tmp; then
  9027.     echo 'Must unpack archives in sequence!'
  9028.     echo Please unpack part `cat _shar_seq_.tmp` next
  9029.     exit 1
  9030. fi
  9031. # ============= main.icn ==============
  9032. if test -f 'main.icn' -a X"$1" != X"-c"; then
  9033.     echo 'x - skipping main.icn (File already exists)'
  9034.     rm -f _shar_wnt_.tmp
  9035. else
  9036. > _shar_wnt_.tmp
  9037. echo 'x - extracting main.icn (Text)'
  9038. sed 's/^X//' << 'SHAR_EOF' > 'main.icn' &&
  9039. X# for UNIX - make sure your IPL is fully updated!
  9040. X# link iwinds, iolib, iscreen, getchlib
  9041. X
  9042. X# non-UNIX
  9043. X# link iwinds, iolib, iscreen (make sure you have getch())
  9044. X
  9045. Xprocedure main()
  9046. X
  9047. X    # global LINES, COLS (defined in iwinds.icn)
  9048. X    local w, w2, w3, y, x
  9049. X
  9050. X    # Initiate windowing mode.
  9051. X    window("on")
  9052. X
  9053. X    # Display a 10x30 window in the upper left corner of the screen.
  9054. X    # Give it a border of spaces in reverse video mode.  Fill the box
  9055. X    # with "x" characters in normal mode.
  9056. X    w := createw(1, 1, 10, 30, 0, "x", "        ", 1)
  9057. X
  9058. X    # Now for fun, move the window just created diagonally down, until
  9059. X    # it gets to the bottom of the screen.  Be sure not to overrun the
  9060. X    # screen.
  9061. X    x := 1
  9062. X    every y := 3 to LINES - 10 by 3 do
  9063. X    movew(w, y, x +:= 6)
  9064. X
  9065. X    # Lay down a small window.
  9066. X    w2 := createw(8, 20, 3, 10, 1)
  9067. X    # Print the word "hello" in it.
  9068. X    writew(w2, "hello", 1, 1)
  9069. X
  9070. X    # Lay down a window over top of the first one.
  9071. X    w3 := createw(14, 50, 9, 30, 0, ".", "        ",1)
  9072. X
  9073. X    # Move the small window down on top of the other two.
  9074. X    x := 20
  9075. X    every y := 11 to LINES - 7 by 3 do
  9076. X    movew(w2, y, x +:= 7)
  9077. X
  9078. X    # Change the message in the little window.
  9079. X    writew(w2, "done!!  ", 1, 1, 3)
  9080. X    # Erase the two big windows.
  9081. X    hidew(w3)
  9082. X    hidew(w)
  9083. X
  9084. X    # Move the little window back up to where it started.
  9085. X    every y := y to 3 by -3 do
  9086. X    movew(w2, y, x -:= 7)
  9087. X
  9088. X    # Quit.
  9089. X    window("off")
  9090. X    exit_prog()
  9091. X
  9092. Xend
  9093. SHAR_EOF
  9094. true || echo 'restore of main.icn failed'
  9095. rm -f _shar_wnt_.tmp
  9096. fi
  9097. # ============= main2.icn ==============
  9098. if test -f 'main2.icn' -a X"$1" != X"-c"; then
  9099.     echo 'x - skipping main2.icn (File already exists)'
  9100.     rm -f _shar_wnt_.tmp
  9101. else
  9102. > _shar_wnt_.tmp
  9103. echo 'x - extracting main2.icn (Text)'
  9104. sed 's/^X//' << 'SHAR_EOF' > 'main2.icn' &&
  9105. Xglobal me
  9106. X
  9107. Xprocedure main()
  9108. X
  9109. X    local command_table, command_set, s, response, tmp
  9110. X    initial {
  9111. X    window("on")
  9112. X    command_table := make_command_table()
  9113. X    command_set := set()
  9114. X    every insert(command_set, key(command_table))
  9115. X    }
  9116. X
  9117. X    me := createw(LINES / 2 - 1, COLS / 2 - 4, 3, 8, 0, " ", "        ", 1)
  9118. X
  9119. X    repeat {
  9120. X    s := ""; response := ""
  9121. X    writew(me, "      ", 2, 2, 0)
  9122. X    writew(me, "", 2, 2, 0)
  9123. X    while s ||:= getch() do {
  9124. X        tmp := []
  9125. X        every put(tmp, complete(s, command_set))
  9126. X        if *tmp > 0 then {
  9127. X        if *tmp = 1 then {
  9128. X            command_table[!tmp]()
  9129. X            s := ""; next
  9130. X        }
  9131. X        else next
  9132. X        } else {
  9133. X        if *s > 1 then {
  9134. X            iputs(getval("vb"|"bl") | "\x07")
  9135. X            break next
  9136. X        }
  9137. X        else {
  9138. X            if any(&digits, s) then {
  9139. X            response ||:= s
  9140. X            writew(me, s,,,0)
  9141. X            s := ""
  9142. X            if *response > 6 then {
  9143. X                iputs(getval("vb"|"bl") | "\x07")
  9144. X                break next
  9145. X            }
  9146. X            next
  9147. X            }
  9148. X            else {
  9149. X            iputs(getval("vb"|"bl") | "\x07")
  9150. X            break next
  9151. X            }
  9152. X        }
  9153. X        }
  9154. X    }
  9155. X    }
  9156. X
  9157. X    # End windowing mode.
  9158. X    window("off")
  9159. X
  9160. Xend
  9161. X
  9162. X
  9163. Xprocedure make_command_table()
  9164. X
  9165. X    local t
  9166. X
  9167. X    t := table()
  9168. X
  9169. X    every insert(t, "y"|getval("K1"|"HM"|"kh"), move_ul)
  9170. X    every insert(t, getval("ku")|"k", move_u)
  9171. X    every insert(t, "u"|getval("K3"|"PU"|"kP"), move_ur)
  9172. X    every insert(t, getval("kr")|"l", move_r)
  9173. X    every insert(t, "n"|getval("K5"|"PD"|"kN"), move_lr)
  9174. X    every insert(t, getval("kd")|"j", move_d)
  9175. X    every insert(t, "b"|getval("K4"|"EN"|"@7"), move_ll)
  9176. X    every insert(t, getval("kl")|"h", move_l)
  9177. X    every insert(t, "\x12", redraw)
  9178. X    return t
  9179. X
  9180. Xend
  9181. X
  9182. X
  9183. Xprocedure move_ul() 
  9184. X    movew(me, 1 < me.begy - 1, 1 < me.begx - 1) &
  9185. X    return
  9186. Xend
  9187. Xprocedure move_u()
  9188. X    movew(me, 1 < me.begy - 1, me.begx) &
  9189. X    return
  9190. Xend
  9191. Xprocedure move_ur()
  9192. X    movew(me, 1 < me.begy - 1, COLS - 7 > me.begx + 1) &
  9193. X    return
  9194. Xend
  9195. Xprocedure move_r()
  9196. X    movew(me, me.begy, COLS - 7 > me.begx + 1) &
  9197. X    return
  9198. Xend
  9199. Xprocedure move_lr()
  9200. X    movew(me, LINES - 2 > me.begy + 1, COLS - 7 > me.begx + 1) &
  9201. X    return
  9202. Xend
  9203. Xprocedure move_d()
  9204. X    movew(me, LINES - 2 > me.begy + 1, me.begx) &
  9205. X    return
  9206. Xend
  9207. Xprocedure move_ll()
  9208. X    movew(me, LINES - 2 > me.begy + 1, 1 < me.begx - 1) &
  9209. X    return
  9210. Xend
  9211. Xprocedure move_l()
  9212. X    movew(me, me.begy, 1 < me.begx - 1) &
  9213. X    return
  9214. Xend
  9215. SHAR_EOF
  9216. true || echo 'restore of main2.icn failed'
  9217. rm -f _shar_wnt_.tmp
  9218. fi
  9219. # ============= iwinds.icn ==============
  9220. if test -f 'iwinds.icn' -a X"$1" != X"-c"; then
  9221.     echo 'x - skipping iwinds.icn (File already exists)'
  9222.     rm -f _shar_wnt_.tmp
  9223. else
  9224. > _shar_wnt_.tmp
  9225. echo 'x - extracting iwinds.icn (Text)'
  9226. sed 's/^X//' << 'SHAR_EOF' > 'iwinds.icn' &&
  9227. X############################################################################
  9228. X#
  9229. X#    Name:     iwinds.icn
  9230. X#
  9231. X#    Title:     windowing routines
  9232. X#
  9233. X#    Author:     Richard L. Goerwitz
  9234. X#
  9235. X#    Version: 1.5 (a very preliminary version)
  9236. X#
  9237. X############################################################################
  9238. X#
  9239. X#  This file contains a relatively small windowing package for use on
  9240. X#  UNIX systems with an installed (and updated) Icon Program Library.
  9241. X#  It will probably work under MS-DOS and other such systems as well,
  9242. X#  although you'll need to read the docs for iolib.icn and iscreen.icn
  9243. X#  in the IPL.
  9244. X#
  9245. X#  Note:  This is not a curses clone, and it is very slow.  I was just
  9246. X#  trying to decide how a windowing interface might possibly be done
  9247. X#  in Icon (which has no pointers, and hence forces me to use things
  9248. X#  like records and global variables where I'd like to use explicit
  9249. X#  pointers to smaller data types).  It's an exercize, and I'd really
  9250. X#  appreciate any advice on how to speed it up.
  9251. X#
  9252. X#  For those seriously interested in character-based I/O that will work
  9253. X#  using stock terminals, check out the work being done by Iconic Soft-
  9254. X#  ware Inc.  They have a curses interface for their Icon interpreter
  9255. X#  that is terminfo based, and runs on most i386 UNIX versions.  As of
  9256. X#  this writing, it's in the end stages of beta testing.
  9257. X#
  9258. X############################################################################
  9259. X#
  9260. X#  This file contains the following routines:
  9261. X#
  9262. X#      createw(begy, begx, lines, cols, wmode, wchar, border, bmode)
  9263. X#      exit_prog(procname, message, exit_code)
  9264. X#      hidew(w)
  9265. X#      movew(w, begy, begx)
  9266. X#      redraw()
  9267. X#      readw(w, ypos, xpos, mode)
  9268. X#      getchw(w, ypos, xpos, mode)  - for no-echo, just use getch()
  9269. X#      window(mode)
  9270. X#      writew(w, s, pos, xpos, mode)
  9271. X#
  9272. X#  To initiate windowing mode one must call window() with the argu-
  9273. X#  ment "on".  To end it, one must call it with the argument "off".
  9274. X#  To "stop" a program while in windowing mode, call exit_prog(),
  9275. X#  using the current function name as arg 1, a diagnostic message as
  9276. X#  arg 2, and an exit code as arg 3.  If you don't follow this
  9277. X#  protocol under UNIX, you'll find your terminal locked up in raw
  9278. X#  mode.
  9279. X#
  9280. X#  To create a window, call createw() with the following arguments, in
  9281. X#  order: 1) the beginning line and 2) the beginning column for the
  9282. X#  upper left-hand square of the window; 3) the number of lines and 4)
  9283. X#  columns the window occupies; if desired, you can specify a default
  9284. X#  mode (5 - where 0 = normal, 1 = reverse video, 2 = underline, and 3
  9285. X#  = boldface), and a default character (6).  You can also specify a
  9286. X#  border (7) and a default mode for the border (8).  Note that the
  9287. X#  border argument must be a string or list with 8 members,
  9288. X#  corresponding to the top left, top, top right, right, bottom right,
  9289. X#  bottom, bottom left, and left characters used to form the border.
  9290. X#  If you call it with some other nonnull argument, "+-+|+-+|" will be
  9291. X#  used as the default.
  9292. X#
  9293. X#  To hide a window on the screen, call hidew(w).  If you want to free
  9294. X#  up the storage occupied by a window, hide it, and then set variables
  9295. X#  that point to it to &null.  If you are anal-retentive, you can call
  9296. X#  collect().  Hidew() fails if you try to hide _mainw, or try to hide
  9297. X#  an already-hidden window.
  9298. X#
  9299. X#  The redraw() procedure (no arguments) redraws the entire physical
  9300. X#  screen.  Movew(w, y, x) moves window w so that its upper left-hand
  9301. X#  corner is at line y and column x.
  9302. X#
  9303. X#  Writew(w, s, y, x, mode) writes string s to window w beginning at
  9304. X#  position y,x using mode as the default mode.  There is no scroll or
  9305. X#  wordwrap, although writes to the bottom right corner will come back
  9306. X#  around to the upper left corner.  I forget why I did things this
  9307. X#  way.
  9308. X#
  9309. X#  Readw(w, y, x, mode) reads and returns a string, echoing it, while
  9310. X#  it is being typed, to window w, starting at position y,x using mode
  9311. X#  as the default mode.  If you want to do non-echoing reads, just use
  9312. X#  getch().  In general, don't read &input using read(), reads(), or
  9313. X#  getche() while in windowing mode.  It will look silly on the screen,
  9314. X#  and if you're running under UNIX, the read functions may not work as
  9315. X#  expected (remember, you're in raw mode).
  9316. X#
  9317. X############################################################################
  9318. X#
  9319. X#  Here's a brief example of how to use this library to do pretty things
  9320. X#  on the screen.  It's nothing very complicated - just some simple window
  9321. X#  drawing and moving exercizes, with one window being used for a message.
  9322. X#
  9323. X#  # for UNIX - make sure your IPL is fully updated!
  9324. X#  link iwinds, iolib, iscreen, getchlib
  9325. X#
  9326. X#  # non-UNIX
  9327. X#  # link iwinds, iolib, iscreen (make sure you have getch())
  9328. X#
  9329. X#  procedure main()
  9330. X#
  9331. X#      # global LINES, COLS (defined in iwinds.icn)
  9332. X#      local w, w2, w3, y, x
  9333. X#
  9334. X#      # Initiate windowing mode.
  9335. X#      window("on")
  9336. X#
  9337. X#      # Display a 10x30 window in the upper left corner of the screen.
  9338. X#      # Give it a border of spaces in reverse video mode.  Fill the box
  9339. X#      # with "x" characters in normal mode.
  9340. X#      w := createw(1, 1, 10, 30, 0, "x", "        ", 1)
  9341. X#
  9342. X#      # Now for fun, move the window just created diagonally down, until
  9343. X#      # it gets to the bottom of the screen.  Be sure not to overrun the
  9344. X#      # screen.
  9345. X#      x := 1
  9346. X#      every y := 3 to LINES - 10 by 3 do
  9347. X#      movew(w, y, x +:= 6)
  9348. X#
  9349. X#      # Lay down a small window.
  9350. X#      w2 := createw(8, 20, 3, 10, 1)
  9351. X#      # Print the word "hello" in it.
  9352. X#      writew(w2, "hello", 1, 1)
  9353. X#
  9354. X#      # Lay down a window over top of the first one.
  9355. X#      w3 := createw(14, 50, 9, 30, 0, ".", "        ",1)
  9356. X#
  9357. X#      # Move the small window down on top of the other two.
  9358. X#      x := 20
  9359. X#      every y := 11 to LINES - 7 by 3 do
  9360. X#      movew(w2, y, x +:= 7)
  9361. X#
  9362. X#      # Change the message in the little window.
  9363. X#      writew(w2, "done!!  ", 1, 1, 3)
  9364. X#      # Erase the two big windows.
  9365. X#      hidew(w3)
  9366. X#      hidew(w)
  9367. X#
  9368. X#      # Move the little window back up to where it started.
  9369. X#      every y := y to 3 by -3 do
  9370. X#        movew(w2, y, x -:= 7)
  9371. X#  
  9372. X#      # Quit.
  9373. X#      window("off")
  9374. X#      exit_prog()
  9375. X#
  9376. X#  end
  9377. X#
  9378. X############################################################################
  9379. X#
  9380. X#  Links: itlib or iolib, iscreen, and some implementation of getche()
  9381. X#
  9382. X############################################################################
  9383. X
  9384. X# UNIX - link itlib, iscreen, getchlib
  9385. X
  9386. X# for debugging purposes
  9387. X# link ximage, radcon
  9388. X
  9389. Xglobal _stdscr, _mainw, isUNIX, COLS, LINES
  9390. Xrecord _square(val, over, under)
  9391. Xrecord _window(wlist, begy,begx, lines,cols, ypos,xpos, border)
  9392. X
  9393. X
  9394. Xprocedure window(mode)
  9395. X
  9396. X    #
  9397. X    # Initiates/ends windowing mode.  If arg1 == "on", then windowing
  9398. X    # mode is turned on; "off" does the opposite.  Returns a string
  9399. X    # containing the current mode.  No arg invocation works the same,
  9400. X    # except that no change occurs in the current mode.
  9401. X    #
  9402. X    static wmode
  9403. X    #global isUNIX
  9404. X    initial {
  9405. X    wmode := "off"
  9406. X    find("UNIX", &features) & isUNIX := "yes"
  9407. X    }
  9408. X
  9409. X    if /mode | (wmode === mode)
  9410. X    then return wmode
  9411. X    else {
  9412. X    case mode of {
  9413. X        "off"  : {
  9414. X        \isUNIX & reset_tty()
  9415. X        normal()
  9416. X        iputs(igoto(getval("cm"), 1, LINES))
  9417. X        }
  9418. X        "on"   : {
  9419. X        \isUNIX & setup_tty()
  9420. X        initscr()
  9421. X        }
  9422. X        default: {
  9423. X        exit_prog("window", "mode arg must be \"on\" or \"off\"", 11)
  9424. X        }
  9425. X    }
  9426. X    }
  9427. X
  9428. X    return wmode := mode
  9429. X
  9430. Xend
  9431. X
  9432. X
  9433. Xprocedure initscr(wmode, wchar, border)
  9434. X
  9435. X    #
  9436. X    # Creates _stdscr, and the main window which covers the terminal
  9437. X    # screen (unless TERM has am capability, i.e. won't let us write
  9438. X    # to the last column without wrapping; in which case make _stdscr
  9439. X    # one column narrower than the physical screen).
  9440. X    #
  9441. X
  9442. X    local begy, begx, ypos, xpos, default_cell, wlist, wlist2, r, c, tmp
  9443. X    # global _stdscr, _mainw, COLS, LINES, isUNIX
  9444. X
  9445. X    \isUNIX & setup_tty()    # initializes raw mode (see getchlib.icn)
  9446. X
  9447. X    #
  9448. X    # Set up default size, position, etc.
  9449. X    #
  9450. X    begy    := 1        # initialize variables for a single, blank
  9451. X    begx    := 1        # normal-mode window starting at 1,1 that
  9452. X
  9453. X    LINES   := getval("li")    # covers the entire screen
  9454. X    COLS    := getval("co")
  9455. X    if getval("am") then    # don't use last col if wordwrap will
  9456. X    COLS -:= 1        # occur
  9457. X    ypos    := 1
  9458. X    xpos    := 1
  9459. X   /border  := &null        # main window normally doesn't get a border
  9460. X
  9461. X   /wmode   := 0        # default mode for _mainw is always 0
  9462. X   /wchar   := " "        # default char for _mainw is always " "
  9463. X    if 0 < *wchar < 2
  9464. X    # then default_cell := -(ishift(wmode,16) + ord(wchar))
  9465. X    then default_cell := -((wmode * 65536) + ord(wchar))
  9466. X    else exit_prog("initscr", "wchar must be a single char or &null", 41)
  9467. X
  9468. X    #
  9469. X    # Create a LINES X COLS array of _square() records.
  9470. X    #
  9471. X    every !(wlist := list(LINES)) := list(COLS)
  9472. X    every !(wlist2 := list(LINES)) := list(COLS)
  9473. X    #
  9474. X    # If blank spaces aren't the default, then flag each square for update.
  9475. X    if wmode = 0 & wchar == " " then {
  9476. X    default_cell := abs(default_cell)
  9477. X    clear()
  9478. X    }
  9479. X    #
  9480. X    every r := 1 to LINES do {
  9481. X    every c := 1 to COLS do {
  9482. X        tmp := _square(default_cell, &null, &null)
  9483. X        wlist[r][c] := tmp
  9484. X        wlist2[r][c] := tmp
  9485. X    }
  9486. X    }
  9487. X    _mainw := _window(wlist, begy,begx, LINES,COLS, ypos,xpos, border)
  9488. X    _stdscr := _window(wlist, begy,begx, LINES,COLS, ypos,xpos)
  9489. X    if not (wmode = 0 & wchar == " " & /border) then
  9490. X    refreshw(_mainw)
  9491. X
  9492. X    return _mainw
  9493. X
  9494. Xend
  9495. X
  9496. X
  9497. Xprocedure refreshw(w, dont_foreground)
  9498. X
  9499. X    #
  9500. X    # Foregrounds & redraws window w on the screen.  If dont_foreground
  9501. X    # is nonnull, then only already-visible portions are updated.  Parts
  9502. X    # covered by other windows are left alone.
  9503. X    #
  9504. X    local y, x, stdscr_y, stdscr_x, stdscr_square, window_square, oldval
  9505. X
  9506. X    /w := _mainw        # _mainw is the default (covers whole screen)
  9507. X
  9508. X    every y := 1 to w.lines do {
  9509. X    every x := 1 to w.cols do {
  9510. X
  9511. X        # Create a handle for manipulating the current square in w.
  9512. X        window_square := w.wlist[y][x]
  9513. X
  9514. X        # If the window isn't to be foregrounded, and the square isn't
  9515. X        # visible, then skip this square.  Go right to the next one.
  9516. X        if \dont_foreground then if \window_square.over then next
  9517. X
  9518. X        # Calculate this square's position on _stdscr.
  9519. X        stdscr_y := y + w.begy - 1
  9520. X        stdscr_x := x + w.begx - 1
  9521. X
  9522. X        # Create a handle for manipulating the square which previously
  9523. X        # occupied the spot we're about to put the current window square
  9524. X        # into.  Drop new square into the old one's spot.
  9525. X        stdscr_square := _stdscr.wlist[stdscr_y][stdscr_x]
  9526. X        _stdscr.wlist[stdscr_y][stdscr_x] := window_square
  9527. X
  9528. X        # If window w already occupies this square in _stdscr, then
  9529. X        # there's no need to reshuffle the _stdscr structure.  If w
  9530. X        # does not occupy this square, though...
  9531. X        if window_square ~=== stdscr_square then {
  9532. X
  9533. X        # ...check to see if the window is farther down the _stdscr
  9534. X        # stacks; if so, then remove it from the stack...
  9535. X        if \window_square.over then {
  9536. X            (\window_square.under).over := window_square.over
  9537. X            window_square.over.under := window_square.under
  9538. X        }
  9539. X
  9540. X        # ...then push the old topmost square "down" the stack, and
  9541. X        # finally place the current square on top.
  9542. X        window_square.under := stdscr_square
  9543. X        window_square.over := stdscr_square.over
  9544. X        stdscr_square.over := window_square
  9545. X        # The old square will need to be updated when it's
  9546. X        # uncovered.
  9547. X        oldval := stdscr_square.val
  9548. X        stdscr_square.val := -abs(oldval)
  9549. X        
  9550. X        # Paranoid check.  The topmost member of the stack should
  9551. X        # always have &null as its "over" pointer.
  9552. X        # /window_square.over | {
  9553. X        #    # write(&errout, "window:\n", (\ximage)(window_square))
  9554. X        #    exit_prog("refreshw", "bizarre stack malformation", 21)
  9555. X        # }
  9556. X        }
  9557. X
  9558. X        # Update the current square on the screen.  Don't bother
  9559. X        # drawing it if the previous one had the same val, and it
  9560. X        # wasn't flagged for update.
  9561. X        if stdscr_square.val ~= window_square.val |
  9562. X        ((\oldval | stdscr_square.val) \ 1) < 0
  9563. X        then draw_it(window_square, stdscr_y, stdscr_x)
  9564. X        else window_square.val := abs(window_square.val)
  9565. X        oldval := &null
  9566. X    }
  9567. X    }
  9568. X
  9569. X    return
  9570. X
  9571. Xend
  9572. X
  9573. X
  9574. Xprocedure draw_it(sq, y, x)
  9575. X
  9576. X    #
  9577. X    # Draws square sq on the physical screen at y,x.
  9578. X    #
  9579. X    local mode
  9580. X    static cm, last_mode, last_y, last_x
  9581. X    # global COLS (number of columns in _stdscr)
  9582. X    initial {
  9583. X    cm := getval("cm")
  9584. X    # initialize to impossible values
  9585. X    last_mode := last_y := last_x := -1
  9586. X    }
  9587. X
  9588. X    # mask out update flag so this square doesn't get updated again
  9589. X    sq.val := abs(sq.val)
  9590. X
  9591. X    # If we aren't at the right position already, then reposition the
  9592. X    # cursor manually.
  9593. X    if not (y = last_y & x = (last_x + 1)) then {
  9594. X        # termlib routines put x before y.
  9595. X    iputs(igoto(cm, x, y))
  9596. X    # If we have to reposition the cursor, reset the mode as well.
  9597. X    # This may not be necessary for most terminals.  We'll see.
  9598. X    # last_mode := -1
  9599. X    }
  9600. X    # record the position we're at
  9601. X    last_y := y; last_x := x
  9602. X
  9603. X    # mode is recorded in bits 16-31 of sq.val
  9604. X    # mode := iand(ishift(sq.val, -16), 32767)
  9605. X    mode := sq.val / 65536
  9606. X    # If there's been a mode change since the last square was written,
  9607. X    # or if the cursor's been repositioned, or if we're at the start
  9608. X    # of a line, then reset the mode.
  9609. X    if (last_mode ~=:= mode) | (y = 1) then {
  9610. X    case mode of {
  9611. X        0 : normal()
  9612. SHAR_EOF
  9613. true || echo 'restore of iwinds.icn failed'
  9614. fi
  9615. echo 'End of  part 1'
  9616. echo 'File iwinds.icn is continued in part 2'
  9617. echo 2 > _shar_seq_.tmp
  9618. exit 0
  9619. -- 
  9620.  
  9621.    -Richard L. Goerwitz              goer%sophist@uchicago.bitnet
  9622.    goer@sophist.uchicago.edu         rutgers!oddjob!gide!sophist!goer
  9623.  
  9624. From icon-group-request@arizona.edu  Tue Oct 15 15:39:13 1991
  9625. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Tue, 15 Oct 91 15:39:13 MST
  9626. Resent-From: icon-group-request@arizona.edu
  9627. Received: from Arizona.edu (Merlin.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  9628.     id AA25062; Tue, 15 Oct 91 15:39:11 MST
  9629. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Tue, 15 Oct
  9630.  1991 15:38 MST
  9631. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA08066; Tue, 15 Oct 91
  9632.  15:11:48 -0700
  9633. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  9634.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  9635.  usenet@ucbvax.Berkeley.EDU if you have questions)
  9636. Resent-Date: Tue, 15 Oct 1991 15:38 MST
  9637. Date: 15 Oct 91 11:45:35 GMT
  9638. From: hsi!mlfarm!rosie!ron@uunet.uu.net (Ronald Florence)
  9639. Subject: RE: windowing; an exercize
  9640. Sender: icon-group-request@arizona.edu
  9641. Resent-To: icon-group@cs.arizona.edu
  9642. To: icon-group@arizona.edu
  9643. Resent-Message-Id: <8DC053CED4A1012A@Arizona.edu>
  9644. Message-Id: <1991Oct15.114535.343@mlfarm.com>
  9645. X-Envelope-To: icon-group@CS.Arizona.EDU
  9646. X-Vms-To: icon-group@Arizona.edu
  9647. Organization: Maple Lawn Farm, Stonington, CT
  9648. References: <1991Oct12.182846.10147@midway.uchicago.edu>
  9649.  
  9650. Richard L. Goerwitz writes:
  9651.  
  9652.    About the speed of the package:  I note that the character-based I/O is
  9653.    not the worst bottleneck.  Actually, the sample file I posted does a lot
  9654.    of internal optimization (e.g. when a window is [re]drawn, only those
  9655.    squares that need to be updated are actually placed on the screen).  The
  9656.    odd thing is that it's the internal machinations that take the time, and
  9657.    not so much the actual interaction with the terminal.  I gather you under-
  9658.    stood this, Ron.  So I'd just modify your statement that the problem is
  9659.    one of character-based I/O in an interpreted system to say merely that the
  9660.    problem is simply one inherent in interpreted systems.  LISP programmers
  9661.    have the same problems when writing systems like emacs (the code for which
  9662.    has to be done largely in C).
  9663.  
  9664. Emacs is a good model for user interface systems.  On some platforms
  9665. emacs runs under X-windows; on others, it drives character-based I/O.
  9666. When you hack a lisp function for the editor, you don't have to worry
  9667. about which interface is in use; emacs takes care of that.
  9668.  
  9669. I guess what I'd like to see for windowing functions in Icon is a set
  9670. of interface-independent functions.  Just as Richard's excellent
  9671. termcap code has made character-based Icon code portable between Unix
  9672. and ms-dos platforms, I wonder if we couldn't draw up a set of
  9673. high-level windowing functions, with link-time hooks to the choice of
  9674. 1) a curses-like character-based package; 2) X-windows for Unix
  9675. platforms; or 3) Windows (or some other interface) for ms-dos systems.
  9676. The Icon coder could then freely use functions like makewindow(),
  9677. writewindow(), or movewindow(), without worrying about the low-level
  9678. interface that actually made and manipulated the windows.  
  9679.  
  9680. Is this just dreaming?  I would have said the same thing about
  9681. portable character-based I/O until I began using Richard's termcap
  9682. functions. 
  9683. -- 
  9684.  
  9685.                 Ronald Florence
  9686.                 ron@mlfarm.com
  9687.  
  9688. From icon-group-request@arizona.edu  Tue Oct 15 18:00:47 1991
  9689. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Tue, 15 Oct 91 18:00:47 MST
  9690. Resent-From: icon-group-request@arizona.edu
  9691. Received: from Arizona.edu (Merlin.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  9692.     id AA10164; Tue, 15 Oct 91 18:00:45 MST
  9693. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Tue, 15 Oct
  9694.  1991 18:00 MST
  9695. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA13818; Tue, 15 Oct 91
  9696.  17:43:08 -0700
  9697. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  9698.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  9699.  usenet@ucbvax.Berkeley.EDU if you have questions)
  9700. Resent-Date: Tue, 15 Oct 1991 18:00 MST
  9701. Date: 16 Oct 91 00:28:45 GMT
  9702. From: midway!quads!goer@uunet.uu.net (Richard L. Goerwitz)
  9703. Subject: RE: windowing; an exercize
  9704. Sender: icon-group-request@arizona.edu
  9705. Resent-To: icon-group@cs.arizona.edu
  9706. To: icon-group@arizona.edu
  9707. Resent-Message-Id: <A1875850B4A0F8BF@Arizona.edu>
  9708. Message-Id: <1991Oct16.002845.8678@midway.uchicago.edu>
  9709. X-Envelope-To: icon-group@CS.Arizona.EDU
  9710. X-Vms-To: icon-group@Arizona.edu
  9711. Organization: University of Chicago
  9712. References: <1991Oct14.001550.21718@mlfarm.com>,
  9713.  <1991Oct14.153712.15751@midway.uchicago.edu>, <1991Oct15.114535.343@mlfarm.com>
  9714.  
  9715. Ronald Florence writes:
  9716.  
  9717. >Emacs is a good model for user interface systems.  On some platforms
  9718. >emacs runs under X-windows; on others, it drives character-based I/O.
  9719. >When you hack a lisp function for the editor, you don't have to worry
  9720. >about which interface is in use; emacs takes care of that.
  9721.  
  9722. Yeah, but the Emacs interface is really just a character-based inter-
  9723. face that's been extended to work in an X environment.  When character
  9724. I/O was all we had, it seemed pretty nice.  I use emacs for all program
  9725. editing still now.  It's not slick, though, by recent standards.  I use
  9726. emacs because it's so extensible and understands the syntax of the lang-
  9727. uages I want to edit (handling parentheses, blocks, comments, etc.) -
  9728. not because of its interface.  I'll bet, Ron, that you use emacs for the
  9729. same reasons.
  9730.  
  9731. >I wonder if we couldn't draw up a set of
  9732. >high-level windowing functions, with link-time hooks to the choice of
  9733. >1) a curses-like character-based package; 2) X-windows for Unix
  9734. >platforms; or 3) Windows (or some other interface) for ms-dos systems.
  9735. >The Icon coder could then freely use functions like makewindow(),
  9736. >writewindow(), or movewindow(), without worrying about the low-level
  9737. >interface that actually made and manipulated the windows.  
  9738.  
  9739. I wonder if this is going to be possible, given the drastic differences
  9740. between bit-mapped and character-based displays.  Ron, I'm still waiting
  9741. around for 16-bit characters and interfaces that are smart enough to
  9742. understand that not all languages wrap left-to-right.  I'm worried that
  9743. a curses-compatible function set would lock in certain misfeatures that
  9744. might not be necessary with other systems.
  9745.  
  9746. Do you have some ideas along these lines?  Clinton has mentioned some formal
  9747. notes on the X<->Icon interface under development.  I guess I feel a bit out
  9748. of this discussion because I just don't have the $ or the space to run a big
  9749. system like X, and I'm not aware of any toolkits that really do what I'd
  9750. need anyway (e.g. write Arabic, Greek, English all at once, getting the word-
  9751. wrap right, and all the ligatures and diacritics as well).  I'm still wait-
  9752. ing for NeXT, which promises that it's going to internationalize its inter-
  9753. face, and also support Unicode.
  9754.  
  9755.  
  9756. -- 
  9757.  
  9758.    -Richard L. Goerwitz              goer%sophist@uchicago.bitnet
  9759.    goer@sophist.uchicago.edu         rutgers!oddjob!gide!sophist!goer
  9760.  
  9761. From cjeffery  Tue Oct 15 22:10:56 1991
  9762. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Tue, 15 Oct 91 22:10:56 MST
  9763. Resent-From: "Clinton Jeffery" <cjeffery>
  9764. Received: from Arizona.edu (Merlin.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  9765.     id AA04444; Tue, 15 Oct 91 22:10:54 MST
  9766. Received: from optima.cs.arizona.edu by Arizona.edu with PMDF#10282; Tue, 15
  9767.  Oct 1991 22:10 MST
  9768. Received: from cheltenham.cs.arizona.edu by optima.cs.arizona.edu (4.1/15) id
  9769.  AA04383; Tue, 15 Oct 91 22:10:20 MST
  9770. Received: by cheltenham.cs.arizona.edu; Tue, 15 Oct 91 22:10:19 MST
  9771. Resent-Date: Tue, 15 Oct 1991 22:10 MST
  9772. Date: Tue, 15 Oct 91 22:10:19 MST
  9773. From: "Clinton L. Jeffery" <cjeffery@cs.arizona.edu>
  9774. Subject: windowing; an exercize
  9775. In-Reply-To: Richard L. Goerwitz's message of 16 Oct 91 00:28:45 GMT
  9776.  <1991Oct16.002845.8678@midway.uchicago.edu>
  9777. Resent-To: icon-group@cs.arizona.edu
  9778. To: icon-group@arizona.edu
  9779. Resent-Message-Id: <C479DD2734A10ABD@Arizona.edu>
  9780. Message-Id: <9110160510.AA19981@cheltenham.cs.arizona.edu>
  9781. X-Envelope-To: icon-group@CS.Arizona.EDU
  9782. X-Vms-To: icon-group@Arizona.edu
  9783.  
  9784. Ronald Florence posed the question (paraphrased):
  9785.    >I wonder if we could... draw up a set of high-level windowing functions,
  9786.    >with...choice of 1) a curses-like character-based package; 2) X-windows
  9787.    >for Unix platforms; or 3) ...other interfaces
  9788. Exerpted from an answer by Richard Goerwitz:
  9789.    I wonder if this is going to be possible, given the drastic differences
  9790.    between bit-mapped and character-based displays....  I'm worried that
  9791.    a curses-compatible function set would lock in certain misfeatures that
  9792.    might not be necessary with other systems.
  9793.  
  9794. Ron's idea is not only possible, it is a good idea, and the implementation
  9795. would not pose insurmountable difficulties.  But *designing* the
  9796. perfect character-based I/O library is an almost impossible task even if
  9797. one restricts oneself to the 8-bit character world that Icon lives in.
  9798. And such a standard is useful only if it is almost universally available
  9799. (to the Icon world, anyhow) and most folks genuinely like it.
  9800.  
  9801. From icon-group-request@arizona.edu  Wed Oct 16 13:57:32 1991
  9802. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Wed, 16 Oct 91 13:57:32 MST
  9803. Resent-From: icon-group-request@arizona.edu
  9804. Received: from Arizona.edu (Merlin.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  9805.     id AA06017; Wed, 16 Oct 91 13:57:30 MST
  9806. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Wed, 16 Oct
  9807.  1991 13:56 MST
  9808. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA20326; Wed, 16 Oct 91
  9809.  13:53:10 -0700
  9810. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  9811.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  9812.  usenet@ucbvax.Berkeley.EDU if you have questions)
  9813. Resent-Date: Wed, 16 Oct 1991 13:57 MST
  9814. Date: 16 Oct 91 19:51:35 GMT
  9815. From: snorkelwacker.mit.edu!paperboy!pnh@bloom-beacon.mit.edu (Peter Harbo)
  9816. Subject: Req project management Icon programs
  9817. Sender: icon-group-request@arizona.edu
  9818. Resent-To: icon-group@cs.arizona.edu
  9819. To: icon-group@arizona.edu
  9820. Resent-Message-Id: <48B7655D54A0FF40@Arizona.edu>
  9821. Message-Id: <PNH.91Oct16155135@pmin24.osf.org>
  9822. X-Envelope-To: icon-group@CS.Arizona.EDU
  9823. X-Vms-To: icon-group@Arizona.edu
  9824. Organization: Open Software Foundation
  9825.  
  9826. This is a request for any programs people may have
  9827. written to determine dependencies between tasks described
  9828. in an ASCII database (Gantt chart or similar prj management
  9829. programs welcomed too).
  9830.  
  9831. From icon-group-request@arizona.edu  Thu Oct 17 20:47:32 1991
  9832. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Thu, 17 Oct 91 20:47:32 MST
  9833. Resent-From: icon-group-request@arizona.edu
  9834. Received: from Arizona.edu (Merlin.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  9835.     id AA14464; Thu, 17 Oct 91 20:47:29 MST
  9836. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Thu, 17 Oct
  9837.  1991 20:46 MST
  9838. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA23407; Thu, 17 Oct 91
  9839.  20:36:45 -0700
  9840. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  9841.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  9842.  usenet@ucbvax.Berkeley.EDU if you have questions)
  9843. Resent-Date: Thu, 17 Oct 1991 20:47 MST
  9844. Date: 17 Oct 91 22:28:12 GMT
  9845. From: sun-barr!cs.utexas.edu!qt.cs.utexas.edu!zaphod.mps.ohio-state.edu!caen!uvaarpa!murdoch!aemsun.med.virginia.edu!sdm7g@ames.arc.nasa.gov
  9846.  (Steven D. Majewski)
  9847. Subject: RE: REXX vs Perl ( vs ICON ? )
  9848. Sender: icon-group-request@arizona.edu
  9849. Resent-To: icon-group@cs.arizona.edu
  9850. To: icon-group@arizona.edu
  9851. Resent-Message-Id: <4B275618E4A05D38@Arizona.edu>
  9852. Message-Id: <1991Oct17.222812.21915@murdoch.acc.Virginia.EDU>
  9853. X-Envelope-To: icon-group@CS.Arizona.EDU
  9854. X-Vms-To: icon-group@Arizona.edu
  9855. Organization: University of Virginia - Physiology Dept.
  9856. References: <28F2FAD7.59FB@tct.com>, <1011@cadlab.sublink.ORG>,
  9857.  <*3aHd=d13@cs.psu.edu>
  9858.  
  9859. In article <*3aHd=d13@cs.psu.edu> flee@cs.psu.edu (Felix Lee) writes:
  9860. >Both languages are fairly traditionally Pascal/Algol-like, with some
  9861. >built-in support for string processing.
  9862. >
  9863. >Perl has better support for aggregate types (vectors and tables) than
  9864. >REXX.  Both languages lack support for nontrivial data types.
  9865. >Perl is more compact for some things, especially string processing,
  9866. >but Perl's syntax is harder to read and learn.
  9867. >
  9868.  
  9869. Is it too much to expect that there is someone capable of adding to this
  9870. thread a comparison of ICON .vs. ( REXX or PERL ) ? 
  9871.  
  9872. What are the other string-processing type languages out there 
  9873. ( that are rather widely used and somewhat portable and excluding:
  9874. yacc,lex,awk, SNOBOL (Icon's ancestor).) ?  Does J ( descendant of APL )
  9875. have any special string processing capabilities ?  
  9876.  
  9877. I know PERL is probably the language of choice on Unix systems because 
  9878. of its very complete interface to system & network functions, but just
  9879. considering string processing capabilities: What language would you use?
  9880. ( Programmer time, not run-time, needs to be minimized. Assume that in
  9881. detail, these are usually one-time problem fixes, but that there will be
  9882. enough similar variations on a theme to discount (somewhat) learning
  9883. time.) 
  9884.  
  9885. [
  9886.   An example of the type of application I'm thinking of: 
  9887.   Take text from several format ascii files : refer, bibtex, and ascii
  9888.   dumps from other data-base programs ( typically, lines containing: 
  9889.   "field: value"  pairs. ), Convert to a canonical punctuation and
  9890.   capitalization, verify values and correct where unambiguous,
  9891.   flag for later correction when ambiguous. Reformat the data to be
  9892.   imported into another database program, possibly splitting single 
  9893.   input fields into multiple output fields. Assume there are LOTS of
  9894.   errors in the input data and that we want to minimise human
  9895.   intervention but we can't spend a *lot* of time making the program 
  9896.   *too* artificially intelligent.
  9897. ]
  9898.  
  9899. ======== "If you have a hammer, find a nail" - George Bush,'91  =========
  9900.  Steven D. Majewski        University of Virginia Physiology Dept.
  9901.  sdm7g@Virginia.EDU        Box 449 Health Sciences Center
  9902.  Voice: (804)-982-0831        1600 Jefferson Park Avenue
  9903.  FAX:   (804)-982-1616        Charlottesville, VA 22908
  9904.  
  9905. From LARSSON@sj03.ts.tele.nokia.fi  Fri Oct 18 07:12:57 1991
  9906. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Fri, 18 Oct 91 07:12:57 MST
  9907. Received: from SJ03.TS.TELE.NOKIA.FI by optima.cs.arizona.edu (4.1/15)
  9908.     id AA06358; Fri, 18 Oct 91 07:12:31 MST
  9909. Date:    Fri, 18 Oct 1991 16:11:53 GMT+0300
  9910. From: LARSSON@sj03.ts.tele.nokia.fi (Arne Larsson tel 358-0-5117476 fax 358-0-51044287)
  9911. Message-Id: <911018161153.20606647@sjclus.tele.nokia.fi>
  9912. Subject: Icon and windows: a possible solution?
  9913. To: icon-group@cs.arizona.edu
  9914. X-Vmsmail-To: INET::"icon-group@cs.arizona.edu"
  9915.  
  9916. One model for doing Windows with Icon could perhaps be patterned on 
  9917. the methods used in Arity Prolog.
  9918.  
  9919. The Arity library for Windows (ARITYW.LIB) is a replacement for ARITY.LIB
  9920. that is used to link Microsoft Windows (R) programs that use Arity/Prolog.
  9921.  
  9922. Programs linked with the ARITYW.LIB must be run in either standard mode
  9923. or enhanced mode. 
  9924.  
  9925. Also, programs linked with ARITYW.LIB can only have one instance running
  9926. at a time.  This is an inherent limitation of large model programs in
  9927. Microsoft Windows. 
  9928.  
  9929. Although it is possible to build dynamic link libraries using Arity/Prolog
  9930. it is not recommended. This is because the DLL's will have limited utility.
  9931. In Microsoft Windows, DLL's can have only one instance of its data segments.
  9932. Therefore unless they are "pure" code and read-only data, they cannot be
  9933. used by more than one application at a time.
  9934.  
  9935. Using this library Windows dialogs etc can be specified in a rather 
  9936. 'linguistic' manner:
  9937.  
  9938. NREV DIALOG LOADONCALL MOVEABLE DISCARDABLE 20, 21, 252, 88
  9939. STYLE DS_MODALFRAME | WS_POPUP
  9940. BEGIN
  9941.     CONTROL "Naive Reverse Benchmark (LIPS)", -1, "static", SS_CENTER | WS_GROUP | WS_CHILD, 0, 9, 252, 9
  9942.     CONTROL "Length of List: ", -1, "static", SS_RIGHT | WS_GROUP | WS_CHILD, 64, 29, 63, 8
  9943.     CONTROL "Number of Iterations: ", -1, "static", SS_RIGHT | WS_GROUP | WS_CHILD, 38, 47, 91, 8
  9944.     CONTROL "", ID_NREV_LEN, "edit", ES_LEFT | WS_BORDER | WS_TABSTOP | WS_CHILD, 151, 27, 25, 11
  9945.     CONTROL "", ID_NREV_CNT, "edit", ES_LEFT | WS_BORDER | WS_TABSTOP | WS_CHILD, 150, 47, 27, 11
  9946.     CONTROL "OK", 1, "button", BS_DEFPUSHBUTTON | WS_TABSTOP | WS_CHILD, 82, 68, 38, 12
  9947.     CONTROL "Cancel", 2, "button", BS_PUSHBUTTON | WS_TABSTOP | WS_CHILD, 139, 68, 38, 12
  9948. END
  9949.  
  9950. NREV2 DIALOG LOADONCALL MOVEABLE DISCARDABLE 24, 19, 228, 95
  9951. STYLE DS_MODALFRAME | WS_POPUP
  9952. BEGIN
  9953.     CONTROL "Naive Reverse Benchmark Results", -1, "static", SS_CENTER | WS_GROUP | WS_CHILD, 0, 1, 228, 8
  9954.     CONTROL "Length of List: ", -1, "static", SS_RIGHT | WS_GROUP | WS_CHILD, 0, 17, 167, 9
  9955.     CONTROL "Number of Iterations: ", -1, "static", SS_RIGHT | WS_GROUP | WS_CHILD, 1, 30, 169, 9
  9956.     CONTROL "Time for Test: ", -1, "static", SS_RIGHT | WS_GROUP | WS_CHILD, 0, 43, 167, 9
  9957.     CONTROL "Logical Inferences per Second (LIPS): ", -1, "static", SS_RIGHT | WS_GROUP | WS_CHILD, 2, 55, 166, 8
  9958.     CONTROL "123456789", ID_NREV2_LEN, "static", SS_LEFT | WS_GROUP | WS_CHILD, 170, 17, 50, 8
  9959.     CONTROL "123456789", ID_NREV2_CNT, "static", SS_LEFT | WS_GROUP | WS_CHILD, 170, 30, 50, 8
  9960.     CONTROL "123456789", ID_NREV2_TIME, "static", SS_LEFT | WS_GROUP | WS_CHILD, 170, 43, 50, 8
  9961.     CONTROL "123456789", ID_NREV2_LIPS, "static", SS_LEFT | WS_GROUP | WS_CHILD, 170, 55, 50, 8
  9962.     CONTROL "OK", 1, "button", BS_DEFPUSHBUTTON | WS_TABSTOP | WS_CHILD, 99, 80, 38, 12
  9963. END
  9964.  
  9965. Resources will be given in .RC files:
  9966.  
  9967. #include "windows.h"
  9968. #include "demo.h"
  9969.  
  9970. #include "demo.dlg"
  9971.  
  9972. DemoMenu MENU
  9973. BEGIN
  9974.     POPUP "&File"
  9975.     BEGIN
  9976.  MENUITEM "A&bout...", IDM_ABOUT
  9977.     END
  9978.     POPUP "&Demos"
  9979.     BEGIN
  9980.  MENUITEM "&NREV...", IDM_NREV
  9981.  MENUITEM "&ZEBRA", IDM_ZEBRA
  9982.  MENUITEM "&Dynamic...", IDM_DYNAMIC
  9983.     END
  9984.     POPUP "D&atabase"
  9985.     BEGIN
  9986.  MENUITEM "&Start Torture test",IDM_STARTTORTURE
  9987.  MENUITEM "Sto&p Torture test",IDM_ENDTORTURE,GRAYED
  9988.     END
  9989. END
  9990.  
  9991. Thus the program code and the user interface specifications are 
  9992. strictly distinct from each other and kept in separate files.
  9993.  
  9994. Similar results could possibly be achieved using some standard 
  9995. library, e.g. the Zink Interface Library (which I've heard about 
  9996. but not seen yet).
  9997.  
  9998. Although I'm definitly not the kind of a wizard, who would be in a 
  9999. position to do all these tricks myself, it seems that the 
  10000. techniques necessary do exist.
  10001.  
  10002. Best regards,
  10003. Arne Larsson
  10004. larsson@sjclus.ts.tele.nokia.fi
  10005.  
  10006. From iwtqg!nowlin@att.att.com  Fri Oct 18 07:32:05 1991
  10007. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Fri, 18 Oct 91 07:32:05 MST
  10008. Message-Id: <9110181432.AA06934@optima.cs.arizona.edu>
  10009. Received: from att.att.com by optima.cs.arizona.edu (4.1/15)
  10010.     id AA06934; Fri, 18 Oct 91 07:32:03 MST
  10011. From: iwtqg!nowlin@att.att.com
  10012. Date: Fri, 18 Oct 91 09:26 CDT
  10013. To: att!cs.arizona.edu!icon-group
  10014. Subject: Re: REXX/Perl/Icon
  10015.  
  10016. > Date: 17 Oct 91 22:28:12 GMT
  10017. > From: (Steven D. Majewski)
  10018. > Subject: RE: REXX vs Perl ( vs ICON ? )
  10019. > In article <*3aHd=d13@cs.psu.edu> flee@cs.psu.edu (Felix Lee) writes:
  10020. > >Both languages are fairly traditionally Pascal/Algol-like, with some
  10021. > >built-in support for string processing.
  10022. > >
  10023. > >Perl has better support for aggregate types (vectors and tables) than
  10024. > >REXX.  Both languages lack support for nontrivial data types.
  10025. > > 
  10026. > >Perl is more compact for some things, especially string processing,
  10027. > >but Perl's syntax is harder to read and learn.
  10028. > Is it too much to expect that there is someone capable of adding to this
  10029. > thread a comparison of ICON .vs. ( REXX or PERL ) ? 
  10030. > ...
  10031.  
  10032. There was a very good comparison of several languages posted to this group
  10033. some time ago.  I don't remember REXX but Perl and Icon were in there.  It
  10034. was very large and I didn't save it.  I imagine it's archived on the U of A
  10035. machine and you can use ftp to get it.  Don't ask me how though.
  10036.  
  10037. I responded because of your assertion:
  10038.  
  10039. > I know PERL is probably the language of choice on Unix systems because 
  10040. > of its very complete interface to system & network functions, ...
  10041.  
  10042. I'm glad you "know" that.  I've been using Icon for over six years and
  10043. working on UNIX for a lot longer.  I've found almost nothing that I
  10044. couldn't do in Icon because I needed a more complete interface to UNIX. 
  10045. There are times I've been forced to use other languages for speed, times
  10046. that the bean counters have forced me to use one of the "supported"
  10047. languages, and times that Icon was not the appropriate language for the
  10048. job.  The interface to UNIX has never been a limiting factor.  The
  10049. pipe-open and system calls in Icon provide plenty of UNIX access and
  10050. flexibility.
  10051.  
  10052. There are some things that I would like to see added to the UNIX interface
  10053. but they would force a language that is designed to run on a variety of
  10054. platforms to incorporate yet another operating system specific wart.
  10055.  
  10056. I know that there are a LOT of programmers that prefer Icon over other
  10057. languages for exactly the reason you cited:
  10058.  
  10059.  
  10060. > ( Programmer time, not run-time, needs to be minimized. Assume that in
  10061. > detail, these are usually one-time problem fixes, but that there will be
  10062. > enough similar variations on a theme to discount (somewhat) learning
  10063. > time.) 
  10064.  
  10065. I'm not presumptuous enough to say Icon is the "language of choice" for any
  10066. one group of programmers.  Although I work on UNIX and it certainly is for
  10067. me :-)
  10068.  
  10069. Jerry Nowlin
  10070.  
  10071. From alex@laguna.metaphor.com  Fri Oct 18 13:53:18 1991
  10072. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Fri, 18 Oct 91 13:53:18 MST
  10073. Received: from relay.metaphor.com by optima.cs.arizona.edu (4.1/15)
  10074.     id AA24092; Fri, 18 Oct 91 13:53:11 MST
  10075. Received: from laguna.Metaphor.COM by relay.metaphor.com (4.1/SMI-4.1)
  10076.     id AA08768; Fri, 18 Oct 91 13:51:22 PDT
  10077. Received: by laguna.Metaphor.COM (4.1/SMI-4.0)
  10078.     id AA06420; Fri, 18 Oct 91 13:52:12 PDT
  10079. Date: Fri, 18 Oct 91 13:52:12 PDT
  10080. From: alex@laguna.metaphor.com (Bob Alexander)
  10081. Message-Id: <9110182052.AA06420@laguna.Metaphor.COM>
  10082. To: icon-group@cs.arizona.edu, sdm7g@virginia.edu
  10083. Subject: Re: REXX/Perl/Icon
  10084.  
  10085. Here is a posting from the net (3/91) that y'all will probably find
  10086. interesting:
  10087.  
  10088. --------------------------------------------------------------------------
  10089.  
  10090.  
  10091. > From icon-group-sender@cs.arizona.edu Sat Mar 30 05:38:29 1991
  10092. > Return-Path: <icon-group-sender@cs.arizona.edu>
  10093. > Received: from relay.metaphor.com by laguna.Metaphor.COM (4.0/SMI-4.0)
  10094. >     id AA06677; Sat, 30 Mar 91 05:38:23 PST
  10095. > Errors-To: icon-group-errors@cs.arizona.edu
  10096. > Received: from megaron.cs.arizona.edu by relay.metaphor.com (4.1/SMI-4.1)
  10097. >     id AA00378; Sat, 30 Mar 91 05:34:21 PST
  10098. > Errors-To: icon-group-errors@cs.arizona.edu
  10099. > Received: by megaron.cs.arizona.edu (5.61/15)
  10100. >     id AA18711; Sat, 30 Mar 91 06:33:57 -0700
  10101. > Resent-From: icon-group-request@arizona.edu
  10102. > Resent-Date: Sat, 30 Mar 1991 06:33 MST
  10103. > Date: 29 Mar 91 16:22:11 GMT
  10104. > From: eru!kth.se!sunic!mcsun!ukc!mucs!m1!bevan@bloom-beacon.mit.edu (Stephen J
  10105. >  Bevan)
  10106. > Subject: Survey Results : Perl vs Icon vs .... (> 500 lines)
  10107. > Sender: icon-group-request@arizona.edu
  10108. > Resent-To: icon-group@cs.arizona.edu
  10109. > To: icon-group@arizona.edu
  10110. > Resent-Message-Id: <E198C3D4FC6051A9@Arizona.edu>
  10111. > Message-Id: <BEVAN.91Mar29162211@panda.cs.man.ac.uk>
  10112. > X-Envelope-To: icon-group@CS.Arizona.EDU
  10113. > X-Vms-To: icon-group@Arizona.edu
  10114. > Organization: Department of Computer Science, University of Manchester
  10115. > Errors-To: icon-group-errors@cs.arizona.edu
  10116. > Status: RO
  10117.  
  10118. [Note I've crossposted to all the groups I send my original message
  10119. to.  This was at the request of some of the respondents (sp?)]
  10120.  
  10121. Here are the results of my question regarding which language to use for
  10122. writing programs to extract information from files, generate reports
  10123. ... etc.  I initially suggested languages like Perl, Icon, Python ...
  10124.  
  10125. As part of my original message I said :-
  10126.  
  10127. > Rather than FTP all of them and wade through the documentation, I was
  10128. > wondering if anybody has experiences with them that they'd like to
  10129. > share?
  10130.  
  10131. I would like to thank the following people for replying :-
  10132.  
  10133. Dan Bernstein - brnstnd@kramden.acf.nyu.edu 
  10134. Tom Christiansen - tchrist@convex.COM
  10135. Chris Eich - chrise@hpnmdla.hp.com
  10136. Richard L. Goerwitz - goer@midway.uchicago.edu
  10137. Clinton Jeffery - cjeffery@cs.arizona.edu
  10138. Guido van Rossum - guido@cwi.nl
  10139. Randal L. Schwartz - merlyn@iWarp.intel.com
  10140. Peter da Silva - peter@ficc.ferranti.com
  10141. Alan Thew - QQ11@LIVERPOOL.AC.UK
  10142. Edward Vielmetti - emv@ox.com
  10143. ?? - russell@ccu1.aukuni.ac.nz
  10144.  
  10145. Most of the replies were about Perl, so I didn't learn much about the
  10146. other languages I suggested (other than very general things).
  10147. Even though I was originally hoping not to have to ftp any stuff, I
  10148. ended up getting the source to Python, GAWK, TCL, Icon and the texinfo
  10149. manual for Perl.
  10150.  
  10151. To save you going through my list of good and bad points of the
  10152. languages I looked at, here is the summary of what I see the languages
  10153. as :-
  10154.  
  10155. TCL - an embedded language i.e. an extension language for large
  10156.       programs (IMHO only if you haven't got, or don't
  10157.       like, Scheme based ones like ELK).
  10158. Perl - the de facto UNIX scripting language.  You name it, and you
  10159.        can probably cobble a solution together in Perl.
  10160.        Beyond the fact that a lot of people use it, I can see nothing
  10161.        to recommend it.  It's a bit like C in that respect.
  10162. Python - Good prototyping language with a consistent design.  It might
  10163.          not have all the low level UNIX stuff built in, but by using 
  10164.          modules, its easy to add the necessary things in an ordered way.
  10165. Icon - the `nearly' language.  Well designed language, that never seemed
  10166.        to make it into general use.  Seems to cover the ground all the
  10167.        way from AWK type applications to Prolog/Lisp ones.
  10168.        If I wasn't already happy with Scheme, I'd use this for more
  10169.        general programming.
  10170.        I would recommend people at least look at this language.
  10171. GAWK - simple scripting language.  Definitely better than `old' awk.
  10172.        I would only use it if the job were really simple or if
  10173.        something like Python or TCL were not available.
  10174.  
  10175. Note I wouldn't expect anybody to make a choice on what I say.  I
  10176. suggest you get the source/manuals yourself and have a good long look
  10177. at the language/implementation before you decide.
  10178.  
  10179. For the types of things _I_ want to do, it would be a tie between Icon
  10180. and Python.  Having said that, given that I'd have to extend both to
  10181. cover the sort of things I want to do, I'll probably use Scheme
  10182. instead (ELK in particular).  The reason I didn't just use Scheme in
  10183. the first place is that I was hoping one of the languages would have
  10184. all the facilities I want without me having to extend them myself.
  10185.  
  10186. Before, the summary of the languages themselves, I thought I'd try and
  10187. list some of the things I was looking for.  (Actually, I showed an
  10188. earlier version of this summary to somebody and they didn't understand
  10189. some of the terms I was using, so this is my attempt at an
  10190. explanation).  Note that most of the things are to do with structuring
  10191. the code and alike.  This is not the sort of thing you usually worry
  10192. about when writing small scripts, but I plan to convert and write a
  10193. number of tools, some of which are around the 1000 LOC mark.  For
  10194. example, I'd like to convert a particular lex/yacc/C program I have
  10195. into the chosen language.
  10196.  
  10197. You can skip ahead to the actual summary by searching for SUMMARY.
  10198. (Well I can do this in GNUS, I don't know about other news readers
  10199. like rn)
  10200.  
  10201. Packages/Modules
  10202. ----------------
  10203. These are a mechanism for splitting up the name space so that function
  10204. name clashes are reduced.  Most systems work by declaring a package
  10205. and then all functions listed from then on are members of that
  10206. package.  You then access the functions using the package prefix, or
  10207. import the whole package so that you don't have to use the prefix.
  10208. The following is an example in CommonLisp :-
  10209.  
  10210. ;;; foo.lsp                     ;;; bar.lsp
  10211. (in-package 'foo)        (in-package 'bar)
  10212. (export '(bob))                 (export '(bob))
  10213. (defun bob (a b) ...)        (defun bob (x) ...)
  10214.  
  10215. ;;; main.lsp
  10216. (foo:bob 10 20)
  10217. (bar:bob 3)
  10218.  
  10219. Packages are not perfect, but they do help.  You can get the same
  10220. effect by declaring implicit package prefixes :-
  10221.  
  10222. ;;; foo.lsp            ;; bar.lsp
  10223. (defun foo-bob (a b) ...)    (defun bar-bob (x) ...)
  10224.  
  10225. ;; main.lsp
  10226. (foo-bob 10 30)
  10227. (bar-bob 4)
  10228.  
  10229. The advantage of packages over this is that you don't have to use a
  10230. package prefix in the package itself when you want to call a function.
  10231. This can be a saving if you have lots of functions in a package, and
  10232. only a few are exported.
  10233.  
  10234. Exception Handling
  10235. ------------------
  10236. This is useful for dealing with error that shouldn't happen. e.g.
  10237. reaching the end of the file when you were looking for some valid
  10238. data.  For example, in CommonLisp :-
  10239.  
  10240. (defun foo (x y)
  10241.   ...
  10242.   (if (catch 'some-unexpexted-error (bar x y) nil)
  10243.     (handle-the-exception ...)
  10244.   
  10245. (define bar (a b)
  10246.   ...
  10247.   (if (something-wrong) (throw 'some-unexpected-error t))
  10248.   ...)
  10249.  
  10250. Here the function `foo' calls `bar', and if any error occurs whilst
  10251. processing, it is handled by the exception handler.  (The example is a
  10252. bit primitive as I'm trying to save space).
  10253.  
  10254. The advantage of this is that you don't have to explicitly pass back
  10255. all sorts of error codes from your functions to handle unusual errors.
  10256. It also usually means you won't have so many nested `if's to handle
  10257. the special cases, therefore, making your code clearer.
  10258.  
  10259. Records/Tuples/Aggregates/Structs
  10260. ---------------------------------
  10261. It's handy to be to define objects that contain certain number of
  10262. elements.  You can then pass these objects around and access the
  10263. individual bits.  For example in CommonLisp :-
  10264.  
  10265. (defstruct point x y)
  10266.  
  10267. This declares `point' as a type containing two items called `x' and
  10268. `y'.  Some languages don't name the items, they rely on position
  10269. instead.  I see these as equivalent (assuming you have some sort of
  10270. pattern matching)
  10271.  
  10272. Provide/Require
  10273. ---------------
  10274. This is a primitive facility for declaring that one package depends on
  10275. another one.  For example in CommonLisp :-
  10276.  
  10277. ;;; foo.lsp
  10278. (defun bob (a b) ...)
  10279. (provide 'foo)
  10280.  
  10281. ;;; main.lsp
  10282. (require 'foo)
  10283. (bob 10 3)
  10284.  
  10285. The above declares that the file `foo' provides the function `bob' and
  10286. that the file `main' requires `foo' to be loaded for it to work.
  10287. So when you load in `main' and `foo' hasn't been loaded, it is
  10288. automatically loaded by the system.
  10289.  
  10290. C Interface
  10291. -----------
  10292. How easy is it to call C from the language.
  10293. Is there a dynamic loading facility i.e. do I have to recompile the
  10294. program to use some arbitrary C code, or can it load in a .o file at
  10295. runtime?
  10296.  
  10297. Arbitrary Restrictions
  10298. ----------------------
  10299. This really applies to the implementations rather than the languages.
  10300. However, as there is only one implementation for most of the languages
  10301. I'm looking at, they tend to be synonymous
  10302.  
  10303. If there is one thing I hate about an [implementation of] a languages
  10304. its arbitrary restrictions.  For example, `the length of the input
  10305. line must not exceed 80 characters', or "strings must be less than 255
  10306. characters long".  I can except some initial restrictions if :-
  10307.  
  10308. 1) they are documented.
  10309. 2) they will be removed in future versions.
  10310.  
  10311. Note. I realise that some restrictions are not arbitrary, or at least
  10312. not under the control of the language implementor e.g. the number of
  10313. open files under UNIX.
  10314.  
  10315. SUMMARY
  10316. -------
  10317. If you want to know more about the languages, there follows a brief
  10318. description of the languages, how to get an implementation and some
  10319. good and bad points as I see them.  Each point is preceded by a
  10320. character indicating the type of point :-
  10321.  
  10322.     +  good point
  10323.     -  bad point
  10324.     *  just a point to note
  10325.     !  subjective point
  10326.  
  10327. Other than the `*' items, I guess it is all subjective, however, I've
  10328. tried to put things that are generally good/bad in `+'/`-' and limit
  10329. really subjective statements to `!'.
  10330.  
  10331.                    TCL - version 4.0 patch level 1
  10332.                    -------------------------------
  10333.  
  10334. TCL (Tool Command Language) was developed by John Ousterhout at Berkeley.
  10335. It started out as a small language that could be embedded in
  10336. applications.  It has now been extended by some people at hackercorp
  10337. into more of a general purpose shell type programming language.
  10338. It is described by Peter Da Silva (one of the people who extended it)
  10339. as :-
  10340.  
  10341. > TCL is like a text-oriented Lisp, but lets you write algebraic
  10342. > expressions for simplicity and to avoid scaring people away.
  10343.  
  10344. The language itself for some reason reminds me of csh even though I
  10345. can only point to two things (the use of `set' and `$') which a
  10346. definitely like csh.
  10347.  
  10348. Unless you have other ideas about what an extension language should
  10349. look like (e.g. IMO it should be Scheme), then I'd definitely
  10350. recommend this.  It's small, and integrates easily with other C
  10351. programs (you can even have multiple TCL interpreters in an
  10352. application!)
  10353.  
  10354. Version 5.0 is available by anonymous ftp from sprite.berkeley.edu as
  10355. tk.tar.Z (its part of an X toolkit called Tk).  Note, although it has
  10356. a higher number than the one above, does not include the extensions
  10357. mentioned above.  These will apparently be integrated soon.
  10358.  
  10359. Version 4.0 pl1 is available by anonymous ftp from
  10360. media-lab.ai.mit.edu (sorry can't remember the exact path)
  10361.  
  10362. +  exceptions.
  10363. +  packages, called libraries
  10364.    However there is only one name-space.  The libraries are used as a
  10365.    way of storing single versions of code rather than as a solution to
  10366.    the name space pollution problem.
  10367. +  provide/require
  10368. +  C interface is excellent.  You can easily go TCL->C and C->TCL.
  10369. -  No dynamic loading ability that I'm aware of.
  10370. -  Arbitrary line length limit on `gets' and `scan'. i.e. the commands
  10371.    that read lines from files/strings.  I would guess this will go
  10372.    away in the next version.
  10373. -  No records.  The main data types are strings/lists/associative arrays
  10374. +  extensive test suite included.
  10375. !  doesn't look to have been tested on many systems.  The above
  10376.    version actually failed to link on a SPARCstation running SunOS 4.1
  10377.    as the source refers to `strerror'.  This has apparently been fixed
  10378.    in patch level 2.
  10379. +  lots of example code included in distribution.
  10380. +  extensive documentation (all in nroff)
  10381. +  Can trace execution.
  10382. !  To make arguments evaluate, you must enclose them in {} or []
  10383.    This shouldn't be a problem, except that being used to Lisp like
  10384.    languages I expect to quote constants.
  10385. !  The extensions though useful, are not seamless. e.g. some string
  10386.    facilities are in the core language and some in the extensions.
  10387.    This might happen when the hackercorp extensions are officially
  10388.    merged with the Berkeley core language and released by Berkeley.
  10389. +  As part of the extensions, you get tclsh.  This is a shell which you
  10390.    can type command directly into.
  10391. +  scan contexts.  This is sort of regular expressions on files rather
  10392.    than strings.
  10393.  
  10394.                         Python - version 0.9.1
  10395.                         ----------------------
  10396.  
  10397. Available by anonymous ftp from wuarchive.wustl.edu as
  10398. pub/python0.9.1.tar.Z or for Europeans via the info server at
  10399. hp4nl.nluug.nl
  10400.  
  10401. I couldn't think of a good way to describe this, so I'm blatantly
  10402. copying the following from the Python tutorial :-
  10403.  
  10404.     Python is a simple, yet powerful programming language that bridges
  10405.     the gap between C and shell programming, and is thus ideally
  10406.     suited for rapid prototyping.  Its syntax is put together from
  10407.     constructs borrowed from a variety of other languages; most
  10408.     prominent are influences from ABC, C, Modula-3 and Icon
  10409.  
  10410. So far so good, here's some more from the tutorial :-
  10411.  
  10412.     Because of its more general data types Python is applicable to a
  10413.     much larger problem domain that Awk or even Perl, yet most simple
  10414.     things are at least as easy in Python as in those languages.
  10415.  
  10416. i.e. Python seems to be designed for larger tasks than you would
  10417. undertake using the shell/awk/perl.
  10418.  
  10419. +  packages.
  10420. +  exceptions (based on Modula 2/3 modules)
  10421. +  records (actually tuples.  I'm not sure they do everything I want
  10422.    as the documentation is a bit vague in this area)
  10423.    Other main types are lists, sets, tables (associative arrays)
  10424. +  C interface is good.  No dynamic linking that I am aware of.
  10425. -  Arbitrary Restrictions
  10426.    line length limit on readline.
  10427.    This has been fixed and I would guess will appear in the next release.
  10428. +  lots of example python programs included.
  10429.    There is even a TCL (version 2ish) interpreter!
  10430. +  Object oriented features.
  10431.    Based on Modula 3 i.e. classes with methods, all of which are
  10432.    virtual (to use a C++ term).
  10433. *  any un caught errors produce a stack trace.
  10434. +  disassembler included
  10435. +  can inspect stack frames via traceback module
  10436. -  no single step or breakpoint facility
  10437.    (maybe in the next release)
  10438. +  functions can return multiple values.
  10439. *  The default output command `print' inserts a space between each
  10440.    field output.
  10441. !  I don't like the above, or rather I would like the option of not
  10442.    having it done.
  10443. *  Documentation includes tutorial and library reference as TeX files.
  10444.    Both are incomplete, but there is enough in them to be able to
  10445.    write Python code.  The reference manual is not yet finished, and
  10446.    is not currently distributed with the source.
  10447. +  Python mode for Emacs.
  10448.    (Its primitive, but its a start)
  10449.  
  10450.                            Icon - version 8
  10451.                            ----------------
  10452.  
  10453. To quote from one of the Icon books :-
  10454.  
  10455.     Icon is a high-level, general purpose programming language that
  10456.     contains many features for processing nonnumeric data,
  10457.     particularly for textual material consisting of string of
  10458.     characters.
  10459.  
  10460. Available :-
  10461. In USA :- ??, consult `archie'.
  10462. In UK :-  I picked up a copy form the sources archive at Imperial College.
  10463.           The JANET address is 00000510200001
  10464.  
  10465. -  no packages.  Everything is in one namespace.  However ...
  10466. -  no exceptions.
  10467. +  Object oriented features.
  10468.    An extension to the language called Idol is included.
  10469.    This converts Idol into standard Icon.
  10470.    Idol itself looks (to me) like Smalltalk.
  10471. +  has records.  Other types include :- sets, lists, strings, tables
  10472. +  unlimited line length when reading
  10473.    (Note. the newline is discarded)
  10474. !  The only language that has enough facilities to be able to re-write
  10475.    some of my Lex/Yacc code.
  10476. +  stack trace on error.
  10477. +  C interface is good.  Can extend the language by building `personal
  10478.    interpreter'.  No dynamic linking.
  10479. +  extensive documentation
  10480.    9 technical reports in all (PostScript and ASCII)
  10481. -  Unix interface is quite primitive.
  10482.    If you just want to use a command, you can use `callout', anything
  10483.    more complicated requires building a personal interpreter (not as
  10484.    difficult as it may sound)
  10485. +  extensive test suite
  10486. +  Usenet group exists specifically for it - comp.lang.icon
  10487. -  Unless you use Idol, all procedures are at the same level
  10488.    i.e. one scope.
  10489. -  regular expressions not supported.
  10490.    However, in many cases, you can use an Icon functions `find',
  10491.    `match', `many' and `upto' instead.
  10492. +  Can trace execution.
  10493. *  Pascal/C like syntax
  10494.    i.e. uses {} but has a few more keywords than C.
  10495. +  lots of example programs included.
  10496. +  can define your own iterators
  10497.    i.e. your own procedures for iterating through arbitrary structures.
  10498. +  co-expressions.  Powerful tool, hard to explain briefly.  See
  10499.    chapter 13 of the Icon Programming Language.
  10500. -  co-expressions haven't been implemented on Sun 4s (the type of
  10501.    machine I use)
  10502. +  has an `initial' section in procedures that is only ever executed
  10503.    once and allows you to initialise C like static variables with the
  10504.    result of other functions (unlike C).
  10505. +  arbitrary precision integers.
  10506.  
  10507. As well as the excellent documentation included in the source, there
  10508. are two books on Icon available (I skimmed through both of them) :-
  10509.  
  10510.     The Icon Programmming Language
  10511.     Ralph E. Griswold and Madge T. Griswold
  10512.     Prentice Hall 1983
  10513.  
  10514.     The Implementation of the Icon Programmming Language
  10515.     Ralph E. Griswold and Madge T. Griswold
  10516.     Princeton University Press 1986
  10517.  
  10518. The second one is particularly useful if you are considering
  10519. extending Icon yourself.  Appendix E of this book also contains a list
  10520. of projects that could be undertaken to extend and improve Icon.
  10521.  
  10522. Here are some projects, that if implemented, would greatly improve the
  10523. usefulness of Icon :-
  10524.  
  10525. E.2.4 Add a regular expression data type.  Modify the functions find
  10526.       and match to perate appropriately when their first argument is a
  10527.       regular expression.
  10528.  
  10529. E.2.5 \  All of these suggest extending
  10530. E.5.4  | the string scanning facilities to
  10531. E.5.5 /  cope with files and strings in a uniform way.
  10532.  
  10533. E.12.1 Provide a way to load functions (written in C) at runtime
  10534.  
  10535.  
  10536.                                  Perl
  10537.                                  ----
  10538. Available :-
  10539. USA :- ??, consult `archie'
  10540. UK :- Imperial sources archive
  10541.  
  10542. I received more responses about Perl than anything else, so I that
  10543. most people already know a lot about the language.
  10544.  
  10545. Here are some edited highlights from a message I received from Tom
  10546. Christiansen :-
  10547.  
  10548. First some good words from Tom :-
  10549.  
  10550. > ... I shall now reveal my true colors as perl disciple
  10551. > and perhaps not infrequent evangelist.  Perl is without question the
  10552. > greatest single program to appear to the UNIX community (although it runs
  10553. > elsewhere too) in the last 10 years.  It makes progamming fun again.  It's
  10554. > simple enough to get a quick start on, but rich enough for some very
  10555. > complex tasks.
  10556.  
  10557. > ... perl is a strict superset of sed and awk, so much so that s2p and
  10558. > a2p translators exist for these utilities.  You can do anything in
  10559. > perl that you can do in the shell, although perl is not strictly
  10560. > speaking a command interpreter.  It's more of a programming language.
  10561.  
  10562. and now some of the low points of Perl.  [Note this is only a small
  10563. part of a long post, that explained a lot of good things about Perl.
  10564. As most people seem to use/like Perl, I thought I'd highlight some of
  10565. the things wrong with the language, and what better place to get
  10566. information than from the designer of the language.  Note also that
  10567. this is from a message dated June 90, so some of it may be out of date.]
  10568.  
  10569. Larry Wall :-
  10570.  
  10571. > The basic problem with Perl is that it's not about complex data structures.
  10572. > Just as spreadsheet programs take a single data structure and try to
  10573. > cram the whole world into it, so too Perl takes a few simple data structures
  10574. > and drives them into the ground.  This is both a strength and a weakness,
  10575. > depending on the complexity and structure of the problem.
  10576. > The basic underlying fault of Perl is that there isn't a real good way
  10577. > of building composite structures, or to make one variable refer to a piece
  10578. > of another variable, without giving an operational definition of it.
  10579. > ...  In a sense, the problem with Perl is not that it is too
  10580. > complicated or hard to learn, but that perhaps it is not expressive
  10581. > enough for the effort you put into learning it.  Then again, maybe it
  10582. > is.  Your call.  Some people are excited about Perl because, despite
  10583. > its obvious faults, it lets them get creative.
  10584. > There are many things I'd do differently if I were designing Perl from
  10585. > scratch.  It would probably be a little more object oriented.  Filehandles
  10586. > and their associated magical variables would probably be abstract types
  10587. > of some sort.  I don't like the way the use of $`, $&, $' and $<digit>
  10588. > impact the efficiency of the language.  I'd probably consider some kind
  10589. > of copy-on-write semantics like many versions of BASIC use.  The subroutine
  10590. > linkage is currently somewhat problematical in how efficiently it can
  10591. > be implemented.  And of course there are historical artifacts that wouldn't
  10592. > be there.
  10593.  
  10594. I think the above is a vary fair summary of the low points of the
  10595. language.  At one point it says `... perhaps it is not expressive
  10596. enought for the effort you put into learning it.  Then again maybe it
  10597. is.  Your call'.  Well _my_ call is that it is not.
  10598.  
  10599. Note I didn't actually pick up the source to this, just the manual.
  10600. Consequently I haven't been able to check all the points listed below.
  10601.  
  10602. +  packages.
  10603. !  Note in the examples that I've seen in comp.lang.perl, people don't
  10604.    seem to use the facility, instead they put everything directly in
  10605.    `main' (i.e. the top level scope) rather than in the local scope.
  10606. +  exceptions
  10607. +  provide/require
  10608. *  C Interface ??  I couldn't find this in the documentation I had.
  10609. +  No arbitrary restrictions
  10610. +  has a source level debugger
  10611. +  Well integrated with Unix (nearly all system calls are built in !)
  10612. !  However, like Unix, only one name space seems to be used (see above)
  10613. *  C like syntax
  10614. +  source contains texinfo manual.
  10615.    You can always buy the (Camel) book for more information.
  10616. -  no records.  Other types lists, strings, tables (associative arrays)
  10617. *  some types have distinct scopes.
  10618. !  You prefix the name with `@', '$', '%' to indicate which type
  10619.    you want.  This is one of the ugliest things I've ever seen.
  10620. !  Uses lots of short strings to contain often used things e.g. `$_'
  10621.    is the current input, `$.' is current line number.  I guess some
  10622.    people must like this, but I prefer names like `input' and
  10623.    `line-number' myself.
  10624. +  includes programs to convert existing awk, find and sed scripts into
  10625.    Perl.
  10626. +  Usenet news group - comp.lang.perl
  10627. +  Perl mode for Emacs.
  10628.  
  10629.                  GAWK
  10630.                  ----
  10631. Available :- 
  10632. USA :- prep.ai.mit.edu, probably other places as well.  Consult `archie'
  10633. UK :- Imperial sources archive.
  10634.  
  10635. A few points about GNU awk as it seems to fix some of the problems
  10636. with `old' awk.
  10637.  
  10638. -  no packages
  10639. -  no exceptions
  10640. -  no C interface 
  10641. -  no records
  10642. +  allows user defined functions
  10643. +  can read and write to arbitrary files
  10644. +  much more informative error messages than the old awk.
  10645.  
  10646.  
  10647. From icon-group-request@arizona.edu  Fri Oct 18 17:20:01 1991
  10648. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Fri, 18 Oct 91 17:20:01 MST
  10649. Resent-From: icon-group-request@arizona.edu
  10650. Received: from Arizona.edu (Maggie.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  10651.     id AA02934; Fri, 18 Oct 91 17:19:59 MST
  10652. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Fri, 18 Oct
  10653.  1991 17:19 MST
  10654. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA05237; Fri, 18 Oct 91
  10655.  17:05:50 -0700
  10656. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  10657.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  10658.  usenet@ucbvax.Berkeley.EDU if you have questions)
  10659. Resent-Date: Fri, 18 Oct 1991 17:19 MST
  10660. Date: 18 Oct 91 15:38:58 GMT
  10661. From: cis.ohio-state.edu!pacific.mps.ohio-state.edu!linac!midway!quads!goer@ucbvax.berkeley.edu (Richard
  10662.  L. Goerwitz)
  10663. Subject: RE: Icon and windows: a possible solution?
  10664. Sender: icon-group-request@arizona.edu
  10665. Resent-To: icon-group@cs.arizona.edu
  10666. To: icon-group@arizona.edu
  10667. Resent-Message-Id: <F753F423EEA046A3@Arizona.edu>
  10668. Message-Id: <1991Oct18.153858.18585@midway.uchicago.edu>
  10669. X-Envelope-To: icon-group@CS.Arizona.EDU
  10670. X-Vms-To: icon-group@Arizona.edu
  10671. Organization: University of Chicago
  10672. References: <911018161153.20606647@sjclus.tele.nokia.fi>
  10673.  
  10674. Arne Larsson writes:
  10675.  
  10676. >One model for doing Windows with Icon could perhaps be patterned on 
  10677. >the methods used in Arity Prolog.
  10678. >
  10679. >The Arity library for Windows (ARITYW.LIB) is a replacement for ARITY.LIB
  10680. >that is used to link Microsoft Windows (R) programs that use Arity/Prolog.
  10681. >
  10682. >Programs linked with the ARITYW.LIB must be run in either standard mode
  10683. >or enhanced mode. 
  10684. >
  10685. >Also, programs linked with ARITYW.LIB can only have one instance running
  10686. >at a time.  This is an inherent limitation of large model programs in
  10687. >Microsoft Windows. 
  10688.  
  10689. I think gave the impression that there are no windows for Icon! There are
  10690. at least three available ways of creating an interface via Icon.  Not all
  10691. are available yet, and I confess that the ones that are are pretty much a
  10692. single-OS affair.  The first is the U of Arizona's own X interface, which
  10693. is not yet part of the standard Icon distribution, but which we may see by
  10694. the spring.  The second is ISI's 3/486 UNIX curses/ETI interface, which
  10695. is now in the late stages of beta testing.  The third is ProIcon, which runs
  10696. on a Mac, and can do lots of those nifty Mac tricks, so I am told.  Of the
  10697. three, the X interface will theoretically be available on the largest num-
  10698. ber of platforms, but will naturally require X.  Curses is implemented on
  10699. many different machines, so theoretically the ISI interface could be ported
  10700. to more platforms.  ISI's implementation is commercial, as is ProIcon.  I
  10701. have not used ProIcon.  ISI's interface is fast and can run on stock ter-
  10702. minals.  It seems well suited for commercial applications involving UNIX/
  10703. {3,4}86 platforms.
  10704.  
  10705. It sounds to me as if the Arity-type solution would represent yet another
  10706. method.  Of course, people who are really interested in creating their own
  10707. solutions can try them out via the Icon extcall mechanism (interpreter).
  10708. The compiler presumably lets you link in and use any C library calls that
  10709. you want.  (Those interested in the compiler should wait, though, until
  10710. the next version is out - one fully in sync with the interpreter; the ver-
  10711. sion on cs.arizona.edu is good, but it's not supposed to be a full-fledged
  10712. production version, and has a few problems with things like type infer-
  10713. encing.)
  10714.  
  10715. The package I posted, incidentally, runs slowly when interpreted.  If com-
  10716. piled using the version of the compiler under development, I'd suspect that
  10717. it would yield acceptable performance.  With the current compiler version,
  10718. it can only be compiled with all the optimizations turned off.  Even in
  10719. that instance, though, it runs twice as fast as the interpreted "execut-
  10720. able."  Of course, this point might be moot when the new compiler comes
  10721. out, depending on how the C interface is structured.
  10722.  
  10723. -- 
  10724.  
  10725.    -Richard L. Goerwitz              goer%sophist@uchicago.bitnet
  10726.    goer@sophist.uchicago.edu         rutgers!oddjob!gide!sophist!goer
  10727.  
  10728. From icon-group-request@arizona.edu  Fri Oct 18 21:36:38 1991
  10729. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Fri, 18 Oct 91 21:36:38 MST
  10730. Resent-From: icon-group-request@arizona.edu
  10731. Received: from Arizona.edu (Maggie.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  10732.     id AA09838; Fri, 18 Oct 91 21:36:36 MST
  10733. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Fri, 18 Oct
  10734.  1991 21:36 MST
  10735. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AB13806; Fri, 18 Oct 91
  10736.  21:33:29 -0700
  10737. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  10738.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  10739.  usenet@ucbvax.Berkeley.EDU if you have questions)
  10740. Resent-Date: Fri, 18 Oct 1991 21:36 MST
  10741. Date: 19 Oct 91 03:04:58 GMT
  10742. From: midway!quads!goer@uunet.uu.net (Richard L. Goerwitz)
  10743. Subject: RE: REXX/Perl/Icon
  10744. Sender: icon-group-request@arizona.edu
  10745. Resent-To: icon-group@cs.arizona.edu
  10746. To: icon-group@arizona.edu
  10747. Resent-Message-Id: <1B2EDE8A58A05F11@Arizona.edu>
  10748. Message-Id: <1991Oct19.030458.10611@midway.uchicago.edu>
  10749. X-Envelope-To: icon-group@CS.Arizona.EDU
  10750. X-Vms-To: icon-group@Arizona.edu
  10751. Organization: University of Chicago
  10752. References: <9110182052.AA06420@laguna.Metaphor.COM>
  10753.  
  10754. Addenda to the 'comparison' posting:
  10755.  
  10756. Where to get Icon -
  10757. >In USA :- ??, consult `archie'.
  10758. >In UK :-  I picked up a copy form the sources archive at Imperial College.
  10759. >          The JANET address is 00000510200001
  10760.  
  10761. USA - cs.arizona.edu
  10762.  
  10763. >-  no packages.  Everything is in one namespace.  However ...
  10764. >-  no exceptions.
  10765.  
  10766. Bzzt.  There is a primitive exception handler.  You can convert most run-
  10767. time errors to expression failure by setting &error to a nonzero value.
  10768. The only problem with this facility is that you must check each expression
  10769. for such failures.  You can't insert an error handler so that it is auto-
  10770. matically called when a given exception occurs.
  10771.  
  10772. >+  Object oriented features.
  10773. >   An extension to the language called Idol is included.
  10774. >   This converts Idol into standard Icon.
  10775. >   Idol itself looks (to me) like Smalltalk.
  10776. >+  has records.  Other types include :- sets, lists, strings, tables
  10777. >+  unlimited line length when reading
  10778. >   (Note. the newline is discarded)
  10779. >!  The only language that has enough facilities to be able to re-write
  10780. >   some of my Lex/Yacc code.
  10781. >+  stack trace on error.
  10782. >+  C interface is good.  Can extend the language by building `personal
  10783. >   interpreter'.  No dynamic linking.
  10784. >+  extensive documentation
  10785. >   9 technical reports in all (PostScript and ASCII)
  10786. >-  Unix interface is quite primitive.
  10787. >   If you just want to use a command, you can use `callout', anything
  10788. >   more complicated requires building a personal interpreter (not as
  10789. >   difficult as it may sound)
  10790. >+  extensive test suite
  10791. >+  Usenet group exists specifically for it - comp.lang.icon
  10792. >-  Unless you use Idol, all procedures are at the same level
  10793. >   i.e. one scope.
  10794. >-  regular expressions not supported.
  10795. >   However, in many cases, you can use an Icon functions `find',
  10796. >   `match', `many' and `upto' instead.
  10797.  
  10798. See below.  Right linear grammars represent a very limited sub-type of
  10799. the kinds of grammars one can recognize and parse using string scanning
  10800. mechanisms of Icon and SNOBOL.  Regular expressions really aren't needed
  10801. in Icon (at least for those who know how to use string scanning).
  10802.  
  10803. >+  Can trace execution.
  10804. >*  Pascal/C like syntax
  10805. >   i.e. uses {} but has a few more keywords than C.
  10806. >+  lots of example programs included.
  10807. >+  can define your own iterators
  10808. >   i.e. your own procedures for iterating through arbitrary structures.
  10809. >+  co-expressions.  Powerful tool, hard to explain briefly.  See
  10810. >   chapter 13 of the Icon Programming Language.
  10811. >-  co-expressions haven't been implemented on Sun 4s (the type of
  10812. >   machine I use)
  10813.  
  10814. They have been implemented since this posting appeared.  In fact, when
  10815. the posting appeared code had actually been posted to the net for Sun4
  10816. coexpressions.  I don't think it had made it into the distribution,
  10817. though.
  10818.  
  10819. >+  has an `initial' section in procedures that is only ever executed
  10820. >   once and allows you to initialise C like static variables with the
  10821. >   result of other functions (unlike C).
  10822. >+  arbitrary precision integers.
  10823.  
  10824. Additional projects that would be good for Icon:
  10825.  
  10826. >E.2.4 Add a regular expression data type.  Modify the functions find
  10827. >      and match to perate appropriately when their first argument is a
  10828. >      regular expression.
  10829.  
  10830. Regular expressions represent a language for representing a very limited
  10831. grammar type (i.e. right linear grammars), and really don't fit into the
  10832. much more elegant and powerful Icon string-scanning mechanisms.  At best
  10833. they are an optimization that might be tacked on.
  10834.  
  10835. Many feel that Icon is big enough without having things tacked on.
  10836.  
  10837. Of course, some would like to see them anyway, just because there are
  10838. some fast algorithms available for them, and because they are fairly
  10839. compact.  If support for regular expressions does get added at some
  10840. point, I sincerely hope that no one will add a new type, or extend the
  10841. builtin functions to handle yet another type.  Just two new functions,
  10842. findre and matchre, would be enough.
  10843.  
  10844. >E.2.5 \  All of these suggest extending
  10845. >E.5.4  | the string scanning facilities to
  10846. >E.5.5 /  cope with files and strings in a uniform way.
  10847. >
  10848. >E.12.1 Provide a way to load functions (written in C) at runtime
  10849.  
  10850.  
  10851. -- 
  10852.  
  10853.    -Richard L. Goerwitz              goer%sophist@uchicago.bitnet
  10854.    goer@sophist.uchicago.edu         rutgers!oddjob!gide!sophist!goer
  10855.  
  10856. From AL302723@VMTECCHI.BITNET  Sun Oct 20 04:08:55 1991
  10857. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Sun, 20 Oct 91 04:08:55 MST
  10858. Received: from Arizona.edu (Merlin.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  10859.     id AA27897; Sun, 20 Oct 91 04:08:52 MST
  10860. Received: from VMTECCHI.CHI.ITESM.MX (MAILER@VMTECCHI) by Arizona.edu with
  10861.  PMDF#10282; Sun, 20 Oct 1991 04:08 MST
  10862. Received: from VMTECCHI (AL302723) by VMTECCHI.CHI.ITESM.MX (Mailer R2.07) with
  10863.  BSMTP id 7554; Sun, 20 Oct 91 01:58:12 EDT
  10864. Date: Sun, 20 Oct 91 01:54:33 EDT
  10865. From: "Mario Camou R." <AL302723@VMTECCHI.BITNET>
  10866. Subject: Icon compiler status...
  10867. To: icon-group@cs.arizona.edu
  10868. Message-Id: <911020.015433.EDT.AL302723@VMTECCHI>
  10869. X-Envelope-To: icon-group@cs.arizona.edu
  10870. Organization: Instituto Tecnologico de Monterrey, Campus Chihuahua
  10871.  
  10872. I've been offline for a while (almost a year now). What's the state of the
  10873. Icon compiler? Has it been ported to MS-DOS?
  10874.  
  10875. +------------------------------------+--------------------------------+
  10876. |     Dr. Mangagoras * StarStaff     |      Mario Camou Riveroll      |
  10877. +------------------------------------+------------+-------------------+
  10878. | Internet:                                       |Bitnet:            |
  10879. |  al302723%vmtecchi.bitnet@tecmtyvm.mty.itesm.mx | em302723@vmtecchi |
  10880. +-------------------------------------------------+-------------------+
  10881. |              Laugh at life....or life will laugh at you             |
  10882. +---------------------------------------------------------------------+
  10883.  
  10884. From icon-group-request@arizona.edu  Sun Oct 20 05:26:01 1991
  10885. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Sun, 20 Oct 91 05:26:01 MST
  10886. Resent-From: icon-group-request@arizona.edu
  10887. Received: from Arizona.edu (Hopey.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  10888.     id AA00347; Sun, 20 Oct 91 05:25:58 MST
  10889. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Sun, 20 Oct
  10890.  1991 05:25 MST
  10891. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA05155; Sun, 20 Oct 91
  10892.  05:18:12 -0700
  10893. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  10894.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  10895.  usenet@ucbvax.Berkeley.EDU if you have questions)
  10896. Resent-Date: Sun, 20 Oct 1991 05:25 MST
  10897. Date: 20 Oct 91 08:07:24 GMT
  10898. From: cis.ohio-state.edu!zaphod.mps.ohio-state.edu!samsung!nstar!towers!yngbld!zeta@ucbvax.berkeley.edu
  10899.  (Gregory Youngblood)
  10900. Subject: COMM
  10901. Sender: icon-group-request@arizona.edu
  10902. Resent-To: icon-group@cs.arizona.edu
  10903. To: icon-group@arizona.edu
  10904. Resent-Message-Id: <25EB10A138A0F228@Arizona.edu>
  10905. Message-Id: <2mT401w164w@yngbld.rn.com>
  10906. X-Envelope-To: icon-group@CS.Arizona.EDU
  10907. X-Vms-To: icon-group@Arizona.edu
  10908. Organization: The Home Grown BBS
  10909.  
  10910. I just d/l ed the MSDOS version of the icon interpreter.
  10911.  
  10912. I haven't run it or anything yet, but am looking forward to getting started 
  10913. on it as soon as possible.
  10914.  
  10915. One of the first things I'm going to be working on is going to require the 
  10916. use of the comm ports, mainly com1 under MSDOS.
  10917.  
  10918. I would welcome any and all advice on installing this version on my 386-33, 
  10919. so i can get this up and running so i can start using it as soon as 
  10920. possible.
  10921.  
  10922. I would also welcome any hints/tricks/help on programming using the comm 
  10923. ports.
  10924.  
  10925. Thankx
  10926. Greg
  10927.  
  10928. REPLIES TO:      zeta@yngbld.rn.com
  10929. The Home Grown BBS     308-237-7501     9600 v.32/v.42bis
  10930.  
  10931. From @um.cc.umich.edu:Paul_Abrahams@MTS.cc.Wayne.edu  Mon Oct 21 06:09:00 1991
  10932. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Mon, 21 Oct 91 06:09:00 MST
  10933. Received: from mailrus.cc.umich.edu by optima.cs.arizona.edu (4.1/15)
  10934.     id AA00739; Mon, 21 Oct 91 06:08:58 MST
  10935. Received: from um.cc.umich.edu by mailrus.cc.umich.edu (5.61/1123-1.0)
  10936.     id AA09577; Mon, 21 Oct 91 09:05:11 -0400
  10937. Received: from MTS.cc.Wayne.edu by um.cc.umich.edu via MTS-Net; Mon, 21 Oct 91 09:07:48 EDT
  10938. Date: Mon, 21 Oct 91 09:07:28 EDT
  10939. From: Paul_Abrahams@mts.cc.wayne.edu
  10940. To: icon-group@cs.arizona.edu
  10941. Message-Id: <376109@MTS.cc.Wayne.edu>
  10942. Subject: Icon versus Awk
  10943.  
  10944.  
  10945. I'd say that Icon is immeasurably superior to awk for programs of more
  10946. than a few (say 5) lines.  Icon is elegant and powerful, while awk is
  10947. just a mess.  The idea of using juxtaposition to indicate concatenation,
  10948. for instance, is a leftover from Snobol that Icon very sensibly tossed
  10949. in the trash.  The awk expression syntax is ridiculous---no clear
  10950. distinction between expressions and statements, yet the two are *not*
  10951. interchangeable.  Why should "close" be a statement while "getline"
  10952. is an expression?  Who knows?  The dual use of "<" for redirection and
  10953. for comparison is madness.  And on the semantic level, has anyone figured
  10954. out how to use "gsub" for any nontrivial useful substitutions?  Or
  10955. how about the wierdnesses of awk function definitions?
  10956.  
  10957. Yet having said all that: awk is probably the superior language for
  10958. *really* short programs, if they happen to fit its model.  You can't
  10959. write useful one-liners in Icon, but you can in awk.  Nor can you write
  10960. an Icon program on the command line as you can with awk.  I'm not sure
  10961. where the cutoff is---one line, two lines, five, or ten.  Under the
  10962. cutoff, awk wins; over the cutoff, Icon does.  The advantages of Icon,
  10963. of course, grow as the program gets longer.
  10964.  
  10965. I'd be interested in postings of *really short* Icon programs that do
  10966. something more useful than hello-worlding.  No fair cramming ten
  10967. expressions onto one line.
  10968.  
  10969. Paul Abrahams
  10970. Abrahams@mts.cc.wayne.edu
  10971.  
  10972. From iwtqg!nowlin@att.att.com  Mon Oct 21 07:03:18 1991
  10973. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Mon, 21 Oct 91 07:03:18 MST
  10974. Message-Id: <9110211403.AA02167@optima.cs.arizona.edu>
  10975. Received: from att.att.com by optima.cs.arizona.edu (4.1/15)
  10976.     id AA02167; Mon, 21 Oct 91 07:03:16 MST
  10977. From: iwtqg!nowlin@att.att.com
  10978. Date: Sat, 24 Feb 90 21:41 CST
  10979. To: att!cs.arizona.edu!icon-group
  10980. Subject: Re: Icon versus Awk
  10981.  
  10982.  > Paul Abrahams writes...
  10983.  >
  10984.  > I'd be interested in postings of *really short* Icon programs that do
  10985.  > something more useful than hello-worlding.  No fair cramming ten
  10986.  > expressions onto one line.
  10987.  
  10988. I use this program frequently to convert UNIX text files to DOS text files
  10989. by adding carriage returns to the end of each line:
  10990.  
  10991.     procedure main()
  10992.         while write(read(),"\r")
  10993.     end
  10994.  
  10995. The awk alternative is shorter but no more simple:
  10996.  
  10997.     nawk ' { print $0 "\r" } '
  10998.  
  10999.  
  11000.  > Yet having said all that: awk is probably the superior language for
  11001.  > *really* short programs, if they happen to fit its model.  You can't
  11002.  > write useful one-liners in Icon, but you can in awk.  Nor can you write
  11003.  > an Icon program on the command line as you can with awk.  I'm not sure
  11004.  
  11005. You can use contrived one-liners:
  11006.  
  11007.     procedure main() ; while write(read(),"\r") ; end
  11008.  
  11009. In fact, I have frequently typed in Icon programs this short from the
  11010. command line using the "- -x" flags.  Simple one shot base conversions is
  11011. an example:
  11012.  
  11013.     icont - -x
  11014.     procedure main()
  11015.     write(16raaa)
  11016.     end
  11017.     <EOF>
  11018.     2730
  11019.  
  11020. This is about as quick as it gets for simple programs to convert to base 10
  11021. unless you have an already written Icon program to do it for you :-)
  11022.  
  11023. Jerry Nowlin
  11024.  
  11025.  
  11026. From ralph  Mon Oct 21 07:30:59 1991
  11027. Date: Mon, 21 Oct 91 07:30:59 MST
  11028. From: "Ralph Griswold" <ralph>
  11029. Message-Id: <9110211430.AA26509@cheltenham.cs.arizona.edu>
  11030. Received: by cheltenham.cs.arizona.edu; Mon, 21 Oct 91 07:30:59 MST
  11031. To: icon-group
  11032. Subject: Icon one-liners
  11033.  
  11034. Assuming you're not sticking at the necessary procedure wrapper or
  11035. are willing to accept Jerry Nowlin's format, there is a large
  11036. class of useful Icon one-liners, of which this is an example:
  11037.  
  11038. procedure main()
  11039.     every write(numeric(!&input))
  11040. end
  11041.  
  11042. This particular instance of the class filters out lines of a file
  11043. that are not numeric.
  11044.     
  11045.     Ralph Griswold / Department of Computer Science 
  11046.     The University of Arizona / Tucson, AZ 85721
  11047.     
  11048.     ralph@cs.arizona.edu / uunet!arizona!ralph
  11049.     
  11050.     voice: 602-621-6609 / fax: 602-621-9618
  11051.  
  11052. From ralph  Mon Oct 21 07:33:54 1991
  11053. Date: Mon, 21 Oct 91 07:33:54 MST
  11054. From: "Ralph Griswold" <ralph>
  11055. Message-Id: <9110211433.AA26583@cheltenham.cs.arizona.edu>
  11056. Received: by cheltenham.cs.arizona.edu; Mon, 21 Oct 91 07:33:54 MST
  11057. To: icon-group
  11058. Subject: Icon one-liners
  11059.  
  11060. Here's a short program by Anthony Hewitt that I particularly like for
  11061. it's "Iconishness" if not its transparancy.  I've resisted putting it
  11062. on one line.
  11063.  
  11064. procedure main()
  11065.    write(s := !&input)
  11066.    every write(s ~==:= !&input)
  11067. end
  11068.  
  11069. It filters out identical adjacent lines in a file.
  11070.     
  11071.     Ralph Griswold / Department of Computer Science 
  11072.     The University of Arizona / Tucson, AZ 85721
  11073.     
  11074.     ralph@cs.arizona.edu / uunet!arizona!ralph
  11075.     
  11076.     voice: 602-621-6609 / fax: 602-621-9618
  11077.  
  11078. From alex@laguna.metaphor.com  Mon Oct 21 12:47:29 1991
  11079. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Mon, 21 Oct 91 12:47:29 MST
  11080. Received: from relay.metaphor.com by optima.cs.arizona.edu (4.1/15)
  11081.     id AA15620; Mon, 21 Oct 91 12:47:27 MST
  11082. Received: from laguna.Metaphor.COM by relay.metaphor.com (4.1/SMI-4.1)
  11083.     id AA10231; Mon, 21 Oct 91 12:46:36 PDT
  11084. Received: by laguna.Metaphor.COM (4.1/SMI-4.0)
  11085.     id AA08288; Mon, 21 Oct 91 12:47:29 PDT
  11086. Date: Mon, 21 Oct 91 12:47:29 PDT
  11087. From: alex@laguna.metaphor.com (Bob Alexander)
  11088. Message-Id: <9110211947.AA08288@laguna.Metaphor.COM>
  11089. To: icon-group@cs.arizona.edu
  11090. Subject: Making a two-liner into one
  11091.  
  11092. Here's a proposed improvement on one of Ralph's almost-one-liners (trying to
  11093. recall the exact text -- I deleted the message):
  11094.  
  11095.   write(s := &input)               --->   every write(s ~===:= !&input)
  11096.   every write(s ~==:= !&input)
  11097.  
  11098. I haven't tested it -- too lazy -- but I think this version is slightly
  11099. more equal than its predecessor (pun intended).
  11100.  
  11101.  
  11102. Here's a one-liner I use occasionally to see exactly what is being passed
  11103. to commands:
  11104.  
  11105.   procedure main(arg)
  11106.     every write(image(!arg))
  11107.   end
  11108.  
  11109.  
  11110. -- Bob Alexander
  11111.  
  11112. Metaphor Computer Systems   (415) 961-3600 x751   alex@metaphor.com
  11113. ====^=== Mountain View, CA  ...{uunet}!{decwrl,apple}!metaphor!alex
  11114.  
  11115. From iwtqg!nowlin@att.att.com  Mon Oct 21 13:34:57 1991
  11116. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Mon, 21 Oct 91 13:34:57 MST
  11117. Message-Id: <9110212034.AA01023@optima.cs.arizona.edu>
  11118. Received: from att.att.com by optima.cs.arizona.edu (4.1/15)
  11119.     id AA01023; Mon, 21 Oct 91 13:34:54 MST
  11120. From: iwtqg!nowlin@att.att.com
  11121. Date: Mon, 21 Oct 91 15:31 CDT
  11122. To: att!cs.arizona.edu!icon-group
  11123. Subject: Re: Icon one-liners
  11124.  
  11125. If you get right down to it and parse an awk script with the kind of
  11126. syntactical breaks that are typically used for procedural languages like
  11127. Icon you don't really have one-liners.  For example, the one-liners I
  11128. compared earlier could reasonably be written like this:
  11129.  
  11130.     nawk ' { print $0 "\r" } '
  11131.  
  11132.     procedure main() ; while write(read(),"\r") ; end
  11133.  
  11134. or like this:
  11135.  
  11136.     nawk '
  11137.         {
  11138.             print $0 "\r"
  11139.         }
  11140.     '
  11141.  
  11142.     procedure main()
  11143.         while write(read(),"\r")
  11144.     end
  11145.  
  11146. Which uses more lines or characters isn't as important as which one a
  11147. naive user can grasp without a manual or tutorial.  Guess which one gets
  11148. my vote?
  11149.  
  11150. Jerry Nowlin
  11151.  
  11152. From kwalker  Mon Oct 21 14:26:50 1991
  11153. Received: from gacham.cs.arizona.edu by cheltenham.cs.arizona.edu; Mon, 21 Oct 91 14:26:50 MST
  11154. Date: Mon, 21 Oct 91 14:26:48 MST
  11155. From: "Kenneth Walker" <kwalker>
  11156. Message-Id: <9110212126.AA04784@gacham.cs.arizona.edu>
  11157. Received: by gacham.cs.arizona.edu; Mon, 21 Oct 91 14:26:48 MST
  11158. In-Reply-To: <911020.015433.EDT.AL302723@VMTECCHI>
  11159. To: icon-group
  11160. Subject: Re:  Icon compiler status...
  11161.  
  11162. > Date: Sun, 20 Oct 91 01:54:33 EDT
  11163. > From: "Mario Camou R." <AL302723@VMTECCHI.BITNET>
  11164. > I've been offline for a while (almost a year now). What's the state of the
  11165. > Icon compiler? Has it been ported to MS-DOS?
  11166.  
  11167. There is a "pre-release" Unix version of the compiler at about V7.6 of
  11168. Icon. We have in-house a V8.? version that still needs some work
  11169. before a public release. Some work has been done under MS-DOS, but the
  11170. compiler uses a lot of memory. It probably will not be useful on a
  11171. 640K machine. We think it will be usable on a 386/486 machine in
  11172. conjunction with a C compiler that has built-in DOS extender. Such
  11173. a version of the compiler will not be available for a while though.
  11174.  
  11175.   Ken Walker / Computer Science Dept / Univ of Arizona / Tucson, AZ 85721
  11176.   +1 602 621-4252  kwalker@cs.arizona.edu {uunet|allegra|noao}!arizona!kwalker
  11177.  
  11178. From TENAGLIA@mis.mcw.edu  Mon Oct 21 14:43:46 1991
  11179. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Mon, 21 Oct 91 14:43:46 MST
  11180. Received: from mis3.mis.mcw.edu by optima.cs.arizona.edu (4.1/15)
  11181.     id AA04425; Mon, 21 Oct 91 14:43:40 MST
  11182. Received: from mis.mcw.edu by mis.mcw.edu (PMDF #12252) id
  11183.  <01GC0JH3HOV491VW6Q@mis.mcw.edu>; Mon, 21 Oct 1991 16:45 CST
  11184. Date: Mon, 21 Oct 1991 16:45 CST
  11185. From: Chris Tenaglia - 257-8765 <TENAGLIA@mis.mcw.edu>
  11186. Subject: One liners
  11187. To: icon-group@cs.arizona.edu
  11188. Message-Id: <01GC0JH3HOV491VW6Q@mis.mcw.edu>
  11189. X-Organization: Medical College of Wisconsin (Milwaukee, WI)
  11190. X-Vms-To: IN%"icon-group@cs.arizona.edu"
  11191.  
  11192.  
  11193. I don't think this could really be considered a one liner, but I have
  11194. a program I call Igrep/Iawk. 
  11195.                  |     |
  11196.                  |     +---> icon awk   : munge using icon expressions
  11197.                  +---------> icon grep  : scan using icon expressions
  11198.  
  11199. They really don't try to emulate awk or grep, but offer an icon substitute,
  11200. and actually they are the same program. Usage : igrep infile
  11201.                                                 iawk  infile outfile
  11202.  
  11203. When invoked it requests icon expressions which it uses to write, compile,
  11204. and run another icon program. Whatever is returned is output. There are a
  11205. nice collection of global variables, and added procedures that I always use.
  11206.  
  11207. Example 1.
  11208. return trim(line)  #will trim trailing spaces off all the lines in the file
  11209.  
  11210. Example 2.
  11211. return right(num,8) || " : " || line #will number all the lines in a file
  11212.  
  11213. While these are not technically 'one liners' in that they are inserted into
  11214. another program, they do offer the 'one liner' feeling, and I find it very
  11215. useful for 'throw away' one time only code. It cleans up all the temporary
  11216. files when done so I don't get confused by having dozens of discarded tool
  11217. fragments left over either.
  11218.  
  11219. Chris Tenaglia (System Manager) | Medical College of Wisconsin
  11220. 8701 W. Watertown Plank Rd.     | Milwaukee, WI 53226
  11221. (414)257-8765                   | tenaglia@mis.mcw.edu, mcwmis!tenaglia
  11222.  
  11223.  
  11224. From @um.cc.umich.edu:Paul_Abrahams@MTS.cc.Wayne.edu  Mon Oct 21 15:33:31 1991
  11225. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Mon, 21 Oct 91 15:33:31 MST
  11226. Received: from mailrus.cc.umich.edu by optima.cs.arizona.edu (4.1/15)
  11227.     id AA06653; Mon, 21 Oct 91 15:33:26 MST
  11228. Received: from um.cc.umich.edu by mailrus.cc.umich.edu (5.61/1123-1.0)
  11229.     id AA09408; Mon, 21 Oct 91 18:29:41 -0400
  11230. Received: from MTS.cc.Wayne.edu by um.cc.umich.edu via MTS-Net; Mon, 21 Oct 91 18:32:43 EDT
  11231. Date: Mon, 21 Oct 91 18:32:10 EDT
  11232. From: Paul_Abrahams@mts.cc.wayne.edu
  11233. To: icon-group@cs.arizona.edu
  11234. Message-Id: <376475@MTS.cc.Wayne.edu>
  11235. Subject: One-liners
  11236.  
  11237. Has anyone thought of creating a wrapper for Icon so that you could write
  11238. something like:
  11239.     iconz 'expr'
  11240. and cause expr to be executed?  The wrapper would:
  11241.   (1) surround expr with procedure(arg)...end
  11242.   (2) call the translator and interpreter
  11243. That would help to equalize the startup costs of Icon and awk.
  11244. Of course I wouldn't expect the wrapper to be system-independent.
  11245.  
  11246. Paul Abrahams
  11247. abrahams@mts.cc.wayne.edu
  11248.  
  11249. From ralph  Mon Oct 21 16:10:56 1991
  11250. Date: Mon, 21 Oct 91 16:10:56 MST
  11251. From: "Ralph Griswold" <ralph>
  11252. Message-Id: <9110212310.AA15609@cheltenham.cs.arizona.edu>
  11253. Received: by cheltenham.cs.arizona.edu; Mon, 21 Oct 91 16:10:56 MST
  11254. To: Paul_Abrahams@mts.cc.wayne.edu, icon-group@cs.arizona.edu
  11255. Subject: Re:  One-liners
  11256.  
  11257. There's such a "wrapper" in the Icon program library -- it takes
  11258. expressions as input, creates a program, and translates and
  11259. executes it using system().
  11260.  
  11261. It works fine under UNIX on platforms that are fast enough to
  11262. make the overhead insignificant in real time.
  11263.     
  11264.     Ralph Griswold / Department of Computer Science 
  11265.     The University of Arizona / Tucson, AZ 85721
  11266.     
  11267.     ralph@cs.arizona.edu / uunet!arizona!ralph
  11268.     
  11269.     voice: 602-621-6609 / fax: 602-621-9618
  11270.  
  11271. From alex@laguna.metaphor.com  Mon Oct 21 17:41:09 1991
  11272. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Mon, 21 Oct 91 17:41:09 MST
  11273. Received: from relay.metaphor.com by optima.cs.arizona.edu (4.1/15)
  11274.     id AA00233; Mon, 21 Oct 91 17:14:13 MST
  11275. Received: from laguna.Metaphor.COM by relay.metaphor.com (4.1/SMI-4.1)
  11276.     id AA00530; Mon, 21 Oct 91 17:13:18 PDT
  11277. Received: by laguna.Metaphor.COM (4.1/SMI-4.0)
  11278.     id AA08868; Mon, 21 Oct 91 17:14:10 PDT
  11279. Date: Mon, 21 Oct 91 17:14:10 PDT
  11280. From: alex@laguna.metaphor.com (Bob Alexander)
  11281. Message-Id: <9110220014.AA08868@laguna.Metaphor.COM>
  11282. To: icon-group@cs.arizona.edu
  11283. Subject: Re: One-liners
  11284.  
  11285. Here's how I do one-liners.  This method accepts an Icon expression or a
  11286. whole program on standard input (UNIX).  I use it directly from shells
  11287. or from within editors such as vi, emacs, or Sun textedit that allow
  11288. filters to operate on selected text.
  11289.  
  11290. Using standard input instead of the command line is more convenient
  11291. since most Icon programs would require that many characters be
  11292. escaped.
  11293.  
  11294. I have a similar program for Macontosh Programmer's Workshop which allows
  11295. selection of text with themouse and execution as an Icon expression/program
  11296. by menu command or command-key, sort of like Smalltalk.
  11297.  
  11298. Probably the most frequent use to which I put this is to enter a simple
  11299. one-liner to see how Icon behaves in certain situations.  Or maybe to
  11300. see how a terminal prints all possible characters:
  11301.  
  11302.     every write(!&cset[33:0]))
  11303.  
  11304. It's done with an Icon program (iconprog.icn) -- the comments explain it
  11305. fairly well:
  11306.  
  11307. --------------------------------------------------------------
  11308.  
  11309. #
  11310. #  Filter to facilitate execution of Icon expressions and programs from
  11311. #  within command shells and editors.
  11312. #
  11313. #  The program checks whether its input stream is an Icon *program*;
  11314. #  i.e.  the first token is "procedure" | "link" | "record" | "global".
  11315. #
  11316. #  If it is a program, it is passed unchanged.  If it is not a program,
  11317. #  it is assumed to be an expression, and is encapsulated within the
  11318. #  following program skeleton:
  11319. #
  11320. #       procedure main()
  11321. #          every write(image({
  11322. #             --- your expression ---
  11323. #             }))
  11324. #       end
  11325. #
  11326. #  The following UNIX shell script (Bourne shell) accepts Icon text from
  11327. #  standard input and executes it as a program or an expression as
  11328. #  appropriate.
  11329. #  
  11330. #
  11331. #       #!/bin/sh
  11332. #       #
  11333. #       #  Run Icon program or expression from standard input
  11334. #       #
  11335. #       f=/tmp/Icon$$
  11336. #       iconprog | icont -s -o $f $* - -x 2>&1
  11337. #       rm -f $f
  11338. #
  11339.  
  11340. procedure main()
  11341.    local space,line,trailer
  11342.    space := ' \t\v\n\r\f'
  11343.    while line := "." ~== read() do line ? {
  11344.       tab(many(space))
  11345.       if ="#" | pos(0) then write(line)
  11346.       else {
  11347.      if not (=("procedure" | "link" | "record" | "global") &
  11348.            any(space) | pos(0)) then {
  11349.         writes("procedure main(); every write(image({")
  11350.         trailer := "})); end"
  11351.         }
  11352.      write(line)
  11353.      break
  11354.      }
  11355.       }
  11356.    while write("." ~== read())
  11357.    write(\trailer)
  11358. end
  11359.  
  11360. From gudeman  Tue Oct 22 17:12:36 1991
  11361. Received: from orator.cs.arizona.edu by cheltenham.cs.arizona.edu; Tue, 22 Oct 91 17:12:36 MST
  11362. Date: Tue, 22 Oct 91 17:12:34 MST
  11363. From: "David Gudeman" <gudeman>
  11364. Message-Id: <9110230012.AA00601@orator.cs.arizona.edu>
  11365. Received: by orator.cs.arizona.edu; Tue, 22 Oct 91 17:12:34 MST
  11366. To: icon-group
  11367. Subject: one-liner builder
  11368.  
  11369. Here is my solution to the problem of conveniently writting and
  11370. running on-liners in Icon.  It has the advantage of allowing you to
  11371. specify a different input file for Icon (this is just in the
  11372. shell-script), and it lets you write more complex programs than you
  11373. probably want to write from the keyboard...
  11374.  
  11375. Run the following shell script to produce two files, iprog and
  11376. mkprog.icn.  Then run 'icont mkprog' to create mkprog.  See the header
  11377. of iprog for (minimal) documentation.
  11378. ================================================================
  11379. #! /bin/sh
  11380. # This is a shell archive.  Remove anything before this line, then unpack
  11381. # it by saving it into a file and typing "sh file".  To overwrite existing
  11382. # files, type "sh file -c".  You can also feed this as standard input via
  11383. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  11384. # will see the following message at the end:
  11385. #        "End of shell archive."
  11386. # Contents:  iprog mkprog.icn
  11387. # Wrapped by gudeman@orator on Tue Oct 22 17:08:55 1991
  11388. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  11389. if test -f 'iprog' -a "${1}" != "-c" ; then 
  11390.   echo shar: Will not clobber existing file \"'iprog'\"
  11391. else
  11392. echo shar: Extracting \"'iprog'\" \(807 characters\)
  11393. sed "s/^X//" >'iprog' <<'END_OF_FILE'
  11394. X#!/bin/sh
  11395. X#
  11396. X# Usage: iprog [-i input-file] args*
  11397. X#
  11398. X# iprog reads an Icon program from standard input.  All lines not
  11399. X# inside a declaration are put into the procedure main(argv).  Then
  11400. X# the Icon program is translated and executed.  If the first paramater
  11401. X# is -i, then the following word is the name of the input file for the
  11402. X# execution of the Icon program.  All other args are put into argv, so
  11403. X# that the nth arg is referenced in the Icon program as argv[n].  You
  11404. X# can redirect stdout with '>' as usual, but if you redirect stdin
  11405. X# with '<', then this is used as the source of the Icon program as
  11406. X# well as the input to the Icon program.
  11407. X
  11408. f=/tmp/icontmp$$
  11409. mkprog >$f.icn
  11410. if test $# = 0
  11411. then
  11412. X  icont -s $f -x
  11413. elif test $1 = -i
  11414. then
  11415. X  in=$2
  11416. X  shift 2
  11417. X  icont -s $f -x $* <$in
  11418. else
  11419. X  icont -s $f -x $*
  11420. fi
  11421. END_OF_FILE
  11422. if test 807 -ne `wc -c <'iprog'`; then
  11423.     echo shar: \"'iprog'\" unpacked with wrong size!
  11424. fi
  11425. chmod +x 'iprog'
  11426. # end of 'iprog'
  11427. fi
  11428. if test -f 'mkprog.icn' -a "${1}" != "-c" ; then 
  11429.   echo shar: Will not clobber existing file \"'mkprog.icn'\"
  11430. else
  11431. echo shar: Extracting \"'mkprog.icn'\" \(1355 characters\)
  11432. sed "s/^X//" >'mkprog.icn' <<'END_OF_FILE'
  11433. X#
  11434. X# Run this program with
  11435. X#
  11436. X#    iprog args
  11437. X#
  11438. X# where args are the arguments to the result program.  Then start
  11439. X# entering an Icon program.  Procedure, global, link, and record
  11440. X# declarations are collected an put out before main().  Then all the
  11441. X# other lines are put in procedure main(argv) in the order in which
  11442. X# they appeared.  Access the nth argument with argv[n].
  11443. X#
  11444. X# This program is meant to be run by the shell script 'iprog'.
  11445. X
  11446. global decls, exprs
  11447. X
  11448. procedure main()
  11449. X    local line
  11450. X
  11451. X    decls := []
  11452. X    exprs := []
  11453. X
  11454. X    while line := read() do line ? {
  11455. X    case tab(upto(&lcase)) & tab(many(&lcase)) of {
  11456. X        "procedure" : read_proc(line)
  11457. X        "link" : put(decls, line)
  11458. X        "record" : read_rec(line)
  11459. X        "global" : put(decls, line)
  11460. X    } |
  11461. X        put(exprs,line)
  11462. X    }
  11463. X
  11464. X    every write(!decls)
  11465. X    write("procedure main(argv)")
  11466. X    every write(!exprs)
  11467. X    write("end")
  11468. end
  11469. X
  11470. procedure read_proc(line)
  11471. X
  11472. X    repeat {
  11473. X    put(decls,line)
  11474. X    if (line == "end") |
  11475. X        (match("end", line, *line - 2) &
  11476. X         any(' \t;}', line, *line - 3)) then {
  11477. X         put(decls,"")
  11478. X         return
  11479. X         }
  11480. X    line := read() |
  11481. X        stop("end-of-file inside a procedure declaration")
  11482. X    }
  11483. end
  11484. X
  11485. procedure read_rec(line)
  11486. X
  11487. X    repeat {
  11488. X    put(decls,line)
  11489. X    if find(")", line) then {
  11490. X        put(decls,"")
  11491. X        return
  11492. X    }
  11493. X    line := read() |
  11494. X        stop("end-of-file inside a record declaration")
  11495. X    }
  11496. end
  11497. END_OF_FILE
  11498. if test 1355 -ne `wc -c <'mkprog.icn'`; then
  11499.     echo shar: \"'mkprog.icn'\" unpacked with wrong size!
  11500. fi
  11501. # end of 'mkprog.icn'
  11502. fi
  11503. echo shar: End of shell archive.
  11504. exit 0
  11505.  
  11506. From icon-group-request@arizona.edu  Wed Oct 23 19:58:07 1991
  11507. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Wed, 23 Oct 91 19:58:07 MST
  11508. Resent-From: icon-group-request@arizona.edu
  11509. Received: from Arizona.edu (Maggie.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  11510.     id AA04576; Wed, 23 Oct 91 19:58:05 MST
  11511. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Wed, 23 Oct
  11512.  1991 19:57 MST
  11513. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA18786; Wed, 23 Oct 91
  11514.  19:43:53 -0700
  11515. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  11516.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  11517.  usenet@ucbvax.Berkeley.EDU if you have questions)
  11518. Resent-Date: Wed, 23 Oct 1991 19:57 MST
  11519. Date: 21 Oct 91 19:51:18 GMT
  11520. From: agate!spool.mu.edu!munnari.oz.au!comp.vuw.ac.nz!waikato.ac.nz!aukuni.ac.nz!russell@ucbvax.berkeley.edu (Russell J
  11521.  Fulton;ccc032u)
  11522. Subject: Comparisions of Perl, Rexx and Icon.
  11523. Sender: icon-group-request@arizona.edu
  11524. Resent-To: icon-group@cs.arizona.edu
  11525. To: icon-group@arizona.edu
  11526. Resent-Message-Id: <FB3B30DFC0801643@Arizona.edu>
  11527. Message-Id: <1991Oct21.195118.29345@ccu1.aukuni.ac.nz>
  11528. X-Envelope-To: icon-group@CS.Arizona.EDU
  11529. X-Vms-To: icon-group@Arizona.edu
  11530. Organization: University of Auckland, New Zealand.
  11531.  
  11532. I have read the recent discussions about Perl, Rexx and Icon with
  11533. interest.  I have, at different times used all 3 languages and have
  11534. found all 3 very useful.
  11535.  
  11536. Rather than try a comprehensive comparison I would like to focus on
  11537. one or two point raised by others. (Sorry I can't acknowledge you
  11538. since I am working from memory and do not have the original articles
  11539. to hand.)  As well as some purely personal reflections.
  11540.  
  11541. One initial point I wish to make is that in *my* view both Rexx and
  11542. Perl are specifically designed to interface directly with the operating
  11543. system (or in the case of Rexx other programs as well eg. Xedit ). Icon
  11544. was designed as general purpose programming language.
  11545.  
  11546. This brings me to the issue of "UNIX and Perl". I use both Perl and
  11547. Icon on UNIX now. Perl's access to most of the UNIX system calls makes
  11548. it invaluable for programming system administration utilities or doing
  11549. one off system jobs. Perl's regular expressions are usually quite
  11550. adequate for matching filenames etc. and are easier to use than the
  11551. much more powerful tools that Icon provides. These features combined
  11552. with the find.pl package make writing disk management software a
  11553. breeze.
  11554.  
  11555. I also use Perl for jobs that I would have previously use C particularly
  11556. for doing prototyping.
  11557.  
  11558. As a general purpose programming language I prefer Icon. It is much
  11559. leaner and cleaner than Perl, which I can only describe as baroque.
  11560. There is one feature that Icon has over Perl in my experience.  Both
  11561. tables and arrays may contain items of arbitrary type in Icon but in
  11562. Perl Associative arrays (Perl's tables) can only hold scalars.
  11563. I have fallen over this several times in Perl and have ended up
  11564. writing the job in Icon instead.
  11565.  
  11566. As for Rexx, I used it for several year on an IBM VM system (we went
  11567. to UNIX about 2 years ago so my view may be somewhat out of date) and
  11568. my view of it is almost certainly coloured by the fact that it was
  11569. such an enormous improvement over the EXEC (1 & 2) that we had before.
  11570. I liked Rexx, it was reasonably simple and straight forward and had
  11571. all the basic tool that one need to write simple scripts. What is
  11572. lacked was any data structures. It did have some limited pattern
  11573. matching. I know that IBM stripped some features out of the original
  11574. implementation when they released. (I saw the manual for the pre
  11575. release version that was running in the local IBM offices and was
  11576. quite disappointed when I found that the features we missing in the
  11577. official release.)
  11578.  
  11579. If Rexx came out today for our UNIX system I would not bother with it
  11580. I would much rather use Icon or Perl because their authors are
  11581. dedicated to producing tools that are useful to people. Rexx is
  11582. controlled by IBM which, contrary to popular belief, does not make
  11583. computers or software, they make money and everything they do is
  11584. influenced by this. Someone In marketing probably decided that the
  11585. particular features in Rexx threatened some other IBM product and so
  11586. out they went.
  11587.  
  11588. As with most things it is a case of 'horses for courses'. Icon is great
  11589. as a general purpose programming language. It is portable and has enough
  11590. of an interface to the operating system for most purposes.
  11591.  
  11592. Perl on the other hand is an excellent tool for the UNIX systems admin.
  11593. It is also quite adequate as a general purpose programming language and
  11594. in fact I tend to use it more than Icon because I am more familiar with
  11595. it even though I prefer Icon as a language.
  11596.  
  11597. If I had access to Icon, Perl and Rexx on the same system I probably
  11598. would not bother with Rexx. The other two do more and do it better.
  11599.  
  11600. If I had to choose one on a UNIX system then the choice would depend
  11601. on my role. As a systems administrator I would choose Perl and as a
  11602. general user I would choose Icon.
  11603.  
  11604. Cheers, Russell.
  11605. -- 
  11606. Russell Fulton, Computer Center, University of Auckland, New Zealand.
  11607. <rj_fulton@aukuni.ac.nz>
  11608.  
  11609. From icon-group-request@arizona.edu  Wed Oct 23 23:45:22 1991
  11610. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Wed, 23 Oct 91 23:45:22 MST
  11611. Resent-From: icon-group-request@arizona.edu
  11612. Received: from Arizona.edu (Merlin.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  11613.     id AA11696; Wed, 23 Oct 91 23:45:20 MST
  11614. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Wed, 23 Oct
  11615.  1991 23:44 MST
  11616. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA26039; Wed, 23 Oct 91
  11617.  23:36:20 -0700
  11618. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  11619.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  11620.  usenet@ucbvax.Berkeley.EDU if you have questions)
  11621. Resent-Date: Wed, 23 Oct 1991 23:45 MST
  11622. Date: 21 Oct 91 20:04:24 GMT
  11623. From: hsi!mlfarm!rosie!ron@uunet.uu.net (Ronald Florence)
  11624. Subject: pipes.icn
  11625. Sender: icon-group-request@arizona.edu
  11626. Resent-To: icon-group@cs.arizona.edu
  11627. To: icon-group@arizona.edu
  11628. Resent-Message-Id: <1AFCE085202010C2@Arizona.edu>
  11629. Message-Id: <1991Oct21.200424.28953@mlfarm.com>
  11630. X-Envelope-To: icon-group@CS.Arizona.EDU
  11631. X-Vms-To: icon-group@Arizona.edu
  11632. Organization: Maple Lawn Farm, Stonington, CT
  11633.  
  11634. Icon is remarkably portable, but I still find that features I assume
  11635. are not present on all implementations.  Pipes.icn is an effort at
  11636. portability between systems with pipes and those without.  Typical
  11637. usages:
  11638.  
  11639.    procedure mail_errors()
  11640.  
  11641.     # code to gather errors in a list, which comes out something like:
  11642.      error_list := [ "You wrote it wrong.",
  11643.              "You screwed up the data.",
  11644.              "The presentation is unclear." ]
  11645.  
  11646.     # use pipeout() to write it to a comand, here "mail" to the author
  11647.      pipeout(error_list, "mail ron@mlfarm.com")
  11648.    end
  11649.  
  11650.    procedure list_dir()
  11651.  
  11652.     # the command to list a directory is system-dependent
  11653.      if find("UNIX", &features) then dir_cmd := "ls"
  11654.      else if find("MS-DOS", &features) then dir_cmd := "dir /w"
  11655.      else stop("Don't know how to list a directory on your system.")
  11656.  
  11657.     # use pipein to list the Icon source
  11658.      every write(pipein(dir_cmd ||" *.icn"))
  11659.    end
  11660.  
  11661. Pipes.icn could use some error-trapping.  We don't have an ms-dos
  11662. machine to test it.
  11663.  
  11664.                 Ronald Florence
  11665.                 ron@mlfarm.com
  11666.  
  11667.  
  11668. -----------------------------[pipes.icn]--------------------------
  11669. # pipes.icn
  11670. # imitates pipes  
  11671. # ron@mlfarm.com, 21 Oct 1991
  11672. # This is a modest effort at portability.  Unix implementations of
  11673. # Icon have the ability to read from and write to pipes.  Pipeout()
  11674. # and pipein() are an effort to duplicate this functionality for
  11675. # systems without pipes, like ms-dos.  Both functions could do with
  11676. # some error-trapping, especially in the ms-dos versions.  My
  11677. # experience with the system function is that it returns 0 (success)
  11678. # on ms-dos machines even when command.com cannot find the command, so
  11679. # I'm at a loss how to trap errors.
  11680.  
  11681.  
  11682.     # write "what" (a list) to command "cmd"
  11683.  
  11684. procedure pipeout(what, cmd)
  11685.   static real_pipes
  11686.  
  11687.   initial real_pipes := find("pipes", &features)
  11688.   p := (\real_pipes & open(cmd, "wp")) | open(tfn := tempname(), "w")
  11689.   every write(p, !what)
  11690.   if \real_pipes then return close(p) 
  11691.   else {
  11692.     cmd ||:= " < " || tfn
  11693.     status := system(cmd)
  11694.     remove(tfn)
  11695.     return status
  11696.   }
  11697. end
  11698.  
  11699.     # read from command "cmd"
  11700.  
  11701. procedure pipein(cmd)
  11702.   static real_pipes
  11703.  
  11704.   initial real_pipes := find("pipes", &features)
  11705.   if \real_pipes then p := open(cmd ||" 2> /dev/null" , "rp")
  11706.   else {
  11707.     p := open(tfn := tempname(), "w")
  11708.     system(cmd || " > " || tfn)
  11709.     close(p)
  11710.     p := open(tfn)
  11711.   }
  11712.   suspend !p
  11713.   /real_pipes & remove(tfn)
  11714. end
  11715.  
  11716.  
  11717.     # Richard Goerwitz's ever-useful generator.
  11718.  
  11719. procedure tempname()
  11720.  
  11721.   every temp_name := "pipe." || right(1 to 999,3,"0") do {
  11722.     close(open(temp_name)) & next
  11723.     suspend \temp_name
  11724.   }
  11725. end
  11726. --------------------------------[eof]-----------------------------
  11727. -- 
  11728.  
  11729.                 Ronald Florence
  11730.                 ron@mlfarm.com
  11731.  
  11732. From shack  Thu Oct 24 23:07:50 1991
  11733. Received: from caslon.cs.arizona.edu by cheltenham.cs.arizona.edu; Thu, 24 Oct 91 23:07:50 MST
  11734. Date: Thu, 24 Oct 91 23:07:48 -0700
  11735. From: "David Shackelford" <shack>
  11736. Message-Id: <9110250607.AA09717@caslon.cs.arizona.edu>
  11737. Received: by caslon.cs.arizona.edu; Thu, 24 Oct 91 23:07:48 -0700
  11738. To: icon-group
  11739. Subject: Icon for OS/2 2.0
  11740.  
  11741.  
  11742. I have been trying to port Icon v8 to OS/2 version 2.0 (beta)
  11743. and have managed to get it to compile without errors.  The
  11744. translator runs on .icn files and produces what seem to be
  11745. reasonable .icx files, but when I try to run the interpreter
  11746. it gives me an error message:
  11747.  
  11748. System error at line 1 in once.icn
  11749. unimplemented opcode: 7602243 (0x00740043)
  11750.  
  11751. Given lots of time to work on the problem I might be able
  11752. to puzzle this out, but my class load doesn't leave me a
  11753. lot of time.  Is there a simple explanation for what would
  11754. cause this?  I suspect it is a problem with my C compiler,
  11755. which is MSC 6.? with 32-bit flat memory model.  Where should
  11756. I look to find the opcodes for .icx files?
  11757.  
  11758. Thanks for your help/suggestions/comments/...
  11759.  
  11760. Dave         | shack@cs.arizona.edu
  11761.  
  11762. From icon-group-request@arizona.edu  Fri Oct 25 03:43:36 1991
  11763. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Fri, 25 Oct 91 03:43:36 MST
  11764. Resent-From: icon-group-request@arizona.edu
  11765. Received: from Arizona.edu (Merlin.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  11766.     id AA13720; Fri, 25 Oct 91 03:43:33 MST
  11767. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Fri, 25 Oct
  11768.  1991 03:43 MST
  11769. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA25372; Fri, 25 Oct 91
  11770.  03:29:21 -0700
  11771. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  11772.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  11773.  usenet@ucbvax.Berkeley.EDU if you have questions)
  11774. Resent-Date: Fri, 25 Oct 1991 03:43 MST
  11775. Date: 22 Oct 91 16:43:11 GMT
  11776. From: micro-heart-of-gold.mit.edu!wupost!uwm.edu!linac!convex!usenet@bloom-beacon.mit.edu (Tom
  11777.  Christiansen)
  11778. Subject: RE: Comparisions of Perl, Rexx and Icon.
  11779. Sender: icon-group-request@arizona.edu
  11780. Resent-To: icon-group@cs.arizona.edu
  11781. To: icon-group@arizona.edu
  11782. Resent-Message-Id: <0570EF54562022BA@Arizona.edu>
  11783. Message-Id: <1991Oct22.164311.24870@convex.com>
  11784. X-Envelope-To: icon-group@CS.Arizona.EDU
  11785. X-Vms-To: icon-group@Arizona.edu
  11786. Organization: CONVEX Software Development, Richardson, TX
  11787. References: <1991Oct21.195118.29345@ccu1.aukuni.ac.nz>
  11788.  
  11789. From the keyboard of russell@ccu1.aukuni.ac.nz (Russell J Fulton;ccc032u):
  11790. :Both tables and arrays may contain items of arbitrary type in Icon but in
  11791. :Perl Associative arrays (Perl's tables) can only hold scalars.
  11792. :I have fallen over this several times in Perl and have ended up
  11793. :writing the job in Icon instead.
  11794.  
  11795. If the truth be known, while it is indeed the case that arrays and tables
  11796. in perl can only hold scalar values, there happens to be a special kind of
  11797. scalar value you can use to circumvent this restriction.  This special 
  11798. scalar is a reference to the symbol table (read: pointer).  Using these,
  11799. the determined program can synthesize arbitrarily complex data types.
  11800. This is discussed in question number 17 of the perl FAQ.  As it says
  11801. there, however, you really have to want to do so badly, as it is
  11802. notationally cumbersome at best.
  11803.  
  11804. --tom
  11805.  
  11806. From icon-group-request@arizona.edu  Fri Oct 25 07:17:54 1991
  11807. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Fri, 25 Oct 91 07:17:54 MST
  11808. Resent-From: icon-group-request@arizona.edu
  11809. Received: from Arizona.edu (Hopey.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  11810.     id AA20250; Fri, 25 Oct 91 07:17:52 MST
  11811. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Fri, 25 Oct
  11812.  1991 07:17 MST
  11813. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA02781; Fri, 25 Oct 91
  11814.  07:06:33 -0700
  11815. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  11816.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  11817.  usenet@ucbvax.Berkeley.EDU if you have questions)
  11818. Resent-Date: Fri, 25 Oct 1991 07:17 MST
  11819. Date: 22 Oct 91 16:57:58 GMT
  11820. From: agate!spool.mu.edu!caen!uvaarpa!murdoch!aemsun.med.virginia.edu!sdm7g@ucbvax.berkeley.edu (Steven
  11821.  D. Majewski)
  11822. Subject: RE: REXX/Perl/Icon
  11823. Sender: icon-group-request@arizona.edu
  11824. Resent-To: icon-group@cs.arizona.edu
  11825. To: icon-group@arizona.edu
  11826. Resent-Message-Id: <2362428EF020E0A4@Arizona.edu>
  11827. Message-Id: <1991Oct22.165758.3137@murdoch.acc.Virginia.EDU>
  11828. X-Envelope-To: icon-group@CS.Arizona.EDU
  11829. X-Vms-To: icon-group@Arizona.edu
  11830. Organization: University of Virginia - Physiology Dept.
  11831. References: <9110181432.AA06934@optima.cs.arizona.edu>
  11832.  
  11833. In article <9110181432.AA06934@optima.cs.arizona.edu> nowlin@iwtqg.UUCP writes:
  11834. >
  11835. >I responded because of your assertion:
  11836. >
  11837. >> I know PERL is probably the language of choice on Unix systems because 
  11838. >> of its very complete interface to system & network functions, ...
  11839. >
  11840. >I'm glad you "know" that.  I've been using Icon for over six years and
  11841. >working on UNIX for a lot longer.  I've found almost nothing that I
  11842. >couldn't do in Icon because I needed a more complete interface to UNIX. 
  11843. >There are times I've been forced to use other languages for speed, times
  11844. >that the bean counters have forced me to use one of the "supported"
  11845. >languages, and times that Icon was not the appropriate language for the
  11846. >job.  The interface to UNIX has never been a limiting factor.  The
  11847. >pipe-open and system calls in Icon provide plenty of UNIX access and
  11848. >flexibility.
  11849. >
  11850. > ... 
  11851. > ...
  11852. >
  11853. >I'm not presumptuous enough to say Icon is the "language of choice" for any
  11854. >one group of programmers.  Although I work on UNIX and it certainly is for
  11855. >me :-)
  11856. >
  11857. >Jerry Nowlin
  11858.  
  11859.  By "Language of choice" I did not mean any qualitative judgement. 
  11860.  I should have said "de facto LofCh". ( We all know de facto standards 
  11861.  just happen to be a historically contingent choice :-) 
  11862.  
  11863.  Qualitatively, I would judge ICON superior to PERL. It is more powerful
  11864.  and cleaner. I haven't done any extensive programming in either. (
  11865.  I just downloaded and built the Icon interpreted yesterday! ) but from
  11866.  looking at both, I think I would choose ICON for any large project. 
  11867.  
  11868.   De-Facto: PERL just happened to be the (almost) right think in the right
  11869.  place at the right time ( at the right price! ) and found a market. 
  11870.  I don't have any statistics, but I would venture my opinion that it is
  11871.  more widely used than ICON. ( Again, no qualitative judgement implied:
  11872.  BASIC is more popular than both combined. ) I would be *HAPPY* to hear
  11873.  other-wise, but PERL seems to be ubiquitous in the unix world. ( It is 
  11874.  installed on all of the University machines here at UVA. ). In fact the
  11875.  void it filled was for a "standard" ( and ubiquitous ) language to replace
  11876.  what was being done awkwardly with a combination of shell-scripts/awk/sed
  11877.  /et.al. ( Could have been worse: what if Unix had come bundled with BASIC :-o)
  11878.    The inclusion of interfaces to just about all of the unix utilities 
  11879.  made PERL the "de facto language of choice" for sys-admin type tasks where
  11880.  that is a major part of the problem. ( Sure, you can use a generic "system"
  11881.  call or write some "glue" routines, but most of these types of jobs are
  11882.  done in a hurry by harried sys-admins - "quick and dirty" by definition. )
  11883.   Larry Wall has admitted that there are things he would have done differently
  11884.  in PERL if he could start over. But I don't believe he was trying to design
  11885.  Yet-Another-Language, so much as get a job done. Ralph Griswold, on the 
  11886.  other had, had quite a bit of experience with language design and 
  11887.  implementation before he developed ICON. It shows. 
  11888.    The language has spread from sys-admin tasks to more general purpose 
  11889.  type programming. That, I would credit mostly to its availability. 
  11890.    I would say that PERL is to AWK what ICON is to SNOBOL. Which is another
  11891.  reason for PERL's success: All unix programmers ( and some users ) are 
  11892.  familiar with the Unix/awk/shell/grep style of regular expressions. 
  11893.  Again, not a qualitative judgement, but familiarity breeds faster learning
  11894.  curves. 
  11895.  
  11896.  BTW: Since the problem I described has a minimal "unix-interface" component,
  11897.  ICON will probably be *my* "language of choice" !
  11898.  Sorry for the cross-posting, but I missed this thread 'cause I was looking
  11899.  for followups in comp.lang.misc. Maybe we can re-join these threads on 
  11900.  languages for (mainly) string processing problems in comp.lang.misc ? 
  11901.  
  11902.  
  11903. ======== "If you have a hammer, find a nail" - George Bush,'91  =========
  11904.  Steven D. Majewski        University of Virginia Physiology Dept.
  11905.  sdm7g@Virginia.EDU        Box 449 Health Sciences Center
  11906.  Voice: (804)-982-0831        1600 Jefferson Park Avenue
  11907.  FAX:   (804)-982-1616        Charlottesville, VA 22908
  11908.  
  11909. From TENAGLIA@mis.mcw.edu  Fri Oct 25 07:40:24 1991
  11910. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Fri, 25 Oct 91 07:40:24 MST
  11911. Received: from MIS3.MIS.MCW.EDU by optima.cs.arizona.edu (4.1/15)
  11912.     id AA20782; Fri, 25 Oct 91 07:40:21 MST
  11913. Received: from mis.mcw.edu by mis.mcw.edu (PMDF #12252) id
  11914.  <01GC5PU8PMTS9AMENT@mis.mcw.edu>; Fri, 25 Oct 1991 09:41 CST
  11915. Date: Fri, 25 Oct 1991 09:41 CST
  11916. From: Chris Tenaglia - 257-8765 <TENAGLIA@mis.mcw.edu>
  11917. Subject: REXX,ICON,PERL
  11918. To: icon-group@cs.arizona.edu
  11919. Message-Id: <01GC5PU8PMTS9AMENT@mis.mcw.edu>
  11920. X-Organization: Medical College of Wisconsin (Milwaukee, WI)
  11921. X-Vms-To: IN%"icon-group@cs.arizona.edu"
  11922.  
  11923.  
  11924. It sounds like PERL has made a solid foothold in unix sys admin.
  11925. I guess I must have been the exception. At my prior position as
  11926. both unix (sunos, xenix, & zsUnix) and vax/vms sys admin I used
  11927. icon extensively as a tool builder. I hadn't even heard of perl.
  11928.  
  11929. The thing I liked about icon was that it was easy to learn and use
  11930. even though my language of choice had been BASIC at the time. I
  11931. could never get the hang of C, Pascal, or Fortran with all their
  11932. data types. I also liked it because as a sys admin for both unix
  11933. and vms, and as a support person for PCs I liked a tool that was
  11934. consistent and available for all worlds.
  11935.  
  11936. Chris Tenaglia (System Manager) |  "The past explained,     
  11937. Medical College of Wisconsin    |   the future fortold, 
  11938. 8701 W. Watertown Plank Rd.     |   the present largely appologized for."
  11939. Milwaukee, WI 53226             |   Organon to The Doctor
  11940. (414)257-8765                   |     
  11941. tenaglia@mis.mcw.edu, mcwmis!tenaglia
  11942.  
  11943.  
  11944. From icon-group-request@arizona.edu  Fri Oct 25 09:02:07 1991
  11945. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Fri, 25 Oct 91 09:02:07 MST
  11946. Resent-From: icon-group-request@arizona.edu
  11947. Received: from Arizona.edu (Hopey.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  11948.     id AA23592; Fri, 25 Oct 91 09:02:04 MST
  11949. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Fri, 25 Oct
  11950.  1991 09:01 MST
  11951. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA06817; Fri, 25 Oct 91
  11952.  08:51:59 -0700
  11953. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  11954.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  11955.  usenet@ucbvax.Berkeley.EDU if you have questions)
  11956. Resent-Date: Fri, 25 Oct 1991 09:01 MST
  11957. Date: 22 Oct 91 18:50:36 GMT
  11958. From: dog.ee.lbl.gov!pasteur!agate!spool.mu.edu!uwm.edu!mrsvr.UUCP!hewitt@ucbvax.berkeley.edu (Anthony
  11959.  V. Hewitt)
  11960. Subject: Makefiles for Icon
  11961. Sender: icon-group-request@arizona.edu
  11962. Resent-To: icon-group@cs.arizona.edu
  11963. To: icon-group@arizona.edu
  11964. Resent-Message-Id: <31EF2F90B6201935@Arizona.edu>
  11965. Message-Id: <HEWITT.91Oct22135036@argus.gemed.com>
  11966. X-Envelope-To: icon-group@CS.Arizona.EDU
  11967. X-Vms-To: icon-group@Arizona.edu
  11968. Organization: GE Medical Systems, Milwaukee, WI
  11969.  
  11970. I've been finding it awkward to manage my icon programs even with make;
  11971. there are many targets in my ~/icon directory and it's hard to be sure that
  11972. the makefile is up to date (particularly when I get lazy).
  11973.  
  11974. This is not very fancy Icon but I've found it automates the process quite
  11975. nicely; it assumes that you have make.  If you're not running Unix, I can
  11976. only tell you that there are versions of make available for DOS and VMS
  11977. (Borland and Microsoft bundle one with their DOS C compilers, I think). 
  11978.  
  11979. What follows four files: newsuffixes.icn, icondepend.icn and the makefiles
  11980. for the program directory and the procedures directory.
  11981.  
  11982. I don't expect this to trash your source but just the same it would be
  11983. prudent to have a current backup copy before you do this for the first time.
  11984. You should start in your prog directory by using icont on the two .icn files
  11985. and then "make clobber", then "make".
  11986.  
  11987. In the progs makefile, you may well have to change the definition of
  11988. PROCSDIR, which currently assumes that procs is a subdirectory of progs (not
  11989. true for the Icon Programmers Library, for example).
  11990.  
  11991. If you're using the Icon compiler, you'll have to make some changes to
  11992. icondepend - it would be cleanest to make it refer to a macro in make, say
  11993. "$(ICONT"), rather than hardwire the string "icont".
  11994.  
  11995.  
  11996. ############################################################################
  11997. #
  11998. #    Name:    newsuffixes.icn
  11999. #
  12000. #    Title:    Replace filename suffixes
  12001. #
  12002. #    Author:    Anthony V. Hewitt
  12003. #
  12004. #    Date:    August 21, 1991
  12005. #
  12006. ############################################################################
  12007.  
  12008. # Take a list of filenames, one per line, and output them with new suffixes
  12009. # The first arg is the old suffix; each new suffix outputs a line for each
  12010. # file that has a suffix matching the old suffix.
  12011.  
  12012. # if the input to "newsuffixes .icn .u1 .u2" is "foo.icn\nbar.junk",
  12013. # the output is
  12014. #    foo.u1
  12015. #    foo.u2
  12016.  
  12017. # The application I had in mind was to put at the top of the procs makefile:
  12018. # all:
  12019. #    make `ls *.icn | newsuffixes .icn .u1 .u2`
  12020. # This removes one source of error from the makefile, since in no longer needs
  12021. # a complete list of .u[12] files as dependencies for "all"
  12022.  
  12023. # If the find fails, nothing is output.  This is intentional, but one
  12024. # could argue that it would be more useful to pass such a filename
  12025. # unmodified.
  12026.  
  12027. # Note that new suffixes may have the value ''; e.g. in the progs makefile,
  12028. # all:
  12029. #    make `ls *.icn | newsuffixes .icn ''`
  12030.  
  12031. # Old suffixes may not have the value '', since that case seems to have no
  12032. # useful interpretation.
  12033.  
  12034. procedure main(args)
  12035.     (*args > 1) |
  12036.     stop("syntax newsuffixes old new [new . . .]")
  12037.     (*(oldsuffix := pop(args)) > 0) |
  12038.     stop("zero-length old suffix is not meaningful")
  12039.     every write(|read() ? tab(find(oldsuffix)), !args)
  12040.     end
  12041.  
  12042.  
  12043. **********************************************************************
  12044.  
  12045. ############################################################################
  12046. #
  12047. #    Name:    icondepend.icn
  12048. #
  12049. #    Title:    Parse an icon source to produce a make rule
  12050. #
  12051. #    Author:    Anthony V. Hewitt
  12052. #
  12053. #    Date:    September 11, 1991
  12054. #
  12055. ############################################################################
  12056.  
  12057. # args are the filenames of the targets to be processed;
  12058. # standard input is a newline-separated list of the filenames
  12059. # (including the path) of the dependency candidates.
  12060.  
  12061. # Usage:
  12062. # Typically:
  12063. # ls [./*.icn] procsdir/*.icn [procsdir1/*.icn...] |
  12064. #                                                 newsuffixes .icn .u1 |
  12065. #                                                 icondepend foo [...]
  12066. # writes to the standard output make-format dependencies for foo
  12067. # e.g if foo.icn contains a statement "link a, b"
  12068. # with a.icn and b.icn present in procsdir, the output of icondepend is
  12069. # foo: foo.icn procsdir/a.u1 procsdir/b.u1
  12070. #       icont $(ICONFLAGS) foo.icn
  12071.  
  12072. # In a makefile
  12073. # %: %.icn FORCE
  12074. #    ls $(PROCSDIR)/*.icn | newsuffixes .icn .u1 | icondepend $@ >>makerules
  12075. #    $(MAKE) $@
  12076. # will create, if necessary, a rule for a target that has
  12077. # a corresponding icon source file.
  12078.  
  12079. # It is assumed that good practice guarantees that each filename is unique
  12080. # in the list of dependencies (though not necessarily in IPATH)
  12081. # even though there may be multiple directories.
  12082. # It is also assumed that the link statements do not include hardcoded paths,
  12083. # since this makes nonportable code.
  12084.  
  12085. procedure main(args)
  12086.     library := table()
  12087.     words := &ascii -- '\t ,"'
  12088.     every s := |read() do
  12089.     library[reverse(reverse(s) ? tab(upto('/')))] := s
  12090.     every target := !args do {
  12091.     source := open(sourcename := (target ? tab(upto('.') | 0) || ".icn"))
  12092.     s := ""
  12093.     every t := (getline(source) ? (tab(match("link")), tab(0))) do {
  12094.         if *t = 0 then t := ","                # a hack, I admit
  12095.         s ||:= t
  12096.         while (s[-1] == ",") do s ||:= getline(source)
  12097.     }
  12098.     writes(target, ": ", sourcename)
  12099.     s ? { while tab(upto(words)) do {
  12100.         t := tab(many(words))
  12101.         every writes(" ",\library[t || (".u1" | ".u2")])
  12102.     }
  12103.       }
  12104.     write("\n\ticont $(ICONFLAGS) ",sourcename)
  12105.     }
  12106. end
  12107.  
  12108. procedure getline(source)
  12109.     while (s := (trim(|read(source)) ? tab(upto('#')|0)))
  12110.     do (*s > 0,  suspend reverse(trim(reverse(s))))
  12111. end
  12112.     
  12113.  
  12114. **********************************************************************
  12115.     
  12116.     
  12117. # Makefile for Icon programs
  12118.  
  12119. PROCSDIR = ./procs
  12120.  
  12121. # Let's be safe
  12122. .SUFFIXES: 
  12123.  
  12124. all:
  12125.     $(MAKE) `ls *.icn | newsuffixes .icn ''`
  12126.  
  12127. %.u1: FORCE
  12128.     cd $(@D) ; $(MAKE) $(@F) $(*F).u2
  12129.  
  12130. %: %.icn FORCE
  12131.     ls $(PROCSDIR)/*.icn | newsuffixes .icn .u1 | icondepend $@ >>makerules
  12132.     $(MAKE) $@
  12133.  
  12134. FORCE:    
  12135.  
  12136. include makerules
  12137.  
  12138. clean:
  12139.     cd $(PROCSDIR); $(MAKE) clobber
  12140.  
  12141. clobber: clean
  12142.     -mv newsuffixes $(HOME)/bin
  12143.     -mv icondepend $(HOME)/bin
  12144.     -$(RM) makerules
  12145.     touch makerules
  12146.     -$(RM) `ls *.icn | newsuffixes .icn ''`
  12147.  
  12148.  
  12149. **********************************************************************
  12150.  
  12151. # Makefile for Icon procedures
  12152.  
  12153. ICONFLAGS = -uc
  12154.  
  12155. # Let's be safe
  12156. .SUFFIXES: 
  12157.  
  12158. all:
  12159.     $(MAKE) `ls *.icn | newsuffixes .icn .u1 .u2`
  12160.  
  12161. %.u1 %.u2: %.icn FORCE
  12162.     ls ./*.icn | newsuffixes .icn .u1 .u2 | icondepend $@ >>makerules
  12163.     $(MAKE) $@
  12164.  
  12165. FORCE:    
  12166.  
  12167. include makerules
  12168.  
  12169. clobber:
  12170.     -$(RM) makerules
  12171.     touch makerules
  12172.     -$(RM) *.u1 *.u2
  12173.  
  12174. --
  12175. ------------------------------------------------------------------------------
  12176. Anthony V. Hewitt                  Phone 414 548-5170 (GE Dialcom 8*320-5170)
  12177. Senior Physicist
  12178. General Electric Company             Fax 414 548-5197 (8*320-5197)
  12179. P.O.Box 414, W-641
  12180. Milwaukee, WI 53201                    Internet: hewitta@aslpet.med.ge.com
  12181. ------------------------------------------------------------------------------
  12182.  
  12183. From whm@sunquest.com  Fri Oct 25 11:28:26 1991
  12184. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Fri, 25 Oct 91 11:28:26 MST
  12185. Received: from ALPHA.SUNQUEST.COM by optima.cs.arizona.edu (4.1/15)
  12186.     id AA29544; Fri, 25 Oct 91 11:28:16 MST
  12187. Received: from sunquest.sunquest.com by ALPHA.SUNQUEST.COM with SMTP; 
  12188.           Fri, 25 Oct 1991 11:28:10 -0700 (MST)
  12189. Received: by sunquest.sunquest.com (4.1/SMI-4.1)
  12190.     id AA22221; Fri, 25 Oct 91 11:28:24 MST
  12191. Date: Fri, 25 Oct 91 11:28:24 MST
  12192. From: whm@sunquest.com (Bill Mitchell)
  12193. Message-Id: <9110251828.AA22221@sunquest.sunquest.com>
  12194. To: icon-group@cs.arizona.edu
  12195. Subject: perl
  12196.  
  12197. I watched perl from a distance for quite a while and then figuring that
  12198. there must be something to it, I read part one of a three-part series on
  12199. it in Unix/World or Unix Review.  Actually, it was more like the first
  12200. two-thirds of part one because I got disgusted and quit.  It seemed like
  12201. there were just too many special cases and irregularities.  I got the feeling
  12202. that I'd have to be constantly thumbing through the O'Reilly book whenever
  12203. I wrote a program.
  12204.  
  12205. I suppose I'll end up learning perl sooner or later, but I've been largely
  12206. able to avoid serious shell programming by using Icon instead, so maybe I'll
  12207. be able to avoid perl as well.
  12208.  
  12209. Maybe what we need is an Idol framework for doing shell script type stuff.
  12210. --------------------------------------------------------------------
  12211. Bill Mitchell                whm@sunquest.com
  12212. Sunquest Information Systems        sunquest!whm@arizona.edu
  12213. 930 N. Finance Center Dr.               {arizona,uunet}!sunquest!whm
  12214. Tucson, AZ, 85710                       sunquest!whm@uunet.uu.net
  12215. 602-885-7700
  12216.  
  12217. From mitch@rock.csd.sgi.com  Fri Oct 25 14:02:23 1991
  12218. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Fri, 25 Oct 91 14:02:23 MST
  12219. Received: from sgi.sgi.com (SGI.COM) by optima.cs.arizona.edu (4.1/15)
  12220.     id AA05931; Fri, 25 Oct 91 14:02:21 MST
  12221. Received: from rock.csd.sgi.com by sgi.sgi.com via SMTP (911016.SGI/910110.SGI)
  12222.     for icon-group@cs.arizona.edu id AA24292; Fri, 25 Oct 91 13:48:04 -0700
  12223. Received: by rock.csd.sgi.com (911016.SGI/910805.SGI)
  12224.     for @sgi.sgi.com:icon-group@cs.arizona.edu id AA12133; Fri, 25 Oct 91 13:48:00 -0700
  12225. Date: Fri, 25 Oct 91 13:48:00 -0700
  12226. From: mitch@rock.csd.sgi.com (Tom Mitchell)
  12227. Message-Id: <9110252048.AA12133@rock.csd.sgi.com>
  12228. To: icon-group@cs.arizona.edu
  12229. In-Reply-To: Bill Mitchell's message of Fri, 25 Oct 91 11:28:24 MST <9110251828.AA22221@sunquest.sunquest.com>
  12230. Subject: perl
  12231.  
  12232.  
  12233.    Date: Fri, 25 Oct 91 11:28:24 MST
  12234.    From: whm@sunquest.com (Bill Mitchell)
  12235.  
  12236.    I watched perl from a distance for quite a while and then figuring that
  12237.    there must be something to it,.....  Actually, it was more like the first
  12238.    two-thirds of part one because I got disgusted and quit.  It seemed like
  12239.    there were just too many special cases and irregularities. 
  12240.  
  12241.  
  12242.    I got the feeling
  12243.    that I'd have to be constantly thumbing through the O'Reilly book whenever
  12244.    I wrote a program.
  12245.  
  12246. Bill's observations have a lot of value.  Perl is full of
  12247. irregularities because it is a collection of functionality
  12248. from at least five different tools.
  12249.  
  12250. In the man page Larry Wall says: "It combines (in the
  12251. author's opinion, anyway) some of the best features of C,
  12252. sed, awk, and sh, so people familiar with those languages
  12253. should have little difficulty with it.  (Language historians
  12254. will also notesome vestiges of csh, Pascal, and even
  12255. BASIC-PLUS.)"
  12256.  
  12257. Most unix tools are built with any of the set of tools in a
  12258. standard Unix.  Perl avoids bouncing from tool to tool by
  12259. including the functionality withing the language.  It is the
  12260. rare unix shell (sh) novice that understands that "[" is a
  12261. link to /bin/test and that 'sh' cannot test for the simplest
  12262. things.  Nor can 'sh' do arithmetic on strings.  Again 'sh'
  12263. programs must invoke an external utility 'expr' to do
  12264. arithmetic and arithmetic comparisons on the strings shell
  12265. understands.
  12266.  
  12267. This is the same corner that modern 'elegent' languages
  12268. (Modula II) found themselves in when users discovered that
  12269. no 'standard' library of tools/functions is available.  You
  12270. want to use the language, but there is no foundation tool
  12271. set to begin with.
  12272.  
  12273. Larry avoided this functionality library problem by rolling
  12274. all things in to the language and his library.
  12275.  
  12276. Thumbing through the O'Reiley book is a tad simpler than
  12277. fumbling through a stack of disjoint unix man pages because
  12278. the book is unified in its table of contents and index.
  12279.  
  12280. From the Unix users side, perl is a simplification.  From the
  12281. language designer side it is a tad grungy.
  12282.  
  12283. Hmmm...  what if perl had 'generators'  :-)
  12284.  
  12285.  
  12286.  
  12287.  
  12288.