In general, the answer is “no,” mostly because it’s not clear in Racket what 
“the type of a value” means. It’s difficult to come up with a definition that 
would be useful enough to satisfy your criterion of not “having to guess it 
first.” Consider: suppose you had a hypothetical `type-of` operation that 
returned a value’s type:

    (type-of 'hello) ; => 'symbol
    (type-of "hello") ; => 'string

Now suppose you apply type-of to a value you know nothing about and get back 
'widget. Well, you don’t know what a widget is, so that didn’t actually get you 
any further from where you started: you still don’t know what to do with the 
value.

Furthermore, types are not actually disjoint. You can write a struct definition 
with properties like prop:procedure and prop:evt, and if a struct has both, 
should type-of return the struct’s name, 'procedure, or 'evt? It’s not really 
clear. You might be able to come up with some more sophisticated system with 
(potentially multiple) inheritance that could capture these relationships, but 
I can say with confidence that no such system currently exists in Racket.

Alexis

> On Aug 3, 2020, at 09:19, Hendrik Boom <hend...@topoi.pooq.com> wrote:
> 
> In plain, untyped Racket:
> 
> It is possible to ask if a value is a symbol with symbol?
> It is possible to ask if a value is a string with string?
> etc.
> 
> Is there a way to ask the type of a value without having to guess it first?
> 
> -- hendrik

-- 
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/C561F2A9-0C78-4EDA-A401-4FB067D79849%40gmail.com.

Reply via email to