Re: [racket-users] Unicode subscripts in code and scribble

2016-03-09 Thread Robby Findler
I think any extension is one that all would want (although I am not sure)
and so maybe pull requests is a good way to extend it?

There is the issue of conflicting imports at the latex level tho, so maybe
it should be specifiable at the document level.

Robby

On Wednesday, March 9, 2016, Vincent St-Amour <
stamo...@eecs.northwestern.edu> wrote:

> Should that table be user-extensible?
>
> Vincent
>
>
> On Wed, 09 Mar 2016 17:11:47 -0600,
> Robby Findler wrote:
> >
> > I think that maybe you're thinking of something fancier than what's
> > there. It just takes some (small) set of well-known unicode and has
> > corresponding latex commands. Then, in the latex backend for scribble,
> > it looks up latex in that table and drops it in, if it finds it.
> >
> > Robby
> >
> > On Wed, Mar 9, 2016 at 5:09 PM, Leif Andersen  > wrote:
> > >> Scribble has a big table mapping unicode to latex commands. Maybe it
> > > needs another entry?
> > >
> > > Woah, does that actually work? I was under the impression there were
> > > unicode characters that could combine other unicode characters.
> > >
> > > (Although I'd love to be wrong about this. :) )
> > >
> > > ~Leif Andersen
> > >
> > >
> > > On Wed, Mar 9, 2016 at 5:55 PM, Robby Findler
> > > > wrote:
> > >> Scribble has a big table mapping unicode to latex commands. Maybe it
> > >> needs another entry?
> > >>
> > >> Robby
> > >>
> > >>
> > >> On Wed, Mar 9, 2016 at 4:07 PM, David Van Horn  > wrote:
> > >>> Yes, the problem then is the code font doesn't support that character
> > >>> so it doesn't show up.
> > >>>
> > >>> David
> > >>>
> > >>>
> > >>> On Wed, Mar 9, 2016 at 5:05 PM, Leif Andersen  > wrote:
> >  Have you tried running the outputted tex file in xetex rather than
> pdflatex?
> > 
> >  ~Leif Andersen
> > 
> > 
> >  On Wed, Mar 9, 2016 at 5:03 PM, David Van Horn  > wrote:
> > > I have some source code I'm trying to typeset in a racketblock that
> > > uses subscript characters like ₀.  This breaks when it gets to
> latex.
> > > Is there some workaround to generate latex friendly output?
> > >
> > > Thanks,
> > > David
> > >
> > > --
> > > 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.
> >
> > --
> > 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] Unicode subscripts in code and scribble

2016-03-09 Thread Vincent St-Amour
Should that table be user-extensible?

Vincent


On Wed, 09 Mar 2016 17:11:47 -0600,
Robby Findler wrote:
> 
> I think that maybe you're thinking of something fancier than what's
> there. It just takes some (small) set of well-known unicode and has
> corresponding latex commands. Then, in the latex backend for scribble,
> it looks up latex in that table and drops it in, if it finds it.
> 
> Robby
> 
> On Wed, Mar 9, 2016 at 5:09 PM, Leif Andersen  wrote:
> >> Scribble has a big table mapping unicode to latex commands. Maybe it
> > needs another entry?
> >
> > Woah, does that actually work? I was under the impression there were
> > unicode characters that could combine other unicode characters.
> >
> > (Although I'd love to be wrong about this. :) )
> >
> > ~Leif Andersen
> >
> >
> > On Wed, Mar 9, 2016 at 5:55 PM, Robby Findler
> >  wrote:
> >> Scribble has a big table mapping unicode to latex commands. Maybe it
> >> needs another entry?
> >>
> >> Robby
> >>
> >>
> >> On Wed, Mar 9, 2016 at 4:07 PM, David Van Horn  wrote:
> >>> Yes, the problem then is the code font doesn't support that character
> >>> so it doesn't show up.
> >>>
> >>> David
> >>>
> >>>
> >>> On Wed, Mar 9, 2016 at 5:05 PM, Leif Andersen  
> >>> wrote:
>  Have you tried running the outputted tex file in xetex rather than 
>  pdflatex?
> 
>  ~Leif Andersen
> 
> 
>  On Wed, Mar 9, 2016 at 5:03 PM, David Van Horn  
>  wrote:
> > I have some source code I'm trying to typeset in a racketblock that
> > uses subscript characters like ₀.  This breaks when it gets to latex.
> > Is there some workaround to generate latex friendly output?
> >
> > Thanks,
> > David
> >
> > --
> > 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.
> 
> -- 
> 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] Unit order matters in `define-values/invoke-unit/infer`

2016-03-09 Thread Robby Findler
No, I believe that's correct behavior. You probably want to use
init-depend so you get a better error, like this:

(define-unit y@
  (import x^)
  (export y^)
  (init-depend x^)
  (define y x))

Also, I see that that the init-depend failure doesn't have good source
location reporting.

Robby


On Wed, Mar 9, 2016 at 5:41 PM, Phil Nguyen  wrote:
> The program below complains that `x` is used before initialization. But if I 
> change the linking order to `x@` before `y@`, it works fine. Is this an 
> intended behavior or a bug? This is Racket v6.4.0.7
>
> #lang racket
>
> (define-signature x^ (x))
> (define-signature y^ (y))
>
> (define-unit x@
>   (import)
>   (export x^)
>   (define x 42))
>
> (define-unit y@
>   (import x^)
>   (export y^)
>   (define y x))
>
> (define-values/invoke-unit/infer
>   (link y@ x@))
>
> --
> 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] Unit order matters in `define-values/invoke-unit/infer`

2016-03-09 Thread Phil Nguyen
The program below complains that `x` is used before initialization. But if I 
change the linking order to `x@` before `y@`, it works fine. Is this an 
intended behavior or a bug? This is Racket v6.4.0.7

#lang racket

(define-signature x^ (x))
(define-signature y^ (y))

(define-unit x@
  (import)
  (export x^)
  (define x 42))

(define-unit y@
  (import x^)
  (export y^)
  (define y x))

(define-values/invoke-unit/infer
  (link y@ x@))

-- 
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] Unicode subscripts in code and scribble

2016-03-09 Thread Robby Findler
I think that maybe you're thinking of something fancier than what's
there. It just takes some (small) set of well-known unicode and has
corresponding latex commands. Then, in the latex backend for scribble,
it looks up latex in that table and drops it in, if it finds it.

Robby

On Wed, Mar 9, 2016 at 5:09 PM, Leif Andersen  wrote:
>> Scribble has a big table mapping unicode to latex commands. Maybe it
> needs another entry?
>
> Woah, does that actually work? I was under the impression there were
> unicode characters that could combine other unicode characters.
>
> (Although I'd love to be wrong about this. :) )
>
> ~Leif Andersen
>
>
> On Wed, Mar 9, 2016 at 5:55 PM, Robby Findler
>  wrote:
>> Scribble has a big table mapping unicode to latex commands. Maybe it
>> needs another entry?
>>
>> Robby
>>
>>
>> On Wed, Mar 9, 2016 at 4:07 PM, David Van Horn  wrote:
>>> Yes, the problem then is the code font doesn't support that character
>>> so it doesn't show up.
>>>
>>> David
>>>
>>>
>>> On Wed, Mar 9, 2016 at 5:05 PM, Leif Andersen  wrote:
 Have you tried running the outputted tex file in xetex rather than 
 pdflatex?

 ~Leif Andersen


 On Wed, Mar 9, 2016 at 5:03 PM, David Van Horn  wrote:
> I have some source code I'm trying to typeset in a racketblock that
> uses subscript characters like ₀.  This breaks when it gets to latex.
> Is there some workaround to generate latex friendly output?
>
> Thanks,
> David
>
> --
> 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.

-- 
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] Unicode subscripts in code and scribble

