[racket-users] Get contract from function

2018-08-24 Thread Joao Pedro Abreu De Souza
The library is with a problem that is when manage the * operator(greedy
repeat), if the term that is repeat would be a string, then he returns a
empty string, that is the equivalent of a rule that always match but
without consume anything. If the term that is repeat would be other thing,
the * returns a empty list.

The problem is : when there's no match of the operand, the * is not
returning "" but (). Some cases this is good, in other force us to handle
more cases that theorically will be the same. Worse than that, force our
users, that may use the link to create a parser, to handle this special
case too. The repository is racket-peg on GitHub, from user rain-1. There's
a issue about empty string in the second place I think if this helps.

Thank you for the attention. :)

2018-08-24 11:02 GMT-03:00 Alex Knauth :

>
>
> On Aug 24, 2018, at 8:50 AM, Joao Pedro Abreu De Souza 
> 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-utiliti
> es.html#(def._((lib._racket%2Fcontract%2Fprivate%2Fguts..
> 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.
> 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.


Re: [racket-users] Get contract from function

2018-08-24 Thread Robby Findler
Perhaps object-contract?

Note that this might not return a contract, however, in which case,
the function might return anything.

Robby

On Fri, Aug 24, 2018 at 7:50 AM Joao Pedro Abreu De Souza
 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?
>
> --
> 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.


Re: [racket-users] Get contract from function

2018-08-24 Thread Alex Knauth


> On Aug 24, 2018, at 8:50 AM, Joao Pedro Abreu De Souza  
> 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))
 



> -- 
> 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.


[racket-users] Get contract from function

2018-08-24 Thread Joao Pedro Abreu De Souza
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?

-- 
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.