From: Damien Mattei <damien.mattei@gmail.com>
To: guile-user <guile-user@gnu.org>
Subject: cond(itionals) with optional execution of statements
Date: Sat, 11 Sep 2021 11:14:17 +0200 [thread overview]
Message-ID: <CADEOadeowKJ37=6hbBQ79vGoqvPnwKv-fS2snX8eJbUdDK1K=w@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1603 bytes --]
hello,
i wrote a little macro (file condx.scm) that allow : cond(itionals) with
optional execution of statements before:
(define-syntax condx
(syntax-rules (exec)
((_)
(error 'condx "No else clause"))
((_ (else e ...))
(let () e ...))
((_ (exec s ...) d1 ...)
(let () s ... (condx d1 ...)))
((_ (t e ...) tail ...)
(if t
(let () e ...)
(condx tail ...)))))
use it like that:
mattei@macbook-pro-touch-bar library-FunctProg % guile
GNU Guile 3.0.7
Copyright (C) 1995-2021 Free Software Foundation, Inc.
Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'.
This program is free software, and you are welcome to redistribute it
under certain conditions; type `,show c' for details.
Enter `,help' for help.
scheme@(guile-user)> (load "condx.scm")
;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0
;;; or pass the --no-auto-compile argument to disable.
;;; compiling /Users/mattei/Dropbox/git/library-FunctProg/condx.scm
;;; compiled
/Users/mattei/.cache/guile/ccache/3.0-LE-8-4.5/Users/mattei/Dropbox/git/library-FunctProg/condx.scm.go
scheme@(guile-user)> (define x 1)
(condx ((= x 7) 'never)
(exec
(define y 3)
(set! x 7))
((= y 1) 'definitely_not)
(exec
(set! y 10)
(define z 2))
((= x 7) (+ x y z))
(else 'you_should_not_be_here))
$1 = 19
i share it to have idea about critics or idea to improve it as it will be
part of a Scheme extension to scheme language that will include other
features....
have a good day
Damien
[-- Attachment #2: condx.scm --]
[-- Type: application/octet-stream, Size: 652 bytes --]
;; condx: cond(itionals) with optional execution of statements before
;
; example:
;(define x 1)
;(condx ((= x 7) 'never)
; (exec
; (define y 3)
; (set! x 7))
; ((= y 1) 'definitely_not)
; (exec
; (set! y 10)
; (define z 2))
; ((= x 7) (+ x y z))
; (else 'you_should_not_be_here))
;
; 19
(define-syntax condx
(syntax-rules (exec)
((_)
(error 'condx "No else clause"))
((_ (else e ...))
(let () e ...))
((_ (exec s ...) d1 ...)
(let () s ... (condx d1 ...)))
((_ (t e ...) tail ...)
(if t
(let () e ...)
(condx tail ...)))))
next reply other threads:[~2021-09-11 9:14 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-11 9:14 Damien Mattei [this message]
2021-09-12 9:41 ` cond(itionals) with optional execution of statements Zelphir Kaltstahl
2021-09-12 17:05 ` Damien Mattei
2021-09-12 18:31 ` Taylan Kammer
2021-09-13 9:08 ` Damien Mattei
2021-09-12 18:36 ` Zelphir Kaltstahl
2021-09-13 10:04 ` 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='CADEOadeowKJ37=6hbBQ79vGoqvPnwKv-fS2snX8eJbUdDK1K=w@mail.gmail.com' \
--to=damien.mattei@gmail.com \
--cc=guile-user@gnu.org \
/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).