2016-03-09 Thread Leif Andersen
> Scribble has a big table mapping unicode to latex commands. Maybe it
needs another entry?

Woah, does that actually work? I was under the impression there were
unicode characters that could combine other unicode characters.

(Although I'd love to be wrong about this. :) )

~Leif Andersen


On Wed, Mar 9, 2016 at 5:55 PM, Robby Findler
 wrote:
> Scribble has a big table mapping unicode to latex commands. Maybe it
> needs another entry?
>
> Robby
>
>
> On Wed, Mar 9, 2016 at 4:07 PM, David Van Horn  wrote:
>> Yes, the problem then is the code font doesn't support that character
>> so it doesn't show up.
>>
>> David
>>
>>
>> On Wed, Mar 9, 2016 at 5:05 PM, Leif Andersen  wrote:
>>> Have you tried running the outputted tex file in xetex rather than pdflatex?
>>>
>>> ~Leif Andersen
>>>
>>>
>>> On Wed, Mar 9, 2016 at 5:03 PM, David Van Horn  wrote:
 I have some source code I'm trying to typeset in a racketblock that
 uses subscript characters like ₀.  This breaks when it gets to latex.
 Is there some workaround to generate latex friendly output?

 Thanks,
 David

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

-- 
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] Unicode subscripts in code and scribble

2016-03-09 Thread Robby Findler
Scribble has a big table mapping unicode to latex commands. Maybe it
needs another entry?

Robby


On Wed, Mar 9, 2016 at 4:07 PM, David Van Horn  wrote:
> Yes, the problem then is the code font doesn't support that character
> so it doesn't show up.
>
> David
>
>
> On Wed, Mar 9, 2016 at 5:05 PM, Leif Andersen  wrote:
>> Have you tried running the outputted tex file in xetex rather than pdflatex?
>>
>> ~Leif Andersen
>>
>>
>> On Wed, Mar 9, 2016 at 5:03 PM, David Van Horn  wrote:
>>> I have some source code I'm trying to typeset in a racketblock that
>>> uses subscript characters like ₀.  This breaks when it gets to latex.
>>> Is there some workaround to generate latex friendly output?
>>>
>>> Thanks,
>>> David
>>>
>>> --
>>> 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.

-- 
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] Unicode subscripts in code and scribble

2016-03-09 Thread David Van Horn
Yes, the problem then is the code font doesn't support that character
so it doesn't show up.

David


On Wed, Mar 9, 2016 at 5:05 PM, Leif Andersen  wrote:
> Have you tried running the outputted tex file in xetex rather than pdflatex?
>
> ~Leif Andersen
>
>
> On Wed, Mar 9, 2016 at 5:03 PM, David Van Horn  wrote:
>> I have some source code I'm trying to typeset in a racketblock that
>> uses subscript characters like ₀.  This breaks when it gets to latex.
>> Is there some workaround to generate latex friendly output?
>>
>> Thanks,
>> David
>>
>> --
>> 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] Unicode subscripts in code and scribble

2016-03-09 Thread Leif Andersen
Have you tried running the outputted tex file in xetex rather than pdflatex?

~Leif Andersen


On Wed, Mar 9, 2016 at 5:03 PM, David Van Horn  wrote:
> I have some source code I'm trying to typeset in a racketblock that
> uses subscript characters like ₀.  This breaks when it gets to latex.
> Is there some workaround to generate latex friendly output?
>
> Thanks,
> David
>
> --
> 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] Unicode subscripts in code and scribble

2016-03-09 Thread David Van Horn
I have some source code I'm trying to typeset in a racketblock that
uses subscript characters like ₀.  This breaks when it gets to latex.
Is there some workaround to generate latex friendly output?

Thanks,
David

-- 
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] submodules in definitions and interactions window.

2016-03-09 Thread Jos Koot
The following does not work in the definitions window of DrRacket:
 
