unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Paul Smith <psmith@gnu.org>
To: Thien-Thi Nguyen <ttn@gnuvola.org>
Cc: guile-user@gnu.org
Subject: Re: Using guile as an extension language for GNU  make
Date: Sun, 18 Sep 2011 15:28:00 -0400	[thread overview]
Message-ID: <1316374080.28907.163.camel@homebase> (raw)
In-Reply-To: <87wrd5x404.fsf@ambire.localdomain>

On Sun, 2011-09-18 at 17:30 +0200, Thien-Thi Nguyen wrote:
> The double-quote stripping is kind of hacky.  I would create a port
> and ‘display’ the result of ‘scm_c_eval_string’ to it.

Thanks for the hints.  I've reworked my code to implement a generic "SCM
to make string" function; currently it looks like this:

        char *
        cvt_scm_to_str (SCM obj)
        {
          char *str;
        
          if (scm_is_bool (obj) && scm_is_true (obj))
            str = xstrdup ("t");
          else if (scm_is_number (obj) || scm_is_string (obj) || scm_is_symbol (obj))
            {
              SCM port = scm_open_output_string ();
        
              scm_display (obj, port);
              str = scm_to_locale_string (scm_get_output_string (port));
              scm_close_output_port (port);
            }
          else
            str = xstrdup ("");
        
          return str;
        }

That's better than what I had before, but I still have some concerns.
For example, what if a Guile call wanted to return a list?  I can use
display as above, but the list will be enclosed in parentheses, which is
not how make displays lists.  Is there a clean way to handle this?  I
could write a function then invoke it with scm_map() (right?) but this
seems like it might be work.  Also what if the data structure is more
complex, where some elements of the list are lists themselves, etc.?  I
can "flatten" the entire thing out, I suppose.

Or I could ignore them as above and require the Guile scripting to
convert the list into a string before returning it.

-- 
-------------------------------------------------------------------------------
 Paul D. Smith <psmith@gnu.org>          Find some GNU make tips at:
 http://www.gnu.org                      http://make.mad-scientist.net
 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist




  reply	other threads:[~2011-09-18 19:28 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-18  0:10 Using guile as an extension language for GNU make Paul Smith
2011-09-18 12:10 ` Ludovic Courtès
2011-09-18 17:21   ` Embedding vs. Extending (was: Re: Using guile as an extension language for GNU make) Paul Smith
2011-09-18 21:48     ` Embedding vs. Extending Ludovic Courtès
2011-09-18 17:42   ` Using guile as an extension language for GNU make Paul Smith
2011-09-18 21:28     ` Ludovic Courtès
2011-09-18 15:30 ` Thien-Thi Nguyen
2011-09-18 19:28   ` Paul Smith [this message]
2011-09-19  0:28     ` Thien-Thi Nguyen
2011-09-19 15:14       ` Paul Smith
2011-09-19 19:41         ` Hans Aberg
2011-09-19 21:56           ` Paul Smith
2011-09-19 22:35             ` Hans Aberg
2011-09-19 23:00             ` Hans Aberg
2011-09-21  2:42             ` Mark H Weaver
2011-09-21  8:24               ` Hans Aberg
2011-09-20 16:17         ` Thien-Thi Nguyen
2011-09-20 17:31           ` Paul Smith
2011-09-20 19:02             ` Paul Smith
2011-09-21  0:48               ` Thien-Thi Nguyen
2011-09-20 20:39             ` 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=1316374080.28907.163.camel@homebase \
    --to=psmith@gnu.org \
    --cc=guile-user@gnu.org \
    --cc=ttn@gnuvola.org \
    /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).