unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* expression and definition context in Scheme
@ 2022-08-27 16:48 Damien Mattei
  2022-08-27 17:00 ` Maxime Devos
  2022-08-30 10:47 ` Linus Björnstam
  0 siblings, 2 replies; 12+ messages in thread
From: Damien Mattei @ 2022-08-27 16:48 UTC (permalink / raw)
  To: guile-user, guile-devel

Hello,

i'm facing sometimes recursively the problem to have definitions in
expression context, which i manage every time by adding an upper empty (let
() my definitions goes here )
the last case i was facing this probleme is defining a 'for macro:

;; scheme@(guile-user)> (for ({i <+ 0} {i < 5} {i <- {i + 1}}) (display i)
(newline))
;; 0
;; 1
;; 2
;; 3
;; 4


(define-syntax for

  (syntax-rules ()

    ((_ (init test incrmt) b1 ...)

       (let ()
           init
           (let loop ()
              (when test
                    b1 ...
                    incrmt
                    (loop)))))))

this one fails in my Scheme+ code below:
(define (compute-carries n)

  (for ( {k <+ 0}  {k <= n}  {k <- {k + 1}} )

       { Ckp1 <+ (compute-Ck-plus1 k) }
       (display-nl Ckp1)))

because { Ckp1 <+ (compute-Ck-plus1 k) } expands in :
(define Ckp1 (compute-Ck-plus1 k))
and i get a compilation error:
;;; Syntax error:
;;; logic-syracuse+.scm:15:7: definition in expression context, where
definitions are not allowed, in form (define Ckp1 (compute-Ck-plus1 k))

so i replace my 'for macro definition with:

(define-syntax for

  (syntax-rules ()

    ((_ (init test incrmt) b1 ...)

       (let ()
           init
           (let loop ()
              (when test
                (let ()
                    b1 ...
                    incrmt
                    (loop))))))))

and it works, but you will notice an abusive use of empty (let () ...) in
the code to avoid the restrictions of definitions not allowed in expression
context.

My ideas is as it is so easy to cheat the compiler from seeing the
expressio context why does the compiler restrict this? expression and
defintion context, i'm not sure they are in scheme standarts, are they
really usefull?
why not remove this from Scheme at all?

Regards,

Damien


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

* Re: expression and definition context in Scheme
  2022-08-27 16:48 expression and definition context in Scheme Damien Mattei
@ 2022-08-27 17:00 ` Maxime Devos
  2022-08-27 19:02   ` Damien Mattei
  2022-08-30 10:47 ` Linus Björnstam
  1 sibling, 1 reply; 12+ messages in thread
From: Maxime Devos @ 2022-08-27 17:00 UTC (permalink / raw)
  To: Damien Mattei, guile-user, guile-devel


[-- Attachment #1.1.1.1: Type: text/plain, Size: 902 bytes --]


On 27-08-2022 18:48, Damien Mattei wrote:
> My ideas is as it is so easy to cheat the compiler
I don't think it's cheating or abusive.
> from seeing the expressio context why does the compiler restrict this? 
> expression and defintion context, i'm not sure they are in scheme 
> standarts, are they really usefull?
> why not remove this from Scheme at all?
>
I haven't read the RnRS closely, but I doubt that

(some-procedure (define foo 0) (define bar 0))

is allowed by the standard and that it could be meaningful.

Also, even if (begin ...) and (let () ...) where unified, it would be a 
shame to lose the ability to only have some definitions temporarily:

(define foo 0)

(let ((foo 0))
   whatever-something-using-the-inner-foo)

something-using-the-outer-foo-again

If 'let' was replaced by 'begin', then it would have different semantics.

Greetings,
Maxime.


[-- Attachment #1.1.1.2: Type: text/html, Size: 1809 bytes --]

[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 929 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]

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

* Re: expression and definition context in Scheme
  2022-08-27 17:00 ` Maxime Devos
