[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: list building and argz_smob

From: Brian S McQueen
Subject: Re: list building and argz_smob
Date: Mon, 9 Feb 2004 10:07:07 -0800 (PST)

I wanted to update folks on the results of applying the advice you all
supplied a few weeks back, when I asked about list buildingand about an

List Building:

I was building an output-list adding data as needed.  cons* was one of the
suggestions of the folks on this list.  Well after implementing this cons*
approach, and gaining some more insight into the functional approach to
programming, I found there was no need for incremental assembling of a
global list.  In fact in the end I didn't even need the cons*.  The
program is much better now.  I eliminated the global list and eliminated
the clumsy list assembly process.  The final result is like this:

     (nop-printer "full_form"
          (string-append "pref_login=\"" pref-login "\"")
          (if cgi-http-cookie
            (let ((nop-item (cgi:cookie "nop_item")))
              (if nop-item
                (string-append "nop_item=\"" (frobnicate nop-item)
                "no_nop_item" ))
          (check-old-data pref-login)
          (selected-groups pref-login)
          (get-data pref-login)
          "devel_name=\"Brian McQueen\""
          "devel_email=\"address@hidden"" ))


This approach obviously produces a SCM list and hands it to a printer.
This is where I had used the argz_smob before.  I had a few db libs around
which used argzs.  After some thinking I found an argz can be treated
exactly like a SCM string, so I eliminated the argz_smob.  Though thats
not all.  I was going through some trouble to join the above SCM list into
a single massive SCM string, creating one massive argz, then the SCM
string containing the argz was passed to the C printer which handled it as
a single argz.  This was a very clumsy and annoying approach, and as you
can see from the above sample, I found a better way to handle the SCM

Turning the list into string was really bad, so I pondered this for a
while and noticed I could use the scm list handlers via calls from the C
world. So I decided to pass the SCM list directly to the C world which
then handles the SCM list, in fact by calling scm_map.  So finally the C
is very simple and it does itz argz handling in a one liner of C code!
It is very simple:

   scm_c_define_gsubr("anon-printer", 1, 0, 0, private_printer),
      argz_list_scm, SCM_EOL);

This one liner goes over each argz in the incoming list and prints it.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]