unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Damien Mattei <damien.mattei@gmail.com>
To: guile-user <guile-user@gnu.org>
Cc: julien.provillard@unice.fr, Jean-Paul Roy <jean-paul.roy@unice.fr>
Subject: syntax-case equivalent to syntax-rules
Date: Sun, 29 Aug 2021 13:29:19 +0200	[thread overview]
Message-ID: <CADEOadczv23PAKMk4fMzpGTayZC5u+dcNm2+wrn7AGHX5UKtxA@mail.gmail.com> (raw)

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) <body> <body>* ...) #`(letrec ((var1 '())) <body>
<body>* ...))

;; 'compiles' but do not have the expected behavior:
((_ (declare var1 ...) <body> ...) #`(letrec ((var1 '()) ...)
      <body> ...))

 ;;  (def (foo) (when #t (return "hello") "bye"))
        ((_ (<name> <arg> ...) <body> <body>* ...)
         (let ((ret-id (datum->syntax stx 'return)))
           #`(define (<name> <arg> ...)
               (call/cc (lambda (#,ret-id) <body> <body>* ...))))))))

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 ...) <body> ...) (letrec ((var1 '()) ...)
<body> ...))))

i want to merge def and def2 in a single macro

any solution?

Damien


             reply	other threads:[~2021-08-29 11:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-29 11:29 Damien Mattei [this message]
2021-08-29 17:17 ` syntax-case equivalent to syntax-rules Damien Mattei

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CADEOadczv23PAKMk4fMzpGTayZC5u+dcNm2+wrn7AGHX5UKtxA@mail.gmail.com \
    --to=damien.mattei@gmail.com \
    --cc=guile-user@gnu.org \
    --cc=jean-paul.roy@unice.fr \
    --cc=julien.provillard@unice.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).