[racket-users] Flat Contract Value Generator

2016-06-04 Thread Chris Bui
I'm trying to create a simple flat contract of my own and a generator for it 
and I really don't know where to start. The docs here: 
https://docs.racket-lang.org/reference/Random_generation.html aren't very 
useful for somebody that doesn't know at a high level what to do.

Also, on this page: 
https://docs.racket-lang.org/reference/data-structure-contracts.html, it says

> The generator argument adds a generator for the flat-named-contract. See 
> contract-generate for more information.

I can't find contract-generate anywhere in the docs or via Google.

Here's what I'm trying to do:

I have a REST API at work written in another language and I'd like to be able 
to hit it with requests with lots of different combinations of parameters. My 
second goal is to be able to verify that the data coming back in json conforms 
to some schema. Essentially, if the value at a certain key is of a certain 
type. I did some research and thought that contracts were perfect for me. Am I 
correct about this?

I started by trying to create a flat-named-contract that checks if the first 
char of a string is a '/', like for a relative url or file path. I can define 
the contract, but the generation aspect has been a wall for me.

Could somebody give me an example?

Thanks!

-- 
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] Case vs. Match

2016-06-04 Thread Gustavo Massaccesi
Oh! More fancy that what I expected (link
https://github.com/racket/racket/blob/master/racket/collects/racket/private/case.rkt
 )

It separates the items by type, and to trigger most of the special
cases it requires at lest 10/12 of each.

Another example, with many special cases:
#lang racket
 (syntax->datum
  (expand
   #'(case x
   [(11 12 13 14 1000 a b c d "a" "b" "c" "d") 100]
   [(15 16 17 18 2000 e f g h "e" "f" "g" "h") 200]
   [(19 20 21 22 3000 i j k l "i" "j" "k" "l") 300])))

Gustavo




On Fri, Jun 3, 2016 at 8:38 PM, Robby Findler
 wrote:
> Really this is not the best example either. I guess best to look at
> the source, which is in racket/private/case and, according to a
> comment in the top of the file, is based on  Clinger's paper, "Rapid
> Case Dispatch in Scheme".
>
> Robby
>
> On Fri, Jun 3, 2016 at 6:35 PM, Robby Findler
>  wrote:
>> I think they need to be bigger, but case does have some smarts. Try
>> this one (add a `pretty-write` if you're running in cmd-line racket).
>>
>> #lang racket
>> (syntax->datum
>>  (expand
>>   #'(case x
>>   [(1 2 3 4 5 6 7 8 9 10) 1]
>>   [(a b c d e f g h i j k l m n o p q r s t) 2])))
>>
>>
>> On Fri, Jun 3, 2016 at 6:23 PM, Gustavo Massaccesi  
>> wrote:
>>>  > [...] I saw in the docs that case specifically mentions it can
>>> distribute in log(n) time [...]
>>>
>>> I think it's strange. I found the reference in
>>> https://docs.racket-lang.org/reference/case.html but it's very
>>> strange. Is it true???
>>>
>>> For example, I tried with
>>>
>>> ;---
>>> #lang racket
>>> (lambda (x)
>>>   (case x
>>> [(1 "1" #"1" |1|) 1]
>>> [(2 "2" #"2" |2|) 2]))
>>> (lambda (x)
>>>   (case x
>>> [(1 3 5 7) 1]
>>> [(2 4 6 8) 2]))
>>> ;---
>>>
>>> but both expand to a bunch of nested if, nothing fancy that may run in
>>> O(log(N)).
>>> (I don't expect that it has a smarter implementation for bigger N.)
>>>
>>> Gustavo
>>>
>>>
>>> On Fri, Jun 3, 2016 at 11:40 AM, Gerald Pipes
>>>  wrote:
 On Friday, June 3, 2016 at 10:30:35 AM UTC-4, Jon Zeppieri wrote:
> There's rarely a good reason. If you were dispatching over a very large 
> set of constants -- fixnums or characters, in particular -- I'd expect 
> better performance from case. That's about it.
>
> > On Jun 3, 2016, at 10:10 AM, Gerald Pipes 
> >  wrote:
> >
> > I have been recently using match a lot and I was wondering what was the 
> > main benefit of using case instead of match?  It seems as though match 
> > has the distribution on a single val-exp except match allows for the 
> > pattern matching and case just uses equal?.
> >
> > --
> > 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.

 Yes, I saw in the docs that case specifically mentions it can distribute 
 in log(n) time but for match there is no time mentioned. I assumed case's 
 performance was better because of the performance omission of match. Does 
 anyone know the actual performance of match?

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

-- 
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] Custom color lexer for DrRacket that requires lookahead

2016-06-04 Thread Robby Findler
On Mon, May 30, 2016 at 2:32 PM, Alexis King  wrote:
>
>> On May 30, 2016, at 12:23, Alexis King  wrote:
>>
>> Now the colorer attempts to lex the slash alone as a new token without
>> attempting to re-lex “foo”. Since a forward slash is not valid at the
>> beginning of an identifier, it is colored as an error.
>>
>> Basically, when I type a forward slash, I want the preceding token to be
>> re-lexed. I don’t need anything more than that... just a single
>> character of lookahead is necessary, effectively.
>
> Actually, I realized just after sending this that my description is not
> the full picture. I think the confusion probably stems from that the
> colorer does, in fact attempt to re-lex “foo” once the forward slash is
> typed. However, since a trailing slash is illegal at the end of an
> identifier as well, it’s still lexed as an error. Now, I keep typing:
>
>   foo/bar
>  ^
>
> This presumably causes the slash to be re-lexed, but since it’s still
> illegal at the beginning of a token, the lexer still fails. My guess
> here was that I needed to include a backup-distance on the error token,
> but that doesn’t seem to help, so I’m unsure how to properly indicate
> the need to re-lex the entire “foo/bar” token once “bar” is added.

I'm wondering why the entire thing isn't a single token, actually. So,
when you type any of these:

  f
  fo
  foo
  foo/
  foo/b
  foo/ba
  foo/bar

your lexer would always say that they are a single token. The fourth
one would be an error token, but still a single token.

Robby

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