@ 2022-08-27 19:02   ` Damien Mattei
  2022-08-27 19:14     ` Maxime Devos
  2022-08-27 19:20     ` Maxime Devos
  0 siblings, 2 replies; 12+ messages in thread
From: Damien Mattei @ 2022-08-27 19:02 UTC (permalink / raw)
  To: guile-user, guile-devel

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

hello Maxime,

On Sat, Aug 27, 2022 at 7:00 PM Maxime Devos <maximedevos@telenet.be> wrote:

>
> On 27-08-2022 18:48, Damien Mattei wrote:
>
> My ideas is as it is so easy to cheat the compiler
>
> I don't think it's cheating or abusive.
>
> from seeing the expressio context why does the compiler restrict this?
> expression and defintion context, i'm not sure they are in scheme
> standarts, are they really usefull?
> why not remove this from Scheme at all?
>
> I haven't read the RnRS closely, but I doubt that
>
> (some-procedure (define foo 0) (define bar 0))
>
? i do not understand well the meaning

> is allowed by the standard and that it could be meaningful.
>
in fact just allow 'define that act locally ,see my comment below

> Also, even if (begin ...) and (let () ...) where unified, it would be a
> shame to lose the ability to only have some definitions temporarily:
>
> (define foo 0)
>
> (let ((foo 0))
>   whatever-something-using-the-inner-foo)
>
> something-using-the-outer-foo-again
>
i do not propose foo to overwrite the global one , just to allow local
define that have a local (in the block) range.

> If 'let' was replaced by 'begin', then it would have different semantics.
>
> Greetings,
> Maxime.
>

Regards,
Damien

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

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

* Re: expression and definition context in Scheme
  2022-08-27 19:02   ` Damien Mattei
@ 2022-08-27 19:14     ` Maxime Devos
  2022-08-27 19:20     ` Maxime Devos
  1 sibling, 0 replies; 12+ messages in thread
From: Maxime Devos @ 2022-08-27 19:14 UTC (permalink / raw)
  To: Damien Mattei, guile-user, guile-devel


