Arc Forumnew | comments | leaders | submitlogin
2 points by akkartik 3641 days ago | link | parent

defop is a macro that doesn't evaluate its first arg. So your question is similar to asking why this doesn't bind y to 34:

  (let x 'y
    (= x 34))
To do what you want you'll need to define the url directly. The definition of defop (approximately, after dropping some indirections) is:

  (mac defop (name parms . body)
    `(= (srvops* ',name)
        (fn ,parms
          ,@body)))
So you can do:

  (let url "hello"
    (= (srvops* sym.url)
       (fn (output req)
         (w/stdout output
           (prrn)
           (pr "hello world")))))
There's a few extra details here. You have to work through the details of how defop is defined. Feel free to ask more questions if something is unclear.


2 points by bh 3641 days ago | link

Thanks, I got it. Also, is there a way to catch all requests?

-----

1 point by akkartik 3641 days ago | link

Can you elaborate? You want to call the same function on any request, and pass in the url from the request? Are you using arc 3.1 or anarki?

Edit: on anarki you get this behavior by replacing the function respond in lib/srv.arc with this code:

  (def respond (out req)
    (w/stdout out
      (prrn "HTTP/1.1 200 OK")
      (prrn "Content-Type: text/html; charset=utf-8")
      (prrn "Connection: close")
      (prrn)
      (wildcard-handler req)))

  (def wildcard-handler (req)
    (prn req!op))
This will display whatever op you request.

-----