unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Re: list building and argz_smob
@ 2004-02-09 18:07 Brian S McQueen
  2004-02-09 18:41 ` Paul Jarc
  0 siblings, 1 reply; 4+ messages in thread
From: Brian S McQueen @ 2004-02-09 18:07 UTC (permalink / raw)


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
argz_smob.

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"
        (list
          (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" ))
             "no_nop_item")
          (check-old-data pref-login)
          (selected-groups pref-login)
          (get-data pref-login)
          (all-groups)
          "devel_name=\"Brian McQueen\""
          "devel_email=\"bqueen@nas.nasa.gov\"" ))

Argz:

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
list.

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_map(
   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.

Brian


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2004-02-09 19:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-02-09 18:07 list building and argz_smob Brian S McQueen
2004-02-09 18:41 ` Paul Jarc
2004-02-09 18:51   ` Paul Jarc
2004-02-09 19:49   ` Thien-Thi Nguyen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).