[-- Attachment #1.1.1: Type: text/plain, Size: 523 bytes --]


On 27-08-2022 21:02, Damien Mattei wrote:
>
>>
>     I haven't read the RnRS closely, but I doubt that
>
>     (some-procedure (define foo 0) (define bar 0))
>
> ? i do not understand well the meaning

Me neither, that's what I meant.

You are proposing to unify expression context and definition context. If 
done, you would need to assign that statement above some meaning somehow.

(define foo 0) is definitely definition context, but it makes no sense 
in expression context.

Greetings,
Maxime.


[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 929 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]

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

* Re: expression and definition context in Scheme
  2022-08-27 19:02   ` Damien Mattei
  2022-08-27 19:14     ` Maxime Devos
@ 2022-08-27 19:20     ` Maxime Devos
       [not found]       ` <CADEOadfCCLaqEvzLYUzEYhg94pqN3r9=c6LT=FmCivJsPudUzg@mail.gmail.com>
  1 sibling, 1 reply; 12+ messages in thread
From: Maxime Devos @ 2022-08-27 19:20 UTC (permalink / raw)
  To: Damien Mattei, guile-user, guile-devel


[-- Attachment #1.1.1: Type: text/plain, Size: 1396 bytes --]


On 27-08-2022 21:02, Damien Mattei wrote:
> in fact just allow 'define that act locally ,see my comment below

I do not know what semantics you want.

>     Also, even if (begin ...) and (let () ...) where unified, it would
>     be a shame to lose the ability to only have some definitions
>     temporarily:
>
>     (define foo 0)
>
>     (let ((foo 0))
>       whatever-something-using-the-inner-foo)
>
>     something-using-the-outer-foo-again
>
> i do not propose foo to overwrite the global one

In that example, (define foo) might be global, but it might as well have 
been

(let ((foo 0))
   (let ((foo 0))
     whatever-something-user-the-inner-foo)
   something-using-the-outer-foo-again)

or

(let ()
   (define foo 0)
   (let ((foo 0))
     whatever-something-user-the-inner-foo)
   something-using-the-outer-foo-again)

I did not assume anything about global/local and wrote nothing about 
overwriting.
> , just to allow local define that have a local (in the block) range.

If with 'block' you mean the local (let ...) form, then this is already 
the case.

If not, maybe you are asking for Python-like lexical variables, but you 
have asked about that in the past -- it's a valid choice, but not Scheme.

If something else, you need to be much less vague and much more precise 
on what you want.

Greetings,
Maxime.


[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 929 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]

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

* Fwd: expression and definition context in Scheme
       [not found]           ` <CADEOadfKR_u3qS5N5MwRuCRTxPjKi_wyWzgv-xJJ96e56X2meg@mail.gmail.com>
@ 2022-08-29 10:10             ` Damien Mattei
  0 siblings, 0 replies; 12+ messages in thread
From: Damien Mattei @ 2022-08-29 10:10 UTC (permalink / raw)
  To: guile-devel, guile-user

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

---------- Forwarded message ---------
From: Damien Mattei <damien.mattei@gmail.com>
Date: Mon, Aug 29, 2022 at 12:09 PM
Subject: Re: expression and definition context in Scheme
To: Maxime Devos <maximedevos@telenet.be>


yes , the same with 'while too, i will make it in my Scheme+ to allow inner
'define in those blocks without other stuff (in Scheme+ i had already a
simple macro : (& ev ...) = (let () ev ...) that replace 'begin when
'define is needed in blocks.

regards,
Damien

On Sun, Aug 28, 2022 at 11:30 AM Maxime Devos <maximedevos@telenet.be>
wrote:

> On 28-08-2022 08:40, Damien Mattei wrote:
>
> in fact my thought was not clear, perhaps just  allow a 'define in an
> instructions as 'when in my example , 'define-ed variable would then be
> local one in the block of 'when, will it change something in scheme
> implementation in a bad way?
>
> Are you asking for 'when' to implicitly wrap its body in a (let () ...)?
>
> If so, that's trivial to implement, without changing the Scheme
> implementation:
>
> (define-syntax-rule (when cond exp ...)
>   (if cond
>       (let () exp ...)))
>
> Greetings,
> Maxime.
>

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

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

* Re: expression and definition context in Scheme
  2022-08-27 16:48 expression and definition context in Scheme Damien Mattei
  2022-08-27 17:00 ` Maxime Devos
@ 2022-08-30 10:47 ` Linus Björnstam
  2022-08-31  7:01   ` Damien Mattei
  2022-09-07 23:12   ` Aleix Conchillo Flaqué
  1 sibling, 2 replies; 12+ messages in thread
From: Linus Björnstam @ 2022-08-30 10:47 UTC (permalink / raw)
  To: Damien Mattei, guile-user, guile-devel

I am working on a patch to guile to add definitions to just about every body except for (begin ...) outside definition context.

The patch is trivial, but I have to document it and a patch to r6rs that makes the r6rs cons work according to spec.

I had a kid recently so it might take some time before I have any computer time, so if anyone has some time this is a really simple thing. You can find the first patch somewhere in this mailing list, it only changes the (begin ...)s in the derived forms in (ice-9 boot-9) to (let () ...). Then i was going to copy the cond and case from the r6rs appendix and add some error reporting.

The most difficult part is documenting it :)

Andy have the idea hos blessing, and will mean guile gets define in expression context in when, unless, cond, case, while, and do as well as in derived forms.

-- 
  Linus Björnstam

On Sat, 27 Aug 2022, at 18:48, Damien Mattei wrote:
> Hello,
>
> i'm facing sometimes recursively the problem to have definitions in 
> expression context, which i manage every time by adding an upper empty 
> (let () my definitions goes here )
> the last case i was facing this probleme is defining a 'for macro:
>
> ;; scheme@(guile-user)> (for ({i <+ 0} {i < 5} {i <- {i + 1}}) (display 
> i) (newline))
> ;; 0
> ;; 1
> ;; 2
> ;; 3
> ;; 4
>
>
> (define-syntax for
>  
>   (syntax-rules ()
>    
>     ((_ (init test incrmt) b1 ...)
>
>        (let ()
>            init
>            (let loop ()
>               (when test
>                     b1 ...
>                     incrmt
>                     (loop)))))))
>
> this one fails in my Scheme+ code below:
> (define (compute-carries n)
>
>   (for ( {k <+ 0}  {k <= n}  {k <- {k + 1}} )
>
>        { Ckp1 <+ (compute-Ck-plus1 k) }
>        (display-nl Ckp1)))
>
> because { Ckp1 <+ (compute-Ck-plus1 k) } expands in :
> (define Ckp1 (compute-Ck-plus1 k))
> and i get a compilation error:
> ;;; Syntax error:
> ;;; logic-syracuse+.scm:15:7: definition in expression context, where 
> definitions are not allowed, in form (define Ckp1 (compute-Ck-plus1 k))
>
> so i replace my 'for macro definition with:
>
> (define-syntax for
>  
>   (syntax-rules ()
>    
>     ((_ (init test incrmt) b1 ...)
>
>        (let ()
>            init
>            (let loop ()
>               (when test
>                 (let ()
>                     b1 ...
>                     incrmt
>                     (loop))))))))
>
> and it works, but you will notice an abusive use of empty (let () ...) 
> in the code to avoid the restrictions of definitions not allowed in 
> expression context. 
>
> My ideas is as it is so easy to cheat the compiler from seeing the 
> expressio context why does the compiler restrict this? expression and 
> defintion context, i'm not sure they are in scheme standarts, are they 
> really usefull?
> why not remove this from Scheme at all?
>
> Regards,
>
> Damien



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

* Re: expression and definition context in Scheme
  2022-08-30 10:47 ` Linus Björnstam
@ 2022-08-31  7:01   ` Damien Mattei
  2022-08-31 15:29     ` Maxime Devos
  2022-09-07 23:12   ` Aleix Conchillo Flaqué
  1 sibling, 1 reply; 12+ messages in thread
From: Damien Mattei @ 2022-08-31  7:01 UTC (permalink / raw)
  To: Linus Björnstam; +Cc: guile-user, guile-devel

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

Hello Linus,

if you have a repo somewhere with code this could be interesting ? do you
think this could be set in the main code of guile? or is it just a personal
project? there is two options, one is to have guile modified for doing this
, the other is: i can modify when, unless, cond, case, while, and do and
insert those macro in my Scheme+ project. I always try to keep
compatibility with RnRS and in fact except cond none of when, unless, cond,
case, while, and do are in standart RnRS scheme, anyway having the
possibility to use 'define in any of those when, unless, cond, case, while,
and do does not remove any backward compatibility. About documentation,
there should not be a lot of work. I can do all that if it is possible to
make it in guile repository if you have no time.

Regards,
Damien

On Tue, Aug 30, 2022 at 12:47 PM Linus Björnstam <
linus.bjornstam@veryfast.biz> wrote:

> I am working on a patch to guile to add definitions to just about every
> body except for (begin ...) outside definition context.
>
> The patch is trivial, but I have to document it and a patch to r6rs that
> makes the r6rs cons work according to spec.
>
> I had a kid recently so it might take some time before I have any computer
> time, so if anyone has some time this is a really simple thing. You can
> find the first patch somewhere in this mailing list, it only changes the
> (begin ...)s in the derived forms in (ice-9 boot-9) to (let () ...). Then i
> was going to copy the cond and case from the r6rs appendix and add some
> error reporting.
>
> The most difficult part is documenting it :)
>
> Andy have the idea hos blessing, and will mean guile gets define in
> expression context in when, unless, cond, case, while, and do as well as in
> derived forms.
>
> --
>   Linus Björnstam
>
> On Sat, 27 Aug 2022, at 18:48, Damien Mattei wrote:
> > Hello,
> >
> > i'm facing sometimes recursively the problem to have definitions in
> > expression context, which i manage every time by adding an upper empty
> > (let () my definitions goes here )
> > the last case i was facing this probleme is defining a 'for macro:
> >
> > ;; scheme@(guile-user)> (for ({i <+ 0} {i < 5} {i <- {i + 1}}) (display
> > i) (newline))
> > ;; 0
> > ;; 1
> > ;; 2
> > ;; 3
> > ;; 4
> >
> >
> > (define-syntax for
> >
> >   (syntax-rules ()
> >
> >     ((_ (init test incrmt) b1 ...)
> >
> >        (let ()
> >            init
> >            (let loop ()
> >               (when test
> >                     b1 ...
> >                     incrmt
> >                     (loop)))))))
> >
> > this one fails in my Scheme+ code below:
> > (define (compute-carries n)
> >
> >   (for ( {k <+ 0}  {k <= n}  {k <- {k + 1}} )
> >
> >        { Ckp1 <+ (compute-Ck-plus1 k) }
> >        (display-nl Ckp1)))
> >
> > because { Ckp1 <+ (compute-Ck-plus1 k) } expands in :
> > (define Ckp1 (compute-Ck-plus1 k))
> > and i get a compilation error:
> > ;;; Syntax error:
> > ;;; logic-syracuse+.scm:15:7: definition in expression context, where
> > definitions are not allowed, in form (define Ckp1 (compute-Ck-plus1 k))
> >
> > so i replace my 'for macro definition with:
> >
> > (define-syntax for
> >
> >   (syntax-rules ()
> >
> >     ((_ (init test incrmt) b1 ...)
> >
> >        (let ()
> >            init
> >            (let loop ()
> >               (when test
> >                 (let ()
> >                     b1 ...
> >                     incrmt
> >                     (loop))))))))
> >
> > and it works, but you will notice an abusive use of empty (let () ...)
> > in the code to avoid the restrictions of definitions not allowed in
> > expression context.
> >
> > My ideas is as it is so easy to cheat the compiler from seeing the
> > expressio context why does the compiler restrict this? expression and
> > defintion context, i'm not sure they are in scheme standarts, are they
> > really usefull?
> > why not remove this from Scheme at all?
> >
> > Regards,
> >
> > Damien
>

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

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

