Instead of the 'everything is a struct' view, you could also use an 'everything is a vector view' and with unsafe-vector-ref take things apart - even when they are opaque.<br><br>(require scheme/unsafe/ops)<br>
<br>(define-struct s (a b c))<br><br>(define s1 (make-s 1 3 5))<br><br>s1 -> #<s><br>(unsafe-vector-ref s1 0) -> #<struct-type:s><br>(unsafe-vector-ref s1 1) -> 1<br>(unsafe-vector-ref s1 2) -> 3<br>
(unsafe-vector-ref s1 3) -> 5<br><br>I assume that as long as I stay within the bounds of the underlying representation (and probably sometimes even if I don't - negative indices are allowed), unsafe-vector-ref will give gladly me the pieces. At least there is no unsafe-vector-set! <br>
<br>Doug<br><br><div class="gmail_quote">On Tue, Nov 10, 2009 at 11:29 AM, Doug Williams <span dir="ltr"><<a href="mailto:m.douglas.williams@gmail.com">m.douglas.williams@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Sounds good. I was just thinking that a lower level implementation could avoid the need to create a vector just to get the variant. But for my code it's no big deal.<div><div></div><div class="h5"><br><br><div class="gmail_quote">
On Tue, Nov 10, 2009 at 11:21 AM, Robby Findler <span dir="ltr"><<a href="mailto:robby@eecs.northwestern.edu" target="_blank">robby@eecs.northwestern.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">On Tue, Nov 10, 2009 at 12:18 PM, Doug Williams<br>
<div><<a href="mailto:m.douglas.williams@gmail.com" target="_blank">m.douglas.williams@gmail.com</a>> wrote:<br>
</div><div>> Robby,<br>
><br>
> I am going to add your variant procedure to the describe collection.<br>
<br>
</div>Great!<br>
<div><br>
> Are you<br>
> happy with the name 'variant' and the contract (-> any/c symbol?)?<br>
<br>
</div>Yes. (You may want to use substring isntead of regexp-match.)<br>
<div><br>
> What is<br>
> the relationship between this and object-name?<br>
<br>
</div>Nothing really. object-name is per-object (and not everything has a name).<br>
<div><br>
> It seems that for actual<br>
> structs they return the same value. Would it make sense to change<br>
> object-name to return the same value as variant in those cases where it<br>
> (i.e., object-name) returns #f? This would trivially make this functionality<br>
> available in #lang scheme, which seems to be a good thing.<br>
<br>
</div>I don't think that that change is really a good idea at this point.<br>
Probably would break lots of stuff.<br>
<font color="#888888"><br>
Robby<br>
</font><div><div></div><div><br>
> Doug<br>
><br>
> On Tue, Nov 10, 2009 at 7:43 AM, Robby Findler <<a href="mailto:robby@eecs.northwestern.edu" target="_blank">robby@eecs.northwestern.edu</a>><br>
> wrote:<br>
>><br>
>> On Tue, Nov 10, 2009 at 8:41 AM, Dave Herman <<a href="mailto:dherman@ccs.neu.edu" target="_blank">dherman@ccs.neu.edu</a>> wrote:<br>
>> >> This probably doesn't help Doug, but here is another way to define the<br>
>> >> function linked above:<br>
>> ><br>
>> > That's neat, thanks! Has struct->vector always worked on non-structs?<br>
>><br>
>> I'm not sure about always, but at some point a while ago, Matthew<br>
>> decided that all values are structs (in the sense that you could have<br>
>> implemented everything with structs and scope, etc even if some of<br>
>> them are implemented in C) and adapted the primitives to make them<br>
>> behave accordingly.<br>
>><br>
>> Robby<br>
><br>
><br>
</div></div></blockquote></div><br>
</div></div></blockquote></div><br>