I wrote a kind of DSL on top of Common Lisp. The domain is rather strange, and my language is very different from Common Lisp. I put the whole interface in a package foo:
(defpackage :foo
(:use :common-lisp
:internal-machinery)
(:shadow :in-package
:*packages*))
Switching between packages is beyond the scope of the language concept, so I turned off this ability by obscuring the in-packageand characters *package*. Now the user (programmer) of my language will not be able to switch packets. Good.
Obviously, I want to use the Common Lisp compiler to compile programs written in this language. The function compile-filelooks fine to me. But there are difficulties.
I want to compile the file as if its contents were inside my package foo. Including (in-package :foo)on top of each program in my prototype language is an undesirable option.
To make things even worse, I have to compile the file inside the function:
(in-package :internal-machinery)
(defun compile-stuff (filename)
(in-package :foo) ; it will have no effect, because
; this macro must be top level form
(compile-file filename) ; other options are omitted
(in-package :internal-machinery)) ; no way, even if it were top level
; form, in-package is shadowed
I have no idea if this is possible or not, so any help would be appreciated.
source
share