Is there a way to write normal scheme code, then (once check-proofed) change a value somewhere and make it use all the unsafe ops, preferably even at DrScheme core?<br>I wonder how much faster the code could get.<br><br>(Just thinking about a possible trade-off: a macro that switches between safe and unsafe locally.)<br>
<br>Laurent<br><br><div class="gmail_quote">On Wed, Nov 11, 2009 at 02:06, Robby Findler <span dir="ltr"><<a href="mailto:robby@eecs.northwestern.edu">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;">
Those ones don't work on everything (fixnums, for example, altho that<br>
may be the only thing) and probably the guarantees of the behavior of<br>
those is less. And, of course, they are unsafe. :)<br>
<br>
Robby<br>
<br>
On Tue, Nov 10, 2009 at 5:57 PM, Doug Williams<br>
<div><div></div><div class="h5"><<a href="mailto:m.douglas.williams@gmail.com">m.douglas.williams@gmail.com</a>> wrote:<br>
> Oh, there is an unsafe-vector-set! - and unsafe-struct-ref and set!.<br>
><br>
> On Tue, Nov 10, 2009 at 4:51 PM, Doug Williams<br>
> <<a href="mailto:m.douglas.williams@gmail.com">m.douglas.williams@gmail.com</a>> wrote:<br>
>><br>
>> Instead of the 'everything is a struct' view, you could also use an<br>
>> 'everything is a vector view' and with unsafe-vector-ref take things apart -<br>
>> 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<br>
>> representation (and probably sometimes even if I don't - negative indices<br>
>> are allowed), unsafe-vector-ref will give gladly me the pieces. At least<br>
>> there is no unsafe-vector-set!<br>
>><br>
>> Doug<br>
>><br>
>> On Tue, Nov 10, 2009 at 11:29 AM, Doug Williams<br>
>> <<a href="mailto:m.douglas.williams@gmail.com">m.douglas.williams@gmail.com</a>> wrote:<br>
>>><br>
>>> Sounds good. I was just thinking that a lower level implementation could<br>
>>> avoid the need to create a vector just to get the variant. But for my code<br>
>>> it's no big deal.<br>
>>><br>
>>> On Tue, Nov 10, 2009 at 11:21 AM, Robby Findler<br>
>>> <<a href="mailto:robby@eecs.northwestern.edu">robby@eecs.northwestern.edu</a>> wrote:<br>
>>>><br>
>>>> On Tue, Nov 10, 2009 at 12:18 PM, Doug Williams<br>
>>>> <<a href="mailto:m.douglas.williams@gmail.com">m.douglas.williams@gmail.com</a>> wrote:<br>
>>>> > Robby,<br>
>>>> ><br>
>>>> > I am going to add your variant procedure to the describe collection.<br>
>>>><br>
>>>> Great!<br>
>>>><br>
>>>> > Are you<br>
>>>> > happy with the name 'variant' and the contract (-> any/c symbol?)?<br>
>>>><br>
>>>> Yes. (You may want to use substring isntead of regexp-match.)<br>
>>>><br>
>>>> > What is<br>
>>>> > the relationship between this and object-name?<br>
>>>><br>
>>>> Nothing really. object-name is per-object (and not everything has a<br>
>>>> name).<br>
>>>><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<br>
>>>> > it<br>
>>>> > (i.e., object-name) returns #f? This would trivially make this<br>
>>>> > functionality<br>
>>>> > available in #lang scheme, which seems to be a good thing.<br>
>>>><br>
>>>> I don't think that that change is really a good idea at this point.<br>
>>>> Probably would break lots of stuff.<br>
>>>><br>
>>>> Robby<br>
>>>><br>
>>>> > Doug<br>
>>>> ><br>
>>>> > On Tue, Nov 10, 2009 at 7:43 AM, Robby Findler<br>
>>>> > <<a href="mailto:robby@eecs.northwestern.edu">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">dherman@ccs.neu.edu</a>><br>
>>>> >> wrote:<br>
>>>> >> >> This probably doesn't help Doug, but here is another way to define<br>
>>>> >> >> the<br>
>>>> >> >> function linked above:<br>
>>>> >> ><br>
>>>> >> > That's neat, thanks! Has struct->vector always worked on<br>
>>>> >> > 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>
>>><br>
>><br>
><br>
><br>
</div></div><div><div></div><div class="h5">_________________________________________________<br>
For list-related administrative tasks:<br>
<a href="http://list.cs.brown.edu/mailman/listinfo/plt-scheme" target="_blank">http://list.cs.brown.edu/mailman/listinfo/plt-scheme</a><br>
</div></div></blockquote></div><br>