From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Matt Wette Newsgroups: gmane.lisp.guile.user Subject: Re: problems with syntax-case and with-syntax Date: Sun, 27 Aug 2017 20:48:29 -0700 Message-ID: <8E3EAC12-824B-4E97-B197-0A0C6DD5112B@gmail.com> References: <87lgm4il3u.fsf@netris.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\)) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1503892141 27913 195.159.176.226 (28 Aug 2017 03:49:01 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 28 Aug 2017 03:49:01 +0000 (UTC) To: Guile User Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Mon Aug 28 05:48:55 2017 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dmB2g-0006g9-0t for guile-user@m.gmane.org; Mon, 28 Aug 2017 05:48:50 +0200 Original-Received: from localhost ([::1]:36784 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dmB2m-0002uP-24 for guile-user@m.gmane.org; Sun, 27 Aug 2017 23:48:56 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:54968) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dmB2S-0002uH-8C for guile-user@gnu.org; Sun, 27 Aug 2017 23:48:37 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dmB2P-0001Xz-4W for guile-user@gnu.org; Sun, 27 Aug 2017 23:48:36 -0400 Original-Received: from mail-pg0-x22f.google.com ([2607:f8b0:400e:c05::22f]:32975) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dmB2O-0001XZ-US for guile-user@gnu.org; Sun, 27 Aug 2017 23:48:33 -0400 Original-Received: by mail-pg0-x22f.google.com with SMTP id t3so20021088pgt.0 for ; Sun, 27 Aug 2017 20:48:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=q19eJi5oP3St2zx5xR4Wf7aa+9ZK+jgkxim+mcpiB4Q=; b=BGogQDMtjCPUszcxl9PglZQqxrzWImxw9VzCgCtJO7XzCQcLsCjhm7nQQ6R/mTcgc0 z7hw3zM+9Oun9pcvfU/jyTZMI2tfnLWumRzpM3czejRjtE28FZ8Py5MjBHrKk+X3OJkc GcaC2bevc4WmToiWX7RUmuyBbFAQydpyQoJXVTcAFpgENmi5OFW0snkebpYNS/6dTzQi ou4jbhj9zNbXfX1FKUfrE4UZm/0pNqNrHNMrv7WFwLvligqyXT57yo3cZ6+yprhB9V5g grsTF+uSpfc9tE6sAq0KSy7k01p9cAe3XUekUJ2hYah1skr3IPFqmGA6gYrldDXAtey9 9dAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=q19eJi5oP3St2zx5xR4Wf7aa+9ZK+jgkxim+mcpiB4Q=; b=dYasTfN4EBwgF1xuyHlwKjEzlTs/CKjmwjx245I7C8ADT0PpR1ASl7roihTwAfSbr4 l9rFzOmQ3Bw+zwzS+knsQB8SBju0t1pZNnGzq0PrrRXu2rB1EdQmMKJmm//w9UBFwVaV CKqIbNF6SPnt3OW64YSs4yjD9Q9UxChjcqFFZ1Q6jQe3UxWps5e78NIJ9wvbSRbY0bsz GDRIYMB5/RXhMgh4HiAaoJj4nF2ucwE2z9AUEAWPB4b2658w/A2F+2f4TBd8IFn4X7Ze R7gJn8r0E0IkH5Q9SCCaXxBu7JoK9qvfjB62bRFCLX0Wectw+vZhsEYsa0uJN6oQPAD3 9paw== X-Gm-Message-State: AHYfb5g1aPRAC+x/bpwdJt4l2FE9jx+WO9jQhRSBKw8epLHQfW5kqiij SHgEHS8A4ig+S5RsOe0= X-Received: by 10.101.72.193 with SMTP id o1mr5988535pgs.448.1503892111246; Sun, 27 Aug 2017 20:48:31 -0700 (PDT) Original-Received: from nautilus.championbroadband.com (216-165-229-229.championbroadband.com. [216.165.229.229]) by smtp.gmail.com with ESMTPSA id y8sm21259060pfi.159.2017.08.27.20.48.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 27 Aug 2017 20:48:30 -0700 (PDT) In-Reply-To: <87lgm4il3u.fsf@netris.org> X-Mailer: Apple Mail (2.3273) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::22f X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.21 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" Xref: news.gmane.org gmane.lisp.guile.user:14070 Archived-At: > On Aug 27, 2017, at 5:36 PM, Mark H Weaver wrote: >=20 > Matt Wette writes: >=20 >> Q1) The code below creates two macros. One called `define-foo' which = generates a new identifier and=20 >> then defines that to #t. The other, `define-foo/p', generates the = same identifier (lexical issue?)=20 >> and another identifier, then "calls" define-foo and then uses both = identifiers in a `define'. When >> executed I get this error: >>=20 >> scheme@(guile-user)> (define-foo/p abc) >> ;;; :2:0: warning: possibly unbound variable `wrap-abc' >> :2:0: :2:0: In procedure module-lookup: = Unbound variable: wrap-abc >>=20 >> What am I doing wrong here? >=20 > The problem is that in Guile 2.2, whenever (define ...) is found = in > the expanded code, where was introduced by a macro (i.e. not = passed > as an explicit argument to the macro), Guile will rewrite the = into > a new name based on the hash of the entire definition form. >=20 > I don't know of any way to make this work without passing 'wrap-abc' > explicitly as an argument to the 'define-foo' macro. >=20 > FWIW, I've always been opposed to these non-standard semantics, but = they > were included in Guile 2.2 over my strenuous objections: >=20 > https://lists.gnu.org/archive/html/guile-devel/2014-01/msg00061.html > https://lists.gnu.org/archive/html/guile-devel/2011-11/msg00021.html > https://lists.gnu.org/archive/html/guile-devel/2011-11/msg00042.html >=20 >> Q2) Also with respect to the code below. Is there any way to pull = the >> definitions for stx->str and gen-id out of the define-syntax body to >> make them general purpose? >=20 > Yes, you can wrap the definitions of 'stx->str' within 'eval-when', = like > this: >=20 > (eval-when (expand load eval) > (define (stx->str stx) > ...) > (define (gen-id tmpl-id . args) > ...)) >=20 > above the macro definitions that use them. >=20 > One more thing: >=20 >> (define-syntax define-foo >> (lambda (x) >> (define (stx->str stx) >> (symbol->string (syntax->datum stx))) >> (define (gen-id tmpl-id . args) >> (datum->syntax >> tmpl-id >> (string->symbol >> (apply string-append >> (map (lambda (ss) (if (string? ss) ss (stx->str ss))) = args))))) >> (syntax-case x () >> ((_ name) >> (with-syntax ((wrap (gen-id x "wrap-" #'name))) >> #'(begin >> (define wrap #t))))))) >=20 > Here, the 'tmpl-id' that is being passed to 'datum-syntax' is not > actually an identifier, but rather a compound syntax object. Although > we do not currently raise an error in this case (we probably should), = it > is against the spec and likely to cause problems in the future, if not > today. You should pass an actual identifier as 'tmpl-id'. >=20 > Regards, > Mark >=20 Thanks. Things look much better now. I just added a case for define-foo syntax with an extra arg for wrap, so = I can pass it. I wrapped gen-id in the eval-when. (Yay!) I replaced `(gen-id x "wrap-" #'name)' with `(gen-id #'name "wrap-" = #'name)'. (I used to write the last step that way but picked up a bad habit at = some time.) Matt