Matching FFI types with "match"

37 views
Skip to first unread message

Peter Samarin

unread,
Jul 14, 2019, 4:28:39 PM7/14/19
to Racket Developers
Hi all,

Is this behavior expected?

(require racket/main
            ffi/unsafe)

(for/list ([type (list _float _double _int)])
  (match type
    [_float 'float]
    [_double 'double]
    [_int 'int]))

> '(float float float)

I was expecting '(float double int)

--Peter

Sam Tobin-Hochstadt

unread,
Jul 14, 2019, 4:32:58 PM7/14/19
to Peter Samarin, Racket Developers
Yes, the problem here is that plain names in `match` are bindings, not
comparisons to things in the environment. So if you replace `_float`
with `empty` or `string=?` it will still produce the same answer.

If you want to compare with something in a `match` pattern, you might
want `==`: https://docs.racket-lang.org/reference/match.html?q=%3D%3D#%28form._%28%28lib._racket%2Fmatch..rkt%29._~3d~3d%29%29

Sam
> --
> You received this message because you are subscribed to the Google Groups "Racket Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to racket-dev+...@googlegroups.com.
> To post to this group, send email to racke...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/racket-dev/de7284e8-e6ec-4681-9110-6cb1756e8276%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Peter Samarin

unread,
Jul 14, 2019, 4:39:34 PM7/14/19
to Racket Developers
Thank you, that was helpful!
Reply all
Reply to author
Forward
0 new messages