#lang racket
(module a racket (display "hello"))
(module b racket (require 'a))
(module c racket (require 'b))
(require 'c)
 
But when putting it in the interactions-window (without the #lang line),
it works.
 
After reading the docs and experimenting a bit,
I found out the following does work in the definitions window:
 
#lang racket
(module a racket (display "hello"))
(module b racket (require (submod ".." a)))
(module c racket (require (submod ".." b)))
(require 'c)
 
This puzzles me.
I know the top-level is hopeless.
Nevertheless I don't see why in this case the REPL
would have to deviate from the definitions window.
 
I am also puzzled why I have to put ".." in stead of ".".
I first tried ".", for this seems more logical to me,
but does not work (as is documented).
Help me to understand this, please.
Thanks, Jos

-- 
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] Setup/teardown for unit testing

2016-03-09 Thread Matthias Felleisen

On Mar 9, 2016, at 11:06 AM, Sam Tobin-Hochstadt  wrote:

> I think having a built-in way to do something like this would be a
> good thing, rather than having everyone write their own abstraction
> for this. One way we've avoided divergence in the Racket community
> despite Racket's flexibility is by building in the right abstractions
> in core libraries.


There is no contradiction. Racket is a more perfect United States of 
Programming Language Design.
Each programmer can use the basic building blocks and the extension mechanisms. 
Each programmer can experiment and request comments on an experiment on this 
list. 
Brian is doing so right now. 
Over time, a good suite of linguistic constructs [can we please not abuse this 
imprecise word 'abstract' like the rest of CS] emerges.
Then we can add those to the core libraries. 

Jay's loop example is perfect. (let loop ...) and (do ... ) provide perfect 
expressive power. 
But who wants to program with these things all the time. 
Comprehensions showed up, for/*&^% was added, and for/#$@! followed.
Now everybody uses for/foobar forever uber & beyond all recognition of original 
Racket program shapes. 

Thanks Brian for the discussion and the push back. -- Matthias

p.s. I am using my own home-baked parameter-based solution for a project right 
now, and I should have recognized the problem that you were pointing out. 

-- 
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] Setup/teardown for unit testing

2016-03-09 Thread Ryan Culpepper
I think it would be more (Racket-)idiomatic to make account a parameter 
(as in make-parameter) and have something that can update the parameter 
around a test case. Here is my preferred extension, by example:


(define account (make-parameter #f))

(define (call/open-bank proc)
  (parameterize ((account (open-bank))) (proc)))

(test-suite "tests"
  #:around-each call/open-bank
  (test-case "test" (check-= (balance (account)) 0))
  )

And #:before-each can be implemented given #:around-each, of course, but 
around is more general. For example, I have written many tests recently 
where I create a custodian for each test case and shut it down at the end.


BTW, I dislike the idea of #:before-each delaying the evaluation of its 
expression; just make it strict and take a procedure.


All that said, I think it's easy enough to create a helper function or 
macro and use it in each test case, so I don't think there's a pressing 
need to extend rackunit (inside of which there is a smaller testing 
framework struggling to get out, of course).


Ryan


On 03/09/2016 11:34 AM, Brian Adkins wrote:

If you're going to add something, please don't do #1 :) That's how it's
done in Ruby, but it's an OO, stateful platform, so it fits.

The only other way I've seen recently is the Elixir version (
http://elixir-lang.org/docs/stable/ex_unit/ExUnit.Case.html) , and I
like it - the setup function simply returns a value that is passed to
the test case. Your example confused me because I think you used balance
instead of account as the param e.g.:

(test-suite #:before-each (open-bank)
 (test-case/param (lambda (account) (check-= (balance account 0)))
  ...))

I would also want to retain the string description.

I agree that divergence can be a problem, but I'm a little less
concerned with that in something like Rackunit, so I'm on the fence on
this now given the simplicity of the solution for my personal need.

The Elixir solution probably uses pattern matching on the test function,
so there's a version that accepts a string description and a
block/lambda, and another version that accepts a string, a hash and a
block/lambda. This saves you from having to introduce a #:param keyword.

Maybe something like:

(test-suite #:before-each (open-bank)
   (test-case/context "Description" account
 (check-= (balance account 0


On Mar 9, 2016, at 11:06 AM, Sam Tobin-Hochstadt > wrote:

I think having a built-in way to do something like this would be a
good thing, rather than having everyone write their own abstraction
for this. One way we've avoided divergence in the Racket community
despite Racket's flexibility is by building in the right abstractions
in core libraries. But I share Jay's worry about the code in your
gist.

Here are a few possible ways I think we could add per-test-case setup
code:

1. Purely state-based. Add a `#:before-each` keyword, which defines an
expression to run before each test case. Then you'd write:

(let ([account #f])
 (test-suite #:before-each (set! account (open-bank))
(test-case (check-= (balance account 0))
 ...)))

2. Parameter-passing, with an explicit lambda (could maybe make this a
keyword version of test-case as well):

(test-suite #:before-each (open-bank)
(test-case/param (lambda (balance) (check-= (balance account 0)))
 ...))

3. Parameter-passing, with a binding position in the macro (perhaps
using a keyword like #:param):

(test-suite #:before-each (open-bank)
(test-case #:param balance (check-= (balance account 0))
 ...))

Certainly 1 is the simplest to implement, but stateful test frameworks
seem quite unfortunate. 2 is also simple, but has a proliferation of
API surface.

Any other thoughts on which of these is preferable? I'm happy to
implement whichever solution seems best.

Sam


On Wed, Mar 9, 2016 at 10:53 AM, Jay McCarthy > wrote:

I looked at the gist you posted. I don't think it is plausible for us
to add
something like that to the test code, because you're imagining
splicing the
test body after the before exprs (because in your example, the before
binds
an identifier.)

I really think you just want a slightly different test-case macro
that does
exactly what you want.

(define-syntax-rule (brian-test-case label account . exprs)
(test-case label (define account (open-bank)) . exprs))

I really can't see the appeal of trying to push something into
Rackunit that
can expand to what your example would do. It just seems so much more
complicated to implement and explain what it means than just putting in a
one line macro like this.

I feel that there is an analogy between `do`, `for`, and `let loop`.
It is
definitely wise to not have to program every `for` loop explicitly
with `let
loop`s, but trying to keep expanding the `for` macro to do more and more
towards the Lisp `do` macro is a bad move, IMHO, because it is so
much more
complicated and 

Re: [racket-users] Racket 6.4 very slow

2016-03-09 Thread Robby Findler
On Sat, Mar 5, 2016 at 8:09 AM, Matthew Flatt  wrote:
> If you start DrRacket fresh or create a new tab and paste
>
> (define (total n)
>   (for/sum ([x (in-range (+ 1 n))]) x))
> (time (total 10))
>
> into the interactions window, then it runs at non-debugging speed.
> After clicking "Run" (with an empty program), the interactions window
> runs the example with debugging speed.
>
> That difference seems confusing, and it might explain why some had
> trouble seeing the example run slowly.

I think this is a bug in the behavior of DrRacket, separate from any
lack of transparency. I've made an attempt at a fix and pushed it.

On Wed, Mar 2, 2016 at 10:25 PM, Neil Van Dyke  wrote:
> Alex Harsanyi wrote on 03/02/2016 11:19 PM:
>>
>> If it cannot be improved, perhaps a warning message should be printed in
>> the eval window...
>
> I like this idea.  Maybe add to the DrRacket REPL banner, the
> debugging/instrumentation options that are enabled.

I've pushed something that uses these strings, put onto the name of
the language as shown in the REPL. Is that what you had in mind? Does
it seem helpful?

  (module-language-repl-no-annotations "")
  (module-language-repl-debug-annotations ", with debugging")
  (module-language-repl-debug/profile-annotations ", with debugging
and profiling")
  (module-language-repl-test-annotations ", with test coverage")

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.


Re: [racket-users] Setup/teardown for unit testing

2016-03-09 Thread Brian Adkins
If you're going to add something, please don't do #1 :) That's how it's done in 
Ruby, but it's an OO, stateful platform, so it fits.

The only other way I've seen recently is the Elixir version ( 
http://elixir-lang.org/docs/stable/ex_unit/ExUnit.Case.html 
) , and I like it 
- the setup function simply returns a value that is passed to the test case. 
Your example confused me because I think you used balance instead of account as 
the param e.g.:

(test-suite #:before-each (open-bank)
(test-case/param (lambda (account) (check-= (balance account 0)))
 ...))

I would also want to retain the string description.

I agree that divergence can be a problem, but I'm a little less concerned with 
that in something like Rackunit, so I'm on the fence on this now given the 
simplicity of the solution for my personal need.

The Elixir solution probably uses pattern matching on the test function, so 
there's a version that accepts a string description and a block/lambda, and 
another version that accepts a string, a hash and a block/lambda. This saves 
you from having to introduce a #:param keyword.

Maybe something like:

(test-suite #:before-each (open-bank)
  (test-case/context "Description" account
(check-= (balance account 0

> On Mar 9, 2016, at 11:06 AM, Sam Tobin-Hochstadt  wrote:
> 
> I think having a built-in way to do something like this would be a
> good thing, rather than having everyone write their own abstraction
> for this. One way we've avoided divergence in the Racket community
> despite Racket's flexibility is by building in the right abstractions
> in core libraries. But I share Jay's worry about the code in your
> gist.
> 
> Here are a few possible ways I think we could add per-test-case setup code:
> 
> 1. Purely state-based. Add a `#:before-each` keyword, which defines an
> expression to run before each test case. Then you'd write:
> 
> (let ([account #f])
>  (test-suite #:before-each (set! account (open-bank))
> (test-case (check-= (balance account 0))
>  ...)))
> 
> 2. Parameter-passing, with an explicit lambda (could maybe make this a
> keyword version of test-case as well):
> 
> (test-suite #:before-each (open-bank)
> (test-case/param (lambda (balance) (check-= (balance account 0)))
>  ...))
> 
> 3. Parameter-passing, with a binding position in the macro (perhaps
> using a keyword like #:param):
> 
> (test-suite #:before-each (open-bank)
> (test-case #:param balance (check-= (balance account 0))
>  ...))
> 
> Certainly 1 is the simplest to implement, but stateful test frameworks
> seem quite unfortunate. 2 is also simple, but has a proliferation of
> API surface.
> 
> Any other thoughts on which of these is preferable? I'm happy to
> implement whichever solution seems best.
> 
> Sam
> 
> 
> On Wed, Mar 9, 2016 at 10:53 AM, Jay McCarthy  wrote:
>> I looked at the gist you posted. I don't think it is plausible for us to add
>> something like that to the test code, because you're imagining splicing the
>> test body after the before exprs (because in your example, the before binds
>> an identifier.)
>> 
>> I really think you just want a slightly different test-case macro that does
>> exactly what you want.
>> 
>> (define-syntax-rule (brian-test-case label account . exprs)
>> (test-case label (define account (open-bank)) . exprs))
>> 
>> I really can't see the appeal of trying to push something into Rackunit that
>> can expand to what your example would do. It just seems so much more
>> complicated to implement and explain what it means than just putting in a
>> one line macro like this.
>> 
>> I feel that there is an analogy between `do`, `for`, and `let loop`. It is
>> definitely wise to not have to program every `for` loop explicitly with `let
>> loop`s, but trying to keep expanding the `for` macro to do more and more
>> towards the Lisp `do` macro is a bad move, IMHO, because it is so much more
>> complicated and non-orthogonal. It's better to make a test system that
>> integrates well with the rest of the language and to just use the language's
>> features for extensibility.
>> 
>> Jay
>> 
>> 
>> On Tue, Mar 8, 2016 at 1:35 PM, Brian Adkins  wrote:
>>> 
>>> Not exactly. I'm looking for a way to run a function before *each*, of
>>> possibly many, test-cases. The test-suite #:before only runs once before
>>> running all the test-cases.
>>> 
>>> Although my gist: https://gist.github.com/lojic/db7016fb95b1c05e4ade only
>>> has a few test-cases, if there were many, the redundancy of specifying the
>>> context each time would be annoying.
>>> 
>>> What I'd really like is something similar to Elixir though, so I think
>>> I'll code up that macro/function. It would be more functional to have each
>>> test-case accept a context parameter, so you'd define a setup function that
>>> returns a value that each test-case accepts as input.

Re: [racket-users] Webserver returns page on ajax get request, but not ajax post

2016-03-09 Thread Marc Kaufmann
Hm, OK. I will try to reproduce it and check that it was not due to
something else (I give that a higher chance than dispatch not working
correctly), but I am in crunch mode for some deadlines, so I may not get
around to it until the weekend. I may misremember the URL that jQuery
created.

On Wed, Mar 9, 2016 at 11:22 AM, Jay McCarthy 
wrote:

> Hi Marc,
>
> If that's correct, then I think there is a problem. Here's a little
> example that shows how `dispatch-rules` should work with `request`s struct
> that have GET queries:
>
> #lang racket/base
> (require web-server/dispatch
>  web-server/http
>  net/url
>  racket/list
>  racket/promise
>  racket/match)
>
> (define-values (blog-dispatch blog-url)
>   (dispatch-rules
>[("") list-posts]
>[("posts" (string-arg)) review-post]
>[("archive" (integer-arg) (integer-arg)) review-archive]
>[else list-posts]))
>
> (define (list-posts req) `(list-posts ,@(request-bindings/raw req)))
> (define (review-post req p) `(review-post ,p))
> (define (review-archive req y m) `(review-archive ,y ,m))
>
> (define (url->request us)
>   (define uri (string->url us))
>   (define bindings-GET
> (delay
>   (filter-map
>(match-lambda
>  [(list-rest k v)
>   (if (and (symbol? k) (string? v))
>   (make-binding:form (string->bytes/utf-8 (symbol->string k))
>  (string->bytes/utf-8 v))
>   #f)])
>(url-query uri
>   (make-request #"GET" uri empty
> bindings-GET #f "1.2.3.4" 80 "4.3.2.1"))
>
> (blog-dispatch
>  (url->request "http://www.chrlsnchrg.com?data=value;))
>
> --
>
> From the perspective of the HTTP library, the ? part is *not* in the URL,
> so if you are seeing it there for dispatch-rules, then there's a problem.
>
> Jay
>
>
> On Wed, Mar 9, 2016 at 11:13 AM, Marc Kaufmann 
> wrote:
>
>> Oh, in this case the reason for wanting other separators, namely the ?
>> used automatically by jQuery's ajax functions. When I use $.get (from
>> jQuery), it adds whatever data I want to send automatically by appending a
>> bunch of ?data1=value1 and so on. That's the only reason for wanting to
>> split the URL by different patterns - or alternatively, to ignore any URL
>> ending in such values. (Maybe that wasn't clear, but a url
>> my-great-website.com?data1=value1 does not work when dispatch is looking
>> for my-great-website.com only. That was really the problem I tried to
>> solve - to let it go through and ignore the end.)
>>
>> That's why I switched to $.post, which doesn't affect the URL that is
>> sent.
>>
>> On Wed, Mar 9, 2016 at 11:05 AM, Jay McCarthy 
>> wrote:
>>
>>> On Sat, Feb 27, 2016 at 5:38 PM, Marc Kaufmann <
>>> marc.kaufman...@gmail.com> wrote:
>>>
 As we are on it, is there a way to have `dispatch-rules work on url's
 with regular expressions, so that it would work on ajax1, ajax2, etc, or
 would I have to create my own bi-directional match-expander for that? (I
 haven't tried to figure out how that would work though.) The reason I ask
 is that when sending bindings in the url,  'dispatch-rules chokes, since
 the url looks different. An alternative is to use continuations, and pass
 the url for the continuation into javascript.

>>>
>>> There is no regular expression bidi-matcher, but you could make one.
>>> You'd have to make the to-url side take in a string and check that it
>>> matches the regexp. However, I'm a little skeptical. What's wrong with
>>> using strings, numbers, etc? You just don't want to have /s separate the
>>> pieces, you want some other character to separate the pieces in the
>>> encoding?
>>>
>>> Jay
>>>
>>>

 On Sat, Feb 27, 2016 at 3:04 PM, Jay McCarthy 
 wrote:

> Hi Marc,
>
> Each `dispatch-rules` rule takes a keyword option for which methods
> you want it to handle, the default being no method and "get". So your
> call is equivalent to
>
> [("test-ajax") #:method "get" ajax]
>
> but you want
>
> [("test-ajax") #:method "put" ajax]
>
> This facilitates more easily having different functions for different
> methods.
>
> Jay
>
>
> On Sat, Feb 27, 2016 at 1:03 PM, Marc Kaufmann
>  wrote:
> > Hi all,
> >
> > I perform the following call in jQuery in a page:
> >
> > $.post( "test-ajax",
> > function( data ) {
> > alert( "Data Loaded: " + data);
> > });
> >
> >
> > The test-ajax page gets called via the url-dispatcher:
> >
> >   (define-values (site-dispatch site-url)
> >  (dispatch-rules
> >...
> >[("test-ajax") ajax]))
> >
> > and the ajax function 

Re: [racket-users] Webserver returns page on ajax get request, but not ajax post

2016-03-09 Thread Jay McCarthy
Hi Marc,

If that's correct, then I think there is a problem. Here's a little example
that shows how `dispatch-rules` should work with `request`s struct that
have GET queries:

#lang racket/base
(require web-server/dispatch
 web-server/http
 net/url
 racket/list
 racket/promise
 racket/match)

(define-values (blog-dispatch blog-url)
  (dispatch-rules
   [("") list-posts]
   [("posts" (string-arg)) review-post]
   [("archive" (integer-arg) (integer-arg)) review-archive]
   [else list-posts]))

(define (list-posts req) `(list-posts ,@(request-bindings/raw req)))
(define (review-post req p) `(review-post ,p))
(define (review-archive req y m) `(review-archive ,y ,m))

(define (url->request us)
  (define uri (string->url us))
  (define bindings-GET
(delay
  (filter-map
   (match-lambda
 [(list-rest k v)
  (if (and (symbol? k) (string? v))
  (make-binding:form (string->bytes/utf-8 (symbol->string k))
 (string->bytes/utf-8 v))
  #f)])
   (url-query uri
  (make-request #"GET" uri empty
bindings-GET #f "1.2.3.4" 80 "4.3.2.1"))

(blog-dispatch
 (url->request "http://www.chrlsnchrg.com?data=value;))

--

>From the perspective of the HTTP library, the ? part is *not* in the URL,
so if you are seeing it there for dispatch-rules, then there's a problem.

Jay


On Wed, Mar 9, 2016 at 11:13 AM, Marc Kaufmann 
wrote:

> Oh, in this case the reason for wanting other separators, namely the ?
> used automatically by jQuery's ajax functions. When I use $.get (from
> jQuery), it adds whatever data I want to send automatically by appending a
> bunch of ?data1=value1 and so on. That's the only reason for wanting to
> split the URL by different patterns - or alternatively, to ignore any URL
> ending in such values. (Maybe that wasn't clear, but a url
> my-great-website.com?data1=value1 does not work when dispatch is looking
> for my-great-website.com only. That was really the problem I tried to
> solve - to let it go through and ignore the end.)
>
> That's why I switched to $.post, which doesn't affect the URL that is sent.
>
> On Wed, Mar 9, 2016 at 11:05 AM, Jay McCarthy 
> wrote:
>
>> On Sat, Feb 27, 2016 at 5:38 PM, Marc Kaufmann > > wrote:
>>
>>> As we are on it, is there a way to have `dispatch-rules work on url's
>>> with regular expressions, so that it would work on ajax1, ajax2, etc, or
>>> would I have to create my own bi-directional match-expander for that? (I
>>> haven't tried to figure out how that would work though.) The reason I ask
>>> is that when sending bindings in the url,  'dispatch-rules chokes, since
>>> the url looks different. An alternative is to use continuations, and pass
>>> the url for the continuation into javascript.
>>>
>>
>> There is no regular expression bidi-matcher, but you could make one.
>> You'd have to make the to-url side take in a string and check that it
>> matches the regexp. However, I'm a little skeptical. What's wrong with
>> using strings, numbers, etc? You just don't want to have /s separate the
>> pieces, you want some other character to separate the pieces in the
>> encoding?
>>
>> Jay
>>
>>
>>>
>>> On Sat, Feb 27, 2016 at 3:04 PM, Jay McCarthy 
>>> wrote:
>>>
 Hi Marc,

 Each `dispatch-rules` rule takes a keyword option for which methods
 you want it to handle, the default being no method and "get". So your
 call is equivalent to

 [("test-ajax") #:method "get" ajax]

 but you want

 [("test-ajax") #:method "put" ajax]

 This facilitates more easily having different functions for different
 methods.

 Jay


 On Sat, Feb 27, 2016 at 1:03 PM, Marc Kaufmann
  wrote:
 > Hi all,
 >
 > I perform the following call in jQuery in a page:
 >
 > $.post( "test-ajax",
 > function( data ) {
 > alert( "Data Loaded: " + data);
 > });
 >
 >
 > The test-ajax page gets called via the url-dispatcher:
 >
 >   (define-values (site-dispatch site-url)
 >  (dispatch-rules
 >...
 >[("test-ajax") ajax]))
 >
 > and the ajax function is simply this:
 >
 >   (define (ajax req)
 > (response/xexpr
 > "1 "))
 >
 > Nonetheless, the above Ajax call fails with a 404 error, but when I
 replace
 > $.post by $.get, it works. As far as I can tell, the only thing about
 the
 > request this changes it the method, from POST to GET.
 >
 > Is there a reason this fails? Do I need to tell the webserver that it
 should
 > serve both POST and GET?
 >
 > Btw, the reason I want to use post is that when I use get, the 

Re: [racket-users] Webserver returns page on ajax get request, but not ajax post

2016-03-09 Thread Marc Kaufmann
Oh, in this case the reason for wanting other separators, namely the ? used
automatically by jQuery's ajax functions. When I use $.get (from jQuery),
it adds whatever data I want to send automatically by appending a bunch of
?data1=value1 and so on. That's the only reason for wanting to split the
URL by different patterns - or alternatively, to ignore any URL ending in
such values. (Maybe that wasn't clear, but a url
my-great-website.com?data1=value1 does not work when dispatch is looking
for my-great-website.com only. That was really the problem I tried to solve
- to let it go through and ignore the end.)

That's why I switched to $.post, which doesn't affect the URL that is sent.

On Wed, Mar 9, 2016 at 11:05 AM, Jay McCarthy 
wrote:

> On Sat, Feb 27, 2016 at 5:38 PM, Marc Kaufmann 
> wrote:
>
>> As we are on it, is there a way to have `dispatch-rules work on url's
>> with regular expressions, so that it would work on ajax1, ajax2, etc, or
>> would I have to create my own bi-directional match-expander for that? (I
>> haven't tried to figure out how that would work though.) The reason I ask
>> is that when sending bindings in the url,  'dispatch-rules chokes, since
>> the url looks different. An alternative is to use continuations, and pass
>> the url for the continuation into javascript.
>>
>
> There is no regular expression bidi-matcher, but you could make one. You'd
> have to make the to-url side take in a string and check that it matches the
> regexp. However, I'm a little skeptical. What's wrong with using strings,
> numbers, etc? You just don't want to have /s separate the pieces, you want
> some other character to separate the pieces in the encoding?
>
> Jay
>
>
>>
>> On Sat, Feb 27, 2016 at 3:04 PM, Jay McCarthy 
>> wrote:
>>
>>> Hi Marc,
>>>
>>> Each `dispatch-rules` rule takes a keyword option for which methods
>>> you want it to handle, the default being no method and "get". So your
>>> call is equivalent to
>>>
>>> [("test-ajax") #:method "get" ajax]
>>>
>>> but you want
>>>
>>> [("test-ajax") #:method "put" ajax]
>>>
>>> This facilitates more easily having different functions for different
>>> methods.
>>>
>>> Jay
>>>
>>>
>>> On Sat, Feb 27, 2016 at 1:03 PM, Marc Kaufmann
>>>  wrote:
>>> > Hi all,
>>> >
>>> > I perform the following call in jQuery in a page:
>>> >
>>> > $.post( "test-ajax",
>>> > function( data ) {
>>> > alert( "Data Loaded: " + data);
>>> > });
>>> >
>>> >
>>> > The test-ajax page gets called via the url-dispatcher:
>>> >
>>> >   (define-values (site-dispatch site-url)
>>> >  (dispatch-rules
>>> >...
>>> >[("test-ajax") ajax]))
>>> >
>>> > and the ajax function is simply this:
>>> >
>>> >   (define (ajax req)
>>> > (response/xexpr
>>> > "1 "))
>>> >
>>> > Nonetheless, the above Ajax call fails with a 404 error, but when I
>>> replace
>>> > $.post by $.get, it works. As far as I can tell, the only thing about
>>> the
>>> > request this changes it the method, from POST to GET.
>>> >
>>> > Is there a reason this fails? Do I need to tell the webserver that it
>>> should
>>> > serve both POST and GET?
>>> >
>>> > Btw, the reason I want to use post is that when I use get, the data I
>>> send
>>> > with the request gets put at the end of the url
>>> (../test-ajax?some-binding)
>>> > and I couldn't figure out how to have the dispatcher deal with this
>>> problem
>>> > (that returned an error 500).
>>> >
>>> > Thanks,
>>> >
>>> > Marc
>>> >
>>> >
>>> >
>>> >
>>> >
>>> > --
>>> > 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.
>>>
>>>
>>>
>>> --
>>> Jay McCarthy
>>> Associate Professor
>>> PLT @ CS @ UMass Lowell
>>> http://jeapostrophe.github.io
>>>
>>>"Wherefore, be not weary in well-doing,
>>>   for ye are laying the foundation of a great work.
>>> And out of small things proceedeth that which is great."
>>>   - D 64:33
>>>
>>
>>
>
>
> --
> Jay McCarthy
> Associate Professor
> PLT @ CS @ UMass Lowell
> http://jeapostrophe.github.io
>
>"Wherefore, be not weary in well-doing,
>   for ye are laying the foundation of a great work.
> And out of small things proceedeth that which is great."
>   - D 64:33
>

-- 
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] Setup/teardown for unit testing

2016-03-09 Thread Brian Adkins
I think you're right. Coming from a Ruby perspective, the lack of a setup 
facility seemed like a glaring omission at first glance, but I do strongly 
favor orthogonality and dislike bloat - thanks for the macro example.

> On Mar 9, 2016, at 10:53 AM, Jay McCarthy  wrote:
> 
> I looked at the gist you posted. I don't think it is plausible for us to add 
> something like that to the test code, because you're imagining splicing the 
> test body after the before exprs (because in your example, the before binds 
> an identifier.)
> 
> I really think you just want a slightly different test-case macro that does 
> exactly what you want.
> 
> (define-syntax-rule (brian-test-case label account . exprs)
>  (test-case label (define account (open-bank)) . exprs))
> 
> I really can't see the appeal of trying to push something into Rackunit that 
> can expand to what your example would do. It just seems so much more 
> complicated to implement and explain what it means than just putting in a one 
> line macro like this.
> 
> I feel that there is an analogy between `do`, `for`, and `let loop`. It is 
> definitely wise to not have to program every `for` loop explicitly with `let 
> loop`s, but trying to keep expanding the `for` macro to do more and more 
> towards the Lisp `do` macro is a bad move, IMHO, because it is so much more 
> complicated and non-orthogonal. It's better to make a test system that 
> integrates well with the rest of the language and to just use the language's 
> features for extensibility.
> 
> Jay
> 
> 
> On Tue, Mar 8, 2016 at 1:35 PM, Brian Adkins wrote:
> Not exactly. I'm looking for a way to run a function before *each*, of 
> possibly many, test-cases. The test-suite #:before only runs once before 
> running all the test-cases.
> 
> Although my gist: https://gist.github.com/lojic/db7016fb95b1c05e4ade 
>  only has a few 
> test-cases, if there were many, the redundancy of specifying the context each 
> time would be annoying.
> 
> What I'd really like is something similar to Elixir though, so I think I'll 
> code up that macro/function. It would be more functional to have each 
> test-case accept a context parameter, so you'd define a setup function that 
> returns a value that each test-case accepts as input.
> 
> It might look something like:
> 
> (test-suite
>   "my test suite"
>   #:setup (lambda () (open-bank))
> 
>   (test-case "initial balance is 0" account
> (check-eq? (balance account) 0))
> 
>   ...
> 
> So, the lambda specified in #:setup returns an object, account, that is 
> passed to each test-case.
> 
> I'll need to think of a reasonable syntax for it, but the idea is that each 
> test-case in a suite will have context created for it functionally.
> 
> 
> On Tuesday, March 8, 2016 at 1:17:53 PM UTC-5, Matthias Felleisen wrote:
> > Are you looking for something like this:
> >
> > #lang racket
> >
> > (require rackunit rackunit/text-ui)
> >
> > (define my-database #f)
> >
> > (define my-first-test-suite
> >   (test-suite
> >"An example suite"
> >#:before (lambda () (set! my-database '(a b c)) (displayln `(Before 
> > ,my-database)))
> >#:after  (lambda () (set! my-database #f)   (displayln `(Before 
> > ,my-database)))
> >(test-case
> > "An example test"
> > (check-eq? 1 1))
> >(test-suite "A nested test suite"
> >(test-case "Another test"
> >   (check-equal? 1 2)
> >
> >
> > Welcome to DrRacket, version 6.4.0.13--2016-03-04(-/f) [3m].
> > Language: racket.
> > > (run-tests my-first-test-suite)
> > (Before (a b c))
> > 
> > An example suite > A nested test suite > Another test
> > Another test
> > FAILURE
> > name:   check-equal?
> > location:   unsaved-editor:17:26
> > actual: 1
> > expected:   2
> > . Check failure
> > 
> > (Before #f)
> > 1 success(es) 1 failure(s) 0 error(s) 2 test(s) run
> > 1
> >
> >
> >
> > On Mar 8, 2016, at 1:14 PM, Brian Adkins wrote:
> >
> > > Jay:
> > >
> > > Here's a gist: https://gist.github.com/lojic/db7016fb95b1c05e4ade 
> > > 
> > >
> > > without.rkt is how I coded it up and with.rkt is how I'd like to be able 
> > > to code it.
> > >
> > > I agree that it's trivial to add, but for something as common as "setup" 
> > > and "teardown" for unit testing, there may be an advantage to having it 
> > > in RackUnit. When it comes down to it, test-case, check-equal, etc. 
> > > aren't hard to add either, but why should we all implement those.
> > >
> > > Brian
> > >
> > > On Tuesday, March 8, 2016 at 12:49:21 PM UTC-5, Jay McCarthy wrote:
> > >> Hi Brian,
> > >>
> > >>
> > >> Can you explain what you want to write? Just imagine that the feature 
> > >> was already there... what do you want?
> > >>
> > >>
> > >> I think of Rackunit as a way of writing checks, so if I wanted to do 
> > >> what you're 

Re: [racket-users] Setup/teardown for unit testing

2016-03-09 Thread Sam Tobin-Hochstadt
I think having a built-in way to do something like this would be a
good thing, rather than having everyone write their own abstraction
for this. One way we've avoided divergence in the Racket community
despite Racket's flexibility is by building in the right abstractions
in core libraries. But I share Jay's worry about the code in your
gist.

Here are a few possible ways I think we could add per-test-case setup code:

1. Purely state-based. Add a `#:before-each` keyword, which defines an
expression to run before each test case. Then you'd write:

(let ([account #f])
  (test-suite #:before-each (set! account (open-bank))
 (test-case (check-= (balance account 0))
  ...)))

2. Parameter-passing, with an explicit lambda (could maybe make this a
keyword version of test-case as well):

 (test-suite #:before-each (open-bank)
 (test-case/param (lambda (balance) (check-= (balance account 0)))
  ...))

3. Parameter-passing, with a binding position in the macro (perhaps
using a keyword like #:param):

 (test-suite #:before-each (open-bank)
 (test-case #:param balance (check-= (balance account 0))
  ...))

Certainly 1 is the simplest to implement, but stateful test frameworks
seem quite unfortunate. 2 is also simple, but has a proliferation of
API surface.

Any other thoughts on which of these is preferable? I'm happy to
implement whichever solution seems best.

Sam


On Wed, Mar 9, 2016 at 10:53 AM, Jay McCarthy  wrote:
> I looked at the gist you posted. I don't think it is plausible for us to add
> something like that to the test code, because you're imagining splicing the
> test body after the before exprs (because in your example, the before binds
> an identifier.)
>
> I really think you just want a slightly different test-case macro that does
> exactly what you want.
>
> (define-syntax-rule (brian-test-case label account . exprs)
>  (test-case label (define account (open-bank)) . exprs))
>
> I really can't see the appeal of trying to push something into Rackunit that
> can expand to what your example would do. It just seems so much more
> complicated to implement and explain what it means than just putting in a
> one line macro like this.
>
> I feel that there is an analogy between `do`, `for`, and `let loop`. It is
> definitely wise to not have to program every `for` loop explicitly with `let
> loop`s, but trying to keep expanding the `for` macro to do more and more
> towards the Lisp `do` macro is a bad move, IMHO, because it is so much more
> complicated and non-orthogonal. It's better to make a test system that
> integrates well with the rest of the language and to just use the language's
> features for extensibility.
>
> Jay
>
>
> On Tue, Mar 8, 2016 at 1:35 PM, Brian Adkins  wrote:
>>
>> Not exactly. I'm looking for a way to run a function before *each*, of
>> possibly many, test-cases. The test-suite #:before only runs once before
>> running all the test-cases.
>>
>> Although my gist: https://gist.github.com/lojic/db7016fb95b1c05e4ade only
>> has a few test-cases, if there were many, the redundancy of specifying the
>> context each time would be annoying.
>>
>> What I'd really like is something similar to Elixir though, so I think
>> I'll code up that macro/function. It would be more functional to have each
>> test-case accept a context parameter, so you'd define a setup function that
>> returns a value that each test-case accepts as input.
>>
>> It might look something like:
>>
>> (test-suite
>>   "my test suite"
>>   #:setup (lambda () (open-bank))
>>
>>   (test-case "initial balance is 0" account
>> (check-eq? (balance account) 0))
>>
>>   ...
>>
>> So, the lambda specified in #:setup returns an object, account, that is
>> passed to each test-case.
>>
>> I'll need to think of a reasonable syntax for it, but the idea is that
>> each test-case in a suite will have context created for it functionally.
>>
>>
>> On Tuesday, March 8, 2016 at 1:17:53 PM UTC-5, Matthias Felleisen wrote:
>> > Are you looking for something like this:
>> >
>> > #lang racket
>> >
>> > (require rackunit rackunit/text-ui)
>> >
>> > (define my-database #f)
>> >
>> > (define my-first-test-suite
>> >   (test-suite
>> >"An example suite"
>> >#:before (lambda () (set! my-database '(a b c)) (displayln `(Before
>> > ,my-database)))
>> >#:after  (lambda () (set! my-database #f)   (displayln `(Before
>> > ,my-database)))
>> >(test-case
>> > "An example test"
>> > (check-eq? 1 1))
>> >(test-suite "A nested test suite"
>> >(test-case "Another test"
>> >   (check-equal? 1 2)
>> >
>> >
>> > Welcome to DrRacket, version 6.4.0.13--2016-03-04(-/f) [3m].
>> > Language: racket.
>> > > (run-tests my-first-test-suite)
>> > (Before (a b c))
>> > 
>> > An example suite > A nested test suite > Another test
>> > Another test
>> > FAILURE
>> > name:   check-equal?
>> > location:   

Re: [racket-users] Webserver returns page on ajax get request, but not ajax post

2016-03-09 Thread Jay McCarthy
On Sat, Feb 27, 2016 at 5:38 PM, Marc Kaufmann 
wrote:

> As we are on it, is there a way to have `dispatch-rules work on url's with
> regular expressions, so that it would work on ajax1, ajax2, etc, or would I
> have to create my own bi-directional match-expander for that? (I haven't
> tried to figure out how that would work though.) The reason I ask is that
> when sending bindings in the url,  'dispatch-rules chokes, since the url
> looks different. An alternative is to use continuations, and pass the url
> for the continuation into javascript.
>

There is no regular expression bidi-matcher, but you could make one. You'd
have to make the to-url side take in a string and check that it matches the
regexp. However, I'm a little skeptical. What's wrong with using strings,
numbers, etc? You just don't want to have /s separate the pieces, you want
some other character to separate the pieces in the encoding?

Jay


>
> On Sat, Feb 27, 2016 at 3:04 PM, Jay McCarthy 
> wrote:
>
>> Hi Marc,
>>
>> Each `dispatch-rules` rule takes a keyword option for which methods
>> you want it to handle, the default being no method and "get". So your
>> call is equivalent to
>>
>> [("test-ajax") #:method "get" ajax]
>>
>> but you want
>>
>> [("test-ajax") #:method "put" ajax]
>>
>> This facilitates more easily having different functions for different
>> methods.
>>
>> Jay
>>
>>
>> On Sat, Feb 27, 2016 at 1:03 PM, Marc Kaufmann
>>  wrote:
>> > Hi all,
>> >
>> > I perform the following call in jQuery in a page:
>> >
>> > $.post( "test-ajax",
>> > function( data ) {
>> > alert( "Data Loaded: " + data);
>> > });
>> >
>> >
>> > The test-ajax page gets called via the url-dispatcher:
>> >
>> >   (define-values (site-dispatch site-url)
>> >  (dispatch-rules
>> >...
>> >[("test-ajax") ajax]))
>> >
>> > and the ajax function is simply this:
>> >
>> >   (define (ajax req)
>> > (response/xexpr
>> > "1 "))
>> >
>> > Nonetheless, the above Ajax call fails with a 404 error, but when I
>> replace
>> > $.post by $.get, it works. As far as I can tell, the only thing about
>> the
>> > request this changes it the method, from POST to GET.
>> >
>> > Is there a reason this fails? Do I need to tell the webserver that it
>> should
>> > serve both POST and GET?
>> >
>> > Btw, the reason I want to use post is that when I use get, the data I
>> send
>> > with the request gets put at the end of the url
>> (../test-ajax?some-binding)
>> > and I couldn't figure out how to have the dispatcher deal with this
>> problem
>> > (that returned an error 500).
>> >
>> > Thanks,
>> >
>> > Marc
>> >
>> >
>> >
>> >
>> >
>> > --
>> > 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.
>>
>>
>>
>> --
>> Jay McCarthy
>> Associate Professor
>> PLT @ CS @ UMass Lowell
>> http://jeapostrophe.github.io
>>
>>"Wherefore, be not weary in well-doing,
>>   for ye are laying the foundation of a great work.
>> And out of small things proceedeth that which is great."
>>   - D 64:33
>>
>
>


-- 
Jay McCarthy
Associate Professor
PLT @ CS @ UMass Lowell
http://jeapostrophe.github.io

   "Wherefore, be not weary in well-doing,
  for ye are laying the foundation of a great work.
And out of small things proceedeth that which is great."
  - D 64:33

-- 
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] Standard web server interface?

2016-03-09 Thread Jay McCarthy
I agree with Sam. The Racket way to do something like this is to have
standard types and function signatures. Roughly that means using the
web-server/http structures for requests and responses and modeling servers
as `request -> response`. A few of the internals of the Web server also
have `request x connection -> void` functions where you can directly write
to the connection, but I think this was a mistake and I should have made
the `response`s more powerful earlier to not need that.

Jay

On Thu, Mar 3, 2016 at 12:51 PM, Sam Tobin-Hochstadt 
wrote:

> On Thu, Mar 3, 2016 at 12:23 PM, Brian Adkins 
> wrote:
> > On Thursday, March 3, 2016 at 12:15:27 PM UTC-5, antoine wrote:
> >> There is the fastcgi protocol http://www.fastcgi.com/drupal/ (maybe it
> >> is underlying rack and wsgi).
> >> I have done basic tests with it:
> >> http://antoineb.github.io/blog/2015/06/02/basic-fastcgi-with-racket/
> >>
> >> I haven't found any racket implementation so far.
> >>
> >> On 03/03/2016 04:16 PM, Brian Adkins wrote:
> >> > Is there anything analogous to Rack (Ruby) or WSGI (Python), i.e. a
> standard protocol between web servers and web applications, in the Racket
> world?
> >> >
> >> > http://rack.github.io/
> >> >
> >> > https://www.python.org/dev/peps/pep-/#abstract
> >> >
> >> > Thanks,
> >> > Brian
> >> >
> >
> > Ah, I remember fastcgi from the early, and painful, days of Rails
> deployments - I don't want to go back to that :)
> >
> > IIRC fastcgi is more about the protocol between a front end web server
> and an application server it's proxying to. I'm referring to the
> intra-process interface between the code handling the low level http
> protocol and the higher level application.
> >
> > In the Ruby world this would be the interface between Unicorn, Puma,
> Passenger, etc. and a Rails application.
> >
> > Rack wasn't available for early releases of Rails, so it's not something
> I *need*, but I also didn't want to be unaware of something that's
> fulfilling that role.
>
> Jay would be able to say more, but there isn't something explicitly
> like Rack in the Racket web server.
>
> Roughly, the `serve/servlet` function talks directly to the web-server
> implementation, and the servlet interface is just a `request ->
> response` function. You could layer things by composing those
> functions -- I think that would be the most Rack-like thing currently.
>
> Sam
>
> --
> 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.
>



-- 
Jay McCarthy
Associate Professor
PLT @ CS @ UMass Lowell
http://jeapostrophe.github.io

   "Wherefore, be not weary in well-doing,
  for ye are laying the foundation of a great work.
And out of small things proceedeth that which is great."
  - D 64:33

-- 
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] Setup/teardown for unit testing

2016-03-09 Thread Jay McCarthy
I looked at the gist you posted. I don't think it is plausible for us to
add something like that to the test code, because you're imagining splicing
the test body after the before exprs (because in your example, the before
binds an identifier.)

I really think you just want a slightly different test-case macro that does
exactly what you want.

(define-syntax-rule (brian-test-case label account . exprs)
 (test-case label (define account (open-bank)) . exprs))

I really can't see the appeal of trying to push something into Rackunit
that can expand to what your example would do. It just seems so much more
complicated to implement and explain what it means than just putting in a
one line macro like this.

I feel that there is an analogy between `do`, `for`, and `let loop`. It is
definitely wise to not have to program every `for` loop explicitly with
`let loop`s, but trying to keep expanding the `for` macro to do more and
more towards the Lisp `do` macro is a bad move, IMHO, because it is so much
more complicated and non-orthogonal. It's better to make a test system that
integrates well with the rest of the language and to just use the
language's features for extensibility.

Jay


On Tue, Mar 8, 2016 at 1:35 PM, Brian Adkins  wrote:

> Not exactly. I'm looking for a way to run a function before *each*, of
> possibly many, test-cases. The test-suite #:before only runs once before
> running all the test-cases.
>
> Although my gist: https://gist.github.com/lojic/db7016fb95b1c05e4ade only
> has a few test-cases, if there were many, the redundancy of specifying the
> context each time would be annoying.
>
> What I'd really like is something similar to Elixir though, so I think
> I'll code up that macro/function. It would be more functional to have each
> test-case accept a context parameter, so you'd define a setup function that
> returns a value that each test-case accepts as input.
>
> It might look something like:
>
> (test-suite
>   "my test suite"
>   #:setup (lambda () (open-bank))
>
>   (test-case "initial balance is 0" account
> (check-eq? (balance account) 0))
>
>   ...
>
> So, the lambda specified in #:setup returns an object, account, that is
> passed to each test-case.
>
> I'll need to think of a reasonable syntax for it, but the idea is that
> each test-case in a suite will have context created for it functionally.
>
>
> On Tuesday, March 8, 2016 at 1:17:53 PM UTC-5, Matthias Felleisen wrote:
> > Are you looking for something like this:
> >
> > #lang racket
> >
> > (require rackunit rackunit/text-ui)
> >
> > (define my-database #f)
> >
> > (define my-first-test-suite
> >   (test-suite
> >"An example suite"
> >#:before (lambda () (set! my-database '(a b c)) (displayln `(Before
> ,my-database)))
> >#:after  (lambda () (set! my-database #f)   (displayln `(Before
> ,my-database)))
> >(test-case
> > "An example test"
> > (check-eq? 1 1))
> >(test-suite "A nested test suite"
> >(test-case "Another test"
> >   (check-equal? 1 2)
> >
> >
> > Welcome to DrRacket, version 6.4.0.13--2016-03-04(-/f) [3m].
> > Language: racket.
> > > (run-tests my-first-test-suite)
> > (Before (a b c))
> > 
> > An example suite > A nested test suite > Another test
> > Another test
> > FAILURE
> > name:   check-equal?
> > location:   unsaved-editor:17:26
> > actual: 1
> > expected:   2
> > . Check failure
> > 
> > (Before #f)
> > 1 success(es) 1 failure(s) 0 error(s) 2 test(s) run
> > 1
> >
> >
> >
> > On Mar 8, 2016, at 1:14 PM, Brian Adkins wrote:
> >
> > > Jay:
> > >
> > > Here's a gist: https://gist.github.com/lojic/db7016fb95b1c05e4ade
> > >
> > > without.rkt is how I coded it up and with.rkt is how I'd like to be
> able to code it.
> > >
> > > I agree that it's trivial to add, but for something as common as
> "setup" and "teardown" for unit testing, there may be an advantage to
> having it in RackUnit. When it comes down to it, test-case, check-equal,
> etc. aren't hard to add either, but why should we all implement those.
> > >
> > > Brian
> > >
> > > On Tuesday, March 8, 2016 at 12:49:21 PM UTC-5, Jay McCarthy wrote:
> > >> Hi Brian,
> > >>
> > >>
> > >> Can you explain what you want to write? Just imagine that the feature
> was already there... what do you want?
> > >>
> > >>
> > >> I think of Rackunit as a way of writing checks, so if I wanted to do
> what you're talking about, then I'd define the macro/function that you
> don't want to. In other words, with Rackunit, you are just writing a
> program and it provides a way to keep track of and print out individual
> tests, so all the features of Racket are there for writing that program.
> There's no reason to add functions, dynamic-wind, and begin blocks to
> Rackunit, because they're already in Racket. For instance, my tests look
> like
> > >>
> > >>
> > >> (define f )
> > >> (module+ test
> > >>  (check-equal? (f ) 

Re: [racket-users] [Redex] "Got nothing"

2016-03-09 Thread Anton Podkopaev
Dear Robby,

Thank you. Yes, the cycles were a problem.

BR,
Anton Podkopaev
podkopaev.net

On Wed, Mar 9, 2016 at 1:50 AM, Robby Findler 
wrote:

> It is possible you're using the #:cycles-ok argument, as in the
> program below? If so, that means that the reduction graph has no
> irreducible terms. So you would need to pass no "expected" arguments
> to test-->> in order for the test case to pass.
>
> Robby
>
> #lang racket
> (require redex/reduction-semantics)
>
> (define-language L
>   (e ::= (loop)))
>
> (define red
>   (reduction-relation
>L
>(--> (loop) (loop
>
> (test-->> red #:cycles-ok (term (loop)) 5)
>
>
> On Tue, Mar 8, 2016 at 12:03 PM, Anton Podkopaev 
> wrote:
> > Dear colleagues,
> >
> > I'm working on a semantics using Redex.
> > I've got a strange message from "test-->>" function --- "got nothing".
> > It is strange, because a term, which I run "test-->>" on, definitely can
> be
> > reduced.
> > For example, I can see lots of its productions in "traces" or "stepper".
> >
> > My assumption, that in Redex there is some bound (parameter?) on how many
> > productions in a trace chain can be. Am I right? Unfortunately, I failed
> to
> > find
> > corresponding information in the Redex reference.
> >
> > BR,
> > Anton Podkopaev
> > podkopaev.net
> >
> > --
> > 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.