How about making an unsafe submodule?

#lang racket/base

(provide vplus)

(module+ unsafe
  (provide vplus)
  (require racket/unsafe/ops))

(define (vplus v1 v2)
  (build-vector (vector-length v1)
    (lambda (i) (+ (vector-ref v1 i)
                   (vector-ref v2 i)))))

(module+ unsafe
  (define (vplus v1 v2)
    (build-vector (unsafe-vector-length v1)
      (lambda (i) (+ (unsafe-vector-ref v1 i)
                     (unsafe-vector-ref v2 i))))))


The require becomes a little ugly, but I guess that's a good warning flag.

#lang racket/base

;(require
;  (only-in "unsafe-submod.rkt" vplus))
(require
  (only-in (submod "unsafe-submod.rkt" unsafe) vplus))

(vplus 0 0) ;; Segfault

On Tue, Sep 29, 2015 at 9:17 AM, Neil Van Dyke <n...@neilvandyke.org> wrote:

> Does it make sense for a non-Racket #lang module to `provide` both *safe*
> and *unsafe* (in the sense of `racket/unsafe/ops`) variants of procedures?
>
> If so, any tricks to doing that?
>
> For example:
> * A function `foo` defined in this #lang module might result in the module
> providing two Racket procedures: `foo` and `foo/unsafe`.
> * `foo/unsafe` might use `racket/unsafe/ops`, but `foo` would not.
> * I want outside Racket code that uses only `foo` (not `foo/unsafe`) from
> this #lang module to not incur any kind of taint.
>
> Neil V.
>
> --
> 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.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to