Xref: utzoo comp.lang.lisp:3503 comp.lang.lisp.franz:4 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!mcsun!ukc!edcastle!aiai!jeff From: jeff@aiai.ed.ac.uk (Jeff Dalton) Newsgroups: comp.lang.lisp,comp.lang.lisp.franz Subject: Re: Trying to convert from Franz to Common lisp Keywords: fexpr, lexpr needed Message-ID: <3222@skye.ed.ac.uk> Date: 17 Aug 90 16:46:02 GMT References: <13416@sun.udel.edu> Reply-To: jeff@aiai.UUCP (Jeff Dalton) Organization: AIAI, University of Edinburgh, Scotland Lines: 68 In article <13416@sun.udel.edu> vandyke@sun.udel.edu (Julie A Vandyke) writes: >I am needing a common lisp implementation of fexpr and lexpr. >Does anyone have or know of one before I work on the >problem myself? I'd love to save myself some effort. > >Thanx in advance for any help- > >Email please, as I do not usually read this newsgroup. I also e-mailed this (plus some other Franz hacks) but thoght this might be of general interest. I wrote this code long ago so I can no longer remember for sure whether it all works. ------------------------------ ;;;; def ;;; ;;; This is one way to let people define nlambdas (fexprs), lexprs, and ;;; vanilla (non-defmacro) Franz macros. 'Apply' will work with lexprs ;;; but not with fexprs or macros ;;; (defmacro def (name (type formals &body body)) (case type (lambda `(defun ,name ,formals ,@body)) (nlambda (if (/= (length formals) 1) (error "Def: fexpr ~S must have exactly one formal parameter." name)) (let ((real-name (intern (concatenate 'string "REAL-" (symbol-name name))))) `(progn (defun ,real-name ,formals ,@body) (defmacro ,name (&rest .fexpr-args.) `(funcall #' ,',real-name ', .fexpr-args.))))) (lexpr (if (/= (length formals) 1) (error "Def: lexpr ~S must have exactly one formal parameter." name) `(defun ,name (&rest .lexpr-args.) (let* ((.lexpr-nargs. (length .lexpr-args.)) (,(first formals) .lexpr-nargs.)) ,@body)))) (macro (if (/= (length formals) 1) (error "Def: macro ~S must have exactly one formal parameter." name) `(defmacro ,name (&rest ,(first formals)) (setq ,(first formals) ;/\/ hack for Kyoto (cons ',name ,(first formals))) ,@body))) (t (error "Def: ~S is not a valid function type for function ~S." type name)))) ;;;; lexpr extras ;;; ;;; These are macros so they can reference '.lexpr-args.' despite ;;; lexical scoping (hee hee). ;;; (defmacro arg (&optional (n nil n-p)) (if n-p `(elt .lexpr-args. ,n) ;? might want to do our own length check? `(progn .lexpr-nargs.))) ;not just a variable so can't be set ------------------------------ Jeff Dalton, JANET: J.Dalton@uk.ac.ed AI Applications Institute, ARPA: J.Dalton%uk.ac.ed@nsfnet-relay.ac.uk Edinburgh University. UUCP: ...!ukc!ed.ac.uk!J.Dalton