> On Aug 24, 2018, at 8:50 AM, Joao Pedro Abreu De Souza <jp_ab...@id.uff.br> > wrote: > > Hi. I am contributing in a library that create functions to parse PEG(parsing > expression grammar). To implement a feature, I need to know the return's type > of a function. We are using racket, not typed-racket, so I think that I need > to get the contract or something like that. I dont see in the reference and > guide how to do that. Can anyone give me a direction?
There's the `value-contract` function [1]. > (define/contract (f x) (-> integer? integer?) x) > (value-contract f) (-> integer? integer?) However, it doesn't work on everything (only values that had to be *wrapped* in chaperones because of higher-order properties), so might be less useful than you think. Also, it only works on functions that were explicitly wrapped with contracts, while most "base" functions do error checking themselves without a contract wrapper. So `value-contract` doesn't work on functions like that: > (value-contract string-length) #f > (value-contract sqrt) #f Also, contracts are *extensible* in a way that types are not, which makes them more flexible but harder to analyze in general. Users can define new contracts and contract combinators that can "do" anything. With types it's about what the type "is" and its relationships to other types and language forms. But with contracts it's about what they "do" when a value comes along that it can check. So someone could create a new contract that checks their function, and `value-contract` would return it, but it wouldn't be an `->` contract, and your library wouldn't be able to analyze it. So can you give more details about what you would need to use it for? [1]: https://docs.racket-lang.org/reference/contract-utilities.html#(def._((lib._racket%2Fcontract%2Fprivate%2Fguts..rkt)._value-contract)) <https://docs.racket-lang.org/reference/contract-utilities.html#(def._((lib._racket/contract/private/guts..rkt)._value-contract))> > -- > 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 > <mailto:racket-users+unsubscr...@googlegroups.com>. > For more options, visit https://groups.google.com/d/optout > <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.