From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Panicz Maciej Godek Newsgroups: gmane.lisp.guile.user Subject: Re: Way to control the order of macro expansion Date: Thu, 2 Jan 2014 15:30:32 +0100 Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: ger.gmane.org 1388673045 3494 80.91.229.3 (2 Jan 2014 14:30:45 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 2 Jan 2014 14:30:45 +0000 (UTC) To: "guile-user@gnu.org" Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Thu Jan 02 15:30:52 2014 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1VyjIO-0001lo-BS for guile-user@m.gmane.org; Thu, 02 Jan 2014 15:30:48 +0100 Original-Received: from localhost ([::1]:45494 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VyjIN-0001v4-Ec for guile-user@m.gmane.org; Thu, 02 Jan 2014 09:30:47 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:36902) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VyjIC-0001ux-C2 for guile-user@gnu.org; Thu, 02 Jan 2014 09:30:37 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VyjIA-0006aL-UF for guile-user@gnu.org; Thu, 02 Jan 2014 09:30:36 -0500 Original-Received: from mail-wi0-x229.google.com ([2a00:1450:400c:c05::229]:47400) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VyjIA-0006a2-JI for guile-user@gnu.org; Thu, 02 Jan 2014 09:30:34 -0500 Original-Received: by mail-wi0-f169.google.com with SMTP id j9so10126843wiv.4 for ; Thu, 02 Jan 2014 06:30:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=DdWvXDkt5QmE1OFd7u99+OZ5Nm51FN5dkGu5bdwHvMI=; b=aBQUFSZz0TEunjdD/6mhGWSyS1rNkaFMJ33EHM0ytYI+uzinSO5hrJqKMqHaAE9BI+ Q68SjuwIYMJ1b7ZmMkAnX0a2XcswppAqzSQUqSe2UN4yci9NNqSzDNoCYZfJUOXHyJeR JyIfywlKuALuSUIC+XXdU5q7dduTUtso6KACQD8BtJJiyFUgVAWyb6NAlNJVQJ7pnRDc eO1jBL7ZVWXXLL2dd2QLTzRP6E164iRn8RPbalKjRxcJDzSQUfC2LvffnYUThTV4epap 4O9u/BIVobECPZZgZVb7RI7602G36dw4eAGcN5ZK+Qu2chtkl6LcFFKrwPIC5/VmuLSD HS6Q== X-Received: by 10.194.92.109 with SMTP id cl13mr50064694wjb.13.1388673032831; Thu, 02 Jan 2014 06:30:32 -0800 (PST) Original-Received: by 10.194.178.134 with HTTP; Thu, 2 Jan 2014 06:30:32 -0800 (PST) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c05::229 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:10953 Archived-At: After reading some of the original paper by Dybvig[1], I finally managed to get the macro right. The trick was to use "with-syntax", which -- I have to admit -- is still a little magical to me. But by mimicking the way the procedure "generate-temporaries" has been used in the Dybvig's implementation of letrec, I came up with the following solution: (define-syntax private+public (lambda (stx) (define (name interface) (define (interface-name interface) (match interface ((head . tail) (interface-name head)) ((? symbol? name) name))) (datum->syntax stx (interface-name (syntax->datum interface)))) (syntax-case stx () ((_ (private ...) ((define-variant interface . body) ...)) (with-syntax (((name ...) (map name #'(interface ...)))) #`(begin (define name (and (defined? 'name) name)) ... (let () private ... (set! name (let () (define-variant interface . body) name)) ...))))))) [1] http://www.cs.indiana.edu/~dyb/pubs/tr356.pdf