[racket] passing a list of dispatch clauses to dispatch-rules
Thanks Jay, your explanation with match helped me get a better
understanding of what's going on.
For the specific case of match, you can make the b-helper example work if
you pass the failure procedure to b-helper and have b-helper return it:
(define (b in)
(match in
[x (=> failure-proc)
(b-helper x failure-proc)]
["home"
"It's home!"]
[_
"Unknown"]))
(define (b-helper x fp)
(define y (string->number x))
(if y
y
(fp)))
(module+ test
(require rackunit)
(check-equal? (b "4") 4)
(check-equal? (b "home") "It's home!")
(check-equal? (b "five") "Unknown"))
But I don't think there's a way to do this with dispatch-url because afaik
it doesn't give you the option of specifying a failure procedure. So, what
you suggested in terms of using serve/launch/wait, dispatch sequencer and
dispatch servlet looks like the way to do it if I was set on a particular
sequence (which for the time being I'm not).
Tobias
On 18 December 2013 09:56, Jay McCarthy <jay.mccarthy at gmail.com> wrote:
> There's an annoying terminological problem.
>
> The core Web server has a concept of a dispatcher sequence and
> (next-dispatcher) jumps to the next of those. The web-server/dispatch
> library helps you write a function that does pattern matching on the
> URL of a request. What you want is that after you take a branch in
> that function, you'd like to have the branch fail and then the pattern
> matching try again.
>
> racket/match [which web-server/dispatch is built on] supports
> something like that:
>
> (define (a in)
> (match in
> [x
> (define y (string->number x))
> (if y
> y
> (failure-cont))]
> ["home"
> "It's home!"]
> [_
> "Unknown"]))
>
> (module+ test
> (require rackunit)
> (check-equal? (a "4") 4)
> (check-equal? (a "home") "It's home!")
> (check-equal? (a "five") "Unknown"))
>
> But the use of (failure-cont) has to be syntactically within the
> match, i.e. the following does not work:
>
> (define (b-helper x)
> (define y (string->number x))
> (if y
> y
> (failure-cont)))
>
> (define (b in)
> (match in
> [x
> (b-helper y)]
> ["home"
> "It's home!"]
> [_
> "Unknown"]))
>
> If you really need to sequence them this way, then you could use
>
> 1. serve/launch/wait
> 2. sequence dispatcher
> 3. dispatch/servlet handling files
> 4. and then dispatch/servlet handling everything else
>
> So that the (next-dispatcher) in step 3 jumped to step 4.
>
> Jay
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20131218/376e6786/attachment.html>