unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* using a module : rename a single definition
@ 2024-03-03  8:46 Damien Mattei
  2024-03-03 11:50 ` Tomas Volf
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Damien Mattei @ 2024-03-03  8:46 UTC (permalink / raw)
  To: guile-user

hello,

is it possible to import a module having just one variable renamed (not
all) , as in Racket:

(require (rename-in srfi/42
             (: s42:))) ; Eager Comprehensions

it seems in Guile either all is imported and prefixed or only a selection
of bindings can be imported:

https://www.gnu.org/software/guile/manual/html_node/Using-Guile-Modules.html

(use-modules ((ice-9 popen)
              #:select ((open-pipe . pipe-open) close-pipe)
              #:prefix unixy:))

regards,


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

* Re: using a module : rename a single definition
  2024-03-03  8:46 using a module : rename a single definition Damien Mattei
@ 2024-03-03 11:50 ` Tomas Volf
  2024-03-03 14:37   ` Damien Mattei
  2024-03-03 12:55 ` tomas
  2024-03-19 23:09 ` Maxime Devos
  2 siblings, 1 reply; 8+ messages in thread
From: Tomas Volf @ 2024-03-03 11:50 UTC (permalink / raw)
  To: Damien Mattei; +Cc: guile-user

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

On 2024-03-03 09:46:41 +0100, Damien Mattei wrote:
> hello,
>
> is it possible to import a module having just one variable renamed (not
> all) , as in Racket:
>
> (require (rename-in srfi/42
>              (: s42:))) ; Eager Comprehensions
>
> it seems in Guile either all is imported and prefixed or only a selection
> of bindings can be imported:
>
> https://www.gnu.org/software/guile/manual/html_node/Using-Guile-Modules.html
>
> (use-modules ((ice-9 popen)
>               #:select ((open-pipe . pipe-open) close-pipe)
>               #:prefix unixy:))
>
> regards,

There does not seem to be a way to *exclude* a single symbol from the import,
but, if you do not mind having *also* the original symbol (or if you will just
override it later with something else anyway), it seems you can do something
like this:

    (use-modules (ice-9 popen)
                 ((ice-9 popen) #:select ((open-pipe . foo-bar))))

After that you have both `open-pipe' and `foo-bar' available, pointing to the
same procedure.  At this point you could just re-define `open-pipe' to something
else and use the `foo-bar'.

Maybe there is a better way, but I did not find it in the manual.

Have a nice day,
Tomas Volf

--
There are only two hard things in Computer Science:
cache invalidation, naming things and off-by-one errors.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: using a module : rename a single definition
  2024-03-03  8:46 using a module : rename a single definition Damien Mattei
  2024-03-03 11:50 ` Tomas Volf
@ 2024-03-03 12:55 ` tomas
  2024-03-19 23:09 ` Maxime Devos
  2 siblings, 0 replies; 8+ messages in thread
From: tomas @ 2024-03-03 12:55 UTC (permalink / raw)
  To: Damien Mattei; +Cc: guile-user

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

On Sun, Mar 03, 2024 at 09:46:41AM +0100, Damien Mattei wrote:
> hello,
> 
> is it possible to import a module having just one variable renamed (not
> all) , as in Racket:
> 
> (require (rename-in srfi/42
>              (: s42:))) ; Eager Comprehensions
> 
> it seems in Guile either all is imported and prefixed or only a selection
> of bindings can be imported:

I was under the impression that #:renamer should give us enough rope
to shoot anyone in the foot ;-)

A quick and unscientific test -- this one should rename xcons to snoc
and leave all the rest of srfi-1 alone:

  tomas@trotzki:~$ guile
  GNU Guile 3.0.9.120-79e836-dirty
  Copyright (C) 1995-2023 Free Software Foundation, Inc.
  scheme@(guile-user)> (use-modules ( (srfi srfi-1)
                                      #:renamer (lambda (sym)
                                                  (if (eq? sym 'xcons)
                                                        'snoc
                                                        sym))))
  
  scheme@(guile-user)> (snoc 'a 'b)
  $1 = (b . a)

Cheers
-- 
t

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

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

* Re: using a module : rename a single definition
  2024-03-03 11:50 ` Tomas Volf
