unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Thien-Thi Nguyen <ttn@gnuvola.org>
To: psmith@gnu.org
Cc: guile-user@gnu.org
Subject: Re: Using guile as an extension language for GNU  make
Date: Tue, 20 Sep 2011 22:39:43 +0200	[thread overview]
Message-ID: <878vpjj6cw.fsf@ambire.localdomain> (raw)
In-Reply-To: <1316539888.28907.201.camel@homebase> (Paul Smith's message of "Tue, 20 Sep 2011 13:31:28 -0400")

[-- Attachment #1: Type: text/plain, Size: 4827 bytes --]

() Paul Smith <psmith@gnu.org>
() Tue, 20 Sep 2011 13:31:28 -0400

   I showed the code in my original post, but the way I've implemented it
   is that the argument to the make "guile" function (that is, everything
   after the "$(guile " to the closing paren--it's handy that Guile parens
   will virtually always match, but you can use ${guile ...} instead if you
   prefer), will first be make-expanded (so all verbatim instances of "$"
   in the Guile script will need to be escaped as "$$"--it doesn't seem
   like Guile uses "$" very much so this shouldn't be too painful) and then
   the result will be passed to scm_c_eval_string().

Ah, ok.

   As far as I understand it, that means the Guile program can be as
   complex as you want.  HOWEVER, you will need to use backslashes to
   escape newlines in your example above.

Distasteful.

   You can also use make's define/endef if you want to write long Guile
   programs and avoid the need for backslashes, then you can run $(guile
   $(DEFINEDVARIABLE)).

   Then make will convert the SCM returned from scm_c_eval_string() into a
   string buffer as discussed below etc., and use that as the expansion of
   the $(guile ...) function.

OK, sounds much better.

   > - Would stuff like ‘normalize’ and ‘trace’ be provided (builtin)?

   You are now running far beyond my understanding of Guile :-).  If it
   works in the environment I describe above then it will work.  If not,
   then I'll need more details.

   However I just tried your example above and I got an error "unbound
   variable: trace" so there's something missing here.  I'll have to read
   about that.

Yeah, ‘trace’ does not exist.  I think it (and other facilities) should
be defined by make, by (perhaps lazily, to avoid penalizing non-users)
loading a file, say, builtin.scm.  The minimum contents might be:

  (define-module (make-user)
    ;; builtins from C
    ;; #:use-module (make-internals)
    #:use-module (guile-user)
    #:use-module (srfi srfi-13)
    #:use-module (srfi srfi-14))
  
  (define DEBUG? (getenv "DEBUG"))
  ;; TODO: Set based on ‘-d’ exposed from C.
  
  (define (fse s . args)
    (apply simple-format (current-error-port) s args))
  
  (define (trace name . etc)
    (cond (DEBUG? (fse "hey: ~A ~S~%" name etc))))
  
  ;;; Add other convenience procs here.

Note that this doesn't export anything; the evaluation would need to
arrange to do its work with this as the "current module".  But, that's
just an idea.  You can also ‘(define-module (guile-user) ...)’ to keep
things simple initially...

   > - What happens if the stuff inside the double quotes includes
   >   $(call...) or $(eval...)?  What about those constructs elsewhere?

   [standard expansion explanation]

OK, got it.

   I suppose it's possible that we could introduce a new, more advanced
   parser for the guile function that took into account quotes.  But I'm
   nervous about this: it's completely different than other expansions, and
   it might be just as annoying as doing it the other way.

I agree, that's probably to be avoided.

   > (define (as-string x) ...)
   > (define (space-sep x) ...)

   Heh, cute!  I haven't done much Lisp of any kind since I wrote a number
   of elisp packages, years ago.  I think I'll have to dust off my Scheme.

Yes, don't delay, just do it!  Playing some more, i realized the above
version 0.0 is suboptimal.  Below is version 0.1 -- perhaps it could go
into builtins.scm.

   Maybe as an exercise, but patsubst IS a core feature, in that it has
   existed forever and there are thousands of makefiles that use it...
   basically rewriting existing capabilities so they're not available if
   Guile is not present changes things from "GNU make with Guile optional"
   to "GNU make with Guile required".  I'm not ready to go there.

Right, i see the sticking point is the "re" in "rewriting".  For me, that
"re" does not imply replacement, just iteration.  My "playing at working"
MO: i skim working code and write (and integrate side-by-side-wise) a
workalike implementation based on what i think are the original's intended
design, then compare the two under load, selecting the impl to use based
on some runtime switch (typically an env var).  This leads to better
questions as understanding (and/or frustration) grows.  Even if the second
impl is inferior (ends up trashed or permanently disabled), i gain
something from the experience (although i lose time, oh well).  Anyway,
that's what i was suggesting.

I chose ‘patsubst’ because its design seems straightforward; it would be
easy to validate another impl.  No worries, i shall harp no more on this.

____________________________________________________

[-- Attachment #2: procs-for-gnu-make-hacking.scm --]
[-- Type: application/x-scheme, Size: 1019 bytes --]

      parent reply	other threads:[~2011-09-20 20:39 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
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 [this message]

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=878vpjj6cw.fsf@ambire.localdomain \
    --to=ttn@gnuvola.org \
    --cc=guile-user@gnu.org \
    --cc=psmith@gnu.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).