Unsafe operations are usually defined externally, like in a C extension,
where safety is harder to guarantee and module hierarchies are less
idiomatic. The "unsafe" moniker is a standard warning that you are
responsible for understanding the underlying implementation and calling
into it responsibly, or risk crashing.

The documentation, assuming you know this, explains how to swap the unsafe
variants into a module that already uses the safe API, effectively
bypassing safety features like contracts and dynamic dispatch.

If you're going to use unsafe operations, make sure you need the extra
juice and are confident nothing is going to break. This isn't just the deep
end of the pool -- it's the screws holding the drain to the bottom.

Eric


On Sat, Dec 14, 2019, 5:58 PM Jack Firth <jackhfi...@gmail.com> wrote:

> I think that documentation fix is a good idea. More broadly, it seems
> awkward that all of the unsafe ops for different data types are combined
> together into a single module. I would instead expect there to be modules
> like racket/fixnum/unsafe, racket/struct/unsafe, racket/vector/unsafe, etc.
> But I've never used the unsafe ops before, maybe those who have can chime
> in?
>
> On Saturday, December 14, 2019 at 1:03:14 PM UTC-8, Dominik Pantůček wrote:
>>
>> Hello,
>>
>> the documentation at https://docs.racket-lang.org/reference/fixnums.html
>> is misleading at best. If you - as I did - use the suggested approach of
>> requiring optimized (and unsafe) fx... operations from racket/unsafe/ops
>> with:
>>
>> (require (filtered-in
>>           (λ (name) (regexp-replace #rx"unsafe-" name ""))
>>           racket/unsafe/ops))
>>
>> You end up using _all_ symbols from racket/unsafe/ops. All of them are -
>> of course - uncontracted. Which means that if you issue for example
>> vector-ref on something that is not a vector, it can crash the runtime
>> without any apparent reason - instead of just throwing an exception as
>> one would expect.
>>
>> A simple documentation fix should probably go along the lines:
>>
>> (require racket/require
>>          (filtered-in
>>           (λ (name)
>>             (and (regexp-match #rx"^unsafe-fx" name)
>>                  (regexp-replace #rx"unsafe-" name "")))
>>            racket/unsafe/ops))
>>
>> Or is it just me running into corner cases with optimized Racket code?
>>
>>
>> Cheers,
>> Dominik
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/c118c47e-fccd-4fab-b252-7a24afe6eef1%40googlegroups.com
> <https://groups.google.com/d/msgid/racket-users/c118c47e-fccd-4fab-b252-7a24afe6eef1%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAORuSUxiZ%3DD9446pqs1cK2XCGzt1OHkoij5Kzf2-65QE_APyTA%40mail.gmail.com.

Reply via email to