@ 2024-03-03 14:37   ` Damien Mattei
  0 siblings, 0 replies; 8+ messages in thread
From: Damien Mattei @ 2024-03-03 14:37 UTC (permalink / raw)
  To: Damien Mattei, guile-user

yes , your solution works, thanks :

(use-modules (Scheme+)
    (matrix+)
    (srfi srfi-42) ; import all definitions
    ((srfi srfi-42)
            #:select ((: . s42-:))) ; rename only one
    ;;((srfi srfi-42) ; Eager Comprehensions
    ;; #:prefix s42-)
    (oop goops)
    (srfi srfi-43)) ; vectors

used in code:

{M <- (vector-ec (s42-: n {lnc - 1}) ; vectors by eager comprehension (SRFI
42)
                            create-matrix-by-function(uniform-dummy nc[n +
1] {nc[n] + 1}))} ;; Matrix-vect

after parsing (convert curly infix scheme+ to classic scheme):

(<- M
      (vector-ec
        (s42-: n (- lnc 1))
        (create-matrix-by-function
          uniform-dummy
          ($bracket-apply$next nc (list (+ n 1)))
          (+ ($bracket-apply$next nc (list n)) 1))))

i tested also the solution of tomas and it works too:

(use-modules (Scheme+)
    (matrix+)
    ;(srfi srfi-42) ; import all definitions
             ((srfi srfi-42)
#:renamer (lambda (sym)
                              (if (eq? sym ':)
                                  's42-:
                                  sym)))
;#:select ((: . s42-:))) ; rename only one
    ;;((srfi srfi-42) ; Eager Comprehensions
;; #:prefix s42-)
    (oop goops)
    (srfi srfi-43)) ; vectors

Merçi

Damien

On Sun, Mar 3, 2024 at 12:50 PM Tomas Volf <~@wolfsden.cz> wrote:

> On 2024-03-03 09:46:41 +0100, Damien Mattei wrote:
> > hello,
> >
> > is it possible to import a module having just one variable renamed (not
> > all) , as in Racket:
> >
> > (require (rename-in srfi/42
> >              (: s42:))) ; Eager Comprehensions
> >
> > it seems in Guile either all is imported and prefixed or only a selection
> > of bindings can be imported:
> >
> >
> https://www.gnu.org/software/guile/manual/html_node/Using-Guile-Modules.html
> >
> > (use-modules ((ice-9 popen)
> >               #:select ((open-pipe . pipe-open) close-pipe)
> >               #:prefix unixy:))
> >
> > regards,
>
> There does not seem to be a way to *exclude* a single symbol from the
> import,
> but, if you do not mind having *also* the original symbol (or if you will
> just
> override it later with something else anyway), it seems you can do
> something
> like this:
>
>     (use-modules (ice-9 popen)
>                  ((ice-9 popen) #:select ((open-pipe . foo-bar))))
>
> After that you have both `open-pipe' and `foo-bar' available, pointing to
> the
> same procedure.  At this point you could just re-define `open-pipe' to
> something
> else and use the `foo-bar'.
>
> Maybe there is a better way, but I did not find it in the manual.
>
> Have a nice day,
> Tomas Volf
>
> --
> There are only two hard things in Computer Science:
> cache invalidation, naming things and off-by-one errors.
>


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

* RE: using a module : rename a single definition
  2024-03-03  8:46 using a module : rename a single definition Damien Mattei
  2024-03-03 11:50 ` Tomas Volf
  2024-03-03 12:55 ` tomas
@ 2024-03-19 23:09 ` Maxime Devos
  2024-03-27  7:42   ` Damien Mattei
  2 siblings, 1 reply; 8+ messages in thread
From: Maxime Devos @ 2024-03-19 23:09 UTC (permalink / raw)
  To: Damien Mattei, guile-user

Yes, with ‘library’ or ‘define-library’ forms.
 
