Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!usc!ucsd!ucbvax!CS.ARIZONA.EDU!gmt From: gmt@CS.ARIZONA.EDU ("Gregg Townsend") Newsgroups: comp.lang.icon Subject: Re: Uses of dynamic typing Message-ID: <9011170450.AA03673@owl.cs.arizona.edu> Date: 17 Nov 90 04:50:18 GMT Sender: daemon@ucbvax.BERKELEY.EDU Distribution: inet Organization: The Internet Lines: 23 I've used Icon's type flexibility a few times to implement traps in subroutine packages. The paradigm works like this: (1) call enable() passing an arbitrary procedure p and other object x along with whatever is necessary to specify the trap conditions. (2) when the trap condition occurs -- for example, on every 60th call to an output routine -- p(x) is called using p and x from the enable() call. Because x can be any type including a list or record, any desired amount of data can be passed to p. This is clumsier in C because instead of an arbitrary object x one must pass a *pointer* to x, with an appropriate cast, and then access the data indirectly. To pick a nit, printf actually can be written in standard C, because the format specifies the expected types of the remaining arguments and there are standard routines for retrieving them. There are other problems such as a danger that getc() has been replaced, but they're irrelevant to this discussion. Gregg Townsend / Computer Science Dept / Univ of Arizona / Tucson, AZ 85721 +1 602 621 4325 gmt@cs.arizona.edu 110 57 16 W / 32 13 45 N / +758m