definitions in expression context for guile
Added a chezscheme (almoste r6rs) version
Changed letrec to letrec*, which should make it more portable

heads

tip
browse log

clone

read-only
https://hg.sr.ht/~bjoli/guile-define
read/write
ssh://hg@hg.sr.ht/~bjoli/guile-define

A small utility macro to allow defines in expression context of function bodies. Install it in your site-dir and import it using (use-modules (syntax define))

#Example

(use-modules (syntax define))
(define (divide-minus-one a b)
  (when (= b 1) (error "We don't allow that here"))
  (define b* (- b 1))
  (/ a b*))

This transforms all defines in expression context to (letrec ...).

#guile 2.2 AND 3

guile-3 famously has definitions in some expression contexts. This expands on that (definitions in cond clauses and so on), and should also work just fine in guile 2.2 - albeit at a performance cost because internal definitions and letrec is slower in guile2.

#Supported forms

The bodies of lambda, define, let, let*, letrec, letrec*, when, unless, case, and cond are transversed and transformed.

#Caveats

begin is NOT supported. This is due to begin being spliced if in the top-level.

This is a module-local transformation, thus macros imported from other modules don't allow this transformation. Say, for example (ie-9 match), srfi-11, (ice-9 receive). For guile-3 many of these will work anyway, but will fail in guile-2.2.

#Portability

The macros are currently written in syntax-rules. If that isn't supported in your scheme, then tough luck.

#License

Permissified ISC.

#Documentation

There is none.