* Re: expression and definition context in Scheme
  2022-08-31  7:01   ` Damien Mattei
@ 2022-08-31 15:29     ` Maxime Devos
  2022-09-01 20:21       ` Damien Mattei
  0 siblings, 1 reply; 12+ messages in thread
From: Maxime Devos @ 2022-08-31 15:29 UTC (permalink / raw)
  To: Damien Mattei, Linus Björnstam; +Cc: guile-user, guile-devel


[-- Attachment #1.1.1: Type: text/plain, Size: 402 bytes --]


On 31-08-2022 09:01, Damien Mattei wrote:
> I always try to keep compatibility with RnRS and in fact except cond 
> none of when, unless, cond, case, while, and do are in standart RnRS schem

'when', 'unless' and 'do' are actually RnRS, see (rnrs control).

'case' is also RnRS, see (rnrs base).

However, looking at (guile)while do, 'while' is indeed non-standard.

Greetings,
Maxime.


[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 929 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]

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

* Re: expression and definition context in Scheme
  2022-08-31 15:29     ` Maxime Devos
@ 2022-09-01 20:21       ` Damien Mattei
  2022-09-04  8:08         ` Damien Mattei
  0 siblings, 1 reply; 12+ messages in thread
From: Damien Mattei @ 2022-09-01 20:21 UTC (permalink / raw)
  To: Maxime Devos; +Cc: Linus Björnstam, guile-user, guile-devel

