Packages and selective permissions

Discussion of Common Lisp
Post Reply
garethw
Posts: 43
Joined: Fri Jul 13, 2012 12:56 pm
Location: Ottawa, ON

Packages and selective permissions

Post by garethw » Wed Feb 13, 2013 10:22 pm

My latest source of general befuddlement is the package system, and how best to use it to implement something somewhat analogous to a friend class in C++.

I've written some code that models a popular uProcessor from the 80s. I've exposed a small, clean interface to allow client code to drive it by sticking it all in a package, Vanilla, and exporting the appropriate symbols.

I've also written some code that provides some debug functionality that requires some access to the internals of the above - single-stepping, disassembly, breakpoints, register inspection, stuff like that. It needs access to, well, just about anything - its whole purpose is to violate the black box. I decided to put this in a separate package, Debug, which exports its own interface.

I'm trying to figure out what the best way to arrange this might be. I've thought of a couple of solutions:
  • 1. Just accept the fact that the debug code needs to violate the boundaries, and use Vanilla::<stuff> to access internals and be done with it. The key point here is that the Debug package is built on top of the Vanilla user package.

    2. Put everything in the Debug package; build the Vanilla package with no real functionality, that just exports a restricted interface without debug functions - the key point here being that the Vanilla user package is built on top of Debug.
Or maybe I'm just far too invested in bondage and discipline languages to realize that I should just stop worrying about it?
~garethw

Goheeca
Posts: 271
Joined: Thu May 10, 2012 12:54 pm
Contact:

Re: Packages and selective permissions

Post by Goheeca » Thu Feb 14, 2013 9:52 am

It appears to me that import is appropriate here.
cl-2dsyntax is my attempt to create a Python-like reader. My mirror of CLHS (and the dark themed version). Temporary mirrors of aferomentioned: CLHS and a dark version.

garethw
Posts: 43
Joined: Fri Jul 13, 2012 12:56 pm
Location: Ottawa, ON

Re: Packages and selective permissions

Post by garethw » Sat Feb 16, 2013 9:45 pm

import definitely helps :)

I kind of assumed I'd be able to do this with the :import keyword in defpackage, but that doesn't seem to work for un-exported symbols in the source package.

Thanks, Goheeca.
~garethw

Post Reply