guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: expression and definition context in Scheme


From: Damien Mattei
Subject: Re: expression and definition context in Scheme
Date: Wed, 31 Aug 2022 09:01:34 +0200

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
>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]