[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Why would anyone want opacity?



> Responding to Mitch Wand, Bill Rozas wrote:
> 
> > As Jeff has argued, your example does not argue for opacity.  It
> > argues for disjointness of new types.
> 
> Yes, that is what I want.  (Mitch too, probably.)  I didn't
> realize that Jeff wasn't arguing against disjointness of new
> types.  Perhaps I should have changed the subject line when
> I responded to Alan Bawden's question.

Sorry 'bout that.  I guess I should have been clearer.  I thought it
was a given that everyone (in rrrs-authors) wanted at least disjoint
types (but perhaps that's not so) and that that would be assumed
for what I wrote as well, without my having to be totally explicit
about it.

> Users of MacScheme+Toolsmith may recall that I do not hesitate
> to provide horribly low-level abstraction-breaking facilities,
> provided everyone understands that the precise result of a call
> to %%RECORD-PEEK (e.g. "Application unexpectedly quit: ID = 1"
> or "segmentation fault; core dumped") will depend upon the
> implementation.

Humm.  I'd like it to be a _bit_ less unspecified than that.
There ought to be some cases that are defined to work, for
instance, if the abstraction-breaker is part of the Scheme
language.  That is, it ought to be possible to write some
portable code.  For instance, I once wrote the following for
Lucid Common Lisp:

;;; These functions have to work for "general" structures, where all
;;; slots are of type T.  They needn't work for structures with more
;;; specialized slot types where slots might be stored in unusual ways.

(defun structurep (obj)
  (sys:structurep obj))

(defun map-structure (f s)
  ;; Returns a copy of s with all slot values v replaced by (f v).
  (let ((new-s (sys:copy-structure s))
        (type (sys:structure-type s)))
    (dotimes (i (sys:structure-length new-s type))
      (setf (sys:structure-ref new-s i type)
            (funcall f (sys:structure-ref s i type))))
    new-s))

And if these low-level oparations (structure-length, etc) were
part of Common Lisp, this would presumably be reasonably portable
code.

-- jeff