unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Brian S McQueen <bqueen@nas.nasa.gov>
Subject: Re: list building and argz_smob
Date: Mon, 9 Feb 2004 10:07:07 -0800 (PST)	[thread overview]
Message-ID: <Pine.GSO.4.58.0402090919280.18897@marcy.nas.nasa.gov> (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


             reply	other threads:[~2004-02-09 18:07 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-02-09 18:07 Brian S McQueen [this message]
2004-02-09 18:41 ` list building and argz_smob Paul Jarc
2004-02-09 18:51   ` Paul Jarc
2004-02-09 19:49   ` Thien-Thi Nguyen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.GSO.4.58.0402090919280.18897@marcy.nas.nasa.gov \
    --to=bqueen@nas.nasa.gov \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).