(see https://www.gnu.org/software/guile/manual/html_node/R6RS-Libraries.html)

(library (insert name here)
  (export [insert exports here])
  (import
    (guile) ; standard imports
    (rename (ice-9 popen) (open-pipe pipe-open)))
  [insert definitions here])



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

* Re: using a module : rename a single definition
  2024-03-19 23:09 ` Maxime Devos
@ 2024-03-27  7:42   ` Damien Mattei
  2024-03-27 10:47     ` Hans-Werner Roitzsch
  0 siblings, 1 reply; 8+ messages in thread
From: Damien Mattei @ 2024-03-27  7:42 UTC (permalink / raw)
  To: Maxime Devos; +Cc: guile-user

yes it should works. I trying to port all my scheme code in R6RS library
style for compatibility,it's a bit complex depending the integration of
R6RS in a particular scheme but i think there should be a compatibility
advantage doing that.

Damien

On Wed, Mar 20, 2024 at 12:09 AM Maxime Devos <maximedevos@telenet.be>
wrote:

> Yes, with ‘library’ or ‘define-library’ forms.
>
> (see
> https://www.gnu.org/software/guile/manual/html_node/R6RS-Libraries.html)
>
>
>
> (library (insert name here)
>
>   (export [insert exports here])
>
>   (import
>
>     (guile) ; standard imports
>
>     (rename (ice-9 popen) (open-pipe pipe-open)))
>
>   [insert definitions here])
>
>
>


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

* Re: using a module : rename a single definition
  2024-03-27  7:42   ` Damien Mattei
@ 2024-03-27 10:47     ` Hans-Werner Roitzsch
  2024-03-27 11:44       ` Damien Mattei
  0 siblings, 1 reply; 8+ messages in thread
From: Hans-Werner Roitzsch @ 2024-03-27 10:47 UTC (permalink / raw)
  To: Damien Mattei; +Cc: guile-user

Hello Damien,

Be aware though, that porting some exports may not work without renaming them:

https://lists.gnu.org/archive/html/guile-user/2023-06/msg00020.html

Regards,
Zelphir

On 3/27/24 08:42, Damien Mattei wrote:
> yes it should works. I trying to port all my scheme code in R6RS library
> style for compatibility,it's a bit complex depending the integration of
> R6RS in a particular scheme but i think there should be a compatibility
> advantage doing that.
>
> Damien
>
> On Wed, Mar 20, 2024 at 12:09 AM Maxime Devos <maximedevos@telenet.be>
> wrote:
>
>> Yes, with ‘library’ or ‘define-library’ forms.
>>
>> (see
>> https://www.gnu.org/software/guile/manual/html_node/R6RS-Libraries.html)
>>
>>
>>
>> (library (insert name here)
>>
>>    (export [insert exports here])
>>
>>    (import
>>
>>      (guile) ; standard imports
>>
>>      (rename (ice-9 popen) (open-pipe pipe-open)))
>>
>>    [insert definitions here])
>>
>>
>>



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

* Re: using a module : rename a single definition
  2024-03-27 10:47     ` Hans-Werner Roitzsch
@ 2024-03-27 11:44       ` Damien Mattei
  0 siblings, 0 replies; 8+ messages in thread
From: Damien Mattei @ 2024-03-27 11:44 UTC (permalink / raw)
  To: Hans-Werner Roitzsch; +Cc: guile-user

thank you for the advice,for now i'm trying with Racket r6rs support and it
is not easy,
the solution in guile seems to be to rename or to use the define-module
style instead of the r6rs library, if only a name in the new library is the
same as an existing name in guile library it is not usable as it is
re-exported as the guile original binding.
If really the problem is so important i'm not sure to use r6rs with guile
now.
regards,
damien

On Wed, Mar 27, 2024 at 11:47 AM Hans-Werner Roitzsch <hwroitzsch@posteo.net>
wrote:

> Hello Damien,
>
> Be aware though, that porting some exports may not work without renaming
> them:
>
> https://lists.gnu.org/archive/html/guile-user/2023-06/msg00020.html
>
> Regards,
> Zelphir
>
> On 3/27/24 08:42, Damien Mattei wrote:
> > yes it should works. I trying to port all my scheme code in R6RS library
> > style for compatibility,it's a bit complex depending the integration of
> > R6RS in a particular scheme but i think there should be a compatibility
> > advantage doing that.
> >
> > Damien
> >
> > On Wed, Mar 20, 2024 at 12:09 AM Maxime Devos <maximedevos@telenet.be>
> > wrote:
> >
> >> Yes, with ‘library’ or ‘define-library’ forms.
> >>
> >> (see
> >> https://www.gnu.org/software/guile/manual/html_node/R6RS-Libraries.html
> )
> >>
> >>
> >>
> >> (library (insert name here)
> >>
> >>    (export [insert exports here])
> >>
> >>    (import
> >>
> >>      (guile) ; standard imports
> >>
> >>      (rename (ice-9 popen) (open-pipe pipe-open)))
> >>
> >>    [insert definitions here])
> >>
> >>
> >>
>


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

end of thread, other threads:[~2024-03-27 11:44 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-03  8:46 using a module : rename a single definition Damien Mattei
2024-03-03 11:50 ` Tomas Volf
2024-03-03 14:37   ` Damien Mattei
2024-03-03 12:55 ` tomas
2024-03-19 23:09 ` Maxime Devos
2024-03-27  7:42   ` Damien Mattei
2024-03-27 10:47     ` Hans-Werner Roitzsch
2024-03-27 11:44       ` Damien Mattei

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