The dispatch pattern is special syntax, not an expression, so you need to write a macro. To get started,
(define-syntax-rule (add-route route method proc) (dispatch-rules! main-container [route #:method method (proc)])) would work. You can get better error reporting if you use syntax-parse. Also, I suspect you really mean to have proc, not (proc), in the body -Philip On Fri, Jun 2, 2017 at 1:58 PM, Zelphir Kaltstahl < zelphirkaltst...@gmail.com> wrote: > Thanks again, I think I got how to use it now. > > Here is my example: > > (define-container main-container (hsk-dispatch a-url)) > (dispatch-rules! main-container > [("") #:method "get" overview-app]) > (dispatch-rules! main-container > [("index") #:method "get" overview-app]) > (dispatch-rules! main-container > [("home") #:method "get" overview-app]) > (dispatch-rules! main-container > [("hsk") #:method "get" hsk-app]) > > I define a container, for the purpose of later adding dispatch rules to > it. That is what I do immediately afterwards. That would be no different to > what I had before with the safe dispatch-rules procedure. However, now I > can at any time add more rules to the container. Before, I did not define a > container, so I was not able to add any dispatch rules to anything. Correct? > > I could now probably (require ...) the part of Racket's web server which > (provide ...)s the (dispatch-rules! ...) procedure wherever else in the > code I need it to add rules dynamically. > > However, to refine the process of adding dispatch rules in my code, I'd > like to do one more thing: I'd like to write a procedure, which looks as > follows: > > (define (add-route route method proc) > (dispatch-rules! main-container > [route #:method method (proc)])) > > If I had such a procedure, I could provide that to other modules, which > require my server module and I would not have to require Racket's web > server in these other modules. > > According to the documentation a dispatch-pattern, which I called "route" > in my (add-route ...) procedure, is either () or (string . > dispatch-pattern) or something else. When I define a dispatch rule, I > simply put parentheses around multiple strings in the call of > dispatch-rules. However, when I do that in the REPL, it gives an error, > because it is not a valid expression on its own. > > Now I would like to know how I can pass a dispatch-pattern to a procedure > and then in that procedure pass it to (dispatch-rules! ...). > > -- > 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.