From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Stephen Compall Newsgroups: gmane.lisp.guile.user Subject: Re: C++ declaration style programming? Date: 20 Jan 2004 23:00:02 -0600 Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Message-ID: References: <16397.43262.881852.180514@localhost.localdomain> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1074662052 7280 80.91.224.253 (21 Jan 2004 05:14:12 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 21 Jan 2004 05:14:12 +0000 (UTC) Cc: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Wed Jan 21 06:14:05 2004 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1AjAgn-0005Ai-00 for ; Wed, 21 Jan 2004 06:14:05 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.24) id 1AjAgP-0006zv-Oy for guile-user@m.gmane.org; Wed, 21 Jan 2004 00:13:41 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.24) id 1AjAdn-00062e-2r for guile-user@gnu.org; Wed, 21 Jan 2004 00:10:59 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.24) id 1AjAd6-0005kG-Eg for guile-user@gnu.org; Wed, 21 Jan 2004 00:10:48 -0500 Original-Received: from [192.195.228.35] (helo=csserver.evansville.edu) by monty-python.gnu.org with esmtp (TLSv1:DES-CBC3-SHA:168) (Exim 4.24) id 1AjAbY-00058A-JA for guile-user@gnu.org; Wed, 21 Jan 2004 00:08:40 -0500 Original-Received: from csserver.evansville.edu (localhost.localdomain [127.0.0.1]) by csserver.evansville.edu (8.12.8/8.12.8) with ESMTP id i0L502lQ023235; Tue, 20 Jan 2004 23:00:03 -0600 Original-Received: (from sc87@localhost) by csserver.evansville.edu (8.12.8/8.12.8/Submit) id i0L502X9023231; Tue, 20 Jan 2004 23:00:02 -0600 X-Authentication-Warning: csserver.evansville.edu: sc87 set sender to s11@member.fsf.org using -f Original-To: hanwen@cs.uu.nl In-Reply-To: <16397.43262.881852.180514@localhost.localdomain> Original-Lines: 68 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.2 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 Xref: main.gmane.org gmane.lisp.guile.user:2672 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.user:2672 Han-Wen Nienhuys writes: > (begin-let* > (def var1 (something)) > (set! var1 (+ var1 2)) > (def var2 (something var1)) > (set! var2 (+ var2 var1)) > (def var3 (something var1 var2)) > ... ) > > > This can presumably be done by writing a macro begin-let* that expands > the statement list in a suitably nested let* > > However, I was wondering whether there exists a standard library > syntax mechanism that lets me write code in this fashion. Viktor Pavlenko is correct in saying that this is just not what you do in Scheme. As Stroustrup (I believe) said, you cannot simply take idioms from one language and use them in another. That said, here is a macro that does the thing. Note, however, that: 1. it arbitrarly interprets forms whose car is 'def to be your define forms 2. you can re-def forms and in so doing shadow their previous definitions (not that this makes any difference, as the scope continues to the end of begin-let*) 3. because of 1., def forms buried deeper than the immediate level will not be found. So (begin-let* (def hello "hello")) is ok, (begin-let* (begin (def hello "hello") (display hello) (newline))) is not ok. 4. also because of 1., you can't (def def newline) and expect (def) as one of your forms to be the same as (newline). (def) will be changed to (let (()) ...), which of course will throw syntax-error. 5. This def doesn't include the function definition shortcut, i.e. "having the first argument be a pair means you're defining a function" isn't recognized. Use lambda instead. Not that you'd do that, being so against the Schemely way of doing things >:-> I suggest you document this macro before using it. (define-macro (begin-let* . forms) (let ((newforms (list 'begin))) (let lp ((forms forms) (lastpair newforms)) (cond ((not (pair? forms)) newforms) ((and (pair? (car forms)) (eq? 'def (caar forms))) (set-cdr! lastpair `((let (,(cdar forms))))) (lp (cdr forms) (cdadr lastpair))) (else (set-cdr! lastpair (list (car forms))) (lp (cdr forms) (cdr lastpair))))))) -- Stephen Compall or s11 or sirian Many receive advice, few profit by it. -- Publilius Syrus 64 Vauxhall Cross csystems passwd CDC Audiotel Skipjack tempest Albright ARPA assassination Ft. Bragg satellite imagery clones ASIO EuroFed _______________________________________________ Guile-user mailing list Guile-user@gnu.org http://mail.gnu.org/mailman/listinfo/guile-user