ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Using \overloaded
@ 2021-01-24  4:13 Rik Kabel
  2021-01-24  9:33 ` Wolfgang Schuster
  2021-01-24 11:56 ` Hans Hagen
  0 siblings, 2 replies; 6+ messages in thread
From: Rik Kabel @ 2021-01-24  4:13 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 1476 bytes --]

Hans and all,

Preparing my standard environments for future strict enforcement of 
overloading prevention, I have run into one issue.

I had been using the following construction to change the formatting of 
URLs:

    \let\OrigHyphenatedurl\hyphenatedurl
    \starttexdefinition hyphenatedurl #URL
       \begingroup
         \URLfont\OrigHyphenatedurl{#URL}
       \endgroup
    \stoptexdefinition

This results in the following warning about overloading \hyphenatedurl:

    csname overload > warning, protection level 3, control sequence
    'hyphenatedurl', properties 'permanent protected', file
    'env_layout.mkvi', line 1

I have tried adding \overloaded to indicate the intentional overloading, 
but \overloaded cannot be used with \starttexdefinition, so I rewrote it as:

    \let\OrigHyphenatedurl\hyphenatedurl
    \overloaded\define[1]\hyphenatedurl{%
       \begingroup%
         \URLfont\OrigHyphenatedurl{#1}%
       \endgroup}%

but that (and also with \overloaded\def\hyphenatedurl#1...) gives the 
same (except for the line number) warning:

    csname overload > warning, protection level 3, control sequence
    'hyphenatedurl', properties 'permanent protected', file
    'env_layout.mkvi', line 822

So, what is the proper way to indicate intentional overloading? Or 
should this redefinition be done in another way?

(Also, it is interesting that the line number in the first warning 
message does not point to the actual line.)

-- 
Rik


[-- Attachment #1.2: Type: text/html, Size: 2055 bytes --]

[-- Attachment #2: Type: text/plain, Size: 493 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: Using \overloaded
  2021-01-24  4:13 Using \overloaded Rik Kabel
@ 2021-01-24  9:33 ` Wolfgang Schuster
  2021-01-24 21:16   ` Rik Kabel
  2021-01-24 11:56 ` Hans Hagen
  1 sibling, 1 reply; 6+ messages in thread
From: Wolfgang Schuster @ 2021-01-24  9:33 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Rik Kabel schrieb am 24.01.2021 um 05:13:
> Hans and all,
> 
> Preparing my standard environments for future strict enforcement of 
> overloading prevention, I have run into one issue.
> 
> I had been using the following construction to change the formatting of 
> URLs:
> 
>     \let\OrigHyphenatedurl\hyphenatedurl
>     \starttexdefinition hyphenatedurl #URL
>        \begingroup
>          \URLfont\OrigHyphenatedurl{#URL}
>        \endgroup
>     \stoptexdefinition


You can use a hook to change the font for \hyphenatedurl.

\starttext

\hyphenatedurl{https://wiki.contextgarden.net/Main_Page}

\appendtoks
   \it
\to \everyhyphenatedurl

\hyphenatedurl{https://wiki.contextgarden.net/Main_Page}

\stoptext


> This results in the following warning about overloading \hyphenatedurl:
> 
>     csname overload > warning, protection level 3, control sequence
>     'hyphenatedurl', properties 'permanent protected', file
>     'env_layout.mkvi', line 1
> 
> I have tried adding \overloaded to indicate the intentional overloading, 
> but \overloaded cannot be used with \starttexdefinition, so I rewrote it as:
> 
>     \let\OrigHyphenatedurl\hyphenatedurl
>     \overloaded\define[1]\hyphenatedurl{%
>        \begingroup%
>          \URLfont\OrigHyphenatedurl{#1}%
>        \endgroup}%
> 
> but that (and also with \overloaded\def\hyphenatedurl#1...) gives the 
> same (except for the line number) warning:
> 
>     csname overload > warning, protection level 3, control sequence
>     'hyphenatedurl', properties 'permanent protected', file
>     'env_layout.mkvi', line 822
> 
> So, what is the proper way to indicate intentional overloading? Or 
> should this redefinition be done in another way?


The best solution is *to not* overload commands because there are either
alternative ways to achieve the desired result or other commands which
can be used.


\overloadmode=4

\starttext

\permanent\def\mycommand#1{[#1]}

\mycommand{Old definition}

\pushoverloadmode

\aliased\let\originalmycommand\mycommand

\permanent\def\mycommand#1%
   {{\it\originalmycommand{#1}}}

\popoverloadmode

\mycommand{New definition}

\stoptext


Wolfgang
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: Using \overloaded
  2021-01-24  4:13 Using \overloaded Rik Kabel
  2021-01-24  9:33 ` Wolfgang Schuster
@ 2021-01-24 11:56 ` Hans Hagen
  1 sibling, 0 replies; 6+ messages in thread
From: Hans Hagen @ 2021-01-24 11:56 UTC (permalink / raw)
  To: mailing list for ConTeXt users, Rik Kabel

On 1/24/2021 5:13 AM, Rik Kabel wrote:
> Hans and all,
> 
> Preparing my standard environments for future strict enforcement of 
> overloading prevention, I have run into one issue.
> 
> I had been using the following construction to change the formatting of 
> URLs:
> 
>     \let\OrigHyphenatedurl\hyphenatedurl
>     \starttexdefinition hyphenatedurl #URL
>        \begingroup
>          \URLfont\OrigHyphenatedurl{#URL}
>        \endgroup
>     \stoptexdefinition
> 
> This results in the following warning about overloading \hyphenatedurl:
> 
>     csname overload > warning, protection level 3, control sequence
>     'hyphenatedurl', properties 'permanent protected', file
>     'env_layout.mkvi', line 1
> 
> I have tried adding \overloaded to indicate the intentional overloading, 
> but \overloaded cannot be used with \starttexdefinition, so I rewrote it as:
> 
>     \let\OrigHyphenatedurl\hyphenatedurl
>     \overloaded\define[1]\hyphenatedurl{%
>        \begingroup%
>          \URLfont\OrigHyphenatedurl{#1}%
>        \endgroup}%
> 
> but that (and also with \overloaded\def\hyphenatedurl#1...) gives the 
> same (except for the line number) warning:
> 
>     csname overload > warning, protection level 3, control sequence
>     'hyphenatedurl', properties 'permanent protected', file
>     'env_layout.mkvi', line 822
> 
> So, what is the proper way to indicate intentional overloading? Or 
> should this redefinition be done in another way?

\pushoverloadmode
    ...
\popoverloadmode

> (Also, it is interesting that the line number in the first warning 
> message does not point to the actual line.)
that has ot do with whne an error is encountered not where it originates 
from

Hans

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
        tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: Using \overloaded
  2021-01-24  9:33 ` Wolfgang Schuster
@ 2021-01-24 21:16   ` Rik Kabel
  2021-01-24 21:20     ` Jairo A. del Rio
  2021-01-24 21:53     ` Hans Hagen
  0 siblings, 2 replies; 6+ messages in thread
From: Rik Kabel @ 2021-01-24 21:16 UTC (permalink / raw)
  To: Wolfgang Schuster, mailing list for ConTeXt users

On 1/24/2021 04:33, Wolfgang Schuster wrote:
> Rik Kabel schrieb am 24.01.2021 um 05:13:
>> Hans and all,
>>
>> Preparing my standard environments for future strict enforcement of 
>> overloading prevention, I have run into one issue.
>>
>> I had been using the following construction to change the formatting 
>> of URLs:
>>
>>     \let\OrigHyphenatedurl\hyphenatedurl
>>     \starttexdefinition hyphenatedurl #URL
>>        \begingroup
>>          \URLfont\OrigHyphenatedurl{#URL}
>>        \endgroup
>>     \stoptexdefinition
>
>
> You can use a hook to change the font for \hyphenatedurl.
>
> \starttext
>
> \hyphenatedurl{https://wiki.contextgarden.net/Main_Page}
>
> \appendtoks
>   \it
> \to \everyhyphenatedurl
>
> \hyphenatedurl{https://wiki.contextgarden.net/Main_Page}
>
> \stoptext
>
>
>> This results in the following warning about overloading \hyphenatedurl:
>>
>>     csname overload > warning, protection level 3, control sequence
>>     'hyphenatedurl', properties 'permanent protected', file
>>     'env_layout.mkvi', line 1
>>
>> I have tried adding \overloaded to indicate the intentional 
>> overloading, but \overloaded cannot be used with \starttexdefinition, 
>> so I rewrote it as:
>>
>>     \let\OrigHyphenatedurl\hyphenatedurl
>>     \overloaded\define[1]\hyphenatedurl{%
>>        \begingroup%
>>          \URLfont\OrigHyphenatedurl{#1}%
>>        \endgroup}%
>>
>> but that (and also with \overloaded\def\hyphenatedurl#1...) gives the 
>> same (except for the line number) warning:
>>
>>     csname overload > warning, protection level 3, control sequence
>>     'hyphenatedurl', properties 'permanent protected', file
>>     'env_layout.mkvi', line 822
>>
>> So, what is the proper way to indicate intentional overloading? Or 
>> should this redefinition be done in another way?
>
>
> The best solution is *to not* overload commands because there are either
> alternative ways to achieve the desired result or other commands which
> can be used.
>
>
> \overloadmode=4
>
> \starttext
>
> \permanent\def\mycommand#1{[#1]}
>
> \mycommand{Old definition}
>
> \pushoverloadmode
>
> \aliased\let\originalmycommand\mycommand
>
> \permanent\def\mycommand#1%
>   {{\it\originalmycommand{#1}}}
>
> \popoverloadmode
>
> \mycommand{New definition}
>
> \stoptext
>
>
> Wolfgang

Thank you, Wolfgang (and Hans),

The hook is perfect for this. I had avoided that construction for a long 
time thinking that it is too low-level, but looking at it again it seems 
to be the right thing here.

I can find no information on \aliased and the push/pop for overloademode 
and such, so will leave documenting that in the wiki to somebody with a 
few more clues.

-- 
Rik

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: Using \overloaded
  2021-01-24 21:16   ` Rik Kabel
@ 2021-01-24 21:20     ` Jairo A. del Rio
  2021-01-24 21:53     ` Hans Hagen
  1 sibling, 0 replies; 6+ messages in thread
From: Jairo A. del Rio @ 2021-01-24 21:20 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 3752 bytes --]

Hi, Rik. If it helps, flags are explained in lowlevel-security manual:

https://www.pragma-ade.com/general/manuals/lowlevel-security.pdf

Jairo :)

El dom, 24 de ene. de 2021 a la(s) 16:16, Rik Kabel (
ConTeXt@rik.users.panix.com) escribió:

> On 1/24/2021 04:33, Wolfgang Schuster wrote:
> > Rik Kabel schrieb am 24.01.2021 um 05:13:
> >> Hans and all,
> >>
> >> Preparing my standard environments for future strict enforcement of
> >> overloading prevention, I have run into one issue.
> >>
> >> I had been using the following construction to change the formatting
> >> of URLs:
> >>
> >>     \let\OrigHyphenatedurl\hyphenatedurl
> >>     \starttexdefinition hyphenatedurl #URL
> >>        \begingroup
> >>          \URLfont\OrigHyphenatedurl{#URL}
> >>        \endgroup
> >>     \stoptexdefinition
> >
> >
> > You can use a hook to change the font for \hyphenatedurl.
> >
> > \starttext
> >
> > \hyphenatedurl{https://wiki.contextgarden.net/Main_Page}
> >
> > \appendtoks
> >   \it
> > \to \everyhyphenatedurl
> >
> > \hyphenatedurl{https://wiki.contextgarden.net/Main_Page}
> >
> > \stoptext
> >
> >
> >> This results in the following warning about overloading \hyphenatedurl:
> >>
> >>     csname overload > warning, protection level 3, control sequence
> >>     'hyphenatedurl', properties 'permanent protected', file
> >>     'env_layout.mkvi', line 1
> >>
> >> I have tried adding \overloaded to indicate the intentional
> >> overloading, but \overloaded cannot be used with \starttexdefinition,
> >> so I rewrote it as:
> >>
> >>     \let\OrigHyphenatedurl\hyphenatedurl
> >>     \overloaded\define[1]\hyphenatedurl{%
> >>        \begingroup%
> >>          \URLfont\OrigHyphenatedurl{#1}%
> >>        \endgroup}%
> >>
> >> but that (and also with \overloaded\def\hyphenatedurl#1...) gives the
> >> same (except for the line number) warning:
> >>
> >>     csname overload > warning, protection level 3, control sequence
> >>     'hyphenatedurl', properties 'permanent protected', file
> >>     'env_layout.mkvi', line 822
> >>
> >> So, what is the proper way to indicate intentional overloading? Or
> >> should this redefinition be done in another way?
> >
> >
> > The best solution is *to not* overload commands because there are either
> > alternative ways to achieve the desired result or other commands which
> > can be used.
> >
> >
> > \overloadmode=4
> >
> > \starttext
> >
> > \permanent\def\mycommand#1{[#1]}
> >
> > \mycommand{Old definition}
> >
> > \pushoverloadmode
> >
> > \aliased\let\originalmycommand\mycommand
> >
> > \permanent\def\mycommand#1%
> >   {{\it\originalmycommand{#1}}}
> >
> > \popoverloadmode
> >
> > \mycommand{New definition}
> >
> > \stoptext
> >
> >
> > Wolfgang
>
> Thank you, Wolfgang (and Hans),
>
> The hook is perfect for this. I had avoided that construction for a long
> time thinking that it is too low-level, but looking at it again it seems
> to be the right thing here.
>
> I can find no information on \aliased and the push/pop for overloademode
> and such, so will leave documenting that in the wiki to somebody with a
> few more clues.
>
> --
> Rik
>
>
> ___________________________________________________________________________________
> If your question is of interest to others as well, please add an entry to
> the Wiki!
>
> maillist : ntg-context@ntg.nl /
> http://www.ntg.nl/mailman/listinfo/ntg-context
> webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
> archive  : https://bitbucket.org/phg/context-mirror/commits/
> wiki     : http://contextgarden.net
>
> ___________________________________________________________________________________
>

[-- Attachment #1.2: Type: text/html, Size: 5508 bytes --]

[-- Attachment #2: Type: text/plain, Size: 493 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: Using \overloaded
  2021-01-24 21:16   ` Rik Kabel
  2021-01-24 21:20     ` Jairo A. del Rio
@ 2021-01-24 21:53     ` Hans Hagen
  1 sibling, 0 replies; 6+ messages in thread
From: Hans Hagen @ 2021-01-24 21:53 UTC (permalink / raw)
  To: mailing list for ConTeXt users, Rik Kabel, Wolfgang Schuster

On 1/24/2021 10:16 PM, Rik Kabel wrote:

> I can find no information on \aliased and the push/pop for overloademode 
> and such, so will leave documenting that in the wiki to somebody with a 
> few more clues.
it will be (and often is) in documentation and manuals in the 
distribution and in articles in user group journals and so

but anyway it's kind of new and i still need to flag all visible (low 
level) macros and variables (still some 700 to go)

the same is also done for metafun (mostly done but also some to go)

it roughly works as follows:

- primitives are marked as 'primitive' (already by the engine)
- we mark all registers we allocate as 'permanent'
- most constants are marked as 'immutable'
- if we don't care (or can't) we mark something as 'mutable'
- user defined instances are 'frozen' (can be \overloaded)
- \aliased just means: take the properties (applies to \let cs)
- \enforced (in the body of a macro) does just that

the last one is special because it gets internalized in ini mode (when 
the format is made)

there are (and might be some more) flags (like \noaligned)

the other large effort is removing some indirectness (using the extended 
lightweight macro argument parsing features) (mostly done, but it can 
introduce issues due to the rather large amount of tiny adptions but 
luckily these are reported here by users)

anyway, what happens after that depends on \overloadmode (th ehigher the 
more strict, odd a warning, even an error)

it is not (and can never be) complete in terms of protection (too many 
macro definitions, also runtime) but good enough for what i have in 
mind: help users to keep their run working by not redefining essential 
macros

Hans

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
        tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

end of thread, other threads:[~2021-01-24 21:53 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-24  4:13 Using \overloaded Rik Kabel
2021-01-24  9:33 ` Wolfgang Schuster
2021-01-24 21:16   ` Rik Kabel
2021-01-24 21:20     ` Jairo A. del Rio
2021-01-24 21:53     ` Hans Hagen
2021-01-24 11:56 ` Hans Hagen

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 NNTP newsgroup(s).