unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* return macro
@ 2021-06-27 23:10 Damien Mattei
  2021-06-28  1:15 ` Taylan Kammer
  0 siblings, 1 reply; 8+ messages in thread
From: Damien Mattei @ 2021-06-27 23:10 UTC (permalink / raw)
  To: guile-user

hi,

i wanted to create a macro that is used like a function definition and
allow return using call/cc:

(define-syntax def
(syntax-rules (return)
((_ (name args ...) body body* ...)
(define name (lambda (args ...)
(call/cc (lambda (return) body body* ...)))))
((_ name expr) (define name expr))))

unfortunaly i got error:

scheme@(guile-user)> (def (test x) (cond ((= x 3) 7) ((= x 2) (return 5))
(else 3)))
;;; <stdin>:2:42: warning: possibly unbound variable `return'
scheme@(guile-user)> (test 2)
ice-9/boot-9.scm:1685:16: In procedure raise-exception:
Unbound variable: return


any idea?

Damien


^ permalink raw reply	[flat|nested] 8+ messages in thread
* Re: return macro
@ 2021-09-30 20:55 dsmich
  2021-10-01  8:37 ` adriano
  0 siblings, 1 reply; 8+ messages in thread
From: dsmich @ 2021-09-30 20:55 UTC (permalink / raw)
  To: 'adriano'; +Cc: 'guile-user'

From: "adriano" 

> (import (ice-9 control))
 >
 > (define (test x)
 > (let/ec return
 > (cond
 > ((= x 3) (return 7))
 > ((= x 2) (return 5)))))

 > What does this return (defined with let/ec) do ?

 > In the orevious versions I could see the call to call/cc so I could
 > (somewhat) figure out the "jump" imlpied by calling return

> But in this last case, where is the return behaviour defined ?

See
https://www.gnu.org/software/guile/manual/guile.html#index-let_002fec

-Dale




^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-10-01  8:37 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-27 23:10 return macro Damien Mattei
2021-06-28  1:15 ` Taylan Kammer
2021-06-28  8:53   ` Damien Mattei
2021-09-30  3:37   ` adriano
2021-09-30  8:46     ` Damien Mattei
2021-09-30  9:18       ` Stefan Israelsson Tampe
  -- strict thread matches above, loose matches on Subject: below --
2021-09-30 20:55 dsmich
2021-10-01  8:37 ` adriano

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).