vandyke@sun.udel.edu (Julie A Vandyke) (08/16/90)
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. Thanx- Julie Van Dyke email: vandyke@udel.edu
jeff@aiai.ed.ac.uk (Jeff Dalton) (08/17/90)
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
baxter@madeleine.ics.uci.edu (Ira Baxter) (08/18/90)
In case you want to convert DRACO to CommonLisp, this might be handy: In <3222@skye.ed.ac.uk> jeff@aiai.ed.ac.uk (Jeff Dalton) writes: >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 -- Ira Baxter