[Openmcl-devel] New snapshots available

Andrew Shalit alms at clozure.com
Sat Feb 17 20:26:48 UTC 2007



Gary Byers wrote:

 
> (a) by having their components returned as multiple values:
> 
> (multiple-value-bind (frame-width frame-height)
>     (ns:size (make-instance 'ns:ns-attributed-string :with-string "testing")))
> 
> One advantage of this convention is that one could use things like
> NTH-VALUE if you're only interested in (for instance) the height
> of a string, and passing multiple-values around is (fairly cheap.
> 
> A disadvantage is that it's not clear if this approach (viewing 
> a structure as its individual components) should be extended to
> cases where the "value(s)" of that structure is needed:
> 
> (ns:do-something-with-size! foo frame-width frame-height)
> 
> or
> 
> (ns:init-with-frame! view x y width height)
> 
> And, in the case where a message (generic function) has some methods
> which involve structure arguments and some which don't, it would lead
> to a case where the "generic function" took different numbers of required
> arguments according to the class of the specialized argument/receiver,
> as well as the case where something like NS:SIZE returned different numbers
> of values according to the class of the receiver.  Both of those
> situations seem undesirable - to me, not quite undesirable enough
> to kill the idea, but certainly undesirable.

This solution seems to cause more problems than it addresses.

> (b) As Lisp objects (DEFSTRUCTs, something lower-level, CLOS
> instances.)  This is arguably even "lispier", but has some runtime
> costs (memory-allocation and GC) that are hard to avoid.  I think
> that Randall had some code for coercing between foreign structures
> and lisp objects working, and there are probably ways of avoiding
> some incidental consing in some cases.
> 
> This would lead to:
> 
> (let* ((frame-size (ns:size (make-instance 'ns:ns-attributed-string ...))))
>    (format t "~&Size of string is [~S ~S]"
>              (ns:nsize-width frame-size)
>              (ns:ns-size-height frame-size)))
> 
> and
> 
> (let* ((frame (ns:make-rect x y width height)))
>    (ns:init-with-frame& view frame))
> 
> 
> Depending on exactly what an NS:RECT lisp object looked like, it might
> be possible to productively stick a (DECLARE (DYNAMIC-EXTENT FRAME))
> in there.

How about adding a macro that binds the components of a structure to variables?  It should be pretty easy [1] for the compiler to recognize cases where it can actually allocating the object:

(with-structure-components (frame-width frame-height)
     (ns:size (make-instance 'ns:ns-attributed-string :with-string "testing"))
     ...)

But then if you actually want the structure, you can get it:

(let* ((frame (ns:make-rect x y width height)))
   (ns:init-with-frame& view frame))
   ...)

[1] easy for me to say, at least, since I'm not writing the compiler.



More information about the Openmcl-devel mailing list