unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Matt Wette <matt.wette@gmail.com>
To: "Damien Mattei" <damien.mattei@gmail.com>,
	"Linus Björnstam" <linus.bjornstam@veryfast.biz>
Cc: Guile User <guile-user@gnu.org>
Subject: Re: wayland client in Guile without libwayland-client
Date: Sat, 19 Nov 2022 06:50:34 -0800	[thread overview]
Message-ID: <437221f0-7181-505f-535d-8e0604ef30d5@gmail.com> (raw)
In-Reply-To: <CADEOadc478SuTEeFmKh==ng55Tmv+WW2H4OhinS3=ttM3wM5MQ@mail.gmail.com>

On 11/18/22 8:26 PM, Damien Mattei wrote:
> hello,
>
> it is just a question about semantic and aside the subject of project, and
> related to another subject of internal definitions that Linus is talking
> about:
>
> On Fri, Nov 18, 2022 at 5:55 PM Matt Wette<matt.wette@gmail.com>  wrote:
>
>> Here is an example of an auto-coded event decoder:
>>
>>         (lambda (obj-id bv ix cm)
>>           "event decoder for global"
>>           (let*-values
>>             (((name ix) (dec-u32 bv ix))
>>              ((interface ix) (dec-string bv ix))
>>              ((version ix) (dec-u32 bv ix)))
>>             (values obj-id name interface version)))
>>
>>
>>
> i was just thinking how i would write the procedure above in Scheme+ (
> https://github.com/damien-mattei/Scheme-PLUS-for-Guile  ) that has feature
> for multiple values.
> this code could be rewritten like that:
> (lambda (obj-id bv ix cm)
>           "event decoder for global"
>           {(name ix) <+ (dec-u32 bv ix)}
>           {(interface ix) <+ (dec-string bv ix)}
>           {(version ix) <+ (dec-u32 bv ix)}
>             (values obj-id name interface version))
>
> note that <+ is an "operator" that allows multiple values definitions.
>
> but it would fails to compile because of multiple redefinition of ix
> variable:
>
> scheme@(guile-user)> (use-modules (Scheme+))
> scheme@(guile-user)> (lambda (obj-id bv ix cm)
>           "event decoder for global"
>           {(name ix) <+ (dec-u32 bv ix)}
>           {(interface ix) <+ (dec-string bv ix)}
>           {(version ix) <+ (dec-u32 bv ix)}
>             (values obj-id name interface version))
> While compiling expression:
> Syntax error:
> unknownfile:7:0: invalid or duplicate identifier in definition in form
> (lambda (obj-id bv ix cm) "event decoder for global" (<+ (name ix) (dec-u32
> bv ix)) (<+ (interface ix) (dec-string bv ix)) (<+ (version ix) (dec-u32 bv
> ix)) (values obj-id name interface version))
>
> a longer and a bit unsightly solution could be:
>
> (lambda (obj-id bv ix cm)
>           "event decoder for global"
>           (declare name interface version)
>           {(name ix) <v (dec-u32 bv ix)}
>           {(interface ix) <v (dec-string bv ix)}
>           {(version ix) <v (dec-u32 bv ix)}
>             (values obj-id name interface version))
>
> that would be correct:
>
> (note <v instead of <+ is a setter! for already defined values and declare
> just define variables initialised by default with '() in Scheme+)
>
> scheme@(guile-user)> (lambda (obj-id bv ix cm)
>           "event decoder for global"
>           (declare name interface version)
>           {(name ix) <v (dec-u32 bv ix)}
>           {(interface ix) <v (dec-string bv ix)}
>           {(version ix) <v (dec-u32 bv ix)}
>             (values obj-id name interface version))
> ;;; <stdin>:16:24: warning: possibly unbound variable `dec-u32'
> ;;; <stdin>:17:29: warning: possibly unbound variable `dec-string'
> $3 = #<procedure 149009320 at <unknown port>:13:0 (obj-id bv ix cm)>
>
> the first example fails not because of my Scheme+ language extension but
> because in scheme redefinition is only allowed at toplevel or in the REPL.
>
> Would it not be a good idea to allow redefinitions in Scheme and Guile not
> only at toplevel or REPL but in procedure definitions and lambda, in their
> bodies?
>
> personaly i can not see any "bad" side effect or consequences... of course
> it relax the possibility of code error by unchecking a redefinition of
> variable but it is like in C++ where you can define private or protected
> variables but even with protective language feature one can wrote bad
> code...
>
> Best regards,
>
> Damien

Another approach might be a state monad (guix has code for this).   I am not sure
about other implementations, but I am reasonably confident that the Guile compiler
can turn my values-heavy Scheme into efficient bytecode.  I'm also working to
keep allocations down also (e.g., reusing bytevector buffers).

Thanks for your interest.
Matt


      reply	other threads:[~2022-11-19 14:50 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-18 16:54 wayland client in Guile without libwayland-client Matt Wette
2022-11-18 17:03 ` Matt Wette
2022-11-18 22:34 ` Maxime Devos
2022-11-18 22:58   ` Matt Wette
2022-11-19  4:26 ` Damien Mattei
2022-11-19 14:50   ` Matt Wette [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

  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=437221f0-7181-505f-535d-8e0604ef30d5@gmail.com \
    --to=matt.wette@gmail.com \
    --cc=damien.mattei@gmail.com \
    --cc=guile-user@gnu.org \
    --cc=linus.bjornstam@veryfast.biz \
    /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).