unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* case source code
@ 2022-09-12  7:42 Damien Mattei
  2022-09-12  7:46 ` Zelphir Kaltstahl
  2022-09-12  8:47 ` Taylan Kammer
  0 siblings, 2 replies; 6+ messages in thread
From: Damien Mattei @ 2022-09-12  7:42 UTC (permalink / raw)
  To: guile-user, guile-devel

[-- Attachment #1: Type: text/plain, Size: 153 bytes --]

Hello,
i can not find in the scheme community a definition of 'case in term of
macro as for when, unless,while,do... does anyone have it?
thanks,
Damien

[-- Attachment #2: Type: text/html, Size: 469 bytes --]

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

* Re: case source code
  2022-09-12  7:42 case source code Damien Mattei
@ 2022-09-12  7:46 ` Zelphir Kaltstahl
  2022-09-12  8:27   ` Damien Mattei
  2022-09-12  8:47 ` Taylan Kammer
  1 sibling, 1 reply; 6+ messages in thread
From: Zelphir Kaltstahl @ 2022-09-12  7:46 UTC (permalink / raw)
  To: Damien Mattei; +Cc: guile-user, guile-devel

Hello Damien,

On 9/12/22 09:42, Damien Mattei wrote:
> Hello,
> i can not find in the scheme community a definition of 'case in term of
> macro as for when, unless,while,do... does anyone have it?
> thanks,
> Damien

Can you give an example of what form you mean?

Regards,
Zelphir

-- 
repositories: https://notabug.org/ZelphirKaltstahl




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

* Re: case source code
  2022-09-12  7:46 ` Zelphir Kaltstahl
@ 2022-09-12  8:27   ` Damien Mattei
  2022-09-12  8:30     ` Damien Mattei
  0 siblings, 1 reply; 6+ messages in thread
From: Damien Mattei @ 2022-09-12  8:27 UTC (permalink / raw)
  To: Zelphir Kaltstahl; +Cc: guile-user, guile-devel

sorry if my question was unclear , i search the source code if it exist in
scheme with macro (or not) but not in C for the 'case function (procedure
or macro) , i want to modify the code to allow inner definitions the way i
do it for example with 'do:

;; with a definition inside only the new version works:
;; (do ((i 1 (1+ i))
;;      (p 3 (* 3 p)))
;;     ((> i 4)
;;      p)
;;   (define x 7)
;;   (set! p (+ p i x)))
;; $3 = 1257

(define-syntax do

  (syntax-rules ()

    ((do ((var init step ...) ...)

         (test expr ...)

         command ...)

     (letrec

       ((loop

         (lambda (var ...)

           (if test

               ;;(begin
      (let ()

                 #f ; avoid empty begin

                 expr ...)

               ;;(begin
      (let ()

                 command

                 ...

                 (loop (do "step" var step ...)

                       ...))))))

       (loop init ...)))

    ((do "step" x)

     x)

    ((do "step" x y)

     y)))

regards,
Damien

On Mon, Sep 12, 2022 at 9:46 AM Zelphir Kaltstahl <
zelphirkaltstahl@posteo.de> wrote:

> Hello Damien,
>
> On 9/12/22 09:42, Damien Mattei wrote:
> > Hello,
> > i can not find in the scheme community a definition of 'case in term of
> > macro as for when, unless,while,do... does anyone have it?
> > thanks,
> > Damien
>
> Can you give an example of what form you mean?
>
> Regards,
> Zelphir
>
> --
> repositories: https://notabug.org/ZelphirKaltstahl
>
>


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

* Re: case source code
  2022-09-12  8:27   ` Damien Mattei
@ 2022-09-12  8:30     ` Damien Mattei
  0 siblings, 0 replies; 6+ messages in thread
From: Damien Mattei @ 2022-09-12  8:30 UTC (permalink / raw)
  To: Zelphir Kaltstahl; +Cc: guile-user, guile-devel

just forget to add , if it is unclear it is 'case of scheme:
https://www.gnu.org/software/guile/docs/docs-1.8/guile-ref/if-cond-case.html#if-cond-case

On Mon, Sep 12, 2022 at 10:27 AM Damien Mattei <damien.mattei@gmail.com>
wrote:

> sorry if my question was unclear , i search the source code if it exist in
> scheme with macro (or not) but not in C for the 'case function (procedure
> or macro) , i want to modify the code to allow inner definitions the way i
> do it for example with 'do:
>
> ;; with a definition inside only the new version works:
> ;; (do ((i 1 (1+ i))
> ;;      (p 3 (* 3 p)))
> ;;     ((> i 4)
> ;;      p)
> ;;   (define x 7)
> ;;   (set! p (+ p i x)))
> ;; $3 = 1257
>
> (define-syntax do
>
>   (syntax-rules ()
>
>     ((do ((var init step ...) ...)
>
>          (test expr ...)
>
>          command ...)
>
>      (letrec
>
>        ((loop
>
>          (lambda (var ...)
>
>            (if test
>
>                ;;(begin
>       (let ()
>
>                  #f ; avoid empty begin
>
>                  expr ...)
>
>                ;;(begin
>       (let ()
>
>                  command
>
>                  ...
>
>                  (loop (do "step" var step ...)
>
>                        ...))))))
>
>        (loop init ...)))
>
>     ((do "step" x)
>
>      x)
>
>     ((do "step" x y)
>
>      y)))
>
> regards,
> Damien
>
> On Mon, Sep 12, 2022 at 9:46 AM Zelphir Kaltstahl <
> zelphirkaltstahl@posteo.de> wrote:
>
>> Hello Damien,
>>
>> On 9/12/22 09:42, Damien Mattei wrote:
>> > Hello,
>> > i can not find in the scheme community a definition of 'case in term of
>> > macro as for when, unless,while,do... does anyone have it?
>> > thanks,
>> > Damien
>>
>> Can you give an example of what form you mean?
>>
>> Regards,
>> Zelphir
>>
>> --
>> repositories: https://notabug.org/ZelphirKaltstahl
>>
>>


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

* Re: case source code
  2022-09-12  7:42 case source code Damien Mattei
  2022-09-12  7:46 ` Zelphir Kaltstahl
@ 2022-09-12  8:47 ` Taylan Kammer
  2022-09-13  9:18   ` Damien Mattei
  1 sibling, 1 reply; 6+ messages in thread
From: Taylan Kammer @ 2022-09-12  8:47 UTC (permalink / raw)
  To: Damien Mattei, guile-user, guile-devel

On 12.09.2022 09:42, Damien Mattei wrote:
> 
> Hello,
> i can not find in the scheme community a definition of 'case in term of macro as for when, unless,while,do... does anyone have it?
> thanks,
> Damien

The RnRS often contain such definitions.  The following is taken from R7RS-small:

(define-syntax case
  (syntax-rules (else =>)
    ((case (key ...) clauses ...)
     (let ((atom-key (key ...)))
       (case atom-key clauses ...)))
    ((case key (else => result))
     (result key))
    ((case key
       (else result1 result2 ...))
     (begin result1 result2 ...))
    ((case key
       ((atoms ...) result1 result2 ...))
     (if (memv key ’(atoms ...))
	 (begin result1 result2 ...)))
    ((case key
       ((atoms ...) => result))
     (if (memv key ’(atoms ...))
	 (result key)))
    ((case key
       ((atoms ...) => result)
       clause clauses ...)
     (if (memv key ’(atoms ...))
	 (result key)
	 (case key clause clauses ...)))
    ((case key
       ((atoms ...) result1 result2 ...)
       clause clauses ...)
     (if (memv key ’(atoms ...))
	 (begin result1 result2 ...)
	 (case key clause clauses ...))))

-- 
Taylan




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

* Re: case source code
  2022-09-12  8:47 ` Taylan Kammer
@ 2022-09-13  9:18   ` Damien Mattei
  0 siblings, 0 replies; 6+ messages in thread
From: Damien Mattei @ 2022-09-13  9:18 UTC (permalink / raw)
  To: Taylan Kammer; +Cc: guile-user, guile-devel

thanks, if just replaced the 'begin by 'let () to allow internal
definitions but i haven't test it yet (finally no need in my code of define
internal at this point)
regards,
Damien

On Mon, Sep 12, 2022 at 10:47 AM Taylan Kammer <taylan.kammer@gmail.com>
wrote:

> On 12.09.2022 09:42, Damien Mattei wrote:
> >
> > Hello,
> > i can not find in the scheme community a definition of 'case in term of
> macro as for when, unless,while,do... does anyone have it?
> > thanks,
> > Damien
>
> The RnRS often contain such definitions.  The following is taken from
> R7RS-small:
>
> (define-syntax case
>   (syntax-rules (else =>)
>     ((case (key ...) clauses ...)
>      (let ((atom-key (key ...)))
>        (case atom-key clauses ...)))
>     ((case key (else => result))
>      (result key))
>     ((case key
>        (else result1 result2 ...))
>      (begin result1 result2 ...))
>     ((case key
>        ((atoms ...) result1 result2 ...))
>      (if (memv key ’(atoms ...))
>          (begin result1 result2 ...)))
>     ((case key
>        ((atoms ...) => result))
>      (if (memv key ’(atoms ...))
>          (result key)))
>     ((case key
>        ((atoms ...) => result)
>        clause clauses ...)
>      (if (memv key ’(atoms ...))
>          (result key)
>          (case key clause clauses ...)))
>     ((case key
>        ((atoms ...) result1 result2 ...)
>        clause clauses ...)
>      (if (memv key ’(atoms ...))
>          (begin result1 result2 ...)
>          (case key clause clauses ...))))
>
> --
> Taylan
>
>


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

end of thread, other threads:[~2022-09-13  9:18 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-12  7:42 case source code Damien Mattei
2022-09-12  7:46 ` Zelphir Kaltstahl
2022-09-12  8:27   ` Damien Mattei
2022-09-12  8:30     ` Damien Mattei
2022-09-12  8:47 ` Taylan Kammer
2022-09-13  9:18   ` Damien Mattei

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