[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

cond(itionals) with optional execution of statements

From: Damien Mattei
Subject: cond(itionals) with optional execution of statements
Date: Sat, 11 Sep 2021 11:14:17 +0200


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
scheme@(guile-user)> (define x 1)

(condx ((= x 7) 'never)
          (define y 3)
          (set! x 7))
        ((= y 1) 'definitely_not)
          (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

have a good day


Attachment: condx.scm
Description: Binary data

reply via email to

[Prev in Thread] Current Thread [Next in Thread]