home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group91d.txt < prev    next >
Internet Message Format  |  1991-12-31  |  360KB

  1. From isidev!nowlin@uunet.uu.net  Sat Oct 26 07:17:16 1991
  2. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Sat, 26 Oct 91 07:17:16 MST
  3. Received: from relay1.UU.NET by optima.cs.arizona.edu (4.1/15)
  4.     id AA09309; Sat, 26 Oct 91 07:17:14 MST
  5. Received: from uunet.uu.net (via LOCALHOST.UU.NET) by relay1.UU.NET with SMTP 
  6.     (5.61/UUNET-internet-primary) id AA17544; Sat, 26 Oct 91 10:17:11 -0400
  7. Date: Sat, 26 Oct 91 10:17:11 -0400
  8. From: isidev!nowlin@uunet.uu.net
  9. Message-Id: <9110261417.AA17544@relay1.UU.NET>
  10. Received: from isidev.UUCP by uunet.uu.net with UUCP/RMAIL
  11.     (queueing-rmail) id 101647.2800; Sat, 26 Oct 1991 10:16:47 EDT
  12. To: uunet!cs.arizona.edu!icon-group@uunet.uu.net
  13. Subject: Re: makefiles for Icon
  14.  
  15. I didn't wade through every bit of the code Anthony had for generating
  16. makefiles.  I liked the part that searched for link statements and
  17. adds those files that another file links as dependencies for it.
  18.  
  19. I have this simple high level makefile file that I pull into other
  20. makefiles with the make include statement:
  21.  
  22.     ICONT    = icont
  23.     TFLAGS    = -c
  24.     LFLAGS    =
  25.     IBIN    = .
  26.  
  27.     .SUFFIXES:
  28.     .SUFFIXES:    .u1 .icn
  29.  
  30.     .icn:
  31.         $(ICONT) $(LFLAGS) -o $(IBIN)/$@ $<
  32.  
  33.     .u1:
  34.         $(ICONT) $(LFLAGS) -o $(IBIN)/$@ $<
  35.  
  36.     .icn.u1:
  37.         $(ICONT) $(TFLAGS) $<
  38.  
  39. If I just name this file "makefile" the suffix rules it contains
  40. allow me to execute:
  41.  
  42.     make foo
  43.  
  44. and if there's a file called foo.icn in the current directory, make
  45. knows enough to handle everything.  Anthony's stuff would be nice for
  46. programs that require several ucode files to make an icode file.  I
  47. just use explicit dependency lines for these:
  48.  
  49.     menu2:    menu2.u1 welcome.u1 io.u1
  50.         $(ICONT) menu2
  51.  
  52. Due to the suffix rules in the earlier makefile this dependency line
  53. causes the correct .u1 files to be automatically built from the
  54. corresponding source files.  The welcome and io ucode files are
  55. "link"ed into menu2 and Anthony's tool would be useful for detecting
  56. this.  The right suffix rules make makefiles much simpler to write and
  57. maintain.
  58.  
  59. Of course I usually use a modified version of this makefile that
  60. invokes isicont :-)
  61.  
  62. --- ---
  63.  | S | Iconic Software, Inc.  -  Jerry Nowlin  -  uunet!isidev!nowlin
  64. --- ---
  65.  
  66.  
  67. From icon-group-request@arizona.edu  Fri Nov  1 05:49:17 1991
  68. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Fri, 1 Nov 91 05:49:17 MST
  69. Resent-From: icon-group-request@arizona.edu
  70. Received: from Arizona.edu (Hopey.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  71.     id AA24489; Fri, 1 Nov 91 05:49:15 MST
  72. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Fri, 1 Nov
  73.  1991 05:48 MST
  74. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA23886; Fri, 1 Nov 91 03:38:56
  75.  -0800
  76. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  77.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  78.  usenet@ucbvax.Berkeley.EDU if you have questions)
  79. Resent-Date: Fri, 1 Nov 1991 05:49 MST
  80. Date: 28 Oct 91 23:32:07 GMT
  81. From: csus.edu!wupost!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!midway!ellis!goer@ucdavis.ucdavis.edu
  82.  (Richard L. Goerwitz)
  83. Subject: regular expression in Icon
  84. Sender: icon-group-request@arizona.edu
  85. Resent-To: icon-group@cs.arizona.edu
  86. To: icon-group@arizona.edu
  87. Resent-Message-Id: <97291E97A880533B@Arizona.edu>
  88. Message-Id: <1991Oct28.233207.1119@midway.uchicago.edu>
  89. X-Envelope-To: icon-group@CS.Arizona.EDU
  90. X-Vms-To: icon-group@Arizona.edu
  91. Organization: University of Chicago
  92.  
  93. I've been mulling over the problem of regular expressions and Icon for
  94. some time now.  I can't really decide on how they should be implemen-
  95. ted.  Has anyone else thought on this question?  (Obviously the answer
  96. is "yes," so I'm basically just asking for input.)
  97.  
  98. A while back I wrote a regular expression handler for Icon that used
  99. a NFA to accomplish something halfway between what Icon's find() and
  100. UNIX's egrep do.  This program is now in the IPL.  Trouble is that it
  101. is slow.  As I mentioned when I posted test versions of it, I tried
  102. to use a DFA, but I just couldn't figure a way to do this in Icon and
  103. still keep the automaton small and fast.  I even tried egrep-like
  104. optimizations, which create only that portion of the atomaton that
  105. is needed (i.e. it compiles it incrementally as needed).  This still
  106. didn't work.
  107.  
  108. I wasn't happy with that effort, at least on the implementation
  109. level.  The idea of integrating regular expressions into Icon, though,
  110. without using a new data type, seems good, though.
  111.  
  112. Does anyone disagree?
  113.  
  114. I'd like to hear variant opinions.
  115.  
  116. If anyone running a SYSV system would like to try some extensions to
  117. the Icon run-time system, I have an implementation of find and match
  118. on hand that take regular expressions for arg1.  They seem to work
  119. just fine, and I can't find any memory leaks in the buffering system
  120. I hacked together.  Installing them would require slight modifications
  121. to three of the Icon source files and a recompilation.  I'll be happy
  122. to send a copy to anyone who feels adventurous.
  123.  
  124. -- 
  125.  
  126.    -Richard L. Goerwitz              goer%sophist@uchicago.bitnet
  127.    goer@sophist.uchicago.edu         rutgers!oddjob!gide!sophist!goer
  128.  
  129. From reid@vtopus.cs.vt.edu  Fri Nov  1 06:07:56 1991
  130. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Fri, 1 Nov 91 06:07:56 MST
  131. Resent-From: reid@vtopus.cs.vt.edu
  132. Received: from Arizona.edu (Merlin.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  133.     id AA25065; Fri, 1 Nov 91 06:07:54 MST
  134. Received: from vtopus.cs.vt.edu by Arizona.edu with PMDF#10282; Fri, 1 Nov 1991
  135.  06:07 MST
  136. Received: by vtopus.cs.vt.edu (5.57/Ultrix3.0-C) id AA00166; Fri, 1 Nov 91
  137.  08:07:06 -0500
  138. Resent-Date: Fri, 1 Nov 1991 06:07 MST
  139. Date: Fri, 1 Nov 91 08:07:06 -0500
  140. From: reid@vtopus.cs.vt.edu (Thomas F. Reid)
  141. Subject: Ralph Griswold Tutorial on Icon
  142. Resent-To: icon-group@cs.arizona.edu
  143. To: icon-group@arizona.edu
  144. Cc: reid@vtopus.cs.vt.edu
  145. Resent-Message-Id: <99C2D3A8A0403442@Arizona.edu>
  146. Message-Id: <9111011307.AA00166@vtopus.cs.vt.edu>
  147. X-Envelope-To: icon-group@CS.Arizona.EDU
  148. X-Vms-To: icon-group@Arizona.edu
  149. X-Vms-Cc: reid@vtopus.cs.vt.edu
  150.  
  151.  
  152. Ralph will give a one day tutorial on Icon in the Washington, DC area at
  153. the University of Maryland Adult Education Center on Friday, November 22nd.
  154. An announcement is attached.  Please feel free to call/write me if there is
  155. anything I can do to help you attend.
  156. ----------------------  Attachment  ------------------------
  157.  
  158. The Washington, DC Chapter of ACM Professional Development
  159. Committee presents over 20 one-day tutorials a year taught by
  160. many of the world's top computer scientists.  During the week of
  161. November 18-22, 1991, the PDC will offer 10 tutorials.  Of
  162. special interest is the tutorial on November 22 on the Icon
  163. programming language given by Dr. Ralph Griswold, Regents'
  164. Professor of Computer Science at The University of Arizona.
  165.  
  166. Dr. Griswold is Regents' Professor of Computer Science at The
  167. University of Arizona.  He has nearly 30 years of experience in
  168. the design, implementation, and use of high-level programming
  169. languages.  He started his work at Bell Laboratories, where he
  170. co-authored the SNOBOL series of programming languages for string
  171. manipulation.  Since 1971, he has continued his
  172. programming-language work at Arizona, concentrating on facilities
  173. for non-numerical computation.  He is author or co-author of six
  174. books on programming languages and their implementation.
  175.  
  176. Other tutorials given the same week as Dr. Griswold's are:
  177. Object-Oriented Program Design Using C++ by David Bern and Peer
  178. Reviews - Theory and Practice by Richard Cohen on Monday,
  179. November 18; Code Metrics and Design Metrics by Dr. Wayne M. Zage
  180. and Software Reverse Engineering by Dr. Hasan Sayani on Tuesday,
  181. November 19; Applying Statistical Process Control to Software
  182. Development by Barba Affourtit and Software Repository and Bridge
  183. Technology by Dr. Robert Arnold on Wednesday, November 20;
  184. Information Modeling by Dr. Cy Svoboda and Unit Testing During
  185. Maintenance by Thomas Bogart on Thursday, November 21; and
  186. Software Maintenance Technology by Nicholas Zvegintzov on Friday,
  187. November 22.
  188.  
  189. The tutorials will be given at the University of Maryland Center
  190. of Adult Education in College Park, Maryland.  Registration can
  191. be by mail or telephone.  For a brochure describing all of the
  192. courses, please call the PDC's answering machine at 202-462-1215. 
  193. Phone registration by credit card can be made by calling Ms.
  194. Eliane Van Ty Smith at 301-299-4286.  Prices for check or credit
  195. card are $170 for Washington DC ACM chapter members and $175 for
  196. non-members by November 4; $205 after November 4.  Purchase order
  197. are $230.  Full-time students and senior citizens are $60.
  198.  
  199. If you have questions, please call the PDC answering machine at
  200. 202-462-1215 or internet Tom Reid at reid@vtopus.cs.vt.edu or
  201. call at (703)698-4712.
  202. 
  203.  
  204. From icon-group-request@arizona.edu  Fri Nov  1 08:36:41 1991
  205. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Fri, 1 Nov 91 08:36:41 MST
  206. Resent-From: icon-group-request@arizona.edu
  207. Received: from Arizona.edu (Merlin.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  208.     id AA28901; Fri, 1 Nov 91 08:36:39 MST
  209. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Fri, 1 Nov
  210.  1991 08:36 MST
  211. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA01253; Fri, 1 Nov 91 07:19:33
  212.  -0800
  213. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  214.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  215.  usenet@ucbvax.Berkeley.EDU if you have questions)
  216. Resent-Date: Fri, 1 Nov 1991 08:36 MST
  217. Date: 29 Oct 91 07:37:44 GMT
  218. From: ntrlink!mips!zaphod.mps.ohio-state.edu!caen!uvaarpa!murdoch!usenet@decwrl.dec.com (Steven D.
  219.  Majewski)
  220. Subject: Approximate string matching
  221. Sender: icon-group-request@arizona.edu
  222. Resent-To: icon-group@cs.arizona.edu
  223. To: icon-group@arizona.edu
  224. Resent-Message-Id: <AE8BC8F50820481F@Arizona.edu>
  225. Message-Id: <1991Oct29.073744.13155@murdoch.acc.Virginia.EDU>
  226. X-Envelope-To: icon-group@CS.Arizona.EDU
  227. X-Vms-To: icon-group@Arizona.edu
  228. Organization: University of Virginia
  229.  
  230. I am implementing the Levenshtein string-edit distance in Icon.
  231. ( number of insertions, deletions & replacements. Note: there 
  232. is nothing about THIS algorithm especiall suited to ICON, but
  233.  
  234. there is going to be pleanty of other string/symbol processing 
  235. in the rest of the program that that routine will go in. )
  236.  
  237. Has anyone done any *weighted* versions ( that weight 
  238. "natural" mispelling replacements like (S|Z) less, or even better,
  239. that handle some pairs as one 'symbol' ?    
  240.  
  241. Anyone have any experience with different (more 'symbolic') algorithms ? 
  242.  
  243. I know U.Arizona has an 'approximate' grep program. I ftp-ed a copy,
  244. but I can't ( at the moment ) read the PostScript document. Can anyone
  245. give me a quick description of the algorithm they use ? 
  246.  
  247. Note: I have Hall&Dowling:Approximate String Matching and Sankoff&Kruskal:
  248.  Time Warps, String edits and Macromolecules: the theory and practice 
  249.  of sequence comparison. ( I haven't read it all yet, but I've sure got it!)
  250.  So I'm not looking for theory as much as practice. War stories invited!
  251.  
  252.  -Steve Majewski
  253.  
  254.  
  255.  
  256.  
  257.  
  258. --
  259. ========= "If you've got a hammer, find a nail!" - George Bush =========
  260.  Steven D. Majewski        University of Virginia Physiology Dept.
  261.  sdm7g@Virginia.EDU        Box 449 Health Sciences Center
  262.  (804)-982-0831            Charlottesville, VA 22908
  263.  
  264. From icon-group-request@arizona.edu  Fri Nov  1 08:37:24 1991
  265. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Fri, 1 Nov 91 08:37:24 MST
  266. Resent-From: icon-group-request@arizona.edu
  267. Received: from Arizona.edu (Merlin.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  268.     id AA28916; Fri, 1 Nov 91 08:37:23 MST
  269. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Fri, 1 Nov
  270.  1991 08:36 MST
  271. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA01162; Fri, 1 Nov 91 07:17:10
  272.  -0800
  273. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  274.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  275.  usenet@ucbvax.Berkeley.EDU if you have questions)
  276. Resent-Date: Fri, 1 Nov 1991 08:37 MST
  277. Date: 29 Oct 91 07:06:10 GMT
  278. From: usenet.coe.montana.edu!caen!uvaarpa!murdoch!usenet@decwrl.dec.com (Steven
  279.  D. Majewski)
  280. Subject: Icon futures ? (coroutines,patterns,etc.)
  281. Sender: icon-group-request@arizona.edu
  282. Resent-To: icon-group@cs.arizona.edu
  283. To: icon-group@arizona.edu
  284. Resent-Message-Id: <AEA5DB26C82062A0@Arizona.edu>
  285. Message-Id: <1991Oct29.070610.12954@murdoch.acc.Virginia.EDU>
  286. X-Envelope-To: icon-group@CS.Arizona.EDU
  287. X-Vms-To: icon-group@Arizona.edu
  288. Organization: University of Virginia
  289.  
  290. I have been reading Ken Walker's paper in Computer Language (1989)
  291. First Class Patterns for Icon.
  292.  
  293. I also saw poking around the archives a statement that there was no
  294. plan for incorporating this feature ( I think they were referred to as 
  295. "C-expressions" ? )
  296.  
  297. Is this still an acurate statement ? 
  298. Are there any other similar developments ?
  299.  
  300. [ This paper described a change to the semantics of Icon co-expressions
  301.   to allow patterns to be defined as unevaluated co-expressions. ]
  302.  
  303. I am just beginning to learn Icon and I've only READ a few dozen lines
  304. of SNOBOL code, but I must agree that although I find the Icon way of 
  305. doing things flexible and powerful, some of the pattern matching code
  306. is not as clear or obvious to the eye as, say, a BISON|YACC grammar.
  307.  
  308. [ Anyone written the ICON equivalent? A table driven Icon code generator?]
  309.  
  310. Also- I saw the idea of grep-type regexp routines discussed.
  311. Sorry if all this has been hashed over and settled, but although
  312. Icon mathing expressions are very powerful, some things like regular
  313. expressions seem to be a special case in terms of the possible effeciency.
  314.  
  315. [ There is a paper by Ken-Chih Liu that proposes (for modified PASCAL)
  316.   a pattern declaration and a "REGULAR" pattern declaration, so that
  317.  string matching functions can make use of regular expression matching
  318. when possible.]
  319.  
  320. Rather than the typical Unix/grep type regexp patterns, I would suggest
  321. a list of character-strings, csets or list of character strings .
  322. ( I'm not sure about the best way of expressing multiple occurances.)
  323.  
  324. Icon is a typed language without type declarations and with some limited
  325. automatic coercion of types. ( I hope that is an acurate statement. )
  326. What would be the ramifications of changing the language to a hierarchy
  327. of types ( a la russel, or like OO class inheritance perhaps )
  328. Thus csets would become, not another type, but a special case of 
  329. character strings. Regular expressions would be a sequence of strings,
  330. csets and sets of strings...  I guess that this is no longer Icon,
  331. but anyone have a good idea of how to put it together consistently ? 
  332.  
  333. - Steve Majewski
  334.  
  335.  
  336.  
  337.  
  338.  
  339.  
  340.  
  341.  
  342.  
  343. --
  344. ========= "If you've got a hammer, find a nail!" - George Bush =========
  345.  Steven D. Majewski        University of Virginia Physiology Dept.
  346.  sdm7g@Virginia.EDU        Box 449 Health Sciences Center
  347.  (804)-982-0831            Charlottesville, VA 22908
  348.  
  349. From cjeffery  Fri Nov  1 10:50:02 1991
  350. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Fri, 1 Nov 91 10:50:02 MST
  351. Resent-From: "Clinton Jeffery" <cjeffery>
  352. Received: from Arizona.edu (Hopey.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  353.     id AA04827; Fri, 1 Nov 91 10:49:59 MST
  354. Received: from optima.cs.arizona.edu by Arizona.edu with PMDF#10282; Fri, 1 Nov
  355.  1991 10:49 MST
  356. Received: from cheltenham.cs.arizona.edu by optima.cs.arizona.edu (4.1/15) id
  357.  AA04803; Fri, 1 Nov 91 10:48:58 MST
  358. Received: by cheltenham.cs.arizona.edu; Fri, 1 Nov 91 10:48:57 MST
  359. Resent-Date: Fri, 1 Nov 1991 10:49 MST
  360. Date: Fri, 1 Nov 91 10:48:57 MST
  361. From: "Clinton L. Jeffery" <cjeffery@cs.arizona.edu>
  362. Subject: RE: Icon futures ? (coroutines,patterns,etc.)
  363. Resent-To: icon-group@cs.arizona.edu
  364. To: icon-group@arizona.edu
  365. Resent-Message-Id: <C123334BE8206991@Arizona.edu>
  366. Message-Id: <9111011748.AA29800@cheltenham.cs.arizona.edu>
  367. X-Envelope-To: icon-group@CS.Arizona.EDU
  368. X-Vms-To: icon-group@Arizona.edu
  369.  
  370. I have enjoyed Richard Goerwitz and Steve Majewski's recent posts to the
  371. group, and I'd like to add my 2 cents worth.
  372.  
  373. First, all these proposals seem to be about adding something to the
  374. language, rather than just adding Icon program library procedure(s),
  375. and the compelling reason (for those without the Icon compiler) is speed.
  376.  
  377. Second, the "right" thing to add to the language is not clear at all.
  378. "findre" and "matchre" aren't general enough for many situations I wish
  379. I had regular expressions.  Richard was asking for examples.  I want
  380. to be able to match a regular expression while selecting some pieces of
  381. it that I need, and discarding others.  In order to process an Icon
  382. declaration, for instance, I only want the second, fifth, and sixth
  383. components of the following regular expression:
  384.  
  385.     [ \t]* (procedure|record) [\ t]* "(" {[a-zA-Z0-9] (,[a-zA-Z0-9]*)*} ")"
  386.  
  387. I won't belabor this point, but proposals for official additions to Icon
  388. undergo a lot more scrutiny than proposals for Icon library procedures.
  389. (If my regular expression notation looks weird, that just shows that
  390. regular expression notations are not all equal).
  391.  
  392. Third, anyone who wants to add RE's as Icon builtins might look for a
  393. suitable set of public domain C functions on which to build.  I believe
  394. several free versions exist, such as one by Henry Spencer of the U. of
  395. Toronto, but I don't know which are public domain and which are "copylefted"
  396. and such.  But the point is that the best way to build grass-roots support
  397. for an extension is to produce an implementation that works on *lots* of
  398. (and potentially all) versions of Icon, not just certain UNIX'es.
  399.  
  400. Now I'd like to continue my ranting by moving onto Steve Majewski's post.
  401. There are no plans to add patterns or regular expressions to Icon that I
  402. know of within the Icon Project.  I agree with you though that string
  403. scanning is an incredibly verbose (and therefore cumbersome) way of
  404. describing lots of string operations that are done easily in other
  405. languages.  You compare them to YACC -- which is more than a little
  406. unfair since Icon is a "General Purpose" language and YACC is not.
  407. If we add patterns or regular expressions to Icon, will they fit into
  408. Icon, or will they be a separate sublanguage?  On the other hand, I
  409. think someone has in fact written a YACC-type program for Icon, one
  410. that generates Icon code.
  411.  
  412. SM> Icon is a typed language without type declarations and with some limited
  413. SM> automatic coercion of types. ( I hope that is an acurate statement. )
  414. SM> What would be the ramifications of changing the language to a hierarchy
  415. SM> of types ( a la russel, or like OO class inheritance perhaps )
  416. SM> Thus csets would become, not another type, but a special case of 
  417. SM> character strings. Regular expressions would be a sequence of strings,
  418. SM> csets and sets of strings...  I guess that this is no longer Icon,
  419. SM> but anyone have a good idea of how to put it together consistently ? 
  420.  
  421. This sounds like an excellent area of future research.  I may well choose to
  422. pursue this within the context of Idol, an object-oriented version of Icon.
  423. Csets, though, should not be a special case of strings!  And where regular
  424. expressions fit is less clear than you'd like them to be.  You are right
  425. that this is no longer Icon you envision.  This is a successor to Icon.
  426.  
  427. Clint Jeffery
  428.  
  429. From icon-group-request@arizona.edu  Fri Nov  1 13:18:50 1991
  430. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Fri, 1 Nov 91 13:18:50 MST
  431. Resent-From: icon-group-request@arizona.edu
  432. Received: from Arizona.edu (Osprey.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  433.     id AA11441; Fri, 1 Nov 91 13:18:48 MST
  434. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Fri, 1 Nov
  435.  1991 13:17 MST
  436. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA07527; Fri, 1 Nov 91 10:23:56
  437.  -0800
  438. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  439.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  440.  usenet@ucbvax.Berkeley.EDU if you have questions)
  441. Resent-Date: Fri, 1 Nov 1991 13:18 MST
  442. Date: 29 Oct 91 04:32:23 GMT
  443. From: cis.ohio-state.edu!pacific.mps.ohio-state.edu!linac!midway!quads!goer@ucbvax.berkeley.edu (Richard
  444.  L. Goerwitz)
  445. Subject: What is Icon?
  446. Sender: icon-group-request@arizona.edu
  447. Resent-To: icon-group@cs.arizona.edu
  448. To: icon-group@arizona.edu
  449. Resent-Message-Id: <D5F142ABC8804E96@Arizona.edu>
  450. Message-Id: <1991Oct29.043223.9307@midway.uchicago.edu>
  451. X-Envelope-To: icon-group@CS.Arizona.EDU
  452. X-Vms-To: icon-group@Arizona.edu
  453. Organization: University of Chicago
  454.  
  455. I receive fairly frequent letters from people who want to know what
  456. Icon is.  Often I have some blurb around, but typically it's been writ-
  457. ten by someone else, and reflects a theorist or language-designer's
  458. vantage point.  Usually, I advise the person to read comp.lang.icon a
  459. while, but I guess I don't really see how that would help, given the
  460. nature of most postings here.  Just for the sake of people who I've
  461. sent here, and for the sake of people who are reading along trying to
  462. find out what Icon is, here's a longer blurb that reflects a humanist's
  463. perspective on the language:
  464.  
  465. ----
  466.  
  467.     Icon (1976) represents a combination of Prolog-like evaluation
  468. mechanisms with an Algol-based syntax and SNOBOL-derived string
  469. processing facilities.  Icon offers automatic storage allocation and
  470. garbage collection, as well as built in associative arrays, lists,
  471. "real" strings (i.e. not just char arrays), and a data type resembling
  472. mathematical sets.  Icon is a strongly, though not statically, typed
  473. language offering transparent automatic type conversions (i.e. 10,
  474. depending on its context, may be converted to real, string, etc.) and
  475. an elegant string processing mechanism known as "scanning."
  476.     Central to Icon is the concept of the generator, i.e. the
  477. inherent capacity on the part of expressions to produce multiple
  478. results.  Central also is the notion of goal-directed evaluation - a
  479. form of backtracking in which the components of an expression are
  480. resumed until some result is achieved, or else the expression as a
  481. whole fails.  Icon was originally designed by Ralph Griswold, Dave
  482. Hanson, and Tim Korb.  It was first implemented in C by Steve Wampler.
  483. Definitive references: Ralph E. and Madge T. Griswold, _The Icon
  484. Programming Language_ (2nd ed.; Prentice Hall, 1989); _The
  485. Implementation of the Icon Programming Language_ (Princeton Univ. Pr.,
  486. 1986).
  487.     Icon is at its best when used as a prototyping tool, for
  488. processing text, for performing various mappings and conversions, and
  489. as a general tool for solving problems that tend to require heuristic
  490. mechanisms, rather than purely algorithmic ones.  In general, Icon's
  491. design assigns a higher priority to consistency and lucidity than to
  492. functionality within one or another operating environment.  For this
  493. reason, it is not a good UNIX system administration tool.  Nor is it
  494. particularly fast.  It is a clean, portable system implemented under
  495. VMS, MVS, SYSV, Mach, BSD, Ultrix, HP/UX, AEGIS, OS/2, and many other
  496. operating systems, as well as for various micros, such as the Atari,
  497. Amiga, and PC.  Icon is a good language choice for theorists exploring
  498. language design, for scholars in the humanities, and generally for
  499. people interested in nonnumeric computing.
  500.     Ongoing interesting work being done in Icon include an object-
  501. oriented extension to the language, known as IDOL.  A compiler is also
  502. being developed (a preliminary version of which is on cs.arizona.edu).
  503. Interfaces are being created for X, and also (commercially) for curses.
  504. There is a commercial version for the Mac available from Catspaw (known
  505. primarily for its PC SNOBOL).
  506.     Examples of Icon code can be obtained from many sources.  The
  507. primary source is certainly the Icon Program Library, which can be ob-
  508. tained from cs.arizona.edu (icon/library).  There is also a publication
  509. put out by the Icon Project (icon-project@cs.arizona.edu) called the
  510. _Analyst_.  Naturally the two definitive works cited above contain a
  511. fair amount of code.  There are also several programs available on the
  512. internet that are written in Icon (e.g. "mtf", "jargon," "quranref,"
  513. all in various issues of comp.sources.misc).  At times, large chunks
  514. of code get posted to comp.lang.icon, but these tend to come in fits
  515. and starts.  A final place to look for Icon code is in the icon/con-
  516. trib directory on cs.arizona.edu.
  517.  
  518. -----
  519.  
  520. I really hope that this posting answers in a systematic way many of the
  521. questions newcomers to Icon have on their minds.
  522.  
  523.  
  524. -- 
  525.  
  526.    -Richard L. Goerwitz              goer%sophist@uchicago.bitnet
  527.    goer@sophist.uchicago.edu         rutgers!oddjob!gide!sophist!goer
  528.  
  529. From icon-group-request@arizona.edu  Fri Nov  1 13:19:40 1991
  530. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Fri, 1 Nov 91 13:19:40 MST
  531. Resent-From: icon-group-request@arizona.edu
  532. Received: from Arizona.edu (Osprey.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  533.     id AA11458; Fri, 1 Nov 91 13:19:37 MST
  534. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Fri, 1 Nov
  535.  1991 13:18 MST
  536. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA07527; Fri, 1 Nov 91 10:23:56
  537.  -0800
  538. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  539.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  540.  usenet@ucbvax.Berkeley.EDU if you have questions)
  541. Resent-Date: Fri, 1 Nov 1991 13:19 MST
  542. Date: 29 Oct 91 04:32:23 GMT
  543. From: cis.ohio-state.edu!pacific.mps.ohio-state.edu!linac!midway!quads!goer@ucbvax.berkeley.edu (Richard
  544.  L. Goerwitz)
  545. Subject: What is Icon?
  546. Sender: icon-group-request@arizona.edu
  547. Resent-To: icon-group@cs.arizona.edu
  548. To: icon-group@arizona.edu
  549. Resent-Message-Id: <D6113B0718805B1A@Arizona.edu>
  550. Message-Id: <1991Oct29.043223.9307@midway.uchicago.edu>
  551. X-Envelope-To: icon-group@CS.Arizona.EDU
  552. X-Vms-To: icon-group@Arizona.edu
  553. Organization: University of Chicago
  554.  
  555.  
  556. From alex@laguna.metaphor.com  Fri Nov  1 18:03:34 1991
  557. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Fri, 1 Nov 91 18:03:34 MST
  558. Received: from relay.metaphor.com by optima.cs.arizona.edu (4.1/15)
  559.     id AA26844; Fri, 1 Nov 91 18:03:26 MST
  560. Received: from laguna.Metaphor.COM by relay.metaphor.com (4.1/SMI-4.1)
  561.     id AA09270; Fri, 1 Nov 91 17:02:20 PST
  562. Received: by laguna.Metaphor.COM (4.1/SMI-4.0)
  563.     id AA17910; Fri, 1 Nov 91 17:03:21 PST
  564. Date: Fri, 1 Nov 91 17:03:21 PST
  565. From: alex@laguna.metaphor.com (Bob Alexander)
  566. Message-Id: <9111020103.AA17910@laguna.Metaphor.COM>
  567. To: icon-group@cs.arizona.edu
  568. Subject: Re:  regular expression in Icon
  569.  
  570. Well, since there seems to be so much interest in regular expressions
  571. recently in icon-group, I have an offering that addresses the two
  572. predominant objections I've been hearing:
  573.  
  574. 1)    Richard G's concern about speed -- the routines that I've
  575.     attached to this message run at least 10 times faster than
  576.     the findre() suite.  Smaller too.  There is an interesting
  577.     technique used to exploit Icon's built-in backtracking so
  578.     that it does not have to be done explicitly in the Icon code.
  579.  
  580. 2)    Clint's concern about full-featuredness -- these routines
  581.     support the perl RE style, which is all of egrep's features
  582.     plus a few more, including access to sub-expressions
  583.     matched.
  584.  
  585. There is *lots* of documentation in the code.
  586.  
  587. I haven't gotten around to submitting these to the library yet, but plan
  588. to eventually -- hopefully before the next update.  In the meantime, I'd
  589. be interested in feedback from any of you Icon enthusiasts interested
  590. enough to give them a try.
  591.  
  592. I also attached an "igrep" program so you can use it without having
  593. to write your own test program.
  594.  
  595. -- Bob Alexander
  596.  
  597. Metaphor Computer Systems   (415) 961-3600 x751   alex@metaphor.com
  598. ====^=== Mountain View, CA  ...{uunet}!{decwrl,apple}!metaphor!alex
  599.  
  600.  
  601. --------------------------  regexp.icn  ----------------------------
  602.  
  603. ############################################################################
  604. #
  605. #    Name:    regexp.icn
  606. #
  607. #    Title:    UNIX-like Regular Expression Pattern Matching Procedures
  608. #
  609. #    Author: Robert J. Alexander
  610. #
  611. #    Date:    April 24, 1991
  612. #
  613. ############################################################################
  614. #
  615. #  This is a kit of procedures to deal with UNIX-like regular expression
  616. #  patterns.
  617. #
  618. #  These procedures are interesting partly because of the "recursive
  619. #  suspension" (or "suspensive recursion" :-) technique used to simulate
  620. #  conjunction of an arbitrary number of computed expressions (see
  621. #  notes, below).
  622. #
  623. #
  624. #  The public procedures are:
  625. #
  626. #  ReMatch(pattern,s,i1,i2) : i3,i4,...,iN
  627. #  ReFind(pattern,s,i1,i2) : i3,i4,...,iN
  628. #  RePat(s) : pattern list
  629. #
  630. #
  631. #  ReMatch() produces the sequence of positions in "s" past a substring
  632. #  starting at "i1" that matches "pattern", but fails if there is no
  633. #  such position.  Similar to match(), but is capable of generating
  634. #  multiple positions.
  635. #
  636. #  ReFind() produces the sequence of positions in "s" where substrings
  637. #  begin that match "pattern", but fails if there is no such position.
  638. #  Similar to find().  Each position is produced only once, even if
  639. #  several possible matches are possible at that position.
  640. #
  641. #  "pattern" can be either a string or a pattern list -- see RePat(),
  642. #  below.
  643. #
  644. #  Default values of s, i1, and i2 are handled as for Icon's built-in
  645. #  string scanning procedures such as match().
  646. #
  647. #
  648. #  RePat(s) : L
  649. #
  650. #  Creates a pattern element list from pattern string "s", but fails if
  651. #  the pattern string is not syntactically correct.  ReMatch() and
  652. #  ReFind() will automatically convert a pattern string to a pattern
  653. #  list, but it is faster to do the conversion explicitly if multiple
  654. #  operations are done using the same pattern.  An additional advantage
  655. #  to compiling the pattern separately is avoiding ambiguity of failure
  656. #  caused by an incorrect pattern and failure to match a correct pattern.
  657. #
  658. #
  659. #  Accessible Global Variables
  660. #
  661. #  After a match, the strings matched by parenthesized regular
  662. #  expressions are left in list "Re_ParenGroups", and can be accessed by
  663. #  subscripting in using the same number as the \N construct.
  664. #
  665. #  If it is desired that regular expression format be similar to UNIX
  666. #  filename generation patterns but still retain the power of full
  667. #  regular expressions, make the following assignments prior to
  668. #  compiling the pattern string:
  669. #
  670. #    Re_ArbString := "*"    # Defaults to ".*"
  671. #    Re_AnyString := "?"    # Defaults to "."
  672. #
  673. #  The sets of characters (csets) that define a word, digits, and white
  674. #  space can be modified.  The following assignments can be made before
  675. #  compiling the pattern string.  The character sets are captured when
  676. #  the pattern is compiled, so changing them after pattern compilation
  677. #  will not alter the behavior of matches unless the pattern string is
  678. #  recompiled.
  679. #
  680. #    Re_WordChars := 'whatever you like'
  681. #            # Defaults to &letters ++ &digits ++ "_"
  682. #    Re_Digits := &digits ++ 'ABCDEFabcdef'
  683. #            # Defaults to &digits
  684. #    Re_Space := 'whatever you like'
  685. #            # Defaults to ' \t\v\n\r\f'
  686. #
  687. #  These globals are normally not initialized until the first call to
  688. #  RePat(), and then only if they are null.  They can be explicitly
  689. #  initialized to their defaults (if they are null) by calling
  690. #  Re_Default().
  691. #
  692. #  Characters compiled into patterns can be passed through a
  693. #  user-supplied filter procedure, provided in global variable
  694. #  Re_Filter.  The filtering is done before the characters are bound
  695. #  into the pattern.  The filter proc is passed one argument, the string
  696. #  to filter, and it must return the filtered string as its result.  If
  697. #  the filter proc fails, the string will be used unfiltered.  The
  698. #  filter proc is called with an argument of either type string (for
  699. #  characters in the pattern) or cset (for character classes [...]).  A
  700. #  typical use for this facility is to implement case-independent
  701. #  matching.  All pattern characters can downshifted by assigning
  702. #
  703. #    Re_Filter := map
  704. #
  705. #  Filtering is done only as the pattern is compiled.  Filtering of
  706. #  strings to be matched must be explicitly done.  Therefore,
  707. #  case-independent matching will occur only if map() is applied to all
  708. #  strings to be matched.
  709. #
  710. #  In the case of patterns containing alternation, ReFind() will
  711. #  generally not produce positions in increasing order, but will produce
  712. #  all positions from the first term of the alternation (in increasing
  713. #  order) followed by all positions from the second (in increasing
  714. #  order).  If it is necessary that the positions be generated in
  715. #  strictly increasing order, with no duplicates, assign any non-null
  716. #  value to Re_Ordered:
  717. #
  718. #    Re_Ordered := 1
  719. #
  720. #  If the Re_Ordered options is chosen, there is a *small* penalty in
  721. #  efficiency in some cases, and the co-expression facility is required
  722. #  in your Icon implementation.  Example:
  723. #  
  724. #
  725. #  Regular Expression Characters and Features Supported
  726. #
  727. #  The regular expression format supported by procedures in this file
  728. #  model very closely those supported by the UNIX "egrep" program, with
  729. #  modifications as in the Perl programming language definition.
  730. #  Following is a brief description of the special characters used in
  731. #  regular expressions.  In the description, the abbreviation RE means
  732. #  regular expression.
  733. #
  734. #  c        An ordinary character (not one of the special characters
  735. #        discussed below) is a one-character RE that matches that
  736. #        character.
  737. #
  738. #  \c        A backslash followed by any special character is a one-
  739. #        character RE that matches the special character itself.
  740. #
  741. #        Note that backslash escape sequences representing
  742. #        non-graphic characters are not supported directly
  743. #        by these procedures.  Of course, strings coded in an
  744. #        Icon program will have such escapes handled by the
  745. #        Icon translator.  If such escapes must be supported
  746. #        in strings read from the run-time environment (e.g.
  747. #        files), they will have to be converted by other means,
  748. #        such as the Icon Program Library procedure "escape()".
  749. #
  750. #  .        A period is a one-character RE that # matches any
  751. #        character.
  752. #
  753. #  [string]    A non-empty string enclosed in square brackets is a one-
  754. #        character RE that matches any *one* character of that
  755. #        string.  If, the first character is "^" (circumflex),
  756. #        the RE matches any character not in the remaining
  757. #        characters of the string.  The "-" (minus), when between
  758. #        two other characters, may be used to indicate a range of
  759. #        consecutive ASCII characters (e.g. [0-9] is equivalent to
  760. #        [0123456789]).  Other special characters stand for
  761. #        themselves in a bracketed string.
  762. #
  763. #  *        Matches zero or more occurrences of the RE to its left.
  764. #
  765. #  +        Matches one or more occurrences of the RE to its left.
  766. #
  767. #  ?        Matches zero or one occurrences of the RE to its left.
  768. #
  769. #  {N}        Matches exactly N occurrences of the RE to its left.
  770. #
  771. #  {N,}        Matches at least N occurrences of the RE to its left.
  772. #
  773. #  {N,M}    Matches at least N occurrences but at most M occurrences
  774. #        of the RE to its left.
  775. #
  776. #  ^        A caret at the beginning of an entire RE constrains
  777. #        that RE to match an initial substring of the subject
  778. #        string.
  779. #
  780. #  $        A currency symbol at the end of an entire RE constrains
  781. #        that RE to match a final substring of the subject string.
  782. #
  783. #  |        Alternation: two REs separated by "|" match either a
  784. #        match for the first or a match for the second.
  785. #
  786. #  ()        A RE enclosed in parentheses matches a match for the
  787. #        regular expression (parenthesized groups are used
  788. #        for grouping, and for accessing the matched string
  789. #        subsequently in the match using the \N expression).
  790. #
  791. #  \N        Where N is a digit in the range 1-9, matches the same
  792. #        string of characters as was matched by a parenthesized
  793. #        RE to the left in the same RE.  The sub-expression
  794. #        specified is that beginning with the Nth occurrence
  795. #        of "(" counting from the left.  E.g., ^(.*)\1$ matches
  796. #        a string consisting of two consecutive occurrences of
  797. #        the same string.
  798. #
  799. #  Perl Extensions
  800. #
  801. #  The following extensions to UNIX REs, as specified in the Perl
  802. #  programming language, are supported.
  803. #
  804. #  \w        Matches any alphanumeric (including "_").
  805. #  \W        Matches any non-alphanumeric.
  806. #
  807. #  \b        Matches only at a word-boundary (word defined as a string
  808. #        of alphanumerics as in \w).
  809. #  \B        Matches only non-word-boundaries.
  810. #
  811. #  \s        Matches any white-space character.
  812. #  \S        Matches any non-white-space character.
  813. #
  814. #  \d        Matches any digit [0-9].
  815. #  \D        Matches any non-digit.
  816. #
  817. #  \w, \W, \s, \S, \d, \D can be used within [string] REs.
  818. #
  819. #
  820. #  Note on Details of Matching
  821. #
  822. #  The method of matching differs a bit from UNIX-style regular
  823. #  expressions -- particularly where closures are concerned ("*", "+",
  824. #  "{}", "?").  UNIX regular expressions are documented to match the
  825. #  "longest, leftmost" strings in cases where a choice is needed.  The
  826. #  procedures in this file are capable of generating all possible
  827. #  matches of the pattern, and generate the possibilities by matching
  828. #  the fewest first ("shortest, leftmost").  Matching of the various
  829. #  pattern elements is performed exactly as though it were an Icon
  830. #  conjunction of the elements.
  831. #
  832. #
  833. #  Notes on computed conjunction expressions by "suspensive recursion"
  834. #
  835. #  A conjunction expression of an arbitrary number of terms can be
  836. #  computed in a looping fashion by the following recursive technique:
  837. #
  838. #    procedure Conjunct(v)
  839. #       if <there is another term to be appended to the conjunction> then
  840. #          suspend Conjunct(<the next term expression>)
  841. #       else
  842. #          suspend v
  843. #    end
  844. #
  845. #  The argument "v" is needed for producing the value of the last term
  846. #  as the value of the conjunction expression, accurately modeling Icon
  847. #  conjunction.  If the value of the conjunction is not needed, the
  848. #  technique can be slightly simplified by eliminating "v":
  849. #
  850. #    procedure ConjunctAndProduceNull()
  851. #       if <there is another term to be appended to the conjunction> then
  852. #          suspend ConjunctAndProduceNull(<the next term expression>)
  853. #       else
  854. #          suspend
  855. #    end
  856. #
  857. #  Note that <the next term expression> must still remain in the suspend
  858. #  expression to test for failure of the term, although its value is not
  859. #  passed to the recursive invocation,  This could have been coded as
  860. #
  861. #          suspend <the next term expression> & ConjunctAndProduceNull()
  862. #
  863. #  but wouldn't have been as provocative.
  864. #
  865. #  Since the computed conjunctions in this program are evaluated only for
  866. #  their side effects, the second technique is used in two situations:
  867. #
  868. #    (1)    To compute the conjunction of all of the elements in the
  869. #        regular expression pattern list (Re_match1()).
  870. #
  871. #    (2)    To evaluate the "exactly N times" and "N to M times"
  872. #        control operations (Re_NTimes()).
  873. #
  874.  
  875.  
  876. record Re_Tok(proc,args)
  877.  
  878. global Re_ParenGroups,Re_Filter,Re_Ordered
  879. global Re_WordChars,Re_NonWordChars
  880. global Re_Space,Re_NonSpace
  881. global Re_Digits,Re_NonDigits
  882. global Re_ArbString,Re_AnyString
  883. global Re_TabMatch
  884.  
  885.  
  886. ###################  Pattern Translation Procedures  ###################
  887.  
  888.  
  889. procedure RePat(s) # L
  890. #
  891. #  Produce pattern list representing pattern string s.
  892. #
  893.    #
  894.    #  Create a list of pattern elements.  Pattern strings are parsed
  895.    #  and converted into list elements as shown in the following table.
  896.    #  Since some list elements reference other pattern lists, the
  897.    #  structure is really a tree.
  898.    #
  899.    # Token    Generates            Matches...
  900.    # -----    ---------            ----------
  901.    #  ^        Re_Tok(pos,[1])            Start of string or line
  902.    #  $        Re_Tok(pos,[0])            End of string or line
  903.    #  .        Re_Tok(move,[1])        Any single character
  904.    #  +        Re_Tok(Re_OneOrMore,[tok])    At least one occurrence of
  905.    #                        previous token
  906.    #  *        Re_Tok(Re_ArbNo,[tok])        Zero or more occurrences of
  907.    #                        previous token
  908.    #  |        Re_Tok(Re_Alt,[pattern,pattern]) Either of prior expression
  909.    #                        or next expression
  910.    #  [...]    Re_Tok(Re_TabAny,[cset])    Any single character in
  911.    #                        specified set (see below)
  912.    #  (...)    Re_Tok(Re_MatchReg,[pattern])    Parenthesized pattern as
  913.    #                        single token
  914.    #  <string of non-special characters>    The string of no-special
  915.    #        Re_Tok(Re+TabMatch,string)      characters
  916.    #  \b    Re_Tok(Re_WordBoundary,[Re_WordChars,Re_NonWordChars])
  917.    #                        A word-boundary
  918.    #                          (word default: [A-Za-z0-9_]+)
  919.    #  \B    Re_Tok(Re_NonWordBoundary,[Re_WordChars,Re_NonWordChars])
  920.    #                        A non-word-boundary
  921.    #  \w    Re_Tok(Re_TabAny,[Re_WordChars])A word-character
  922.    #  \W    Re_Tok(Re_TabAny,[Re_NonWordChars]) A non-word-character
  923.    #  \s    Re_Tok(Re_TabAny,[Re_Space])    A space-character
  924.    #  \S    Re_Tok(Re_TabAny,[Re_NonSpace])    A non-space-character
  925.    #  \d    Re_Tok(Re_TabAny,[Re_Digits])    A digit
  926.    #  \D    Re_Tok(Re_TabAny,[Re_NonDigits]) A non-digit
  927.    #  {n,m}    Re_Tok(Re_NToMTimes,[tok,n,m])    n to m occurrences of
  928.    #                        previous token
  929.    #  {n,}    Re_Tok(Re_NOrMoreTimes,[tok,n])    n or more occurrences of
  930.    #                        previous token
  931.    #  {n}    Re_Tok(Re_NTimes,[tok,n])    exactly n occurrences of
  932.    #                        previous token
  933.    #  ?        Re_Tok(Re_ZeroOrOneTimes,[tok])    one or zero occurrences of
  934.    #                        previous token
  935.    #  \<digit>    Re_Tok(Re_MatchParenGroup,[n])    The string matched by
  936.    #                        parenthesis group <digit>
  937.    #
  938.    local plist,starter,ender
  939.    #
  940.    #  Initialize.
  941.    #
  942.    initial Re_Default()
  943.    Re_WordChars := cset(Re_WordChars)
  944.    Re_NonWordChars := ~Re_WordChars
  945.    Re_Space := cset(Re_Space)
  946.    Re_NonSpace := ~Re_Space
  947.    Re_Digits := cset(Re_Digits)
  948.    Re_NonDigits := ~Re_Digits
  949.    #
  950.    #  Deal with ^ and $, which can only appear at the beginning and end,
  951.    #  respectively, of a whole RE.
  952.    #
  953.    if s[1] == "^" then {
  954.       starter := Re_Tok(pos,[1])
  955.       s[1] := ""
  956.       }
  957.    if s[-1] == "$" then {
  958.       ender := Re_Tok(pos,[0])
  959.       s[-1] := ""
  960.       }
  961.    s ? (plist :=  Re_pat1(0)) | fail
  962.    push(plist,\starter)
  963.    put(plist,\ender)
  964.    return plist
  965. end
  966.  
  967.  
  968. procedure Re_pat1(level) # L
  969. #
  970. #  Recursive portion of RePat()
  971. #
  972.    local plist,n,m,x,comma
  973.    static none,parenNbr
  974.    initial {
  975.       Re_TabMatch := proc("=",1)
  976.       none := []
  977.       }
  978.    if level = 0 then parenNbr := 0
  979.    plist := []
  980.    #
  981.    #  Loop to put pattern elements on list.
  982.    #
  983.    until pos(0) do {
  984.       (="|",plist := [Re_Tok(Re_Alt,[plist,Re_pat1(level + 1) | fail])]) |
  985.       put(plist,
  986.      (match(")"),level > 0,break) |
  987.      (=Re_ArbString,Re_Tok(Re_Arb,none)) |
  988.      (=Re_AnyString,Re_Tok(move,[1])) |
  989.      (="+",Re_Tok(Re_OneOrMore,[pull(plist) | fail])) |
  990.      (="*",Re_Tok(Re_ArbNo,[pull(plist) | fail])) |
  991.      Re_Tok(Re_TabAny,[Re_cset()]) |
  992.      3(="(",n := parenNbr +:= 1,
  993.            Re_Tok(Re_MatchReg,[Re_pat1(level + 1) | fail,n]),
  994.            move(1) | fail) |
  995.      (="\\b",Re_Tok(Re_WordBoundary,[Re_WordChars,Re_NonWordChars])) |
  996.      (="\\B",Re_Tok(Re_NonWordBoundary,[Re_WordChars,Re_NonWordChars])) |
  997.      (="\\w",Re_Tok(Re_TabAny,[Re_WordChars])) |
  998.      (="\\W",Re_Tok(Re_TabAny,[Re_NonWordChars])) |
  999.      (="\\s",Re_Tok(Re_TabAny,[Re_Space])) |
  1000.      (="\\S",Re_Tok(Re_TabAny,[Re_NonSpace])) |
  1001.      (="\\d",Re_Tok(Re_TabAny,[Re_Digits])) |
  1002.      (="\\D",Re_Tok(Re_TabAny,[Re_NonDigits])) |
  1003.      (="{",(n := tab(many(&digits)),comma := =(",") | &null,
  1004.         m := tab(many(&digits)) | &null,="}") | fail,
  1005.         if \m then Re_Tok(Re_NToMTimes,
  1006.           [pull(plist),integer(n),integer(m)])
  1007.         else if \comma then Re_Tok(Re_NOrMoreTimes,
  1008.           [pull(plist),integer(n)])
  1009.         else Re_Tok(Re_NTimes,[pull(plist),integer(n)])) |
  1010.      (="?",Re_Tok(Re_ZeroOrOneTimes,[pull(plist) | fail])) |
  1011.      Re_Tok(Re_TabMatch,[Re_string(level)]) |
  1012.      (="\\",n := tab(any(&digits)),Re_Tok(Re_MatchParenGroup,[integer(n)]))
  1013.      ) |
  1014.       fail
  1015.       }
  1016.    return plist
  1017. end
  1018.  
  1019.  
  1020. procedure Re_Default()
  1021. #
  1022. #  Assign default values to regular expression translation globals, but
  1023. #  only to variables whose values are null.
  1024. #
  1025.    /Re_WordChars := &letters ++ &digits ++ "_"
  1026.    /Re_Space := ' \t\v\n\r\f'
  1027.    /Re_Digits := &digits
  1028.    /Re_ArbString := ".*"
  1029.    /Re_AnyString := "."
  1030.    return
  1031. end
  1032.  
  1033.  
  1034. procedure Re_cset()
  1035. #
  1036. #  Matches a [...] construct and returns a cset.
  1037. #
  1038.    local complement,c,e,ch,chars
  1039.    (="[",complement := ="^" | &null,
  1040.      c := (ch := (="-" | "")) || move(1) || tab(find("]")),move(1)) |
  1041.      fail
  1042.    c ? {
  1043.       e := ch
  1044.       while chars := tab(upto('-\\')) do {
  1045.      e ++:= case move(1) of {
  1046.         "-": chars[1:-1] ++
  1047.           &cset[ord(chars[-1]) + 1:ord(move(1)) + 2] | "-"
  1048.         "\\": case ch := move(1) of {
  1049.            "w": Re_WordChars
  1050.            "W": Re_NonWordChars
  1051.            "s": Re_Space
  1052.            "S": Re_NonSpace
  1053.            "d": Re_Digits
  1054.            "D": Re_NonDigits
  1055.            default: ch
  1056.            }
  1057.         }
  1058.      }
  1059.       e ++:= tab(0)
  1060.       if \complement then e := ~e
  1061.       }
  1062.    e := (\Re_Filter)(e)
  1063.    return cset(e)
  1064. end
  1065.  
  1066.  
  1067. procedure Re_string(level)
  1068. #
  1069. #  Matches a string of non-special characters, returning a string.
  1070. #
  1071.    local special,s,p,c
  1072.    static nondigits
  1073.    initial nondigits := ~&digits
  1074.    special := if level = 0 then '\\.+*|[({?' else  '\\.+*|[({?)'
  1075.    s := tab(upto(special) | 0)
  1076.    while ="\\" do {
  1077.       p := &pos
  1078.       if tab(any('wWbBsSdD')) |
  1079.         (tab(any('123456789')) & (pos(0) | any(nondigits))) then {
  1080.      tab(p - 1)
  1081.      break
  1082.      }
  1083.       s ||:= c || tab(upto(special))
  1084.       }
  1085.    s := string((\Re_Filter)(s))
  1086.    return "" ~== s
  1087. end
  1088.  
  1089.  
  1090. #####################  Matching Engine Procedures  ########################
  1091.  
  1092.  
  1093. procedure ReMatch(plist,s,i1,i2) # i3,i4,...,iN
  1094. #
  1095. #  Produce the sequence of positions in s past a string starting at i1
  1096. #  that matches the pattern plist, but fails if there is no such
  1097. #  position.  Similar to match(), but is capable of generating multiple
  1098. #  positions.
  1099. #
  1100.    if type(plist) ~== "list" then plist := RePat(plist) | fail
  1101.    /i1:= if /s := &subject then &pos else 1 ; /i2 := 0
  1102.    Re_ParenGroups := []
  1103.    suspend s[i1:i2] ? (Re_match1(plist,1),i1 + &pos - 1)
  1104. end
  1105.  
  1106.  
  1107. procedure Re_match1(plist,i) # s1,s2,...,sN
  1108. #
  1109. #  Used privately by ReMatch() to simulate a computed conjunction
  1110. #  expression via recursive generation.
  1111. #
  1112.    local tok
  1113.    suspend if tok := plist[i] then
  1114.       Re_tok_match(tok,plist,i) & Re_match1(plist,i + 1) else &null
  1115. end
  1116.  
  1117.  
  1118. procedure ReFind(plist,s,i1,i2) # i3,i4,...,iN
  1119. #
  1120. #  Produce the sequence of positions in s where strings begin that match
  1121. #  the pattern plist, but fails if there is no such position.  Similar
  1122. #  to find().
  1123. #
  1124.    local p
  1125.    if type(plist) ~== "list" then plist := RePat(plist) | fail
  1126.    /i1 := if /s := &subject then &pos else 1 ; /i2 := 0
  1127.    s[i1:i2] ? suspend (
  1128.      tab(Re_skip(plist,1)) &
  1129.      p := &pos &
  1130.      Re_match1(plist,1)\1 &
  1131.      i1 + p - 1)
  1132. end
  1133.  
  1134.  
  1135. procedure Re_tok_match(tok,plist,i)
  1136. #
  1137. #  Match a single token.  Can be recursively called by the token
  1138. #  procedure.
  1139. #
  1140.    local prc
  1141.    prc := tok.proc
  1142.    suspend (
  1143.       if prc === Re_Arb then Re_Arb(plist,i)
  1144.       else suspend prc!tok.args
  1145.       )
  1146. end
  1147.  
  1148.  
  1149. ##########  Heuristic Code for Matching Arbitrary Characters  ##########
  1150.  
  1151.  
  1152. procedure Re_skip(plist,i) # s1,s2,...,sN
  1153. #
  1154. #  Used privately -- match a sequence of strings in s past which a match
  1155. #  of the first pattern element in plist is likely to succeed.  This
  1156. #  procedure is used for heuristic performance improvement by ReMatch()
  1157. #  for the ".*" pattern element, and by ReFind().
  1158. #
  1159.    local x,s,p,prc
  1160.    x := plist[i]
  1161.    suspend case prc := (\x).proc | &null of {
  1162.       Re_TabMatch: find!x.args
  1163.       Re_TabAny: upto!x.args
  1164.       pos: x.args[1]
  1165.       ## Re_WordBoundary: Re_WordBoundaries!x.args
  1166.       Re_WordBoundary |
  1167.       Re_NonWordBoundary:
  1168.         p := &pos & tab(Re_skip(plist,i + 1)) & prc!x.args & untab(p)
  1169.       Re_OneOrMore |
  1170.       Re_MatchParenGroup: if s := (\Re_ParenGroups)[x.args[1]] then
  1171.         find(s) else &pos to *&subject + 1
  1172.       Re_NToMTimes |
  1173.       Re_NOrMoreTimes |
  1174.       Re_NTimes:
  1175.         if x.args[2] > 0 then Re_skip(x.args[1],1) else &pos to &subject + 1
  1176.       Re_MatchReg: Re_skip(x.args[1],1)
  1177.       Re_Alt:
  1178.         if \Re_Ordered then
  1179.           Re_result_merge{Re_skip(x.args[1],1),Re_skip(x.args[2],1)}
  1180.         else
  1181.           Re_skip(x.args[1 | 2],1)
  1182.       default: &pos to *&subject + 1
  1183.       }
  1184. end
  1185.  
  1186.  
  1187. procedure Re_result_merge(L)
  1188. #
  1189. #  Programmer-defined control operation to merge the result sequences of
  1190. #  two integer-producing generators.  Both generators must produce their
  1191. #  result sequences in numerically increasing order with no duplicates,
  1192. #  and the output sequence will be in increasing order with no
  1193. #  duplicates.
  1194. #
  1195.    local e1,e2,r1,r2
  1196.    e1 := L[1] ; e2 := L[2]
  1197.    r1 := @e1 ; r2 := @e2
  1198.    while \(r1 | r2) do
  1199.      if /r2 | \r1 < r2 then
  1200.            suspend r1 do r1 := @e1 | &null
  1201.      else if /r1 | r1 > r2 then
  1202.            suspend r2 do r2 := @e2 | &null
  1203.      else
  1204.            r2 := @e2 | &null
  1205. end
  1206.  
  1207.  
  1208. procedure untab(origPos)
  1209. #
  1210. #  Converts a string scanning expression that moves the cursor to one
  1211. #  that produces a cursor position and doesn't move the cursor (converts
  1212. #  something like tab(find(x)) to find(x).  The template for using this
  1213. #  procedure is
  1214. #
  1215. #    origPos := &pos ; tab(x) & ... & untab(origPos)
  1216. #
  1217.    local newPos
  1218.    newPos := &pos
  1219.    tab(origPos)
  1220.    suspend newPos
  1221.    tab(newPos)
  1222. end
  1223.  
  1224.  
  1225. ## procedure Re_WordBoundaries(wd)
  1226. ## #
  1227. ## #  Produce positions that are word boundaries.
  1228. ## #
  1229.    ## local p,q
  1230.    ## p1 := p := &pos
  1231.    ## while q := upto(wd,,p) | break do {
  1232.       ## suspend q
  1233.       ## p := many(wd,,q)
  1234.       ## suspend p
  1235.       ## }
  1236.    ## tab(p1)
  1237. ## end
  1238.  
  1239.  
  1240. #######################  Matching Procedures #######################
  1241.  
  1242.  
  1243. procedure Re_Arb(plist,i)
  1244. #
  1245. #  Match arbitrary characters (.*)
  1246. #
  1247.    suspend tab(if \plist then Re_skip(plist,i + 1) else 1 to *&subject + 1)
  1248. end
  1249.  
  1250.  
  1251. procedure Re_TabAny(C)
  1252. #
  1253. #  Match a character of a character set ([...],\w,\W,\s,\S,\d,\D
  1254. #)
  1255.    suspend tab(any(C))
  1256. end
  1257.  
  1258.  
  1259. procedure Re_MatchReg(tokList,groupNbr)
  1260. #
  1261. #  Match parenthesized group and assign matched string to list Re_ParenGroup
  1262. #
  1263.    local p,s
  1264.    p := &pos
  1265.    every Re_match1(tokList,1) do {
  1266.       /Re_ParenGroups := []
  1267.       while *Re_ParenGroups < groupNbr do put(Re_ParenGroups)
  1268.       s := &subject[p:&pos]
  1269.       Re_ParenGroups[groupNbr] := s
  1270.       suspend s
  1271.       }
  1272.    Re_ParenGroups[groupNbr] := &null
  1273. end
  1274.  
  1275.  
  1276. procedure Re_WordBoundary(wd,nonwd)
  1277. #
  1278. #  Match word-boundary (\b)
  1279. #
  1280.    suspend ((pos(1),any(wd)) | (pos(0),move(-1),tab(any(wd))) | (move(-1),
  1281.          (tab(any(wd)),any(nonwd)) | (tab(any(nonwd)),any(wd))),"")
  1282. end
  1283.  
  1284.  
  1285. procedure Re_NonWordBoundary(wd,nonwd)
  1286. #
  1287. #  Match non-word-boundary (\B)
  1288. #
  1289.    suspend ((pos(1),any(nonwd)) | (pos(0),move(-1),tab(any(nonwd))) | (move(-1),
  1290.          (tab(any(wd)),any(wd)) | (tab(any(nonwd)),any(nonwd)),""))
  1291. end
  1292.  
  1293.  
  1294. procedure Re_MatchParenGroup(n)
  1295. #
  1296. #  Match same string matched by previous parenthesized group (\N)
  1297. #
  1298.    suspend if s := \Re_ParenGroups[n] then =s else ""
  1299. end
  1300.  
  1301.  
  1302. ###################  Control Operation Procedures  ###################
  1303.  
  1304.  
  1305. procedure Re_ArbNo(tok)
  1306. #
  1307. #  Match any number of times (*)
  1308. #
  1309.    suspend "" | (Re_tok_match(tok) & Re_ArbNo(tok))
  1310. end
  1311.  
  1312.  
  1313. procedure Re_OneOrMore(tok)
  1314. #
  1315. #  Match one or more times (+)
  1316. #
  1317.    suspend Re_tok_match(tok) & Re_ArbNo(tok)
  1318. end
  1319.  
  1320.  
  1321. procedure Re_NToMTimes(tok,n,m)
  1322. #
  1323. #  Match n to m times ({n,m}
  1324. #
  1325.    suspend Re_NTimes(tok,n) & Re_ArbNo(tok)\(m - n + 1)
  1326. end
  1327.  
  1328.  
  1329. procedure Re_NOrMoreTimes(tok,n)
  1330. #
  1331. #  Match n or more times ({n,})
  1332. #
  1333.    suspend Re_NTimes(tok,n) & Re_ArbNo(tok)
  1334. end
  1335.  
  1336.  
  1337. procedure Re_NTimes(tok,n)
  1338. #
  1339. #  Match exactly n times ({n})
  1340. #
  1341.    if n > 0 then
  1342.       suspend Re_tok_match(tok) & Re_NTimes(tok,n - 1)
  1343.    else suspend
  1344. end
  1345.  
  1346.  
  1347. procedure Re_ZeroOrOneTimes(tok)
  1348. #
  1349. #  Match zero or one times (?)
  1350. #
  1351.    suspend "" | Re_tok_match(tok)
  1352. end
  1353.  
  1354.  
  1355. procedure Re_Alt(tokList1,tokList2)
  1356. #
  1357. #  Alternation (|)
  1358. #
  1359.    suspend Re_match1(tokList1 | tokList2,1)
  1360. end
  1361.  
  1362. --------------------------  igrep.icn  ----------------------------
  1363.  
  1364. #
  1365. #  Program to emulate UNIX egrep, but using the enhanced regular
  1366. #  expressions supported by regexp.icn.  Options supported are nearly
  1367. #  identical to those supported by egrep (no -b:  print disk block
  1368. #  number).  There is one additional option, -E, to allow Icon-type
  1369. #  (hence C-type) string escape sequences in the pattern string.
  1370. #  BEWARE:  when -E is used, backslashes that are meant to be processed
  1371. #  in the regular expression context must be doubled.  The following
  1372. #  patterns are equivalent:
  1373. #
  1374. #    without -E:    '\bFred\b'
  1375. #    with    -E:    '\\bFred\\b'
  1376. #
  1377.  
  1378. procedure Usage(n)
  1379.    write(&errout,
  1380.       "igrep -- emulates UNIX egrep\n_
  1381.       Usage: igrep -Options [expression] filename..._
  1382.     \n    Options:_
  1383.     \n    c    print count of matching lines rather than actual lines_
  1384.     \n    h    don't display file names_
  1385.     \n    i    ignore case of letters_
  1386.     \n    l    list only the names of files containing matching lines_
  1387.     \n    n    precede lines with line numbers_
  1388.     \n    s    work silently -- display nothing_
  1389.     \n    v    invert search to display only lines that don't match_
  1390.     \n    e expr    useful if expressions starts with -_
  1391.     \n    E expr    expresson containing Icon escape sequences_
  1392.     \n    f file    take list of alternated expressions from \"file\"")
  1393.    exit(n)
  1394. end
  1395.  
  1396. link options,regexp
  1397.  
  1398. procedure main(arg)
  1399.    if *arg = 0 then Usage()
  1400.    Options(arg)
  1401.    compiledPattern := GetPattern(arg) |
  1402.          {write(&errout,"Bad pattern ",image(Pattern)) ; exit(2)}
  1403.    exit(ScanFiles(arg,compiledPattern))
  1404. end
  1405.  
  1406. global CountOnly,NoNames,NamesOnly,NumberLines,Out,Invert,Escapes,
  1407.       Pattern,PatternFile
  1408.  
  1409. procedure Options(arg)
  1410.    opt := options(arg,"chilnsve:E:f:")
  1411.    CountOnly := opt["c"]
  1412.    NoNames := opt["h"]
  1413.    if \opt["i"] then Re_Filter := map
  1414.    NamesOnly := opt["l"]
  1415.    NumberLines := opt["n"]
  1416.    Out := if \opt["s"] then &null else &output
  1417.    Invert := opt["v"]
  1418.    Pattern := \opt["e" | "E"]
  1419.    Escapes := opt["E"]
  1420.    PatternFile := opt["f"]
  1421.    return opt
  1422. end
  1423.  
  1424. procedure GetPattern(arg)
  1425.    if \PatternFile then {
  1426.       f := open(PatternFile) |
  1427.         stop("Can't open pattern file \"",PatternFile,"\"")
  1428.       (/Pattern := "" & sep := "") | (sep := "|")
  1429.       while Pattern ||:= sep || read(f) do sep := "|"
  1430.       close(f)
  1431.       }
  1432.    /Pattern := get(arg)
  1433.    if /Pattern then Usage(2)
  1434.    return RePat(if \Escapes then istring(Pattern) else Pattern)
  1435. end
  1436.  
  1437. procedure ScanFiles(arg,pattern)
  1438.    local errors
  1439.    totalCount := 0
  1440.    if *arg = 0 then arg := ["-"]
  1441.    every fn := !arg do {
  1442.       f := if fn == "-" then &input else open(fn) |
  1443.             {write(&errout,"Can't open \"",fn,"\" -- skipped") ; errors := 2 ;
  1444.         next}
  1445.       header := if \NoNames | *arg = 1 then &null else fn || ":"
  1446.       lineNbr := count := 0
  1447.       while line := read(f) do {
  1448.          lineNbr +:= 1
  1449.          line := (\Re_Filter)(line)
  1450.          status := ReFind(pattern,line) | &null
  1451.      status := if \Invert then (\status,&null) | 1
  1452.          if \status then {
  1453.         count +:= 1
  1454.         if count = 1 & \NamesOnly then {write(\Out,fn) ; next}
  1455.         lineNbrTag := if \NumberLines then lineNbr || ":" else &null
  1456.         if not \(CountOnly | NamesOnly) then
  1457.           write(\Out,header,lineNbrTag,line)
  1458.         }
  1459.          }
  1460.       close(f)
  1461.       if \CountOnly then write(header,count)
  1462.       totalCount +:= count
  1463.       }
  1464.    ## if \CountOnly & *arg > 1 then write(\Out,"** Total ** ",totalCount)
  1465.    return \errors | if totalCount = 0 then 1 else 0
  1466. end
  1467.  
  1468. #
  1469. #  istring() -- Procedure to convert a string containing special escape
  1470. #  constructs, of the same format as Icon source language character
  1471. #  strings, to their true string representation.  Value returned is the
  1472. #  string with special constructs converted to their respective
  1473. #  characters.
  1474. #
  1475.  
  1476. procedure istring(s)
  1477.   local r,c
  1478.   r := ""
  1479.   s ? {
  1480.     while r ||:= tab(upto('\\')) do {
  1481.       move(1)
  1482.       r ||:= case c := map(move(1)) of {
  1483.     "b": "\b"        # backspace
  1484.     "d": "\d"        # delete (rubout)
  1485.     "e": "\e"        # escape (altmode)
  1486.     "f": "\f"        # formfeed
  1487.     "l": "\l"        # linefeed (newline)
  1488.     "n": "\n"        # newline (linefeed)
  1489.     "r": "\r"        # carriage return
  1490.     "t": "\t"        # horizontal tab
  1491.     "v": "\v"        # vertical tab
  1492.     "x": istring_radix(16,2)# hexadecimal code
  1493.     "^": char(ord(move(1)) % 32) | break # control code
  1494.     default: {        # either octal code or non-escaped character
  1495.       if any('01234567',c) then {    # if octal digit
  1496.         move(-1)
  1497.         istring_radix(8,3)
  1498.       }
  1499.       else c            # else non-escaped character
  1500.     } | break
  1501.       }
  1502.     }
  1503.     r ||:= tab(0)
  1504.   }
  1505.   return r
  1506. end
  1507.  
  1508. procedure istring_radix(r,max)
  1509.   local n,d,i,c
  1510.   d := "0123456789abcdef"[1:r + 1]
  1511.   n := 0
  1512.   every 1 to max do {
  1513.     c := move(1) | break
  1514.     if not (i := find(map(c),d) - 1) then {
  1515.       move(-1)
  1516.       break
  1517.     }
  1518.     n := n * r + i
  1519.   }
  1520.   return char(n)
  1521. end
  1522.  
  1523. From L.Lu@computer-science.birmingham.ac.uk  Sat Nov  2 08:34:07 1991
  1524. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Sat, 2 Nov 91 08:34:07 MST
  1525. Resent-From: L.Lu@computer-science.birmingham.ac.uk
  1526. Received: from Arizona.edu (Hopey.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  1527.     id AA23384; Sat, 2 Nov 91 06:29:51 MST
  1528. Received: from sun2.nsfnet-relay.ac.uk by Arizona.edu with PMDF#10282; Sat, 2
  1529.  Nov 1991 06:29 MST
  1530. Received: from computer-science.birmingham.ac.uk by sun2.nsfnet-relay.ac.uk via
  1531.  JANET with NIFTP id <3189-0@sun2.nsfnet-relay.ac.uk>; Sat, 2 Nov 1991 12:29:57
  1532.  +0000
  1533. Received: from christopher by new-percy.cs.bham.ac.uk with SMTP (PP) id
  1534.  <2742-0@new-percy.cs.bham.ac.uk>; Sat, 2 Nov 1991 12:29:58 +0000
  1535. Received: from eeyore by christopher-robin.cs.bham.ac.uk (4.1/fileserver/1.2)
  1536.  id AA06638; Sat, 2 Nov 91 12:31:16 GMT
  1537. Resent-Date: Sat, 2 Nov 1991 06:29 MST
  1538. Date: Sat, 02 Nov 91 12:31:24 GMT
  1539. From: L.Lu@computer-science.birmingham.ac.uk
  1540. Resent-To: icon-group@cs.arizona.edu
  1541. To: icon-group@arizona.edu, L.Lu@computer-science.birmingham.ac.uk
  1542. Resent-Message-Id: <65FC4F7D08206D36@Arizona.edu>
  1543. Message-Id: <6638.9111021231@christopher-robin.cs.bham.ac.uk>
  1544. X-Envelope-To: icon-group@CS.Arizona.EDU
  1545. X-Vms-To: icon-group@Arizona.edu, L.Lu@computer-science.birmingham.ac.uk
  1546.  
  1547. signoff Lunjin Lu
  1548.  
  1549.  
  1550. |---------------------------------------------------------------|
  1551. | Lunjin Lu                     |Email: L.Lu@cs.bham.ac.uk      |
  1552. | School of Computer Science    |Voice: +44 21-414-3736         |
  1553. | University of Birmingham      |Fax  : +44 21-414-4281         |
  1554. | Edgbaston, Birmingham B15 2TT |Telex: 333762 UOBHAM G         |
  1555. | The United Kingdom            |                               |
  1556. |---------------------------------------------------------------|
  1557.  
  1558. From L.Lu@computer-science.birmingham.ac.uk  Sat Nov  2 08:34:09 1991
  1559. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Sat, 2 Nov 91 08:34:09 MST
  1560. Resent-From: L.Lu@computer-science.birmingham.ac.uk
  1561. Received: from Arizona.edu (Osprey.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  1562.     id AA23581; Sat, 2 Nov 91 06:40:50 MST
  1563. Received: from sun2.nsfnet-relay.ac.uk by Arizona.edu with PMDF#10282; Sat, 2
  1564.  Nov 1991 06:29 MST
  1565. Received: from computer-science.birmingham.ac.uk by sun2.nsfnet-relay.ac.uk via
  1566.  JANET with NIFTP id <3191-0@sun2.nsfnet-relay.ac.uk>; Sat, 2 Nov 1991 12:30:42
  1567.  +0000
  1568. Received: from christopher by new-percy.cs.bham.ac.uk with SMTP (PP) id
  1569.  <2753-0@new-percy.cs.bham.ac.uk>; Sat, 2 Nov 1991 12:30:44 +0000
  1570. Received: from eeyore by christopher-robin.cs.bham.ac.uk (4.1/fileserver/1.2)
  1571.  id AA06641; Sat, 2 Nov 91 12:32:02 GMT
  1572. Resent-Date: Sat, 2 Nov 1991 06:29 MST
  1573. Date: Sat, 02 Nov 91 12:32:11 GMT
  1574. From: L.Lu@computer-science.birmingham.ac.uk
  1575. Resent-To: icon-group@cs.arizona.edu
  1576. To: icon-group@arizona.edu, L.Lu@computer-science.birmingham.ac.uk
  1577. Resent-Message-Id: <6600ED4818805E14@Arizona.edu>
  1578. Message-Id: <6641.9111021232@christopher-robin.cs.bham.ac.uk>
  1579. X-Envelope-To: icon-group@CS.Arizona.EDU
  1580. X-Vms-To: icon-group@Arizona.edu, L.Lu@computer-science.birmingham.ac.uk
  1581.  
  1582. unsubscribe Lunjin Lu
  1583.  
  1584. |---------------------------------------------------------------|
  1585. | Lunjin Lu                     |Email: L.Lu@cs.bham.ac.uk      |
  1586. | School of Computer Science    |Voice: +44 21-414-3736         |
  1587. | University of Birmingham      |Fax  : +44 21-414-4281         |
  1588. | Edgbaston, Birmingham B15 2TT |Telex: 333762 UOBHAM G         |
  1589. | The United Kingdom            |                               |
  1590. |---------------------------------------------------------------|
  1591.  
  1592. From icon-group-request@arizona.edu  Sat Nov  2 10:53:30 1991
  1593. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Sat, 2 Nov 91 10:53:30 MST
  1594. Resent-From: icon-group-request@arizona.edu
  1595. Received: from Arizona.edu (Hopey.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  1596.     id AA05893; Sat, 2 Nov 91 10:53:29 MST
  1597. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Sat, 2 Nov
  1598.  1991 10:52 MST
  1599. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA18134; Sat, 2 Nov 91 09:44:38
  1600.  -0800
  1601. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  1602.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  1603.  usenet@ucbvax.Berkeley.EDU if you have questions)
  1604. Resent-Date: Sat, 2 Nov 1991 10:53 MST
  1605. Date: 29 Oct 91 17:55:05 GMT
  1606. From: csusac!csus.edu!wupost!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!pacific.mps.ohio-state.edu!linac!midway!ellis!goer@ucdavis.ucdavis.edu
  1607.  (Richard L. Goerwitz)
  1608. Subject: RE: Icon futures ? (coroutines,patterns,etc.)
  1609. Sender: icon-group-request@arizona.edu
  1610. Resent-To: icon-group@cs.arizona.edu
  1611. To: icon-group@arizona.edu
  1612. Resent-Message-Id: <8AD24E29A8206802@Arizona.edu>
  1613. Message-Id: <1991Oct29.175505.16924@midway.uchicago.edu>
  1614. X-Envelope-To: icon-group@CS.Arizona.EDU
  1615. X-Vms-To: icon-group@Arizona.edu
  1616. Organization: University of Chicago
  1617. References: <1991Oct29.070610.12954@murdoch.acc.Virginia.EDU>
  1618.  
  1619. sdm7g@galen.med.Virginia.EDU (Steven D. Majewski) writes:
  1620.  
  1621. >I have been reading Ken Walker's paper in Computer Language (1989)
  1622. >First Class Patterns for Icon.
  1623.  
  1624. An interesting article, but probably a bad place to start if you're
  1625. just beginning Icon :-).
  1626.  
  1627. >I am just beginning to learn Icon and I've only READ a few dozen lines
  1628. >of SNOBOL code, but I must agree that although I find the Icon way of 
  1629. >doing things flexible and powerful, some of the pattern matching code
  1630. >is not as clear or obvious to the eye as, say, a BISON|YACC grammar.
  1631. >
  1632. >[ Anyone written the ICON equivalent? A table driven Icon code generator?]
  1633.  
  1634. This is on my long-term project list.  It's a subject that keeps coming up
  1635. over and over.  Basically, what people seem to want is a parser generator
  1636. that outputs Icon code.
  1637.  
  1638. In a way, it's not fair to compare YACC with Icon.  A more accurate compari-
  1639. son would be Icon vs. C on the level of string processing facilities.  To
  1640. compare YACC mixes levels.  There *is* no compiler compiler for Icon.  Al-
  1641. though Icon makes it unnecessary to use YACC-type tools in many instances,
  1642. it would still be very, very useful to have a YACC-like tool for it.  That's
  1643. an opinion I fully agree with.
  1644.  
  1645. >Sorry if all this has been hashed over and settled, but although
  1646. >Icon mathing expressions are very powerful, some things like regular
  1647. >expressions seem to be a special case in terms of the possible efficiency...
  1648. >
  1649. >Rather than the typical Unix/grep type regexp patterns, I would suggest
  1650. >a list of character-strings, csets or list of character strings.
  1651. >(I'm not sure about the best way of expressing multiple occurances.)
  1652.  
  1653. I'm in favor of splicing in a portable form of regular expressions.  What-
  1654. ever we do, it's going to represent bloat.  Right linear grammars are quite
  1655. trivial to recognize, using Icon's intrinsic facilities, so we'd just be
  1656. adding regexps as (in your words) "a special case in terms of possible
  1657. efficiency."  Given that they'd be tacked on for efficiency, I'd advocate
  1658. that they not be altered in any way.  Just use the format everyone already
  1659. knows and loves.  To extend Icon to house a new regular expression string
  1660. or other data type would (I think) be to overfeed the fat man.
  1661.  
  1662. One problem I have run into in adding regex handlers to the run-time system
  1663. is that there does not seem to be any way to keep a C structure around as
  1664. long as a generator needs it to be around, and yet make it visible to the
  1665. garbage collector.  With the SYSV regex routines there's no problem, since
  1666. they return a char pointer, and this can be stuck into an Icon string (in
  1667. the underlying implementation, the string descriptor is called a qualifi-
  1668. er).  The GNU Emacs and grep distributions have some nice regexp handlers,
  1669. but these utilize structures that would need to be housed in a new block
  1670. data structure in Icon in order for them to interact properly with the
  1671. system.  They also use alloca, which not everyone has, and malloc/realloc/
  1672. free, which aren't the normal way of handling Icon storage for anything
  1673. but coexpressions.
  1674.  
  1675. Put briefly:  For SYSV people, there's a simple solution to the regexp prob-
  1676. lem.  A bit of a kludge.  But it works.  For others, though, it's not as
  1677. easy as it looks.  What with all the people in the Icon Project have to do
  1678. already, we'll need to figure out some solution for ourselves.  The most we
  1679. could perhaps do is ask them to include some mechanism for making C objects
  1680. have the same lifetime and visibility as Icon arguments, so that we can use
  1681. them in creating new builtin generators.  If this isn't trivial (which I'd
  1682. guess it isn't), then some mechanism for keeping C strings and ints around
  1683. for the same purpose would be sufficient.  Ken Walker (thanks!) mentioned
  1684. to me that you can just define a function to take extra arguments, and then
  1685. use the descriptors passed in the extra arguments to house the required ob-
  1686. jects.  This seems to work fine, although it screws up the tracing and error
  1687. termination displays.
  1688.  
  1689. >Icon is a typed language without type declarations and with some limited
  1690. >automatic coercion of types. ( I hope that is an acurate statement. )
  1691.  
  1692. Close.  Icon variables are capable of being assigned any data type.  They
  1693. are not statically typed.  One might even call them untyped.  Icon values,
  1694. though, are typed.  In practice, this means you can assign a variable any
  1695. value of any type any time you want.  But the run-time system will always
  1696. know precisely what type a variable has at any given moment.  Many people
  1697. identify non-static typing with weak typing.  Clearly, though, this doesn't
  1698. describe Icon.  (Not to say you said this, but I just want to point it
  1699. out.)  Note that there are no type coercions in Icon, in the sense that I
  1700. think you mean it.  There are value conversions.  If, say, I want to write
  1701. the integer 10 to the standard output, I can say
  1702.  
  1703.     i := 10
  1704.     write(i)
  1705.  
  1706. The i is not affected by the write() function, but when it's de-referenced
  1707. the resulting descriptor is checked to see if it's a string.  If it's not,
  1708. the descriptor is actually converted to a string.  It's actually far more
  1709. flexible than a type cast for some purposes (though more constraining for
  1710. others, e.g. you have to use ord() and char() to switch from internal ints
  1711. to 1-char strings).
  1712.  
  1713. >What would be the ramifications of changing the language to a hierarchy
  1714. >of types ( a la russel, or like OO class inheritance perhaps )
  1715. >Thus csets would become, not another type, but a special case of 
  1716. >character strings. Regular expressions would be a sequence of strings,
  1717. >csets and sets of strings...  I guess that this is no longer Icon,
  1718. >but anyone have a good idea of how to put it together consistently ? 
  1719.  
  1720. It's funny, but someone I was talking to the other day said *precisely*
  1721. the same thing.  He said if Icon supported such a hierarchy, we could
  1722. just define a regular expression sub-type, and everyone would think it
  1723. was a great idea.
  1724.  
  1725. Icon is pre-OO (1976), and I can't imagine anyone at the Icon Project
  1726. would relish the though of redesigning the entire system.  Clinton Jef-
  1727. fery has designed an Icon OO preprocessor.  But I think that, in order
  1728. to do what you want, you'd need to design another language like Icon
  1729. that wasn't Icon.  (Or is this just semantics?)
  1730.  
  1731. Let me add here the usual disclaimers.  I'm not a member of the Icon Pro-
  1732. ject, and I am not in the CS field (if that isn't obvious).  The state-
  1733. ments I make I hope are accurate.  But I wouldn't give them any great
  1734. weight without hearing from people more heavily involved in Icon's in-
  1735. nards.  At best, I hope I've added to what could be an interesting ongoing
  1736. discussion.
  1737.  
  1738. -- 
  1739.  
  1740.    -Richard L. Goerwitz              goer%sophist@uchicago.bitnet
  1741.    goer@sophist.uchicago.edu         rutgers!oddjob!gide!sophist!goer
  1742.  
  1743. From icon-group-request@arizona.edu  Sat Nov  2 12:09:51 1991
  1744. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Sat, 2 Nov 91 12:09:51 MST
  1745. Resent-From: icon-group-request@arizona.edu
  1746. Received: from Arizona.edu (Hopey.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  1747.     id AA08030; Sat, 2 Nov 91 12:09:52 MST
  1748. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Sat, 2 Nov
  1749.  1991 12:09 MST
  1750. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA20415; Sat, 2 Nov 91 10:56:56
  1751.  -0800
  1752. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  1753.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  1754.  usenet@ucbvax.Berkeley.EDU if you have questions)
  1755. Resent-Date: Sat, 2 Nov 1991 12:09 MST
  1756. Date: 1 Nov 91 19:50:34 GMT
  1757. From: micro-heart-of-gold.mit.edu!wupost!uwm.edu!linac!midway!ellis!goer@bloom-beacon.mit.edu (Richard
  1758.  L. Goerwitz)
  1759. Subject: RE: Icon futures ? (coroutines,patterns,etc.)
  1760. Sender: icon-group-request@arizona.edu
  1761. Resent-To: icon-group@cs.arizona.edu
  1762. To: icon-group@arizona.edu
  1763. Resent-Message-Id: <957DD7FF3880532A@Arizona.edu>
  1764. Message-Id: <1991Nov1.195034.18246@midway.uchicago.edu>
  1765. X-Envelope-To: icon-group@CS.Arizona.EDU
  1766. X-Vms-To: icon-group@Arizona.edu
  1767. Organization: University of Chicago
  1768. References: <9111011748.AA29800@cheltenham.cs.arizona.edu>
  1769.  
  1770. cjeffery@CS.ARIZONA.EDU ("Clinton L. Jeffery") writes:
  1771.  
  1772. >"Findre" and "matchre" aren't general enough for many situations I wish
  1773. >I had regular expressions.  Richard was asking for examples.  I want
  1774. >to be able to match a regular expression while selecting some pieces of
  1775. >it that I need, and discarding others.  In order to process an Icon
  1776. >declaration, for instance, I only want the second, fifth, and sixth
  1777. >components of the following regular expression:
  1778. >
  1779. >    [ \t]* (procedure|record) [\ t]* "(" {[a-zA-Z0-9] (,[a-zA-Z0-9]*)*} ")"
  1780.  
  1781. In Icon right now, you can't select series of characters via some sort of
  1782. macro language.  You have to break down what you want into upto() and many()
  1783. or any() functions.  This is the way Icon is set up, and in some cases it
  1784. may be verbose.  If done correctly, it's also very clear and readable, not
  1785. to mention powerful.
  1786.  
  1787. My ideas of findre and matchre are pretty much analogous to upto and many.
  1788. When you tab(upto(cs)) you don't know how far tab(many(cs)) will take you
  1789. afterwards.  So you have to call both functions.  Same with findre.  You
  1790. don't know how much farther the pattern will extend after the position re-
  1791. turned by findre(), so you call matchre to find out, a la:
  1792.  
  1793.     tab(upto(cs)) & tab(many(cs))
  1794.     tab(findre(regexp)) & tab(matchre(regexp))
  1795.  
  1796. It's quite consistent and logical.  If you like a terser style, then in this
  1797. case you really *are* talking about something useful but not Iconish - some-
  1798. thing that ought to go into the IPL.  It wouldn't be that difficult to do,
  1799. really.  A split() function would be simple, and it could set global vari-
  1800. ables that would correspond to AWK or PERL-like variables.
  1801.  
  1802. My only question is whether matchre() should have a companion function that
  1803. is a generator, or if it should be a generator itself, suspending all posi-
  1804. tions from the end of the string (or j) to i which match the regexp given
  1805. as its first argument.  I'm sure if you think about it you'll see how it is
  1806. important to be able to backtrack this way.  Egrep does it deterministically
  1807. when you say "a*ab".  If you feed it "aaaaab" it won't fail, because it knows
  1808. when it finds b that it could be in one of two states.  To get this intui-
  1809. tive functionality in Icon, you'd need to make matchre a generator.
  1810.  
  1811. >Third, anyone who wants to add RE's as Icon builtins might look for a
  1812. >suitable set of public domain C functions on which to build.  I believe
  1813. >several free versions exist, such as one by Henry Spencer of the U. of
  1814. >Toronto, but I don't know which are public domain and which are "copylefted"
  1815. >and such.  But the point is that the best way to build grass-roots support
  1816. >for an extension is to produce an implementation that works on *lots* of
  1817. >(and potentially all) versions of Icon, not just certain UNIX'es.
  1818.  
  1819. Spencer's regexp library uses a (possibly terribly slow) NFA.  I'm now re-
  1820. writing the FSF's regex functions for use in Icon, and adding an experimen-
  1821. tal block type that holds the regexp pattern buffer.  I did much of the work
  1822. last night adding the new block and descriptors, and letting the memory
  1823. management system know all that it needs to know about them.  I now need to
  1824. write a regfind and regmatch function (seem like good names), and probably
  1825. also an alc-- routine for the new block, and do housekeeping like alter
  1826. fdefs.h, the function prototypes, and the makefiles.  Looks like outimage
  1827. is the only internal function I'll need to fool with, since the new block
  1828. type is not visible to the user.
  1829.  
  1830. Please let me know if I've forgotten anything.  This will take me a week or
  1831. so, because I'm working very hard on a dissertation in Near Eastern Lang-
  1832. uages, and I don't work on this sort of thing until the evenings for the
  1833. most part.
  1834.  
  1835. Just for a ruse I did try writing a builtin called refind() and one called
  1836. rematch().  These are already in my version of Icon.  They work under SYSV,
  1837. and exploit the fact that the SYSV regex routines return a character pointer
  1838. that can be stuffed into a regular Icon qualifier.  Cute, but not very gen-
  1839. eral.  Ken Walker has a copy (which has a bug in it, Ken - I add 1 to the
  1840. length in qtosij(), which isn't right).  I don't plan on using these rou-
  1841. tines, because they aren't portable.
  1842.  
  1843. I definitely think this whole thing is workable, and whether or not anyone
  1844. else goes along with me, I'm at least taking advantage of the personal in-
  1845. terpreter facilities Icon offers :-).
  1846.  
  1847. One more note:
  1848.  
  1849. >On the other hand, I
  1850. >think someone has in fact written a YACC-type program for Icon, one
  1851. >that generates Icon code.
  1852.  
  1853. This YACC is a very limited exercize, and the action fields you can spe-
  1854. cify are heavily circumscribed in what they contain.  As I recall, this
  1855. YACC does not generate an LR(k) parser, but rather a recursive descent
  1856. backtracking parser, and so loops on left-recursive grammars.  Don't quote
  1857. me on this.  It's just what I recall.
  1858.  
  1859. In order to become a production tool, we need to give Icon a flexible
  1860. parser generator.  But let's not gripe to the Icon Project :-).  Icon is
  1861. PD, and they are already overworked.  If anyone has any ideas, let's hear
  1862. them!
  1863.  
  1864.  
  1865. -- 
  1866.  
  1867.    -Richard L. Goerwitz              goer%sophist@uchicago.bitnet
  1868.    goer@sophist.uchicago.edu         rutgers!oddjob!gide!sophist!goer
  1869.  
  1870. From cjeffery  Sat Nov  2 12:52:47 1991
  1871. Date: Sat, 2 Nov 91 12:52:47 MST
  1872. From: "Clinton L. Jeffery" <cjeffery>
  1873. Message-Id: <9111021952.AA09016@cheltenham.cs.arizona.edu>
  1874. Received: by cheltenham.cs.arizona.edu; Sat, 2 Nov 91 12:52:47 MST
  1875. To: icon-group
  1876. In-Reply-To: Richard
  1877.  L. Goerwitz's message of 1 Nov 91 19:50:34 GMT <1991Nov1.195034.18246@midway.uchicago.edu>
  1878. Subject: Icon futures ? (coroutines,patterns,etc.)
  1879.  
  1880. Richard Goerwitz:
  1881. > Spencer's regexp library uses a (possibly terribly slow) NFA.  I'm now re-
  1882. > writing the FSF's regex functions for use in Icon, and adding an experimen-
  1883. > tal block type that holds the regexp pattern buffer.
  1884.  
  1885. Well, I love the FSF, but if you are hacking GNU code, we can never put it
  1886. in Icon.  GNU code is copylefted, Icon is really Public Domain.  I guess
  1887. you can come out with Gnu Icon, but I wish there were a public domain
  1888. regexp library you could use instead.  It sounds like you're really hacking
  1889. the implementation on this one!  I hope you're looking forward to doing
  1890. your changes for the Icon compiler as well...heh, heh, heh.  Wouldn't it
  1891. be nice if the compiler and the interpreter used the same runtime system?
  1892.  
  1893. From cjeffery  Sat Nov  2 14:46:18 1991
  1894. Date: Sat, 2 Nov 91 14:46:18 MST
  1895. From: "Clinton L. Jeffery" <cjeffery>
  1896. Message-Id: <9111022146.AA11560@cheltenham.cs.arizona.edu>
  1897. Received: by cheltenham.cs.arizona.edu; Sat, 2 Nov 91 14:46:18 MST
  1898. To: icon-group
  1899. In-Reply-To: Richard L. Goerwitz's message of 29 Oct 91 17:55:05 GMT <1991Oct29.175505.16924@midway.uchicago.edu>
  1900. Subject: Icon futures ? (coroutines,patterns,etc.)
  1901.  
  1902.    From: Richard L. Goerwitz
  1903.    sdm7g@galen.med.Virginia.EDU (Steven D. Majewski) writes:
  1904.    >What would be the ramifications of changing the language to a hierarchy
  1905.  
  1906.    It's funny, but someone I was talking to the other day said *precisely*
  1907.    the same thing.  He said if Icon supported such a hierarchy, we could
  1908.    just define a regular expression sub-type, and everyone would think it
  1909.    was a great idea.
  1910.  
  1911. Do you guys mean a subtype of strings (because a regular expression is a
  1912. string that denotes something else) or a subtype of sets of strings, because
  1913. regular expressions are a concise notation for regular languages?  Or both?
  1914. Hey--another application of multiple inheritance...
  1915.  
  1916.    Icon is pre-OO (1976), and I can't imagine anyone at the Icon Project
  1917.    would relish the though of redesigning the entire system.  Clinton Jef-
  1918.    fery has designed an Icon OO preprocessor.  But I think that, in order
  1919.    to do what you want, you'd need to design another language like Icon
  1920.    that wasn't Icon.  (Or is this just semantics?)
  1921.  
  1922. What you and Steve are describing certainly *isn't* Icon.  But this new
  1923. language you're talking about isn't far off, and redesigning the entire
  1924. system isn't necessary to achieve it.  While I admit that my own object
  1925. oriented language Idol is far from perfect, it is also far from finished.
  1926. The fact that it is a preprocessor and not a native translator is an
  1927. *implementation detail* ; preprocessing does not add significantly to
  1928. translation time or to execution time.  Oh, it adds a field access onto
  1929. some procedure invocations, but field access is one of Icon's faster
  1930. operations.  But, some people will never believe me, and that's OK! :-)
  1931.  
  1932. Clint
  1933.  
  1934. From icon-group-request@arizona.edu  Sun Nov  3 03:50:10 1991
  1935. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Sun, 3 Nov 91 03:50:10 MST
  1936. Resent-From: icon-group-request@arizona.edu
  1937. Received: from Arizona.edu (Hopey.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  1938.     id AA07401; Sun, 3 Nov 91 03:50:06 MST
  1939. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Sun, 3 Nov
  1940.  1991 03:49 MST
  1941. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA21711; Sun, 3 Nov 91 02:11:51
  1942.  -0800
  1943. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  1944.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  1945.  usenet@ucbvax.Berkeley.EDU if you have questions)
  1946. Resent-Date: Sun, 3 Nov 1991 03:49 MST
  1947. Date: 31 Oct 91 07:17:21 GMT
  1948. From: elroy.jpl.nasa.gov!sdd.hp.com!uakari.primate.wisc.edu!caen!uvaarpa!murdoch!galen.med.Virginia.EDU!sdm7g@ames.arc.nasa.gov (Steven D.
  1949.  Majewski)
  1950. Subject: RE: Icon futures ? (coroutines,patterns,etc.)
  1951. Sender: icon-group-request@arizona.edu
  1952. Resent-To: icon-group@cs.arizona.edu
  1953. To: icon-group@arizona.edu
  1954. Resent-Message-Id: <18D7E0C4788061AC@Arizona.edu>
  1955. Message-Id: <1991Oct31.071721.25952@murdoch.acc.Virginia.EDU>
  1956. X-Envelope-To: icon-group@CS.Arizona.EDU
  1957. X-Vms-To: icon-group@Arizona.edu
  1958. Organization: University of Virginia
  1959. References: <1991Oct29.070610.12954@murdoch.acc.Virginia.EDU>,
  1960.  <1991Oct29.175505.16924@midway.uchicago.edu>
  1961.  
  1962. In article <1991Oct29.175505.16924@midway.uchicago.edu> goer@ellis.uchicago.edu (Richard L. Goerwitz) writes:
  1963. >sdm7g@galen.med.Virginia.EDU (Steven D. Majewski) writes:
  1964. >
  1965. >>I have been reading Ken Walker's paper in Computer Language (1989)
  1966. >>First Class Patterns for Icon.
  1967. >
  1968. >An interesting article, but probably a bad place to start if you're
  1969. >just beginning Icon :-).
  1970. >
  1971.  
  1972. I like to try to combine theory & practice ( fun & work ) ! :-)
  1973.  
  1974. >
  1975. >In a way, it's not fair to compare YACC with Icon.  A more accurate compari-
  1976. >son would be Icon vs. C on the level of string processing facilities.  To
  1977. >compare YACC mixes levels.  There *is* no compiler compiler for Icon.  Al-
  1978. >though Icon makes it unnecessary to use YACC-type tools in many instances,
  1979. >it would still be very, very useful to have a YACC-like tool for it.  That's
  1980. >an opinion I fully agree with.
  1981. >
  1982.  
  1983. I'm arguring for the facility, not proposing any particular implementation.
  1984. The point Ken Walker makes in his paper is that Icon string matching, being
  1985. proceduarily embedded, are somewhat obscure. It may take time and thought to
  1986. write an unambiguous YACC grammar, but it is pretty clean looking and not to
  1987. bad to modify. A YACC in Icon that outputs Icon code would be an acceptable 
  1988. solution. Ken Walker's extension to coexpressions ( patterns as unevaluated
  1989. expressions ) is another solution that does not seem too far from the Spirit
  1990. of Icon.
  1991.  
  1992. I *Would* argue, though, that it is not as important to clone a replica 
  1993. of YACC|regexp. Icon is not C ! Perhaps existing practice can be improved 
  1994. upon. For example: Icon's dynamic typing would easily allow more 
  1995. variability in the sematic value returned - terminals could return a single
  1996. value while non-terminals yield a parse tree of the expression. ( Yes, you
  1997. can certainly do it in C with Unions of Structures, but its probably easier
  1998. in Icon. )
  1999.  
  2000. I don't think there is anything magical about the unix stype regular 
  2001. expression notation. If it *WAS* used consistently by all of the tools,
  2002. one could argue for consistency with mathematical notation (Kleene),
  2003. but it is NOT used consistently. ( + is Kleene +, but * is wildcard )
  2004.  
  2005. Steven Kearns(*) uses (in TLex) a very lisp-ish  notation:
  2006.  
  2007. ( define MP ( or empty ( seq '{' MP '}' )))
  2008. ( define alphanumeric ( or ( from "0" to "9" )
  2009.                ( from A to Z )
  2010.                ( from a to z ) )
  2011. ( define nonAN ( notclass alphanumeric ))
  2012.  
  2013. I perfer Lisp-like to Grep-like, but is there a particularly Icon-like 
  2014. representation ?  ( Other than Ken Walker's ? ) 
  2015.  
  2016. BTW: Kearns paper both describes TLex ( Tyranosaurus Lex ) and compares
  2017. performance of: TLex, FLex, GAWK, YACC & Icon - and Icon does not do badly,
  2018. so perhaps the argument of the effeciency of DFA pattern matching is 
  2019. not as strong as I thought. ( But probably not, there were only 2 tests 
  2020. and Icon did best in the simplest one. ) 
  2021.  
  2022.  
  2023.  
  2024. (*) Kearns, Steven M. TLEX. Software-Practice and Experience. Vol. 21(8)
  2025.             PP 805-821 (AUGUST 1991)
  2026.     Kearns, Steve M. Extending Regular Expressions with Context Operators 
  2027.         and Parse Extraction. Software-Practice and Experience.
  2028.          Vol 21(8) pp 787-804 (August 1991)
  2029.     Kearns, Steven M. TLEX v.68 User's Manual. Coulmbia University Technical
  2030.         Report. CUCS-037-90
  2031.  
  2032.  
  2033. Thanks for your other comments and corrections.
  2034.  
  2035. >
  2036. >Icon is pre-OO (1976), and I can't imagine anyone at the Icon Project
  2037. >would relish the though of redesigning the entire system.  Clinton Jef-
  2038. >fery has designed an Icon OO preprocessor.  But I think that, in order
  2039. >to do what you want, you'd need to design another language like Icon
  2040. >that wasn't Icon.  (Or is this just semantics?)
  2041. >
  2042.  
  2043. I started out looking for a comparison of various string and symbol
  2044. processing oriented tools and languages available. ( The old perl .vs. 
  2045. Icon .vs. ... thread. ) Which is better ? I've decided that they are
  2046. incomensurable: Icon, Perl & Yacc, for example each have a rather
  2047. different domain. ( It's not even Apples&Oranges ; it's more like 
  2048. Applesause and OrangeJuice! ) 
  2049.  But I'm still trying to sort out the "basic" paradigms of string &
  2050. string-oriented-symbol processin. ( To back up and digress, there 
  2051. seems to be two constellations: the world of regexps&grammars/AWK/
  2052. Perl/Yacc/etc. and ( make that two-and-a-half! ) SNOBOL type 
  2053. pattern matching which has split off into SNOBOL-type functions 
  2054. graafted onto other languages ( PROLOG, SETL, VAX/VMS LIB$C_{SPANC,ANY,etc.},
  2055. and Icon. )  If an ideal solution leads to Yet-another-language, I won't
  2056. complain. But at this point I don't know what an ideal solution would
  2057. LOOK like! ( Maybe it actually looks a lot like Icon ;-) 
  2058.  
  2059. - Steve Majewski 
  2060.  
  2061.  
  2062. --
  2063. ========= "If you've got a hammer, find a nail!" - George Bush =========
  2064.  Steven D. Majewski        University of Virginia Physiology Dept.
  2065.  sdm7g@Virginia.EDU        Box 449 Health Sciences Center
  2066.  (804)-982-0831            Charlottesville, VA 22908
  2067.  
  2068. From icon-group-request@arizona.edu  Sun Nov  3 21:59:13 1991
  2069. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Sun, 3 Nov 91 21:59:13 MST
  2070. Resent-From: icon-group-request@arizona.edu
  2071. Received: from Arizona.edu (Merlin.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  2072.     id AA07586; Sun, 3 Nov 91 21:59:13 MST
  2073. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Sun, 3 Nov
  2074.  1991 21:58 MST
  2075. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA27919; Sun, 3 Nov 91 20:47:53
  2076.  -0800
  2077. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  2078.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  2079.  usenet@ucbvax.Berkeley.EDU if you have questions)
  2080. Resent-Date: Sun, 3 Nov 1991 21:58 MST
  2081. Date: 1 Nov 91 04:21:31 GMT
  2082. From: midway!quads!goer@handies.ucar.edu (Richard L. Goerwitz)
  2083. Subject: RE: Icon futures ? (coroutines,patterns,etc.)
  2084. Sender: icon-group-request@arizona.edu
  2085. Resent-To: icon-group@cs.arizona.edu
  2086. To: icon-group@arizona.edu
  2087. Resent-Message-Id: <B0FD81A808204D37@Arizona.edu>
  2088. Message-Id: <1991Nov1.042131.6075@midway.uchicago.edu>
  2089. X-Envelope-To: icon-group@CS.Arizona.EDU
  2090. X-Vms-To: icon-group@Arizona.edu
  2091. Organization: University of Chicago
  2092. References: <1991Oct29.070610.12954@murdoch.acc.Virginia.EDU>
  2093.  
  2094. sdm7g@galen.med.Virginia.EDU (Steven D. Majewski) writes:
  2095.  
  2096. >I *Would* argue, though, that it is not as important to clone a replica 
  2097. >of YACC|regexp. Icon is not C ! Perhaps existing practice can be improved 
  2098. >upon. For example: Icon's dynamic typing would easily allow more 
  2099. >variability in the sematic value returned - terminals could return a single
  2100. >value while non-terminals yield a parse tree of the expression. ( Yes, you
  2101. >can certainly do it in C with Unions of Structures, but its probably easier
  2102. >in Icon. )
  2103.  
  2104. Couldn't agree more.  Icon code could be arranged as a big case statement
  2105. and the states could be squirted out by a coexpression, as in:
  2106.  
  2107.     case @get_state of {
  2108.         1:  code for state 1
  2109.         2:  code for state 2
  2110.         etc.
  2111.  
  2112. The parse tree could be built ad hoc by user code or by the parser itself.
  2113. Dunno.  Anyway, there are lots of neat things one could do.  But certainly
  2114. you're right that we would not have to use a yacc clone.
  2115.  
  2116. I hope that one of us actually gets to doing this project.
  2117.  
  2118. >Steven Kearns(*) uses (in TLex) a very lisp-ish  notation:
  2119. >
  2120. >( define MP ( or empty ( seq '{' MP '}' )))
  2121. >( define alphanumeric ( or ( from "0" to "9" )
  2122. >               ( from A to Z )
  2123. >               ( from a to z ) )
  2124. >( define nonAN ( notclass alphanumeric ))
  2125.  
  2126. Since the control structures and contexts are so different, it's hard to
  2127. compare.  In Icon [A-Z] is &ucase; [a-z] is &lcase; [0-9] is &digits.
  2128. You can construct character sets manually,
  2129.  
  2130.     vowels := 'aeiouAEIOUyY'
  2131.  
  2132. Note that this is not a string.  A string is "aeiouAEIOUyY" (with quota-
  2133. tion marks).  Here's how you create the set of alphanumeric characters
  2134. that are not vowels:
  2135.  
  2136.     NonVowels := (&letters -- vowels) ++ &digits
  2137.  
  2138. >I perfer Lisp-like to Grep-like, but is there a particularly Icon-like 
  2139. >representation ?  ( Other than Ken Walker's ? ) 
  2140.  
  2141. Depends on what you want, really.
  2142.  
  2143. >BTW: Kearns paper both describes TLex ( Tyranosaurus Lex ) and compares
  2144. >performance of: TLex, FLex, GAWK, YACC & Icon - and Icon does not do badly,
  2145. >so perhaps the argument of the effeciency of DFA pattern matching is 
  2146. >not as strong as I thought. ( But probably not, there were only 2 tests 
  2147. >and Icon did best in the simplest one. ) 
  2148.  
  2149. >...I'm still trying to sort out the "basic" paradigms of string &
  2150. >string-oriented-symbol processin. ( To back up and digress, there 
  2151. >seem to be two constellations: the world of regexps&grammars/AWK/
  2152. >Perl/Yacc/etc. and ( make that two-and-a-half! ) SNOBOL type 
  2153. >pattern matching which has split off into SNOBOL-type functions 
  2154. >graafted onto other languages ( PROLOG, SETL, VAX/VMS LIB$C_{SPANC,ANY,etc.},
  2155. >and Icon. )  If an ideal solution leads to Yet-another-language, I won't
  2156. >complain. But at this point I don't know what an ideal solution would
  2157. >LOOK like! ( Maybe it actually looks a lot like Icon ;-) 
  2158.  
  2159. Icon's really not a bad solution, I don't think.  But we do need some sort
  2160. of flexible parser generation system for it.  Luckily, Icon lets us get away
  2161. in more cases than other languages without such a system.  This is, I would
  2162. guess, why the language has gotten along so well without one.
  2163.  
  2164. It's certainly on my long-term list.  I still have a lot to learn about
  2165. parser generation systems.  I'm kinda killing time until Rekers' work at
  2166. Amsterdam is published, since the parallel-parser system he outlines in
  2167. his forthcoming dissertation is fairly simple, and handles a much wider
  2168. subset of context free languages than YACC (without too great a sacri-
  2169. fice of performance [using LR(0) tables to boot!]).  I also need to get
  2170. through the "dragon book," which for a non-CS person is no easy task.
  2171.  
  2172. -- 
  2173.  
  2174.    -Richard L. Goerwitz              goer%sophist@uchicago.bitnet
  2175.    goer@sophist.uchicago.edu         rutgers!oddjob!gide!sophist!goer
  2176.  
  2177. From R.J.Hare@edinburgh.ac.uk  Mon Nov  4 15:54:32 1991
  2178. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Mon, 4 Nov 91 15:54:32 MST
  2179. Received: from Arizona.edu (Merlin.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  2180.     id AA17986; Mon, 4 Nov 91 15:54:28 MST
  2181. Received: from UKACRL.BITNET (MAILER@UKACRL) by Arizona.edu with PMDF#10282;
  2182.  Mon, 4 Nov 1991 15:54 MST
  2183. Received: from RL.IB by UKACRL.BITNET (Mailer R2.07) with BSMTP id 0845; Mon,
  2184.  04 Nov 91 09:11:33 GMT
  2185. Received: from RL.IB by UK.AC.RL.IB (Mailer R2.07) with BSMTP id 3964; Mon, 04
  2186.  Nov 91 09:11:28 GMT
  2187. Date: 04 Nov 91  09:10:58 gmt
  2188. From: R.J.Hare@edinburgh.ac.uk
  2189. Subject: Ken Walkers paper
  2190. To: icon-group@cs.arizona.edu
  2191. Message-Id: <04 Nov 91  09:10:58 gmt  320785@EMAS-A>
  2192. X-Envelope-To: icon-group@cs.arizona.edu
  2193. Via:        UK.AC.ED.EMAS-A;  4 NOV 91  9:11:26 GMT
  2194.  
  2195.  
  2196. Could someone please post a full citation for Ken Walkers paper referred to
  2197. on ths board a few messages back? We don't get this journal and our ILL people
  2198. require as full a citation as possible before they can institute a search.
  2199.  
  2200. Thanks.
  2201.  
  2202. Roger Hare.
  2203.  
  2204. From kwalker  Mon Nov  4 16:08:34 1991
  2205. Received: from ocotillo.cs.arizona.edu by cheltenham.cs.arizona.edu; Mon, 4 Nov 91 16:08:34 MST
  2206. Date: Mon, 4 Nov 91 16:08:33 MST
  2207. From: "Kenneth Walker" <kwalker>
  2208. Message-Id: <9111042308.AA19543@ocotillo.cs.arizona.edu>
  2209. Received: by ocotillo.cs.arizona.edu; Mon, 4 Nov 91 16:08:33 MST
  2210. To: icon-group
  2211. Subject: Re:  Ken Walkers paper
  2212.  
  2213. > Date: 04 Nov 91  09:10:58 gmt
  2214. > From: R.J.Hare@edinburgh.ac.uk
  2215. >  
  2216. > Could someone please post a full citation for Ken Walkers paper referred to
  2217. > on ths board a few messages back? We don't get this journal and our ILL people
  2218. > require as full a citation as possible before they can institute a search.
  2219.  
  2220.    %A Kenneth W. Walker
  2221.    %T ``First-Class Patterns for Icon''
  2222.    %J Journal of Computer Languages
  2223.    %V 14
  2224.    %N 3
  2225.    %D 1989
  2226.    %P 153-163
  2227.  
  2228.   Ken Walker / Computer Science Dept / Univ of Arizona / Tucson, AZ 85721
  2229.   +1 602 621-4252  kwalker@cs.arizona.edu {uunet|allegra|noao}!arizona!kwalker
  2230.  
  2231. From isidev!nowlin@uunet.uu.net  Tue Nov  5 10:54:37 1991
  2232. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Tue, 5 Nov 91 10:54:37 MST
  2233. Received: from relay2.UU.NET by optima.cs.arizona.edu (4.1/15)
  2234.     id AA28578; Tue, 5 Nov 91 10:54:34 MST
  2235. Received: from uunet.uu.net (via LOCALHOST.UU.NET) by relay2.UU.NET with SMTP 
  2236.     (5.61/UUNET-internet-primary) id AA23808; Tue, 5 Nov 91 12:54:35 -0500
  2237. Date: Tue, 5 Nov 91 12:54:35 -0500
  2238. From: isidev!nowlin@uunet.uu.net
  2239. Message-Id: <9111051754.AA23808@relay2.UU.NET>
  2240. Received: from isidev.UUCP by uunet.uu.net with UUCP/RMAIL
  2241.     (queueing-rmail) id 125333.3483; Tue, 5 Nov 1991 12:53:33 EST
  2242. To: uunet!cs.arizona.edu!icon-group@uunet.uu.net
  2243. Subject: ISI phone troubles
  2244.  
  2245. I apologize to those who have tried to call Iconic Software using the
  2246. phone number included in the latest newsletter.  That number is
  2247. correct but we switched to a new office last week (plenty of time you
  2248. say!) and the phone lines are still in limbo.  They should be
  2249. straightened out by this afternoon (11/05/91).  If you have problems
  2250. with the voice line please use email for inquiries.  The email address
  2251. is below.  Thanks for your patience.
  2252.  
  2253. --- ---
  2254.  | S | Iconic Software, Inc.  -  Jerry Nowlin  -  uunet!isidev!isi
  2255. --- ---
  2256.  
  2257.  
  2258. From icon-group-request@arizona.edu  Tue Nov  5 17:21:11 1991
  2259. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Tue, 5 Nov 91 17:21:11 MST
  2260. Resent-From: icon-group-request@arizona.edu
  2261. Received: from Arizona.edu (Hopey.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  2262.     id AA00302; Tue, 5 Nov 91 17:21:08 MST
  2263. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Tue, 5 Nov
  2264.  1991 17:20 MST
  2265. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA03722; Tue, 5 Nov 91 04:56:38
  2266.  -0800
  2267. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  2268.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  2269.  usenet@ucbvax.Berkeley.EDU if you have questions)
  2270. Resent-Date: Tue, 5 Nov 1991 17:20 MST
  2271. Date: 3 Nov 91 02:51:12 GMT
  2272. From: dog.ee.lbl.gov!hellgate.utah.edu!caen!zaphod.mps.ohio-state.edu!uwm.edu!linac!midway!ellis!goer@ucbvax.berkeley.edu
  2273.  (Richard L. Goerwitz)
  2274. Subject: RE: regular expression in Icon (addendum)
  2275. Sender: icon-group-request@arizona.edu
  2276. Resent-To: icon-group@cs.arizona.edu
  2277. To: icon-group@arizona.edu
  2278. Resent-Message-Id: <1C78F8E36820431D@Arizona.edu>
  2279. Message-Id: <1991Nov3.025112.5191@midway.uchicago.edu>
  2280. X-Envelope-To: icon-group@CS.Arizona.EDU
  2281. X-Vms-To: icon-group@Arizona.edu
  2282. Organization: University of Chicago
  2283. References: <9111020103.AA17910@laguna.Metaphor.COM>
  2284.  
  2285. alex@LAGUNA.METAPHOR.COM (Bob Alexander) writes:
  2286.  
  2287. >Well, since there seems to be so much interest in regular expressions
  2288. >recently in icon-group, I have an offering that addresses the two
  2289. >predominant objections I've been hearing:
  2290. >
  2291. >1)    Richard G's concern about speed -- the routines that I've
  2292. >    attached to this message run at least 10 times faster than
  2293. >    the findre() suite.  Smaller too.  There is an interesting
  2294. >    technique used to exploit Icon's built-in backtracking so
  2295. >    that it does not have to be done explicitly in the Icon code.
  2296.  
  2297. One addendum:  I claimed your code was faster than mine in my last
  2298. posting.  I tried a few tests, and this seemed to be the case.  I just
  2299. tried them out in some actual working programs, though, and things look
  2300. different.  Here's why.  My egrep routine compiles patterns into an
  2301. automaton, which is then saved and used if the string is encountered
  2302. again.  Under version 8 the automata are not too big, and the savings
  2303. in execution speed is pretty good.  Note that the automata also don't
  2304. disable Icon's backtracking mechanisms.  Several people have mentioned
  2305. that they do, but this is not correct.  The end result is that if you
  2306. are calling findre() with just a couple of strings over and over (a
  2307. very typical case), it runs much better than yours.  Try a test pro-
  2308. gram like this:
  2309.  
  2310.   procedure main()
  2311.     lst1 := ["a*b[cdef](gh)+", "abc", "aaaaab(dghgh)?$"]
  2312.     lst2 := ["abc", "abfgh", "aaaaabdghgh"]
  2313.     every 1 to 500 do
  2314.     ReFind(?lst1, ?lst2)
  2315.     # findre(?lst1, ?lst2)
  2316.   end
  2317.  
  2318. Anyway, I think this is all academic.  Compare our regexp routines
  2319. to UNIX-based ones some time for a big laugh.
  2320.  
  2321. -- 
  2322.  
  2323.    -Richard L. Goerwitz              goer%sophist@uchicago.bitnet
  2324.    goer@sophist.uchicago.edu         rutgers!oddjob!gide!sophist!goer
  2325.  
  2326. From icon-group-request@arizona.edu  Thu Nov  7 14:40:34 1991
  2327. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Thu, 7 Nov 91 14:40:34 MST
  2328. Resent-From: icon-group-request@arizona.edu
  2329. Received: from Arizona.edu (Osprey.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  2330.     id AA05783; Thu, 7 Nov 91 14:40:33 MST
  2331. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Thu, 7 Nov
  2332.  1991 14:39 MST
  2333. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA22123; Thu, 7 Nov 91 13:22:54
  2334.  -0800
  2335. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  2336.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  2337.  usenet@ucbvax.Berkeley.EDU if you have questions)
  2338. Resent-Date: Thu, 7 Nov 1991 14:40 MST
  2339. Date: 7 Nov 91 00:51:12 GMT
  2340. From: fernwood!cronos!laguna!alex@uunet.uu.net (Bob Alexander)
  2341. Subject: Corrections to regular expression procedures
  2342. Sender: icon-group-request@arizona.edu
  2343. Resent-To: icon-group@cs.arizona.edu
  2344. To: icon-group@arizona.edu
  2345. Resent-Message-Id: <985D4D9D98808D03@Arizona.edu>
  2346. Message-Id: <1554@cronos.metaphor.com>
  2347. X-Envelope-To: icon-group@CS.Arizona.EDU
  2348. X-Vms-To: icon-group@Arizona.edu
  2349. Organization: Metaphor Computer Systems, Mountain View, CA
  2350.  
  2351. I'm a bit embarrassed about the quality of the regular expression
  2352. routines I posted a few days ago.  I'd like to thank Richard G. for
  2353. spotting and reporting several bugs -- all of the bugs mentioned in his
  2354. posting were valid.  I coded these routines last April, and I think I
  2355. forgot that I hadn't tested them very well -- some of the bugs were
  2356. all too obvious.
  2357.  
  2358. All the reported bugs have been corrected; I hope I haven't introduced
  2359. any new ones.  But it's likely that some bugs remain -- please don't
  2360. hesitate to send in those cards and letters!
  2361.  
  2362. The updated regexp.icn source code follows the message text.  There is
  2363. no change to igrep.icn.
  2364.  
  2365. Here are Richard's points one-by-one:
  2366.  
  2367. > There's a bug in the code that prevents the "+" operator from working
  2368. > correctly.  For instance, if I compile your igrep program, and type
  2369.  
  2370. >     echo 'hello' | igrep 'el+o'
  2371.  
  2372. > It doesn't work.
  2373.  
  2374. The most embarrassing bug was that the precedence of adjacent
  2375. characters was real high: this example was grouping as (el)+o.  Of
  2376. course, it *should* be e(l)+o. It's fixed now.
  2377.  
  2378. > Also, a frequent bug with egrep programs is that they can't do this:
  2379.  
  2380. >     echo 'hello' | igrep 'el*llo'
  2381.  
  2382. This, too, was grouping as (el)*(llo).
  2383.  
  2384. > Your gets this one right.  Nice job!
  2385.  
  2386. Thanks for the compliment, however undeserved :-).
  2387.  
  2388. > Unfortunately, it doesn't get this one right:
  2389.  
  2390. >     echo 'hello' | igrep 'hel?o'
  2391.  
  2392. Grouping problem again -- (hel)?o -- fixed.
  2393.  
  2394. > One really neat improvement over egrep is that your program handles
  2395. > [a-z] right, but takes the dash in [a-] as a dash.  In egrep, this is a
  2396. > syntax error.  I guess it depends on how compatible you want to be.  I
  2397. > like your way better.  If you're into fixing misfeatures, perhaps you
  2398. > should also fix the problem with "*a" being a syntax error in most
  2399. > egreps (and yours).  The GNU egrep program recognizes this pattern
  2400. > correctly.  I.e. it knows the "*" can't possibly be a metacharacter.
  2401. > I'd either make [a-] and *a errors or make them both work.  Not half
  2402. > and half.
  2403.  
  2404. It's now consistent, but on the negative side -- now [a-] is an error,
  2405. too.  I could have gone the other way, but it seemed unimportant and
  2406. would have cost some extra code.  (Actually, although [a-] was
  2407. accepted, the "a" was being discarded!).
  2408.  
  2409. > Probably the only maddening feature of your igrep is that it barfs on
  2410. > back- slashed parentheses, and other escaped metacharacters.
  2411.  
  2412. Barfing fixed.
  2413.  
  2414. > It also seems to have a precedence bug somewhere in the
  2415. > vertical-slash-handling routines (e.g.  echo 'hello' | igrep
  2416. > '^helg|lo$' doesn't accept the string, as it should for all
  2417. > egrep-compatible regexp routines).
  2418.  
  2419. I had misunderstood the manual on this one.  It was handling the ^ and
  2420. $ only at the front of a *whole* RE, but not bracketing terms of
  2421. alternation.  It now works for alternation -- hope I got it right
  2422. this time.
  2423.  
  2424. > I get an unpleasant abort also when specifying a pattern like
  2425. > '^hel(m|g)o$'.
  2426.  
  2427. Fixed.
  2428.  
  2429.  
  2430. ############################################################################
  2431. #
  2432. #    Name:    regexp.icn
  2433. #
  2434. #    Title:    UNIX-like Regular Expression Pattern Matching Procedures
  2435. #
  2436. #    Author: Robert J. Alexander
  2437. #
  2438. #    Date:    November 6, 1991
  2439. #
  2440. ############################################################################
  2441. #
  2442. #  This is a kit of procedures to deal with UNIX-like regular expression
  2443. #  patterns.
  2444. #
  2445. #  These procedures are interesting partly because of the "recursive
  2446. #  suspension" (or "suspensive recursion" :-) technique used to simulate
  2447. #  conjunction of an arbitrary number of computed expressions (see
  2448. #  notes, below).
  2449. #
  2450. #
  2451. #  The public procedures are:
  2452. #
  2453. #  ReMatch(pattern,s,i1,i2) : i3,i4,...,iN
  2454. #  ReFind(pattern,s,i1,i2) : i3,i4,...,iN
  2455. #  RePat(s) : pattern list
  2456. #
  2457. #
  2458. #  ReMatch() produces the sequence of positions in "s" past a substring
  2459. #  starting at "i1" that matches "pattern", but fails if there is no
  2460. #  such position.  Similar to match(), but is capable of generating
  2461. #  multiple positions.
  2462. #
  2463. #  ReFind() produces the sequence of positions in "s" where substrings
  2464. #  begin that match "pattern", but fails if there is no such position.
  2465. #  Similar to find().  Each position is produced only once, even if
  2466. #  several possible matches are possible at that position.
  2467. #
  2468. #  "pattern" can be either a string or a pattern list -- see RePat(),
  2469. #  below.
  2470. #
  2471. #  Default values of s, i1, and i2 are handled as for Icon's built-in
  2472. #  string scanning procedures such as match().
  2473. #
  2474. #
  2475. #  RePat(s) : L
  2476. #
  2477. #  Creates a pattern element list from pattern string "s", but fails if
  2478. #  the pattern string is not syntactically correct.  ReMatch() and
  2479. #  ReFind() will automatically convert a pattern string to a pattern
  2480. #  list, but it is faster to do the conversion explicitly if multiple
  2481. #  operations are done using the same pattern.  An additional advantage
  2482. #  to compiling the pattern separately is avoiding ambiguity of failure
  2483. #  caused by an incorrect pattern and failure to match a correct pattern.
  2484. #
  2485. #
  2486. #  Accessible Global Variables
  2487. #
  2488. #  After a match, the strings matched by parenthesized regular
  2489. #  expressions are left in list "Re_ParenGroups", and can be accessed by
  2490. #  subscripting in using the same number as the \N construct.
  2491. #
  2492. #  If it is desired that regular expression format be similar to UNIX
  2493. #  filename generation patterns but still retain the power of full
  2494. #  regular expressions, make the following assignments prior to
  2495. #  compiling the pattern string:
  2496. #
  2497. #    Re_ArbString := "*"    # Defaults to ".*"
  2498. #    Re_AnyString := "?"    # Defaults to "."
  2499. #
  2500. #  The sets of characters (csets) that define a word, digits, and white
  2501. #  space can be modified.  The following assignments can be made before
  2502. #  compiling the pattern string.  The character sets are captured when
  2503. #  the pattern is compiled, so changing them after pattern compilation
  2504. #  will not alter the behavior of matches unless the pattern string is
  2505. #  recompiled.
  2506. #
  2507. #    Re_WordChars := 'whatever you like'
  2508. #            # Defaults to &letters ++ &digits ++ "_"
  2509. #    Re_Digits := &digits ++ 'ABCDEFabcdef'
  2510. #            # Defaults to &digits
  2511. #    Re_Space := 'whatever you like'
  2512. #            # Defaults to ' \t\v\n\r\f'
  2513. #
  2514. #  These globals are normally not initialized until the first call to
  2515. #  RePat(), and then only if they are null.  They can be explicitly
  2516. #  initialized to their defaults (if they are null) by calling
  2517. #  Re_Default().
  2518. #
  2519. #  Characters compiled into patterns can be passed through a
  2520. #  user-supplied filter procedure, provided in global variable
  2521. #  Re_Filter.  The filtering is done before the characters are bound
  2522. #  into the pattern.  The filter proc is passed one argument, the string
  2523. #  to filter, and it must return the filtered string as its result.  If
  2524. #  the filter proc fails, the string will be used unfiltered.  The
  2525. #  filter proc is called with an argument of either type string (for
  2526. #  characters in the pattern) or cset (for character classes [...]).  A
  2527. #  typical use for this facility is to implement case-independent
  2528. #  matching.  All pattern characters can downshifted by assigning
  2529. #
  2530. #    Re_Filter := map
  2531. #
  2532. #  Filtering is done only as the pattern is compiled.  Filtering of
  2533. #  strings to be matched must be explicitly done.  Therefore,
  2534. #  case-independent matching will occur only if map() is applied to all
  2535. #  strings to be matched.
  2536. #
  2537. #  In the case of patterns containing alternation, ReFind() will
  2538. #  generally not produce positions in increasing order, but will produce
  2539. #  all positions from the first term of the alternation (in increasing
  2540. #  order) followed by all positions from the second (in increasing
  2541. #  order).  If it is necessary that the positions be generated in
  2542. #  strictly increasing order, with no duplicates, assign any non-null
  2543. #  value to Re_Ordered:
  2544. #
  2545. #    Re_Ordered := 1
  2546. #
  2547. #  If the Re_Ordered options is chosen, there is a *small* penalty in
  2548. #  efficiency in some cases, and the co-expression facility is required
  2549. #  in your Icon implementation.  Example:
  2550. #  
  2551. #
  2552. #  Regular Expression Characters and Features Supported
  2553. #
  2554. #  The regular expression format supported by procedures in this file
  2555. #  model very closely those supported by the UNIX "egrep" program, with
  2556. #  modifications as in the Perl programming language definition.
  2557. #  Following is a brief description of the special characters used in
  2558. #  regular expressions.  In the description, the abbreviation RE means
  2559. #  regular expression.
  2560. #
  2561. #  c        An ordinary character (not one of the special characters
  2562. #        discussed below) is a one-character RE that matches that
  2563. #        character.
  2564. #
  2565. #  \c        A backslash followed by any special character is a one-
  2566. #        character RE that matches the special character itself.
  2567. #
  2568. #        Note that backslash escape sequences representing
  2569. #        non-graphic characters are not supported directly
  2570. #        by these procedures.  Of course, strings coded in an
  2571. #        Icon program will have such escapes handled by the
  2572. #        Icon translator.  If such escapes must be supported
  2573. #        in strings read from the run-time environment (e.g.
  2574. #        files), they will have to be converted by other means,
  2575. #        such as the Icon Program Library procedure "escape()".
  2576. #
  2577. #  .        A period is a one-character RE that matches any
  2578. #        character.
  2579. #
  2580. #  [string]    A non-empty string enclosed in square brackets is a one-
  2581. #        character RE that matches any *one* character of that
  2582. #        string.  If, the first character is "^" (circumflex),
  2583. #        the RE matches any character not in the remaining
  2584. #        characters of the string.  The "-" (minus), when between
  2585. #        two other characters, may be used to indicate a range of
  2586. #        consecutive ASCII characters (e.g. [0-9] is equivalent to
  2587. #        [0123456789]).  Other special characters stand for
  2588. #        themselves in a bracketed string.
  2589. #
  2590. #  *        Matches zero or more occurrences of the RE to its left.
  2591. #
  2592. #  +        Matches one or more occurrences of the RE to its left.
  2593. #
  2594. #  ?        Matches zero or one occurrences of the RE to its left.
  2595. #
  2596. #  {N}        Matches exactly N occurrences of the RE to its left.
  2597. #
  2598. #  {N,}        Matches at least N occurrences of the RE to its left.
  2599. #
  2600. #  {N,M}    Matches at least N occurrences but at most M occurrences
  2601. #        of the RE to its left.
  2602. #
  2603. #  ^        A caret at the beginning of an entire RE constrains
  2604. #        that RE to match an initial substring of the subject
  2605. #        string.
  2606. #
  2607. #  $        A currency symbol at the end of an entire RE constrains
  2608. #        that RE to match a final substring of the subject string.
  2609. #
  2610. #  |        Alternation: two REs separated by "|" match either a
  2611. #        match for the first or a match for the second.
  2612. #
  2613. #  ()        A RE enclosed in parentheses matches a match for the
  2614. #        regular expression (parenthesized groups are used
  2615. #        for grouping, and for accessing the matched string
  2616. #        subsequently in the match using the \N expression).
  2617. #
  2618. #  \N        Where N is a digit in the range 1-9, matches the same
  2619. #        string of characters as was matched by a parenthesized
  2620. #        RE to the left in the same RE.  The sub-expression
  2621. #        specified is that beginning with the Nth occurrence
  2622. #        of "(" counting from the left.  E.g., ^(.*)\1$ matches
  2623. #        a string consisting of two consecutive occurrences of
  2624. #        the same string.
  2625. #
  2626. #  Perl Extensions
  2627. #
  2628. #  The following extensions to UNIX REs, as specified in the Perl
  2629. #  programming language, are supported.
  2630. #
  2631. #  \w        Matches any alphanumeric (including "_").
  2632. #  \W        Matches any non-alphanumeric.
  2633. #
  2634. #  \b        Matches only at a word-boundary (word defined as a string
  2635. #        of alphanumerics as in \w).
  2636. #  \B        Matches only non-word-boundaries.
  2637. #
  2638. #  \s        Matches any white-space character.
  2639. #  \S        Matches any non-white-space character.
  2640. #
  2641. #  \d        Matches any digit [0-9].
  2642. #  \D        Matches any non-digit.
  2643. #
  2644. #  \w, \W, \s, \S, \d, \D can be used within [string] REs.
  2645. #
  2646. #
  2647. #  Note on Details of Matching
  2648. #
  2649. #  The method of matching differs a bit from UNIX-style regular
  2650. #  expressions -- particularly where closures are concerned ("*", "+",
  2651. #  "{}", "?").  UNIX regular expressions are documented to match the
  2652. #  "longest, leftmost" strings in cases where a choice is needed.  The
  2653. #  procedures in this file are capable of generating all possible
  2654. #  matches of the pattern, and generate the possibilities by matching
  2655. #  the fewest first ("shortest, leftmost").  Matching of the various
  2656. #  pattern elements is performed exactly as though it were an Icon
  2657. #  conjunction of the elements.
  2658. #
  2659. #
  2660. #  Notes on computed conjunction expressions by "suspensive recursion"
  2661. #
  2662. #  A conjunction expression of an arbitrary number of terms can be
  2663. #  computed in a looping fashion by the following recursive technique:
  2664. #
  2665. #    procedure Conjunct(v)
  2666. #       if <there is another term to be appended to the conjunction> then
  2667. #          suspend Conjunct(<the next term expression>)
  2668. #       else
  2669. #          suspend v
  2670. #    end
  2671. #
  2672. #  The argument "v" is needed for producing the value of the last term
  2673. #  as the value of the conjunction expression, accurately modeling Icon
  2674. #  conjunction.  If the value of the conjunction is not needed, the
  2675. #  technique can be slightly simplified by eliminating "v":
  2676. #
  2677. #    procedure ConjunctAndProduceNull()
  2678. #       if <there is another term to be appended to the conjunction> then
  2679. #          suspend ConjunctAndProduceNull(<the next term expression>)
  2680. #       else
  2681. #          suspend
  2682. #    end
  2683. #
  2684. #  Note that <the next term expression> must still remain in the suspend
  2685. #  expression to test for failure of the term, although its value is not
  2686. #  passed to the recursive invocation,  This could have been coded as
  2687. #
  2688. #          suspend <the next term expression> & ConjunctAndProduceNull()
  2689. #
  2690. #  but wouldn't have been as provocative.
  2691. #
  2692. #  Since the computed conjunctions in this program are evaluated only for
  2693. #  their side effects, the second technique is used in two situations:
  2694. #
  2695. #    (1)    To compute the conjunction of all of the elements in the
  2696. #        regular expression pattern list (Re_match1()).
  2697. #
  2698. #    (2)    To evaluate the "exactly N times" and "N to M times"
  2699. #        control operations (Re_NTimes()).
  2700. #
  2701.  
  2702.  
  2703. record Re_Tok(proc,args)
  2704.  
  2705. global Re_ParenGroups,Re_Filter,Re_Ordered
  2706. global Re_WordChars,Re_NonWordChars
  2707. global Re_Space,Re_NonSpace
  2708. global Re_Digits,Re_NonDigits
  2709. global Re_ArbString,Re_AnyString
  2710. global Re_TabMatch
  2711.  
  2712.  
  2713. ###################  Pattern Translation Procedures  ###################
  2714.  
  2715.  
  2716. procedure RePat(s) # L
  2717. #
  2718. #  Produce pattern list representing pattern string s.
  2719. #
  2720.    #
  2721.    #  Create a list of pattern elements.  Pattern strings are parsed
  2722.    #  and converted into list elements as shown in the following table.
  2723.    #  Since some list elements reference other pattern lists, the
  2724.    #  structure is really a tree.
  2725.    #
  2726.    # Token    Generates            Matches...
  2727.    # -----    ---------            ----------
  2728.    #  ^        Re_Tok(pos,[1])            Start of string or line
  2729.    #  $        Re_Tok(pos,[0])            End of string or line
  2730.    #  .        Re_Tok(move,[1])        Any single character
  2731.    #  +        Re_Tok(Re_OneOrMore,[tok])    At least one occurrence of
  2732.    #                        previous token
  2733.    #  *        Re_Tok(Re_ArbNo,[tok])        Zero or more occurrences of
  2734.    #                        previous token
  2735.    #  |        Re_Tok(Re_Alt,[pattern,pattern]) Either of prior expression
  2736.    #                        or next expression
  2737.    #  [...]    Re_Tok(Re_TabAny,[cset])    Any single character in
  2738.    #                        specified set (see below)
  2739.    #  (...)    Re_Tok(Re_MatchReg,[pattern])    Parenthesized pattern as
  2740.    #                        single token
  2741.    #  <string of non-special characters>    The string of no-special
  2742.    #        Re_Tok(Re+TabMatch,string)      characters
  2743.    #  \b    Re_Tok(Re_WordBoundary,[Re_WordChars,Re_NonWordChars])
  2744.    #                        A word-boundary
  2745.    #                          (word default: [A-Za-z0-9_]+)
  2746.    #  \B    Re_Tok(Re_NonWordBoundary,[Re_WordChars,Re_NonWordChars])
  2747.    #                        A non-word-boundary
  2748.    #  \w    Re_Tok(Re_TabAny,[Re_WordChars])A word-character
  2749.    #  \W    Re_Tok(Re_TabAny,[Re_NonWordChars]) A non-word-character
  2750.    #  \s    Re_Tok(Re_TabAny,[Re_Space])    A space-character
  2751.    #  \S    Re_Tok(Re_TabAny,[Re_NonSpace])    A non-space-character
  2752.    #  \d    Re_Tok(Re_TabAny,[Re_Digits])    A digit
  2753.    #  \D    Re_Tok(Re_TabAny,[Re_NonDigits]) A non-digit
  2754.    #  {n,m}    Re_Tok(Re_NToMTimes,[tok,n,m])    n to m occurrences of
  2755.    #                        previous token
  2756.    #  {n,}    Re_Tok(Re_NOrMoreTimes,[tok,n])    n or more occurrences of
  2757.    #                        previous token
  2758.    #  {n}    Re_Tok(Re_NTimes,[tok,n])    exactly n occurrences of
  2759.    #                        previous token
  2760.    #  ?        Re_Tok(Re_ZeroOrOneTimes,[tok])    one or zero occurrences of
  2761.    #                        previous token
  2762.    #  \<digit>    Re_Tok(Re_MatchParenGroup,[n])    The string matched by
  2763.    #                        parenthesis group <digit>
  2764.    #
  2765.    local plist
  2766.    #
  2767.    #  Initialize.
  2768.    #
  2769.    initial Re_Default()
  2770.    Re_WordChars := cset(Re_WordChars)
  2771.    Re_NonWordChars := ~Re_WordChars
  2772.    Re_Space := cset(Re_Space)
  2773.    Re_NonSpace := ~Re_Space
  2774.    Re_Digits := cset(Re_Digits)
  2775.    Re_NonDigits := ~Re_Digits
  2776.  
  2777.    s ? (plist := Re_pat1(0)) | fail
  2778.    return plist
  2779. end
  2780.  
  2781.  
  2782. procedure Re_pat1(level) # L
  2783. #
  2784. #  Recursive portion of RePat()
  2785. #
  2786.    local plist,n,m,c,comma
  2787.    static none,parenNbr
  2788.    initial {
  2789.       Re_TabMatch := proc("=",1)
  2790.       none := []
  2791.       }
  2792.    if level = 0 then parenNbr := 0
  2793.    plist := []
  2794.    #
  2795.    #  Loop to put pattern elements on list.
  2796.    #
  2797.    until pos(0) do {
  2798.       (="|",plist := [Re_Tok(Re_Alt,[plist,Re_pat1(level + 1) | fail])]) |
  2799.       put(plist,
  2800.      ## (="^",*plist = 0 | plist[-1].proc === Re_Alt,Re_Tok(pos,[1])) |
  2801.      (="^",pos(2) | &subject[-2] == "|",Re_Tok(pos,[1])) |
  2802.      (="$",pos(0) | match("|"),Re_Tok(pos,[0])) |
  2803.      (match(")"),level > 0,break) |
  2804.      (=Re_ArbString,Re_Tok(Re_Arb,none)) |
  2805.      (=Re_AnyString,Re_Tok(move,[1])) |
  2806.      (="+",Re_Tok(Re_OneOrMore,[Re_prevTok(plist) | fail])) |
  2807.      (="*",Re_Tok(Re_ArbNo,[Re_prevTok(plist) | fail])) |
  2808.      1(Re_Tok(Re_TabAny,[c := Re_cset()]),\c | fail) |
  2809.      3(="(",n := parenNbr +:= 1,
  2810.            Re_Tok(Re_MatchReg,[Re_pat1(level + 1) | fail,n]),
  2811.            move(1) | fail) |
  2812.      (="\\b",Re_Tok(Re_WordBoundary,[Re_WordChars,Re_NonWordChars])) |
  2813.      (="\\B",Re_Tok(Re_NonWordBoundary,[Re_WordChars,Re_NonWordChars])) |
  2814.      (="\\w",Re_Tok(Re_TabAny,[Re_WordChars])) |
  2815.      (="\\W",Re_Tok(Re_TabAny,[Re_NonWordChars])) |
  2816.      (="\\s",Re_Tok(Re_TabAny,[Re_Space])) |
  2817.      (="\\S",Re_Tok(Re_TabAny,[Re_NonSpace])) |
  2818.      (="\\d",Re_Tok(Re_TabAny,[Re_Digits])) |
  2819.      (="\\D",Re_Tok(Re_TabAny,[Re_NonDigits])) |
  2820.      (="{",(n := tab(many(&digits)),comma := =(",") | &null,
  2821.         m := tab(many(&digits)) | &null,="}") | fail,
  2822.         if \m then Re_Tok(Re_NToMTimes,
  2823.           [Re_prevTok(plist),integer(n),integer(m)])
  2824.         else if \comma then Re_Tok(Re_NOrMoreTimes,
  2825.           [Re_prevTok(plist),integer(n)])
  2826.         else Re_Tok(Re_NTimes,[Re_prevTok(plist),integer(n)])) |
  2827.      (="?",Re_Tok(Re_ZeroOrOneTimes,[Re_prevTok(plist) | fail])) |
  2828.      Re_Tok(Re_TabMatch,[Re_string(level)]) |
  2829.      (="\\",n := tab(any(&digits)),Re_Tok(Re_MatchParenGroup,[integer(n)]))
  2830.      ) |
  2831.       fail
  2832.       }
  2833.    return plist
  2834. end
  2835.  
  2836.  
  2837. procedure Re_prevTok(plist)
  2838. #
  2839. #  Pull previous token from the pattern list.  This procedure must take
  2840. #  into account the fact that successive character tokens have been
  2841. #  optimized into a single string token.
  2842. #
  2843.    local lastTok,s,r
  2844.    lastTok := pull(plist) | fail
  2845.    if lastTok.proc === Re_TabMatch then {
  2846.       s := lastTok.args[1]
  2847.       r := Re_Tok(Re_TabMatch,[s[-1]])
  2848.       s[-1] := ""
  2849.       if *s > 0 then {
  2850.      put(plist,lastTok)
  2851.      lastTok.args[1] := s
  2852.      }
  2853.       return r
  2854.       }
  2855.    return lastTok
  2856. end
  2857.  
  2858.  
  2859. procedure Re_Default()
  2860. #
  2861. #  Assign default values to regular expression translation globals, but
  2862. #  only to variables whose values are null.
  2863. #
  2864.    /Re_WordChars := &letters ++ &digits ++ "_"
  2865.    /Re_Space := ' \t\v\n\r\f'
  2866.    /Re_Digits := &digits
  2867.    /Re_ArbString := ".*"
  2868.    /Re_AnyString := "."
  2869.    return
  2870. end
  2871.  
  2872.  
  2873. procedure Re_cset()
  2874. #
  2875. #  Matches a [...] construct and returns a cset.
  2876. #
  2877.    local complement,c,e,ch,chars
  2878.    (="[",complement := ="^" | &null,
  2879.      c := (ch := (="-" | "")) || move(1) || tab(find("]")),move(1)) |
  2880.      fail
  2881.    c ? {
  2882.       e := ch
  2883.       while chars := tab(upto('-\\')) do {
  2884.      e ++:= case move(1) of {
  2885.         "-": chars[1:-1] ++
  2886.           &cset[ord(chars[-1]) + 1:ord(move(1)) + 2] | return &null
  2887.         "\\": case ch := move(1) of {
  2888.            "w": Re_WordChars
  2889.            "W": Re_NonWordChars
  2890.            "s": Re_Space
  2891.            "S": Re_NonSpace
  2892.            "d": Re_Digits
  2893.            "D": Re_NonDigits
  2894.            default: ch
  2895.            }
  2896.         }
  2897.      }
  2898.       e ++:= tab(0)
  2899.       if \complement then e := ~e
  2900.       }
  2901.    e := (\Re_Filter)(e)
  2902.    return cset(e)
  2903. end
  2904.  
  2905.  
  2906. procedure Re_string(level)
  2907. #
  2908. #  Matches a string of non-special characters, returning a string.
  2909. #
  2910.    local special,s,p
  2911.    static nondigits
  2912.    initial nondigits := ~&digits
  2913.    special := if level = 0 then '\\.+*|[({?' else  '\\.+*|[({?)'
  2914.    s := tab(upto(special) | 0)
  2915.    while ="\\" do {
  2916.       p := &pos
  2917.       if tab(any('wWbBsSdD')) |
  2918.         (tab(any('123456789')) & (pos(0) | any(nondigits))) then {
  2919.      tab(p - 1)
  2920.      break
  2921.      }
  2922.       s ||:= move(1) || tab(upto(special) | 0)
  2923.       }
  2924.    if pos(0) & s[-1] == "$" then {
  2925.       move(-1)
  2926.       s[-1] := ""
  2927.       }
  2928.    s := string((\Re_Filter)(s))
  2929.    return "" ~== s
  2930. end
  2931.  
  2932.  
  2933. #####################  Matching Engine Procedures  ########################
  2934.  
  2935.  
  2936. procedure ReMatch(plist,s,i1,i2) # i3,i4,...,iN
  2937. #
  2938. #  Produce the sequence of positions in s past a string starting at i1
  2939. #  that matches the pattern plist, but fails if there is no such
  2940. #  position.  Similar to match(), but is capable of generating multiple
  2941. #  positions.
  2942. #
  2943.    if type(plist) ~== "list" then plist := RePat(plist) | fail
  2944.    /i1:= if /s := &subject then &pos else 1 ; /i2 := 0
  2945.    Re_ParenGroups := []
  2946.    suspend s[i1:i2] ? (Re_match1(plist,1),i1 + &pos - 1)
  2947. end
  2948.  
  2949.  
  2950. procedure Re_match1(plist,i) # s1,s2,...,sN
  2951. #
  2952. #  Used privately by ReMatch() to simulate a computed conjunction
  2953. #  expression via recursive generation.
  2954. #
  2955.    local tok
  2956.    suspend if tok := plist[i] then
  2957.       Re_tok_match(tok,plist,i) & Re_match1(plist,i + 1) else &null
  2958. end
  2959.  
  2960.  
  2961. procedure ReFind(plist,s,i1,i2) # i3,i4,...,iN
  2962. #
  2963. #  Produce the sequence of positions in s where strings begin that match
  2964. #  the pattern plist, but fails if there is no such position.  Similar
  2965. #  to find().
  2966. #
  2967.    local p
  2968.    if type(plist) ~== "list" then plist := RePat(plist) | fail
  2969.    /i1 := if /s := &subject then &pos else 1 ; /i2 := 0
  2970.    s[i1:i2] ? suspend (
  2971.      tab(Re_skip(plist,1)) &
  2972.      p := &pos &
  2973.      Re_match1(plist,1)\1 &
  2974.      i1 + p - 1)
  2975. end
  2976.  
  2977.  
  2978. procedure Re_tok_match(tok,plist,i)
  2979. #
  2980. #  Match a single token.  Can be recursively called by the token
  2981. #  procedure.
  2982. #
  2983.    local prc
  2984.    prc := tok.proc
  2985.    suspend (
  2986.       if prc === Re_Arb then Re_Arb(plist,i)
  2987.       else suspend prc!tok.args
  2988.       )
  2989. end
  2990.  
  2991.  
  2992. ##########  Heuristic Code for Matching Arbitrary Characters  ##########
  2993.  
  2994.  
  2995. procedure Re_skip(plist,i) # s1,s2,...,sN
  2996. #
  2997. #  Used privately -- match a sequence of strings in s past which a match
  2998. #  of the first pattern element in plist is likely to succeed.  This
  2999. #  procedure is used for heuristic performance improvement by ReMatch()
  3000. #  for the ".*" pattern element, and by ReFind().
  3001. #
  3002.    local x,s,p,prc
  3003.    x := plist[i]
  3004.    suspend case prc := (\x).proc | &null of {
  3005.       Re_TabMatch: find!x.args
  3006.       Re_TabAny: upto!x.args
  3007.       pos: x.args[1]
  3008.       ## Re_WordBoundary: Re_WordBoundaries!x.args
  3009.       Re_WordBoundary |
  3010.       Re_NonWordBoundary:
  3011.         p := &pos & tab(Re_skip(plist,i + 1)) & prc!x.args & untab(p)
  3012.       Re_OneOrMore |
  3013.       Re_MatchParenGroup: if s := (\Re_ParenGroups)[x.args[1]] then
  3014.         find(s) else &pos to *&subject + 1
  3015.       Re_NToMTimes |
  3016.       Re_NOrMoreTimes |
  3017.       Re_NTimes:
  3018.         if x.args[2] > 0 then Re_skip(x.args[1],1) else &pos to &subject + 1
  3019.       Re_MatchReg: Re_skip(x.args[1],1)
  3020.       Re_Alt:
  3021.         if \Re_Ordered then
  3022.           Re_result_merge{Re_skip(x.args[1],1),Re_skip(x.args[2],1)}
  3023.         else
  3024.           Re_skip(x.args[1 | 2],1)
  3025.       default: &pos to *&subject + 1
  3026.       }
  3027. end
  3028.  
  3029.  
  3030. procedure Re_result_merge(L)
  3031. #
  3032. #  Programmer-defined control operation to merge the result sequences of
  3033. #  two integer-producing generators.  Both generators must produce their
  3034. #  result sequences in numerically increasing order with no duplicates,
  3035. #  and the output sequence will be in increasing order with no
  3036. #  duplicates.
  3037. #
  3038.    local e1,e2,r1,r2
  3039.    e1 := L[1] ; e2 := L[2]
  3040.    r1 := @e1 ; r2 := @e2
  3041.    while \(r1 | r2) do
  3042.      if /r2 | \r1 < r2 then
  3043.            suspend r1 do r1 := @e1 | &null
  3044.      else if /r1 | r1 > r2 then
  3045.            suspend r2 do r2 := @e2 | &null
  3046.      else
  3047.            r2 := @e2 | &null
  3048. end
  3049.  
  3050.  
  3051. procedure untab(origPos)
  3052. #
  3053. #  Converts a string scanning expression that moves the cursor to one
  3054. #  that produces a cursor position and doesn't move the cursor (converts
  3055. #  something like tab(find(x)) to find(x).  The template for using this
  3056. #  procedure is
  3057. #
  3058. #    origPos := &pos ; tab(x) & ... & untab(origPos)
  3059. #
  3060.    local newPos
  3061.    newPos := &pos
  3062.    tab(origPos)
  3063.    suspend newPos
  3064.    tab(newPos)
  3065. end
  3066.  
  3067.  
  3068. ## procedure Re_WordBoundaries(wd)
  3069. ## #
  3070. ## #  Produce positions that are word boundaries.
  3071. ## #
  3072.    ## local p,q
  3073.    ## p1 := p := &pos
  3074.    ## while q := upto(wd,,p) | break do {
  3075.       ## suspend q
  3076.       ## p := many(wd,,q)
  3077.       ## suspend p
  3078.       ## }
  3079.    ## tab(p1)
  3080. ## end
  3081.  
  3082.  
  3083. #######################  Matching Procedures #######################
  3084.  
  3085.  
  3086. procedure Re_Arb(plist,i)
  3087. #
  3088. #  Match arbitrary characters (.*)
  3089. #
  3090.    suspend tab(if \plist then Re_skip(plist,i + 1) else 1 to *&subject + 1)
  3091. end
  3092.  
  3093.  
  3094. procedure Re_TabAny(C)
  3095. #
  3096. #  Match a character of a character set ([...],\w,\W,\s,\S,\d,\D
  3097. #)
  3098.    suspend tab(any(C))
  3099. end
  3100.  
  3101.  
  3102. procedure Re_MatchReg(tokList,groupNbr)
  3103. #
  3104. #  Match parenthesized group and assign matched string to list Re_ParenGroup
  3105. #
  3106.    local p,s
  3107.    p := &pos
  3108.    /Re_ParenGroups := []
  3109.    every Re_match1(tokList,1) do {
  3110.       while *Re_ParenGroups < groupNbr do put(Re_ParenGroups)
  3111.       s := &subject[p:&pos]
  3112.       Re_ParenGroups[groupNbr] := s
  3113.       suspend s
  3114.       }
  3115.    Re_ParenGroups[groupNbr] := &null
  3116. end
  3117.  
  3118.  
  3119. procedure Re_WordBoundary(wd,nonwd)
  3120. #
  3121. #  Match word-boundary (\b)
  3122. #
  3123.    suspend ((pos(1),any(wd)) | (pos(0),move(-1),tab(any(wd))) | (move(-1),
  3124.          (tab(any(wd)),any(nonwd)) | (tab(any(nonwd)),any(wd))),"")
  3125. end
  3126.  
  3127.  
  3128. procedure Re_NonWordBoundary(wd,nonwd)
  3129. #
  3130. #  Match non-word-boundary (\B)
  3131. #
  3132.    suspend ((pos(1),any(nonwd)) | (pos(0),move(-1),tab(any(nonwd))) | (move(-1),
  3133.          (tab(any(wd)),any(wd)) | (tab(any(nonwd)),any(nonwd)),""))
  3134. end
  3135.  
  3136.  
  3137. procedure Re_MatchParenGroup(n)
  3138. #
  3139. #  Match same string matched by previous parenthesized group (\N)
  3140. #
  3141.    suspend if s := \Re_ParenGroups[n] then =s else ""
  3142. end
  3143.  
  3144.  
  3145. ###################  Control Operation Procedures  ###################
  3146.  
  3147.  
  3148. procedure Re_ArbNo(tok)
  3149. #
  3150. #  Match any number of times (*)
  3151. #
  3152.    suspend "" | (Re_tok_match(tok) & Re_ArbNo(tok))
  3153. end
  3154.  
  3155.  
  3156. procedure Re_OneOrMore(tok)
  3157. #
  3158. #  Match one or more times (+)
  3159. #
  3160.    suspend Re_tok_match(tok) & Re_ArbNo(tok)
  3161. end
  3162.  
  3163.  
  3164. procedure Re_NToMTimes(tok,n,m)
  3165. #
  3166. #  Match n to m times ({n,m}
  3167. #
  3168.    suspend Re_NTimes(tok,n) & Re_ArbNo(tok)\(m - n + 1)
  3169. end
  3170.  
  3171.  
  3172. procedure Re_NOrMoreTimes(tok,n)
  3173. #
  3174. #  Match n or more times ({n,})
  3175. #
  3176.    suspend Re_NTimes(tok,n) & Re_ArbNo(tok)
  3177. end
  3178.  
  3179.  
  3180. procedure Re_NTimes(tok,n)
  3181. #
  3182. #  Match exactly n times ({n})
  3183. #
  3184.    if n > 0 then
  3185.       suspend Re_tok_match(tok) & Re_NTimes(tok,n - 1)
  3186.    else suspend
  3187. end
  3188.  
  3189.  
  3190. procedure Re_ZeroOrOneTimes(tok)
  3191. #
  3192. #  Match zero or one times (?)
  3193. #
  3194.    suspend "" | Re_tok_match(tok)
  3195. end
  3196.  
  3197.  
  3198. procedure Re_Alt(tokList1,tokList2)
  3199. #
  3200. #  Alternation (|)
  3201. #
  3202.    suspend Re_match1(tokList1 | tokList2,1)
  3203. end
  3204.  
  3205. From icon-group-request@arizona.edu  Thu Nov  7 23:04:51 1991
  3206. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Thu, 7 Nov 91 23:04:51 MST
  3207. Resent-From: icon-group-request@arizona.edu
  3208. Received: from Arizona.edu (Merlin.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  3209.     id AA25028; Thu, 7 Nov 91 23:04:58 MST
  3210. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Thu, 7 Nov
  3211.  1991 23:04 MST
  3212. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA12836; Thu, 7 Nov 91 21:55:40
  3213.  -0800
  3214. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  3215.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  3216.  usenet@ucbvax.Berkeley.EDU if you have questions)
  3217. Resent-Date: Thu, 7 Nov 1991 23:04 MST
  3218. Date: 7 Nov 91 17:44:39 GMT
  3219. From: milton!nntp.uoregon.edu!euclid!haertel@beaver.cs.washington.edu
  3220. Subject: RE: Corrections to regular expression procedures
  3221. Sender: icon-group-request@arizona.edu
  3222. Resent-To: icon-group@cs.arizona.edu
  3223. To: icon-group@arizona.edu
  3224. Resent-Message-Id: <DED5409EE020ABBA@Arizona.edu>
  3225. Message-Id: <1991Nov7.174439.5613@nntp.uoregon.edu>
  3226. X-Envelope-To: icon-group@CS.Arizona.EDU
  3227. X-Vms-To: icon-group@Arizona.edu
  3228. Organization: Department of Mathematics, University of Oregon
  3229. References: <1554@cronos.metaphor.com>,
  3230.  <1991Nov7.161613.2974@midway.uchicago.edu>
  3231.  
  3232. In article <1991Nov7.161613.2974@midway.uchicago.edu> goer@ellis.uchicago.edu (Richard L. Goerwitz) writes:
  3233. >The final big syntax difference (and this one's bitten me time after time)
  3234.  
  3235. Oops, it looks like it bit you again!  Ouch! :-)
  3236.  
  3237. >is the question of when ^, *, and $ are metas.  In awk and egrep, the ^ only
  3238. >has special meaning at SOL after | and (, and also after [ (but note [^-z]).
  3239. >Conversely, $ only indicates EOL after ) and |.  *, +, and ? are only spe-
  3240. >cial in the opposite environments (i.e. NOT after |, ( and ), and also not
  3241. >at SOL, or inside brackets, [*$?], or ^/$ at the end/beginning of a line).
  3242. >In grep, the $ and ^ always have their special meaning.  Note that your
  3243. >egrep command flags things like '(*a)', which I think is good, but isn't the
  3244. >normal egrep way of handling things.
  3245.  
  3246. A good description of how ^, $, and * can lose their special meaning
  3247. depending on surrounding context, but...  it is precisely backwards:
  3248.  
  3249. In awk and egrep, the ^, $, and * symbols have their special meaning
  3250. all the time.  In grep, the ^, $ and * symbols may have their
  3251. special meaning turned off, depending where they appear in the
  3252. regexp, as described above.  The bad news is that the context-dependent
  3253. meanings of $, ^, and * made it into the Posix standard for regular
  3254. expressions, so there is no relief for future grep implementors.
  3255.  
  3256. From @um.cc.umich.edu:Paul_Abrahams@MTS.cc.Wayne.edu  Fri Nov  8 06:51:48 1991
  3257. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Fri, 8 Nov 91 06:51:48 MST
  3258. Received: from mailrus.cc.umich.edu by optima.cs.arizona.edu (4.1/15)
  3259.     id AA12845; Fri, 8 Nov 91 06:51:45 MST
  3260. Received: from um.cc.umich.edu by mailrus.cc.umich.edu (5.61/1123-1.0)
  3261.     id AA26171; Fri, 8 Nov 91 08:47:48 -0500
  3262. Received: from MTS.cc.Wayne.edu by um.cc.umich.edu via MTS-Net; Fri, 8 Nov 91 08:46:48 EST
  3263. Date: Fri, 8 Nov 91 08:46:32 EST
  3264. From: Paul_Abrahams@mts.cc.wayne.edu
  3265. To: icon-group@cs.arizona.edu
  3266. Message-Id: <384006@MTS.cc.Wayne.edu>
  3267. Subject: Obtaining Icon code
  3268.  
  3269. Lots of code has been posted to this forum.  Is there any way to obtain
  3270. it---particularly for people like me who don't have ftp access?
  3271.  
  3272. Paul Abrahams
  3273.  
  3274. From icon-group-request@arizona.edu  Sat Nov  9 12:32:04 1991
  3275. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Sat, 9 Nov 91 12:32:04 MST
  3276. Resent-From: icon-group-request@arizona.edu
  3277. Received: from Arizona.edu (Merlin.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  3278.     id AA04010; Sat, 9 Nov 91 12:32:02 MST
  3279. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Sat, 9 Nov
  3280.  1991 12:31 MST
  3281. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA29311; Sat, 9 Nov 91 11:23:51
  3282.  -0800
  3283. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  3284.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  3285.  usenet@ucbvax.Berkeley.EDU if you have questions)
  3286. Resent-Date: Sat, 9 Nov 1991 12:31 MST
  3287. Date: 9 Nov 91 06:47:40 GMT
  3288. From: fernwood!cronos!laguna!alex@uunet.uu.net (Bob Alexander)
  3289. Subject: Regular expression timings
  3290. Sender: icon-group-request@arizona.edu
  3291. Resent-To: icon-group@cs.arizona.edu
  3292. To: icon-group@arizona.edu
  3293. Resent-Message-Id: <18C15EA7A6600343@Arizona.edu>
  3294. Message-Id: <1580@cronos.metaphor.com>
  3295. X-Envelope-To: icon-group@CS.Arizona.EDU
  3296. X-Vms-To: icon-group@Arizona.edu
  3297. Organization: Metaphor Computer Systems, Mountain View, CA
  3298.  
  3299. From: alex@laguna.metaphor.com (Bob Alexander)
  3300. Newsgroups: comp.lang.icon
  3301. Subject: Regular expression timings
  3302. References: 
  3303. Sender: 
  3304. Followup-To: 
  3305. Distribution: world
  3306. Organization: Metaphor Computer Systems, Mountain View, CA
  3307. Keywords: 
  3308.  
  3309. Here are some timings done comparing regular expression routines in
  3310. Icon and otherwise.  The timings are the result of the C shell "time"
  3311. command applied to the GNU regression test set -- two trials each.
  3312.  
  3313. What surprises me most about these results is that the Icon versions
  3314. are not really all that much slower than standard UNIX egrep (I never
  3315. built GNU egrep, but it's probably faster).  I had expected the Icon
  3316. versions to be several times slower than egrep, but they're not.
  3317.  
  3318. Using the Icon *compiler*, the times might be downright competitive!
  3319.  
  3320. 2.9u  7.2s 0:13 76% 0+108k 0+10io 0pf+0w  standard UNIX egrep (sun4)
  3321. 2.8u  7.2s 0:13 76% 0+112k 0+10io 0pf+0w
  3322.  
  3323. 3.4u 10.5s 0:18 75% 0+176k 0+11io 0pf+0w  igrep
  3324. 3.4u 10.5s 0:18 74% 0+172k 0+ 9io 0pf+0w
  3325.  
  3326. 4.5u 10.7s 0:20 76% 0+188k 0+ 9io 0pf+0w  igrep using findre() instead of
  3327. 4.7u 10.4s 0:20 74% 0+184k 0+10io 0pf+0w  ReFind()
  3328.  
  3329. From icon-group-request@arizona.edu  Sat Nov  9 12:32:58 1991
  3330. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Sat, 9 Nov 91 12:32:58 MST
  3331. Resent-From: icon-group-request@arizona.edu
  3332. Received: from Arizona.edu (Merlin.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  3333.     id AA04029; Sat, 9 Nov 91 12:32:56 MST
  3334. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Sat, 9 Nov
  3335.  1991 12:32 MST
  3336. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA29032; Sat, 9 Nov 91 11:16:09
  3337.  -0800
  3338. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  3339.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  3340.  usenet@ucbvax.Berkeley.EDU if you have questions)
  3341. Resent-Date: Sat, 9 Nov 1991 12:32 MST
  3342. Date: 9 Nov 91 06:16:04 GMT
  3343. From: midway!ellis!goer@uunet.uu.net (Richard L. Goerwitz)
  3344. Subject: RE: Latest regexp.icn
  3345. Sender: icon-group-request@arizona.edu
  3346. Resent-To: icon-group@cs.arizona.edu
  3347. To: icon-group@arizona.edu
  3348. Resent-Message-Id: <18E26E8D76600344@Arizona.edu>
  3349. Message-Id: <1991Nov9.061604.3716@midway.uchicago.edu>
  3350. X-Envelope-To: icon-group@CS.Arizona.EDU
  3351. X-Vms-To: icon-group@Arizona.edu
  3352. Organization: University of Chicago
  3353. References: <1576@cronos.metaphor.com>
  3354.  
  3355. In <1576@cronos.metaphor.com> alex@laguna.metaphor.com (Bob Alexander) writes:
  3356.  
  3357. >I'm not sure if anyone really cares about such minor differences
  3358. >concerning only incorrect regular expressions.  My inclination is to
  3359. >leave the code as is.  It could be changed to pass the GNU tests, but
  3360. >that would result in (probably) more code.  My objective was to create
  3361. >useful, correct RE procedures, not really to create an *exact*
  3362. >duplicate of any existing product.
  3363.  
  3364. I can't speak for anyone but myself, but after long and intense use of
  3365. regular expressions for natural language processing tasks of various
  3366. I've found that some of the small differences we have been discussing
  3367. are actually very important to experienced hands.  If you want me to
  3368. prioritize, then I'd say that things like "\" and "[^]" are not really
  3369. all that vital.  But the question of where metacharacters have their
  3370. special meaning, where they are literals, and where they are errors,
  3371. is really very important.
  3372.  
  3373. This is just my personal opinion.  It's been formed over several years
  3374. of almost daily work in natural language parsing and processing.  It's
  3375. not so much a religious thing as a practical one.  Let me give you a
  3376. typical example that every sysadmin can relate to.  Very often, in con-
  3377. junction with the find command, I find myself checking quickly through
  3378. lots of compressed files, trying to find a given pattern (and the name
  3379. of the file it occurs in):
  3380.  
  3381.     find . -name '*.Z' -exec zcat {} \; -print | egrep '(^\./|pattern)'
  3382.  
  3383. There are other examples I could list, but this one will suffice to illus-
  3384. trate the point.  Your earlier incarnation of igrep handles this expression
  3385. like UNIX grep, not egrep.  It therefore fails in precisely those situations
  3386. where I expect it to accept a line.  Since your procedures are geared mainly
  3387. for egrep-style patterns, this inconsistency could be maddening unless well
  3388. documented.  And if it came to this, I'd wonder whether it might not be bet-
  3389. ter simply to re-code in accordance with the standard.
  3390.  
  3391. So in general, I'd reiterate that some of those little things count for a
  3392. lot.
  3393.  
  3394. I can't speak for the PERL extensions, incidentally, since I'm only a casual
  3395. PERL user.  I've never really gotten out of the habit of just using sed,
  3396. awk, and what not.
  3397.  
  3398. -- 
  3399.  
  3400.    -Richard L. Goerwitz              goer%sophist@uchicago.bitnet
  3401.    goer@sophist.uchicago.edu         rutgers!oddjob!gide!sophist!goer
  3402.  
  3403. From icon-group-request@arizona.edu  Sat Nov  9 13:02:44 1991
  3404. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Sat, 9 Nov 91 13:02:44 MST
  3405. Resent-From: icon-group-request@arizona.edu
  3406. Received: from Arizona.edu (Merlin.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  3407.     id AA04863; Sat, 9 Nov 91 13:02:42 MST
  3408. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Sat, 9 Nov
  3409.  1991 13:02 MST
  3410. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA00687; Sat, 9 Nov 91 11:57:56
  3411.  -0800
  3412. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  3413.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  3414.  usenet@ucbvax.Berkeley.EDU if you have questions)
  3415. Resent-Date: Sat, 9 Nov 1991 13:02 MST
  3416. Date: 9 Nov 91 07:29:47 GMT
  3417. From: uakari.primate.wisc.edu!sdd.hp.com!cs.utexas.edu!uwm.edu!linac!midway!ellis!goer@ames.arc.nasa.gov
  3418.  (Richard L. Goerwitz)
  3419. Subject: RE: Latest regexp.icn (mods to the preceding)
  3420. Sender: icon-group-request@arizona.edu
  3421. Resent-To: icon-group@cs.arizona.edu
  3422. To: icon-group@arizona.edu
  3423. Resent-Message-Id: <1D06576006600395@Arizona.edu>
  3424. Message-Id: <1991Nov9.072947.6283@midway.uchicago.edu>
  3425. X-Envelope-To: icon-group@CS.Arizona.EDU
  3426. X-Vms-To: icon-group@Arizona.edu
  3427. Organization: University of Chicago
  3428. References: <1576@cronos.metaphor.com>,
  3429.  <1991Nov9.061604.3716@midway.uchicago.edu>
  3430.  
  3431. >    find . -name '*.Z' -exec zcat {} \; -print | egrep '(^\./|pattern)'
  3432. >
  3433. >Your earlier incarnation of igrep handles this expression like UNIX grep,
  3434. >not egrep.
  3435.  
  3436. Hmmm.  Just checked your latest version, and presto, it works like egrep,
  3437. so that's one thing I'd call a possibly important incompatibility solved.
  3438. But while checking I noticed something else.  Try this:
  3439.  
  3440. procedure main()
  3441.     if ReFind("lo", "hello", -3, 0) > 3
  3442. #    if find("lo", "hello", -3, 0) > 3
  3443.     then write("okay")
  3444.     else write("nogo")
  3445. end
  3446.  
  3447. Getting the defaults right for &subject and &pos, accounting for negative
  3448. values, and checking for out-of-bounds values is a bit of a headache.  It's
  3449. also technically legal to say this:
  3450.  
  3451.     "hello" ? find("ll", &null, 3, 5)
  3452.  
  3453. So I'd expect this to be okay, too:
  3454.  
  3455.     "hello" ? ReFind("ll", &null, 3, 5)
  3456.  
  3457. This is kind of hard (*I* think) to get right.  Maybe others haven't had the
  3458. same problems I've had, and maybe in your case, Bob, you didn't want to bo-
  3459. ther with full emulation of the builtins' behavior.  When I'm trying to go
  3460. the whole nine yards, I usually do something like this:
  3461.  
  3462.     if /s := &subject
  3463.     then default_val := &pos
  3464.     else default_val := 1
  3465.  
  3466.     if \i then {
  3467.     if i < 1 then
  3468.         i := *s + (i+1)
  3469.     }
  3470.     else i := default_val
  3471.     
  3472.     if \j then {
  3473.     if j < 1 then
  3474.         j := *s + (j+1)
  3475.     }
  3476.     else j := *s+1
  3477.  
  3478. Oh, and one thing I often forget is to switch i and j around if j is bigger
  3479. than i.  You need to do that after setting all the defaults.  That's how the
  3480. builtins do it.  Right now, Re{match,find} don't do this, and it yields some
  3481. backwards results.
  3482.  
  3483. I see you don't need to check if i and j are in range the way your doing
  3484. things.  The subscript expression will just fail, and you'll achieve the
  3485. desired result automatically if i and/or j is out of range.
  3486.  
  3487. This is very subtle stuff, in my opinion, but over time I've killed myself
  3488. enough times straying from standard i,j builtin behavior that I've just
  3489. thrown in the towel, and followed the patterns I see in the source code for
  3490. the builtins.  Maybe this is nit-picking.  Thought it might be interesting
  3491. to post, though, and see if anyone else cares about such things.
  3492.  
  3493. -- 
  3494.  
  3495.    -Richard L. Goerwitz              goer%sophist@uchicago.bitnet
  3496.    goer@sophist.uchicago.edu         rutgers!oddjob!gide!sophist!goer
  3497.  
  3498. From icon-group-request@arizona.edu  Sat Nov  9 14:22:03 1991
  3499. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Sat, 9 Nov 91 14:22:03 MST
  3500. Resent-From: icon-group-request@arizona.edu
  3501. Received: from Arizona.edu (Maggie.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  3502.     id AA06672; Sat, 9 Nov 91 14:21:59 MST
  3503. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Sat, 9 Nov
  3504.  1991 14:20 MST
  3505. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA02988; Sat, 9 Nov 91 13:04:21
  3506.  -0800
  3507. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  3508.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  3509.  usenet@ucbvax.Berkeley.EDU if you have questions)
  3510. Resent-Date: Sat, 9 Nov 1991 14:21 MST
  3511. Date: 9 Nov 91 08:49:12 GMT
  3512. From: cis.ohio-state.edu!pacific.mps.ohio-state.edu!linac!midway!ellis!goer@ucbvax.berkeley.edu (Richard
  3513.  L. Goerwitz)
  3514. Subject: RE: Regular expression timings
  3515. Sender: icon-group-request@arizona.edu
  3516. Resent-To: icon-group@cs.arizona.edu
  3517. To: icon-group@arizona.edu
  3518. Resent-Message-Id: <280C1A4926600442@Arizona.edu>
  3519. Message-Id: <1991Nov9.084912.9703@midway.uchicago.edu>
  3520. X-Envelope-To: icon-group@CS.Arizona.EDU
  3521. X-Vms-To: icon-group@Arizona.edu
  3522. Organization: University of Chicago
  3523. References: <1580@cronos.metaphor.com>
  3524.  
  3525. In <1580@cronos.metaphor.com> alex@laguna.metaphor.com (Bob Alexander) writes:
  3526. >
  3527. >Here are some timings done comparing regular expression routines in
  3528. >Icon and otherwise...
  3529. >
  3530. >What surprises me most about these results is that the Icon versions
  3531. >are not really all that much slower than standard UNIX egrep (I never
  3532. >built GNU egrep, but it's probably faster).  I had expected the Icon
  3533. >versions to be several times slower than egrep, but they're not.
  3534.  
  3535. I'd guess that what you're actually testing in the cases you cited is
  3536. the speed of compilation.  Load and startup time is absorbed largely by
  3537. the sys time in the "time" command's output, but it doesn't take into
  3538. account how long the executable takes to initialize and compile the
  3539. regular expression.  I'll wager that if you take a standard-size file,
  3540. say 50k or so, and run each of the greps on it, you'll find that the
  3541. Icon-based ones are significantly slower.
  3542.  
  3543. I just tried doing an "egrep find regexp.icn" using your igrep, my system
  3544. egrep command, and GNU egrep.  Igrep was 1.3u, while both GNU and my sys-
  3545. tem egrep took up so little time that the system registered it as 0.0u.
  3546.  
  3547. I've run a lot of indexing and text retrieval programs, and I've always
  3548. found that it was well worth going through all the trouble of writing data
  3549. to a temp file, then turning the system egrep command loose on it, rather
  3550. than to try to use my findre.  I'd like to see whether your program will
  3551. run fast enough to make the difference less pronounced, or at least to
  3552. give me a secondary option on systems that don't have pipes, and don't
  3553. have a regexp-based pattern finder in the system inventory.  Sounds like it
  3554. might (which would make my day!).
  3555.  
  3556. -- 
  3557.  
  3558.    -Richard L. Goerwitz              goer%sophist@uchicago.bitnet
  3559.    goer@sophist.uchicago.edu         rutgers!oddjob!gide!sophist!goer
  3560.  
  3561. From icon-group-request@arizona.edu  Sat Nov  9 19:02:44 1991
  3562. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Sat, 9 Nov 91 19:02:44 MST
  3563. Resent-From: icon-group-request@arizona.edu
  3564. Received: from Arizona.edu (Maggie.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  3565.     id AA13244; Sat, 9 Nov 91 19:02:42 MST
  3566. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Sat, 9 Nov
  3567.  1991 19:02 MST
  3568. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA11401; Sat, 9 Nov 91 17:45:49
  3569.  -0800
  3570. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  3571.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  3572.  usenet@ucbvax.Berkeley.EDU if you have questions)
  3573. Resent-Date: Sat, 9 Nov 1991 19:02 MST
  3574. Date: 9 Nov 91 23:31:47 GMT
  3575. From: fernwood!cronos!laguna!alex@uunet.uu.net (Bob Alexander)
  3576. Subject: More fixes to regexp.icn
  3577. Sender: icon-group-request@arizona.edu
  3578. Resent-To: icon-group@cs.arizona.edu
  3579. To: icon-group@arizona.edu
  3580. Resent-Message-Id: <4F519F2706600643@Arizona.edu>
  3581. Message-Id: <1581@cronos.metaphor.com>
  3582. X-Envelope-To: icon-group@CS.Arizona.EDU
  3583. X-Vms-To: icon-group@Arizona.edu
  3584. Organization: Metaphor Computer Systems, Mountain View, CA
  3585.  
  3586. Next round of bug fixes -- minor but nonetheless bugs.
  3587.  
  3588. From Richard G.:
  3589.  
  3590. > Getting the defaults right for &subject and &pos, accounting for negative
  3591. > values, and checking for out-of-bounds values is a bit of a headache.
  3592. >    ...
  3593. > This is kind of hard (*I* think) to get right.  Maybe others haven't had the
  3594. > same problems I've had ...
  3595.  
  3596. Well, obviously *this* programmer had some difficulty, too, since there
  3597. were errors.  One can consider oneself as a slick coder until someone
  3598. *actually uses* the code :-).  But seriously, I really appreciate the
  3599. enthusiastic help and am having a lot of fun with this.  (I think I'm
  3600. going to have to revisit some other procedures I've written that have
  3601. the same defaulting bugs).
  3602.  
  3603. These bugs are minor enough that I won't repost the whole huge thing
  3604. again, but replacement of the body of ReMatch with the following
  3605. appears to handle the defaults properly.  The same sort of changes
  3606. should also be applied to ReFind.
  3607.  
  3608.    local i                            <-- new
  3609.    if type(plist) ~== "list" then plist := RePat(plist) | fail
  3610.    if /s := &subject then /i1 := &pos else /i1 := 1 ; /i2 := 0    <-- changed
  3611.    s ? {(tab(i1),i := &pos,s := tab(i2)) | fail ; i >:= &pos}    <-- new
  3612.    Re_ParenGroups := []
  3613.    suspend s ? (Re_match1(plist,1),i + &pos - 1)        <-- changed
  3614.  
  3615. Since providing the defaults for builtin-like user-defined scanning
  3616. procedures is tricky, and it is a recurring problem, maybe it would be
  3617. useful to have a handy procedure to do the job unerringly every time,
  3618. e.g.:
  3619.  
  3620.   #
  3621.   #  returns a list of
  3622.   #      [<substring to match>,<starting position in original string>]
  3623.   #
  3624.   procedure defaults(s,i1,i2)
  3625.      if /s := &subject then
  3626.     /i1 := &pos
  3627.      else
  3628.     /i1 := 1
  3629.      /i2 := 0
  3630.      s ? {
  3631.     (tab(i1) & i1 := &pos & s := tab(i2)) | fail
  3632.     i1 >:= &pos
  3633.     }
  3634.      return [s,i1]
  3635.   end
  3636.  
  3637.  
  3638. The ReMatch procedure body could then be written as:
  3639.  
  3640.    local i
  3641.    if type(plist) ~== "list" then plist := RePat(plist) | fail
  3642.    d := defaults(s,i1,i2) | fail
  3643.    Re_ParenGroups := []
  3644.    suspend d[1] ? (Re_match1(plist,1),d[2] + &pos - 1)
  3645.  
  3646.  
  3647. Comments?  Improvements?  Would this be a useful IPL procedure?
  3648.  
  3649. -- Bob
  3650.  
  3651. From icon-group-request@arizona.edu  Sat Nov  9 19:35:08 1991
  3652. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Sat, 9 Nov 91 19:35:08 MST
  3653. Resent-From: icon-group-request@arizona.edu
  3654. Received: from Arizona.edu (Merlin.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  3655.     id AA14177; Sat, 9 Nov 91 19:35:04 MST
  3656. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Sat, 9 Nov
  3657.  1991 19:34 MST
  3658. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA12384; Sat, 9 Nov 91 18:19:16
  3659.  -0800
  3660. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  3661.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  3662.  usenet@ucbvax.Berkeley.EDU if you have questions)
  3663. Resent-Date: Sat, 9 Nov 1991 19:34 MST
  3664. Date: 9 Nov 91 01:05:38 GMT
  3665. From: fernwood!cronos!laguna!alex@uunet.uu.net (Bob Alexander)
  3666. Subject: Latest regexp.icn
  3667. Sender: icon-group-request@arizona.edu
  3668. Resent-To: icon-group@cs.arizona.edu
  3669. To: icon-group@arizona.edu
  3670. Resent-Message-Id: <53D66BE646600690@Arizona.edu>
  3671. Message-Id: <1576@cronos.metaphor.com>
  3672. X-Envelope-To: icon-group@CS.Arizona.EDU
  3673. X-Vms-To: icon-group@Arizona.edu
  3674. Organization: Metaphor Computer Systems, Mountain View, CA
  3675.  
  3676. Hopefully we'll soon get past the point where a new version of these
  3677. regular expression routines gets posted daily.
  3678.  
  3679. I've finally had a chance to look over the last round of bug reports on
  3680. the regular expression code.  I found (1) one more real bug, (2) one
  3681. questionable item in the bug report, and (3) some cases where
  3682. syntactically incorrect (or at least really wierd) regular expressions
  3683. were handled differently.
  3684.  
  3685. (1)
  3686.  
  3687. I downloaded the GNU test suite, and discovered a bug when trying the
  3688. Khadafy test.  In a pattern like [-z], the dash should be interpreted
  3689. as a dash rather than as a range operator (so the pattern matches
  3690. either a dash or a z).  This wasn't working, and it's fixed in the
  3691. attached copy.
  3692.  
  3693. Just for fun, this is the Khadafy test expression:
  3694.  
  3695.     M[ou]'?am+[ae]r .*([AEae]l[- ])?[GKQ]h?[aeu]+([dtz][dhz]?)+af[iy]
  3696.  
  3697.                                ^  Used to fail here.
  3698.                                |
  3699.  
  3700. (2)
  3701.  
  3702. One of the bugs mentioned is not really a bug (IMHO).
  3703. Richard Goerwitz's comment:
  3704.  
  3705. > The new routines do have a few equally new bugs.  For instance, it seems
  3706. > that ^ is interpreted as a metacharacter in the context [^-z], where the
  3707. > precedence of the "-" should make it interpreted as a regular character.
  3708.  
  3709. In a [...] construct, a ^ in the first position complements the
  3710. following "cset", and a "-" in the front is taken as itself rather than
  3711. in its meta-meaning as a range operator.  So [^-z] parses to mean:  any
  3712. character but "-" or "z".  This seems to be how UNIX egrep handles it.
  3713. Mine does too, but it used to fail due to the bug mentioned above (1).
  3714.  
  3715. (3)
  3716.  
  3717. Some of the discrepancies are in handling of badly-formed regular
  3718. expressions.  Among GNU, UNIX, and mine, some errors are reported, and
  3719. other errors are not reported but some interpretation is made of the
  3720. erroneous construct. E.g., Richard G. writes:
  3721.  
  3722. > The expression [^] should incite a syntax error, too (so SYSV egrep, and
  3723. > also its GNU equivalent).  I'm just as happy it doesn't, but I wonder how
  3724. > it't being interpreted.
  3725.  
  3726. My routine takes this as a literal '^', where GNU calls it an error.
  3727. (Kind of the opposite of the reaction to "*a", where mine calls it an
  3728. error but GNU doesn't).
  3729.  
  3730. The remaining few discrepancies detected by the GNU test suite are of
  3731. this nature (see the test results, below).  Note that the discrepancies
  3732. in UNIX egrep are also for wierd REs except the last which, it seems to
  3733. me, should match.
  3734.  
  3735. I'm not sure if anyone really cares about such minor differences
  3736. concerning only incorrect regular expressions.  My inclination is to
  3737. leave the code as is.  It could be changed to pass the GNU tests, but
  3738. that would result in (probably) more code.  My objective was to create
  3739. useful, correct RE procedures, not really to create an *exact*
  3740. duplicate of any existing product.
  3741.  
  3742. I modified the GNU test driver to provide more information on
  3743. failures.  Here are the failures using the attached procedure:
  3744.  
  3745. Status code legend: 0 - match; 1 - no match; 2 - syntax error
  3746.  
  3747. GNU test results with igrep
  3748. ---------------------------
  3749.  
  3750. Test 52. Pattern: '*a'; String: '-'; Expected status: 1
  3751. Spencer test #52 failed: status: 2
  3752.  
  3753. Test 55. Pattern: '(*)b'; String: '-'; Expected status: 1
  3754. Spencer test #55 failed: status: 2
  3755.  
  3756. Test 57. Pattern: 'a\'; String: '-'; Expected status: 2
  3757. Spencer test #57 failed: status: 1
  3758.  
  3759. Test 62. Pattern: 'abc)'; String: '-'; Expected status: 2
  3760. Spencer test #62 failed: status: 1
  3761.  
  3762.  
  3763. GNU test results with UNIX sun4 egrep
  3764. -------------------------------------
  3765.  
  3766. Test 50. Pattern: '()ef'; String: 'def'; Expected status: 0
  3767. Spencer test #50 failed: status: 2
  3768.  
  3769. Test 51. Pattern: '()*'; String: '-'; Expected status: 0
  3770. Spencer test #51 failed: status: 2
  3771.  
  3772. Test 52. Pattern: '*a'; String: '-'; Expected status: 1
  3773. Spencer test #52 failed: status: 2
  3774.  
  3775. Test 55. Pattern: '(*)b'; String: '-'; Expected status: 1
  3776. Spencer test #55 failed: status: 2
  3777.  
  3778. Test 56. Pattern: '$b'; String: 'b'; Expected status: 1
  3779. Spencer test #56 failed: status: 0
  3780.  
  3781. Test 71. Pattern: '(a|)*'; String: '-'; Expected status: 0
  3782. Spencer test #71 failed: status: 2
  3783.  
  3784. Test 78. Pattern: '(ab|)*'; String: '-'; Expected status: 0
  3785. Spencer test #78 failed: status: 2
  3786.  
  3787. Test 94. Pattern: '(abc|)ef'; String: 'abcdef'; Expected status: 0
  3788. Spencer test #94 failed: status: 2
  3789.  
  3790. Test 122. Pattern: '(....).*\1'; String: 'beriberi'; Expected status: 0
  3791. Spencer test #122 failed: status: 1
  3792.  
  3793.  
  3794. ############################################################################
  3795. #
  3796. #    Name:    regexp.icn
  3797. #
  3798. #    Title:    UNIX-like Regular Expression Pattern Matching Procedures
  3799. #
  3800. #    Author: Robert J. Alexander
  3801. #
  3802. #    Date:    November 8, 1991
  3803. #
  3804. ############################################################################
  3805. #
  3806. #  This is a kit of procedures to deal with UNIX-like regular expression
  3807. #  patterns.
  3808. #
  3809. #  These procedures are interesting partly because of the "recursive
  3810. #  suspension" (or "suspensive recursion" :-) technique used to simulate
  3811. #  conjunction of an arbitrary number of computed expressions (see
  3812. #  notes, below).
  3813. #
  3814. #
  3815. #  The public procedures are:
  3816. #
  3817. #  ReMatch(pattern,s,i1,i2) : i3,i4,...,iN
  3818. #  ReFind(pattern,s,i1,i2) : i3,i4,...,iN
  3819. #  RePat(s) : pattern list
  3820. #
  3821. #
  3822. #  ReMatch() produces the sequence of positions in "s" past a substring
  3823. #  starting at "i1" that matches "pattern", but fails if there is no
  3824. #  such position.  Similar to match(), but is capable of generating
  3825. #  multiple positions.
  3826. #
  3827. #  ReFind() produces the sequence of positions in "s" where substrings
  3828. #  begin that match "pattern", but fails if there is no such position.
  3829. #  Similar to find().  Each position is produced only once, even if
  3830. #  several possible matches are possible at that position.
  3831. #
  3832. #  "pattern" can be either a string or a pattern list -- see RePat(),
  3833. #  below.
  3834. #
  3835. #  Default values of s, i1, and i2 are handled as for Icon's built-in
  3836. #  string scanning procedures such as match().
  3837. #
  3838. #
  3839. #  RePat(s) : L
  3840. #
  3841. #  Creates a pattern element list from pattern string "s", but fails if
  3842. #  the pattern string is not syntactically correct.  ReMatch() and
  3843. #  ReFind() will automatically convert a pattern string to a pattern
  3844. #  list, but it is faster to do the conversion explicitly if multiple
  3845. #  operations are done using the same pattern.  An additional advantage
  3846. #  to compiling the pattern separately is avoiding ambiguity of failure
  3847. #  caused by an incorrect pattern and failure to match a correct pattern.
  3848. #
  3849. #
  3850. #  Accessible Global Variables
  3851. #
  3852. #  After a match, the strings matched by parenthesized regular
  3853. #  expressions are left in list "Re_ParenGroups", and can be accessed by
  3854. #  subscripting in using the same number as the \N construct.
  3855. #
  3856. #  If it is desired that regular expression format be similar to UNIX
  3857. #  filename generation patterns but still retain the power of full
  3858. #  regular expressions, make the following assignments prior to
  3859. #  compiling the pattern string:
  3860. #
  3861. #    Re_ArbString := "*"    # Defaults to ".*"
  3862. #    Re_AnyString := "?"    # Defaults to "."
  3863. #
  3864. #  The sets of characters (csets) that define a word, digits, and white
  3865. #  space can be modified.  The following assignments can be made before
  3866. #  compiling the pattern string.  The character sets are captured when
  3867. #  the pattern is compiled, so changing them after pattern compilation
  3868. #  will not alter the behavior of matches unless the pattern string is
  3869. #  recompiled.
  3870. #
  3871. #    Re_WordChars := 'whatever you like'
  3872. #            # Defaults to &letters ++ &digits ++ "_"
  3873. #    Re_Digits := &digits ++ 'ABCDEFabcdef'
  3874. #            # Defaults to &digits
  3875. #    Re_Space := 'whatever you like'
  3876. #            # Defaults to ' \t\v\n\r\f'
  3877. #
  3878. #  These globals are normally not initialized until the first call to
  3879. #  RePat(), and then only if they are null.  They can be explicitly
  3880. #  initialized to their defaults (if they are null) by calling
  3881. #  Re_Default().
  3882. #
  3883. #  Characters compiled into patterns can be passed through a
  3884. #  user-supplied filter procedure, provided in global variable
  3885. #  Re_Filter.  The filtering is done before the characters are bound
  3886. #  into the pattern.  The filter proc is passed one argument, the string
  3887. #  to filter, and it must return the filtered string as its result.  If
  3888. #  the filter proc fails, the string will be used unfiltered.  The
  3889. #  filter proc is called with an argument of either type string (for
  3890. #  characters in the pattern) or cset (for character classes [...]).  A
  3891. #  typical use for this facility is to implement case-independent
  3892. #  matching.  All pattern characters can downshifted by assigning
  3893. #
  3894. #    Re_Filter := map
  3895. #
  3896. #  Filtering is done only as the pattern is compiled.  Filtering of
  3897. #  strings to be matched must be explicitly done.  Therefore,
  3898. #  case-independent matching will occur only if map() is applied to all
  3899. #  strings to be matched.
  3900. #
  3901. #  In the case of patterns containing alternation, ReFind() will
  3902. #  generally not produce positions in increasing order, but will produce
  3903. #  all positions from the first term of the alternation (in increasing
  3904. #  order) followed by all positions from the second (in increasing
  3905. #  order).  If it is necessary that the positions be generated in
  3906. #  strictly increasing order, with no duplicates, assign any non-null
  3907. #  value to Re_Ordered:
  3908. #
  3909. #    Re_Ordered := 1
  3910. #
  3911. #  If the Re_Ordered options is chosen, there is a *small* penalty in
  3912. #  efficiency in some cases, and the co-expression facility is required
  3913. #  in your Icon implementation.  Example:
  3914. #  
  3915. #
  3916. #  Regular Expression Characters and Features Supported
  3917. #
  3918. #  The regular expression format supported by procedures in this file
  3919. #  model very closely those supported by the UNIX "egrep" program, with
  3920. #  modifications as in the Perl programming language definition.
  3921. #  Following is a brief description of the special characters used in
  3922. #  regular expressions.  In the description, the abbreviation RE means
  3923. #  regular expression.
  3924. #
  3925. #  c        An ordinary character (not one of the special characters
  3926. #        discussed below) is a one-character RE that matches that
  3927. #        character.
  3928. #
  3929. #  \c        A backslash followed by any special character is a one-
  3930. #        character RE that matches the special character itself.
  3931. #
  3932. #        Note that backslash escape sequences representing
  3933. #        non-graphic characters are not supported directly
  3934. #        by these procedures.  Of course, strings coded in an
  3935. #        Icon program will have such escapes handled by the
  3936. #        Icon translator.  If such escapes must be supported
  3937. #        in strings read from the run-time environment (e.g.
  3938. #        files), they will have to be converted by other means,
  3939. #        such as the Icon Program Library procedure "escape()".
  3940. #
  3941. #  .        A period is a one-character RE that matches any
  3942. #        character.
  3943. #
  3944. #  [string]    A non-empty string enclosed in square brackets is a one-
  3945. #        character RE that matches any *one* character of that
  3946. #        string.  If, the first character is "^" (circumflex),
  3947. #        the RE matches any character not in the remaining
  3948. #        characters of the string.  The "-" (minus), when between
  3949. #        two other characters, may be used to indicate a range of
  3950. #        consecutive ASCII characters (e.g. [0-9] is equivalent to
  3951. #        [0123456789]).  Other special characters stand for
  3952. #        themselves in a bracketed string.
  3953. #
  3954. #  *        Matches zero or more occurrences of the RE to its left.
  3955. #
  3956. #  +        Matches one or more occurrences of the RE to its left.
  3957. #
  3958. #  ?        Matches zero or one occurrences of the RE to its left.
  3959. #
  3960. #  {N}        Matches exactly N occurrences of the RE to its left.
  3961. #
  3962. #  {N,}        Matches at least N occurrences of the RE to its left.
  3963. #
  3964. #  {N,M}    Matches at least N occurrences but at most M occurrences
  3965. #        of the RE to its left.
  3966. #
  3967. #  ^        A caret at the beginning of an entire RE constrains
  3968. #        that RE to match an initial substring of the subject
  3969. #        string.
  3970. #
  3971. #  $        A currency symbol at the end of an entire RE constrains
  3972. #        that RE to match a final substring of the subject string.
  3973. #
  3974. #  |        Alternation: two REs separated by "|" match either a
  3975. #        match for the first or a match for the second.
  3976. #
  3977. #  ()        A RE enclosed in parentheses matches a match for the
  3978. #        regular expression (parenthesized groups are used
  3979. #        for grouping, and for accessing the matched string
  3980. #        subsequently in the match using the \N expression).
  3981. #
  3982. #  \N        Where N is a digit in the range 1-9, matches the same
  3983. #        string of characters as was matched by a parenthesized
  3984. #        RE to the left in the same RE.  The sub-expression
  3985. #        specified is that beginning with the Nth occurrence
  3986. #        of "(" counting from the left.  E.g., ^(.*)\1$ matches
  3987. #        a string consisting of two consecutive occurrences of
  3988. #        the same string.
  3989. #
  3990. #  Perl Extensions
  3991. #
  3992. #  The following extensions to UNIX REs, as specified in the Perl
  3993. #  programming language, are supported.
  3994. #
  3995. #  \w        Matches any alphanumeric (including "_").
  3996. #  \W        Matches any non-alphanumeric.
  3997. #
  3998. #  \b        Matches only at a word-boundary (word defined as a string
  3999. #        of alphanumerics as in \w).
  4000. #  \B        Matches only non-word-boundaries.
  4001. #
  4002. #  \s        Matches any white-space character.
  4003. #  \S        Matches any non-white-space character.
  4004. #
  4005. #  \d        Matches any digit [0-9].
  4006. #  \D        Matches any non-digit.
  4007. #
  4008. #  \w, \W, \s, \S, \d, \D can be used within [string] REs.
  4009. #
  4010. #
  4011. #  Note on Details of Matching
  4012. #
  4013. #  The method of matching differs a bit from UNIX-style regular
  4014. #  expressions -- particularly where closures are concerned ("*", "+",
  4015. #  "{}", "?").  UNIX regular expressions are documented to match the
  4016. #  "longest, leftmost" strings in cases where a choice is needed.  The
  4017. #  procedures in this file are capable of generating all possible
  4018. #  matches of the pattern, and generate the possibilities by matching
  4019. #  the fewest first ("shortest, leftmost").  Matching of the various
  4020. #  pattern elements is performed exactly as though it were an Icon
  4021. #  conjunction of the pattern elements.
  4022. #
  4023. #
  4024. #  Notes on computed conjunction expressions by "suspensive recursion"
  4025. #
  4026. #  A conjunction expression of an arbitrary number of terms can be
  4027. #  computed in a looping fashion by the following recursive technique:
  4028. #
  4029. #    procedure Conjunct(v)
  4030. #       if <there is another term to be appended to the conjunction> then
  4031. #          suspend Conjunct(<the next term expression>)
  4032. #       else
  4033. #          suspend v
  4034. #    end
  4035. #
  4036. #  The argument "v" is needed for producing the value of the last term
  4037. #  as the value of the conjunction expression, accurately modeling Icon
  4038. #  conjunction.  If the value of the conjunction is not needed, the
  4039. #  technique can be slightly simplified by eliminating "v":
  4040. #
  4041. #    procedure ConjunctAndProduceNull()
  4042. #       if <there is another term to be appended to the conjunction> then
  4043. #          suspend ConjunctAndProduceNull(<the next term expression>)
  4044. #       else
  4045. #          suspend
  4046. #    end
  4047. #
  4048. #  Note that <the next term expression> must still remain in the suspend
  4049. #  expression to test for failure of the term, although its value is not
  4050. #  passed to the recursive invocation,  This could have been coded as
  4051. #
  4052. #          suspend <the next term expression> & ConjunctAndProduceNull()
  4053. #
  4054. #  but wouldn't have been as provocative.
  4055. #
  4056. #  Since the computed conjunctions in this program are evaluated only for
  4057. #  their side effects, the second technique is used in two situations:
  4058. #
  4059. #    (1)    To compute the conjunction of all of the elements in the
  4060. #        regular expression pattern list (Re_match1()).
  4061. #
  4062. #    (2)    To evaluate the "exactly N times" and "N to M times"
  4063. #        control operations (Re_NTimes()).
  4064. #
  4065.  
  4066.  
  4067. record Re_Tok(proc,args)
  4068.  
  4069. global Re_ParenGroups,Re_Filter,Re_Ordered
  4070. global Re_WordChars,Re_NonWordChars
  4071. global Re_Space,Re_NonSpace
  4072. global Re_Digits,Re_NonDigits
  4073. global Re_ArbString,Re_AnyString
  4074. global Re_TabMatch
  4075.  
  4076.  
  4077. ###################  Pattern Translation Procedures  ###################
  4078.  
  4079.  
  4080. procedure RePat(s) # L
  4081. #
  4082. #  Produce pattern list representing pattern string s.
  4083. #
  4084.    #
  4085.    #  Create a list of pattern elements.  Pattern strings are parsed
  4086.    #  and converted into list elements as shown in the following table.
  4087.    #  Since some list elements reference other pattern lists, the
  4088.    #  structure is really a tree.
  4089.    #
  4090.    # Token    Generates            Matches...
  4091.    # -----    ---------            ----------
  4092.    #  ^        Re_Tok(pos,[1])            Start of string or line
  4093.    #  $        Re_Tok(pos,[0])            End of string or line
  4094.    #  .        Re_Tok(move,[1])        Any single character
  4095.    #  +        Re_Tok(Re_OneOrMore,[tok])    At least one occurrence of
  4096.    #                        previous token
  4097.    #  *        Re_Tok(Re_ArbNo,[tok])        Zero or more occurrences of
  4098.    #                        previous token
  4099.    #  |        Re_Tok(Re_Alt,[pattern,pattern]) Either of prior expression
  4100.    #                        or next expression
  4101.    #  [...]    Re_Tok(Re_TabAny,[cset])    Any single character in
  4102.    #                        specified set (see below)
  4103.    #  (...)    Re_Tok(Re_MatchReg,[pattern])    Parenthesized pattern as
  4104.    #                        single token
  4105.    #  <string of non-special characters>    The string of no-special
  4106.    #        Re_Tok(Re+TabMatch,string)      characters
  4107.    #  \b    Re_Tok(Re_WordBoundary,[Re_WordChars,Re_NonWordChars])
  4108.    #                        A word-boundary
  4109.    #                          (word default: [A-Za-z0-9_]+)
  4110.    #  \B    Re_Tok(Re_NonWordBoundary,[Re_WordChars,Re_NonWordChars])
  4111.    #                        A non-word-boundary
  4112.    #  \w    Re_Tok(Re_TabAny,[Re_WordChars])A word-character
  4113.    #  \W    Re_Tok(Re_TabAny,[Re_NonWordChars]) A non-word-character
  4114.    #  \s    Re_Tok(Re_TabAny,[Re_Space])    A space-character
  4115.    #  \S    Re_Tok(Re_TabAny,[Re_NonSpace])    A non-space-character
  4116.    #  \d    Re_Tok(Re_TabAny,[Re_Digits])    A digit
  4117.    #  \D    Re_Tok(Re_TabAny,[Re_NonDigits]) A non-digit
  4118.    #  {n,m}    Re_Tok(Re_NToMTimes,[tok,n,m])    n to m occurrences of
  4119.    #                        previous token
  4120.    #  {n,}    Re_Tok(Re_NOrMoreTimes,[tok,n])    n or more occurrences of
  4121.    #                        previous token
  4122.    #  {n}    Re_Tok(Re_NTimes,[tok,n])    exactly n occurrences of
  4123.    #                        previous token
  4124.    #  ?        Re_Tok(Re_ZeroOrOneTimes,[tok])    one or zero occurrences of
  4125.    #                        previous token
  4126.    #  \<digit>    Re_Tok(Re_MatchParenGroup,[n])    The string matched by
  4127.    #                        parenthesis group <digit>
  4128.    #
  4129.    local plist
  4130.    #
  4131.    #  Initialize.
  4132.    #
  4133.    initial Re_Default()
  4134.    Re_WordChars := cset(Re_WordChars)
  4135.    Re_NonWordChars := ~Re_WordChars
  4136.    Re_Space := cset(Re_Space)
  4137.    Re_NonSpace := ~Re_Space
  4138.    Re_Digits := cset(Re_Digits)
  4139.    Re_NonDigits := ~Re_Digits
  4140.  
  4141.    s ? (plist := Re_pat1(0)) | fail
  4142.    return plist
  4143. end
  4144.  
  4145.  
  4146. procedure Re_pat1(level) # L
  4147. #
  4148. #  Recursive portion of RePat()
  4149. #
  4150.    local plist,n,m,c,comma
  4151.    static none,parenNbr
  4152.    initial {
  4153.       Re_TabMatch := proc("=",1)
  4154.       none := []
  4155.       }
  4156.    if level = 0 then parenNbr := 0
  4157.    plist := []
  4158.    #
  4159.    #  Loop to put pattern elements on list.
  4160.    #
  4161.    until pos(0) do {
  4162.       (="|",plist := [Re_Tok(Re_Alt,[plist,Re_pat1(level + 1) | fail])]) |
  4163.       put(plist,
  4164.      ## (="^",*plist = 0 | plist[-1].proc === Re_Alt,Re_Tok(pos,[1])) |
  4165.      (="^",pos(2) | &subject[-2] == ("|" | "("),Re_Tok(pos,[1])) |
  4166.      (="$",pos(0) | match("|" | ")"),Re_Tok(pos,[0])) |
  4167.      (match(")"),level > 0,break) |
  4168.      (=Re_ArbString,Re_Tok(Re_Arb,none)) |
  4169.      (=Re_AnyString,Re_Tok(move,[1])) |
  4170.      (="+",Re_Tok(Re_OneOrMore,[Re_prevTok(plist) | fail])) |
  4171.      (="*",Re_Tok(Re_ArbNo,[Re_prevTok(plist) | fail])) |
  4172.      1(Re_Tok(Re_TabAny,[c := Re_cset()]),\c | fail) |
  4173.      3(="(",n := parenNbr +:= 1,
  4174.            Re_Tok(Re_MatchReg,[Re_pat1(level + 1) | fail,n]),
  4175.            move(1) | fail) |
  4176.      (="\\b",Re_Tok(Re_WordBoundary,[Re_WordChars,Re_NonWordChars])) |
  4177.      (="\\B",Re_Tok(Re_NonWordBoundary,[Re_WordChars,Re_NonWordChars])) |
  4178.      (="\\w",Re_Tok(Re_TabAny,[Re_WordChars])) |
  4179.      (="\\W",Re_Tok(Re_TabAny,[Re_NonWordChars])) |
  4180.      (="\\s",Re_Tok(Re_TabAny,[Re_Space])) |
  4181.      (="\\S",Re_Tok(Re_TabAny,[Re_NonSpace])) |
  4182.      (="\\d",Re_Tok(Re_TabAny,[Re_Digits])) |
  4183.      (="\\D",Re_Tok(Re_TabAny,[Re_NonDigits])) |
  4184.      (="{",(n := tab(many(&digits)),comma := =(",") | &null,
  4185.         m := tab(many(&digits)) | &null,="}") | fail,
  4186.         if \m then Re_Tok(Re_NToMTimes,
  4187.           [Re_prevTok(plist),integer(n),integer(m)])
  4188.         else if \comma then Re_Tok(Re_NOrMoreTimes,
  4189.           [Re_prevTok(plist),integer(n)])
  4190.         else Re_Tok(Re_NTimes,[Re_prevTok(plist),integer(n)])) |
  4191.      (="?",Re_Tok(Re_ZeroOrOneTimes,[Re_prevTok(plist) | fail])) |
  4192.      Re_Tok(Re_TabMatch,[Re_string(level)]) |
  4193.      (="\\",n := tab(any(&digits)),Re_Tok(Re_MatchParenGroup,[integer(n)]))
  4194.      ) |
  4195.       fail
  4196.       }
  4197.    return plist
  4198. end
  4199.  
  4200.  
  4201. procedure Re_prevTok(plist)
  4202. #
  4203. #  Pull previous token from the pattern list.  This procedure must take
  4204. #  into account the fact that successive character tokens have been
  4205. #  optimized into a single string token.
  4206. #
  4207.    local lastTok,s,r
  4208.    lastTok := pull(plist) | fail
  4209.    if lastTok.proc === Re_TabMatch then {
  4210.       s := lastTok.args[1]
  4211.       r := Re_Tok(Re_TabMatch,[s[-1]])
  4212.       s[-1] := ""
  4213.       if *s > 0 then {
  4214.      put(plist,lastTok)
  4215.      lastTok.args[1] := s
  4216.      }
  4217.       return r
  4218.       }
  4219.    return lastTok
  4220. end
  4221.  
  4222.  
  4223. procedure Re_Default()
  4224. #
  4225. #  Assign default values to regular expression translation globals, but
  4226. #  only to variables whose values are null.
  4227. #
  4228.    /Re_WordChars := &letters ++ &digits ++ "_"
  4229.    /Re_Space := ' \t\v\n\r\f'
  4230.    /Re_Digits := &digits
  4231.    /Re_ArbString := ".*"
  4232.    /Re_AnyString := "."
  4233.    return
  4234. end
  4235.  
  4236.  
  4237. procedure Re_cset()
  4238. #
  4239. #  Matches a [...] construct and returns a cset.
  4240. #
  4241.    local complement,c,e,ch,chars
  4242.    ="[" | fail
  4243.    (complement := ="^" | &null,
  4244.      (e := (="-" | "")) || (c := move(1) || tab(find("]"))),move(1)) |
  4245.      return &null
  4246.    c ? {
  4247.       while chars := tab(upto('-\\')) do {
  4248.      e ++:= case move(1) of {
  4249.         "-": chars[1:-1] ++
  4250.           &cset[ord(chars[-1]) + 1:ord(move(1)) + 2] | return &null
  4251.         "\\": case ch := move(1) of {
  4252.            "w": Re_WordChars
  4253.            "W": Re_NonWordChars
  4254.            "s": Re_Space
  4255.            "S": Re_NonSpace
  4256.            "d": Re_Digits
  4257.            "D": Re_NonDigits
  4258.            default: ch
  4259.            }
  4260.         }
  4261.      }
  4262.       e ++:= tab(0)
  4263.       if \complement then e := ~e
  4264.       }
  4265.    e := (\Re_Filter)(e)
  4266.    return cset(e)
  4267. end
  4268.  
  4269.  
  4270. procedure Re_string(level)
  4271. #
  4272. #  Matches a string of non-special characters, returning a string.
  4273. #
  4274.    local special,s,p
  4275.    static nondigits
  4276.    initial nondigits := ~&digits
  4277.    special := if level = 0 then '\\.+*|[({?' else  '\\.+*|[({?)'
  4278.    s := tab(upto(special) | 0)
  4279.    while ="\\" do {
  4280.       p := &pos
  4281.       if tab(any('wWbBsSdD')) |
  4282.         (tab(any('123456789')) & (pos(0) | any(nondigits))) then {
  4283.      tab(p - 1)
  4284.      break
  4285.      }
  4286.       s ||:= move(1) || tab(upto(special) | 0)
  4287.       }
  4288.    if pos(0) & s[-1] == "$" then {
  4289.       move(-1)
  4290.       s[-1] := ""
  4291.       }
  4292.    s := string((\Re_Filter)(s))
  4293.    return "" ~== s
  4294. end
  4295.  
  4296.  
  4297. #####################  Matching Engine Procedures  ########################
  4298.  
  4299.  
  4300. procedure ReMatch(plist,s,i1,i2) # i3,i4,...,iN
  4301. #
  4302. #  Produce the sequence of positions in s past a string starting at i1
  4303. #  that matches the pattern plist, but fails if there is no such
  4304. #  position.  Similar to match(), but is capable of generating multiple
  4305. #  positions.
  4306. #
  4307.    if type(plist) ~== "list" then plist := RePat(plist) | fail
  4308.    /i1:= if /s := &subject then &pos else 1 ; /i2 := 0
  4309.    Re_ParenGroups := []
  4310.    suspend s[i1:i2] ? (Re_match1(plist,1),i1 + &pos - 1)
  4311. end
  4312.  
  4313.  
  4314. procedure Re_match1(plist,i) # s1,s2,...,sN
  4315. #
  4316. #  Used privately by ReMatch() to simulate a computed conjunction
  4317. #  expression via recursive generation.
  4318. #
  4319.    local tok
  4320.    suspend if tok := plist[i] then
  4321.       Re_tok_match(tok,plist,i) & Re_match1(plist,i + 1) else &null
  4322. end
  4323.  
  4324.  
  4325. procedure ReFind(plist,s,i1,i2) # i3,i4,...,iN
  4326. #
  4327. #  Produce the sequence of positions in s where strings begin that match
  4328. #  the pattern plist, but fails if there is no such position.  Similar
  4329. #  to find().
  4330. #
  4331.    local p
  4332.    if type(plist) ~== "list" then plist := RePat(plist) | fail
  4333.    /i1 := if /s := &subject then &pos else 1 ; /i2 := 0
  4334.    s[i1:i2] ? suspend (
  4335.      tab(Re_skip(plist,1)) &
  4336.      p := &pos &
  4337.      Re_match1(plist,1)\1 &
  4338.      i1 + p - 1)
  4339. end
  4340.  
  4341.  
  4342. procedure Re_tok_match(tok,plist,i)
  4343. #
  4344. #  Match a single token.  Can be recursively called by the token
  4345. #  procedure.
  4346. #
  4347.    local prc
  4348.    prc := tok.proc
  4349.    suspend (
  4350.       if prc === Re_Arb then Re_Arb(plist,i)
  4351.       else suspend prc!tok.args
  4352.       )
  4353. end
  4354.  
  4355.  
  4356. ##########  Heuristic Code for Matching Arbitrary Characters  ##########
  4357.  
  4358.  
  4359. procedure Re_skip(plist,i) # s1,s2,...,sN
  4360. #
  4361. #  Used privately -- match a sequence of strings in s past which a match
  4362. #  of the first pattern element in plist is likely to succeed.  This
  4363. #  procedure is used for heuristic performance improvement by ReMatch()
  4364. #  for the ".*" pattern element, and by ReFind().
  4365. #
  4366.    local x,s,p,prc
  4367.    x := plist[i]
  4368.    suspend case prc := (\x).proc | &null of {
  4369.       Re_TabMatch: find!x.args
  4370.       Re_TabAny: upto!x.args
  4371.       pos: x.args[1]
  4372.       ## Re_WordBoundary: Re_WordBoundaries!x.args
  4373.       Re_WordBoundary |
  4374.       Re_NonWordBoundary:
  4375.         p := &pos & tab(Re_skip(plist,i + 1)) & prc!x.args & untab(p)
  4376.       Re_OneOrMore |
  4377.       Re_MatchParenGroup: if s := (\Re_ParenGroups)[x.args[1]] then
  4378.         find(s) else &pos to *&subject + 1
  4379.       Re_NToMTimes |
  4380.       Re_NOrMoreTimes |
  4381.       Re_NTimes:
  4382.         if x.args[2] > 0 then Re_skip(x.args[1],1) else &pos to &subject + 1
  4383.       Re_MatchReg: Re_skip(x.args[1],1)
  4384.       Re_Alt:
  4385.         if \Re_Ordered then
  4386.           Re_result_merge{Re_skip(x.args[1],1),Re_skip(x.args[2],1)}
  4387.         else
  4388.           Re_skip(x.args[1 | 2],1)
  4389.       default: &pos to *&subject + 1
  4390.       }
  4391. end
  4392.  
  4393.  
  4394. procedure Re_result_merge(L)
  4395. #
  4396. #  Programmer-defined control operation to merge the result sequences of
  4397. #  two integer-producing generators.  Both generators must produce their
  4398. #  result sequences in numerically increasing order with no duplicates,
  4399. #  and the output sequence will be in increasing order with no
  4400. #  duplicates.
  4401. #
  4402.    local e1,e2,r1,r2
  4403.    e1 := L[1] ; e2 := L[2]
  4404.    r1 := @e1 ; r2 := @e2
  4405.    while \(r1 | r2) do
  4406.      if /r2 | \r1 < r2 then
  4407.            suspend r1 do r1 := @e1 | &null
  4408.      else if /r1 | r1 > r2 then
  4409.            suspend r2 do r2 := @e2 | &null
  4410.      else
  4411.            r2 := @e2 | &null
  4412. end
  4413.  
  4414.  
  4415. procedure untab(origPos)
  4416. #
  4417. #  Converts a string scanning expression that moves the cursor to one
  4418. #  that produces a cursor position and doesn't move the cursor (converts
  4419. #  something like tab(find(x)) to find(x).  The template for using this
  4420. #  procedure is
  4421. #
  4422. #    origPos := &pos ; tab(x) & ... & untab(origPos)
  4423. #
  4424.    local newPos
  4425.    newPos := &pos
  4426.    tab(origPos)
  4427.    suspend newPos
  4428.    tab(newPos)
  4429. end
  4430.  
  4431.  
  4432. #######################  Matching Procedures #######################
  4433.  
  4434.  
  4435. procedure Re_Arb(plist,i)
  4436. #
  4437. #  Match arbitrary characters (.*)
  4438. #
  4439.    suspend tab(if \plist then Re_skip(plist,i + 1) else 1 to *&subject + 1)
  4440. end
  4441.  
  4442.  
  4443. procedure Re_TabAny(C)
  4444. #
  4445. #  Match a character of a character set ([...],\w,\W,\s,\S,\d,\D
  4446. #)
  4447.    suspend tab(any(C))
  4448. end
  4449.  
  4450.  
  4451. procedure Re_MatchReg(tokList,groupNbr)
  4452. #
  4453. #  Match parenthesized group and assign matched string to list Re_ParenGroup
  4454. #
  4455.    local p,s
  4456.    p := &pos
  4457.    /Re_ParenGroups := []
  4458.    every Re_match1(tokList,1) do {
  4459.       while *Re_ParenGroups < groupNbr do put(Re_ParenGroups)
  4460.       s := &subject[p:&pos]
  4461.       Re_ParenGroups[groupNbr] := s
  4462.       suspend s
  4463.       }
  4464.    Re_ParenGroups[groupNbr] := &null
  4465. end
  4466.  
  4467.  
  4468. procedure Re_WordBoundary(wd,nonwd)
  4469. #
  4470. #  Match word-boundary (\b)
  4471. #
  4472.    suspend ((pos(1),any(wd)) | (pos(0),move(-1),tab(any(wd))) | (move(-1),
  4473.          (tab(any(wd)),any(nonwd)) | (tab(any(nonwd)),any(wd))),"")
  4474. end
  4475.  
  4476.  
  4477. procedure Re_NonWordBoundary(wd,nonwd)
  4478. #
  4479. #  Match non-word-boundary (\B)
  4480. #
  4481.    suspend ((pos(1),any(nonwd)) | (pos(0),move(-1),tab(any(nonwd))) | (move(-1),
  4482.          (tab(any(wd)),any(wd)) | (tab(any(nonwd)),any(nonwd)),""))
  4483. end
  4484.  
  4485.  
  4486. procedure Re_MatchParenGroup(n)
  4487. #
  4488. #  Match same string matched by previous parenthesized group (\N)
  4489. #
  4490.    local s
  4491.    suspend if s := \Re_ParenGroups[n] then =s else ""
  4492. end
  4493.  
  4494.  
  4495. ###################  Control Operation Procedures  ###################
  4496.  
  4497.  
  4498. procedure Re_ArbNo(tok)
  4499. #
  4500. #  Match any number of times (*)
  4501. #
  4502.    suspend "" | (Re_tok_match(tok) & Re_ArbNo(tok))
  4503. end
  4504.  
  4505.  
  4506. procedure Re_OneOrMore(tok)
  4507. #
  4508. #  Match one or more times (+)
  4509. #
  4510.    suspend Re_tok_match(tok) & Re_ArbNo(tok)
  4511. end
  4512.  
  4513.  
  4514. procedure Re_NToMTimes(tok,n,m)
  4515. #
  4516. #  Match n to m times ({n,m}
  4517. #
  4518.    suspend Re_NTimes(tok,n) & Re_ArbNo(tok)\(m - n + 1)
  4519. end
  4520.  
  4521.  
  4522. procedure Re_NOrMoreTimes(tok,n)
  4523. #
  4524. #  Match n or more times ({n,})
  4525. #
  4526.    suspend Re_NTimes(tok,n) & Re_ArbNo(tok)
  4527. end
  4528.  
  4529.  
  4530. procedure Re_NTimes(tok,n)
  4531. #
  4532. #  Match exactly n times ({n})
  4533. #
  4534.    if n > 0 then
  4535.       suspend Re_tok_match(tok) & Re_NTimes(tok,n - 1)
  4536.    else suspend
  4537. end
  4538.  
  4539.  
  4540. procedure Re_ZeroOrOneTimes(tok)
  4541. #
  4542. #  Match zero or one times (?)
  4543. #
  4544.    suspend "" | Re_tok_match(tok)
  4545. end
  4546.  
  4547.  
  4548. procedure Re_Alt(tokList1,tokList2)
  4549. #
  4550. #  Alternation (|)
  4551. #
  4552.    suspend Re_match1(tokList1 | tokList2,1)
  4553. end
  4554.  
  4555. From icon-group-request@arizona.edu  Sat Nov  9 21:01:27 1991
  4556. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Sat, 9 Nov 91 21:01:27 MST
  4557. Resent-From: icon-group-request@arizona.edu
  4558. Received: from Arizona.edu (Merlin.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  4559.     id AA16450; Sat, 9 Nov 91 21:01:25 MST
  4560. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Sat, 9 Nov
  4561.  1991 21:00 MST
  4562. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA15129; Sat, 9 Nov 91 19:47:49
  4563.  -0800
  4564. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  4565.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  4566.  usenet@ucbvax.Berkeley.EDU if you have questions)
  4567. Resent-Date: Sat, 9 Nov 1991 21:01 MST
  4568. Date: 9 Nov 91 23:26:36 GMT
  4569. From: ogicse!milton!nntp.uoregon.edu!euclid!haertel@uunet.uu.net (Mike Haertel)
  4570. Subject: RE: Regular expression timings
  4571. Sender: icon-group-request@arizona.edu
  4572. Resent-To: icon-group@cs.arizona.edu
  4573. To: icon-group@arizona.edu
  4574. Resent-Message-Id: <5FE89D39766006B8@Arizona.edu>
  4575. Message-Id: <1991Nov9.232636.14560@nntp.uoregon.edu>
  4576. X-Envelope-To: icon-group@CS.Arizona.EDU
  4577. X-Vms-To: icon-group@Arizona.edu
  4578. Organization: Department of Mathematics, University of Oregon
  4579. References: <1580@cronos.metaphor.com>
  4580.  
  4581. In article <1580@cronos.metaphor.com> alex@laguna.metaphor.com (Bob Alexander) writes:
  4582. >Here are some timings done comparing regular expression routines in
  4583. >Icon and otherwise.  The timings are the result of the C shell "time"
  4584. >command applied to the GNU regression test set -- two trials each.
  4585.  
  4586. These timings are essentially meaningless for grep performance.
  4587.  
  4588. I'd be much more interested to see the timings for situations
  4589. dominated by search time, rather than regexp compile time.  The
  4590. algorithms for regular expressions are dominated by data structures
  4591. like sets and graphs, and operations like transitive closure; these
  4592. are operations that Icon does very well.
  4593.  
  4594. But regexp compile time doesn't matter all that much.  Most people
  4595. use grep to quickly search through a large amount of data looking
  4596. for a single pattern.  So search time is what dominates grep usage.
  4597.  
  4598. Once an automaton is built, regexp search is dominated by array
  4599. indexing time (by character codes).  This is something that C does
  4600. very well.  In the search phase, the GNU egrep regexp matcher
  4601. (dfa.c, not regex.c) averages fewer than 10 machine instructions
  4602. per character (on the 68020), and it never backtracks.  Also note
  4603. that the search phase of GNU egrep is prefiltered by a Boyer-Moore
  4604. scan, and so in actual practice for typical patterns it probably
  4605. averages less than 1 instruction per character of the input file,
  4606. since it need not look at every character.
  4607.  
  4608. I really seriously doubt that any matcher written in Icon can
  4609. even begin to touch performance like this.
  4610.  
  4611. From wgg@cs.ucsd.edu  Mon Nov 11 15:35:51 1991
  4612. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Mon, 11 Nov 91 15:35:51 MST
  4613. Received: from ucsd.edu by optima.cs.arizona.edu (4.1/15)
  4614.     id AA01940; Mon, 11 Nov 91 15:35:30 MST
  4615. Received: from gremlin.ucsd.edu by ucsd.edu; id AA10504
  4616.     sendmail 5.64/UCSD-2.2-sun via SMTP
  4617.     Mon, 11 Nov 91 14:35:26 -0800 for icon-group@cs.arizona.edu
  4618. Received: by gremlin.ucsd.edu (4.1/UCSDPSEUDO.4)
  4619.     id AA22258 for icon-group@cs.arizona.edu; Mon, 11 Nov 91 14:35:24 PST
  4620. Date: Mon, 11 Nov 91 14:35:24 PST
  4621. From: wgg@cs.ucsd.edu (William Griswold)
  4622. Message-Id: <9111112235.AA22258@gremlin.ucsd.edu>
  4623. To: icon-group@cs.arizona.edu
  4624. Subject: writing sorting routines in Icon
  4625.  
  4626. Recently I was trying to implement a priority queue data type with a `heap'
  4627. data structure.  This type would allow me to select the k greatest elements
  4628. in a list in sorted order--the ``k most common words'' problem.  It can be
  4629. easily solved by building a table of word counts and sorting the whole
  4630. table, but with big tables this is a big loser, since sorting is N log N for
  4631. list of length N.  With a priority queue I can select the k greatest
  4632. elements in N log k time (or likely much less), since each p-queue operation
  4633. takes log time, but there needn't be more than k elements in the queue at
  4634. any time.
  4635.  
  4636. The priority queue is basically a sorting data structure.  However, I was
  4637. inhibited from implementing a queue that could handle elements from all
  4638. types the way Icon sort does, because I need a less-than operation that can
  4639. compare values from any type.  Icon directly supports only < (for integers)
  4640. and << (for strings).  Oddly, there is a generic equals operator, ===, but
  4641. no <<<.  How did I solve this problem?  Here is how I implemented generic_lt
  4642. (a generic less-than):
  4643.  
  4644.   procedure generic_lt(x,y)
  4645.     return (x ~=== y) & (sort([x,y])[2] === y)
  4646.   end
  4647.  
  4648. Not very pretty, but it will work (no, I haven't tested it yet).  This cannot
  4649. be very efficient, but it will always adhere to the very important constraint
  4650. that sorting with my priority queues will work just like Icon's built-in sort.
  4651. Does anyone see a way of implementing this *without* sort?  Icon has the
  4652. peculiar definition of sorting things like records by ``age''.  In the current
  4653. implementation I can get an objects x's age by computing image(x) and then
  4654. lifting the object number out of the text string, but that is very
  4655. unportable, probably.  I think calling sort is the only reasonable way to build
  4656. my own Icon-compatible sorting-class routines.
  4657.  
  4658. My priority-queue solution to `k most common words' (using integer
  4659. comparison for ordering) is roughly twice as fast my old straight-sorting
  4660. solution for computing the 10 most common words on a 2 1/2 meg file, so
  4661. wanting to implement my own sorting-class routines is not unwarranted.
  4662.  
  4663. In my opinion, since implementing these routines--and wanting them to be
  4664. efficient and consistent with Icon sort--is not unwarranted, the bottom line
  4665. is that Icon has a design flaw because it is missing <<<, >>>, <<<= and >>>=,
  4666. or because Icon sort can sort things in a way that a programmer cannot compare
  4667. them.
  4668.  
  4669. Comments?
  4670.  
  4671.                         Bill Griswold
  4672.  
  4673. From ralph  Mon Nov 11 18:06:52 1991
  4674. Date: Mon, 11 Nov 91 18:06:52 MST
  4675. From: "Ralph Griswold" <ralph>
  4676. Message-Id: <9111120106.AA13433@cheltenham.cs.arizona.edu>
  4677. Received: by cheltenham.cs.arizona.edu; Mon, 11 Nov 91 18:06:52 MST
  4678. To: icon-group@cs.arizona.edu, wgg@cs.ucsd.edu
  4679. Subject: Re:  writing sorting routines in Icon
  4680.  
  4681. Icon has a lot of design flaws.
  4682.  
  4683. One is having too many functions and operators.
  4684.  
  4685. We considered structure comparison operators but did not implement them
  4686. because we felt the additional linguisitic litter overshadowed the
  4687. additional functionality.
  4688.  
  4689. Whether you agree depends on how you feel about language design.
  4690.     
  4691.     Ralph Griswold / Department of Computer Science 
  4692.     The University of Arizona / Tucson, AZ 85721
  4693.     
  4694.     ralph@cs.arizona.edu / uunet!arizona!ralph
  4695.     
  4696.     voice: 602-621-6609 / fax: 602-621-9618
  4697.  
  4698. From icon-group-request@arizona.edu  Wed Nov 13 19:34:36 1991
  4699. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Wed, 13 Nov 91 19:34:36 MST
  4700. Resent-From: icon-group-request@arizona.edu
  4701. Received: from Arizona.edu (Merlin.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  4702.     id AA08770; Wed, 13 Nov 91 19:02:56 MST
  4703. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Wed, 13 Nov
  4704.  1991 19:02 MST
  4705. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA11088; Wed, 13 Nov 91
  4706.  17:44:19 -0800
  4707. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  4708.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  4709.  usenet@ucbvax.Berkeley.EDU if you have questions)
  4710. Resent-Date: Wed, 13 Nov 1991 19:02 MST
  4711. Date: 13 Nov 91 19:42:10 GMT
  4712. From: micro-heart-of-gold.mit.edu!wupost!spool.mu.edu!uwm.edu!mrsvr.UUCP!hewitt@bloom-beacon.mit.edu
  4713.  (Anthony V. Hewitt)
  4714. Subject: RE: list manipulation
  4715. Sender: icon-group-request@arizona.edu
  4716. Resent-To: icon-group@cs.arizona.edu
  4717. To: icon-group@arizona.edu
  4718. Resent-Message-Id: <740596FDD4602D12@Arizona.edu>
  4719. Message-Id: <HEWITT.91Nov13134210@argus.gemed.com>
  4720. X-Envelope-To: icon-group@CS.Arizona.EDU
  4721. X-Vms-To: icon-group@Arizona.edu
  4722. Organization: GE Medical Systems, Milwaukee, WI
  4723. References: <1991Nov12.114242.2062@arizona.edu>
  4724.  
  4725. It's my understanding that in Icon, even more than in most languages, a
  4726. concern for efficiency can be counterproductive; it's not at all obvious
  4727. which version of your code will run fastest, even if you understand the
  4728. language implementation (which I don't).
  4729.  
  4730. Explicit subscripts just don't seem idiomatic in Icon; you might not expect
  4731. them to have as polished an implementation as more interesting language
  4732. features.  But are they slower than the alternatives?  Try it and see!
  4733.  
  4734. The queue and stack access methods provided by put(L,x), push(L,x), pop(L),
  4735. get(L), pull(L) are efficient, so I'm told, and I have found them very
  4736. useful.  Steve Wampler published some time ago a comment about a student's
  4737. program that used pop() to advantage when the list needed to be accessed
  4738. only once.  A construction like while write(pop(L)) is quite handy.
  4739.  
  4740. --
  4741. ------------------------------------------------------------------------------
  4742. Anthony V. Hewitt                  Phone 414 548-5170 (GE Dialcom 8*320-5170)
  4743. Senior Physicist
  4744. General Electric Company             Fax 414 548-5197 (8*320-5197)
  4745. P.O.Box 414, W-641
  4746. Milwaukee, WI 53201                    Internet: hewitta@aslpet.med.ge.com
  4747. ------------------------------------------------------------------------------
  4748.  
  4749. From icon-group-request@arizona.edu  Fri Nov 15 06:00:49 1991
  4750. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Fri, 15 Nov 91 06:00:49 MST
  4751. Resent-From: icon-group-request@arizona.edu
  4752. Received: from Arizona.edu (Merlin.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  4753.     id AA21932; Fri, 15 Nov 91 06:00:47 MST
  4754. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Fri, 15 Nov
  4755.  1991 06:00 MST
  4756. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA25040; Fri, 15 Nov 91
  4757.  04:45:53 -0800
  4758. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  4759.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  4760.  usenet@ucbvax.Berkeley.EDU if you have questions)
  4761. Resent-Date: Fri, 15 Nov 1991 06:00 MST
  4762. Date: 15 Nov 91 00:36:17 GMT
  4763. From: elroy.jpl.nasa.gov!swrinde!mips!news.cs.indiana.edu!arizona.edu!arizona.edu!news@ames.arc.nasa.gov
  4764.  (Kurt Parten)
  4765. Subject: Icon memory management
  4766. Sender: icon-group-request@arizona.edu
  4767. Resent-To: icon-group@cs.arizona.edu
  4768. To: icon-group@arizona.edu
  4769. Resent-Message-Id: <9916E78D58604738@Arizona.edu>
  4770. Message-Id: <1991Nov14.173618.2088@arizona.edu>
  4771. X-Envelope-To: icon-group@CS.Arizona.EDU
  4772. X-Vms-To: icon-group@Arizona.edu
  4773. Organization: Dept of Electrical and Computer Engineering, University of
  4774.  Arizona, Tucson, Arizona
  4775.  
  4776. Does anyone out there know details of Icon's memory management?
  4777. Is there some sort of garbage collection which goes on?
  4778. Do I have to worry about running out of heap? 
  4779. Is there a compiler option to specify heapsize?
  4780. Is heapsize set by the compiler?
  4781. Is heapsize whatever memory will allow?
  4782.  
  4783. Thanks,
  4784. Kurt
  4785.  
  4786. --
  4787. Kurt Parten
  4788. parten@helios.ece.arizona.edu
  4789.  
  4790. From icon-group-request@arizona.edu  Fri Nov 15 06:45:37 1991
  4791. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Fri, 15 Nov 91 06:45:37 MST
  4792. Resent-From: icon-group-request@arizona.edu
  4793. Received: from Arizona.edu (Merlin.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  4794.     id AA23459; Fri, 15 Nov 91 06:45:35 MST
  4795. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Fri, 15 Nov
  4796.  1991 06:45 MST
  4797. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA26408; Fri, 15 Nov 91
  4798.  05:41:35 -0800
  4799. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  4800.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  4801.  usenet@ucbvax.Berkeley.EDU if you have questions)
  4802. Resent-Date: Fri, 15 Nov 1991 06:45 MST
  4803. Date: 15 Nov 91 02:47:45 GMT
  4804. From: news@arizona.edu (Kurt Parten)
  4805. Subject: list manipulation
  4806. Sender: icon-group-request@arizona.edu
  4807. Resent-To: icon-group@cs.arizona.edu
  4808. To: icon-group@arizona.edu
  4809. Resent-Message-Id: <9F5931195860452B@Arizona.edu>
  4810. Message-Id: <1991Nov14.194746.2091@arizona.edu>
  4811. X-Envelope-To: icon-group@CS.Arizona.EDU
  4812. X-Vms-To: icon-group@Arizona.edu
  4813. Organization: Dept of Electrical and Computer Engineering, University of
  4814.  Arizona, Tucson, Arizona
  4815.  
  4816. Thanks to all who replied to the prev. post about list
  4817. manipulation.  Replacing occurences of
  4818.  
  4819. somelist |||:= [item]
  4820.  
  4821. with
  4822.  
  4823. put(somelist, item)
  4824.  
  4825. changed execution time from 11.7 secs to 9.4 secs.  Roughly 20% shaved
  4826. off.  And there was no noticable savings between
  4827.  
  4828. put(somelist, item)
  4829.  
  4830. and
  4831.  
  4832. push(somelist, item)
  4833.  
  4834. Has anyone done anything else profiling Icon?
  4835. --
  4836. Kurt Parten
  4837. parten@helios.ece.arizona.edu
  4838.  
  4839. From hbair@austin.onu.edu  Sat Nov 16 23:46:03 1991
  4840. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Sat, 16 Nov 91 23:46:03 MST
  4841. Resent-From: hbair@austin.onu.edu
  4842. Received: from Arizona.edu (Merlin.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  4843.     id AA19662; Sat, 16 Nov 91 23:46:01 MST
  4844. Received: from austin.onu.edu by Arizona.edu with PMDF#10282; Sat, 16 Nov 1991
  4845.  23:45 MST
  4846. Received: by austin.onu.edu (AIX 3.1/UCB 5.61/4.03) id AA33346; Sun, 17 Nov 91
  4847.  01:45:21 -0500
  4848. Resent-Date: Sat, 16 Nov 1991 23:45 MST
  4849. Date: Sun, 17 Nov 91 01:45:21 -0500
  4850. From: hbair@austin.onu.edu (Heath Bair (x1666))
  4851. Subject: Mail
  4852. Resent-To: icon-group@cs.arizona.edu
  4853. To: Icon-group@arizona.edu
  4854. Resent-Message-Id: <F7107FA298604F91@Arizona.edu>
  4855. Message-Id: <9111170645.AA33346@austin.onu.edu>
  4856. X-Envelope-To: icon-group@CS.Arizona.EDU
  4857. X-Vms-To: Icon-group@Arizona.edu
  4858.  
  4859.    I would like to be apart of your mail group.
  4860. Heath C. Bair
  4861.  
  4862. From icon-group-request@arizona.edu  Sun Nov 17 11:06:06 1991
  4863. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Sun, 17 Nov 91 11:06:06 MST
  4864. Resent-From: icon-group-request@arizona.edu
  4865. Received: from Arizona.edu (Hopey.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  4866.     id AA08153; Sun, 17 Nov 91 11:06:04 MST
  4867. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Sun, 17 Nov
  4868.  1991 11:05 MST
  4869. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA11920; Sun, 17 Nov 91
  4870.  09:52:08 -0800
  4871. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  4872.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  4873.  usenet@ucbvax.Berkeley.EDU if you have questions)
  4874. Resent-Date: Sun, 17 Nov 1991 11:05 MST
  4875. Date: 17 Nov 91 17:05:54 GMT
  4876. From: agate!spool.mu.edu!samsung!zaphod.mps.ohio-state.edu!uwm.edu!ux1.cso.uiuc.edu!uchinews!ellis!goer@ucbvax.berkeley.edu
  4877.  (Richard L. Goerwitz)
  4878. Subject: global variables, builtins
  4879. Sender: icon-group-request@arizona.edu
  4880. Resent-To: icon-group@cs.arizona.edu
  4881. To: icon-group@arizona.edu
  4882. Resent-Message-Id: <5612272BE86044A5@Arizona.edu>
  4883. Message-Id: <1991Nov17.170554.17717@midway.uchicago.edu>
  4884. X-Envelope-To: icon-group@CS.Arizona.EDU
  4885. X-Vms-To: icon-group@Arizona.edu
  4886. Organization: University of Chicago Computing Organizations
  4887.  
  4888. Can someone explain to me why the following only works so long as I
  4889. comment out the ", write" part?  This behavior seems to break Jerry
  4890. Nowlin's solit.icn program in the IPL ("global kbhit").  I was not
  4891. aware that global variable names designating functions were different
  4892. from globals designating user-defined procedures.  My Icon run-time
  4893. system passed all the tests, and I tested this both at home and on a
  4894. Sun4.  Something subtle is going on that I don't understand.
  4895.  
  4896. global mywrite#, write
  4897. procedure main()
  4898.     write :=: mywrite
  4899.     write("hello")
  4900. end
  4901. procedure mywrite(a[])
  4902.     return mywrite!a
  4903. end
  4904.  
  4905. -- 
  4906.  
  4907.    -Richard L. Goerwitz              goer%sophist@uchicago.bitnet
  4908.    goer@sophist.uchicago.edu         rutgers!oddjob!gide!sophist!goer
  4909.  
  4910. From isidev!nowlin@uunet.uu.net  Sun Nov 17 14:52:19 1991
  4911. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Sun, 17 Nov 91 14:52:19 MST
  4912. Received: from relay1.UU.NET by optima.cs.arizona.edu (4.1/15)
  4913.     id AA17237; Sun, 17 Nov 91 14:52:16 MST
  4914. Received: from uunet.uu.net (via LOCALHOST.UU.NET) by relay1.UU.NET with SMTP 
  4915.     (5.61/UUNET-internet-primary) id AA25943; Sun, 17 Nov 91 16:52:11 -0500
  4916. Date: Sun, 17 Nov 91 16:52:11 -0500
  4917. From: isidev!nowlin@uunet.uu.net
  4918. Message-Id: <9111172152.AA25943@relay1.UU.NET>
  4919. Received: from isidev.UUCP by uunet.uu.net with UUCP/RMAIL
  4920.     (queueing-rmail) id 165110.22006; Sun, 17 Nov 1991 16:51:10 EST
  4921. To: uunet!cs.arizona.edu!icon-group@uunet.uu.net
  4922. Subject: Re: global variables
  4923.  
  4924.  > Can someone explain to me why the following only works so long as I
  4925.  > comment out the ", write" part?  This behavior seems to break Jerry
  4926.  > Nowlin's solit.icn program in the IPL ("global kbhit").  I was not
  4927.  > aware that global variable names designating functions were different
  4928.  > from globals designating user-defined procedures.
  4929.  > ...
  4930.  > global mywrite#, write
  4931.  
  4932. The problem is that declaring a global with the same name as a built-in
  4933. function replaces the built-in function even before anything is assigned to
  4934. the name.  By the time you used the exchange values operator to swap the
  4935. original write() with mywrite() it was too late.  The global value for
  4936. write was already &null.
  4937.  
  4938.  > write :=: mywrite
  4939.  
  4940. ISIcon gives warnings about this.  I find them very useful.  When the
  4941. program included in the original posting was translated with ISIcon the
  4942. following message was generated:
  4943.  
  4944.     Warning, "write": global declaration overrides built-in function
  4945.  
  4946. The program still works just like PD Icon, since this is a warning, but you
  4947. are cautioned that you may have done something you will regret.  In this
  4948. case a handy warning.
  4949.  
  4950. I don't know exactly what was meant by "break ... solit.icn program in the
  4951. IPL".  The only built-in function that was redefined in solit.icn was
  4952. display() and that didn't break anything.  The kbhit() function, which is
  4953. only implemented for DOS in PD Icon, isn't used in solit.icn.
  4954.  
  4955. --- ---
  4956.  | S | Iconic Software, Inc.  -  Jerry Nowlin  -  uunet!isidev!nowlin
  4957. --- ---
  4958.  
  4959.  
  4960. From icon-group-request@arizona.edu  Sun Nov 17 17:38:12 1991
  4961. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Sun, 17 Nov 91 17:38:12 MST
  4962. Resent-From: icon-group-request@arizona.edu
  4963. Received: from Arizona.edu (Merlin.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  4964.     id AA22490; Sun, 17 Nov 91 17:38:09 MST
  4965. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Sun, 17 Nov
  4966.  1991 17:37 MST
  4967. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA21016; Sun, 17 Nov 91
  4968.  16:25:25 -0800
  4969. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  4970.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  4971.  usenet@ucbvax.Berkeley.EDU if you have questions)
  4972. Resent-Date: Sun, 17 Nov 1991 17:37 MST
  4973. Date: 17 Nov 91 23:57:13 GMT
  4974. From: cis.ohio-state.edu!zaphod.mps.ohio-state.edu!qt.cs.utexas.edu!cs.utexas.edu!uwm.edu!ux1.cso.uiuc.edu!uchinews!ellis!goer@ucbvax.berkeley.edu (Richard L.
  4975.  Goerwitz)
  4976. Subject: RE: global variables
  4977. Sender: icon-group-request@arizona.edu
  4978. Resent-To: icon-group@cs.arizona.edu
  4979. To: icon-group@arizona.edu
  4980. Resent-Message-Id: <8CD60C0958604FC3@Arizona.edu>
  4981. Message-Id: <1991Nov17.235713.27108@midway.uchicago.edu>
  4982. X-Envelope-To: icon-group@CS.Arizona.EDU
  4983. X-Vms-To: icon-group@Arizona.edu
  4984. Organization: University of Chicago Computing Organizations
  4985. References: <9111172152.AA25943@relay1.UU.NET>
  4986.  
  4987. In article <9111172152.AA25943@relay1.UU.NET> nowlin@isidev.UUCP writes:
  4988. >
  4989. > > Can someone explain to me why [declaring a variable with the same
  4990. > > name as a builtin function nulls the variable]?
  4991. >
  4992. >The problem is that declaring a global with the same name as a built-in
  4993. >function replaces the built-in function even before anything is assigned to
  4994. >the name.
  4995.  
  4996. Obviously what you say describes what I observe.  I wish the behavior was the
  4997. same for builtins as for user-defined procedures, though.  It's clearly trip-
  4998. ped up more than one person.  Not you, of course.  But take a look at this:
  4999.  
  5000.  
  5001. --------------------------  from solit.icn (IPL) ------------------------
  5002.  
  5003. #  Name:    solit.icn
  5004. <stuff deleted>
  5005. global   whitespace, amode, seed, deck, over, hidden, run, ace, kbhit
  5006. <more stuff deleted>
  5007.     if not(&features == "keyboard functions") then kbhit := 2
  5008. <even more stuff deleted>
  5009.    if proc(kbhit) then writes( " [Press any key to return.]")
  5010.  
  5011. -----------------------------  end IPL material ---------------------------
  5012.  
  5013. Looks to me like somebody couldn't decide whether to test for the presence
  5014. of kbhit() via &features or proc().  The second method is better, since it
  5015. detects kbhit() even if it's added as a library function.  The global defi-
  5016. nition kbhit := 2 nulls out the expression kbhit() if there is no builtin
  5017. kbhit function.
  5018.  
  5019. For those who are confused here, the solit game is supposed to auto-detect
  5020. the presence of the kbhit utility in the run-time system.  If an Icon imple-
  5021. mentation has kbhit(), getch(), and getche(), then the following expression
  5022. will succeed:  find("keyboard func", &features).  But what if you have added
  5023. kbhit() via Icon code?  I don't see an easy way to do this (see the file
  5024. getchlib.icn in the IPL).  But if somebody does, proc(kbhit) will succeed.
  5025. So proc(kbhit) is a better way of checking for the presence of this function
  5026. in the run-time system or as a user-defined procedure.  If proc(kbhit) fails,
  5027. you can null out the procedure by assigning the integer 2 to kbhit.  That way
  5028. kbhit() will evaluate to 2(), which is essentially a no-op, and will always
  5029. fail.  The idea is this:  If the user has a kbhit() function (either builtin
  5030. or via Icon code), then use it; otherwise, null out the function kbhit, and
  5031. make kbhit() a no-op.
  5032.  
  5033. The problem is that, if kbhit() isn't a function or user-defined procedure,
  5034. kbhit() will only work "right" if a) kbhit is assigned an integer value,
  5035. and b) gets assigned the value 2 every time the variable is encountered and
  5036. proc(kbhit) fails.  Making kbhit global doesn't work for the reasons Jerry
  5037. discussed.
  5038.  
  5039. >ISIcon gives warnings about this.  I find them very useful.  When the
  5040. >program included in the original posting was translated with ISIcon the
  5041. >following message was generated:
  5042. >
  5043. >    Warning, "write": global declaration overrides built-in function
  5044.  
  5045. You wouldn't happen to have a connection to ISI, would you :-).  Tell you
  5046. what:  I'll overlook the commercialism if you'll check to see if this
  5047. SYSV code works correctly on your machines.  I run Xenix, as you know,
  5048. and have rdchk().  You guys should, too (SYSVr3 or later).  I'm curious
  5049. about how these routines would work with ISI's windowing enabled.  Just
  5050. append them to src/iconx/fsys.c and add KeyboardFncs to the defines.h
  5051. file:
  5052.  
  5053. /* #include <stdio.h> - included by ../h/config.h */
  5054. #include <sys/termio.h>
  5055. #include <sys/ioctl.h>
  5056. #include <sys/errno.h>
  5057.  
  5058. #define CopyTty(t1,t2)    if (! reset_flag) {\
  5059.               t2 = t1;\
  5060.               reset_flag = 1;\
  5061.             }
  5062. /*
  5063.  * kbhit(): word
  5064.  *
  5065.  * Routine to check for the availability of characters on the stdin
  5066.  * stream.  Does not actually read any characters.  Returns nonzero
  5067.  * value if characters are waiting; otherwise, zero.
  5068.  */
  5069. word kbhit()
  5070. {
  5071.   struct termio tty, new_tty;
  5072.   register word status, reset_flag = 0;
  5073.   extern word errno;
  5074.  
  5075.   if (isatty(0)) {
  5076.  
  5077.     if (ioctl(0, TCGETA, &tty) == -1)
  5078.       RunErr(-214, NULL);
  5079.      
  5080.     if (tty.c_lflag & ICANON) {
  5081.       CopyTty(tty, new_tty);
  5082.       new_tty.c_lflag &= ~ICANON;
  5083.       if (ioctl(0, TCSETA, &new_tty) == -1)
  5084.     RunErr(-214, NULL);
  5085.     }
  5086.   }
  5087.  
  5088.   /* see if anything is waiting to be read from the file */
  5089.   status = rdchk(0);
  5090.   if (status == -1) {
  5091.     switch (errno) {
  5092.     case EBADF:
  5093.       RunErr(-212, NULL);
  5094.     default:
  5095.       RunErr(-214, NULL);
  5096.     }
  5097.   }
  5098.  
  5099.   if (reset_flag) {
  5100.     if (ioctl(0, TCSETA, &tty) == -1)
  5101.       RunErr(-214, NULL);
  5102.   }
  5103.      
  5104.   return status;
  5105. }
  5106.  
  5107. /*
  5108.  * getch(): word
  5109.  *
  5110.  * Routine to read one char from the standard input.  Disables canonical
  5111.  * processing so as to read the character right from the buffer, without
  5112.  * having to wait for a carriage return.  Re-enables canonical processing
  5113.  * after reading a character.  Note that getch() does not echo any char-
  5114.  * acters to the screen, although characters might appear on the screen
  5115.  * anyway, if they were typed before getch() was invoked.
  5116.  */
  5117. word getch()
  5118. {
  5119.  
  5120.   char c;
  5121.   struct termio tty, new_tty;
  5122.   register word status, reset_flag = 0;
  5123.   extern word errno;
  5124.   
  5125.   if (isatty(0)) {
  5126.     if (ioctl(0, TCGETA, &tty) == -1)
  5127.       RunErr(-214, NULL);
  5128.      
  5129.     if (tty.c_lflag & ICANON) {
  5130.       CopyTty(tty, new_tty);    /* sets reset_flag */
  5131.       new_tty.c_lflag &= ~ICANON;
  5132.     }
  5133.     if (tty.c_cc[VMIN] != '\1') {
  5134.       CopyTty(tty, new_tty);
  5135.       new_tty.c_cc[VMIN] = (unsigned char )'\1';
  5136.     }
  5137.     if (tty.c_cc[VTIME]) {
  5138.       CopyTty(tty, new_tty);
  5139.       new_tty.c_cc[VTIME] = (unsigned char )'\0';
  5140.     }
  5141.     if (tty.c_lflag & ECHO) {
  5142.       CopyTty(tty, new_tty);
  5143.       new_tty.c_lflag &= ~ECHO;
  5144.     }
  5145.  
  5146.     if (reset_flag) {
  5147.       if (ioctl(0, TCSETA, &new_tty) == -1)
  5148.     RunErr(-214, NULL);
  5149.     }
  5150.   }
  5151.  
  5152.   status = read(0, &c, 1);
  5153.   if (status == -1) {
  5154.     switch (errno) {
  5155.     case EBADF:
  5156.       RunErr(-212, NULL);
  5157.     default:
  5158.       RunErr(-214, NULL);
  5159.     }
  5160.   }
  5161.  
  5162.   if (reset_flag) {
  5163.     if (ioctl(0, TCSETA, &tty) == -1)
  5164.       RunErr(-214, NULL);
  5165.   }
  5166.  
  5167.   if (! status) return -1;
  5168.   else return (word )c;
  5169. }
  5170.  
  5171. /*
  5172.  * getche(): word
  5173.  *
  5174.  * Routine to read one char from the standard input.  Disables canonical
  5175.  * processing so as to read the character right from the buffer, without
  5176.  * having to wait for a carriage return.  Re-enables canonical processing
  5177.  * after reading a character.  NOTE:  Getche() does not disable echoing,
  5178.  * so anything typed after it is invoked will be echoed to the screen
  5179.  * (unlike getch(), which disables echoing; see above).
  5180.  */
  5181. word getche()
  5182. {
  5183.  
  5184.   char c;
  5185.   struct termio tty, new_tty;
  5186.   register word status, reset_flag = 0;
  5187.   extern word errno;
  5188.   
  5189.   if (isatty(0)) {
  5190.     if (ioctl(0, TCGETA, &tty) == -1)
  5191.       RunErr(-214, NULL);
  5192.      
  5193.     if (tty.c_lflag & ICANON) {
  5194.       CopyTty(tty, new_tty);    /* sets reset_flag */
  5195.       new_tty.c_lflag &= ~ICANON;
  5196.     }
  5197.     if (tty.c_cc[VMIN] != '\1') {
  5198.       CopyTty(tty, new_tty);
  5199.       new_tty.c_cc[VMIN] = (unsigned char )'\1';
  5200.     }
  5201.     if (tty.c_cc[VTIME]) {
  5202.       CopyTty(tty, new_tty);
  5203.       new_tty.c_cc[VTIME] = (unsigned char )'\0';
  5204.     }
  5205.     if (! (tty.c_lflag & ECHO)) {
  5206.       CopyTty(tty, new_tty);
  5207.       new_tty.c_lflag |= ECHO;
  5208.     }
  5209.  
  5210.     if (reset_flag) {
  5211.       if (ioctl(0, TCSETA, &new_tty) == -1)
  5212.     RunErr(-214, NULL);
  5213.     }
  5214.   }
  5215.  
  5216.   status = read(0, &c, 1);
  5217.   if (status == -1) {
  5218.     switch (errno) {
  5219.     case EBADF:
  5220.       RunErr(-212, NULL);
  5221.     default:
  5222.       RunErr(-214, NULL);
  5223.     }
  5224.   }
  5225.  
  5226.   if (reset_flag) {
  5227.     if (ioctl(0, TCSETA, &tty) == -1)
  5228.       RunErr(-214, NULL);
  5229.   }
  5230.  
  5231.   if (! status) return -1;
  5232.   else return (word )c;
  5233. }
  5234. -- 
  5235.  
  5236.    -Richard L. Goerwitz              goer%sophist@uchicago.bitnet
  5237.    goer@sophist.uchicago.edu         rutgers!oddjob!gide!sophist!goer
  5238.  
  5239. From icon-group-request@arizona.edu  Mon Nov 18 07:38:28 1991
  5240. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Mon, 18 Nov 91 07:38:28 MST
  5241. Resent-From: icon-group-request@arizona.edu
  5242. Received: from Arizona.edu (Maggie.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  5243.     id AA17968; Mon, 18 Nov 91 07:38:26 MST
  5244. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Mon, 18 Nov
  5245.  1991 07:37 MST
  5246. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA15694; Mon, 18 Nov 91
  5247.  06:35:20 -0800
  5248. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  5249.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  5250.  usenet@ucbvax.Berkeley.EDU if you have questions)
  5251. Resent-Date: Mon, 18 Nov 1991 07:38 MST
  5252. Date: 13 Nov 91 04:57:36 GMT
  5253. From: cis.ohio-state.edu!zaphod.mps.ohio-state.edu!mips!spool.mu.edu!cs.umn.edu!umn.edu!msi.umn.edu!noc.MR.NET!uc.msc.edu!shamash!uchinews!ellis!goer@ucbvax.berkeley.edu (Richard L.
  5254.  Goerwitz)
  5255. Subject: RE: list manipulation
  5256. Sender: icon-group-request@arizona.edu
  5257. Resent-To: icon-group@cs.arizona.edu
  5258. To: icon-group@arizona.edu
  5259. Resent-Message-Id: <02381777E860638F@Arizona.edu>
  5260. Message-Id: <1991Nov13.045736.857@midway.uchicago.edu>
  5261. X-Envelope-To: icon-group@CS.Arizona.EDU
  5262. X-Vms-To: icon-group@Arizona.edu
  5263. Organization: University of Chicago Computing Organizations
  5264. References: <1991Nov12.114242.2062@arizona.edu>
  5265.  
  5266. Kurt Parten writes:
  5267.  
  5268. >I am curious about efficient ways of manipulating lists.
  5269.  
  5270. If you're really concerned with efficiency, the typical answer is:  Use
  5271. C.  If you want elegance, maintainability, and ease of coding, use Icon.
  5272. Of course I know this isn't what you want to know about.  You want to
  5273. know if there are any obvious ways to code list manipulating routines
  5274. in Icon to maximize efficiency within that framework.
  5275.  
  5276. There's a neat way of checking the speed of Icon expressions, it turns
  5277. out.  In the Icon Program Library there's a little program called empg.
  5278. It's a timing utility.
  5279.  
  5280. If you want to time, say,
  5281.  
  5282.     l := []
  5283.     every put(l, 1 to 4)
  5284.  
  5285. you'd put these two lines into a file (prepend a colon to the first line,
  5286. though; this is how you tell empg to execute the line, but not time it),
  5287. and then run empg on that file.  I just put the above two lines into a
  5288. file called "xxx," and ran empg on it ("[iconx] empg xxx").  The result
  5289. was a file called xxx.icn, which I then compiled and ran.  The output was:
  5290.  
  5291. ---------------------------------------------------------------------------
  5292. iterations: 10000
  5293. &version: Icon Version 8.0.  March 25, 1990
  5294. &host: SCO XENIX System V/386
  5295. &dateline: Tuesday, November 12, 1991  10:39 pm
  5296. region sizes: 
  5297.    static   20480
  5298.    string   65024
  5299.    block    65024
  5300.  l := []
  5301. every put(l, 1 to 4)
  5302.    0.47200 ms.
  5303. garbage collections:
  5304.    total    5
  5305.    static   0
  5306.    string   0
  5307.    block    5
  5308. region sizes: 
  5309.    static   20480
  5310.    string   65024
  5311.    block    562176
  5312. ----------------------------------------------------------------------------
  5313.  
  5314. The block region looks pretty huge to me after the test - as if garbage
  5315. collection wasn't getting done or something.  Maybe I'll look at the code
  5316. and see what's up.
  5317.  
  5318. Anyway, you can see the .472 ms. above tells you how long it takes to do
  5319. an "every put(l, 1 to 4)."  You can use this program to test other list
  5320. operations.
  5321.  
  5322. I guess this doesn't really answer your question about what sorts of list
  5323. ops in Icon are fastest, but I'm not really sure of all that you want to
  5324. do.  The empg program will give you answers far more specific than you'd
  5325. get from me, though :-).
  5326.  
  5327. Let us know what you find out.
  5328.  
  5329. -- 
  5330.  
  5331.    -Richard L. Goerwitz              goer%sophist@uchicago.bitnet
  5332.    goer@sophist.uchicago.edu         rutgers!oddjob!gide!sophist!goer
  5333. -- 
  5334.  
  5335.    -Richard L. Goerwitz              goer%sophist@uchicago.bitnet
  5336.    goer@sophist.uchicago.edu         rutgers!oddjob!gide!sophist!goer
  5337.  
  5338. From kwalker  Mon Nov 18 11:50:46 1991
  5339. Received: from ocotillo.cs.arizona.edu by cheltenham.cs.arizona.edu; Mon, 18 Nov 91 11:50:46 MST
  5340. Date: Mon, 18 Nov 91 11:50:45 MST
  5341. From: "Kenneth Walker" <kwalker>
  5342. Message-Id: <9111181850.AA29453@ocotillo.cs.arizona.edu>
  5343. Received: by ocotillo.cs.arizona.edu; Mon, 18 Nov 91 11:50:45 MST
  5344. To: icon-group
  5345. Subject: RE: list manipulation
  5346.  
  5347. > Richard Goerwitz writes:
  5348.  
  5349. > If you want to time, say,
  5350.  
  5351. >     l := []
  5352. >     every put(l, 1 to 4)
  5353.  
  5354. > you'd put these two lines into a file (prepend a colon to the first line,
  5355. > though; this is how you tell empg to execute the line, but not time it),
  5356. > and then run empg on that file.
  5357. > ...
  5358. > The block region looks pretty huge to me after the test - as if garbage
  5359. > collection wasn't getting done or something.
  5360.  
  5361. The problem here is that put(l, 1 to 4) is being executed repeatedly
  5362. (otherwise the timing will be less than the resolution of the system
  5363. clock). The same list is used for each execution and all the elements
  5364. end up in it so nothing can be collected.
  5365.  
  5366.   Ken Walker / Computer Science Dept / Univ of Arizona / Tucson, AZ 85721
  5367.   +1 602 621-4252  kwalker@cs.arizona.edu {uunet|allegra|noao}!arizona!kwalker
  5368.  
  5369. From icon-group-request@arizona.edu  Tue Nov 19 19:04:09 1991
  5370. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Tue, 19 Nov 91 19:04:09 MST
  5371. Resent-From: icon-group-request@arizona.edu
  5372. Received: from Arizona.edu (Merlin.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  5373.     id AA28150; Tue, 19 Nov 91 18:30:09 MST
  5374. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Tue, 19 Nov
  5375.  1991 18:29 MST
  5376. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA04437; Tue, 19 Nov 91
  5377.  15:24:55 -0800
  5378. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  5379.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  5380.  usenet@ucbvax.Berkeley.EDU if you have questions)
  5381. Resent-Date: Tue, 19 Nov 1991 18:29 MST
  5382. Date: 19 Nov 91 20:10:11 GMT
  5383. From: micro-heart-of-gold.mit.edu!wupost!uwm.edu!linac!uchinews!ellis!goer@bloom-beacon.mit.edu (Richard
  5384.  L. Goerwitz)
  5385. Subject: getch() for UNIX (was Re: global variables)
  5386. Sender: icon-group-request@arizona.edu
  5387. Resent-To: icon-group@cs.arizona.edu
  5388. To: icon-group@arizona.edu
  5389. Resent-Message-Id: <2671E71D0A606591@Arizona.edu>
  5390. Message-Id: <1991Nov19.201011.15479@midway.uchicago.edu>
  5391. X-Envelope-To: icon-group@CS.Arizona.EDU
  5392. X-Vms-To: icon-group@Arizona.edu
  5393. Organization: University of Chicago Computing Organizations
  5394. References: <9111172152.AA25943@relay1.UU.NET>,
  5395.  <1991Nov17.235713.27108@midway.uchicago.edu>
  5396.  
  5397.  
  5398. From icon-group-request@arizona.edu  Tue Nov 19 19:04:22 1991
  5399. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Tue, 19 Nov 91 19:04:22 MST
  5400. Resent-From: icon-group-request@arizona.edu
  5401. Received: from Arizona.edu (Osprey.Telcom.Arizona.EDU) by optima.cs.arizona.edu (4.1/15)
  5402.     id AA28112; Tue, 19 Nov 91 18:30:01 MST
  5403. Received: from ucbvax.Berkeley.EDU by Arizona.edu with PMDF#10282; Tue, 19 Nov
  5404.  1991 18:28 MST
  5405. Received: by ucbvax.Berkeley.EDU (5.63/1.42) id AA04437; Tue, 19 Nov 91
  5406.  15:24:55 -0800
  5407. Received: from USENET by ucbvax.Berkeley.EDU with netnews for
  5408.  icon-group@arizona.edu (icon-group@arizona.edu) (contact
  5409.  usenet@ucbvax.Berkeley.EDU if you have questions)
  5410. Resent-Date: Tue, 19 Nov 1991 18:29 MST
  5411. Date: 19 Nov 91 20:10:11 GMT
  5412. From: micro-heart-of-gold.mit.edu!wupost!uwm.edu!linac!uchinews!ellis!goer@bloom-beacon.mit.edu (Richard
  5413.  L. Goerwitz)
  5414. Subject: getch() for UNIX (was Re: global variables)
  5415. Sender: icon-group-request@arizona.edu
  5416. Resent-To: icon-group@cs.arizona.edu
  5417. To: icon-group@arizona.edu
  5418. Resent-Message-Id: <26613FBB4C0031AA@Arizona.edu>
  5419. Message-Id: <1991Nov19.201011.15479@midway.uchicago.edu>
  5420. X-Envelope-To: icon-group@CS.Arizona.EDU
  5421. X-Vms-To: icon-group@Arizona.edu
  5422. Organization: University of Chicago Computing Organizations
  5423. References: <9111172152.AA25943@relay1.UU.NET>,
  5424.  <1991Nov17.235713.27108@midway.uchicago.edu>
  5425.  
  5426. After teasing Jerry Nowlin for an understandable desire to promote his
  5427. fine product, I asked if he'd perhaps check to see if some SYSV code
  5428. worked with ISIcon.  What it was was a getch() implementation for UNIX.
  5429.  
  5430. I've been fooling with some code to do this, and passing it around to
  5431. some people.  It seems to work okay, but it's SYSV only right now.  I
  5432. took a stab at how to do it under BSD, but didn't really get anywhere,
  5433. not being a BSD person primarily.
  5434.  
  5435. Anyway, if someone knows a thing or two about BSD ioctl and character
  5436. special files, then perhaps he or she could clean up the following code
  5437. so it works like the SYSV code its stuck together with.  The end result
  5438. would be a workable set of kbhit(), getch(), getche() routines for
  5439. UNIX.
  5440.  
  5441. To compile these into Icon, you'll need to (for __STDC__ systems) define
  5442. the routines here in h/proto.h (or wherever the prototypes are), and also
  5443. reconfigure your Icon source with config/unix/your-unix-variant/defines.h
  5444. mentioning #define KeyboardFncs.  Then tack these routines onto the end
  5445. of src/iconx/fsys.c, making sure you've checked it over for your system.
  5446.  
  5447. Note:  Don't screw up your Icon source tree while testing.  Use the Icon
  5448. personalized interpreter mechanism.  Note also:  The routines below are
  5449. defined as working only for XENIX_386.  There are some #ifdef BSD routines
  5450. later on that aren't tested.  These are what really need work.  The Xenix
  5451. routines may work on all SYSVr3-4 systems, but you'll need to add -lx to
  5452. the config/unix/your-unix-verions/iconx.hdr file where the libraries are
  5453. mentioned if you're using Xenix (SYSV, too?).
  5454.  
  5455. With a little team effort, maybe we can get this all worked out.
  5456.  
  5457. #ifdef XENIX_386  /* maybe any SYSV; if so define it in the define.h file */
  5458.  
  5459. /* #include <stdio.h> - included by ../h/config.h above */
  5460. #include <sys/termio.h>
  5461. #include <sys/ioctl.h>
  5462. #include <sys/errno.h>
  5463. #include <sys/signal.h>
  5464.  
  5465. #define ECHO_ON 1
  5466. #define ECHO_OFF 0
  5467. #define CopyTty(t1,t2)    if (! reset_flag) {\
  5468.               t2 = t1;\
  5469.               reset_flag = 1;\
  5470.             }
  5471. #define ResetTty(t1)    if (reset_flag) {\
  5472.               if (ioctl(0, TCSETA, t1) == -1)\
  5473.                 RunErr(-214, NULL);\
  5474.             }
  5475. /*
  5476.  * kbhit(): word
  5477.  *
  5478.  * Routine to check for the availability of characters on the stdin
  5479.  * stream.  Does not actually read any characters.  Returns nonzero
  5480.  * value if characters are waiting; otherwise, zero.
  5481.  */
  5482. word kbhit()
  5483. {
  5484.   struct termio tty, new_tty;
  5485.   register word status, isa_tty = 0, reset_flag = 0;
  5486.   extern word errno;
  5487.  
  5488.   if (isatty(0)) {
  5489.  
  5490.     isa_tty = 1;
  5491.     if (ioctl(0, TCGETA, &tty) == -1)
  5492.       RunErr(-214, NULL);
  5493.  
  5494.     if (tty.c_lflag & ICANON) {
  5495.       CopyTty(tty, new_tty);
  5496.       new_tty.c_lflag &= ~ICANON;
  5497.       if (ioctl(0, TCSETA, &new_tty) == -1) {
  5498.     ResetTty(&tty);
  5499.     RunErr(-214, NULL);
  5500.       }
  5501.     }
  5502.   }
  5503.  
  5504.   /* see if anything is waiting to be read from the file */
  5505.   status = rdchk(0);
  5506.   if (status == -1) {
  5507.     if (isa_tty) ResetTty(&tty);
  5508.     switch (errno) {
  5509.     case EBADF:
  5510.       RunErr(-212, NULL);
  5511.     default:
  5512.       RunErr(-214, NULL);
  5513.     }
  5514.   }
  5515.  
  5516.   ResetTty(&tty);     
  5517.   return status;
  5518. }
  5519.  
  5520. /*
  5521.  * getch(): word
  5522.  *
  5523.  * Routine to read one char from the standard input.  Disables canonical
  5524.  * processing so as to read the character right from the buffer, without
  5525.  * having to wait for a carriage return.  Re-enables canonical processing
  5526.  * after reading a character.  Note that getch() does not echo any char-
  5527.  * acters to the screen, although characters might appear on the screen
  5528.  * anyway, if they were typed before getch() was invoked.
  5529.  */
  5530. word getch()
  5531. {
  5532.   word read_a_char();
  5533.   return read_a_char(ECHO_OFF);
  5534. }
  5535.  
  5536. /*
  5537.  * getche(): word
  5538.  *
  5539.  * Routine to read one char from the standard input.  Disables canonical
  5540.  * processing so as to read the character right from the buffer, without
  5541.  * having to wait for a carriage return.  Re-enables canonical processing
  5542.  * after reading a character.  NOTE:  Getche() does not disable echoing,
  5543.  * so anything typed after it is invoked will be echoed to the screen
  5544.  * (unlike getch(), which disables echoing; see above).
  5545.  */
  5546. word getche()
  5547. {
  5548.   word read_a_char();
  5549.   return read_a_char(ECHO_ON);
  5550. }
  5551.  
  5552. /*
  5553.  * read_a_char(turn_echo_on): word
  5554.  *
  5555.  * Routine to actually do the reading (either with echo or without,
  5556.  * depending on whether turn_echo_on is 1 or 0).
  5557.  */
  5558. word read_a_char(turn_echo_on)
  5559. word turn_echo_on;
  5560. {
  5561.  
  5562.   char c;
  5563.   struct termio tty, new_tty;
  5564.   register word status, isa_tty = 0, reset_flag = 0;
  5565.   novalue abort_on_signal();
  5566.   extern word errno;
  5567.   
  5568.   if (isatty(0)) {
  5569.  
  5570.     isa_tty = 1;
  5571.     if (ioctl(0, TCGETA, &tty) == -1)
  5572.       RunErr(-214, NULL);
  5573.  
  5574.     /* disable keyboard signals quit & interrupt */
  5575.     if (tty.c_lflag & ISIG) {
  5576.       CopyTty(tty, new_tty);    /* a macro, defined above */
  5577.       new_tty.c_lflag &= ~ISIG;
  5578.     }
  5579.     /* disable canonical input processing (like BSD cbreak) */
  5580.     if (tty.c_lflag & ICANON) {
  5581.       CopyTty(tty, new_tty);
  5582.       new_tty.c_lflag &= ~ICANON;
  5583.     }
  5584.     if (tty.c_cc[VMIN] != '\1') {
  5585.       CopyTty(tty, new_tty);
  5586.       new_tty.c_cc[VMIN] = (unsigned char )'\1';
  5587.     }
  5588.     if (tty.c_cc[VTIME]) {
  5589.       CopyTty(tty, new_tty);
  5590.       new_tty.c_cc[VTIME] = (unsigned char )'\0';
  5591.     }
  5592.     if (turn_echo_on) {
  5593.       /* set echo bit, i.e. enable echo */
  5594.       if (! (tty.c_lflag & ECHO)) {
  5595.     CopyTty(tty, new_tty);
  5596.     new_tty.c_lflag |= ECHO;
  5597.       }
  5598.     }
  5599.     else { /* i.e. if _not_ turn_echo_on */
  5600.       /* mask out echo bit, i.e. disable echo */
  5601.       if (tty.c_lflag & ECHO) {
  5602.     CopyTty(tty, new_tty);
  5603.     new_tty.c_lflag &= ~ECHO;
  5604.       }
  5605.     }
  5606.     ResetTty(&new_tty);        /* a macro, defined above */
  5607.   }
  5608.  
  5609.   /* finally, read 1 char from the standard input */
  5610.   status = read(0, &c, 1);
  5611.   if (status == -1) {
  5612.     if (isa_tty) ResetTty(&tty);
  5613.     switch (errno) {
  5614.     case EBADF:
  5615.       RunErr(-212, NULL);
  5616.     default:
  5617.       RunErr(-214, NULL);
  5618.     }
  5619.   }
  5620.  
  5621.   /* Check for quit and interrupt characters. */
  5622.   if (isa_tty) {
  5623.     if ((unsigned char)c == tty.c_cc[VINTR]) {
  5624.       ResetTty(&tty);
  5625.       if (kill(getpid(), SIGINT) == -1) {
  5626.     perror("kill");
  5627.     RunErr(500, NULL);
  5628.       }
  5629.     }
  5630.     else if ((unsigned char)c == tty.c_cc[VQUIT]) {
  5631.       ResetTty(&tty);
  5632.       if (kill(getpid(), SIGQUIT) == -1) {
  5633.     perror("kill");
  5634.     RunErr(500, NULL);
  5635.       }
  5636.     } else ResetTty(&tty);
  5637.   } else ResetTty(&tty);
  5638.  
  5639.   if (! status) return -1;
  5640.   else return (word )c;
  5641. }
  5642.  
  5643. #else                /* not XENIX_386 */
  5644. #if defined(SUN) || defined(NEXT)
  5645.  
  5646. /* This code is quite untested, and is considerably less sophisticated
  5647.  * than the SYSVr3+/XENIX code I wrote above.  Somebody who knows the
  5648.  * ins and outs of BSD ioctls, please take a look at this!
  5649.  */
  5650.  
  5651. /* #include <stdio.h> - included by ../h/config.h */
  5652. #ifdef SUN
  5653. #include <sys/filio.h>
  5654. #endif
  5655. #include <sys/ioctl.h>
  5656. #include <errno.h>
  5657.  
  5658. #define CopyTty(t1,t2)    if (! reset_flag) {\
  5659.               t2 = t1;\
  5660.               reset_flag = 1;\
  5661.             }
  5662. word kbhit()
  5663. {
  5664.  
  5665.   word arg;
  5666.   struct sgttyb tty, new_tty;
  5667.   register status, reset_flag = 0;
  5668.   extern word errno;
  5669.  
  5670.   if (isatty(0)) {
  5671.     if (ioctl(0, TIOCGETP, &tty) == -1)
  5672.       RunErr(-214, NULL);
  5673.      
  5674.     if (! (tty.sg_flags & CBREAK)) {
  5675.       CopyTty(tty, new_tty);
  5676.       new_tty.sg_flags |= CBREAK;
  5677.       if (ioctl(0, TIOCSETN, &new_tty) == -1)
  5678.     RunErr(-214, NULL);
  5679.     }
  5680.   }
  5681.      
  5682.   status = ioctl(0, FIONREAD, &arg);
  5683.   if (status == -1) {
  5684.     switch (errno) {
  5685.     case EBADF:
  5686.       RunErr(-212, NULL);
  5687.     default:
  5688.       RunErr(-214, NULL);
  5689.     }
  5690.   }
  5691.      
  5692.   if (reset_flag) {
  5693.     if (status = ioctl(0, TIOCSETN, &tty) == -1)
  5694.       RunErr(-214, NULL);
  5695.   }
  5696.  
  5697.   return(arg);
  5698. }
  5699.  
  5700. /*
  5701.  * getch(): word
  5702.  *
  5703.  * Routine to read one char from the standard input.  Enables cbreak mode
  5704.  * so as to read a character right from the buffer, without having to wait
  5705.  * for a carriage return.  Disables cbreak mode after reading a character.
  5706.  * Note that getch() does not echo any characters to the screen, although
  5707.  * characters might appear on the screen anyway, if they were typed before
  5708.  * getch() was invoked.
  5709.  */
  5710. word getch()
  5711. {
  5712.  
  5713.   char c;
  5714.   struct sgttyb tty, new_tty;
  5715.   register word status, reset_flag = 0;
  5716.   extern word errno;
  5717.   
  5718.   if (isatty(0)) {
  5719.     if (ioctl(0, TIOCGETP, &tty) == -1)
  5720.       RunErr(-214, NULL);
  5721.      
  5722.     if (! (tty.sg_flags & CBREAK)) {
  5723.       CopyTty(tty, new_tty);    /* sets reset_flag */
  5724.       new_tty.sg_flags |= CBREAK;
  5725.     }
  5726.     if (tty.sg_flags & ECHO) {
  5727.       CopyTty(tty, new_tty);
  5728.       new_tty.sg_flags &= ~ECHO;
  5729.     }
  5730.  
  5731.     if (reset_flag) {
  5732.       if (ioctl(0, TIOCSETN, &new_tty) == -1)
  5733.     RunErr(-214, NULL);
  5734.     }
  5735.   }
  5736.  
  5737.   status = read(0, &c, 1);
  5738.   if (status == -1) {
  5739.     switch (errno) {
  5740.     case EBADF:
  5741.       RunErr(-212, NULL);
  5742.     default:
  5743.       RunErr(-214, NULL);
  5744.     }
  5745.   }
  5746.  
  5747.   if (reset_flag) {
  5748.     if (ioctl(0, TIOCSETN, &tty) == -1)
  5749.       RunErr(-214, NULL);
  5750.   }
  5751.  
  5752.   if (! status) return -1;
  5753.   else return (word )c;
  5754. }
  5755.  
  5756. /*
  5757.  * getche(): word
  5758.  *
  5759.  * Routine to read one char from the standard input.  Enables cbreak mode,
  5760.  * to read the character right from the buffer, without having to wait for
  5761.  * a carriage return.  Disables cbreak mode after reading a character.  NOTE:
  5762.  * Getche() does not disable echoing, so anything typed after it is invoked
  5763.  * will be echoed to the screen (unlike getch(), which disables echoing; see
  5764.  * above).
  5765.  */
  5766. word getche()
  5767. {
  5768.  
  5769.   char c;
  5770.   struct sgttyb tty, new_tty;
  5771.   register word status, reset_flag = 0;
  5772.   extern word errno;
  5773.   
  5774.   if (isatty(0)) {
  5775.     if (ioctl(0, TIOCGETP, &tty) == -1)
  5776.       RunErr(-214, NULL);
  5777.      
  5778.     if (! (tty.sg_flags & CBREAK)) {
  5779.       CopyTty(tty, new_tty);    /* sets reset_flag */
  5780.       new_tty.sg_flags |= CBREAK;
  5781.     }
  5782.     if (! (tty.sg_flags & ECHO)) {
  5783.       CopyTty(tty, new_tty);
  5784.       new_tty.sg_flags |= ECHO;
  5785.     }
  5786.  
  5787.     if (reset_flag) {
  5788.       if (ioctl(0, TIOCSETN, &new_tty) == -1)
  5789.     RunErr(-214, NULL);
  5790.     }
  5791.   }
  5792.  
  5793.   status = read(0, &c, 1);
  5794.   if (status == -1) {
  5795.     switch (errno) {
  5796.     case EBADF:
  5797.       RunErr(-212, NULL);
  5798.     default:
  5799.       RunErr(-214, NULL);
  5800.     }
  5801.   }
  5802.  
  5803.   if (reset_flag) {
  5804.     if (ioctl(0, TIOCSETN, &tty) == -1)
  5805.       RunErr(-214, NULL);
  5806.   }
  5807.  
  5808.   if (! status) return -1;
  5809.   else return (word )c;
  5810. }
  5811. #endif                /* SUN or NEXT */
  5812. #endif                /* XENIX_386 */
  5813. #endif                /* KeyboardFncs */
  5814. -- 
  5815.  
  5816.    -Richard L. Goerwitz              goer%sophist@uchicago.bitnet
  5817.    goer@sophist.uchicago.edu         rutgers!oddjob!gide!sophist!goer
  5818.  
  5819. From icon-group-request  Sat Nov 23 21:37:11 1991
  5820. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Sat, 23 Nov 91 21:37:11 MST
  5821. Received: from ucbvax.Berkeley.EDU by optima.cs.arizona.edu (4.1/15)
  5822.     id AA09553; Sat, 23 Nov 91 21:37:09 MST
  5823. Received: by ucbvax.Berkeley.EDU (5.63/1.42)
  5824.     id AA20120; Sat, 23 Nov 91 20:24:58 -0800
  5825. Received: from USENET by ucbvax.Berkeley.EDU with netnews
  5826.     for icon-group@cs.arizona.edu (icon-group@cs.arizona.edu)
  5827.     (contact usenet@ucbvax.Berkeley.EDU if you have questions)
  5828. Date: 21 Nov 91 14:44:23 GMT
  5829. From: mailer.cc.fsu.edu!sun13!sun8.scri.fsu.edu@gatech.edu  (John Nall)
  5830. Organization: SCRI, Florida State University
  5831. Subject: Combinatorial generator
  5832. Message-Id: <5628@sun13.scri.fsu.edu>
  5833. Sender: icon-group-request@cs.arizona.edu
  5834. To: icon-group@cs.arizona.edu
  5835.  
  5836.  
  5837. Hello, world:
  5838.      Does anyone happen to have a combinatorial generator they would
  5839. be willing to share with me??  I'm a novice at writing in Icon, and
  5840. although I've been able to do most (but not all) of the exercises in
  5841. the book, I can't seem to figure out how to solve this particular
  5842. problem.
  5843.  
  5844.      What I am looking for would be something along the lines of:
  5845.  
  5846.               every  group := combination("abcd",3)
  5847.  
  5848. which would say "generate all combinations of the four objects "a", "b",
  5849. "c" and "d", taken 3 at a time". ("abc", "abd", "acd" and "bcd")
  5850.  
  5851.      Since I'm interested in how to program the problem, rather than any
  5852. particular application, if you could even share a variation of the above
  5853. it would probably be helpful.
  5854.  
  5855. Thanks much
  5856. --
  5857. John W. Nall        | Supercomputer Computations Research Institute
  5858. nall@sun8.scri.fsu.edu  | Florida State University, Tallahassee, FL 32306
  5859. (904)-644-6008          | "Down with liberals.  Down with conservatives."
  5860.  
  5861. From icon-group-request  Sat Nov 23 23:23:11 1991
  5862. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Sat, 23 Nov 91 23:23:11 MST
  5863. Received: from ucbvax.Berkeley.EDU by optima.cs.arizona.edu (4.1/15)
  5864.     id AA11967; Sat, 23 Nov 91 23:23:09 MST
  5865. Received: by ucbvax.Berkeley.EDU (5.63/1.42)
  5866.     id AA23759; Sat, 23 Nov 91 22:15:59 -0800
  5867. Received: from USENET by ucbvax.Berkeley.EDU with netnews
  5868.     for icon-group@cs.arizona.edu (icon-group@cs.arizona.edu)
  5869.     (contact usenet@ucbvax.Berkeley.EDU if you have questions)
  5870. Date: 21 Nov 91 20:10:20 GMT
  5871. From: world!ksr!tim@uunet.uu.net  (Tim Peters)
  5872. Organization: Kendall Square Research Corp.
  5873. Subject: Re: Combinatorial generator
  5874. Message-Id: <7238@ksr.com>
  5875. References: <5628@sun13.scri.fsu.edu>
  5876. Sender: icon-group-request@cs.arizona.edu
  5877. To: icon-group@cs.arizona.edu
  5878.  
  5879. In article <5628@sun13.scri.fsu.edu> nall@sun8.scri.fsu.edu (John Nall) writes:
  5880. > ...
  5881. >     What I am looking for would be something along the lines of:
  5882. >
  5883. >              every  group := combination("abcd",3)
  5884. >
  5885. >which would say "generate all combinations of the four objects "a", "b",
  5886. >"c" and "d", taken 3 at a time". ("abc", "abd", "acd" and "bcd")
  5887. >
  5888. >     Since I'm interested in how to program the problem, rather than any
  5889. >particular application, if you could even share a variation of the above
  5890. >it would probably be helpful.
  5891.  
  5892. John, once you get the hang of "recursive generators" in Icon, you'll
  5893. find that this kind of problem is surprisingly easy -- the coding is a
  5894. snap, the hard part is just finding the proper recurrence to build on
  5895. (which has nothing to do with Icon itself).  E.g.,
  5896.  
  5897. procedure main()
  5898.    local string, k
  5899.    every string := left("abcde", 0 to 5) & k := 0 to 1+*string do {
  5900.       write("Combinations of '", string, "' taken ", k, " at a time:")
  5901.       every write( "   '", comb(string, k), "'" )
  5902.    }
  5903. end
  5904.  
  5905. procedure comb( s, k )
  5906.    k < 0 & stop("error in comb argument, need k=", k, " to be >=0")
  5907.    k = 0 & return ""
  5908.    *s < k & fail
  5909.    suspend (s[1] || comb(s[2:0], k-1)) | comb(s[2:0], k)
  5910. end
  5911.  
  5912.  
  5913. is built directly from the reasoning underlying the recurrence
  5914.     C(n,k) = C(n-1,k-1) + C(n-1,k)
  5915. for binomial coefficients (see any combinatorics text for a derivation).
  5916.  
  5917. The program prints:
  5918.  
  5919. Combinations of '' taken 0 at a time:
  5920.    ''
  5921. Combinations of '' taken 1 at a time:
  5922. Combinations of 'a' taken 0 at a time:
  5923.    ''
  5924. Combinations of 'a' taken 1 at a time:
  5925.    'a'
  5926. Combinations of 'a' taken 2 at a time:
  5927. Combinations of 'ab' taken 0 at a time:
  5928.    ''
  5929. Combinations of 'ab' taken 1 at a time:
  5930.    'a'
  5931.    'b'
  5932. Combinations of 'ab' taken 2 at a time:
  5933.    'ab'
  5934. Combinations of 'ab' taken 3 at a time:
  5935. Combinations of 'abc' taken 0 at a time:
  5936.    ''
  5937. Combinations of 'abc' taken 1 at a time:
  5938.    'a'
  5939.    'b'
  5940.    'c'
  5941. Combinations of 'abc' taken 2 at a time:
  5942.    'ab'
  5943.    'ac'
  5944.    'bc'
  5945. Combinations of 'abc' taken 3 at a time:
  5946.    'abc'
  5947. Combinations of 'abc' taken 4 at a time:
  5948. Combinations of 'abcd' taken 0 at a time:
  5949.    ''
  5950. Combinations of 'abcd' taken 1 at a time:
  5951.    'a'
  5952.    'b'
  5953.    'c'
  5954.    'd'
  5955. Combinations of 'abcd' taken 2 at a time:
  5956.    'ab'
  5957.    'ac'
  5958.    'ad'
  5959.    'bc'
  5960.    'bd'
  5961.    'cd'
  5962. Combinations of 'abcd' taken 3 at a time:
  5963.    'abc'
  5964.    'abd'
  5965.    'acd'
  5966.    'bcd'
  5967. Combinations of 'abcd' taken 4 at a time:
  5968.    'abcd'
  5969. Combinations of 'abcd' taken 5 at a time:
  5970. Combinations of 'abcde' taken 0 at a time:
  5971.    ''
  5972. Combinations of 'abcde' taken 1 at a time:
  5973.    'a'
  5974.    'b'
  5975.    'c'
  5976.    'd'
  5977.    'e'
  5978. Combinations of 'abcde' taken 2 at a time:
  5979.    'ab'
  5980.    'ac'
  5981.    'ad'
  5982.    'ae'
  5983.    'bc'
  5984.    'bd'
  5985.    'be'
  5986.    'cd'
  5987.    'ce'
  5988.    'de'
  5989. Combinations of 'abcde' taken 3 at a time:
  5990.    'abc'
  5991.    'abd'
  5992.    'abe'
  5993.    'acd'
  5994.    'ace'
  5995.    'ade'
  5996.    'bcd'
  5997.    'bce'
  5998.    'bde'
  5999.    'cde'
  6000. Combinations of 'abcde' taken 4 at a time:
  6001.    'abcd'
  6002.    'abce'
  6003.    'abde'
  6004.    'acde'
  6005.    'bcde'
  6006. Combinations of 'abcde' taken 5 at a time:
  6007.    'abcde'
  6008. Combinations of 'abcde' taken 6 at a time:
  6009.  
  6010.  
  6011. Suspect the first stumbling block for you will be believing that
  6012. recursive generators really work <grin>; the second will be figuring out
  6013. why I wrote the routine to fail in some endcases but to return a null
  6014. string in others.  Those choices aren't really as arbitrary as they may
  6015. appear ...
  6016.  
  6017. indeed-the-hardest-part-is-getting-the-endcases-just-right-ly y'rs  -
  6018.    tim
  6019.  
  6020. Tim Peters   Kendall Square Research Corp
  6021. tim@ksr.com,         ksr!tim@uunet.uu.net
  6022.  
  6023. From isidev!nowlin@uunet.uu.net  Sun Nov 24 13:32:09 1991
  6024. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Sun, 24 Nov 91 13:32:09 MST
  6025. Received: from relay2.UU.NET by optima.cs.arizona.edu (4.1/15)
  6026.     id AA05820; Sun, 24 Nov 91 13:32:05 MST
  6027. Received: from uunet.uu.net (via LOCALHOST.UU.NET) by relay2.UU.NET with SMTP 
  6028.     (5.61/UUNET-internet-primary) id AA13447; Sun, 24 Nov 91 15:32:08 -0500
  6029. Date: Sun, 24 Nov 91 15:32:08 -0500
  6030. From: isidev!nowlin@uunet.uu.net
  6031. Message-Id: <9111242032.AA13447@relay2.UU.NET>
  6032. Received: from isidev.UUCP by uunet.uu.net with UUCP/RMAIL
  6033.     (queueing-rmail) id 153104.18589; Sun, 24 Nov 1991 15:31:04 EST
  6034. To: uunet!cs.arizona.edu!icon-group@uunet.uu.net
  6035. Subject: Re: combinations
  6036.  
  6037. This reminded me of a program I wrote for my daughter when she was in 4th
  6038. grade some years ago.  She had a list of 10 letters and the challenge was
  6039. to get as many words from the list as possible.  Since parents were allowed
  6040. to help, I wrote a program in Icon to generate all the possible
  6041. combinations of the 10 letters, run it through a spelling checker to
  6042. identify non-words, and then list the real words left over.  Not being real
  6043. foresighted, I didn't really ponder how many possible combinations there
  6044. were until I looked the next day and I'd run the my hard disk out of space
  6045. and still not generated all the possibilities.
  6046.  
  6047. Here's a program that has both the unique combinations (sets) that John
  6048. Nall requested and Tim Peters provided, and the whole shebang with the
  6049. order of objects in a given combination being significant.  You feed this
  6050. the objects and size instead of it iterating on everything.  Let me know if
  6051. I goofed since I blew away my original program a long time ago.
  6052.  
  6053. Sorry but I couldn't leave Tim's procedure alone.  I just changed it a
  6054. little.  I prefer clarity to idiomatic code, sometimes :-)  Here's the
  6055. output from the program for groups of three objects of size three:
  6056.  
  6057.         $ comb abc 3
  6058.         Unique combinations:
  6059.         abc
  6060.         All combinations:
  6061.         abc
  6062.         acb
  6063.         bac
  6064.         bca
  6065.         cab
  6066.         cba
  6067.  
  6068. WARNING: Try this on large groups of objects at your own risk:
  6069.  
  6070.   procedure main(args)
  6071.       local objs, size
  6072.  
  6073.       objs := get(args) | stop("No 1st argument")
  6074.       size := get(args) | stop("No 2nd argument")
  6075.  
  6076.       write("Unique combinations:")
  6077.       every write(combu(objs,size))
  6078.  
  6079.       write("All combinations:")
  6080.       every write(comba(objs,size))
  6081.   end
  6082.  
  6083.   procedure combu(objs,size)
  6084.       if size < 1 then fail
  6085.       else if size = 1 then suspend !objs
  6086.       else suspend objs[1] || combu(objs[2:0],size - 1) | combu(objs[2:0],size)
  6087.   end
  6088.  
  6089.   procedure comba(objs,size)
  6090.       local n
  6091.  
  6092.       if size < 1 then fail
  6093.       else if size = 1 then suspend !objs
  6094.       else {
  6095.           every n := 1 to *objs do
  6096.               if n = 1 then
  6097.                    suspend objs[1] || comba(objs[2:0],size-1)
  6098.               else if n = *objs then
  6099.                    suspend objs[n] || comba(objs[1:n],size-1)
  6100.               else suspend objs[n] || comba(objs[1:n] || objs[n+1:0],size-1)
  6101.       }
  6102.   end
  6103.  
  6104. --- ---
  6105.  | S | Iconic Software, Inc.  -  Jerry Nowlin  -  uunet!isidev!nowlin
  6106. --- ---
  6107.  
  6108.  
  6109. From icon-group-request  Sun Nov 24 16:24:41 1991
  6110. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Sun, 24 Nov 91 16:24:41 MST
  6111. Received: from ucbvax.Berkeley.EDU by optima.cs.arizona.edu (4.1/15)
  6112.     id AA10962; Sun, 24 Nov 91 16:24:39 MST
  6113. Received: by ucbvax.Berkeley.EDU (5.63/1.42)
  6114.     id AA17180; Sun, 24 Nov 91 15:21:20 -0800
  6115. Received: from USENET by ucbvax.Berkeley.EDU with netnews
  6116.     for icon-group@cs.arizona.edu (icon-group@cs.arizona.edu)
  6117.     (contact usenet@ucbvax.Berkeley.EDU if you have questions)
  6118. Date: 24 Nov 91 23:08:11 GMT
  6119. From: ksr!tim@uunet.uu.net  (Tim Peters)
  6120. Organization: Kendall Square Research Corp.
  6121. Subject: Re: combinations
  6122. Message-Id: <7301@ksr.com>
  6123. References: <9111242032.AA13447@relay2.UU.NET>
  6124. Sender: icon-group-request@cs.arizona.edu
  6125. To: icon-group@cs.arizona.edu
  6126.  
  6127. In article <9111242032.AA13447@relay2.UU.NET> nowlin@isidev.UUCP writes:
  6128. >... a list of 10 letters and the challenge was to get as many words
  6129. >from the list as possible. ... I wrote a program in Icon to generate
  6130. >all the possible combinations of the 10 letters, run it through a
  6131. >spelling checker to identify non-words, and then list the real words
  6132. >left over.
  6133.  
  6134. Jerry, I faced a similar problem when writing a program to generate
  6135. anagrams.  I had thought that anagrams would be rare (based on how hard
  6136. it is to find them by hand), but to the contrary found that, for a
  6137. decent-sized phrase, there are an enormous number of anagrams.  E.g., I
  6138. just let the program run on "Iconic Software" for 5 seconds & it came up
  6139. with several thousand distinct anagrams, not counting permutations of
  6140. the words or of letters within the words.  E.g., "I can coo swifter",
  6141. "actinic woofers", "action if escrow" (and "action" can be replaced by
  6142. "cation", and/or "escrow" by "cowers"), "I, of conic waters", "ionic cot
  6143. wafers", ... and those are some of the few anagrams that actually make
  6144. some sense <grin -- but your standards for "sense" do degenerate the
  6145. longer you look at a list of possibilities -- after pondering, e.g.,
  6146. "twice oaf is corn" & "twice fiasco nor" & "twain foci cores", I'm ready
  6147. to settle for just about anything>.
  6148.  
  6149. That program turned into quite a mess of backtracking trickery, but if
  6150. anyone faces a similar sub-task, a good start is to go thru the entire
  6151. dictionary (e.g., UNIX(tm) systems usually have large word lists hiding
  6152. in /usr/dict/) at the beginning, saving away all the *feasible* words in
  6153. an Icon set.  Then all the checking can be done internal to the program
  6154. (& set membership tests are quite fast), and against a vastly reduced
  6155. set of possibilities.
  6156.  
  6157. >...
  6158. >Sorry but I couldn't leave Tim's procedure alone.  I just changed it a
  6159. >little.  I prefer clarity to idiomatic code, sometimes :-)
  6160.  
  6161. Well, it's about time!  No newsgroup has really arrived until it's
  6162. hosted its first vicious style flame <grin>.  Seriously, I find either
  6163. style easy to read, & in programs this simple actually do find your
  6164. style clearer.
  6165.  
  6166. Attached is a slightly fiddled copy of your program, showing a different
  6167. way to get the "comba" (all permutations of "objs" taken "size" at a
  6168. time) function -- comba2 simply takes the result sequence of combu and
  6169. generates all permutations of each result.  I think this is conceptually
  6170. cleaner because it breaks the task into distinct subtasks (generating
  6171. combinations, and generating permutations).  More to the point, I really
  6172. like this "perms" function & haven't seen it posted before <grin>.
  6173.  
  6174. Finally, should note that "comb" and "permute" functions are already
  6175. just a "link" statement away, via the file "permute.icn" in the Icon
  6176. Program Library.
  6177.  
  6178. a-vastly-underappreciated-resource-ly y'rs  - tim
  6179.  
  6180. Tim Peters   Kendall Square Research Corp
  6181. tim@ksr.com,         ksr!tim@uunet.uu.net
  6182.  
  6183. procedure main(args)
  6184.     local objs, size
  6185.  
  6186.     objs := get(args) | stop("No 1st argument")
  6187.     size := integer(get(args)) | stop("Need integer 2nd argument")
  6188.  
  6189.     write("Unique combinations:")
  6190.     every write(combu(objs,size))
  6191.  
  6192.     write("All combinations:")
  6193.     every write(comba(objs,size))
  6194.  
  6195.     write("All combinations, a different way:")
  6196.     every write(comba2(objs,size))
  6197. end
  6198.  
  6199. procedure combu(objs,size)
  6200.     if size < 1 then fail
  6201.     else if size = 1 then suspend !objs
  6202.     else suspend objs[1] || combu(objs[2:0],size-1) | combu(objs[2:0],size)
  6203. end
  6204.  
  6205. procedure comba(objs,size)
  6206.     local n
  6207.  
  6208.     if size < 1 then fail
  6209.     else if size = 1 then suspend !objs
  6210.     else {
  6211.         every n := 1 to *objs do
  6212.             if n = 1 then
  6213.                  suspend objs[1] || comba(objs[2:0],size-1)
  6214.             else if n = *objs then
  6215.                  suspend objs[n] || comba(objs[1:n],size-1)
  6216.             else suspend objs[n] || comba(objs[1:n] || objs[n+1:0],size-1)
  6217.     }
  6218. end
  6219.  
  6220. procedure comba2(objs,size)
  6221.     suspend perms(combu(objs,size))
  6222. end
  6223.  
  6224. procedure perms(objs) # generate all permutations of objs
  6225.     if *objs <= 1 then return objs
  6226.     else suspend (objs[1] <-> !objs) || perms(objs[2:0])
  6227. end
  6228.  
  6229. >>> END OF MSG
  6230.  
  6231. From TENAGLIA@mis.mcw.edu  Tue Nov 26 09:56:00 1991
  6232. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Tue, 26 Nov 91 09:56:00 MST
  6233. Received: from MIS4.MIS.MCW.EDU by optima.cs.arizona.edu (4.1/15)
  6234.     id AA19660; Tue, 26 Nov 91 09:55:51 MST
  6235. Received: from mis.mcw.edu by mis.mcw.edu (PMDF #12252) id
  6236.  <01GDEHV25ZLS9AMF1Y@mis.mcw.edu>; Tue, 26 Nov 1991 10:58 CST
  6237. Date: Tue, 26 Nov 1991 10:58 CST
  6238. From: Chris Tenaglia - 257-8765 <TENAGLIA@mis.mcw.edu>
  6239. Subject: Holiday Tidbit
  6240. To: icon-group@cs.arizona.edu
  6241. Message-Id: <01GDEHV25ZLS9AMF1Y@mis.mcw.edu>
  6242. X-Organization: Medical College of Wisconsin (Milwaukee, WI)
  6243. X-Vms-To: IN%"icon-group@cs.arizona.edu"
  6244.  
  6245.  
  6246. As yet another holiday approaches I couldn't resist but to submit another
  6247. game implemented in icon. TicTacToe is old hat to most of us. I also know
  6248. I'll be flamed for my VT100 IO routines, oh well.
  6249.  
  6250. Ten years ago I wrote a basic interpreter for a very unusual workstation
  6251. that happened to have IBM 360 architecture. To test it's solidity I wrote
  6252. a brute force tictactoe that would never loose. Impressive at first, but
  6253. boring after a short time.
  6254.  
  6255. I decided to try it again, this time in Icon. While on the way to coding
  6256. the bulletproof version I envisioned, an alpha version has developed that
  6257. doesn't win all the time. What's even more curious, it sometimes cheats!
  6258. I'm including the source below for your comments and enjoyment. I'm going
  6259. to save it myself for reference, but I hope to develope the invincable and
  6260. fairplay version perhaps for the next holiday.
  6261.  
  6262. Enjoy!
  6263.  
  6264. Chris Tenaglia (System Manager) |  "The past explained,     
  6265. Medical College of Wisconsin    |   the future fortold, 
  6266. 8701 W. Watertown Plank Rd.     |   the present largely appologized for."
  6267. Milwaukee, WI 53226             |   Organon to The Doctor
  6268. (414)257-8765                   |     
  6269. tenaglia@mis.mcw.edu, mcwmis!tenaglia
  6270.  
  6271. ###############################################################
  6272. #                                                             #
  6273. #          file : ttt.icn                                     #
  6274. #          updt : 25-nov-1991                                 #
  6275. #          auth : chris tenaglia                              #
  6276. #          desc : tictactoe icon implementation               #
  6277. #                                                             #
  6278. ###############################################################
  6279. global me,you,true,false,draw,pointer,wins,pass,taken,winner
  6280. procedure main()                              
  6281.   init()                  #declare some global stuff
  6282.   play := true
  6283.   while play == true do
  6284.     {
  6285.     me      := set()      # computer is me
  6286.     you     := set()      # player   is you
  6287.     victory := false      # we haven't won yet
  6288.     pass    := 0          # start flag
  6289.     winner  := ""
  6290.     taken   := table(false)    # taken position table (rather than set?)
  6291.     display()
  6292.     insert(me,5)
  6293.     taken[5] := true
  6294.     display()
  6295.     insert(you,(tmp := get_your_move()))
  6296.     taken[integer(tmp)] := true
  6297.     display()
  6298.     repeat
  6299.       {
  6300.       insert(me,(tmp := choose([1,2,3,4,6,7,8,9])))
  6301.       taken[integer(tmp)] := true
  6302.       display()
  6303.       if (victory := done_yet()) == (true|draw) then break
  6304.       insert(you,(tmp := get_your_move()))
  6305.       taken[integer(tmp)] := true
  6306.       if (victory := done_yet()) == (true|draw) then break
  6307.       }
  6308.     display()
  6309.     if winner == "you" then victory := false
  6310.     case victory of
  6311.       {
  6312.       true : write(at(1,22),chop(&host)," Wins, You Loose!") 
  6313.       false: write(at(1,22),chop(),"Wow! You actually beat the Computer.")
  6314.       draw : write(at(1,22),chop(),"Game was a draw.")
  6315.       }
  6316.     play := map(input(at(1,23) || "Another Game (Y/N) :")[1])
  6317.     }
  6318.   end
  6319.  
  6320. #
  6321. # procedure to display the current tictactoe grid and plays
  6322. #
  6323. procedure display()
  6324.   if (pass +:= 1) = 1 then
  6325.     {
  6326.     write(cls(),uhalf(),"          T I C - T A C - T O E")
  6327.     write(lhalf(),"          T I C - T A C - T O E")
  6328.     write(trim(center("Computer is 'O' and you are 'X'",80)))
  6329.     line := repl("q",60) ; line[21] := "n" ; line[41] := "n"
  6330.     every y := 5 to 20 do writes(at(30,y),graf("x"))
  6331.     every y := 5 to 20 do writes(at(50,y),graf("x"))
  6332.     writes(at(10,10),graf(line))
  6333.     writes(at(10,15),graf(line))
  6334.     every x := 1 to 9  do writes(pointer[x],x)
  6335.     }
  6336.   every writes(pointer[!me],high("O"))
  6337.   every writes(pointer[!you],blink("X"))
  6338.   end
  6339.  
  6340. #
  6341. # procedure to obtain a move choice from the player
  6342. #
  6343. procedure get_your_move()
  6344.   local yours,all_moves
  6345.   repeat {
  6346.   writes(at(5,22))
  6347.   yours := input("Enter block # (1-9) :")
  6348.   if not(integer(yours)) then
  6349.     {
  6350.     writes(at(5,23),beep(),"Invalid Input! Choose 1-9.")
  6351.     next
  6352.     }
  6353.   if (1 > yours) | (yours > 9) then
  6354.     {
  6355.     writes(at(5,23),beep(),"Value out of range! Choose 1-9.")
  6356.     next
  6357.     }
  6358.   if taken[integer(yours)] == true then
  6359.     {
  6360.     writes(at(5,23),beep(),"That position is already taken! Try again.")
  6361.     next
  6362.     }
  6363.   break }
  6364.   return yours
  6365.   end
  6366.  
  6367. #
  6368. # procedure chooses for the host a strong move
  6369. #
  6370. procedure choose(lst)
  6371.   local val,test
  6372.   test := 0
  6373.   repeat {
  6374.   val := ?lst
  6375.   if (test +:= 1) > 200 then write(val," Choose: infinite loop")
  6376.   if taken[integer(val)] == true then next else break }
  6377.   return val
  6378.   end
  6379.   
  6380. #
  6381. # procedure to test if computer has won, or the game is a draw
  6382. #
  6383. procedure done_yet()
  6384.   every outcome := !wins do
  6385.     {
  6386.     test := 0
  6387.     every part := !outcome do
  6388.       if member(me,part) then test +:= 1
  6389.     if test = 3 then
  6390.       {
  6391.       winner := &host
  6392.       return true
  6393.       }
  6394.     }
  6395.   every outcome := !wins do
  6396.     {
  6397.     test := 0
  6398.     every part := !outcome do
  6399.       if member(you,part) then test +:= 1
  6400.     if test = 3 then
  6401.       {
  6402.       winner := "you"
  6403.       return true
  6404.       }
  6405.     }
  6406.   if *me + *you > 7 then return draw
  6407.   return false
  6408.   end
  6409.  
  6410. #
  6411. # prompts for an input from the user
  6412. #
  6413. procedure input(prompt)
  6414.   writes(prompt)
  6415.   return read()
  6416.   end
  6417.  
  6418. #
  6419. # procedures to output ansi graphics and attributes
  6420. #
  6421. procedure at(x,y)
  6422.   return "\e[" || y || ";" || x || "f"
  6423.   end
  6424.   
  6425. procedure graf(str)
  6426.   return "\e(0" || str || "\e(B"
  6427.   end
  6428.  
  6429. procedure uhalf(str)
  6430.   /str := ""
  6431.   return "\e#3" || str
  6432.   end
  6433.  
  6434. procedure lhalf(str)
  6435.   /str := ""
  6436.   return "\e#4" || str
  6437.   end
  6438.  
  6439. procedure high(str)
  6440.   return "\e[1m" || str || "\e[0m"
  6441.   end
  6442.  
  6443. procedure normal(str)
  6444.   return "\e[0m" || str
  6445.   end
  6446.  
  6447. procedure under(str)
  6448.   return "\e[4m" || str || "\e[0m"
  6449.   end
  6450.  
  6451. procedure blink(str)
  6452.   return "\e[5m" || str || "\e[0m"
  6453.   end
  6454.  
  6455. procedure cls(str)
  6456.   /str := ""
  6457.   return "\e[2J\e[H" || str
  6458.   end
  6459.  
  6460. procedure chop(str)
  6461.   /str := ""
  6462.   return "\e[J" || str
  6463.   end
  6464.  
  6465. procedure beep()
  6466.   return "\7"
  6467.   end
  6468.   
  6469. #
  6470. # procedure to init useful global variables for later use
  6471. #
  6472. procedure init()
  6473.   true    := "y"
  6474.   false   := "n"
  6475.   draw    := "?"
  6476.   &rand   := map(&clock,":","0")   #randomize
  6477.   wins    := [set([1,5,9]),set([3,5,7]),set([1,2,3]),set([4,5,6]),
  6478.               set([7,8,9]),set([1,4,7]),set([2,5,8]),set([3,6,9])]
  6479.   pointer := [at(17,7), at(37,7), at(57,7),
  6480.               at(17,12),at(37,12),at(57,12),
  6481.               at(17,17),at(37,17),at(57,17)]
  6482.   end
  6483.   
  6484.               
  6485.                                                     
  6486.  
  6487.  
  6488. From TENAGLIA@mis.mcw.edu  Wed Nov 27 07:03:42 1991
  6489. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Wed, 27 Nov 91 07:03:42 MST
  6490. Received: from MIS4.MIS.MCW.EDU by optima.cs.arizona.edu (4.1/15)
  6491.     id AA14551; Wed, 27 Nov 91 07:03:38 MST
  6492. Received: from mis.mcw.edu by mis.mcw.edu (PMDF #12252) id
  6493.  <01GDFQ5RI3C09AMFPF@mis.mcw.edu>; Wed, 27 Nov 1991 08:06 CST
  6494. Date: Wed, 27 Nov 1991 08:06 CST
  6495. From: Chris Tenaglia - 257-8765 <TENAGLIA@mis.mcw.edu>
  6496. Subject: TikTakToe
  6497. To: icon-group@cs.arizona.edu
  6498. Message-Id: <01GDFQ5RI3C09AMFPF@mis.mcw.edu>
  6499. X-Organization: Medical College of Wisconsin (Milwaukee, WI)
  6500. X-Vms-To: IN%"icon-group@cs.arizona.edu"
  6501.  
  6502.  
  6503. I've a little closer inspection of the tiktaktoe game I submitted. I did find
  6504. some careless coding. I've spiffed it up, and improved some of the video, but
  6505. it still cheats. It can't recognize when the player has a winning row. I won't
  6506. repost yet. I'm looking a little closer still. Oh well, that's what 2 hours
  6507. programming turns out.
  6508.  
  6509. Chris Tenaglia (System Manager) | Medical College of Wisconsin
  6510. 8701 W. Watertown Plank Rd.     | Milwaukee, WI 53226
  6511. (414)257-8765                   | tenaglia@mis.mcw.edu, mcwmis!tenaglia
  6512.  
  6513.  
  6514. From icon-group-request  Wed Nov 27 15:16:21 1991
  6515. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Wed, 27 Nov 91 15:16:21 MST
  6516. Received: from ucbvax.Berkeley.EDU by optima.cs.arizona.edu (4.1/15)
  6517.     id AA15400; Wed, 27 Nov 91 15:16:19 MST
  6518. Received: by ucbvax.Berkeley.EDU (5.63/1.42)
  6519.     id AA25764; Tue, 26 Nov 91 11:28:44 -0800
  6520. Received: from USENET by ucbvax.Berkeley.EDU with netnews
  6521.     for icon-group@cs.arizona.edu (icon-group@cs.arizona.edu)
  6522.     (contact usenet@ucbvax.Berkeley.EDU if you have questions)
  6523. Date: 26 Nov 91 01:35:35 GMT
  6524. From: ksr!tim@uunet.uu.net  (Tim Peters)
  6525. Organization: Kendall Square Research Corp.
  6526. Subject: Re: case insensitive find()
  6527. Message-Id: <7330@ksr.com>
  6528. References: <1991Nov25.120052.2151@arizona.edu>
  6529. Sender: icon-group-request@cs.arizona.edu
  6530. To: icon-group@cs.arizona.edu
  6531.  
  6532. In article <1991Nov25.120052.2151@arizona.edu> parten@ece.arizona.edu (Kurt Parten) writes:
  6533. >Has anyone come up with a case insensitive find()?
  6534. >I am not even sure how to implement such a creature.
  6535.  
  6536. Try rolling your own on the fly, Kurt.  E.g., where you have
  6537.     find( needle, haystack )
  6538. now, try
  6539.     find( map(needle), map(haystack) )
  6540. instead.  Or where you have
  6541.     haystack ? { ... find(needle) ... }
  6542. now, try
  6543.     map(haystack) ? { ... find(map(needle)) ... }
  6544. instead.
  6545.  
  6546. Many people I've shown the last version to are leery of it, because
  6547. somewhere along the way they got the idea that the subject of string
  6548. scanning must be a plain variable name or constant; but Icon is very
  6549. consistent about allowing an arbitrary expression anywhere a value is
  6550. allowed.
  6551.  
  6552. or-if-you-know-how-to-write-"find"-using-more-primitive-operations-
  6553.    you-can-write-a-"case_insenstive_find"-in-much-the-same-way-ly
  6554.    y'rs  - tim
  6555.  
  6556. Tim Peters   Kendall Square Research Corp
  6557. tim@ksr.com,         ksr!tim@uunet.uu.net
  6558.  
  6559. From TENAGLIA@mis.mcw.edu  Wed Nov 27 15:38:28 1991
  6560. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Wed, 27 Nov 91 15:38:28 MST
  6561. Received: from MIS4.MIS.MCW.EDU by optima.cs.arizona.edu (4.1/15)
  6562.     id AA16489; Wed, 27 Nov 91 15:38:20 MST
  6563. Received: from mis.mcw.edu by mis.mcw.edu (PMDF #12252) id
  6564.  <01GDG84VP5M89AMFPF@mis.mcw.edu>; Wed, 27 Nov 1991 16:41 CST
  6565. Date: Wed, 27 Nov 1991 16:41 CST
  6566. From: Chris Tenaglia - 257-8765 <TENAGLIA@mis.mcw.edu>
  6567. Subject: Holiday Tidbit Version 2
  6568. To: icon-group@cs.arizona.edu
  6569. Message-Id: <01GDG84VP5M89AMFPF@mis.mcw.edu>
  6570. X-Organization: Medical College of Wisconsin (Milwaukee, WI)
  6571. X-Vms-To: IN%"icon-group@cs.arizona.edu"
  6572.  
  6573.  
  6574. Well it's the holiday again. I poked at the tictactoe game a little more
  6575. and still couldn't find the reason why it cheats. I'm reposting the latest
  6576. version for anyone interested in a holiday hack. I kind of like it this
  6577. way. The more you try to win, the more you loose. The key is not trying
  6578. to win (it doesn't, but it does)! Enjoy.
  6579.  
  6580. Chris Tenaglia (System Manager) |  "The past explained,     
  6581. Medical College of Wisconsin    |   the future fortold, 
  6582. 8701 W. Watertown Plank Rd.     |   the present largely appologized for."
  6583. Milwaukee, WI 53226             |   Organon to The Doctor
  6584. (414)257-8765                   |     
  6585. tenaglia@mis.mcw.edu, mcwmis!tenaglia
  6586. --------------------------------------------------------------------------
  6587. ###############################################################
  6588. #                                                             #
  6589. #          file : ttt.icn                                     #
  6590. #          updt : 27-nov-1991                                 #
  6591. #          auth : chris tenaglia                              #
  6592. #          desc : tictactoe icon implementation               #
  6593. #                                                             #
  6594. ###############################################################
  6595. global me,you,true,false,draw,pointer,wins,pass,taken,winner,mark,row
  6596. procedure main()
  6597.   init()
  6598.   play := true
  6599.   while play == true do
  6600.     {
  6601.     me      := set()      # computer is me
  6602.     you     := set()      # player   is you
  6603.     victory := ""         # nobodys' won yet
  6604.     pass    := 0          # start flag
  6605.     winner  := ""
  6606.     taken   := table(false)    # taken position table (rather than set?)
  6607.     display()
  6608.     insert(me,5)
  6609.     taken[5] := true
  6610.     display()
  6611.     insert(you,(tmp := get_your_move()))
  6612.     taken[integer(tmp)] := true
  6613.     display()
  6614.     repeat
  6615.       {
  6616.       insert(me,(tmp := choose([1,2,3,4,6,7,8,9])))
  6617.       taken[integer(tmp)] := true
  6618.       display()
  6619.       if (victory := done_yet()) == (true|false|draw) then break
  6620.       insert(you,(tmp := get_your_move()))
  6621.       taken[integer(tmp)] := true
  6622.       if (victory := done_yet()) == (true|false|draw) then break
  6623.       }
  6624.     display()
  6625.     case winner of
  6626.       {
  6627.       "me" : {
  6628.              write(at(1,22),chop(&host)," Wins, You Loose!")
  6629.              every square := !row do writes(pointer[square],mark)
  6630.              }
  6631.       "you": {
  6632.              write(at(1,22),chop(),"Wow! You actually beat the Computer.")
  6633.              write(at(1,22),chop(&host)," Wins, You Loose!")
  6634.              every square := !row do writes(pointer[square],mark)
  6635.              } 
  6636.       draw : write(at(1,22),chop(),"Game was a draw.")
  6637.       }
  6638.     play := map(input(at(1,23) || "Another Game (Y/N) :")[1])
  6639.     }
  6640.   end
  6641. # #
  6642. #
  6643. # procedure to display the current tictactoe grid and plays
  6644. #
  6645. procedure display()
  6646.   if (pass +:= 1) = 1 then
  6647.     {
  6648.     write(cls(),uhalf(),"          T I C - T A C - T O E")
  6649.     write(lhalf(),"          T I C - T A C - T O E")
  6650.     write(trim(center("Computer is 'O' and you are 'X'",80)))
  6651.     line := repl("q",60) ; line[21] := "n" ; line[41] := "n"
  6652.     every y := 5 to 20 do writes(at(30,y),graf("x"))
  6653.     every y := 5 to 20 do writes(at(50,y),graf("x"))
  6654.     writes(at(10,10),graf(line))
  6655.     writes(at(10,15),graf(line))
  6656.     every x := 1 to 9  do writes(pointer[x],dim(x))
  6657.     }
  6658.   every writes(pointer[!me],high("O"))
  6659.   every writes(pointer[!you],under("X"))
  6660.   end
  6661.  
  6662. #
  6663. # procedure to obtain a move choice from the player
  6664. #
  6665. procedure get_your_move()
  6666.   local yours,all_moves
  6667.   repeat {
  6668.   writes(at(5,22))
  6669.   yours := input("Enter block # (1-9) :")
  6670.   writes(at(5,23),chop())
  6671.   if not(integer(yours)) then
  6672.     {
  6673.     writes(at(5,23),beep(),"Invalid Input! Choose 1-9.")
  6674.     next
  6675.     }
  6676.   if (1 > yours) | (yours > 9) then
  6677.     {
  6678.     writes(at(5,23),beep(),"Value out of range! Choose 1-9.")
  6679.     next
  6680.     }
  6681.   if taken[integer(yours)] == true then
  6682.     {
  6683.     writes(at(5,23),beep(),"That position is already taken! Try again.")
  6684.     next
  6685.     }
  6686.   break }
  6687.   return yours
  6688.   end
  6689. # #
  6690. #
  6691. # procedure chooses for the host a strong move
  6692. #
  6693. procedure choose(lst)
  6694.   local val,test
  6695.   test := 0
  6696.   repeat {
  6697.   val := ?lst
  6698.   if (test +:= 1) > 200 then write(val," Choose: infinite loop")
  6699.   if taken[integer(val)] == true then next else break }
  6700.   return val
  6701.   end
  6702.   
  6703. #
  6704. # procedure to test if computer has won, or the game is a draw
  6705. #
  6706. procedure done_yet()
  6707.   every outcome := !wins do
  6708.     {
  6709.     test := 0
  6710.     every part := !outcome do
  6711.       if member(you,part) then test +:= 1
  6712.     if test = 3 then
  6713.       {
  6714.       winner := "you"
  6715.       row    := outcome
  6716.       mark   := high(blink("X"))
  6717.       return true
  6718.       }
  6719.     }
  6720.   every outcome := !wins do
  6721.     {
  6722.     test := 0
  6723.     every part := !outcome do
  6724.       if member(me,part) then test +:= 1
  6725.     if test = 3 then
  6726.       {
  6727.       winner := "me"
  6728.       row    := outcome
  6729.       mark   := high(blink("O"))
  6730.       return true
  6731.       }             
  6732.     }
  6733.   if *me + *you > 8 then
  6734.     {
  6735.     winner := draw
  6736.     return draw
  6737.     }
  6738.   return "not done yet"
  6739.   end
  6740.  
  6741. #
  6742. # prompts for an input from the user
  6743. #
  6744. procedure input(prompt)
  6745.   writes(prompt)
  6746.   return read()
  6747.   end
  6748. # #
  6749. #
  6750. # procedures to output ansi graphics and attributes
  6751. #
  6752. procedure at(x,y)
  6753.   return "\e[" || y || ";" || x || "f"
  6754.   end
  6755.   
  6756. procedure graf(str)
  6757.   return "\e(0" || str || "\e(B"
  6758.   end
  6759.  
  6760. procedure uhalf(str)
  6761.   /str := ""
  6762.   return "\e#3" || str
  6763.   end
  6764.  
  6765. procedure lhalf(str)
  6766.   /str := ""
  6767.   return "\e#4" || str
  6768.   end
  6769.  
  6770. procedure high(str)
  6771.   return "\e[1m" || str || "\e[0m"
  6772.   end
  6773.  
  6774. procedure normal(str)
  6775.   return "\e[0m" || str
  6776.   end
  6777.  
  6778. procedure dim(str)
  6779.   return "\e[2m" || str || "\e[0m"
  6780.   end
  6781.   
  6782. procedure under(str)
  6783.   return "\e[4m" || str || "\e[0m"
  6784.   end
  6785.  
  6786. procedure blink(str)
  6787.   return "\e[5m" || str || "\e[0m"
  6788.   end
  6789.  
  6790. procedure cls(str)
  6791.   /str := ""
  6792.   return "\e[2J\e[H" || str
  6793.   end
  6794.  
  6795. procedure chop(str)
  6796.   /str := ""
  6797.   return "\e[J" || str
  6798.   end
  6799.  
  6800. procedure beep()
  6801.   return "\7"
  6802.   end
  6803. # #  
  6804. #
  6805. # procedure to init useful global variables for later use
  6806. #
  6807. procedure init()
  6808.   true    := "y"
  6809.   false   := "n"
  6810.   draw    := "?"
  6811.   &random := map(&clock,":","0")
  6812.   wins    := [set([1,5,9]),set([3,5,7]),set([1,2,3]),set([4,5,6]),
  6813.               set([7,8,9]),set([1,4,7]),set([2,5,8]),set([3,6,9])]
  6814.   pointer := [at(17,7), at(37,7), at(57,7),
  6815.               at(17,12),at(37,12),at(57,12),
  6816.               at(17,17),at(37,17),at(57,17)]
  6817.   end
  6818.   
  6819.               
  6820.                                                     
  6821.  
  6822.  
  6823. From icon-group-request  Wed Nov 27 18:25:34 1991
  6824. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Wed, 27 Nov 91 18:25:34 MST
  6825. Received: from ucbvax.Berkeley.EDU by optima.cs.arizona.edu (4.1/15)
  6826.     id AA01096; Wed, 27 Nov 91 18:25:30 MST
  6827. Received: by ucbvax.Berkeley.EDU (5.63/1.42)
  6828.     id AA25523; Tue, 26 Nov 91 11:18:10 -0800
  6829. Received: from USENET by ucbvax.Berkeley.EDU with netnews
  6830.     for icon-group@cs.arizona.edu (icon-group@cs.arizona.edu)
  6831.     (contact usenet@ucbvax.Berkeley.EDU if you have questions)
  6832. Date: 26 Nov 91 00:46:11 GMT
  6833. From: uchinews!ellis!goer@uunet.uu.net  (Richard L. Goerwitz)
  6834. Organization: University of Chicago Computing Organizations
  6835. Subject: Re: case insensitive find()
  6836. Message-Id: <1991Nov26.004611.8383@midway.uchicago.edu>
  6837. References: <1991Nov25.120052.2151@arizona.edu>
  6838. Sender: icon-group-request@cs.arizona.edu
  6839. To: icon-group@cs.arizona.edu
  6840.  
  6841. parten@ece.arizona.edu (Kurt Parten) writes:
  6842.  
  6843. >Has anyone come up with a case insensitive find()?
  6844. >I am not even sure how to implement such a creature.
  6845.  
  6846. Find all cases of string s in file f:
  6847.  
  6848.     f := open("some-file-or-other")
  6849.     lowercase_s := map(s)
  6850.     every line := !f do {
  6851.         if find(lowercase_s, map(line)) then
  6852.         write("found ",s," in ",line)
  6853.     }
  6854. -- 
  6855.  
  6856.    -Richard L. Goerwitz              goer%sophist@uchicago.bitnet
  6857.    goer@sophist.uchicago.edu         rutgers!oddjob!gide!sophist!goer
  6858.  
  6859. From icon-group-request  Wed Nov 27 18:33:06 1991
  6860. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Wed, 27 Nov 91 18:33:06 MST
  6861. Received: from ucbvax.Berkeley.EDU by optima.cs.arizona.edu (4.1/15)
  6862.     id AA01277; Wed, 27 Nov 91 18:33:03 MST
  6863. Received: by ucbvax.Berkeley.EDU (5.63/1.42)
  6864.     id AA02727; Wed, 27 Nov 91 16:31:05 -0800
  6865. Received: from USENET by ucbvax.Berkeley.EDU with netnews
  6866.     for icon-group@cs.arizona.edu (icon-group@cs.arizona.edu)
  6867.     (contact usenet@ucbvax.Berkeley.EDU if you have questions)
  6868. Date: 27 Nov 91 22:28:00 GMT
  6869. From: UTARLG.UTA.EDU!B912DIEG@ucbvax.berkeley.edu
  6870. Subject: Machine Translation Program available via anonymous FTP
  6871. Message-Id: <01GDG7O2WRS00001JS@utarlg.uta.edu>
  6872. Sender: icon-group-request@cs.arizona.edu
  6873. To: icon-group@cs.arizona.edu
  6874.  
  6875. 11/27/91
  6876. Dear Fellow Icon Enthusiasts:
  6877.  
  6878.      I have just uploaded a new version of my TRAN1 machine 
  6879. translation program to the ICON Project.  It may be retrieved via 
  6880. anonymous FTP from cs.arizona.edu:icon/contrib .  There are three 
  6881. files: 
  6882.  
  6883.      TRAN1SP.ZIP  The TRAN1 machine translation program for 
  6884.                   Spanish.
  6885.      PCL.ZIP      Documentation for TRAN1 in Helett-Packard Laser 
  6886.                   Jet format.
  6887.      PCW.ZIP      Documentation for TRAN1 in PC-Write Format.
  6888.  
  6889.      The original TRAN1.ZIP is also still available.  It is still 
  6890. of some value as a demo.  For one thing, it will execute on an 
  6891. 8088 machine with limited memory.  I'm not sure the new version 
  6892. will execute on a machine with limited memory (it was developed 
  6893. with ICON 386), and it certainly won't in the near future when I 
  6894. expand it again.  The original TRAN1.ZIP is also a little simpler, 
  6895. so it would be good as a tutorial.  I'm planning to add some more 
  6896. features to TRAN1SP over the next couple of months, so it will be 
  6897. getting more and more complicated.  So, you may want to download 
  6898. TRAN1.ZIP as well if you haven't already. 
  6899.  
  6900.      The documentation is an electronic copy of my thesis.  
  6901. Chapter four is the most interesting chapter for ICON programmers.  
  6902.  
  6903.      Those who don't have anonymous FTP access can send me a post-
  6904. paid mailer with an MS-DOS compatible disk or disks, and I will 
  6905. return the files by surface mail.  A 1.2 Meg or 1.44 Meg disk 
  6906. would be best.  (Three 360 K or two 720 K disks would also work.) 
  6907.  
  6908. Doug Witmer
  6909. Internet: b912dieg@utarlg.uta.edu
  6910. Bitnet:   b912dieg@utarlg
  6911. smail: 1102 Enterprise Drive #149, Grand Prairie, Texas  75051
  6912.  
  6913.  
  6914.  
  6915. From icon-group-request  Wed Nov 27 18:43:46 1991
  6916. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Wed, 27 Nov 91 18:43:46 MST
  6917. Received: from ucbvax.Berkeley.EDU by optima.cs.arizona.edu (4.1/15)
  6918.     id AA01614; Wed, 27 Nov 91 18:43:43 MST
  6919. Received: by ucbvax.Berkeley.EDU (5.63/1.42)
  6920.     id AA29723; Mon, 25 Nov 91 17:15:05 -0800
  6921. Received: from USENET by ucbvax.Berkeley.EDU with netnews
  6922.     for icon-group@cs.arizona.edu (icon-group@cs.arizona.edu)
  6923.     (contact usenet@ucbvax.Berkeley.EDU if you have questions)
  6924. Date: 25 Nov 91 19:00:51 GMT
  6925. From: att!news.cs.indiana.edu!arizona.edu!arizona.edu!news@ucbvax.berkeley.edu  (Kurt Parten)
  6926. Organization: Dept of Electrical and Computer Engineering, University of Arizona, Tucson, Arizona
  6927. Subject: case insensitive find()
  6928. Message-Id: <1991Nov25.120052.2151@arizona.edu>
  6929. Sender: icon-group-request@cs.arizona.edu
  6930. To: icon-group@cs.arizona.edu
  6931.  
  6932. Has anyone come up with a case insensitive find()?
  6933. I am not even sure how to implement such a creature.
  6934. Thanks for any help,
  6935. Kurt
  6936.  
  6937. --
  6938. Kurt Parten
  6939. parten@helios.ece.arizona.edu
  6940.  
  6941. From icon-group-request  Wed Nov 27 23:11:53 1991
  6942. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Wed, 27 Nov 91 23:11:53 MST
  6943. Received: from ucbvax.Berkeley.EDU by optima.cs.arizona.edu (4.1/15)
  6944.     id AA12214; Wed, 27 Nov 91 23:11:49 MST
  6945. Received: by ucbvax.Berkeley.EDU (5.63/1.42)
  6946.     id AA18996; Wed, 27 Nov 91 22:02:47 -0800
  6947. Received: from USENET by ucbvax.Berkeley.EDU with netnews
  6948.     for icon-group@cs.arizona.edu (icon-group@cs.arizona.edu)
  6949.     (contact usenet@ucbvax.Berkeley.EDU if you have questions)
  6950. Date: 28 Nov 91 05:53:00 GMT
  6951. From: UTARLG.UTA.EDU!B912DIEG@ucbvax.berkeley.edu
  6952. Subject: Machine Translation program available via anonymous FTP
  6953. Message-Id: <01GDGN7ORTE80003IX@utarlg.uta.edu>
  6954. Sender: icon-group-request@cs.arizona.edu
  6955. To: icon-group@cs.arizona.edu
  6956.  
  6957. 11/27/91
  6958. Dear Fellow Icon Enthusiasts:
  6959.  
  6960.      I have just uploaded a new version of my TRAN1 machine 
  6961. translation program to the ICON Project.  It may be retrieved via 
  6962. anonymous FTP from cs.arizona.edu:icon/contrib .  There are three 
  6963. files: 
  6964.  
  6965.      TRAN1SP.ZIP  The TRAN1 machine translation program for 
  6966.                   Spanish.
  6967.      PCL.ZIP      Documentation for TRAN1 in Helett-Packard Laser 
  6968.                   Jet format.
  6969.      PCW.ZIP      Documentation for TRAN1 in PC-Write Format.
  6970.  
  6971.      The original TRAN1.ZIP is also still available.  It is still 
  6972. of some value as a demo.  For one thing, it will execute on an 
  6973. 8088 machine with limited memory.  I'm not sure the new version 
  6974. will execute on a machine with limited memory (it was developed 
  6975. with ICON 386), and it certainly won't in the near future when I 
  6976. expand it again.  The original TRAN1.ZIP is also a little simpler, 
  6977. so it would be good as a tutorial.  I'm planning to add some more 
  6978. features to TRAN1SP over the next couple of months, so it will be 
  6979. getting more and more complicated.  So, you may want to download 
  6980. TRAN1.ZIP as well if you haven't already. 
  6981.  
  6982.      The documentation is an electronic copy of my thesis.  
  6983. Chapter four is the most interesting chapter for ICON programmers.  
  6984.  
  6985.      Those who don't have anonymous FTP access can send me a post-
  6986. paid mailer with an MS-DOS compatible disk or disks, and I will 
  6987. return the files by surface mail.  A 1.2 Meg or 1.44 Meg disk 
  6988. would be best.  (Three 360 K or two 720 K disks would also work.) 
  6989.  
  6990. Doug Witmer
  6991. Internet: b912dieg@utarlg.uta.edu
  6992. Bitnet:   b912dieg@utarlg
  6993. smail: 1102 Enterprise Drive #149, Grand Prairie, Texas  75051
  6994.  
  6995.  
  6996.  
  6997. From icon-group-request  Fri Nov 29 06:00:02 1991
  6998. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Fri, 29 Nov 91 06:00:02 MST
  6999. Received: from ucbvax.Berkeley.EDU by optima.cs.arizona.edu (4.1/15)
  7000.     id AA03851; Fri, 29 Nov 91 06:00:00 MST
  7001. Received: by ucbvax.Berkeley.EDU (5.63/1.42)
  7002.     id AA20971; Fri, 29 Nov 91 04:46:59 -0800
  7003. Received: from USENET by ucbvax.Berkeley.EDU with netnews
  7004.     for icon-group@cs.arizona.edu (icon-group@cs.arizona.edu)
  7005.     (contact usenet@ucbvax.Berkeley.EDU if you have questions)
  7006. Date: 27 Nov 91 23:49:28 GMT
  7007. From: fernwood!cronos!laguna!alex@uunet.uu.net  (Bob Alexander)
  7008. Organization: Metaphor Computer Systems, Mountain View, CA
  7009. Subject: Re: case insensitive find()
  7010. Message-Id: <1648@cronos.metaphor.com>
  7011. References: <1991Nov25.120052.2151@arizona.edu>, <7330@ksr.com>
  7012. Sender: icon-group-request@cs.arizona.edu
  7013. To: icon-group@cs.arizona.edu
  7014.  
  7015. In article <7330@ksr.com> tim@ksr.com (Tim Peters) writes:
  7016.  
  7017. >    map(haystack) ? { ... find(map(needle)) ... }
  7018.  
  7019. Beware -- a potential gotcha with this technique is in using parts of
  7020. the scanned string, e.g.:
  7021.  
  7022.     map(haystack) ? { ... (s := tab(find(map(needle)))) ... }
  7023.  
  7024. sets s to the downshifted string, not the original portion of
  7025. haystack.
  7026.  
  7027. -- Bob Alexander
  7028.  
  7029. Metaphor Computer Systems   (415) 961-3600 x751   alex@metaphor.com
  7030. ====^=== Mountain View, CA  ...{uunet}!{decwrl,apple}!metaphor!alex
  7031.  
  7032. From icon-group-request  Mon Dec  2 12:12:18 1991
  7033. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Mon, 2 Dec 91 12:12:18 MST
  7034. Received: from ucbvax.Berkeley.EDU by optima.cs.arizona.edu (4.1/15)
  7035.     id AA10769; Mon, 2 Dec 91 12:12:15 MST
  7036. Received: by ucbvax.Berkeley.EDU (5.63/1.42)
  7037.     id AA19145; Mon, 2 Dec 91 10:47:20 -0800
  7038. Received: from USENET by ucbvax.Berkeley.EDU with netnews
  7039.     for icon-group@cs.arizona.edu (icon-group@cs.arizona.edu)
  7040.     (contact usenet@ucbvax.Berkeley.EDU if you have questions)
  7041. Date: 2 Dec 91 17:14:51 GMT
  7042. From: mcsun!uknet!warwick!kingpol!titan.kingston.ac.uk!as_m455@uunet.uu.net
  7043. Organization: Kingston Polytechnic
  7044. Subject: ICON, MUDs and Neural Nets ...
  7045. Message-Id: <1991Dec2.171451.1@titan.kingston.ac.uk>
  7046. Sender: icon-group-request@cs.arizona.edu
  7047. To: icon-group@cs.arizona.edu
  7048.  
  7049. Hi,
  7050. I'm coding a MUD in ICON ... as an extension of a simple interpreter I wrote in
  7051. the summer ... and I'd like some info. on how to add sockets to the system. My
  7052. code will be running under DEC ULTRIX on a microVAX, and currently I'm planning
  7053. to use pipes for interprocess comms while I'm waithing to get a socket library
  7054. written.
  7055. I'm also plaguing comp.ai.neural-nets as I'm planning to implement the monsters
  7056. as neural nets, allowing them to respond in a more interesting manner.
  7057. If anyone can give me help with either of these, or ideas for features to add
  7058. to the MUD (which will also be a full-blown command shell) I'd be pleased to
  7059. hear from you.
  7060.  
  7061.                         - Hermes, the Megaflow Junkie.
  7062.  
  7063. email - as_m455@titan.kingston.ac.uk
  7064.  
  7065. From icon-group-request  Mon Dec  2 19:25:20 1991
  7066. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Mon, 2 Dec 91 19:25:20 MST
  7067. Received: from ucbvax.Berkeley.EDU by optima.cs.arizona.edu (4.1/15)
  7068.     id AA29829; Mon, 2 Dec 91 19:25:18 MST
  7069. Received: by ucbvax.Berkeley.EDU (5.63/1.42)
  7070.     id AA05316; Mon, 2 Dec 91 18:05:46 -0800
  7071. Received: from USENET by ucbvax.Berkeley.EDU with netnews
  7072.     for icon-group@cs.arizona.edu (icon-group@cs.arizona.edu)
  7073.     (contact usenet@ucbvax.Berkeley.EDU if you have questions)
  7074. Date: 2 Dec 91 23:20:49 GMT
  7075. From: micro-heart-of-gold.mit.edu!wupost!uwm.edu!ux1.cso.uiuc.edu!uchinews!ellis!goer@bloom-beacon.mit.edu  (Richard L. Goerwitz)
  7076. Organization: University of Chicago Computing Organizations
  7077. Subject: Re: ICON, MUDs and Neural Nets ...
  7078. Message-Id: <1991Dec2.232049.20559@midway.uchicago.edu>
  7079. References: <1991Dec2.171451.1@titan.kingston.ac.uk>
  7080. Sender: icon-group-request@cs.arizona.edu
  7081. To: icon-group@cs.arizona.edu
  7082.  
  7083. In <1991Dec2.171451.1@titan.kingston.ac.uk> as_m455@titan.kingston.ac.uk writes:
  7084.  
  7085. >I'm coding a MUD in ICON ... as an extension of a simple interpreter I wrote in
  7086. >the summer ... and I'd like some info. on how to add sockets to the system. My
  7087. >code will be running under DEC ULTRIX on a microVAX, and currently I'm planning
  7088. >to use pipes for interprocess comms while I'm waithing to get a socket library
  7089. >written.
  7090.  
  7091. Tell me if I'm wrong, but it looks like you want interprocess communication
  7092. facilities to be accessible from Icon.  The big question is what you expect
  7093. to be reading from those sockets.  Named pipes are certainly an easier way to
  7094. do things, since you can set up everything using simple system() commands.
  7095.  
  7096. >I'm also plaguing comp.ai.neural-nets as I'm planning to implement the monsters
  7097. >as neural nets, allowing them to respond in a more interesting manner.
  7098. >If anyone can give me help with either of these, or ideas for features to add
  7099. >to the MUD (which will also be a full-blown command shell) I'd be pleased to
  7100. >hear from you.
  7101.  
  7102. Wish I could help more.  Let us know what you come up with.
  7103.  
  7104. -- 
  7105.  
  7106.    -Richard L. Goerwitz              goer%sophist@uchicago.bitnet
  7107.    goer@sophist.uchicago.edu         rutgers!oddjob!gide!sophist!goer
  7108.  
  7109. From icon-group-request  Tue Dec 10 13:12:09 1991
  7110. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Tue, 10 Dec 91 13:12:09 MST
  7111. Received: from ucbvax.Berkeley.EDU by optima.cs.arizona.edu (4.1/15)
  7112.     id AA06978; Tue, 10 Dec 91 13:12:02 MST
  7113. Received: by ucbvax.Berkeley.EDU (5.63/1.42)
  7114.     id AA19526; Mon, 9 Dec 91 15:25:19 -0800
  7115. Received: from USENET by ucbvax.Berkeley.EDU with netnews
  7116.     for icon-group@cs.arizona.edu (icon-group@cs.arizona.edu)
  7117.     (contact usenet@ucbvax.Berkeley.EDU if you have questions)
  7118. Date: 8 Dec 91 00:02:49 GMT
  7119. From: csus.edu!beach.csulb.edu!nic.csu.net!usc!samsung!think.com!rpi!uwm.edu!linac!uchinews!ellis!goer@ucdavis.ucdavis.edu  (Richard L. Goerwitz)
  7120. Organization: University of Chicago Computing Organizations
  7121. Subject: getch() again
  7122. Message-Id: <1991Dec8.000249.3032@midway.uchicago.edu>
  7123. Sender: icon-group-request@cs.arizona.edu
  7124. To: icon-group@cs.arizona.edu
  7125.  
  7126. Followup to a previous post:  Here's a version of getch() that works
  7127. for a Sun4 and for Xenix/386.  May work elsewhere.  Tried to figure
  7128. out how to get things to work under Mach on a NeXT, but didn't make
  7129. any progress during the brief time I was fooling with it.
  7130.  
  7131. -Richard
  7132.  
  7133. #ifdef XENIX_386
  7134.  
  7135. /* #include <stdio.h> - included by ../h/config.h above */
  7136. #include <sys/termio.h>
  7137. #include <sys/ioctl.h>
  7138. #include <sys/errno.h>
  7139. #include <sys/signal.h>
  7140.  
  7141. #define ECHO_ON 1
  7142. #define ECHO_OFF 0
  7143. #define CopyTty(t1,t2)    if (! reset_flag) {\
  7144.               t2 = t1;\
  7145.               reset_flag = 1;\
  7146.             }
  7147. #define ResetTty(t1)    if (reset_flag) {\
  7148.               if (ioctl(0, TCSETA, t1) == -1)\
  7149.                 RunErr(-214, NULL);\
  7150.             }
  7151. /*
  7152.  * kbhit(): word
  7153.  *
  7154.  * Routine to check for the availability of characters on the stdin
  7155.  * stream.  Does not actually read any characters.  Returns nonzero
  7156.  * value if characters are waiting; otherwise, zero.  The idea here,
  7157.  * as in getch() and getche(), is not to touch the tty settings
  7158.  * unless we have to.
  7159.  */
  7160. word kbhit()
  7161. {
  7162.   struct termio tty, new_tty;
  7163.   register word status, isa_tty = 0, reset_flag = 0;
  7164.   extern word errno;
  7165.  
  7166.   if (isatty(0)) {
  7167.  
  7168.     isa_tty = 1;
  7169.     if (ioctl(0, TCGETA, &tty) == -1)
  7170.       RunErr(-214, NULL);
  7171.     if (tty.c_lflag & ICANON) {
  7172.       CopyTty(tty, new_tty);
  7173.       new_tty.c_lflag &= ~ICANON;
  7174.     }
  7175.  
  7176.     ResetTty(&new_tty);
  7177.   }
  7178.  
  7179.   /* see if anything is waiting to be read from the file */
  7180.   status = rdchk(0);
  7181.   if (isa_tty) ResetTty(&tty);
  7182.   if (status == -1) {
  7183.     switch (errno) {
  7184.     case EBADF:
  7185.       RunErr(-212, NULL);
  7186.     default:
  7187.       RunErr(-214, NULL);
  7188.     }
  7189.   }
  7190.  
  7191.   return status;
  7192. }
  7193.  
  7194. /*
  7195.  * getch(): word
  7196.  *
  7197.  * Routine to read one char from the standard input.  Disables canonical
  7198.  * processing so as to read the character right from the buffer, without
  7199.  * having to wait for a carriage return.  Re-enables canonical processing
  7200.  * after reading a character.  Note that getch() does not echo any char-
  7201.  * acters to the screen, although characters might appear on the screen
  7202.  * anyway, if they were typed before getch() was invoked.
  7203.  */
  7204. word getch()
  7205. {
  7206.   word read_a_char();
  7207.   return read_a_char(ECHO_OFF);
  7208. }
  7209.  
  7210. /*
  7211.  * getche(): word
  7212.  *
  7213.  * Routine to read one char from the standard input.  Disables canonical
  7214.  * processing so as to read the character right from the buffer, without
  7215.  * having to wait for a carriage return.  Re-enables canonical processing
  7216.  * after reading a character.  NOTE:  Getche() does not disable echoing,
  7217.  * so anything typed after it is invoked will be echoed to the screen
  7218.  * (unlike getch(), which disables echoing; see above).
  7219.  */
  7220. word getche()
  7221. {
  7222.   word read_a_char();
  7223.   return read_a_char(ECHO_ON);
  7224. }
  7225.  
  7226. /*
  7227.  * read_a_char(turn_echo_on): word
  7228.  *
  7229.  * Routine to actually do the reading (either with echo or without,
  7230.  * depending on whether turn_echo_on is 1 or 0).
  7231.  */
  7232. word read_a_char(turn_echo_on)
  7233. word turn_echo_on;
  7234. {
  7235.  
  7236.   char c;
  7237.   struct termio tty, new_tty;
  7238.   register word status, isa_tty = 0, reset_flag = 0;
  7239.   novalue abort_on_signal();
  7240.   extern word errno;
  7241.   
  7242.   if (isatty(0)) {
  7243.  
  7244.     isa_tty = 1;
  7245.     if (ioctl(0, TCGETA, &tty) == -1)
  7246.       RunErr(-214, NULL);
  7247.  
  7248.     /* disable keyboard signals quit & interrupt */
  7249.     if (tty.c_lflag & ISIG) {
  7250.       CopyTty(tty, new_tty);    /* a macro, defined above */
  7251.       new_tty.c_lflag &= ~ISIG;
  7252.     }
  7253.     /* disable canonical input processing (like BSD cbreak) */
  7254.     if (tty.c_lflag & ICANON) {
  7255.       CopyTty(tty, new_tty);
  7256.       new_tty.c_lflag &= ~ICANON;
  7257.     }
  7258.     if (tty.c_cc[VMIN] != '\1') {
  7259.       CopyTty(tty, new_tty);
  7260.       new_tty.c_cc[VMIN] = (unsigned char )'\1';
  7261.     }
  7262.     if (tty.c_cc[VTIME]) {
  7263.       CopyTty(tty, new_tty);
  7264.       new_tty.c_cc[VTIME] = (unsigned char )'\0';
  7265.     }
  7266.     if (turn_echo_on) {
  7267.       /* set echo bit, i.e. enable echo */
  7268.       if (! (tty.c_lflag & ECHO)) {
  7269.     CopyTty(tty, new_tty);
  7270.     new_tty.c_lflag |= ECHO;
  7271.       }
  7272.     }
  7273.     else { /* i.e. if _not_ turn_echo_on */
  7274.       /* mask out echo bit, i.e. disable echo */
  7275.       if (tty.c_lflag & ECHO) {
  7276.     CopyTty(tty, new_tty);
  7277.     new_tty.c_lflag &= ~ECHO;
  7278.       }
  7279.     }
  7280.     ResetTty(&new_tty);        /* a macro, defined above */
  7281.   }
  7282.  
  7283.   /* finally, read 1 char from the standard input */
  7284.   status = read(0, &c, 1);
  7285.   if (isa_tty) ResetTty(&tty);
  7286.   if (status == -1) {
  7287.     switch (errno) {
  7288.     case EBADF:
  7289.       RunErr(-212, NULL);
  7290.     default:
  7291.       RunErr(-214, NULL);
  7292.     }
  7293.   }
  7294.  
  7295.   /* Check for quit and interrupt characters. */
  7296.   if (isa_tty) {
  7297.     if ((unsigned char)c == tty.c_cc[VINTR]) {
  7298.       if (kill(getpid(), SIGINT) == -1) {
  7299.     perror("kill");
  7300.     RunErr(500, NULL);
  7301.       }
  7302.     }
  7303.     else if ((unsigned char)c == tty.c_cc[VQUIT]) {
  7304.       if (kill(getpid(), SIGQUIT) == -1) {
  7305.     perror("kill");
  7306.     RunErr(500, NULL);
  7307.       }
  7308.     }
  7309.   }
  7310.  
  7311.   if (! status) return -1;
  7312.   else return (word )c;
  7313. }
  7314.  
  7315. #else                /* not XENIX_386 */
  7316. #ifdef SUN
  7317.  
  7318. /* #include <stdio.h> - included by ../h/config.h */
  7319. #include <sys/ioctl.h>
  7320. #include <errno.h>
  7321. #include <sys/signal.h>
  7322.  
  7323. #define ECHO_ON 1
  7324. #define ECHO_OFF 0
  7325. #define CopyTty(t1,t2)    if (! reset_flag) {\
  7326.               t2 = t1;\
  7327.               reset_flag = 1;\
  7328.             }
  7329. #define ResetTty(t1)    if (reset_flag) {\
  7330.               if (ioctl(0, TIOCSETN, t1) == -1)\
  7331.                 RunErr(-214, NULL);\
  7332.             }
  7333. /*
  7334.  * kbhit(): word
  7335.  *
  7336.  * Routine to check for the availability of characters on the stdin
  7337.  * stream.  Does not actually read any characters.  Returns nonzero
  7338.  * value if characters are waiting; otherwise, zero.  The idea here,
  7339.  * as in getch() and getche(), is not to touch the tty settings
  7340.  * unless we have to.
  7341.  */
  7342. word kbhit()
  7343. {
  7344.  
  7345.   word arg;
  7346.   struct sgttyb tty, new_tty;
  7347.   register word status, isa_tty = 0, reset_flag = 0;
  7348.   extern word errno;
  7349.  
  7350.   if (isatty(0)) {
  7351.  
  7352.     isa_tty = 1;
  7353.     if (ioctl(0, TIOCGETP, &tty) == -1)
  7354.       RunErr(-214, NULL);
  7355.  
  7356.     /* Our Sun4s here at the U of Chicago need this */
  7357.     if (tty.sg_flags & ECHO) {
  7358.       CopyTty(tty, new_tty);
  7359.       new_tty.sg_flags &= ~ECHO;
  7360.     }
  7361.     /* enable cbreak mode */
  7362.     if (! (tty.sg_flags & CBREAK)) {
  7363.       CopyTty(tty, new_tty);
  7364.       new_tty.sg_flags |= CBREAK;
  7365.     }
  7366.  
  7367.     ResetTty(&tty);
  7368.   }
  7369.  
  7370.   /* see if anything is waiting to be read from the file */
  7371.   status = ioctl(0, FIONREAD, &arg);
  7372.   if (isa_tty) ResetTty(&tty);
  7373.   if (status == -1) {
  7374.     switch (errno) {
  7375.     case EBADF:
  7376.       RunErr(-212, NULL);
  7377.     default:
  7378.       RunErr(-214, NULL);
  7379.     }
  7380.   }
  7381.  
  7382.   return arg;
  7383. }
  7384.  
  7385. /*
  7386.  * getch(): word
  7387.  *
  7388.  * Routine to read one char from the standard input.  Enables cbreak mode
  7389.  * so as to read a character right from the buffer, without having to wait
  7390.  * for a carriage return.  Disables cbreak mode after reading a character.
  7391.  * Note that getch() does not echo any characters to the screen, although
  7392.  * characters might appear on the screen anyway, if they were typed before
  7393.  * getch() was invoked.
  7394.  */
  7395. word getch()
  7396. {
  7397.   word read_a_char();
  7398.   return read_a_char(ECHO_OFF);
  7399. }
  7400.  
  7401. /*
  7402.  * getche(): word
  7403.  *
  7404.  * Routine to read one char from the standard input.  Enables cbreak mode,
  7405.  * to read the character right from the buffer, without having to wait for
  7406.  * a carriage return.  Disables cbreak mode after reading a character.  NOTE:
  7407.  * Getche() does not disable echoing, so anything typed after it is invoked
  7408.  * will be echoed to the screen (unlike getch(), which disables echoing; see
  7409.  * above).
  7410.  */
  7411. word getche()
  7412. {
  7413.   word read_a_char();
  7414.   return read_a_char(ECHO_ON);
  7415. }
  7416.  
  7417. /*
  7418.  * read_a_char(turn_echo_on): word
  7419.  *
  7420.  * Routine to actually do the reading (either with echo or without,
  7421.  * depending on whether turn_echo_on is 1 or 0).
  7422.  */
  7423. word read_a_char(turn_echo_on)
  7424. word turn_echo_on;
  7425. {
  7426.  
  7427.   char c;
  7428.   struct tchars tty_characters;
  7429.   struct sgttyb tty, new_tty;
  7430.   register word status, isa_tty = 0, reset_flag = 0;
  7431.   extern word errno;
  7432.   
  7433.   if (isatty(0)) {
  7434.  
  7435.     isa_tty = 1;
  7436.     if (ioctl(0, TIOCGETP, &tty) == -1)
  7437.       RunErr(-214, NULL);
  7438.     if (ioctl(0, TIOCGETC, &tty_characters) == -1)
  7439.       RunErr(-214, NULL);
  7440.  
  7441.     if (turn_echo_on) {
  7442.       /* set echo bit, i.e. enable echo */
  7443.       if (! (tty.sg_flags & ECHO)) {
  7444.     CopyTty(tty, new_tty);    /* macro, defined above */
  7445.     new_tty.sg_flags |= ECHO;
  7446.       }
  7447.     }
  7448.     else {
  7449.       /* mask out echo bit, i.e. disable echo */
  7450.       if (tty.sg_flags & ECHO) {
  7451.     CopyTty(tty, new_tty);
  7452.     new_tty.sg_flags &= ~ECHO;
  7453.       }
  7454.     }
  7455.     /* raw mode; we'll process quit and interrupt by hand */
  7456.     if (! (tty.sg_flags & RAW)) {
  7457.       CopyTty(tty, new_tty);
  7458.       new_tty.sg_flags |= RAW;
  7459.     }
  7460.     ResetTty(&new_tty);        /* a macro, defined above */
  7461.   }
  7462.  
  7463.   status = read(0, &c, 1);
  7464.   if (isa_tty) ResetTty(&tty);
  7465.   if (status == -1) {
  7466.     switch (errno) {
  7467.     case EBADF:
  7468.       RunErr(-212, NULL);
  7469.     default:
  7470.       RunErr(-214, NULL);
  7471.     }
  7472.   }
  7473.  
  7474.   /* Check for quit and interrupt characters. */
  7475.   if (isa_tty) {
  7476.     if ((char )c == tty_characters.t_intrc) {
  7477.       if (kill(getpid(), SIGINT) == -1) {
  7478.     perror("kill");
  7479.     RunErr(500, NULL);
  7480.       }
  7481.     }
  7482.     else if ((char )c == tty_characters.t_quitc) {
  7483.       if (kill(getpid(), SIGQUIT) == -1) {
  7484.     perror("kill");
  7485.     RunErr(500, NULL);
  7486.       }
  7487.     }
  7488.   }
  7489.  
  7490.   if (! status) return -1;
  7491.   else return (word )c;
  7492. }
  7493. #endif                /* SUN */
  7494. #endif                /* XENIX_386 */
  7495. #endif                /* KeyboardFncs */
  7496. -- 
  7497.  
  7498.    -Richard L. Goerwitz              goer%sophist@uchicago.bitnet
  7499.    goer@sophist.uchicago.edu         rutgers!oddjob!gide!sophist!goer
  7500.  
  7501. From icon-group-request  Tue Dec 10 15:00:58 1991
  7502. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Tue, 10 Dec 91 15:00:58 MST
  7503. Received: from ucbvax.Berkeley.EDU by optima.cs.arizona.edu (4.1/15)
  7504.     id AA12923; Tue, 10 Dec 91 15:00:53 MST
  7505. Received: by ucbvax.Berkeley.EDU (5.63/1.42)
  7506.     id AA24561; Tue, 10 Dec 91 03:04:42 -0800
  7507. Received: from USENET by ucbvax.Berkeley.EDU with netnews
  7508.     for icon-group@cs.arizona.edu (icon-group@cs.arizona.edu)
  7509.     (contact usenet@ucbvax.Berkeley.EDU if you have questions)
  7510. Date: 7 Dec 91 17:02:11 GMT
  7511. From: asuvax!cs.utexas.edu!uwm.edu!linac!uchinews!ellis!goer@g.ms.uky.edu  (Richard L. Goerwitz)
  7512. Organization: University of Chicago Computing Organizations
  7513. Subject: expanding regions, Mach
  7514. Message-Id: <1991Dec7.170211.22874@midway.uchicago.edu>
  7515. Sender: icon-group-request@cs.arizona.edu
  7516. To: icon-group@cs.arizona.edu
  7517.  
  7518. Has anyone looked into the problem of memory management using Icon
  7519. on, say, a NeXT?  I just want to ramble a few minutes here, with some
  7520. ideas and questions.
  7521.  
  7522. First, it looks as though Mach is like VMS in the sense that sbrk does
  7523. not function as the lowest-level interface to the memory management
  7524. routines.  In both cases, successive calls are not guaranteed to re-
  7525. turn pointers to memory chunks contiguous with the last chunk reques-
  7526. ted via sbrk().
  7527.  
  7528. I just looked at the VMS routines for Icon, and I wonder how easy it
  7529. would be to adapt them to Mach.
  7530.  
  7531. Also, how viable would it be simply to have a routine that sat around
  7532. and waited for sbrk(> 0) requests, and then (when it encountered them),
  7533. just used vm_alloc (or whatever it is you use on a NeXT), obtained a
  7534. block of contiguous memory, then did a block copy of the static, block,
  7535. and string regions, realigned all the base pointers and what not, and
  7536. then freed the old contiguous block (or, if there's a vm_realloc func-
  7537. tion, used that)?
  7538.  
  7539. Just curious.
  7540.  
  7541. It's pretty annoying to have to manually set region sizes.  Naive users
  7542. can't use programs that require them to be so set, unless they are wrap-
  7543. ped in a shell script that knows how much memory the program is likely
  7544. to use.
  7545.  
  7546. -- 
  7547.  
  7548.    -Richard L. Goerwitz              goer%sophist@uchicago.bitnet
  7549.    goer@sophist.uchicago.edu         rutgers!oddjob!gide!sophist!goer
  7550.  
  7551. From icon-group-request  Tue Dec 10 23:51:48 1991
  7552. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Tue, 10 Dec 91 23:51:48 MST
  7553. Received: from ucbvax.Berkeley.EDU by optima.cs.arizona.edu (4.1/15)
  7554.     id AA06756; Tue, 10 Dec 91 23:51:45 MST
  7555. Received: by ucbvax.Berkeley.EDU (5.63/1.42)
  7556.     id AA14954; Tue, 10 Dec 91 22:45:43 -0800
  7557. Received: from USENET by ucbvax.Berkeley.EDU with netnews
  7558.     for icon-group@cs.arizona.edu (icon-group@cs.arizona.edu)
  7559.     (contact usenet@ucbvax.Berkeley.EDU if you have questions)
  7560. Date: 11 Dec 91 06:10:08 GMT
  7561. From: world!ksr!tim@decwrl.dec.com  (Tim Peters)
  7562. Organization: Kendall Square Research Corp.
  7563. Subject: Re: String Scanning Question (from novice)
  7564. Message-Id: <7762@ksr.com>
  7565. References: <6030@sun13.scri.fsu.edu>
  7566. Sender: icon-group-request@cs.arizona.edu
  7567. To: icon-group@cs.arizona.edu
  7568.  
  7569. In article <6030@sun13.scri.fsu.edu> nall@sun8.scri.fsu.edu (John Nall) writes:
  7570. %I had a bug in a program, and finally found it.
  7571. % ... [this one is yielding unexpected behavior] ...
  7572. %procedure main()
  7573. %  line := "Now and then"
  7574. %  line ?:=  move(3) & move(4)
  7575. %  write(line)    # writes only "Now"
  7576. %end
  7577. %
  7578. %BUT...(the fix) if I do it like this, it works ok:
  7579. %
  7580. %procedure main()
  7581. %  line := "Now and then"
  7582. %  line ?:= { move(3) & move(4) }
  7583. %  write(line)    # writes " and" as it is supposed to
  7584. %end
  7585. %...
  7586.  
  7587. Not to worry, John -- all will be clear!  You need to look at the end of
  7588. Appendix A to get the precedence of the operators straight.  Note that
  7589. in Icon (like as in C or Perl or ... but unlike as in Pascal or Fortran
  7590. or ...), assignment is a binary operator, much like "+" and "*" and "&".
  7591. Because it is just another binary operator, the precedence of assignment
  7592. with respect to the other binary operators is important, and can
  7593. occasionally lead to surprise.  That's what's happening to you above.
  7594.  
  7595. The table at the end of Appendix A says that all forms of assignment in
  7596. Icon (whether plain, or the "swap" flavor, or augmented) have the same
  7597. precedence, and that it's higher (binds more tightly) than the
  7598. precedence of the "&" operator.  In fact, "&" has *the* lowest
  7599. precedence, which you will appreciate some day (trust me <grin>).
  7600.  
  7601. So in
  7602.  
  7603.     line ?:=  move(3) & move(4)
  7604.  
  7605. the "?:=" binds more tightly than the "&", so Icon groups it this way:
  7606.  
  7607.     (line ?:=  move(3)) & move(4)
  7608.  
  7609. The "move(4)" is off in outer space somewhere, & has nothing to do with
  7610. scanning "line"; the attempt to move(4) will actually fail in your
  7611. program, but failure doesn't generally cause an error msg so you
  7612. probably didn't realize it.  Try this line to see it a bit more clearly:
  7613.  
  7614.   line ?:=  move(3) & (move(4) | write("I can't!"))
  7615.  
  7616. The good news is that Icon is working as documented & that it isn't hard
  7617. to learn "the rules".  The bad news is that experience with other
  7618. languages will work against you at first (some of your expectations are,
  7619. well, wrong <grin>).
  7620.  
  7621. hang-in-there-it's-worth-a-little-initial-discomfort-ly y'rs  - tim
  7622.  
  7623. Tim Peters   Kendall Square Research Corp
  7624. tim@ksr.com,         ksr!tim@uunet.uu.net
  7625.  
  7626.  
  7627. ps:  It's probably a bit more idiomatic to write your
  7628.     line ?:= { move(3) & move(4) }
  7629.      as
  7630.     line ?:= ( move(3) & move(4) )
  7631.      although
  7632.     line ?:= { move(3); move(4) }
  7633.      is a suggestive alternative to think about.
  7634.  
  7635. From isidev!nowlin@uunet.uu.net  Wed Dec 11 06:53:18 1991
  7636. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Wed, 11 Dec 91 06:53:18 MST
  7637. Received: from relay1.UU.NET by optima.cs.arizona.edu (4.1/15)
  7638.     id AA24785; Wed, 11 Dec 91 06:53:15 MST
  7639. Received: from uunet.uu.net (via LOCALHOST.UU.NET) by relay1.UU.NET with SMTP 
  7640.     (5.61/UUNET-internet-primary) id AA20684; Wed, 11 Dec 91 08:53:06 -0500
  7641. Date: Wed, 11 Dec 91 08:53:06 -0500
  7642. From: isidev!nowlin@uunet.uu.net
  7643. Message-Id: <9112111353.AA20684@relay1.UU.NET>
  7644. Received: from isidev.UUCP by uunet.uu.net with UUCP/RMAIL
  7645.     (queueing-rmail) id 085253.13836; Wed, 11 Dec 1991 08:52:53 EST
  7646. To: uunet!cs.arizona.edu!icon-group@uunet.uu.net
  7647. Subject: Re: novice scanning question
  7648.  
  7649.  > From: uunet!arizona!decwrl.dec.com!world!ksr!tim  (Tim Peters)
  7650.  > In article ... nall@sun8.scri.fsu.edu (John Nall) writes:
  7651.  > %I had a bug in a program, and finally found it.
  7652.  > % ... [this one is yielding unexpected behavior] ...
  7653.  > %procedure main()
  7654.  > %  line := "Now and then"
  7655.  > %  line ?:=  move(3) & move(4)
  7656.  > %  write(line)    # writes only "Now"
  7657.  > %end
  7658.  > %
  7659.  > %BUT...(the fix) if I do it like this, it works ok:
  7660.  > %
  7661.  > %procedure main()
  7662.  > %  line := "Now and then"
  7663.  > %  line ?:= { move(3) & move(4) }
  7664.  > %  write(line)    # writes " and" as it is supposed to
  7665.  > %end
  7666.  > %...
  7667.  >
  7668.  > { good explanation of operator precedence }
  7669.  >
  7670.  > ps:  It's probably a bit more idiomatic to write your
  7671.  >     line ?:= { move(3) & move(4) }
  7672.  >      as
  7673.  >     line ?:= ( move(3) & move(4) )
  7674.  >      although
  7675.  >     line ?:= { move(3); move(4) }
  7676.  >      is a suggestive alternative to think about.
  7677.  > 
  7678.  
  7679. It's most idiomatic (I think) to write:
  7680.  
  7681.     procedure main()
  7682.       line := "Now and then"
  7683.       line ?:= ( move(3) , move(4) )
  7684.       write(line)
  7685.     end
  7686.  
  7687. This is called mutual evaluation and while it's usually used for long
  7688. sequences of compound conjunction operations it works just fine with
  7689. only two expressions.
  7690.  
  7691. --- ---
  7692.  | S | Iconic Software, Inc.  -  Jerry Nowlin  -  uunet!isidev!nowlin
  7693. --- ---
  7694.  
  7695.  
  7696. From icon-group-request  Wed Dec 11 14:31:55 1991
  7697. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Wed, 11 Dec 91 14:31:55 MST
  7698. Received: from ucbvax.Berkeley.EDU by optima.cs.arizona.edu (4.1/15)
  7699.     id AA17133; Wed, 11 Dec 91 14:31:52 MST
  7700. Received: by ucbvax.Berkeley.EDU (5.63/1.42)
  7701.     id AA19470; Wed, 11 Dec 91 13:26:12 -0800
  7702. Received: from USENET by ucbvax.Berkeley.EDU with netnews
  7703.     for icon-group@cs.arizona.edu (icon-group@cs.arizona.edu)
  7704.     (contact usenet@ucbvax.Berkeley.EDU if you have questions)
  7705. Date: 10 Dec 91 21:31:19 GMT
  7706. From: mailer.cc.fsu.edu!sun13!sun8.scri.fsu.edu@gatech.edu  (John Nall)
  7707. Organization: SCRI, Florida State University
  7708. Subject: String Scanning Question (from novice)
  7709. Message-Id: <6030@sun13.scri.fsu.edu>
  7710. Sender: icon-group-request@cs.arizona.edu
  7711. To: icon-group@cs.arizona.edu
  7712.  
  7713. I had a bug in a program, and finally found it.  But
  7714. although I can fix it easily, I still don't understand
  7715. what I did wrong.
  7716.  
  7717. The book, page 32, says that the form of a string-scanning
  7718. expression is:
  7719.  
  7720.        expr1 ? expr2
  7721.  
  7722. It also says (page 38) that an augmented assignment of the form:
  7723.  
  7724.        s ?:= expr 
  7725.  
  7726. "can be used to scan s and assign a new value to it as a result.
  7727. The value assigned is the value produced by expr".
  7728.  
  7729. The book also says (page 18) that when the conjunction
  7730.  
  7731.        expr1 & expr2
  7732.  
  7733. is evaluated, it produces the value of expr2 (assuming both succeed).
  7734.  
  7735. The following little nonsense program illustrates the problem.
  7736. As I understand, the expression "line ?:= move(3) & move(4)" should
  7737. result in line being assigned the value resulting from the
  7738. "move(4)" part.  But it does not.  Instead it assigns the value
  7739. resulting from the "move(3)" part instead.  (My bug, by the way :-)  )
  7740.  
  7741. procedure main()
  7742.   line := "Now and then"
  7743.   line ?:=  move(3) & move(4) 
  7744.   write(line)    # writes only "Now"
  7745. end
  7746.  
  7747. BUT...(the fix) if I do it like this, it works ok:
  7748.  
  7749. procedure main()
  7750.   line := "Now and then"
  7751.   line ?:= { move(3) & move(4) }
  7752.   write(line)    # writes " and" as it is supposed to
  7753. end
  7754.  
  7755. So is the book wrong?  Or am I just misunderstanding what it says?
  7756.  
  7757. Thanks
  7758.  
  7759. --
  7760. John W. Nall        | Supercomputer Computations Research Institute
  7761. nall@sun8.scri.fsu.edu  | Florida State University, Tallahassee, FL 32306
  7762. (904)-644-6008          | "Down with liberals.  Down with conservatives."
  7763.  
  7764. From icon-group-request  Thu Dec 12 00:18:17 1991
  7765. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Thu, 12 Dec 91 00:18:17 MST
  7766. Received: from ucbvax.Berkeley.EDU by optima.cs.arizona.edu (4.1/15)
  7767.     id AA16919; Thu, 12 Dec 91 00:18:14 MST
  7768. Received: by ucbvax.Berkeley.EDU (5.63/1.42)
  7769.     id AA10169; Wed, 11 Dec 91 23:05:25 -0800
  7770. Received: from USENET by ucbvax.Berkeley.EDU with netnews
  7771.     for icon-group@cs.arizona.edu (icon-group@cs.arizona.edu)
  7772.     (contact usenet@ucbvax.Berkeley.EDU if you have questions)
  7773. Date: 12 Dec 91 01:56:19 GMT
  7774. From: ksr!tim@uunet.uu.net  (Tim Peters)
  7775. Organization: Kendall Square Research Corp.
  7776. Subject: Re: novice scanning question
  7777. Message-Id: <7803@ksr.com>
  7778. References: <9112111353.AA20684@relay1.UU.NET>
  7779. Sender: icon-group-request@cs.arizona.edu
  7780. To: icon-group@cs.arizona.edu
  7781.  
  7782. In article <9112111353.AA20684@relay1.UU.NET> nowlin@isidev.UUCP writes:
  7783. >
  7784. > > From: uunet!arizona!decwrl.dec.com!world!ksr!tim  (Tim Peters)
  7785. > > ...
  7786. > >     line ?:= { move(3) & move(4) }
  7787. > >      vs
  7788. > >     line ?:= ( move(3) & move(4) )
  7789. > >      vs
  7790. > >     line ?:= { move(3); move(4) }
  7791. > > ...
  7792. >It's most idiomatic (I think) to write:
  7793. >
  7794. >    procedure main()
  7795. >      line := "Now and then"
  7796. >      line ?:= ( move(3) , move(4) )
  7797. >      write(line)
  7798. >    end
  7799. >
  7800. >This is called mutual evaluation and while it's usually used for long
  7801. >sequences of compound conjunction operations it works just fine with
  7802. >only two expressions.
  7803.  
  7804. It was an artificial example so it's hard to tell what "the natural"
  7805. approach would be, but I got the impression that mutual evaluation
  7806. (whether spelled as "e1 & e2" or "(e1, e2)") was not a natural approach
  7807. to the poster's real task.  I.e., do you really want to suck a self-
  7808. proclaimed "novice" into the mysteries of backtracking <grin>?
  7809.  
  7810. Anyway, I steered him toward the quite different (semantically as well
  7811. as syntactically) "{ e1; e2; ... }" form believing that it's less
  7812. confusing for an Icon newbie -- works pretty much the way sequential
  7813. blocks in other languages work.
  7814.  
  7815. Whatever, I'm glad you drew explicit attention to mutual evaluation,
  7816. Jerry; could well be what he's really looking for.
  7817.  
  7818. consulting-via-telepathy-has-its-limitations<grin>-ly y'rs  - tim
  7819.  
  7820. Tim Peters   Kendall Square Research Corp
  7821. tim@ksr.com,         ksr!tim@uunet.uu.net
  7822.  
  7823. From icon-group-request  Thu Dec 12 04:18:33 1991
  7824. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Thu, 12 Dec 91 04:18:33 MST
  7825. Received: from ucbvax.Berkeley.EDU by optima.cs.arizona.edu (4.1/15)
  7826.     id AA27734; Thu, 12 Dec 91 04:18:30 MST
  7827. Received: by ucbvax.Berkeley.EDU (5.63/1.42)
  7828.     id AA20278; Thu, 12 Dec 91 03:14:24 -0800
  7829. Received: from USENET by ucbvax.Berkeley.EDU with netnews
  7830.     for icon-group@cs.arizona.edu (icon-group@cs.arizona.edu)
  7831.     (contact usenet@ucbvax.Berkeley.EDU if you have questions)
  7832. Date: 10 Dec 91 23:44:43 GMT
  7833. From: fernwood!cronos!laguna!alex@uunet.uu.net  (Bob Alexander)
  7834. Organization: Metaphor Computer Systems, Mountain View, CA
  7835. Subject: Re: expanding regions, Mach
  7836. Message-Id: <1696@cronos.metaphor.com>
  7837. References: <1991Dec7.170211.22874@midway.uchicago.edu>
  7838. Sender: icon-group-request@cs.arizona.edu
  7839. To: icon-group@cs.arizona.edu
  7840.  
  7841. In article <1991Dec7.170211.22874@midway.uchicago.edu>
  7842. goer@midway.uchicago.edu writes:
  7843.  
  7844. >Also, how viable would it be simply to have a routine that sat around
  7845. >and waited for sbrk(> 0) requests, and then (when it encountered them),
  7846. >just used vm_alloc (or whatever it is you use on a NeXT), obtained a
  7847. >block of contiguous memory, then did a block copy of the static, block,
  7848. >and string regions, realigned all the base pointers and what not, and
  7849. >then freed the old contiguous block (or, if there's a vm_realloc func-
  7850. >tion, used that)?
  7851.  
  7852. If I follow your drift, the technique you suggest is pretty much what
  7853. is done in the Macintosh-MPW version.  I didn't put in any code to
  7854. relocate anything, though, so the region has to be expanded in place
  7855. using a realloc()-type call in the Mac O/S that promises not to move
  7856. anything.
  7857.  
  7858. The problem is, of course, that by the time region expansion is needed,
  7859. it's likely that other non-relocatable blocks have been allocated by
  7860. some system service in such a way that the Icon-block can't be expanded
  7861. in place.  I haven't done any tests to see just how often region
  7862. expansion succeeds or fails, but in general I don't think you can
  7863. really count on it, and the best bet is to allocate bigger regions
  7864. beforehand.
  7865.  
  7866. Obviously, this technique works MUCH better if the Icon memory can be
  7867. relocated, as Richard suggested.  I haven't looked into how hard this
  7868. would be -- perhaps the garbage collector could do it quite easily.  Of
  7869. course, you still have the problem of needing <old memory size> + <new
  7870. memory size> to perform the copy.
  7871.  
  7872. -- Bob Alexander
  7873.  
  7874. Metaphor Computer Systems   (415) 961-3600 x751   alex@metaphor.com
  7875. ====^=== Mountain View, CA  ...{uunet}!{decwrl,apple}!metaphor!alex
  7876.  
  7877. From icon-group-request  Thu Dec 12 06:48:24 1991
  7878. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Thu, 12 Dec 91 06:48:24 MST
  7879. Received: from ucbvax.Berkeley.EDU by optima.cs.arizona.edu (4.1/15)
  7880.     id AA02352; Thu, 12 Dec 91 06:48:20 MST
  7881. Received: by ucbvax.Berkeley.EDU (5.63/1.42)
  7882.     id AA02090; Thu, 12 Dec 91 05:45:22 -0800
  7883. Received: from USENET by ucbvax.Berkeley.EDU with netnews
  7884.     for icon-group@cs.arizona.edu (icon-group@cs.arizona.edu)
  7885.     (contact usenet@ucbvax.Berkeley.EDU if you have questions)
  7886. Date: 11 Dec 91 04:09:26 GMT
  7887. From: csus.edu!wupost!zaphod.mps.ohio-state.edu!uwm.edu!linac!uchinews!ellis!goer@ucdavis.ucdavis.edu  (Richard L. Goerwitz)
  7888. Organization: University of Chicago Computing Organizations
  7889. Subject: Re: String Scanning Question (from novice)
  7890. Message-Id: <1991Dec11.040926.11559@midway.uchicago.edu>
  7891. References: <6030@sun13.scri.fsu.edu>
  7892. Sender: icon-group-request@cs.arizona.edu
  7893. To: icon-group@cs.arizona.edu
  7894.  
  7895. In article <6030@sun13.scri.fsu.edu> nall@sun8.scri.fsu.edu (John Nall) writes:
  7896. >
  7897. >is evaluated, it produces the value of expr2 (assuming both succeed).
  7898. >
  7899. >The following little nonsense program illustrates the problem.
  7900. >As I understand, the expression "line ?:= move(3) & move(4)" should
  7901. >result in line being assigned the value resulting from the
  7902. >"move(4)" part.  But it does not.  Instead it assigns the value
  7903. >resulting from the "move(3)" part instead.  (My bug, by the way :-)  )
  7904. >
  7905. >procedure main()
  7906. >  line := "Now and then"
  7907. >  line ?:=  move(3) & move(4) 
  7908. >  write(line)    # writes only "Now"
  7909. >end
  7910.  
  7911. Think of line ?:= move(3) & move(4) as line := line ? move(3) & move(4).
  7912. The precedences work out like this:  (line := (line ? move(3))) & move(4).
  7913. The result is that line is evaluated, producing a variable, then the scan-
  7914. ning expression (line ? move(3)) gets evaluated, producing the value of
  7915. move(3) (if it succeeds), and then assigning that value to the variable
  7916. produced earlier on.  If this whole business succeeds, then move(4) is
  7917. evaluated.  By now we're outside of the scanning expression, and &pos and
  7918. &subject havewhatever values they had before evaluation of this line be-
  7919. gan, so the results are irrelevant (and aren't used anyway).
  7920.  
  7921. I guess the bottom line is that expression1 op:= expression2 always works
  7922. out as expression1 := expression1 op expression2.
  7923.  
  7924. >BUT...(the fix) if I do it like this, it works ok:
  7925. >
  7926. >procedure main()
  7927. >  line := "Now and then"
  7928. >  line ?:= { move(3) & move(4) }
  7929. >  write(line)    # writes " and" as it is supposed to
  7930. >end
  7931.  
  7932. Good fix.  It's always good to group expressions manually if there could
  7933. be any confusion about their order of evaluation.  Basically what you're
  7934. doing is forcing move(3) & move(4) into a single expression that gets
  7935. evaluated within the scanning operation set up by the ?:= operator.  You
  7936. could also just write line ?:= (move(3), move(4)), which to me looks more
  7937. idiomatic, but does the same thing.  If you prefer the other way, that's
  7938. fine, too.
  7939.  
  7940. >So is the book wrong?  Or am I just misunderstanding what it says?
  7941.  
  7942. Nobody's wrong.  Everybody's right.  Merry Christmas!  :-)
  7943.  
  7944. -- 
  7945.  
  7946.    -Richard L. Goerwitz              goer%sophist@uchicago.bitnet
  7947.    goer@sophist.uchicago.edu         rutgers!oddjob!gide!sophist!goer
  7948.  
  7949. From cats!mark  Thu Dec 12 06:48:48 1991
  7950. Received: from univers.cs.arizona.edu by cheltenham.cs.arizona.edu; Thu, 12 Dec 91 06:48:48 MST
  7951. Message-Id: <9112121348.AA11072@univers.cs.arizona.edu>
  7952. Received: from cats.UUCP by univers.cs.arizona.edu; Thu, 12 Dec 91 06:48:44 MST
  7953. Date: 12/12/81 06:43:23
  7954. To: arizona!icon-group
  7955. From: cats!mark
  7956. Subject: Re: expanding regions, Mach
  7957.  
  7958. SPITBOL has the same sbrk() problems as expandable-region Icon, and
  7959. uses it in the same way.  Sadly, sbrk() is getting harder to find
  7960. in new systems, and I find myself sometimes having to stand on my
  7961. head to give SPITBOL an expanding workspace.
  7962.  
  7963. You don't need any special routine to "watch for sbrk(>0) calls".
  7964. You just write your own sbrk function and link it when you build Icon,
  7965. thus replacing the library sbrk (assuming you _can_ figure out how
  7966. to write a well-behaved sbrk).  Plain old brk() can be trivially written
  7967. in terms of sbrk if you need it.
  7968.  
  7969. To give the PharLap DOS-Extended version of Icon-386 expandable regions,
  7970. I wrote an assembly-language sbrk built on top of PharLap's page-wise
  7971. realloc system call.
  7972.  
  7973. The only trick here is to recognize that your new, spiffy sbrk may
  7974. be called before Icon's C-language main()! That is, some C startup
  7975. code likes to copy environment (shell) variables and command line
  7976. arguments into the program's local data space.  Some C systems copy
  7977. them to the stack, others use malloc() to get some memory to copy
  7978. to.  malloc() in turn can call sbrk.  As long as your sbrk is written
  7979. properly, there's no problem.  However, it can make for some interesting
  7980. debugging if the debugger insists on running the program up to main()
  7981. before giving control to you.
  7982.  
  7983. I don't have access to a NeXT, so I can't say what's involved there.
  7984. I'm just pointing out some of what I've found to be useful on other
  7985. systems.
  7986.  
  7987. The last sbrk I built was for OS/2 2.0.  Programs here can have a
  7988. 512 Mb virtual workspace.  I allocated a 256 Mb region using the option
  7989. to "not commit" pages within that space.  This call costs nothing
  7990. -- it doesn't allocate RAM or disk pages -- it just reserves address
  7991. space.  My sbrk could then allocate from within this region, selectively
  7992. committing pages as needed.  Works like a champ.  Maybe something
  7993. like that can be done for NeXT?
  7994.  
  7995. I'm happy to send my various sbrks to anyone who's interested in pursuing
  7996. this.
  7997.  
  7998. Mark Emmer
  7999. Catspaw, Inc.
  8000. P.O. Box 1123
  8001. Salida, Colorado 81201 USA
  8002.  
  8003.    Phone: 719-539-3884,  8 a.m. - 5 p.m., GMT-7.
  8004.      Fax: 719-539-4830
  8005. Internet: cats!mark@cs.arizona.edu
  8006.  uucpnet: ...{uunet,allegra,noao}!arizona!cats!mark
  8007.  
  8008.  
  8009.  
  8010. From kwalker  Thu Dec 12 11:07:59 1991
  8011. Received: from ocotillo.cs.arizona.edu by cheltenham.cs.arizona.edu; Thu, 12 Dec 91 11:07:59 MST
  8012. Date: Thu, 12 Dec 91 11:07:59 MST
  8013. From: "Kenneth Walker" <kwalker>
  8014. Message-Id: <9112121807.AA21184@ocotillo.cs.arizona.edu>
  8015. Received: by ocotillo.cs.arizona.edu; Thu, 12 Dec 91 11:07:59 MST
  8016. To: icon-group
  8017. Subject: Re: expanding regions, Mach
  8018.  
  8019. > Date: 10 Dec 91 23:44:43 GMT
  8020. > From: fernwood!cronos!laguna!alex@uunet.uu.net  (Bob Alexander)
  8021.  
  8022. [discussion about expanding regions with realloc() or malloc(); realloc()
  8023. can fail if the space cannot be extended in-place]
  8024.  
  8025. > Obviously, this technique works MUCH better if the Icon memory can be
  8026. > relocated, as Richard suggested.  I haven't looked into how hard this
  8027. > would be -- perhaps the garbage collector could do it quite easily.  Of
  8028. > course, you still have the problem of needing <old memory size> + <new
  8029. > memory size> to perform the copy.
  8030.  
  8031. The string and block regions can be relocated upward during a garbage
  8032. collection to accommodate expansion of a region below them. If you know
  8033. soon enough, it shouldn't be hard to relocate them to another chunk of
  8034. memory. Even if you find out late in the game that this is needed to get
  8035. enough free space (which I'm pretty sure is the case), you can always go
  8036. through the motions of garbage collection a second time and do the relocation
  8037. then. Two garbage collectons seem a little expensive, but is clearly better
  8038. than dying with an "insufficient memory" message and is only done when you
  8039. actually have to expand.
  8040.  
  8041. You cannot relocate the static region, but this is not a problem. The static
  8042. region is used to provided a controlled version of malloc(). In the scheme
  8043. we are talking about, you are using the system supplied malloc() and there
  8044. is no Icon-controled static region.
  8045.  
  8046.   Ken Walker / Computer Science Dept / Univ of Arizona / Tucson, AZ 85721
  8047.   +1 602 621-4252  kwalker@cs.arizona.edu {uunet|allegra|noao}!arizona!kwalker
  8048.  
  8049. From icon-group-request  Thu Dec 12 20:49:45 1991
  8050. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Thu, 12 Dec 91 20:49:45 MST
  8051. Received: from ucbvax.Berkeley.EDU by optima.cs.arizona.edu (4.1/15)
  8052.     id AA12047; Thu, 12 Dec 91 20:49:40 MST
  8053. Received: by ucbvax.Berkeley.EDU (5.63/1.42)
  8054.     id AA20867; Thu, 12 Dec 91 19:42:56 -0800
  8055. Received: from USENET by ucbvax.Berkeley.EDU with netnews
  8056.     for icon-group@cs.arizona.edu (icon-group@cs.arizona.edu)
  8057.     (contact usenet@ucbvax.Berkeley.EDU if you have questions)
  8058. Date: 12 Dec 91 22:51:53 GMT
  8059. From: sdd.hp.com!cs.utexas.edu!convex!russur@hplabs.hpl.hp.com  (Russ Urquhart)
  8060. Organization: CONVEX Computer Corporation, Richardson, Tx., USA
  8061. Subject: Snobol4 to Icon: A converter?
  8062. Message-Id: <russur.692578313@convex.convex.com>
  8063. Sender: icon-group-request@cs.arizona.edu
  8064. To: icon-group@cs.arizona.edu
  8065.  
  8066. I'm kind of new to this group, so if this question has already been
  8067. asked/answered, please bear with me.
  8068.  
  8069. I an looking for a snobol4 to icon conversion. I have some snobol4 programs
  8070. that I would like to convert and use under icon.
  8071.  
  8072. Any help would be appreciated!
  8073.  
  8074. Thanks
  8075.  
  8076.  
  8077. Russ Urquhart
  8078. Convex Computer Corporation 
  8079.  
  8080. From bralich@uhccux.uhcc.hawaii.edu  Fri Dec 13 00:15:12 1991
  8081. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Fri, 13 Dec 91 00:15:12 MST
  8082. Received: from uhccux.uhcc.Hawaii.Edu ([128.171.7.2]) by optima.cs.arizona.edu (4.1/15)
  8083.     id AA17874; Fri, 13 Dec 91 00:15:00 MST
  8084. Received: by uhccux.uhcc.Hawaii.Edu (5.61/Ultrix3.1)
  8085.     id AA20758; Thu, 12 Dec 91 21:14:59 -1000
  8086. Date: Thu, 12 Dec 91 21:14:59 -1000
  8087. From: Phil Bralich  <bralich@uhccux.uhcc.hawaii.edu>
  8088. Message-Id: <9112130714.AA20758@uhccux.uhcc.Hawaii.Edu>
  8089. To: icon-group@cs.arizona.edu
  8090. Subject: From Snobol4 to Icon
  8091.  
  8092. I am accostomed to programming in Snobol4, but people have repeatedly advised
  8093. me to move to Icon.  However, I am rather comfortable with the Snobol4
  8094. devices such as "break" and "arb" and "bal."  I realize that I can write
  8095. functions in Icon to do jobs I get from the Snobol4 langauge, but I am not
  8096. an accomplished programmer.  Would there be anyone who has done this before
  8097. who could advise me on this?
  8098.  
  8099. Phil Bralich
  8100. bralich@uhccux.uhcc.Hawaii.edu
  8101.  
  8102. From @festival.edinburgh.ac.uk,@emas-a.edinburgh.ac.uk:R.J.Hare@edinburgh.ac.uk  Fri Dec 13 05:13:54 1991
  8103. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Fri, 13 Dec 91 05:13:54 MST
  8104. Received: from sun2.nsfnet-relay.ac.uk by optima.cs.arizona.edu (4.1/15)
  8105.     id AA00820; Fri, 13 Dec 91 05:13:45 MST
  8106. Received: from festival.edinburgh.ac.uk by sun2.nsfnet-relay.ac.uk via JANET 
  8107.           with NIFTP id <5588-13@sun2.nsfnet-relay.ac.uk>;
  8108.           Thu, 12 Dec 1991 10:15:05 +0000
  8109. Received: from emas-a.ed.ac.uk by castle.ed.ac.uk id aa08854; 9 Dec 91 9:55 WET
  8110. Date: 09 Dec 91 09:55:44 gmt
  8111. From: R.J.Hare@edinburgh.ac.uk
  8112. Subject: Test
  8113. To: icon-group@cs.arizona.edu
  8114. Message-Id: <09 Dec 91 09:55:44 gmt 320815@EMAS-A>
  8115. Sender: "R.J.Hare" <@emas-a.edinburgh.ac.uk:R.J.Hare@edinburgh.ac.uk>
  8116.  
  8117. This is a test message, please ignore.
  8118.  
  8119. Roger Hare.
  8120.  
  8121. From icon-group-request  Fri Dec 13 23:43:04 1991
  8122. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Fri, 13 Dec 91 23:43:04 MST
  8123. Received: from ucbvax.Berkeley.EDU by optima.cs.arizona.edu (4.1/15)
  8124.     id AA22479; Fri, 13 Dec 91 23:43:02 MST
  8125. Received: by ucbvax.Berkeley.EDU (5.63/1.42)
  8126.     id AA05070; Fri, 13 Dec 91 22:28:57 -0800
  8127. Received: from USENET by ucbvax.Berkeley.EDU with netnews
  8128.     for icon-group@cs.arizona.edu (icon-group@cs.arizona.edu)
  8129.     (contact usenet@ucbvax.Berkeley.EDU if you have questions)
  8130. Date: 13 Dec 91 17:56:39 GMT
  8131. From: sdd.hp.com!wupost!dsuvax.dsu.edu!ghelmer@hplabs.hpl.hp.com  (Guy Helmer)
  8132. Organization: Dakota State University
  8133. Subject: CFP: SIXTH INTERNATIONAL CONFERENCE on SYMBOLIC and LOGICAL COMPUTING
  8134. Message-Id: <1991Dec13.175639.23063@dsuvax.dsu.edu>
  8135. Sender: icon-group-request@cs.arizona.edu
  8136. To: icon-group@cs.arizona.edu
  8137.  
  8138.  
  8139.  
  8140.    SIXTH INTERNATIONAL CONFERENCE on SYMBOLIC and LOGICAL COMPUTING
  8141.  
  8142.                       DAKOTA STATE UNIVERSITY
  8143.                        MADISON, SOUTH DAKOTA
  8144.                        OCTOBER 15 - 16, 1992
  8145.  
  8146.     ICEBOL6, the Sixth International Conference on Symbolic and Logical
  8147. Computing, is designed for teachers, scholars, and programmers who want
  8148. to meet to exchange ideas about computer programming for non-numeric
  8149. applications -- especially those in the humanities.  In addition to a
  8150. focus on SNOBOL4, SPITBOL, and Icon, ICEBOL6 invites presentations on
  8151. textual and logical processing in a variety of programming languages such
  8152. as Prolog and C.  Topics of discussion will include artificial
  8153. intelligence and expert systems, and a wide range of analyses of texts in
  8154. English and other natural languages.  Parallel tracks of concurrent
  8155. sessions are planned.
  8156.  
  8157.     ICEBOL's coffee breaks, social hours, lunches, and banquet will
  8158. provide a series of opportunities for participants to meet and informally
  8159. exchange information.
  8160.  
  8161.  
  8162. CALL FOR PAPERS
  8163.  
  8164.     Abstracts (250-750 words) of proposed papers to be read at ICEBOL6
  8165. are invited in any area of non-numeric programming.  Planned sessions
  8166. include the following:
  8167.  
  8168.     analysis of texts (including bibliography, concordance, and index
  8169.        generation)
  8170.     artificial intelligence and expert systems
  8171.     computational linguistics
  8172.     computer languages and compilers designed for non-numeric processing
  8173.     electronic texts and encoding
  8174.     grammar and style checkers
  8175.     linguistic and lexical analysis (including parsing and machine
  8176.        translation)
  8177.     music analysis
  8178.     preparation of texts for publishing
  8179.  
  8180.  
  8181.     Papers must be in English and may not exceed twenty minutes reading
  8182. time.  Abstracts should be received by March 1, 1992.  Notification of
  8183. acceptance (based on recommendations of readers) will follow promptly.
  8184. Papers will be published in ICEBOL6 Proceedings.
  8185.  
  8186.     Presentations at previous ICEBOL conferences were made by Paul
  8187. Abrahams (ACM President), Gene Amdahl (Andor Systems), Robert Dewar (New
  8188. York University), Mark Emmer (Catspaw, Inc.),  James Gimpel (Lehigh),
  8189. Ralph Griswold (Arizona), Susan Hockey (Oxford), Nancy Ide (Vassar) and
  8190. many others.  Copies of the ICEBOL5 Proceedings are available.
  8191.  
  8192.  
  8193. FOR FURTHER INFORMATION
  8194.  
  8195.     All correspondence including abstracts of proposed papers as well as
  8196. requests for registration materials may be sent to:
  8197.  
  8198.                    Eric Johnson
  8199.                    ICEBOL Director
  8200.                    114 Beadle Hall
  8201.                    Dakota State University
  8202.                    Madison, SD  57042 U.S.A.
  8203.  
  8204.     Inquiries, abstracts, and correspondence are encouraged via
  8205. electronic mail, and they may be sent to Eric Johnson at:
  8206.  
  8207.                    ERIC@SDNET.BITNET
  8208.  
  8209.                           or
  8210.  
  8211.                 johnsone@dsuvax.dsu.edu
  8212.  
  8213. -- 
  8214.           Guy Helmer, Dakota State University Computing Services
  8215. ghelmer@dsuvax.dsu.edu, helmer@sdnet.bitnet, dsuvax!ghelmer@wunoc.wustl.edu
  8216.          Whip me, beat me, but don't make me maintain BASIC code!
  8217.  
  8218. From icon-group-request  Sat Dec 14 05:59:02 1991
  8219. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Sat, 14 Dec 91 05:59:02 MST
  8220. Received: from ucbvax.Berkeley.EDU by optima.cs.arizona.edu (4.1/15)
  8221.     id AA09303; Sat, 14 Dec 91 05:59:00 MST
  8222. Received: by ucbvax.Berkeley.EDU (5.63/1.42)
  8223.     id AA20165; Sat, 14 Dec 91 04:56:04 -0800
  8224. Received: from USENET by ucbvax.Berkeley.EDU with netnews
  8225.     for icon-group@cs.arizona.edu (icon-group@cs.arizona.edu)
  8226.     (contact usenet@ucbvax.Berkeley.EDU if you have questions)
  8227. Date: 12 Dec 91 18:53:06 GMT
  8228. From: arizona.edu!arizona.edu!news@arizona.edu  (Kurt Parten)
  8229. Organization: Dept of Electrical and Computer Engineering, University of Arizona, Tucson, Arizona
  8230. Subject: read() problems
  8231. Message-Id: <1991Dec12.115308.2254@arizona.edu>
  8232. Sender: icon-group-request@cs.arizona.edu
  8233. To: icon-group@cs.arizona.edu
  8234.  
  8235. Is there a way for read to be OS independent, so that DOS text files
  8236. look like UNIX text files.  I'm running icon under UNIX, but the
  8237. data files are in DOS format.  I would like to get rid of
  8238. the ^M character that shows up in every line.  
  8239.  
  8240. I tried trim(read(dosfile), "\r"), but that transformed
  8241.  
  8242. h  e  l  l  o \r \n
  8243.  
  8244. to:
  8245.  
  8246. h  e  l  l  o \r \r \n
  8247.  
  8248. instead of
  8249.  
  8250. h  e  l  l  o  \n
  8251. --
  8252. Kurt Parten
  8253. parten@helios.ece.arizona.edu
  8254.  
  8255. From ralph  Sat Dec 14 06:43:19 1991
  8256. Date: Sat, 14 Dec 91 06:43:19 MST
  8257. From: "Ralph Griswold" <ralph>
  8258. Message-Id: <9112141343.AA12627@cheltenham.cs.arizona.edu>
  8259. Received: by cheltenham.cs.arizona.edu; Sat, 14 Dec 91 06:43:19 MST
  8260. To: arizona.edu!arizona.edu!news@arizona.edu, icon-group@cs.arizona.edu
  8261. Subject: Re:  read() problems
  8262.  
  8263. Icon automatically translates to and from "UNIX" format on input
  8264. and output on non-UNIX platforms. However, on a UNIX platform there
  8265. is no way to tell if a file is a file produced by UNIX file or, say, a
  8266. a file produced by MS-DOS. (A line of text in UNIX can legitimately contain
  8267. a ^M character.)
  8268.  
  8269. If you know you are reading an MS-DOS file, you can remove the last character
  8270. of every line read using any number of techniques.  trim(read(),`\^M`)
  8271. probably is safe for reading MS-DOS files.
  8272.     
  8273.     Ralph Griswold / Department of Computer Science 
  8274.     The University of Arizona / Tucson, AZ 85721
  8275.     
  8276.     ralph@cs.arizona.edu / uunet!arizona!ralph
  8277.     
  8278.     voice: 602-621-6609 / fax: 602-621-9618
  8279.  
  8280. From icon-group-request  Wed Dec 18 15:24:57 1991
  8281. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Wed, 18 Dec 91 15:24:57 MST
  8282. Received: from ucbvax.Berkeley.EDU by optima.cs.arizona.edu (4.1/15)
  8283.     id AA23223; Wed, 18 Dec 91 15:24:50 MST
  8284. Received: by ucbvax.Berkeley.EDU (5.63/1.43)
  8285.     id AA13775; Wed, 18 Dec 91 14:07:26 -0800
  8286. Received: from USENET by ucbvax.Berkeley.EDU with netnews
  8287.     for icon-group@cs.arizona.edu (icon-group@cs.arizona.edu)
  8288.     (contact usenet@ucbvax.Berkeley.EDU if you have questions)
  8289. Date: 13 Dec 91 16:52:27 GMT
  8290. From: csus.edu!wupost!sdd.hp.com!caen!uvaarpa!murdoch!aemsun.med.Virginia.EDU!sdm7g@ucdavis.ucdavis.edu  (Steven D. Majewski)
  8291. Organization: University of Virginia - Physiology Dept.
  8292. Subject: Bug in sort() with list of mixed size integers ?
  8293. Message-Id: <1991Dec13.165227.17369@murdoch.acc.Virginia.EDU>
  8294. Sender: icon-group-request@cs.arizona.edu
  8295. To: icon-group@cs.arizona.edu
  8296.  
  8297. There seems to be a problem ( at least with Icon v8 on Sparc/SunOS )
  8298. with sorting mixed large and small integer lists.
  8299.  
  8300. Can anyone reproduce this bug on another architecture?
  8301. ANY COMMENTS? 
  8302.  
  8303.  
  8304. -------------
  8305. program:
  8306. -------------
  8307.  
  8308. procedure main( ARGL )
  8309.  
  8310.   write ( &version )
  8311.   system( "head -1 /etc/motd" )
  8312.  
  8313.   bases := []
  8314.   if ( *ARGL < 1) then
  8315.      bases := [10]
  8316.   every b := !ARGL do 
  8317.     bases |||:= [ numeric( b ) ]
  8318.  
  8319.   L := []
  8320.   every n := ( 0 to 20 ) do
  8321.     every b := !bases do
  8322.        L |||:= [ b^n ]
  8323.  
  8324.   every x := !L do
  8325.     write( x )
  8326.  
  8327.   write( "######## sort #######" )
  8328.  
  8329.   L := sort( L )
  8330.   every x := !L do
  8331.     write( type(x), "  :  ", x  )
  8332.  
  8333. end
  8334.  
  8335. --------------
  8336. output:
  8337. errtest
  8338. --------------
  8339.  
  8340. Icon Version 8.0.  May 7, 1990
  8341. SunOS Release 4.1.1 (AEMSUN_KNL) #1: Wed Sep 4 19:17:09 EDT 1991
  8342. 0
  8343. 10
  8344. 100
  8345. 1000
  8346. 10000
  8347. 100000
  8348. 1000000
  8349. 10000000
  8350. 100000000
  8351. 1000000000
  8352. 10000000000
  8353. 100000000000
  8354. 1000000000000
  8355. 10000000000000
  8356. 100000000000000
  8357. 1000000000000000
  8358. 10000000000000000
  8359. 100000000000000000
  8360. 1000000000000000000
  8361. 10000000000000000000
  8362. 100000000000000000000
  8363. ######## sort #######
  8364. integer  :  0
  8365. integer  :  10
  8366. integer  :  100
  8367. integer  :  1000
  8368. integer  :  10000
  8369. integer  :  100000
  8370. integer  :  1000000
  8371. integer  :  10000000
  8372. integer  :  10000000000
  8373. integer  :  100000000000
  8374. integer  :  1000000000000
  8375. integer  :  10000000000000
  8376. integer  :  100000000000000
  8377. integer  :  1000000000000000
  8378. integer  :  10000000000000000
  8379. integer  :  100000000000000000
  8380. integer  :  1000000000000000000
  8381. integer  :  10000000000000000000
  8382. integer  :  100000000000000000000
  8383. integer  :  100000000
  8384. integer  :  1000000000
  8385.  
  8386. -------------
  8387. output:
  8388. errtest 2 3
  8389. -------------
  8390.  
  8391. Icon Version 8.0.  May 7, 1990
  8392. SunOS Release 4.1.1 (AEMSUN_KNL) #1: Wed Sep 4 19:17:09 EDT 1991
  8393. 0
  8394. 0
  8395. 2
  8396. 3
  8397. 4
  8398. 9
  8399. 8
  8400. 27
  8401. 16
  8402. 81
  8403. 32
  8404. 243
  8405. 64
  8406. 729
  8407. 128
  8408. 2187
  8409. 256
  8410. 6561
  8411. 512
  8412. 19683
  8413. 1024
  8414. 59049
  8415. 2048
  8416. 177147
  8417. 4096
  8418. 531441
  8419. 8192
  8420. 1594323
  8421. 16384
  8422. 4782969
  8423. 32768
  8424. 14348907
  8425. 65536
  8426. 43046721
  8427. 131072
  8428. 129140163
  8429. 262144
  8430. 387420489
  8431. 524288
  8432. 1162261467
  8433. 1048576
  8434. 3486784401
  8435. ######## sort #######
  8436. integer  :  0
  8437. integer  :  0
  8438. integer  :  2
  8439. integer  :  3
  8440. integer  :  4
  8441. integer  :  8
  8442. integer  :  9
  8443. integer  :  16
  8444. integer  :  27
  8445. integer  :  32
  8446. integer  :  64
  8447. integer  :  81
  8448. integer  :  128
  8449. integer  :  243
  8450. integer  :  256
  8451. integer  :  512
  8452. integer  :  729
  8453. integer  :  1024
  8454. integer  :  2048
  8455. integer  :  2187
  8456. integer  :  4096
  8457. integer  :  6561
  8458. integer  :  8192
  8459. integer  :  16384
  8460. integer  :  19683
  8461. integer  :  32768
  8462. integer  :  59049
  8463. integer  :  65536
  8464. integer  :  131072
  8465. integer  :  177147
  8466. integer  :  262144
  8467. integer  :  3486784401
  8468. integer  :  524288
  8469. integer  :  531441
  8470. integer  :  1048576
  8471. integer  :  1594323
  8472. integer  :  4782969
  8473. integer  :  14348907
  8474. integer  :  43046721
  8475. integer  :  129140163
  8476. integer  :  387420489
  8477. integer  :  1162261467
  8478.  
  8479. ------------
  8480. Note:
  8481.  The problem occurs at or about the boundary between 2^30 and 2^31
  8482.  So I assmue this a a problem with sorting the two different
  8483.  representations of integers. ( I stuck the type(x) in there just 
  8484.  to check that they were all actually integers. ) 
  8485.  
  8486.  
  8487. [ Sorry to have dropped out of the theoretical discussions,
  8488.   re: icon futures, etc. But I decided to hold off on further
  8489.   comments until I am a bit more familiar with Icon/Idol 
  8490.   programming. With Richard Goerwitz and others help I can 
  8491.   now write a working program or two, so I have been tied up
  8492.   with actually trying to get some work done. - Thanks ] 
  8493.  
  8494.  
  8495. ======== "If you have a hammer, find a nail" - George Bush,'91  =========
  8496.  Steven D. Majewski        University of Virginia Physiology Dept.
  8497.  sdm7g@Virginia.EDU        Box 449 Health Sciences Center
  8498.  Voice: (804)-982-0831        1600 Jefferson Park Avenue
  8499.  FAX:   (804)-982-1616        Charlottesville, VA 22908
  8500.  
  8501. From icon-group-request  Wed Dec 18 20:37:23 1991
  8502. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Wed, 18 Dec 91 20:37:23 MST
  8503. Received: from ucbvax.Berkeley.EDU by optima.cs.arizona.edu (4.1/15)
  8504.     id AA05311; Wed, 18 Dec 91 20:37:19 MST
  8505. Received: by ucbvax.Berkeley.EDU (5.63/1.43)
  8506.     id AA23282; Wed, 18 Dec 91 19:25:21 -0800
  8507. Received: from USENET by ucbvax.Berkeley.EDU with netnews
  8508.     for icon-group@cs.arizona.edu (icon-group@cs.arizona.edu)
  8509.     (contact usenet@ucbvax.Berkeley.EDU if you have questions)
  8510. Date: 14 Dec 91 01:54:52 GMT
  8511. From: world!ksr!tim@uunet.uu.net  (Tim Peters)
  8512. Organization: Kendall Square Research Corp.
  8513. Subject: Re: Bug in sort() with list of mixed size integers ?
  8514. Message-Id: <7872@ksr.com>
  8515. References: <1991Dec13.165227.17369@murdoch.acc.Virginia.EDU>
  8516. Sender: icon-group-request@cs.arizona.edu
  8517. To: icon-group@cs.arizona.edu
  8518.  
  8519. In article <1991Dec13.165227.17369@murdoch.acc.Virginia.EDU> sdm7g@aemsun.med.Virginia.EDU (Steven D. Majewski) writes:
  8520. >There seems to be a problem ( at least with Icon v8 on Sparc/SunOS )
  8521. >with sorting mixed large and small integer lists.
  8522. >
  8523. >Can anyone reproduce this bug on another architecture?
  8524. > ...[and a failing program is attached]...
  8525.  
  8526. Steve, ya, there are some bugs in V8 bigint support.  You may have
  8527. noticed that n^0 is coming out as 0 instead of as 1 in your output --
  8528. that's another bug (at least according to me <grin>).
  8529.  
  8530. Don't know whether they're universal; have reported a few before but
  8531. nobody bit the bait; the system I'm running is pretty much like yours:
  8532.  
  8533. Icon Version 8.0.  May 7, 1990
  8534. OS/SMP 4.0Da_Export (XD/root) #0: Wed Aug 21 08:06:46 1991
  8535.  
  8536. That's a Solbourne; another SPARC and running a Sun OS.
  8537.  
  8538. Try replacing your
  8539.  
  8540.     L := sort( L )
  8541. by
  8542.     every !L *:= -1  # negate each number in list
  8543.     L := sort( L )
  8544.     every !L *:= -1  # and restore
  8545.  
  8546. This doesn't work any better, but does lead to a prettier pattern in the
  8547. output (which would be strictly decreasing if it worked right).  It also
  8548. leads to to a workaround that will do the trick until Icon is fixed:
  8549.  
  8550.     huge := 10^10        # must be big enough to make this true:
  8551.     every !L +:= huge    # force every number to be a bignum
  8552.     L := sort( L )
  8553.     every !L -:= huge    # & restore original values
  8554.  
  8555. You already made the key observation for understanding why this works:
  8556. the bugs in Icon's V8 bignums (& bignums were new in V8, so it's not
  8557. surprising there are some bugs ...) seem to have mostly to do with the
  8558. boundary between native integers & the huge ones.  So as a general rule,
  8559. when bit by one of these guys a good approach is to move the data away
  8560. from the boundary, at least for the duration of the flaky operation.
  8561.  
  8562. >ANY COMMENTS?
  8563.  
  8564. No, but a handy tip <grin>:  You'll eventually discover that building a
  8565. list via repeated list concatenation (|||) of a singleton is very slow.
  8566. It's much faster (and, believe it or not, in time much clearer) to avoid
  8567. the temp variables and build lists via "put".  E.g.,
  8568.  
  8569.     every put( bases, numeric(!ARGL) )
  8570. instead of
  8571.     every b := !ARGL do bases |||:= [ numeric( b ) ]
  8572.  
  8573. Similarly you'll (eventually) find
  8574.  
  8575.     every n := 0 to 20 & put( L, (!bases)^n )  # marginal, I admit
  8576.     every n := 0 to 20 do every put( L, (!bases)^n )  # clearer(?)
  8577. and
  8578.     every write( !L )
  8579.  
  8580. faster & clearer than the way you're writing them now.
  8581.  
  8582. if-it's-any-consolation-perl-has-a-hundred-bugs-for-every-one-i've-
  8583.    found-in-icon<0.3-grin>-ly y'rs  - tim
  8584.  
  8585. Tim Peters   Kendall Square Research Corp
  8586. tim@ksr.com,         ksr!tim@uunet.uu.net
  8587.  
  8588. From icon-group-request  Sat Dec 21 20:37:58 1991
  8589. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Sat, 21 Dec 91 20:37:58 MST
  8590. Received: from ucbvax.Berkeley.EDU by optima.cs.arizona.edu (4.1/15)
  8591.     id AA01463; Sat, 21 Dec 91 20:37:56 MST
  8592. Received: by ucbvax.Berkeley.EDU (5.63/1.43)
  8593.     id AA19536; Sat, 21 Dec 91 19:31:07 -0800
  8594. Received: from USENET by ucbvax.Berkeley.EDU with netnews
  8595.     for icon-group@cs.arizona.edu (icon-group@cs.arizona.edu)
  8596.     (contact usenet@ucbvax.Berkeley.EDU if you have questions)
  8597. Date: 21 Dec 91 03:22:27 GMT
  8598. From: world!ksr!tim@decwrl.dec.com  (Tim Peters)
  8599. Organization: Kendall Square Research Corp.
  8600. Subject: Re: Memory Mangement
  8601. Message-Id: <8080@ksr.com>
  8602. References: <1991Dec19.015629.3966@utagraph.uta.edu>
  8603. Sender: icon-group-request@cs.arizona.edu
  8604. To: icon-group@cs.arizona.edu
  8605.  
  8606. In article <1991Dec19.015629.3966@utagraph.uta.edu> b912dieg@utarlg.uta.edu writes:
  8607. >...
  8608. >I know from my readings that the ICON system finds it necessary to
  8609. >perform frequent garbage collections to maintain an adequate supply of
  8610. >unfragmented memory.
  8611.  
  8612. Guess I'll have to do until a real expert comes along <grin>.  The
  8613. frequency of Icon garbage collection depends on an awful lot of things.
  8614. In general, I'd say that if Icon *is* doing collections frequently,
  8615. there's an easily-changed (if not easily-found ...) way to stop that by
  8616. rewriting a bit of the Icon application.  For most Icon programs most
  8617. times, garbage collection should not be a problem; indeed, for many real
  8618. Icon programs garbage collection is never needed at all.
  8619.  
  8620. > ...
  8621. >     Mathematica does memory management with reference counts, 
  8622. >     so that pieces of memory are freed as soon as they stop
  8623. >     being used.  This means that Mathematica can make use of
  8624. >     essentially all the memory that is available on a 
  8625. >     particular computer, without the need for operations such
  8626. >     as garbage collection.  (Mathematica by Wolfram 1988:xvi)
  8627. >
  8628. >Does anyone have an explanation of reference counts?
  8629. >Can the use of reference counts really eliminate garbage collection?
  8630.  
  8631. Dynamic memory management has become a rather large field by now, but
  8632. the intro in Knuth's "Art of Computer Programming" (Volume 1) remains
  8633. helpful.
  8634.  
  8635. Assuming you can read Icon, here's a fragement to help explain the
  8636. differences:
  8637.  
  8638.    B := [2]
  8639.    A := [1, b, 3]  # === [1, B === pointer to [2], 3]
  8640.    B := &null
  8641.    A := &null
  8642.  
  8643. I'll call those lines #1, #2, #3 and #4.
  8644.  
  8645. Icon-style garbage collection works by (in effect) putting a mark on all
  8646. the memory you can possibly reference, then reusing all the memory that
  8647. is *not* marked (it's trickier than that, of course, but I think that's
  8648. a fair summary of the basic idea).
  8649.  
  8650. So if garbage collection (GC) occurs right after line #2, the memory
  8651. earlier allocated for the lists A and B will get marked, because you
  8652. could still reference that memory in the future just by mentioning A or
  8653. B.
  8654.  
  8655. If GC occurs after #3, we must still keep all the memory around, but for
  8656. a subtler reason:  even though you can't reference the [2] list directly
  8657. via B any more, the garbage collector knows you might still reference A,
  8658. and the value of A still contains a pointer to the list that used to be
  8659. named by B.  So all the allocated memory is still potentially reachable,
  8660. so the garbage collector can't reuse it.  GC must in general not only
  8661. mark all the memory reachable in "one step", but all the memory
  8662. reachable from that in turn, and so on & so on.
  8663.  
  8664. If GC occurs after #4, of course neither of the earlier-allocated lists
  8665. are reachable, so the memory they occupy won't get "marked", so that
  8666. memory will get reused.
  8667.  
  8668. The general behavior is that "the system" doesn't worry about memory
  8669. until it runs out of it, at which point it stops everything else to
  8670. find & recycle the old memory that's no longer being used.
  8671.  
  8672. This can take an appreciable amount of time when it happens, and of
  8673. course the collector is itself a program that needs memory for its own
  8674. use.  That's the likely source of the (misleading; see below) claim that
  8675. Mathematica can use "essentially all" the memory for real stuff.
  8676.  
  8677. Reference counting (RC) is a different technique.  Under RC, each piece
  8678. of allocated memory keeps track of how many times it's pointed *at* by
  8679. other pieces of memory; when this count drops to 0, the memory can be
  8680. reused (that the count is 0 *means* that it's not being pointed at).
  8681.  
  8682. So in executing line #1, a piece of data is attached to the [2] list
  8683. that records that the [2] list is pointed at once (by the program
  8684. variable A).
  8685.  
  8686. In executing line #2, the "reference count" for the [2] list must be
  8687. bumped up by 1 because the [2] list is again referenced by a pointer
  8688. embedded in the A list.  In addition, a RC of 1 must be attached to the
  8689. list assigned to A.
  8690.  
  8691. In line #3, the system sees that B is being changed to point at a
  8692. different chunk of memory, so the RC of what it used to point at (the
  8693. [2] list) must be decreased by 1.  This will decrease it from 2 to 1.
  8694. Since it's 1, it's still being pointed at by something, so the system
  8695. can't reuse it.
  8696.  
  8697. Similarly, in line #4 the reference count of the A list is decreased
  8698. from 1 to 0.  Aha!  Since it's 0, nobody else is referencing it, so the
  8699. system can reuse it.  Since it will be reused, the reference counts of
  8700. everything *it* points at must also be decreased by 1, so the system has
  8701. to examine the A list carefully to find all the things it points at.  It
  8702. will find that it's pointing to the [2] list, so will decrease the [2]
  8703. list's RC by 1.  That in turn decrease's the [2] list's RC to 0, so that's
  8704. no longer used either.  The system then searches thru the [2] list in
  8705. order to find anything *it* may be referencing, but doesn't find another
  8706. pointer so the process stops there.
  8707.  
  8708. There are several things to note about this:  (1) It takes memory to
  8709. store the reference counts.  So a claim that an RC approach lets you use
  8710. "almost all" the available memory for "real stuff" is misleading.  (2)
  8711. Like Icon-flavor GC, RC also needs to recursively traverse your data
  8712. structures looking for contained pointers.  (3) It takes time to
  8713. increase and decrease the counts.  (4) While Icon-flavor GC lumps all
  8714. the work together at one time, RC-based systems tend to spread the work
  8715. out over time so that memory-management "hiccups" (pauses) aren't
  8716. noticeable.  (5) An RC-based system does all the work of maintaining the
  8717. counts whether or not you eventually run out of memory; so an Icon-
  8718. flavor GC gets off cheaper in the common case where the initial memory
  8719. region suffices.
  8720.  
  8721.  
  8722. Dynamic memory management is a very involved topic, and the stuff above
  8723. conveniently ignored almost all the interesting problems & possible
  8724. workarounds in both systems.  They both face real problems in practice!
  8725. As another complication, almost all large programs (like Icon, and
  8726. probably Mathematica too) use several different strategies (e.g., Icon
  8727. uses a different scheme for strings than it uses for co-expressions, and
  8728. so on).
  8729.  
  8730. I just hoped to convey enough of the essentials to make you skeptical of
  8731. marketing hype <grin>.
  8732.  
  8733. from-what-i-know-of-them-icon's-strategies-are-very-intelligent-choices-
  8734.    for-icon's-needs-and-i'd-be-real-surprised-if-mathematica's-choices-
  8735.    weren't-intelligent-for-its-needs-ly y'rs  - tim
  8736.  
  8737. Tim Peters   Kendall Square Research Corp
  8738. tim@ksr.com,         ksr!tim@uunet.uu.net
  8739.  
  8740. From icon-group-request  Sat Dec 21 21:07:55 1991
  8741. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Sat, 21 Dec 91 21:07:55 MST
  8742. Received: from ucbvax.Berkeley.EDU by optima.cs.arizona.edu (4.1/15)
  8743.     id AA02121; Sat, 21 Dec 91 21:07:51 MST
  8744. Received: by ucbvax.Berkeley.EDU (5.63/1.43)
  8745.     id AA20805; Sat, 21 Dec 91 19:58:58 -0800
  8746. Received: from USENET by ucbvax.Berkeley.EDU with netnews
  8747.     for icon-group@cs.arizona.edu (icon-group@cs.arizona.edu)
  8748.     (contact usenet@ucbvax.Berkeley.EDU if you have questions)
  8749. Date: 21 Dec 91 04:52:15 GMT
  8750. From: news@psuvax1.cs.psu.edu  (Felix Lee)
  8751. Organization: Penn State Computer Science
  8752. Subject: Re: Memory Mangement
  8753. Message-Id: <lfdH+&=f4@cs.psu.edu>
  8754. References: <1991Dec19.015629.3966@utagraph.uta.edu>
  8755. Sender: icon-group-request@cs.arizona.edu
  8756. To: icon-group@cs.arizona.edu
  8757.  
  8758. >     Mathematica does memory management with reference counts, 
  8759. >     so that pieces of memory are freed as soon as they stop
  8760. >     being used.  This means that Mathematica can make use of
  8761. >     essentially all the memory that is available on a 
  8762. >     particular computer, without the need for operations such
  8763. >     as garbage collection.  (Mathematica by Wolfram 1988:xvi)
  8764.  
  8765. This is called "propaganda": condensing many subtle issues into a
  8766. sweeping, positive-image statement.
  8767.  
  8768. The memory management problem is this: if X used to refer to A but now
  8769. refers to B, you can reuse the memory occupied by A, but only if
  8770. noone else is using A.
  8771.  
  8772. Reference counting (RC) is giving each object a count of how many
  8773. things are using it.  When you assign X = A, you increase A's count by
  8774. one.  When you later assign X = B, you decrease A's count, and
  8775. increase B's count.  When the count for something reaches zero, you
  8776. know that noone is using it, so you can reclaim it.
  8777.  
  8778. The main flaw is this does not handle circular references.  Say that A
  8779. refers to B and B refers to A, but neither A nor B is being used any
  8780. more.  In principle you can reclaim both A and B, but RC cannot
  8781. discover this fact easily.  This isn't a problem if you can't create
  8782. recursive structures.  Perhaps Mathematica forbids them.  But these
  8783. types of structures are quite natural and common in languages like
  8784. Icon and Lisp.
  8785.  
  8786. Garbage collection (GC) strategies are more general than RC.  Rather
  8787. than continually doing RC bookkeeping, you periodically discover which
  8788. objects are in use and reclaim everything else.  There are several
  8789. different strategies for this, with different contraints and
  8790. characteristics.  I'm not going to describe them here.
  8791.  
  8792. The main flaw with GC is it has a bad image.  At apparently random
  8793. times, the system may pause for several seconds to do GC.  But modern
  8794. GC systems tend to behave well, and there's still plenty of active
  8795. research into improving GC in different ways.
  8796.  
  8797. There is good evidence that, overall, GC is more efficient than RC.
  8798. All the bookkeeping involved in RC doesn't come free.  However, the
  8799. costs get amortized over all operations, giving you a more predictable
  8800. response time.  This is attractive for interactive and real-time use,
  8801. as long as you can ignore the circular-reference problem.  Incremental
  8802. and concurrent GC strategies may be viable alternatives.
  8803.  
  8804. Memory fragmentation is a related issue.  If you allocate variably
  8805. sized pieces of memory, then the available memory in the system tends
  8806. to become scattered into many small pieces over the course of many
  8807. allocations and deallocations.
  8808.  
  8809. Now say you need to allocate 16 bytes.  There may be more than 1600
  8810. bytes of memory available, but you won't be able to use any of it if
  8811. all the pieces are smaller than 16 bytes.  RC is not enough to ensure
  8812. you can actually use "all the memory that is available on a particular
  8813. computer".
  8814.  
  8815. Pathological fragmentation is unavoidable in general unless you do
  8816. garbage compaction.  This involves moving all the objects in memory to
  8817. collect the available memory into a single area.  This suffers from
  8818. all the performance objections that apply to GC.  Note, however, that
  8819. with some types of GC you get compaction for free.
  8820.  
  8821. Now, try to condense all this into a simple blurb.  "Mathematica uses
  8822. reference counting instead of garbage collection because it seemed
  8823. like a good idea at the time."  Not very marketroidish...
  8824. --
  8825. Felix Lee    flee@cs.psu.edu
  8826.  
  8827. From NED@hmcvax.claremont.edu  Sun Dec 22 06:29:17 1991
  8828. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Sun, 22 Dec 91 06:29:17 MST
  8829. Received: from CBROWN.CLAREMONT.EDU by optima.cs.arizona.edu (4.1/15)
  8830.     id AA16944; Sun, 22 Dec 91 06:29:13 MST
  8831. Received: from HMCVAX.CLAREMONT.EDU by HMCVAX.CLAREMONT.EDU (PMDF #11000) id
  8832.  <01GEEHX9YKR69N3W7T@HMCVAX.CLAREMONT.EDU>; Sun, 22 Dec 1991 05:28 PST
  8833. Date: Sun, 22 Dec 1991 05:28 PST
  8834. From: "Ned Freed, Postmaster" <NED@hmcvax.claremont.edu>
  8835. Subject: Re: Memory Mangement
  8836. To: news@psuvax1.cs.psu.edu
  8837. Cc: icon-group@cs.arizona.edu
  8838. Message-Id: <01GEEHX9YKR69N3W7T@HMCVAX.CLAREMONT.EDU>
  8839. X-Vms-To: IN%"news@psuvax1.cs.psu.edu"
  8840. X-Vms-Cc: IN%"icon-group@cs.arizona.edu"
  8841.  
  8842. > >     Mathematica does memory management with reference counts,
  8843. > >     so that pieces of memory are freed as soon as they stop
  8844. > >     being used.  This means that Mathematica can make use of
  8845. > >     essentially all the memory that is available on a
  8846. > >     particular computer, without the need for operations such
  8847. > >     as garbage collection.  (Mathematica by Wolfram 1988:xvi)
  8848.  
  8849. > This is called "propaganda": condensing many subtle issues into a
  8850. > sweeping, positive-image statement.
  8851.  
  8852. This is indeed propaganda (the book is loaded with similar material), and other
  8853. postings have pointed out the inherent flaws in reference counts and how they
  8854. do not provide a viable general solution for Icon (and more generally for LISP
  8855. as well as lots of other language runtime facilities). However, the problem
  8856. presented by languages like Mathematica that only deal with a _very_ limited
  8857. subset of the universe of data structures and this subset is in fact quite
  8858. amenable to the use of reference counts.
  8859.  
  8860. For the most part, algebraic languages only have to deal with trees, and very
  8861. simple trees at that. Insertion of reference counts in every node of the tree
  8862. is gross overkill -- counts are only needed in the case of common
  8863. subexpressions and (possibly) in the case of cross-function references (this
  8864. depends on the characteristics of the language itself). This simplifies the
  8865. problem greatly and for this simplified problem reference counts are a very
  8866. attractive solution. It is even possible to deal with functions that reference
  8867. each other recursively in an clean and elegant fashion, since despite
  8868. appearances to the contrary these are _not_ really circular data structures
  8869. (this is because of the shallow name binding properties of most algebra
  8870. languages). Property lists are actually a somewhat tricker problem, but even
  8871. they can be dealt with nicely.
  8872.  
  8873. In my own algebraic language work I've found that reference counts were an easy
  8874. and obvious solution to many memory management problems.  The overhead is quite
  8875. low and the performance is usually excellent. When coupled with lookaside lists
  8876. and a few other tricky little low-level goodies like block allocation it is
  8877. easy to put together code where memory reclamation is so efficient that its
  8878. effect on bottom-line performance is insignificant both in terms of time and
  8879. space used. (Of course, once the problem gets large the positive benefits of
  8880. reclamation can be overwhelming, especially on virtual memory systems.) 
  8881.  
  8882. But this is just your average competent design, that's all. I certainly don't
  8883. go around tooting my horn in print about the reference count subsystem that I
  8884. employed in MATHLIB (another algebra language), which was implemented long
  8885. before the first line of Mathematica was ever written. I didn't think it was
  8886. particularly impressive when I wrote it, and I don't think it is impressive
  8887. now. It is just competent design, and certainly not the first such design
  8888. either.
  8889.  
  8890. However, you should keep in mind the characteristics of some other algebra
  8891. systems. They make Mathematica look a lot better than it actually is. Those
  8892. that run inside of more general environments (usually LISP) can scarcely be
  8893. blamed for using reclamation strategies that don't precisely match the
  8894. characteristics of the algebraic data structures these programs use, but that's
  8895. the price you pay for using such a general environment.
  8896.  
  8897. A more interesting example is the memory management of Wolfram's earler opus,
  8898. SMP. It is quite simply terrible. I won't go into details -- I don't like to
  8899. recall them. Wolfram et al did get it right the second time around, which I
  8900. suppose is something, but he really blew it big-time the first time. This is
  8901. probably not what all the Wolfram-o-philes want to hear...
  8902.  
  8903. > Now, try to condense all this into a simple blurb.  "Mathematica uses
  8904. > reference counting instead of garbage collection because it seemed
  8905. > like a good idea at the time."  Not very marketroidish...
  8906.  
  8907. I'd prefer to say that "Mathematica uses reference counting because it is the
  8908. obvious preferred solution to the problem of memory reclamation given the
  8909. nature of the language."
  8910.  
  8911. I also find the strategies employed in Icon to be extremely interesting and in
  8912. several places amazingly clever, and I have employed a number of Icon's tricks
  8913. in my own work. (The implementation of coexpressions is the part I like the
  8914. most.) I actually use this and similar information about Icon implementation
  8915. details a bit more than I actually use the Icon itself! So, if anyone has any
  8916. hesitations about discussing such matters, please note that some of the
  8917. readership of this list is very interested in these things.
  8918.  
  8919.                     Ned
  8920.  
  8921. From icon-group-request  Sun Dec 22 11:40:41 1991
  8922. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Sun, 22 Dec 91 11:40:41 MST
  8923. Received: from ucbvax.Berkeley.EDU by optima.cs.arizona.edu (4.1/15)
  8924.     id AA22223; Sun, 22 Dec 91 11:40:39 MST
  8925. Received: by ucbvax.Berkeley.EDU (5.63/1.43)
  8926.     id AA00634; Sun, 22 Dec 91 10:27:00 -0800
  8927. Received: from USENET by ucbvax.Berkeley.EDU with netnews
  8928.     for icon-group@cs.arizona.edu (icon-group@cs.arizona.edu)
  8929.     (contact usenet@ucbvax.Berkeley.EDU if you have questions)
  8930. Date: 12 Dec 91 01:56:19 GMT
  8931. From: ksr!tim@uunet.uu.net  (Tim Peters)
  8932. Organization: Kendall Square Research Corp.
  8933. Subject: Re: novice scanning question
  8934. Message-Id: <7803@ksr.com>
  8935. References: <9112111353.AA20684@relay1.UU.NET>
  8936. Sender: icon-group-request@cs.arizona.edu
  8937. To: icon-group@cs.arizona.edu
  8938.  
  8939. In article <9112111353.AA20684@relay1.UU.NET> nowlin@isidev.UUCP writes:
  8940. >
  8941. > > From: uunet!arizona!decwrl.dec.com!world!ksr!tim  (Tim Peters)
  8942. > > ...
  8943. > >     line ?:= { move(3) & move(4) }
  8944. > >      vs
  8945. > >     line ?:= ( move(3) & move(4) )
  8946. > >      vs
  8947. > >     line ?:= { move(3); move(4) }
  8948. > > ...
  8949. >It's most idiomatic (I think) to write:
  8950. >
  8951. >    procedure main()
  8952. >      line := "Now and then"
  8953. >      line ?:= ( move(3) , move(4) )
  8954. >      write(line)
  8955. >    end
  8956. >
  8957. >This is called mutual evaluation and while it's usually used for long
  8958. >sequences of compound conjunction operations it works just fine with
  8959. >only two expressions.
  8960.  
  8961. It was an artificial example so it's hard to tell what "the natural"
  8962. approach would be, but I got the impression that mutual evaluation
  8963. (whether spelled as "e1 & e2" or "(e1, e2)") was not a natural approach
  8964. to the poster's real task.  I.e., do you really want to suck a self-
  8965. proclaimed "novice" into the mysteries of backtracking <grin>?
  8966.  
  8967. Anyway, I steered him toward the quite different (semantically as well
  8968. as syntactically) "{ e1; e2; ... }" form believing that it's less
  8969. confusing for an Icon newbie -- works pretty much the way sequential
  8970. blocks in other languages work.
  8971.  
  8972. Whatever, I'm glad you drew explicit attention to mutual evaluation,
  8973. Jerry; could well be what he's really looking for.
  8974.  
  8975. consulting-via-telepathy-has-its-limitations<grin>-ly y'rs  - tim
  8976.  
  8977. Tim Peters   Kendall Square Research Corp
  8978. tim@ksr.com,         ksr!tim@uunet.uu.net
  8979.  
  8980. From alfred@adt.uni-paderborn.de  Mon Dec 23 05:22:38 1991
  8981. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Mon, 23 Dec 91 05:22:38 MST
  8982. Received: from pbinfo.uni-paderborn.de ([131.234.2.3]) by optima.cs.arizona.edu (4.1/15)
  8983.     id AA19179; Mon, 23 Dec 91 05:21:07 MST
  8984. Received: from alpha.uni-paderborn.de ([131.234.128.175]) by pbinfo.uni-paderborn.de with SMTP
  8985.     (5.65c8/PB-3.100+yp+master) id AA26793; Mon, 23 Dec 1991 13:19:19 +0100
  8986. Received: by alpha.uni-paderborn.de
  8987.     (5.61++/PB-3.41) id AA06719; Mon, 23 Dec 91 13:18:38 -0100
  8988. From: Alfred Schmidt <alfred@adt.uni-paderborn.de>
  8989. Message-Id: <9112231418.AA06719@alpha.uni-paderborn.de>
  8990. Subject: Xmas Greetings from Germany
  8991. To: icon-group@cs.arizona.edu
  8992. Date: Mon, 23 Dec 91 13:18:35 MEZ
  8993. X-Mailer: ELM [version 2.3 PL10]
  8994.  
  8995. MERRY XMAS FROM GERMANY
  8996.       and a happy new year.
  8997.  
  8998. Thanks to the whole ICON community for the fruitful hints and the very
  8999. special support.
  9000.  
  9001.   Icon User Group
  9002.   Paderborn/Germany
  9003.  
  9004. +------------------------------------------------------------------------+
  9005. | Alfred Schmidt                            The University of Paderborn  |
  9006. | Systems Engineer                          Dept. EEE                    |
  9007. | voice: +49 5251 60 3279                   Section Software Engineering |
  9008. | fax  : +49 5251 60 3246                   PO Box 1621                  |
  9009. | email: alfred@adt.uni-paderborn.de        D-4790 Paderborn/Germany     |
  9010. +------------------------------------------------------------------------+
  9011.  
  9012. From TENAGLIA@mis.mcw.edu  Mon Dec 23 11:24:05 1991
  9013. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Mon, 23 Dec 91 11:24:05 MST
  9014. Received: from MIS4.MIS.MCW.EDU by optima.cs.arizona.edu (4.1/15)
  9015.     id AA28098; Mon, 23 Dec 91 11:23:56 MST
  9016. Received: from mis.mcw.edu by mis.mcw.edu (PMDF #12252) id
  9017.  <01GEGASK9M5S934S7K@mis.mcw.edu>; Mon, 23 Dec 1991 12:25 CST
  9018. Date: Mon, 23 Dec 1991 12:25 CST
  9019. From: Chris Tenaglia - 257-8765 <TENAGLIA@mis.mcw.edu>
  9020. Subject: Holiday Offering, Thanksgiving leftovers
  9021. To: icon-group@cs.arizona.edu
  9022. Message-Id: <01GEGASK9M5S934S7K@mis.mcw.edu>
  9023. X-Organization: Medical College of Wisconsin (Milwaukee, WI)
  9024. X-Vms-To: IN%"icon-group@cs.arizona.edu"
  9025.  
  9026.  
  9027. The response on the brain-dead, cheating tic-tac-toe game offering of the
  9028. Thanksgiving holiday has been underwhelming. Oh well, I promised a smarter
  9029. version the next time. Here it is. It uses a strategy list. It's not very
  9030. elegant, always starts first (and in the same spot), and always ends in a
  9031. draw or computer winning. At least it plays fair and has a few more comments.
  9032. I've tested it under VMS and Unix (ultrix) using VT compatible emulation.
  9033.  
  9034. The next step would be to have it start in a random corner (maintain several
  9035. more strategy lists). The next step after that would be to allow the player to
  9036. start (a lot more work). I threw this together in a quiet evening and a lunch
  9037. hour. Enjoy!
  9038.  
  9039. Chris Tenaglia (System Manager) | Medical College of Wisconsin
  9040. 8701 W. Watertown Plank Rd.     | Milwaukee, WI 53226
  9041. (414)257-8765                   | tenaglia@mis.mcw.edu, mcwmis!tenaglia
  9042.  
  9043. ###############################################################
  9044. #                                                             #
  9045. #          file : tt2.icn                                     #
  9046. #          updt : 23-dec-1991                                 #
  9047. #          auth : chris tenaglia                              #
  9048. #          desc : tictactoe icon implementation               #
  9049. #          note : This version plays fair, it uses a strategy #
  9050. #                 but isn't very creative.                    #
  9051. #                                                             #
  9052. ###############################################################
  9053. global me,you,true,false,draw,pointer,wins,pass,taken,winner
  9054. global mark,row,routes,route
  9055. procedure main()
  9056.   init()
  9057.   play := true
  9058.   while play == true do
  9059.     {
  9060.     me      := set()      # computer is me
  9061.     you     := set()      # player   is you
  9062.     victory := ""         # nobodys' won yet
  9063.     winner  := ""         # winner flag
  9064.     pass    := 0          # start flag
  9065.     taken   := table(false)    # taken position table (rather than set?)
  9066.     display()
  9067. #
  9068. # computer makes first move
  9069. #
  9070.     insert(me,1)
  9071.     taken[1] := true
  9072.     display()
  9073. #
  9074. # player follows
  9075. #
  9076.     insert(you,(tmp := integer(get_your_move())))
  9077.     taken[integer(tmp)] := true
  9078.     display()
  9079.     path := routes[tmp]              # players' move determines strategy
  9080.     index := 2                       # points at 2nd move just happened
  9081.  
  9082. #
  9083. # computers' next move determined from strategy list
  9084. #
  9085.     insert(me,(tmp := integer(path[(index+:=1)])))
  9086.     taken[tmp] := true
  9087.     display()
  9088. #
  9089. # player follows
  9090. #
  9091.     insert(you,(tmp := integer(get_your_move())))
  9092.     taken[integer(tmp)] := true
  9093.     your_last_move := tmp
  9094.     display()
  9095. #
  9096. # if didn't take position dictated, loss ensues
  9097. #
  9098.     if your_last_move ~= (tmp := integer(path[(index+:=1)])) then
  9099.       {
  9100.       winner := "me"
  9101.       insert(me,tmp)
  9102.       taken[tmp] := true
  9103.       display()
  9104.       done_yet()
  9105.       write(at(1,22),chop(&host)," Wins, You Loose!")
  9106.       every square := !row do writes(pointer[square],mark)
  9107.       again := map(input(at(1,23) || "Another game? Y/N :"))[1]
  9108.       if again=="y" then next
  9109.       stop(at(1,23),"Game Over.",chop())
  9110.       }
  9111.  
  9112. #
  9113. # user made a good move, continue (computer plays now)
  9114. #
  9115.     insert(me,(tmp := integer(path[(index+:=1)])))
  9116.     taken[tmp] := true
  9117.     display()
  9118. #
  9119. # player follows
  9120. #
  9121.     insert(you,(tmp := integer(get_your_move())))
  9122.     taken[integer(tmp)] := true
  9123.     your_last_move := tmp
  9124.     display()
  9125.  
  9126. #
  9127. # if didn't take position dictated, loss ensues
  9128. #
  9129.     if your_last_move ~= (tmp := integer(path[(index+:=1)])) then
  9130.       {
  9131.       winner := "me"
  9132.       insert(me,tmp)
  9133.       taken[tmp] := true
  9134.       display()
  9135.       done_yet()
  9136.       write(at(1,22),chop(&host)," Wins, You Loose!")
  9137.       every square := !row do writes(pointer[square],mark)
  9138.       again := map(input(at(1,23) || "Another game? Y/N :"))[1]
  9139.       if again=="y" then next
  9140.       stop(at(1,23),"Game Over.",chop())
  9141.       }
  9142. #
  9143. # if players first move wasn't 5, they lose now too
  9144. #
  9145.     if integer(path[2]) ~= 5 then
  9146.       {
  9147.       tmp := integer(path[(index+:=1)])
  9148.       winner := "me"
  9149.       insert(me,tmp)
  9150.       taken[tmp] := true
  9151.       display()
  9152.       done_yet()
  9153.       write(at(1,22),chop(&host)," Wins, You Loose!")
  9154.       every square := !row do writes(pointer[square],mark)
  9155.       again := map(input(at(1,23) || "Another game? Y/N :"))[1]
  9156.       if again=="y" then next
  9157.       stop(at(1,23),"Game Over.",chop())
  9158.       }
  9159.  
  9160. #
  9161. # user made a good move, continue (computer plays now)
  9162. #
  9163.     insert(me,(tmp := integer(path[(index+:=1)])))
  9164.     taken[tmp] := true
  9165.     display()
  9166.     write(at(1,22),chop(),"Game was a draw.")
  9167.     again := map(input(at(1,23) || "Another game? Y/N :"))[1]
  9168.     if again=="y" then next
  9169.     stop(at(1,23),"Game Over.",chop())
  9170.     }
  9171.   end
  9172. # #
  9173. #
  9174. # procedure to display the current tictactoe grid and plays
  9175. #               
  9176. procedure display()
  9177.   if (pass +:= 1) = 1 then
  9178.     {
  9179.     write(cls(),uhalf(),"          T I C - T A C - T O E")
  9180.     write(lhalf(),"          T I C - T A C - T O E")
  9181.     write(trim(center("Computer is 'O' and you are 'X'",80)))
  9182.     line := repl("q",60) ; line[21] := "n" ; line[41] := "n"
  9183.     every y := 5 to 20 do writes(at(30,y),graf("x"))
  9184.     every y := 5 to 20 do writes(at(50,y),graf("x"))
  9185.     writes(at(10,10),graf(line))
  9186.     writes(at(10,15),graf(line))
  9187.     every x := 1 to 9  do writes(pointer[x],dim(x))
  9188.     }
  9189.   every writes(pointer[!me],high("O"))
  9190.   every writes(pointer[!you],under("X"))
  9191.   end
  9192.                 
  9193. #
  9194. # procedure to obtain a move choice from the player
  9195. #
  9196. procedure get_your_move()
  9197.   local yours,all_moves
  9198.   repeat {
  9199.   writes(at(5,22))
  9200.   yours := input("Enter block # (1-9) :")
  9201.   writes(at(5,23),chop())
  9202.   if not(integer(yours)) then
  9203.     {
  9204.     writes(at(5,23),beep(),"Invalid Input! Choose 1-9.")
  9205.     next
  9206.     }
  9207.   if (1 > yours) | (yours > 9) then
  9208.     {
  9209.     writes(at(5,23),beep(),"Value out of range! Choose 1-9.")
  9210.     next
  9211.     }
  9212.   if taken[integer(yours)] == true then
  9213.     {
  9214.     writes(at(5,23),beep(),"That position is already taken! Try again.")
  9215.     next
  9216.     }
  9217.   break }
  9218.   return integer(yours)
  9219.   end
  9220.  
  9221. #
  9222. # procedure to test if computer has won, or the game is a draw
  9223. #
  9224. procedure done_yet()
  9225.   every outcome := !wins do
  9226.     {
  9227.     test := 0
  9228.     every part := !outcome do
  9229.       if member(you,part) then test +:= 1
  9230.     if test = 3 then
  9231.       {
  9232.       winner := "you"
  9233.       row    := outcome
  9234.       mark   := high(blink("X"))
  9235.       return true
  9236.       }
  9237.     }
  9238.   every outcome := !wins do
  9239.     {
  9240.     test := 0
  9241.     every part := !outcome do
  9242.       if member(me,part) then test +:= 1
  9243.     if test = 3 then
  9244.       {
  9245.       winner := "me"
  9246.       row    := outcome
  9247.       mark   := high(blink("O"))
  9248.       return true
  9249.       }             
  9250.     }
  9251.   if *me + *you > 8 then
  9252.     {
  9253.     winner := draw
  9254.     return draw
  9255.     }
  9256.   return "not done yet"
  9257.   end
  9258. # #
  9259. #
  9260. # prompts for an input from the user
  9261. #
  9262. procedure input(prompt)
  9263.   writes(prompt)
  9264.   return read()
  9265.   end
  9266. # #
  9267. #
  9268. # procedures to output ansi graphics and attributes
  9269. #
  9270. procedure at(x,y)
  9271.   return "\e[" || y || ";" || x || "f"
  9272.   end
  9273.   
  9274. procedure graf(str)
  9275.   return "\e(0" || str || "\e(B"
  9276.   end
  9277.  
  9278. procedure uhalf(str)
  9279.   /str := ""
  9280.   return "\e#3" || str
  9281.   end
  9282.  
  9283. procedure lhalf(str)
  9284.   /str := ""
  9285.   return "\e#4" || str
  9286.   end
  9287.  
  9288. procedure high(str)
  9289.   return "\e[1m" || str || "\e[0m"
  9290.   end
  9291.  
  9292. procedure normal(str)
  9293.   return "\e[0m" || str
  9294.   end
  9295.  
  9296. procedure dim(str)
  9297.   return "\e[2m" || str || "\e[0m"
  9298.   end
  9299.   
  9300. procedure under(str)
  9301.   return "\e[4m" || str || "\e[0m"
  9302.   end
  9303.  
  9304. procedure blink(str)
  9305.   return "\e[5m" || str || "\e[0m"
  9306.   end
  9307.  
  9308. procedure cls(str)
  9309.   /str := ""
  9310.   return "\e[2J\e[H" || str
  9311.   end
  9312.  
  9313. procedure chop(str)
  9314.   /str := ""
  9315.   return "\e[J" || str
  9316.   end
  9317.  
  9318. procedure beep()
  9319.   return "\7"
  9320.   end
  9321. # #  
  9322. #
  9323. # procedure to init useful global variables for later use
  9324. #
  9325. procedure init()
  9326.   true    := "y"
  9327.   false   := "n"
  9328.   draw    := "?"
  9329.   &random := map(&clock,":","0")
  9330.   routes  := ["-","1274958","1374958","1432956","1547328",
  9331.                   "1632745","1732956","1874352","1974352"]
  9332.   wins    := [set([1,5,9]),set([3,5,7]),set([1,2,3]),set([4,5,6]),
  9333.               set([7,8,9]),set([1,4,7]),set([2,5,8]),set([3,6,9])]
  9334.   pointer := [at(17,7), at(37,7), at(57,7),
  9335.               at(17,12),at(37,12),at(57,12),
  9336.               at(17,17),at(37,17),at(57,17)]
  9337.   end
  9338.   
  9339.  
  9340. From icon-group-request  Mon Dec 23 11:56:24 1991
  9341. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Mon, 23 Dec 91 11:56:24 MST
  9342. Received: from ucbvax.Berkeley.EDU by optima.cs.arizona.edu (4.1/15)
  9343.     id AA29106; Mon, 23 Dec 91 11:56:23 MST
  9344. Received: by ucbvax.Berkeley.EDU (5.63/1.43)
  9345.     id AA28850; Mon, 23 Dec 91 10:48:39 -0800
  9346. Received: from USENET by ucbvax.Berkeley.EDU with netnews
  9347.     for icon-group@cs.arizona.edu (icon-group@cs.arizona.edu)
  9348.     (contact usenet@ucbvax.Berkeley.EDU if you have questions)
  9349. Date: 19 Dec 91 01:44:22 GMT
  9350. From: mips.mitek.com!utacfd.uta.edu!utagraph.uta.edu!utarlg.uta.edu!b912dieg@apple.com  (DOUG WITMER)
  9351. Organization: The University of Texas at Arlington
  9352. Subject: Memory Mangement
  9353. Message-Id: <1991Dec19.015629.3966@utagraph.uta.edu>
  9354. Sender: icon-group-request@cs.arizona.edu
  9355. To: icon-group@cs.arizona.edu
  9356.  
  9357. This question is directed at those having an in depth knowledge
  9358. of ICON internals and in particular ICON memory management.  I
  9359. know from my readings that the ICON system finds it necessary
  9360. to perform frequent garbage collections to maintain an adequate
  9361. supply of unfragmented memory.  I also know that ICON is 
  9362. implemented in the C language.  My question stems from a claim
  9363. which I read today concerning the Mathematica language which is
  9364. also implemented in C.  Here is what they say about garbage 
  9365. collection:
  9366.  
  9367.      Mathematica does memory management with reference counts, 
  9368.      so that pieces of memory are freed as soon as they stop
  9369.      being used.  This means that Mathematica can make use of
  9370.      essentially all the memory that is available on a 
  9371.      particular computer, without the need for operations such
  9372.      as garbage collection.  (Mathematica by Wolfram 1988:xvi)
  9373.  
  9374. Does anyone have an explanation of reference counts?  Can the
  9375. use of reference counts really eliminate garbage collection?
  9376. Thanks for helping satisfy my curiosity.
  9377. Doug Witmer
  9378. b912dieg@utarlg.uta.edu
  9379.  
  9380. From wgg@cs.ucsd.edu  Wed Dec 25 00:38:24 1991
  9381. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Wed, 25 Dec 91 00:38:24 MST
  9382. Received: from relay2.UU.NET by optima.cs.arizona.edu (4.1/15)
  9383.     id AA21051; Wed, 25 Dec 91 00:38:34 MST
  9384. Received: from ucsd.edu by relay2.UU.NET with SMTP 
  9385.     (5.61/UUNET-internet-primary) id AA01643; Wed, 25 Dec 91 02:38:33 -0500
  9386. Received: from gremlin.ucsd.edu by ucsd.edu; id AA11078
  9387.     sendmail 5.64/UCSD-2.2-sun via SMTP
  9388.     Tue, 24 Dec 91 23:38:31 -0800 for isidev!nowlin@uunet.uu.net
  9389. Received: by gremlin.ucsd.edu (4.1/UCSDPSEUDO.4)
  9390.     id AA13508 for uunet!cs.arizona.edu!icon-group@uunet.uu.net; Tue, 24 Dec 91 23:38:29 PST
  9391. Date: Tue, 24 Dec 91 23:38:29 PST
  9392. From: wgg@cs.ucsd.edu (William Griswold)
  9393. Message-Id: <9112250738.AA13508@gremlin.ucsd.edu>
  9394. To: isidev!nowlin@uunet.uu.net, cs.arizona.edu!icon-group@uunet.uu.net
  9395. Subject: Re: tic-tac-toe
  9396.  
  9397. Several years ago, as a novice Icon programmer, I wrote a learning
  9398. tic-tac-toe player that sounds similar to Jerry's.  This player was so
  9399. `dumb' that it didn't even know what a winning board was!  Tic-tac-toe was
  9400. the domain we chose to test a learning algorithm based on creating general
  9401. knowledge from specific examples.  The player discovered this general knowledge
  9402. by `intersecting' boards to create fuzzy board patterns.  A fuzzy pattern
  9403. consisted of X's, O's, empty squares, and Don't Cares.  When two
  9404. boards were combined to make a pattern, squares that exactly matched
  9405. retained their value in the new board, but others became don't care.  Of
  9406. course, when we intersected two boards, we also combined their win-loss-tie
  9407. histories, which guided their use during play.  To make things interesting,
  9408. we limited the pattern space (``memory'') to be less than the number of
  9409. possible boards, and then let the board patterns `compete' for the available
  9410. space.  Like Jerry's player, ours learned faster against good opponents than
  9411. bad ones.
  9412.  
  9413.                         Bill Griswold
  9414.  
  9415. From icon-group-request  Sun Dec 29 10:55:22 1991
  9416. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Sun, 29 Dec 91 10:55:22 MST
  9417. Received: from ucbvax.Berkeley.EDU by optima.cs.arizona.edu (4.1/15)
  9418.     id AA05432; Sun, 29 Dec 91 10:55:20 MST
  9419. Received: by ucbvax.Berkeley.EDU (5.63/1.43)
  9420.     id AA14218; Sun, 29 Dec 91 09:41:46 -0800
  9421. Received: from USENET by ucbvax.Berkeley.EDU with netnews
  9422.     for icon-group@cs.arizona.edu (icon-group@cs.arizona.edu)
  9423.     (contact usenet@ucbvax.Berkeley.EDU if you have questions)
  9424. Date: 10 Dec 91 21:31:19 GMT
  9425. From: mailer.cc.fsu.edu!sun13!sun8.scri.fsu.edu@gatech.edu  (John Nall)
  9426. Organization: SCRI, Florida State University
  9427. Subject: String Scanning Question (from novice)
  9428. Message-Id: <6030@sun13.scri.fsu.edu>
  9429. Sender: icon-group-request@cs.arizona.edu
  9430. To: icon-group@cs.arizona.edu
  9431.  
  9432. I had a bug in a program, and finally found it.  But
  9433. although I can fix it easily, I still don't understand
  9434. what I did wrong.
  9435.  
  9436. The book, page 32, says that the form of a string-scanning
  9437. expression is:
  9438.  
  9439.        expr1 ? expr2
  9440.  
  9441. It also says (page 38) that an augmented assignment of the form:
  9442.  
  9443.        s ?:= expr 
  9444.  
  9445. "can be used to scan s and assign a new value to it as a result.
  9446. The value assigned is the value produced by expr".
  9447.  
  9448. The book also says (page 18) that when the conjunction
  9449.  
  9450.        expr1 & expr2
  9451.  
  9452. is evaluated, it produces the value of expr2 (assuming both succeed).
  9453.  
  9454. The following little nonsense program illustrates the problem.
  9455. As I understand, the expression "line ?:= move(3) & move(4)" should
  9456. result in line being assigned the value resulting from the
  9457. "move(4)" part.  But it does not.  Instead it assigns the value
  9458. resulting from the "move(3)" part instead.  (My bug, by the way :-)  )
  9459.  
  9460. procedure main()
  9461.   line := "Now and then"
  9462.   line ?:=  move(3) & move(4) 
  9463.   write(line)    # writes only "Now"
  9464. end
  9465.  
  9466. BUT...(the fix) if I do it like this, it works ok:
  9467.  
  9468. procedure main()
  9469.   line := "Now and then"
  9470.   line ?:= { move(3) & move(4) }
  9471.   write(line)    # writes " and" as it is supposed to
  9472. end
  9473.  
  9474. So is the book wrong?  Or am I just misunderstanding what it says?
  9475.  
  9476. Thanks
  9477.  
  9478. --
  9479. John W. Nall        | Supercomputer Computations Research Institute
  9480. nall@sun8.scri.fsu.edu  | Florida State University, Tallahassee, FL 32306
  9481. (904)-644-6008          | "Down with liberals.  Down with conservatives."
  9482.  
  9483. From ralph  Sun Dec 29 11:07:51 1991
  9484. Date: Sun, 29 Dec 91 11:07:51 MST
  9485. From: "Ralph Griswold" <ralph>
  9486. Message-Id: <9112291807.AA03934@cheltenham.cs.arizona.edu>
  9487. Received: by cheltenham.cs.arizona.edu; Sun, 29 Dec 91 11:07:51 MST
  9488. To: icon-group@cs.arizona.edu,
  9489.         mailer.cc.fsu.edu!sun13!sun8.scri.fsu.edu@gatech.edu
  9490. Subject: Re:  String Scanning Question (from novice)
  9491.  
  9492. Your problem is precedence.  The conjunction operation, &, has the lowest
  9493. precedence of all infix operations.  Therefore,
  9494.  
  9495.     e1 ? e2 & e3
  9496.  
  9497. groups as
  9498.  
  9499.     (e1 ? e2) & e3
  9500.  
  9501.  
  9502. See page 40 of the second edition of the Icon book.
  9503.     
  9504.     Ralph Griswold / Department of Computer Science 
  9505.     The University of Arizona / Tucson, AZ 85721
  9506.     
  9507.     ralph@cs.arizona.edu / uunet!arizona!ralph
  9508.     
  9509.     voice: 602-621-6609 / fax: 602-621-9618
  9510.  
  9511. From icon-group-request  Sun Dec 29 15:43:24 1991
  9512. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Sun, 29 Dec 91 15:43:24 MST
  9513. Received: from ucbvax.Berkeley.EDU by optima.cs.arizona.edu (4.1/15)
  9514.     id AA17942; Sun, 29 Dec 91 15:43:22 MST
  9515. Received: by ucbvax.Berkeley.EDU (5.63/1.43)
  9516.     id AA27485; Sun, 29 Dec 91 14:28:48 -0800
  9517. Received: from USENET by ucbvax.Berkeley.EDU with netnews
  9518.     for icon-group@cs.arizona.edu (icon-group@cs.arizona.edu)
  9519.     (contact usenet@ucbvax.Berkeley.EDU if you have questions)
  9520. Date: 10 Dec 91 23:44:43 GMT
  9521. From: fernwood!cronos!laguna!alex@uunet.uu.net  (Bob Alexander)
  9522. Organization: Metaphor Computer Systems, Mountain View, CA
  9523. Subject: Re: expanding regions, Mach
  9524. Message-Id: <1696@cronos.metaphor.com>
  9525. References: <1991Dec7.170211.22874@midway.uchicago.edu>
  9526. Sender: icon-group-request@cs.arizona.edu
  9527. To: icon-group@cs.arizona.edu
  9528.  
  9529. In article <1991Dec7.170211.22874@midway.uchicago.edu>
  9530. goer@midway.uchicago.edu writes:
  9531.  
  9532. >Also, how viable would it be simply to have a routine that sat around
  9533. >and waited for sbrk(> 0) requests, and then (when it encountered them),
  9534. >just used vm_alloc (or whatever it is you use on a NeXT), obtained a
  9535. >block of contiguous memory, then did a block copy of the static, block,
  9536. >and string regions, realigned all the base pointers and what not, and
  9537. >then freed the old contiguous block (or, if there's a vm_realloc func-
  9538. >tion, used that)?
  9539.  
  9540. If I follow your drift, the technique you suggest is pretty much what
  9541. is done in the Macintosh-MPW version.  I didn't put in any code to
  9542. relocate anything, though, so the region has to be expanded in place
  9543. using a realloc()-type call in the Mac O/S that promises not to move
  9544. anything.
  9545.  
  9546. The problem is, of course, that by the time region expansion is needed,
  9547. it's likely that other non-relocatable blocks have been allocated by
  9548. some system service in such a way that the Icon-block can't be expanded
  9549. in place.  I haven't done any tests to see just how often region
  9550. expansion succeeds or fails, but in general I don't think you can
  9551. really count on it, and the best bet is to allocate bigger regions
  9552. beforehand.
  9553.  
  9554. Obviously, this technique works MUCH better if the Icon memory can be
  9555. relocated, as Richard suggested.  I haven't looked into how hard this
  9556. would be -- perhaps the garbage collector could do it quite easily.  Of
  9557. course, you still have the problem of needing <old memory size> + <new
  9558. memory size> to perform the copy.
  9559.  
  9560. -- Bob Alexander
  9561.  
  9562. Metaphor Computer Systems   (415) 961-3600 x751   alex@metaphor.com
  9563. ====^=== Mountain View, CA  ...{uunet}!{decwrl,apple}!metaphor!alex
  9564.  
  9565. From icon-group-request  Sun Dec 29 16:56:52 1991
  9566. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Sun, 29 Dec 91 16:56:52 MST
  9567. Received: from ucbvax.Berkeley.EDU by optima.cs.arizona.edu (4.1/15)
  9568.     id AA19293; Sun, 29 Dec 91 16:56:49 MST
  9569. Received: by ucbvax.Berkeley.EDU (5.63/1.43)
  9570.     id AA01147; Sun, 29 Dec 91 15:43:48 -0800
  9571. Received: from USENET by ucbvax.Berkeley.EDU with netnews
  9572.     for icon-group@cs.arizona.edu (icon-group@cs.arizona.edu)
  9573.     (contact usenet@ucbvax.Berkeley.EDU if you have questions)
  9574. Date: 11 Dec 91 04:09:26 GMT
  9575. From: agate!spool.mu.edu!uwm.edu!linac!uchinews!ellis!goer@ucbvax.berkeley.edu  (Richard L. Goerwitz)
  9576. Organization: University of Chicago Computing Organizations
  9577. Subject: Re: String Scanning Question (from novice)
  9578. Message-Id: <1991Dec11.040926.11559@midway.uchicago.edu>
  9579. References: <6030@sun13.scri.fsu.edu>
  9580. Sender: icon-group-request@cs.arizona.edu
  9581. To: icon-group@cs.arizona.edu
  9582.  
  9583. In article <6030@sun13.scri.fsu.edu> nall@sun8.scri.fsu.edu (John Nall) writes:
  9584. >
  9585. >is evaluated, it produces the value of expr2 (assuming both succeed).
  9586. >
  9587. >The following little nonsense program illustrates the problem.
  9588. >As I understand, the expression "line ?:= move(3) & move(4)" should
  9589. >result in line being assigned the value resulting from the
  9590. >"move(4)" part.  But it does not.  Instead it assigns the value
  9591. >resulting from the "move(3)" part instead.  (My bug, by the way :-)  )
  9592. >
  9593. >procedure main()
  9594. >  line := "Now and then"
  9595. >  line ?:=  move(3) & move(4) 
  9596. >  write(line)    # writes only "Now"
  9597. >end
  9598.  
  9599. Think of line ?:= move(3) & move(4) as line := line ? move(3) & move(4).
  9600. The precedences work out like this:  (line := (line ? move(3))) & move(4).
  9601. The result is that line is evaluated, producing a variable, then the scan-
  9602. ning expression (line ? move(3)) gets evaluated, producing the value of
  9603. move(3) (if it succeeds), and then assigning that value to the variable
  9604. produced earlier on.  If this whole business succeeds, then move(4) is
  9605. evaluated.  By now we're outside of the scanning expression, and &pos and
  9606. &subject havewhatever values they had before evaluation of this line be-
  9607. gan, so the results are irrelevant (and aren't used anyway).
  9608.  
  9609. I guess the bottom line is that expression1 op:= expression2 always works
  9610. out as expression1 := expression1 op expression2.
  9611.  
  9612. >BUT...(the fix) if I do it like this, it works ok:
  9613. >
  9614. >procedure main()
  9615. >  line := "Now and then"
  9616. >  line ?:= { move(3) & move(4) }
  9617. >  write(line)    # writes " and" as it is supposed to
  9618. >end
  9619.  
  9620. Good fix.  It's always good to group expressions manually if there could
  9621. be any confusion about their order of evaluation.  Basically what you're
  9622. doing is forcing move(3) & move(4) into a single expression that gets
  9623. evaluated within the scanning operation set up by the ?:= operator.  You
  9624. could also just write line ?:= (move(3), move(4)), which to me looks more
  9625. idiomatic, but does the same thing.  If you prefer the other way, that's
  9626. fine, too.
  9627.  
  9628. >So is the book wrong?  Or am I just misunderstanding what it says?
  9629.  
  9630. Nobody's wrong.  Everybody's right.  Merry Christmas!  :-)
  9631.  
  9632. -- 
  9633.  
  9634.    -Richard L. Goerwitz              goer%sophist@uchicago.bitnet
  9635.    goer@sophist.uchicago.edu         rutgers!oddjob!gide!sophist!goer
  9636.  
  9637. From icon-group-request  Sun Dec 29 18:12:34 1991
  9638. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Sun, 29 Dec 91 18:12:34 MST
  9639. Received: from ucbvax.Berkeley.EDU by optima.cs.arizona.edu (4.1/15)
  9640.     id AA20847; Sun, 29 Dec 91 18:12:33 MST
  9641. Received: by ucbvax.Berkeley.EDU (5.63/1.43)
  9642.     id AA05207; Sun, 29 Dec 91 17:08:19 -0800
  9643. Received: from USENET by ucbvax.Berkeley.EDU with netnews
  9644.     for icon-group@cs.arizona.edu (icon-group@cs.arizona.edu)
  9645.     (contact usenet@ucbvax.Berkeley.EDU if you have questions)
  9646. Date: 11 Dec 91 06:10:08 GMT
  9647. From: ksr!tim@uunet.uu.net  (Tim Peters)
  9648. Organization: Kendall Square Research Corp.
  9649. Subject: Re: String Scanning Question (from novice)
  9650. Message-Id: <7762@ksr.com>
  9651. References: <6030@sun13.scri.fsu.edu>
  9652. Sender: icon-group-request@cs.arizona.edu
  9653. To: icon-group@cs.arizona.edu
  9654.  
  9655. In article <6030@sun13.scri.fsu.edu> nall@sun8.scri.fsu.edu (John Nall) writes:
  9656. %I had a bug in a program, and finally found it.
  9657. % ... [this one is yielding unexpected behavior] ...
  9658. %procedure main()
  9659. %  line := "Now and then"
  9660. %  line ?:=  move(3) & move(4)
  9661. %  write(line)    # writes only "Now"
  9662. %end
  9663. %
  9664. %BUT...(the fix) if I do it like this, it works ok:
  9665. %
  9666. %procedure main()
  9667. %  line := "Now and then"
  9668. %  line ?:= { move(3) & move(4) }
  9669. %  write(line)    # writes " and" as it is supposed to
  9670. %end
  9671. %...
  9672.  
  9673. Not to worry, John -- all will be clear!  You need to look at the end of
  9674. Appendix A to get the precedence of the operators straight.  Note that
  9675. in Icon (like as in C or Perl or ... but unlike as in Pascal or Fortran
  9676. or ...), assignment is a binary operator, much like "+" and "*" and "&".
  9677. Because it is just another binary operator, the precedence of assignment
  9678. with respect to the other binary operators is important, and can
  9679. occasionally lead to surprise.  That's what's happening to you above.
  9680.  
  9681. The table at the end of Appendix A says that all forms of assignment in
  9682. Icon (whether plain, or the "swap" flavor, or augmented) have the same
  9683. precedence, and that it's higher (binds more tightly) than the
  9684. precedence of the "&" operator.  In fact, "&" has *the* lowest
  9685. precedence, which you will appreciate some day (trust me <grin>).
  9686.  
  9687. So in
  9688.  
  9689.     line ?:=  move(3) & move(4)
  9690.  
  9691. the "?:=" binds more tightly than the "&", so Icon groups it this way:
  9692.  
  9693.     (line ?:=  move(3)) & move(4)
  9694.  
  9695. The "move(4)" is off in outer space somewhere, & has nothing to do with
  9696. scanning "line"; the attempt to move(4) will actually fail in your
  9697. program, but failure doesn't generally cause an error msg so you
  9698. probably didn't realize it.  Try this line to see it a bit more clearly:
  9699.  
  9700.   line ?:=  move(3) & (move(4) | write("I can't!"))
  9701.  
  9702. The good news is that Icon is working as documented & that it isn't hard
  9703. to learn "the rules".  The bad news is that experience with other
  9704. languages will work against you at first (some of your expectations are,
  9705. well, wrong <grin>).
  9706.  
  9707. hang-in-there-it's-worth-a-little-initial-discomfort-ly y'rs  - tim
  9708.  
  9709. Tim Peters   Kendall Square Research Corp
  9710. tim@ksr.com,         ksr!tim@uunet.uu.net
  9711.  
  9712.  
  9713. ps:  It's probably a bit more idiomatic to write your
  9714.     line ?:= { move(3) & move(4) }
  9715.      as
  9716.     line ?:= ( move(3) & move(4) )
  9717.      although
  9718.     line ?:= { move(3); move(4) }
  9719.      is a suggestive alternative to think about.
  9720.  
  9721. From icon-group-request  Mon Dec 30 22:39:35 1991
  9722. Received: from optima.cs.arizona.edu by cheltenham.cs.arizona.edu; Mon, 30 Dec 91 22:39:35 MST
  9723. Received: from ucbvax.Berkeley.EDU by optima.cs.arizona.edu (4.1/15)
  9724.     id AA08699; Mon, 30 Dec 91 22:39:27 MST
  9725. Received: by ucbvax.Berkeley.EDU (5.63/1.43)
  9726.     id AA11821; Mon, 30 Dec 91 21:30:53 -0800
  9727. Received: from USENET by ucbvax.Berkeley.EDU with netnews
  9728.     for icon-group@cs.arizona.edu (icon-group@cs.arizona.edu)
  9729.     (contact usenet@ucbvax.Berkeley.EDU if you have questions)
  9730. Date: 30 Dec 91 22:03:32 GMT
  9731. From: uchinews!ellis!goer@speedy.wisc.edu  (Richard L. Goerwitz)
  9732. Organization: University of Chicago Computing Organizations
  9733. Subject: bibleref-2.2
  9734. Message-Id: <1991Dec30.220332.4899@midway.uchicago.edu>
  9735. Sender: icon-group-request@cs.arizona.edu
  9736. To: icon-group@cs.arizona.edu
  9737.  
  9738. For anyone who wants it, a maintenance update of bibleref has been
  9739. placed in ~ftp/icon/contrib/bibleref-2.2.tar.Z on cs.arizona.edu.
  9740. Bibleref is a King James Bible text retrieval program geared for
  9741. UNIX systems.  It comes with a pre-indexed, compressed King James
  9742. text, but other texts can be indexed as well (e.g. the CCAT RSV
  9743. text with the Catholic Apocrypha, the Princeton Qur'an, and the
  9744. Book of Mormon).
  9745.  
  9746. I've not tried running the program under anything but UNIX.  It
  9747. can't run under DOS because of the 64k executable size-limit, but
  9748. maybe it would run under VMS - ?  Dunno.
  9749.  
  9750. Anyone wanting additional information, please drop me a line.
  9751.  
  9752. -- 
  9753.  
  9754.    -Richard L. Goerwitz              goer%sophist@uchicago.bitnet
  9755.    goer@sophist.uchicago.edu         rutgers!oddjob!gide!sophist!goer
  9756.  
  9757.