<div dir="ltr"><div><div><div><div><div>OK, here come some more silly questions...<br><br>I tried using (string-arg) and (next-dispatcher) like this:<br><br><span style="font-family:courier new,monospace">(define-values (blog-dispatch blog-url)<br>

  (dispatch-rules<br>   [((string-arg)) <b>first-request-handler</b>]<br>   [("") list-posts]<br>   [("posts" (string-arg)) review-post]<br>   [("archive" (integer-arg) (integer-arg)) review-archive]<br>

   [else list-posts]))<br><br>(define (<b>first-request-handler</b> req a-string) (<b>next-dispatcher</b>))<br>(define (list-posts req) `(list-posts))<br>(define (review-post req p) `(review-post ,p))<br>(define (review-archive req y m) `(review-archive ,y ,m))<br>

<br></span></div>But when next-dispatcher runs it gives rise to an uncaught exception. So, I guess what's going on is that (next-dispatcher) exits the blog-dispatch call entirely and looks for another dispatcher, rather than just the next matching clause in the dispatch rules of blog-dispatch.<br>

<br>So then I thought what I need must be the dispatch sequencer. So I tried this:<br></div><span style="font-family:courier new,monospace"></span><br><span style="font-family:courier new,monospace">(require web-server/dispatchers/dispatch-sequencer)<br>

<br>(define-values (first-dispatcher first-url-gen)<br>  (dispatch-rules<br>   [((string-arg)) first-request-handler]))<br><br>(define-values (second-dispatcher second-url-gen)<br>  (dispatch-rules<br>   [("") list-posts]<br>

   [("posts" (string-arg)) review-post]<br>   [("archive" (integer-arg) (integer-arg)) review-archive]<br>   [else list-posts]))<br><br>(define master-dispatcher <br>  (make first-dispatcher<br>        second-dispatcher))</span><br>

<br></div>But this raises a contract violation, because "make" expects dispatchers as its arguments, and first-dispatcher and second-dispatcher aren't truly dispatchers. A dispatcher takes a connection and a request as arguments, whereas first-dispatcher and second-dispatcher only take a request as their argument. <br>

<br>So, I need to do something to build first-dispatcher and second-dispatcher into proper dispatchers, but I'm not sure what. The web-server/dispatchers/dispatch-lift module looks like it might do the trick but then I get a conflicting definition of "make". <br>

<br></div>Any help much appreciated! <br><br>This thread from September looks like it's addressing a similar sort of issue:<br><a href="http://lists.racket-lang.org/users/archive/2013-September/059728.html">http://lists.racket-lang.org/users/archive/2013-September/059728.html</a><br>

</div><div>... but I still don't understand how to construct a "next dispatcher" that (next-dispatcher) will call.<br></div><div><br></div>Tobias<br><br><br></div><div class="gmail_extra"><br><br><div class="gmail_quote">

On 16 December 2013 22:44, Jay McCarthy <span dir="ltr"><<a href="mailto:jay.mccarthy@gmail.com" target="_blank">jay.mccarthy@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div class="im">On Mon, Dec 16, 2013 at 3:25 PM, Janos Tobias Locsei<br>
<<a href="mailto:jtlocsei@cantab.net">jtlocsei@cantab.net</a>> wrote:<br>
> Hi, I'm a newbie Racketeer so apologies if this is a silly question:<br>
><br>
> Is it possible to pass a list of dispatch-clause to dispatch-rules? Naive<br>
> use of "apply" doesn't work:<br>
><br>
> (define-values (blog-dispatch blog-url)<br>
>   (let ([arglist<br>
>          (list<br>
>             [("") list-posts]<br>
>             [("posts" (string-arg)) review-post]<br>
>             [("archive" (integer-arg) (integer-arg)) review-archive]<br>
>             [else list-posts])])<br>
>     (apply dispatch-rules arglist)))<br>
<br>
</div>dispatch-rules is a macro, so it cannot be "apply"d<br>
<div class="im"><br>
> (example modified from <a href="http://docs.racket-lang.org/web-server/dispatch.html" target="_blank">docs.racket-lang.org/web-server/dispatch.html</a>) This<br>
> code gives rise to the error<br>
><br>
> string-arg: this match expander must be used inside match in: (string-arg)<br>
<br>
</div>This error happens before you try to apply, beucase (string-arg) can<br>
only be used inside of a dispatch case expression.<br>
<div class="im"><br>
> Maybe there's something clever I could do with delay and force, but I'm not<br>
> very familiar with how they work...<br>
><br>
> Background: the reason I want to do this is so that I can dynamically<br>
> construct a list of all the filenames in a directory of static html files<br>
> and make dispatch clauses so that they can be accessed at URL's without<br>
> ".html" on the end.<br>
<br>
</div>If you want it truly dynamic on every request, then I would just catch<br>
[(string-arg) ...] and in the handler throw next-dispatcher if the<br>
string doesn't correspond to a file.<br>
<br>
Jay<br>
<div class="im"><br>
><br>
> Thanks in advance for any guidance!<br>
><br>
> Tobias<br>
><br>
</div>> ____________________<br>
>   Racket Users list:<br>
>   <a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
><br>
<span class="HOEnZb"><font color="#888888"><br>
<br>
<br>
--<br>
Jay McCarthy <<a href="mailto:jay@cs.byu.edu">jay@cs.byu.edu</a>><br>
Assistant Professor / Brigham Young University<br>
<a href="http://faculty.cs.byu.edu/~jay" target="_blank">http://faculty.cs.byu.edu/~jay</a><br>
<br>
"The glory of God is Intelligence" - D&C 93<br>
</font></span></blockquote></div><br></div>