• RegEx / rename of a function result

    From Thomas@21:1/5 to onewingedshark@gmail.com on Wed Jul 6 18:18:49 2022
    In article <a6e2e912-8aa6-4ecf-9118-9dd29a967734n@googlegroups.com>,
    Shark8 <onewingedshark@gmail.com> wrote:

    On Wednesday, July 7, 2021 at 5:15:43 PM UTC-6, Matt Borchers wrote:

    BTW, what's wrong with
    Gnat.RegExp? It has worked in our code for years.

    Regular expressions are for regular languages; it is very easy to violate that restriction with your incoming data.
    Most of my professional career has been doing maintenance, and RegEx are *terrible* when it comes to maintainability, to the point that I actively avoid them and advise others to as well, even for things that conceptually *could* be done via RegEx (e.g. recognizing an Integer) in favor of actual parsing... or if you need pattern-matching, something more robust like SNOBOL.

    interesting :-)

    is it easy to integrate it in an ada program?
    i'm thinking about AdaControl, which (if i'm right) uses RegEx a lot.



    The RENAME is interesting as I have not seen that before. Is it a rename of the function call (invokes the function upon reference) or a rename of the function result?
    That form of RENAMES is the function result.
    I've found it an excellent alternative to CONSTANT, as it signals my intent to have an alias for some result inside DECLARE blocks and certain internal objects. (eg Default_Map : Map renames Internal_Map_Generation(P1, P2); ... and then I can use "Default_Map" instead of calling the generation-function at each point and possibly messing things up should the parameters change.)

    why renames is better than constant in this case ?
    could you explicit the difference between them, please?

    --
    RAPID maintainer
    http://savannah.nongnu.org/projects/rapid/

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From J-P. Rosen@21:1/5 to All on Wed Jul 6 19:56:47 2022
    Le 06/07/2022 à 18:18, Thomas a écrit :
    or if you need pattern-matching, something more robust like
    SNOBOL.
    interesting:-)
    I think AdaCore has (or used to have) a Snobol package. Snobol was
    invented by Robert Dewar...

    is it easy to integrate it in an ada program?
    i'm thinking about AdaControl, which (if i'm right) uses RegEx a lot.

    AdaControl uses Gnat.Regexp


    --
    J-P. Rosen
    Adalog
    2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX
    Tel: +33 1 45 29 21 52
    https://www.adalog.fr

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jeffrey R.Carter@21:1/5 to J-P. Rosen on Wed Jul 6 21:11:00 2022
    On 2022-07-06 19:56, J-P. Rosen wrote:
    I think AdaCore has (or used to have) a Snobol package. Snobol was invented by
    Robert Dewar...

    SNOBOL was created by Farber,Griswold, and Polonsky in the 1960s. Dewar and Belcher wrote the SPITBOL compiler in the 1970s. GNAT comes with the GNAT.Spitbol.* packages for SNOBOL-like pattern matching.

    --
    Jeff Carter
    "Monsieur Arthur King, who has the brain of a duck, you know."
    Monty Python & the Holy Grail
    09

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Randy Brukardt@21:1/5 to Thomas on Wed Jul 6 19:44:11 2022
    "Thomas" <fantome.forums.tDeContes@free.fr.invalid> wrote in message news:62c5b5e9$0$22251$426a34cc@news.free.fr...
    In article <a6e2e912-8aa6-4ecf-9118-9dd29a967734n@googlegroups.com>,
    Shark8 <onewingedshark@gmail.com> wrote:
    The RENAME is interesting as I have not seen that before. Is it a
    rename of
    the function call (invokes the function upon reference) or a rename of
    the
    function result?
    That form of RENAMES is the function result.
    I've found it an excellent alternative to CONSTANT, as it signals my
    intent
    to have an alias for some result inside DECLARE blocks and certain
    internal
    objects. (eg Default_Map : Map renames Internal_Map_Generation(P1, P2);
    ...
    and then I can use "Default_Map" instead of calling the
    generation-function
    at each point and possibly messing things up should the parameters
    change.)

    why renames is better than constant in this case ?
    could you explicit the difference between them, please?

    In theory, a renames captures the function result object, so for a composite type, you avoid copying it. That can be especially significant for
    controlled types, where you avoid an extra Finalization (and that might be critical if you are implementing Finalize). I believe there also are some accessibility differences that might matter in unusual cases.

    In most cases, however, they are essentially the same, generating
    essentially the same code. So it is a matter of preference which to pick. (I usually use "constant" unless avoiding a copy is necessary.)

    Randy.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From J-P. Rosen@21:1/5 to All on Thu Jul 7 07:51:02 2022
    Le 06/07/2022 à 21:11, Jeffrey R.Carter a écrit :
    On 2022-07-06 19:56, J-P. Rosen wrote:
    I think AdaCore has (or used to have) a Snobol package. Snobol was
    invented by Robert Dewar...

    SNOBOL was created by Farber,Griswold, and Polonsky in the 1960s. Dewar
    and Belcher wrote the SPITBOL compiler in the 1970s. GNAT comes with the GNAT.Spitbol.* packages for SNOBOL-like pattern matching.


    Right. I'm always confused which is which...

    --
    J-P. Rosen
    Adalog
    2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX
    Tel: +33 1 45 29 21 52
    https://www.adalog.fr

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Thomas@21:1/5 to J-P. Rosen on Mon Jul 11 19:49:24 2022
    In article <ta4icu$3hjj$1@dont-email.me>,
    "J-P. Rosen" <rosen@adalog.fr> wrote:

    Le 06/07/2022 à 18:18, Thomas a écrit :
    or if you need pattern-matching, something more robust like
    SNOBOL.
    interesting:-)
    I think AdaCore has (or used to have) a Snobol package. Snobol was
    invented by Robert Dewar...

    is it easy to integrate it in an ada program?
    i'm thinking about AdaControl, which (if i'm right) uses RegEx a lot.

    AdaControl uses Gnat.Regexp

    do you have sth against SPITBOL?
    do you disagree Shark8 ?

    or is it because no one asked for it, or no time for that?

    --
    RAPID maintainer
    http://savannah.nongnu.org/projects/rapid/

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Thomas@21:1/5 to Randy Brukardt on Mon Jul 11 19:45:53 2022
    In article <ta5a8t$5vnn$1@dont-email.me>,
    "Randy Brukardt" <randy@rrsoftware.com> wrote:

    "Thomas" <fantome.forums.tDeContes@free.fr.invalid> wrote in message news:62c5b5e9$0$22251$426a34cc@news.free.fr...
    In article <a6e2e912-8aa6-4ecf-9118-9dd29a967734n@googlegroups.com>,
    Shark8 <onewingedshark@gmail.com> wrote:
    The RENAME is interesting as I have not seen that before. Is it a
    rename of
    the function call (invokes the function upon reference) or a rename of >> > the
    function result?
    That form of RENAMES is the function result.
    I've found it an excellent alternative to CONSTANT, as it signals my
    intent
    to have an alias for some result inside DECLARE blocks and certain
    internal
    objects. (eg Default_Map : Map renames Internal_Map_Generation(P1, P2);


    why renames is better than constant in this case ?
    could you explicit the difference between them, please?

    In theory, a renames captures the function result object, so for a composite type, you avoid copying it. That can be especially significant for
    controlled types, where you avoid an extra Finalization

    yes, i remember that i had to use a renames with a limited type :-)



    I believe there also are some
    accessibility differences that might matter in unusual cases.

    it is a matter of preference which to pick. (I
    usually use "constant" unless avoiding a copy is necessary.)

    (i don't know if that's the case of "some accessibility differences": )

    i don't like that constant keyword is forbidden in a renames.


    i find it less readable when the pointed object is constant,
    since it is not remembered at the point of the renames, and one could
    think that it can be changed.
    in other words, at the review time we have to check at the source of the renames to know if it is constant or not.


    moreover, when the pointed object is variable,
    constant keyword in a renames could mean that the variable could not be modified when used with the "constant renames" identifier.

    i understand that it conflicts with the rule: "the constant keyword
    means that the value never changes"

    i suppose that some people already thought about that ...

    but i don't understant what kind of pb there can be with the 1st case,
    so i would find nice to have the constant keyword when the pointed
    object is one, even if it stay forbidden in the other case.



    (sorry for my english, I did not sleep well)

    --
    RAPID maintainer
    http://savannah.nongnu.org/projects/rapid/

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From J-P. Rosen@21:1/5 to All on Tue Jul 12 07:13:36 2022
    Le 11/07/2022 à 19:49, Thomas a écrit :
    AdaControl uses Gnat.Regexp
    do you have sth against SPITBOL?No, but
    1) Regexp is sufficient for my needs
    2) I don't want my users to have to learn Spitbol. Everybody knows
    regexp (at least the simple forms).

    --
    J-P. Rosen
    Adalog
    2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX
    Tel: +33 1 45 29 21 52
    https://www.adalog.fr

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Randy Brukardt@21:1/5 to Thomas on Tue Jul 12 01:54:43 2022
    "Thomas" <fantome.forums.tDeContes@free.fr.invalid> wrote in message news:62cc61d1$0$22254$426a34cc@news.free.fr...
    ....
    i find it less readable when the pointed object is constant,
    since it is not remembered at the point of the renames, and one could
    think that it can be changed.
    in other words, at the review time we have to check at the source of the renames to know if it is constant or not.

    With a renames, you *always* have to check the original object, since the properties specified in the renames are ignored in most cases. You *will*
    get in trouble if you pay attention to them. That's one reason for
    minimizing the use of renames (if your program can afford a copy, a copy is almost always safer anyway, and when it isn't you have to avoid aliasing and thus avoid renames).


    moreover, when the pointed object is variable,
    constant keyword in a renames could mean that the variable could not be modified when used with the "constant renames" identifier.

    i understand that it conflicts with the rule: "the constant keyword
    means that the value never changes"

    This is a False statement for Ada, (the details are painful), it's true for elementary types and some others, but not most composite types.

    i suppose that some people already thought about that ...

    I don't recall anyone proposing this, but given the way renames works, it
    would either be useless or different from everything else.

    That's because a rename ignores the properties declared with it and use the ones of the actual object. In particular, things like subtypes are not used
    at all for a rename - even if specified. If you care about those things, you need to use a constant. :-)

    It would have been better if Ada had used some sort of matching rule, but
    Ada 83 did not have static matching, and it was too incompatible to
    introduce it in Ada 95, and that will not change.

    but i don't understant what kind of pb there can be with the 1st case,
    so i would find nice to have the constant keyword when the pointed
    object is one, even if it stay forbidden in the other case.

    No problem, per se, just completely different than the current model of renames.

    If you think this is important, you should submit something via the new Community Input site. (Not announced yet, but should be working - it's in
    beta now, so if it fails, we need to know that.) See arg.adaic.org.

    Randy.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From G.B.@21:1/5 to J-P. Rosen on Tue Jul 12 16:45:00 2022
    On 12.07.22 07:13, J-P. Rosen wrote:
    Le 11/07/2022 à 19:49, Thomas a écrit :
    AdaControl uses Gnat.Regexp
    do you have sth against SPITBOL?No, but
    1) Regexp is sufficient for my needs
    2) I don't want my users to have to learn Spitbol.

    Learning Spitbol is great fun, though!

    Everybody knows regexp (at least the simple forms).

    Everybody thinks they know regex (at least the simple forms)... ;-)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)