Re: Overwriting definitions with tm-define

TeXmacs <[email protected]>
Newsgroups gmane.editors.texmacs.devel
Message-ID <[email protected]>
Hi,

Not all scheme functions were defined using tm-define.
The function 'translate' is defined in the glue, so it cannot be tm-overloaded.

Functions that _are_ defined using tm-define can perfectly be overloaded to
take a different number of parameters.  For instance, kbd-return takes zero arguments,
but you can overload it as follows:

  (tm-define (kbd-return . args)
    (:require (nnull? args))
    (display* "kbd-return " args "\n"))

What you cannot do is "overload" it like this:

  (tm-define (kbd-return arg)
    (display* "kbd-return " arg "\n"))

because that is really a redefinition instead of overloading a previous definition.
Overloaded definitions usually come with a ':require' or ':mode' clause,
or with an explicit call of the 'former' primitive:

  (tm-define (kbd-return . args)
    (if (null? args) (former)
        (display* "kbd-return " args "\n")))

If you want to overload a function that was not defined using 'tm-define'
then you can proceed as follows:

  (define built-in-translate translate)

  (tm-define (translate . args)
    (if (== (length args) 1)
        (apply built-in-translate args)
        (apply my-own-translate args)))

I do not think that we need a separate primitive for overloaded definitions
(as Max suggests).  On the other hand, we might want to use different scoping
rules in the future.  We might also automatically consider a tm-define
with a fixed number of arguments as overloading potential previous definitions
with different numbers of arguments.  Maybe that was what Giovanni was expecting.

Best wishes, --Joris



On Thu, Dec 24, 2020 at 12:13:43PM +0100, Massimiliano Gubinelli wrote:
> Hi Giovanni,
>  very likely "translate" is already defined otherwise and overloading it with different number of parameters is not possible.
> 
> I think this speaks for a request I was making to Joris, that is to distinguish the *definition* of a new overloadable function and its *overloading*. Both operation are currently handled by tm-define but from my point of view this is not very nice. Especially because the tm-defined functions are by default imported in all texmacs modules.
> 
> Max
> 
> 
> 
> > On 23. Dec 2020, at 23:36, Giovanni Piredda <[email protected]> wrote:
> > 
> > Dear developers - dear all,
> > 
> > I have noticed that trying to redefine with tm-define the procedure "translate" gets TeXmacs in a non-recoverable state. I found it out as I wanted to call "translate" a graphical procedure.
> > 
> > One error message is
> > 
> > Guile error: ((wrong-number-of-args #f Wrong number of arguments to ~A (#<procedure translate (a b c)>) #f))
> > .../TeXmacs/progs/kernel/boot/debug.scm:231:19: In procedure throw in expression (apply throw err):
> > .../TeXmacs/progs/kernel/boot/debug.scm:231:19: Wrong number of arguments to #<procedure translate (a b c)>
> > 
> > and "native menubar trick" appears in the menus.
> > 
> > Is this expected? I tried to redefine tr-file and this on the opposite is possible.
> > 
> > I am going to call the procedure for translation "shift", so I do not need the redefinition of "translate" to work, but I am curious.
> > 
> > Giovanni
> > 
> > 
> > _______________________________________________
> > Texmacs-dev mailing list
> > [email protected]
> > https://lists.gnu.org/mailman/listinfo/texmacs-dev
> 
> 
> _______________________________________________
> Texmacs-dev mailing list
> [email protected]
> https://lists.gnu.org/mailman/listinfo/texmacs-dev

_______________________________________________
Texmacs-dev mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/texmacs-dev
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.