unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: "Linus Björnstam" <linus.bjornstam@veryfast.biz>
To: "Damien Mattei" <damien.mattei@gmail.com>,
	guile-user <guile-user@gnu.org>,
	guile-devel <guile-devel@gnu.org>
Subject: Re: expression and definition context in Scheme
Date: Tue, 30 Aug 2022 12:47:06 +0200	[thread overview]
Message-ID: <a1f66de8-15fe-4166-8ef5-5864272aeedb@www.fastmail.com> (raw)
In-Reply-To: <CADEOadf5pS917wVJhrNtMU7N_-3=g71CEeRKai+-NZMXsVE1BQ@mail.gmail.com>

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



  parent reply	other threads:[~2022-08-30 10:47 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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é

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

  List information: https://www.gnu.org/software/guile/

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

  git send-email \
    --in-reply-to=a1f66de8-15fe-4166-8ef5-5864272aeedb@www.fastmail.com \
    --to=linus.bjornstam@veryfast.biz \
    --cc=damien.mattei@gmail.com \
    --cc=guile-devel@gnu.org \
    --cc=guile-user@gnu.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).