From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Damien Mattei Newsgroups: gmane.lisp.guile.user Subject: Re: syntax-case equivalent to syntax-rules Date: Sun, 29 Aug 2021 19:17:02 +0200 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="8543"; mail-complaints-to="usenet@ciao.gmane.io" Cc: julien.provillard@unice.fr, Jean-Paul Roy To: guile-user Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Sun Aug 29 19:17:42 2021 Return-path: Envelope-to: guile-user@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mKORC-0001yO-GI for guile-user@m.gmane-mx.org; Sun, 29 Aug 2021 19:17:42 +0200 Original-Received: from localhost ([::1]:45012 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mKORB-0001sm-16 for guile-user@m.gmane-mx.org; Sun, 29 Aug 2021 13:17:41 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:45120) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mKOQo-0001qS-Hc for guile-user@gnu.org; Sun, 29 Aug 2021 13:17:18 -0400 Original-Received: from mail-io1-xd31.google.com ([2607:f8b0:4864:20::d31]:44698) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mKOQl-00064O-LR for guile-user@gnu.org; Sun, 29 Aug 2021 13:17:17 -0400 Original-Received: by mail-io1-xd31.google.com with SMTP id g9so16397914ioq.11 for ; Sun, 29 Aug 2021 10:17:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=la2zaezPhAk1BCVvIr4kRPn+NqWLVjtBeDhSsZMWOvw=; b=DnsA582spKF4sJmMqbsCEn/G0SgTKO3tZilSoAlzB+E6C9OuD17KKWmKIlhEcdpZCt Bp31NcRUG+O5S4+wAq3jYpSvxIQMtJqpMThzpjBVbcYqpgB8P98drZhPvjuCzqrJCZVE 2Hiv/+2p135fzURzCgpUkKNFUVZdhyAN5AfYa3AhBgipJ3ODFvTvPjxSL56ckeYiRPiO FuIX8JC7VNqnqsYLWG+RbrlHRCD5P52WmzkappHRgQIot913S9CBW+QEG246pLvwQnKr qxRBEqRMbrd5RxhM+2d6C13hAexZT1FX0E8vq1euhNg+uDGuCe05VShmDuVUf1cJI9ZS GYrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=la2zaezPhAk1BCVvIr4kRPn+NqWLVjtBeDhSsZMWOvw=; b=cyCVJpudb8e+caeNsLC2Z5dLxOXd4C/s1oRMw8LpfMqo64xgOrGhcgTvje1g4kxNbw Qf3+jGqQEWspmEZzQElS7pA/viU960M5MyPxNTIQ8ummawTNXvOWPz9/Uj92LnxaZdwH kpi/0TtYZOOufWMSlYzlnr1tOlEwyjQM2SgT7F8RNBiqbNb4bpQ3YcwueUO/1IW6K9BC rgQuwzHxm25Gx75jFv/W6ZG3vB1Roh/rirsgoUgreLN7wr5CFMsnlvdSIzVcuAxaYDCn LillOkp9an7+nn/NKpiPWAYB8egD8VC8UUjFY06zVVTsa6ZhjMvgBjWYAEcSAqFE7rni nRNg== X-Gm-Message-State: AOAM5324qjPdp4XP0x93ebjqEX+xTkfailS0VZc0fP+Z/mOpBtub9pE6 izvUaTJddK4WzTRb8WhINLzm4j+iUUVzGm2ZYo1pCbSaJG8tdQ== X-Google-Smtp-Source: ABdhPJya4TGRPnm6cgYCzz/QLSRaz1YfLeAnbUDoKY08ygbFsz0n++rzkcYp+r0RrE7Z+TBcDIsxzvw+tweeQAGK2wU= X-Received: by 2002:a5e:8349:: with SMTP id y9mr10087213iom.34.1630257433823; Sun, 29 Aug 2021 10:17:13 -0700 (PDT) In-Reply-To: Received-SPF: pass client-ip=2607:f8b0:4864:20::d31; envelope-from=damien.mattei@gmail.com; helo=mail-io1-xd31.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Content-Filtered-By: Mailman/MimeDel 2.1.23 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.23 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-mx.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.io gmane.lisp.guile.user:17703 Archived-At: i find myself that the order of cases in syntax-case and macros is important, complex case must be put before simplest ones in order to avoid them to be parsed before, unless that they are shadowed by simplest ones... the solution was just to reorder them from complex -> simple ones: (define-syntax def (lambda (stx) (syntax-case stx (declare) ;; (def (declare x y z) 1 2 (list x y z)) ;; (() () ()) ((_ (declare var1 ...) ...) #`(letrec ((var1 '()) ...) ...)) ;; (def (foo) (when #t (return "hello") "bye")) ((_ ( ...) ...) (let ((ret-id (datum->syntax stx 'return))) #`(define ( ...) (call/cc (lambda (#,ret-id) ...))))) ;; definition without a value assigned ;; (def x) ((_ var) #`(define var '())) ;; (def x 7) ((_ var expr) #`(define var expr)) ))) On Sun, Aug 29, 2021 at 1:29 PM Damien Mattei wrote: > hello, > > i write a macro that needs both the features of syntax-rules and > syntax-case based on documentation: > https://www.gnu.org/software/guile/manual/html_node/Syntax-Case.html > > i have : > > ;; scheme@(guile-user)> (def (foo) (when #t (return "hello") "bye")) > ;; scheme@(guile-user)> (foo) > ;; "hello" > > ;; (def x) > > ;; TODO: study def of a recursive function > (define-syntax def > > (lambda (stx) > (syntax-case stx (declare) > > ;; definition without a value assigned > ;; (def x) > ((_ var) #`(define var '())) > > ;; (def x 7) > ((_ var expr) #`(define var expr)) > > ;; added body body* > ;;((_ (declare var1) * ...) #`(letrec ((var1 '())) > * ...)) > > ;; 'compiles' but do not have the expected behavior: > ((_ (declare var1 ...) ...) #`(letrec ((var1 '()) ...) > ...)) > > ;; (def (foo) (when #t (return "hello") "bye")) > ((_ ( ...) * ...) > (let ((ret-id (datum->syntax stx 'return))) > #`(define ( ...) > (call/cc (lambda (#,ret-id) * ...)))))))) > > and def2 that have the good behavior: > > scheme@(guile-user)> (def2 (declare x y z) (list x y z)) > $1 = (() () ()) > > (define-syntax def2 > > (syntax-rules (declare) > > ((_ (declare var1 ...) ...) (letrec ((var1 '()) ...) > ...)))) > > i want to merge def and def2 in a single macro > > any solution? > > Damien >