Hi all,
Newbie to Lisp here, just reading Graham's On Lisp and trying some
stuff out. I'm working with Drakma, and a call to GET a web-page looks
almost identical to a POST:
(http-request uri
:method :get
:cookie-jar *cookie-container*
:user-agent *user-agent*)
(http-request uri
:method :post
:cookie-jar *cookie-container*
:user-agent *user-agent*)
Now, I've written a simple macro when I can call with (gen-
request :get) and it'll return the above body. But could I do this
with a function? I've tried, but can't figure out how to pass :get as
an arg.
What data type are things like :post or :get exactly? I thought :foo
bla mean that a variable called foo would be bound to bla? Is :get a
keyword in that context?
Sorry if this strikes anyone as a stupid question. But if I can at
least find out the proper nomenclature for the :get type arguments, I
can start Googling them.
Regards,
Liam Clarke
On Mon, 16 Apr 2007 01:18:08 -0700, ··········@gmail.com wrote:
> (http-request uri
> :method :get
> :cookie-jar *cookie-container*
> :user-agent *user-agent*)
>
> (http-request uri
> :method :post
> :cookie-jar *cookie-container*
> :user-agent *user-agent*)
>
> Now, I've written a simple macro when I can call with (gen-request
> :get) and it'll return the above body. But could I do this with a
> function? I've tried, but can't figure out how to pass :get as an arg.
Just pass it like anything else:
(defun hrequest (method uri)
(http-request uri
:method method
:cookie-jar *cookie-container*
:user-agent *user-agent*))
Later on you might want to pass some custom arguments
on to http-request via your wrapper function:
(defun hrequest2 (method uri &rest extra-args)
(apply #'http-request uri
:method method
:cookie-jar *cookie-container*
:user-agent *user-agent*
extra-args))
That way you can do:
(hrequest2 :post "blah.org" :parameters '(("id" . "1234")
("value" . "blah")))
..that is, use any of the &key arguments:
http://weitz.de/drakma/#http-request
--
Lars Rune Nøstdal
http://nostdal.org/
From: Edi Weitz
Subject: Re: Am I using a macro where a function would do?
Date:
Message-ID: <u3b30ybfz.fsf@agharta.de>
On 16 Apr 2007 01:18:08 -0700, ···········@gmail.com" <··········@gmail.com> wrote:
> Newbie to Lisp here, just reading Graham's On Lisp and trying some
> stuff out.
If you are new to Lisp, you should /not/ start with "On Lisp" (which
is a good book, but only really useful for advanced readers). I'd
recommend to start with this one:
http://www.gigamonkeys.com/book/
> I'm working with Drakma, and a call to GET a web-page looks almost
> identical to a POST:
>
> (http-request uri
> :method :get
> :cookie-jar *cookie-container*
> :user-agent *user-agent*)
>
> (http-request uri
> :method :post
> :cookie-jar *cookie-container*
> :user-agent *user-agent*)
>
> Now, I've written a simple macro when I can call with (gen- request
> :get) and it'll return the above body. But could I do this with a
> function?
Yes, there's absolutely no need to use a macro here.
> I've tried, but can't figure out how to pass :get as an arg.
>
> What data type are things like :post or :get exactly? I thought :foo
> bla mean that a variable called foo would be bound to bla? Is :get a
> keyword in that context?
>
> Sorry if this strikes anyone as a stupid question. But if I can at
> least find out the proper nomenclature for the :get type arguments,
> I can start Googling them.
:GET is a "keyword" - see for example here:
http://www.lispworks.com/documentation/HyperSpec/Body/t_kwd.htm
http://www.gigamonkeys.com/book/programming-in-the-large-packages-and-symbols.html
HTH,
Edi.
--
Lisp is not dead, it just smells funny.
Real email: (replace (subseq ·········@agharta.de" 5) "edi")
On Apr 16, 8:23 pm, Edi Weitz <········@agharta.de> wrote:
> On 16 Apr 2007 01:18:08 -0700, ···········@gmail.com" <··········@gmail.com> wrote:
>
> > Newbie to Lisp here, just reading Graham's On Lisp and trying some
> > stuff out.
>
> If you are new to Lisp, you should /not/ start with "On Lisp" (which
> is a good book, but only really useful for advanced readers). I'd
> recommend to start with this one:
>
> http://www.gigamonkeys.com/book/
>
Thanks Edi, you're right - I should probably grasp the basics before
getting too indepth... like how a symbol is represented. >_<
>
> > I'm working with Drakma, and a call to GET a web-page looks almost
> > identical to a POST:
>
> > (http-request uri
> > :method :get
> > :cookie-jar *cookie-container*
> > :user-agent *user-agent*)
>
> > (http-request uri
> > :method :post
> > :cookie-jar *cookie-container*
> > :user-agent *user-agent*)
>
> > Now, I've written a simple macro when I can call with (gen- request
> > :get) and it'll return the above body. But could I do this with a
> > function?
>Yes, there's absolutely no need to use a macro here.
Yeah... I was misinterpreting an error meesage and jumped to a
conclusion. Thanks for the correction.
Regards,
Liam Clarke