Hello,

I am working on a project in which I am trying to implement a Common Lisp-style 
package system. A simple example of usage would be as follows:

   (in-package FOO
     (define BAR 2))
   ; ...
   (in-package FOO
     (define BAZ (add1 BAR)))
   ; ...
   (in-package FOO
     (add1 BAZ)) ; => 4
   ; ...
   (in-package QUUX
     (add1 FOO:BAZ)) ; => 4

I was able to get something to this effect by doing the following:

   1. Create a namespace during phase 1 for each package
   2. Wrap the (in-package ...) body in a submodule 
      (to remove any local bindings in other parts of the file)
   3. Wrap the body in the following:
      (require (for-syntax syntax/parse) racket/splicing)
      (parameterize ((current-namespace #,(package-namespace resolved-package)))
      (splicing-let-syntax ((#%top (λ(stx) 
                               (syntax-parse stx 
                                 [(_ . id) #'(namespace-variable-value 'id)]))))
        #,@#'body))

      This makes all non-local definitions resolve to the current namespace's 
definition. 

This works great. I ran into a problem, however, when trying to create a 
provide transformer for the packages. I wrote the transformer and tried to test 
it, only to be greeted by this message:

   write: cannot marshal value that is embedded in compiled code value

The value in question was one of the namespaces I had created. Some searching 
online led me to http://stackoverflow.com/questions/17437037/what-is-3d-syntax 
, which, while telling me what the problem with my code was, still leaves me 
wondering, is this a bad place for 3D syntax? More or less, I am trying to 
manually link the identifiers in a given environment and export those bindings 
as runtime values. Is there another/a better way to do this? While I could 
perhaps shoehorn these namespace bindings into purely phase 0 code, I would 
rather have more preprocessor overhead and less runtime overhead and link 
everything up during phase 1*. If that's a reasonable idea, how might I go 
about pushing these namespace values from phase 1 to phase 0?

*Disclaimer: There's a decent chance that any such "placement" of the overhead 
is a figment of my imagination and, in reality, pushing it to phase 0 will make 
no difference.

Regards,
- Philip Blair (belph)

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to