public inbox for kawa@sourceware.org
 help / color / mirror / Atom feed
From: Damien Mattei <damien.mattei@gmail.com>
To: kawa mailing list <kawa@sourceware.org>
Subject: Re: rec in kawa?
Date: Sat, 7 Oct 2023 10:39:15 +0200	[thread overview]
Message-ID: <CADEOadffmTaFrOsLnKRvjRiOdxS1NtBS-Sr0QUuDsLuucWLe9w@mail.gmail.com> (raw)
In-Reply-To: <CADEOaddBoXOLX0hDA6ZOA+fysn5uM1ytgUkPf_HcL=JudW13uw@mail.gmail.com>

ok ,from SRFI 31:

(define-syntax rec
  (syntax-rules ()
    ((rec (NAME . VARIABLES) . BODY)
     (letrec ( (NAME (lambda VARIABLES . BODY)) ) NAME))
    ((rec NAME EXPRESSION)
     (letrec ( (NAME EXPRESSION) ) NAME))))

perheaps a good idea to make it default include in kawa....

#|kawa:1|# (load "Scheme+.scm")
#|kawa:2|# (def (bar n) (cond ((= n 0) 'end0) ((= n 7) (return-rec
'end7)) (else (cons n (bar (- n 1))))))
#|kawa:3|# (bar 5)
(5 4 3 2 1 . end0)
#|kawa:4|# (bar 10)
end7
#|kawa:5|# (def (foo n) (cond ((= n 0) 'end0) ((= n 7) (return 'end7))
(else (cons n (foo {n - 1})))))
/dev/tty:5:87: invalid character #\}
#|kawa:6|# (def (foo n) (cond ((= n 0) 'end0) ((= n 7) (return 'end7))
(else (cons n (foo (- n 1))))))
#|kawa:7|# (foo 5)
(5 4 3 2 1 . end0)
#|kawa:8|# (foo 10)
(10 9 8 . end7)

On Sat, Oct 7, 2023 at 10:32 AM Damien Mattei <damien.mattei@gmail.com> wrote:
>
> i have this definition but i miss rec in kawa:
>
> ;; scheme@(guile-user)> (def (foo) (when #t (return "hello") "bye"))
> ;; scheme@(guile-user)> (foo)
> ;;  "hello"
>
> ;; (def x)
>
>
>
> ;; (def (foo n)
> ;;      (cond ((= n 0) 'end0)
> ;;        ((= n 7) (return 'end7))
> ;;        (else (cons n (foo {n - 1})))))
>
>
> ;; scheme@(guile-user)> (foo 5)
> ;; (5 4 3 2 1 . end0)
> ;; scheme@(guile-user)> (foo 10)
> ;; (10 9 8 . end7)
>
> ;; (def (bar n)
> ;;      (cond ((= n 0) 'end0)
> ;;        ((= n 7) (return-rec 'end7))
> ;;        (else (cons n (bar {n - 1})))))
>
> ;; scheme@(guile-user)> (bar 5)
> ;; $4 = (5 4 3 2 1 . end0)
> ;; scheme@(guile-user)> (bar 10)
> ;; $5 = end7
> (define-syntax def
>
>   (lambda (stx)
>
>       (syntax-case stx ()
>
>     ;; multiple definitions without values assigned
>     ;; (def (x y z))
>     ((_ (var1 ...)) #`(begin (define var1 '()) ...))
>
>     ;;  (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>* ...)))))
>
>
>     ((_ (<name> <arg> ...) <body> <body>* ...)
>
>          (let ((ret-id (datum->syntax stx 'return))
>            (ret-rec-id (datum->syntax stx 'return-rec)))
>
>        #`(define (<name> <arg> ...)
>
>            (call/cc (lambda (#,ret-rec-id)
>
>              (apply (rec <name> (lambda (<arg> ...)
>                           (call/cc (lambda (#,ret-id) <body> <body>*
> ...)))) (list <arg> ...)))))))
>
>
>
>
>     ;; single definition without a value assigned
>     ;; (def x)
>     ((_ var) #`(define var '()))
>
>     ;; (def x 7)
>     ((_ var expr) #`(define var expr))
>
>     ((_ err ...) #`(syntax-error "Bad def form"))
>
>     )))
>
>
> any idea of replacement for it?

      reply	other threads:[~2023-10-07  8:39 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-07  8:32 Damien Mattei
2023-10-07  8:39 ` Damien Mattei [this message]

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

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

  git send-email \
    --in-reply-to=CADEOadffmTaFrOsLnKRvjRiOdxS1NtBS-Sr0QUuDsLuucWLe9w@mail.gmail.com \
    --to=damien.mattei@gmail.com \
    --cc=kawa@sourceware.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).