On Wed, Aug 31, 2022 at 5:29 PM Maxime Devos <maximedevos@telenet.be> wrote:

>
> On 31-08-2022 09:01, Damien Mattei wrote:
> > I always try to keep compatibility with RnRS and in fact except cond
> > none of when, unless, cond, case, while, and do are in standart RnRS
> schem
>
> 'when', 'unless' and 'do' are actually RnRS, see (rnrs control).
>

oh your're right...i was sticked to R5RS ,time i was student...

>
> 'case' is also RnRS, see (rnrs base).
>
> However, looking at (guile)while do, 'while' is indeed non-standard.
>

and i had rewritten last week a 'while ... do' like in C or Pascal:
https://www.tutorialspoint.com/pascal/pascal_while_do_loop.htm
https://www.tutorialspoint.com/cprogramming/c_while_loop.htm

in my Scheme+:

;; (define do '())
;; (while {i < 4}
;;    do
;;      (display i)
;;      (newline)
;;      {i <- {i + 1}})
;; 0
;; 1
;; 2
;; 3
;; $1 = #f
(define-syntax while
  (syntax-rules (while do)
    ((_ pred do b1 ...)
     (let loop () (when pred b1 ... (loop))))))

i will have to forget it! as i want to keep compatibility with standard
Scheme also but i will rewrite all with (let () ...) instead of (begin ...)
unless it can cause some incompatibilities, for now , i do not see problems
as "who can do more can do less"......

Regards,
Damien

>
>


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

* Re: expression and definition context in Scheme
  2022-09-01 20:21       ` Damien Mattei
@ 2022-09-04  8:08         ` Damien Mattei
  0 siblings, 0 replies; 12+ messages in thread
From: Damien Mattei @ 2022-09-04  8:08 UTC (permalink / raw)
  To: Maxime Devos; +Cc: Linus Björnstam, guile-user, guile-devel

i finalize my ideas about 'controls' and loops (with break and continue, as
while feature them ,even if scheme and macro do not allow ? (if someone
else have idea and solution about it?) implements of 'continue and 'break
because hygiene forbid it)
https://github.com/damien-mattei/library-FunctProg/blob/master/while-do-when-unless.scm

;; scheme@(guile-user)> (for/break-cont break continue ({i <+ 0} {i < 5} {i
<- {i + 1}}) {x <+ 7} (display x) (newline))
;; 7
;; 7
;; 7
;; 7
;; 7

;; scheme@(guile-user)> (for/break-cont break continue ({i <+ 0} {i < 5} {i
<- {i + 1}}) {x <+ 7} (display x) (newline) (break))
;;7

;; scheme@(guile-user)> (for/break-cont break continue ({i <+ 0} {i < 5} {i
<- {i + 1}}) {x <+ 7} (continue) (display x) (newline) (break))

(define-syntax for/break-cont

  (syntax-rules ()

    ((_ <break-id> <continue-id> (init test incrmt) b1 ...)

     (call/cc (lambda (<break-id>)
(let ()
 init
 (let loop ()
   (when test
 (call/cc (lambda (<continue-id>) b1 ...))
 incrmt
 (loop)))))))))

https://github.com/damien-mattei/library-FunctProg/blob/master/for-next-step.scm

Damien

On Thu, Sep 1, 2022 at 10:21 PM Damien Mattei <damien.mattei@gmail.com>
wrote:

> On Wed, Aug 31, 2022 at 5:29 PM Maxime Devos <maximedevos@telenet.be>
> wrote:
>
>>
>> On 31-08-2022 09:01, Damien Mattei wrote:
>> > I always try to keep compatibility with RnRS and in fact except cond
>> > none of when, unless, cond, case, while, and do are in standart RnRS
>> schem
>>
>> 'when', 'unless' and 'do' are actually RnRS, see (rnrs control).
>>
>
> oh your're right...i was sticked to R5RS ,time i was student...
>
>>
>> 'case' is also RnRS, see (rnrs base).
>>
>> However, looking at (guile)while do, 'while' is indeed non-standard.
>>
>
> and i had rewritten last week a 'while ... do' like in C or Pascal:
> https://www.tutorialspoint.com/pascal/pascal_while_do_loop.htm
> https://www.tutorialspoint.com/cprogramming/c_while_loop.htm
>
> in my Scheme+:
>
> ;; (define do '())
> ;; (while {i < 4}
> ;;    do
> ;;      (display i)
> ;;      (newline)
> ;;      {i <- {i + 1}})
> ;; 0
> ;; 1
> ;; 2
> ;; 3
> ;; $1 = #f
> (define-syntax while
>   (syntax-rules (while do)
>     ((_ pred do b1 ...)
>      (let loop () (when pred b1 ... (loop))))))
>
> i will have to forget it! as i want to keep compatibility with standard
> Scheme also but i will rewrite all with (let () ...) instead of (begin ...)
> unless it can cause some incompatibilities, for now , i do not see problems
> as "who can do more can do less"......
>
> Regards,
> Damien
>
>>
>>


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

* Re: expression and definition context in Scheme
  2022-08-30 10:47 ` Linus Björnstam
  2022-08-31  7:01   ` Damien Mattei
@ 2022-09-07 23:12   ` Aleix Conchillo Flaqué
  1 sibling, 0 replies; 12+ messages in thread
From: Aleix Conchillo Flaqué @ 2022-09-07 23:12 UTC (permalink / raw)
  To: Linus Björnstam; +Cc: Damien Mattei, guile-user, guile-devel

Just came here to say: Congratulations Linus! That was definitely the most
important part of your message :-).

Aleix

On Tue, Aug 30, 2022 at 3:48 AM Linus Björnstam <
linus.bjornstam@veryfast.biz> wrote:

> I am working on a patch to guile to add definitions to just about every
> body except for (begin ...) outside definition context.
>
> The patch is trivial, but I have to document it and a patch to r6rs that
> makes the r6rs cons work according to spec.
>
> I had a kid recently so it might take some time before I have any computer
> time, so if anyone has some time this is a really simple thing. You can
> find the first patch somewhere in this mailing list, it only changes the
> (begin ...)s in the derived forms in (ice-9 boot-9) to (let () ...). Then i
> was going to copy the cond and case from the r6rs appendix and add some
> error reporting.
>
> The most difficult part is documenting it :)
>
> Andy have the idea hos blessing, and will mean guile gets define in
> expression context in when, unless, cond, case, while, and do as well as in
> derived forms.
>
> --
>   Linus Björnstam
>
> On Sat, 27 Aug 2022, at 18:48, Damien Mattei wrote:
> > Hello,
> >
> > i'm facing sometimes recursively the problem to have definitions in
> > expression context, which i manage every time by adding an upper empty
> > (let () my definitions goes here )
> > the last case i was facing this probleme is defining a 'for macro:
> >
> > ;; scheme@(guile-user)> (for ({i <+ 0} {i < 5} {i <- {i + 1}}) (display
> > i) (newline))
> > ;; 0
> > ;; 1
> > ;; 2
> > ;; 3
> > ;; 4
> >
> >
> > (define-syntax for
> >
> >   (syntax-rules ()
> >
> >     ((_ (init test incrmt) b1 ...)
> >
> >        (let ()
> >            init
> >            (let loop ()
> >               (when test
> >                     b1 ...
> >                     incrmt
> >                     (loop)))))))
> >
> > this one fails in my Scheme+ code below:
> > (define (compute-carries n)
> >
> >   (for ( {k <+ 0}  {k <= n}  {k <- {k + 1}} )
> >
> >        { Ckp1 <+ (compute-Ck-plus1 k) }
> >        (display-nl Ckp1)))
> >
> > because { Ckp1 <+ (compute-Ck-plus1 k) } expands in :
> > (define Ckp1 (compute-Ck-plus1 k))
> > and i get a compilation error:
> > ;;; Syntax error:
> > ;;; logic-syracuse+.scm:15:7: definition in expression context, where
> > definitions are not allowed, in form (define Ckp1 (compute-Ck-plus1 k))
> >
> > so i replace my 'for macro definition with:
> >
> > (define-syntax for
> >
> >   (syntax-rules ()
> >
> >     ((_ (init test incrmt) b1 ...)
> >
> >        (let ()
> >            init
> >            (let loop ()
> >               (when test
> >                 (let ()
> >                     b1 ...
> >                     incrmt
> >                     (loop))))))))
> >
> > and it works, but you will notice an abusive use of empty (let () ...)
> > in the code to avoid the restrictions of definitions not allowed in
> > expression context.
> >
> > My ideas is as it is so easy to cheat the compiler from seeing the
> > expressio context why does the compiler restrict this? expression and
> > defintion context, i'm not sure they are in scheme standarts, are they
> > really usefull?
> > why not remove this from Scheme at all?
> >
> > Regards,
> >
> > Damien
>
>


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

end of thread, other threads:[~2022-09-07 23:12 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-27 16:48 expression and definition context in Scheme Damien Mattei
2022-08-27 17:00 ` Maxime Devos
2022-08-27 19:02   ` Damien Mattei
2022-08-27 19:14     ` Maxime Devos
2022-08-27 19:20     ` Maxime Devos
     [not found]       ` <CADEOadfCCLaqEvzLYUzEYhg94pqN3r9=c6LT=FmCivJsPudUzg@mail.gmail.com>
     [not found]         ` <b95df274-b727-5bb9-4657-f263a837e0f1@telenet.be>
     [not found]           ` <CADEOadfKR_u3qS5N5MwRuCRTxPjKi_wyWzgv-xJJ96e56X2meg@mail.gmail.com>
2022-08-29 10:10             ` Fwd: " Damien Mattei
2022-08-30 10:47 ` Linus Björnstam
2022-08-31  7:01   ` Damien Mattei
2022-08-31 15:29     ` Maxime Devos
2022-09-01 20:21       ` Damien Mattei
2022-09-04  8:08         ` Damien Mattei
2022-09-07 23:12   ` Aleix Conchillo Flaqué

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