Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!linus!decvax!yale-com!leichter From: leichter@yale-com.UUCP (Jerry Leichter) Newsgroups: net.lang Subject: Re: Self-modifying code Message-ID: <2678@yale-com.UUCP> Date: Sun, 8-Jan-84 16:31:40 EST Article-I.D.: yale-com.2678 Posted: Sun Jan 8 16:31:40 1984 Date-Received: Mon, 9-Jan-84 04:38:57 EST References: unc.6480 Lines: 32 Two quick comments: SNOBOL does, indeed, allow self-modifying code in several ways of varying power: 1. Functions are defined dynamically, as in LISP. You can re-define any function at any time, effectively changing the meaning of all calls. 2. The compiler is callable as a subroutine. You can take a string, convert it to an expression, and evaluate the expression. Alterna- tively, you can take a string that contains multiple statements, compile them into code, and transfer to the first instruction of the code. Note that both "unevaluated expressions" and "code" are data objects that can be passed around in SNOBOL code. 3. In case (2), if the code being compiled contains any labeled statements, the labels get defined, and can be transfered to. If a label is found that is already defined, the new value replaces the old. As a result, you can "overlay" code within the program, IF it is explicitly transfered to. (If control just flows into the code, it will continue to do so even if the label that used to point to the code no longer does so.) This is not a completely general facility, but it is quite powerful. It is not very widely used. Among the more interesting uses is to have rarely-used functions be read in "on demand" - you initially define the function to point to a stub that reads in the code, compiles it, re-defines the function, and transfers to it. I used these facilities to build an interactive SNOBOL called APLBOL; it provides a user interface almost the same as APL's - you define and edit functions "on the fly". APLBOL passes them off to SNOBOL for compilation. You can do all sorts of unexpected things in SNOBOL if you understand the lang- uage well enough. -- Jerry decvax!yale-comix!leichter leichter@yale