guile-user
[Top][All Lists]
Advanced

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

Re: using a module : rename a single definition


From: Damien Mattei
Subject: Re: using a module : rename a single definition
Date: Sun, 3 Mar 2024 15:37:02 +0100

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


reply via email to

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