guile-user
[Top][All Lists]
Advanced

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

Re: wayland client in Guile without libwayland-client


From: Damien Mattei
Subject: Re: wayland client in Guile without libwayland-client
Date: Sat, 19 Nov 2022 05:26:53 +0100

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:
unknown file: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


reply via email to

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