Re: substr() - copying or not copying, that is here the question.

Liste des GroupesRevenir à cl awk 
Sujet : Re: substr() - copying or not copying, that is here the question.
De : gazelle (at) *nospam* shell.xmission.com (Kenny McCormack)
Groupes : comp.lang.awk
Date : 01. Jun 2025, 13:06:12
Autres entêtes
Organisation : The official candy of the new Millennium
Message-ID : <101hfnk$2qrh$2@news.xmission.com>
References : 1 2 3 4
User-Agent : trn 4.0-test77 (Sep 1, 2010)
In article <101hecq$22ab2$1@dont-email.me>,
Janis Papanagnou  <janis_papanagnou+ng@hotmail.com> wrote:
...
An alternative (depending on the context) would be to consider an
extension that provides an index function with a third argument giving
the initial offset.  I've not looked at how extensions get access to
GAWK strings, so this many not be as easy as it sounds, but I would
guess that it might be relatively simple to do.
>
This, first of all, sounds like a good idea! It would make it
unnecessary to (mis-)use the substr() function as (sort of) a
costly copying-descriptor.[*]
>
I'm unsure about using an extension here. Would there be a name
clash between an built-in index(haystack,needle) function and an
extension index(haystack,needle,start) function? Should they be
separate functions in the first place? (I don't think so.)

Nobody is talking about changing the index() built-in function.

This would be a brand new function, written as an extension library.

You could name it something like index_ex() if you like, or you could give
it a brand new name (**).

Although I have not done this with the extension functions I've already
written (and have widely deployed, so obviously, as the saying goes, it's
way too late to change it), if I had it to do over again, I'd probably have
enforced a convention that my functions always start with some identifying
prefix - to make it clear that these were written by me, not built-ins.  I
do that when writing in other scripting languages; I should have done so in
AWK.  Perhaps, the new namespaces feature would address this (*).

(*) I have not yet taken the time to fully acclimate to the concepts and
start using namespaces in my own code.  I'm still working on getting the
kinks and quirks out of PMA...

(**) My conception of how this would be implemented would handle the
"start"-only case (just add the offset to the "haystack" arg of strstr() -
with error checking to make sure it doesn't overflow, of course).
Implementing "end" would be a bit trickier (but not much).

--
Liberals live in a fantasy world where (street) criminals are good people.

Conservatives live in a fantasy world where businessmen are good people.

Date Sujet#  Auteur
31 May 25 * substr() - copying or not copying, that is here the question.18Janis Papanagnou
31 May 25 `* Re: substr() - copying or not copying, that is here the question.17Mack The Knife
31 May 25  +* Re: substr() - copying or not copying, that is here the question.15Janis Papanagnou
1 Jun 25  i+* Re: substr() - copying or not copying, that is here the question.8Ben Bacarisse
1 Jun 25  ii+* Re: substr() - copying or not copying, that is here the question.3Janis Papanagnou
1 Jun 25  iii`* Re: substr() - copying or not copying, that is here the question.2Kenny McCormack
1 Jun 25  iii `- Re: substr() - copying or not copying, that is here the question.1Janis Papanagnou
1 Jun 25  ii`* Re: substr() - copying or not copying, that is here the question.4Kenny McCormack
1 Jun 25  ii `* Re: substr() - copying or not copying, that is here the question.3Janis Papanagnou
1 Jun 25  ii  `* Re: substr() - copying or not copying, that is here the question.2Kenny McCormack
7 Jun 25  ii   `- Re: substr() - copying or not copying, that is here the question.1Janis Papanagnou
3 Jun 25  i`* Re: substr() - copying or not copying, that is here the question.6Mack The Knife
3 Jun 25  i +- Re: substr() - copying or not copying, that is here the question.1Kenny McCormack
7 Jun 25  i `* Re: substr() - copying or not copying, that is here the question.4Janis Papanagnou
8 Jun 25  i  `* Re: substr() - copying or not copying, that is here the question.3Mack The Knife
11 Jun 25  i   `* Re: substr() - copying or not copying, that is here the question.2Janis Papanagnou
11 Jun 25  i    `- Meta chat (Was: substr() - copying or not copying, that is here the question.)1Kenny McCormack
1 Jun 25  `- Re: substr() - copying or not copying, that is here the question.1Kaz Kylheku

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal