Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!cs.utexas.edu!uunet!mcvax!inria!crcge1!adams From: adams@crcge1.UUCP (Drew Adams) Newsgroups: comp.lang.lisp Subject: Re: Translating Franz Lisp to Common Keywords: lisp, franz, common Message-ID: <4660@crcge1.UUCP> Date: 1 Jun 89 13:35:39 GMT References: <1196@cayman.cme.nbs.gov> Reply-To: adams@crcge1.UUCP (Drew Adams) Organization: Laboratoires de Marcoussis (CGE) - France Lines: 99 In article <1196@cayman.cme.nbs.gov> kramer@cme.nbs.gov (Tom Kramer) writes: > >Around the end of 1988 I inquired from Franz, Inc. whether they had any >programming aids to give to users for translating Franz to Common. They >did not. >I have not heard of a translator program. To write a translator that would >handle a moderately complex (50 twenty-line functions) software system in >Franz with only a few errors and inefficiencies, would take several months >solid work, I think. --------------------------------------- In 1984 I wrote a translator program, FTOC (Franz To Common), which has been used a bit here and elsewhere, since. It (source) is available to anyone for "research" (i.e. non-commercial) purposes. It was written for an old version of Franz (I forget which). The basic program works fine, but its correctness depends on the correctness of the set of rewrite rules used to define the language-language translation. These could be improved, and some are even known to be incorrect. No guarantees are made, of course. The program works by simple macro-expansion (but not evaluation), i.e. "reduction". It may also be used for any other (Lisp-like) language-language translation. (You'll need to define the rewrite rules. Yes, THAT is a lot of work -- it means translating every language expression, if you want a "complete" translator.) No translation program is satisfactory, obviously (there are lots of untranslatable things). FTOC tries to be prudent, rather than clever; whenever possible it tries to maintain the semantics of the original code, rather than "optimizing". Different, more liberal, rewrite rules could of course be used. FTOC is written in Common Lisp, and has run on VAX with VAX-VMS Common Lisp, and on Sun with KCL and Lucid. No claims on portability are made, but I don't recall it using any implementation-dependent features. FTOC does use the Common Lisp reader, so some porting problems may arise regarding character case, filenames etc. FTOC may be used interactively, as well, as a sort of (slow) Franz front end to Common. This is sometimes useful when Franz programmers start to learn Common -- Franz expressions may be translated on the fly and, optionally, executed in Common. In addition to the source, a User's Guide is available. I will try to respond to requests for the program promptly, but I'm a bit overloaded with work, so ... A few remarks: FTOC should be regarded as an AID to translation, rather than an automatic translator. The biggest difference between Franz and Common is that Common uses static scoping of variables (in general). Franz code which depends on dynamic scoping cannot, generally, be translated (automatically). FTOC makes no attempt to wrestle with this problem; it is ignored. Type predicates, after translation, refer to COMMON Lisp types. For example, the Franz predication (BIGP ...) is translated to the Common predication (TYPEP BIGNUM ...) Franz code which manipulates or produces CODE which is SPECIFICALLY Franz will normally NOT work, of course, after translation to COMMON. However, FTOC users may optionally choose to have macro definitions expanded during translation. This may help in some cases. Whenever an expression translation is not straightforward (the result isn't immediately recognizable as a translation of the input by the programmer), the result code is enveloped and labelled for recognition, with an FLET. That is, temporary named functions are created, whose names correspond to the source code names (prefixed by "FRANZ"). Further info on the correspondance is available using the Common Lisp function DOCUMENTATION. Finally to show one of the worst kinds of thing that can happen, because of the desire not to modify the original semantics, here is the Common Lisp code resulting from the Franz expression (+ 2 (+ 3 (+ 4 1))): [Things aren't normally this bad!] (flet ((franz.+ (&optional (n1 0) &rest n2etc) "equivalent to Franz Lisp '+'." (check-type n1 fixnum) (mapc #'(lambda (n) (check-type n fixnum)) n2etc) (if (endp n2etc) n1 (+ n1 (reduce #'+ n2etc))))) (franz.+ 2 (flet [.... AS ABOVE ...] (franz.+ 3 (flet [.... AS ABOVE ...] (franz.+ 4 1)))))) -- Drew ADAMS, Laboratoires de Marcoussis, Centre de Recherche de la Compagnie Generale d'Electricite, Route de Nozay, 91460 MARCOUSSIS, FRANCE Tel. 64.49.11.54, adams@crcge1.cge.fr