From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Thien-Thi Nguyen Newsgroups: gmane.lisp.guile.user Subject: Re: Using guile as an extension language for GNU make Date: Tue, 20 Sep 2011 18:17:37 +0200 Message-ID: <87iponjihq.fsf@ambire.localdomain> References: <1316304616.28907.118.camel@homebase> <87wrd5x404.fsf@ambire.localdomain> <1316374080.28907.163.camel@homebase> <87sjntwf29.fsf@ambire.localdomain> <1316445274.28907.174.camel@homebase> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1316535578 17510 80.91.229.12 (20 Sep 2011 16:19:38 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 20 Sep 2011 16:19:38 +0000 (UTC) Cc: guile-user@gnu.org To: psmith@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Tue Sep 20 18:19:34 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 1R632j-0006oS-Br for guile-user@m.gmane.org; Tue, 20 Sep 2011 18:19:33 +0200 Original-Received: from localhost ([::1]:42474 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R632i-0003hL-P3 for guile-user@m.gmane.org; Tue, 20 Sep 2011 12:19:32 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:54282) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R632d-0003bu-QF for guile-user@gnu.org; Tue, 20 Sep 2011 12:19:31 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1R632Y-0002Cp-VX for guile-user@gnu.org; Tue, 20 Sep 2011 12:19:27 -0400 Original-Received: from smtp206.alice.it ([82.57.200.102]:57459) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R632X-00029I-9z; Tue, 20 Sep 2011 12:19:21 -0400 Original-Received: from ambire.localdomain (95.249.37.120) by smtp206.alice.it (8.5.124.08) id 4E4BBF7702C8BDC4; Tue, 20 Sep 2011 18:19:02 +0200 Original-Received: from ttn by ambire.localdomain with local (Exim 4.69) (envelope-from ) id 1R630r-0000q7-Gd; Tue, 20 Sep 2011 18:17:37 +0200 In-Reply-To: <1316445274.28907.174.camel@homebase> (Paul Smith's message of "Mon, 19 Sep 2011 11:14:34 -0400") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 82.57.200.102 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:8815 Archived-At: () Paul Smith () Mon, 19 Sep 2011 11:14:34 -0400 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: target: $(guile (...some Guile program...)) 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": - 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 "$@")) - (if the former) How would =E2=80=98compute-complex-prerequisites=E2=80=99= be defined? - Would stuff like =E2=80=98normalize=E2=80=99 and =E2=80=98trace=E2=80=99 = be provided (builtin)? - What happens if the stuff inside the double quotes includes $(call...) or $(eval...)? What about those constructs elsewhere? Then I'd like to convert a list like '(dep1 dep2 dep3) into a string "de= p1 dep2 dep3" (not "(dep1 dep2 dep3)" as display would do). But of course each element of the list could be something more complex, as well. So it gets tricky. In Scheme, w/ SRFI 13, you could express this as: (define (as-string x) (cond ((not x) "") ((unspecified? x) "") ((eq? #t x) "t") ((string? x) x) ((null? x) "") (else (object->string x)))) =20=20=20=20=20=20=20=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. Yes but implementing it in C, with the memory management etc., would be a lot of (not fun/interesting) work. Hm. I guess I could write a little Guile program to do it for me :-). Yes, that's the idea! 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 rewriting core features in Guile. Yet?!?! :-). IMHO =E2=80=98patsubst=E2=80=99 is not a core feature (sez the spewful igno= ramus). Rather, i think rewriting =E2=80=98patsubst=E2=80=99 would be a good exercise to he= lp you formulate and answer questions about small technical details that will eventually ser= ve as a foundation for rewriting core features. Why not give it a try?