and yet:
> (for-each
(λ (x) (printf "~a: ~a\n" (~v x #:min-width 28) (struct->vector x)))
`(hello "hello" 43110 #f #(h e l l o) #"hello" (h e l l o)
,(new frame% [label ""])))
hello : #(struct:symbol ...)
"hello" : #(struct:string ...)
43110 : #(struct:fixnum-integer ...)
#f : #(struct:false ...)
#(h e l l o) : #(struct:vector ...)
#"hello" : #(struct:byte-string ...)
(h e l l o) : #(struct:pair ...)
#(struct:object:frame% ...) : #(struct:object:frame% ...)
;)
On Mon, Aug 3, 2020 at 4:20 PM Alexis King <[email protected]> wrote:
> 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 <[email protected]> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/C561F2A9-0C78-4EDA-A401-4FB067D79849%40gmail.com
> .
>
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/racket-users/CABNTSaGUiZWoU9mZbqMjB04FSu_kFOGrgyv0riU8TuKtffB_dg%40mail.gmail.com.