From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Paul Smith Newsgroups: gmane.lisp.guile.user Subject: Re: Using guile as an extension language for GNU make Date: Tue, 20 Sep 2011 13:31:28 -0400 Organization: GNU's Not Unix! Message-ID: <1316539888.28907.201.camel@homebase> References: <1316304616.28907.118.camel@homebase> <87wrd5x404.fsf@ambire.localdomain> <1316374080.28907.163.camel@homebase> <87sjntwf29.fsf@ambire.localdomain> <1316445274.28907.174.camel@homebase> <87iponjihq.fsf@ambire.localdomain> Reply-To: psmith@gnu.org NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="windows-1251" Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1316539906 16272 80.91.229.12 (20 Sep 2011 17:31:46 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 20 Sep 2011 17:31:46 +0000 (UTC) Cc: guile-user@gnu.org To: Thien-Thi Nguyen Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Tue Sep 20 19:31:41 2011 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1R64AV-0001p0-Nv for guile-user@m.gmane.org; Tue, 20 Sep 2011 19:31:39 +0200 Original-Received: from localhost ([::1]:46921 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R64AV-0000KG-Ac for guile-user@m.gmane.org; Tue, 20 Sep 2011 13:31:39 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:36857) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R64AS-0000Jv-KF for guile-user@gnu.org; Tue, 20 Sep 2011 13:31:37 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1R64AQ-0000xU-Hj for guile-user@gnu.org; Tue, 20 Sep 2011 13:31:36 -0400 Original-Received: from oproxy4-pub.bluehost.com ([69.89.21.11]:52726) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1R64AQ-0000xG-7q for guile-user@gnu.org; Tue, 20 Sep 2011 13:31:34 -0400 Original-Received: (qmail 27756 invoked by uid 0); 20 Sep 2011 17:31:32 -0000 Original-Received: from unknown (HELO box531.bluehost.com) (74.220.219.131) by cpoproxy1.bluehost.com with SMTP; 20 Sep 2011 17:31:32 -0000 Original-Received: from 146-115-71-23.c3-0.lex-ubr1.sbo-lex.ma.cable.rcn.com ([146.115.71.23] helo=[172.31.1.105]) by box531.bluehost.com with esmtpsa (SSLv3:AES256-SHA:256) (Exim 4.76) (envelope-from ) id 1R64AN-0000X7-Cx; Tue, 20 Sep 2011 11:31:31 -0600 In-Reply-To: <87iponjihq.fsf@ambire.localdomain> X-Mailer: Evolution 2.32.2 X-Identified-User: {678:box531.bluehost.com:madscie1:mad-scientist.us} {sentby:smtp auth 146.115.71.23 authed with paul+mad-scientist.us} X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 69.89.21.11 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:8816 Archived-At: On Tue, 2011-09-20 at 18:17 +0200, Thien-Thi Nguyen wrote: > () Paul Smith > () Mon, 19 Sep 2011 11:14:34 -0400 >=20 > In make, everything is just words: broken up on whitespace. So for > example, maybe someone writes a Guile function that computes a complex > set of prerequisites for a target: >=20 > target: $(guile (...some Guile program...)) >=20 > Even before thinking about the return value (which, scanning ahead, > you seem to have hit upon a workable plan), i have some questions > about the "some Guile program": >=20 > - Is that just a procedure call or can it be definition(s) + expression(s= )? > e.g., single proc call: > $(guile (compute-complex-prerequisites "$@")) > e.g., complex: > $(guile (use-modules (srfi srfi-13)) > (define (ext filename) > (string-append filename ".ext")) > (define (ext-all ls) > (map ext ls)) > (define normalize ;;; nb: alias > string-tokenize) > (define (compute-complex-prerequisites s) > (ext-all (normalize s))) > ;; comment: do it! > (trace 'compute-complex-prerequisites "$@") > (compute-complex-prerequisites "$@")) 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(). 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. 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. > - Would stuff like =91normalize=92 and =91trace=92 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. > - What happens if the stuff inside the double quotes includes > $(call...) or $(eval...)? What about those constructs elsewhere? As with all GNU make expansions, quotes are ignored. The ONLY special character, to make, in an expansion is "$". Just as with call and eval, if you do not escape the "$" then it will be expanded BEFORE the Guile function is invoked. So, if you are using (make-expand ...) etc. in your Guile program you'll need to escape all the "$" there. There is definitely some complexity here and you have to FIRMLY understand make's expansion rules, just as you do when you use call and eval make functions, or even when writing shell script rules. Some debugging capability, to show the script we are passing to the guile function, seems like it would be quite useful. 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. > In Scheme, w/ SRFI 13, you could express this as: >=20 > (define (as-string x) > (cond ((not x) "") > ((unspecified? x) "") > ((eq? #t x) "t") > ((string? x) x) > ((null? x) "") > (else (object->string x)))) > =20 > (define (space-sep x) > (let ((acc '())) > (define (walk x) > (cond ((pair? x) > (walk (car x)) > (walk (cdr x))) > ((null? x)) > (else > (set! acc (cons x acc))))) > (walk x) > (string-join (map as-string (reverse! acc))))) > =20 > This is not so tricky, i think. 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. > Well, since Guile is not required and I want GNU make to continue to > work as-is on systems where Guile is not available, I won't be rewriti= ng > core features in Guile. Yet?!?! :-). >=20 > IMHO =91patsubst=92 is not a core feature (sez the spewful ignoramus). R= ather, > i think rewriting =91patsubst=92 would be a good exercise to help you for= mulate > and answer questions about small technical details that will eventually s= erve > as a foundation for rewriting core features. Why not give it a try? 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. --=20 ---------------------------------------------------------------------------= ---- Paul D. Smith 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 Scient= ist