• Tags for variables of Korn shell

    From Spiros Bousbouras@21:1/5 to All on Thu Sep 8 08:48:49 2022
    Looking in man ksh I see

    typeset
    [...]
    -t Tags the variables. Tags are user definable and have no special
    meaning to the shell.

    Can someone give me any realistic examples of how this is
    supposed to be used ?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Janis Papanagnou@21:1/5 to Spiros Bousbouras on Thu Sep 8 13:12:58 2022
    On 08.09.2022 10:48, Spiros Bousbouras wrote:
    Looking in man ksh I see

    typeset
    [...]
    -t Tags the variables. Tags are user definable and have no special
    meaning to the shell.

    Can someone give me any realistic examples of how this is
    supposed to be used ?

    Since a tag has no special meaning to the shell and since the
    shell is agnostic about variable semantics it's up to the user
    to identify application cases.

    Effectively you can interrogate all your "tagged variables" by
    typeset [-+]t so that you could define a set of variables for
    special treatment; to interrogate the names and actual values
    of any tagged variables, e.g. for debugging purposes.

    For such a tagging feature it might have been a better design
    ("better" = with wider application range) to enable the user
    defining tag types, though, like typeset -t label var ...
    typeset -t debug a b c
    typeset -t log a e
    typeset -t tmp_res c d
    typeset -t log > logfile
    But all those ideas are void given that some documentation
    sources say "This option is obsolete."

    Myself I've never used typeset -t in my ksh source code but
    now that I've been pointed to that option I think there may
    be useful applications (like the ones hinted above off the
    top of my head or other).

    Janis

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Bit Twister@21:1/5 to Spiros Bousbouras on Thu Sep 8 05:25:53 2022
    On Thu, 8 Sep 2022 08:48:49 -0000 (UTC), Spiros Bousbouras wrote:
    Looking in man ksh I see

    typeset
    [...]
    -t Tags the variables. Tags are user definable and have no special
    meaning to the shell.

    Can someone give me any realistic examples of how this is
    supposed to be used ?

    Well putting
    ksh typeset example
    in the first box at
    https://www.google.com/advanced_search
    gets me
    About 17,800 results (0.48 seconds)
    hits.

    I found the fist selection
    typeset (Learning the Korn Shell, 2nd Edition)
    pretty informative.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Spiros Bousbouras@21:1/5 to Janis Papanagnou on Thu Sep 8 18:41:09 2022
    On Thu, 8 Sep 2022 13:12:58 +0200
    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
    On 08.09.2022 10:48, Spiros Bousbouras wrote:
    Looking in man ksh I see

    typeset
    [...]
    -t Tags the variables. Tags are user definable and have no special
    meaning to the shell.

    Can someone give me any realistic examples of how this is
    supposed to be used ?

    Since a tag has no special meaning to the shell and since the
    shell is agnostic about variable semantics it's up to the user
    to identify application cases.

    Effectively you can interrogate all your "tagged variables" by
    typeset [-+]t so that you could define a set of variables for
    special treatment; to interrogate the names and actual values
    of any tagged variables, e.g. for debugging purposes.

    So you're saying that tagging is just a boolean thing i.e. either
    a variable is tagged or not. If that's the case then it's even
    less useful than I thought. If you want to print the values of
    some variables for debugging , you just print the values , I don't
    see that it buys you anything to tag them first.

    For such a tagging feature it might have been a better design
    ("better" = with wider application range) to enable the user
    defining tag types, though, like typeset -t label var ...
    typeset -t debug a b c
    typeset -t log a e
    typeset -t tmp_res c d
    typeset -t log > logfile

    So you're thinking of the possibility of associating an arbitrary
    tag with a variable. This is how I originally thought it works.
    So for example you could tag that a numerical variable is inches
    and another cm .But even that would not be much useful unless the
    shell offered many more capabilities like taking into account tags
    before performing some operations. And in any case , such tagging
    would be perhaps appropriate for a large project and I don't think
    that a shell is a good language for a large project , tagging or
    no tagging.

    But all those ideas are void given that some documentation
    sources say "This option is obsolete."

    My guess is that it won't be going away despite what the documentation
    says.

    Myself I've never used typeset -t in my ksh source code but
    now that I've been pointed to that option I think there may
    be useful applications (like the ones hinted above off the
    top of my head or other).

    --
    Be bold , verb a noun today.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Janis Papanagnou@21:1/5 to Spiros Bousbouras on Thu Sep 8 21:37:44 2022
    On 08.09.2022 20:41, Spiros Bousbouras wrote:
    On Thu, 8 Sep 2022 13:12:58 +0200
    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
    On 08.09.2022 10:48, Spiros Bousbouras wrote:
    [ ksh's typeset -t ]

    So you're saying that tagging is just a boolean thing i.e. either
    a variable is tagged or not.

    Yes. It seems it's not more that that.

    If that's the case then it's even
    less useful than I thought. If you want to print the values of
    some variables for debugging , you just print the values , I don't
    see that it buys you anything to tag them first.

    Not quite. My thought was along this (sample-)application...

    typeset a ; ... ; typeset -t b c ; ... ; typeset d ; typeset -t e ;
    ... ; printf "*** Debug: %s\n" $( typeset -t ) ; typeset +t e ; ...

    In other words, define the tag attribute when the variable is set
    (or declared) and print all tagged variables later in "one place",
    optionally adjust tags as necessary in the course of the executed
    program. I.e. it would be a mark declaring it as "var is interesting
    for debugging, logging, as intermediate result, ... (whatever)" and
    separating that declaration semantics from the execution point of
    interest.

    [ hypothetical labels as in typeset -t label var ... ]

    So you're thinking of the possibility of associating an arbitrary
    tag with a variable. This is how I originally thought it works.

    Yes, this is what one would naturally assume when talking about
    tags and tagging. But obviously it's just an untyped flag. (My
    picture about the [assumed] implementation in the shell is that
    the type information may be just a bit-field representing { r/o,
    integer, float, ..., and 'tag' }; anything else would require a
    more complex data structure.)

    So for example you could tag that a numerical variable is inches
    and another cm .But even that would not be much useful unless the
    shell offered many more capabilities like taking into account tags
    before performing some operations. And in any case , such tagging
    would be perhaps appropriate for a large project and I don't think
    that a shell is a good language for a large project , tagging or
    no tagging.

    Well, as said, I think it could still be useful. Though not as
    much as it could be, especially as rudimentary as it is provided.

    For example, another application that I can think of being useful
    would be to mark some variables as GDPR-relevant, then it could
    be simply avoided to e.g. log or display values of such variables,
    but that would require to have some inverse-logic flag available;
    currently typeset -t will show the variables (a possible extension
    could be to functionally differentiate between -t and +t, using
    one of it to support that inverse logic). Such an inverse function
    could be considered independently of adding <label> functionality,
    the latter making the shell function change less trivial.


    But all those ideas are void given that some documentation
    sources say "This option is obsolete."

    My guess is that it won't be going away despite what the documentation
    says.

    Most likely.

    With "ksh 93u+m" there would be a path, though, to refine/replace
    that typeset option with a more useful [extended] variant.

    Janis

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Janis Papanagnou@21:1/5 to Janis Papanagnou on Thu Sep 8 22:06:19 2022
    On 08.09.2022 21:37, Janis Papanagnou wrote:

    Yes, this is what one would naturally assume when talking about
    tags and tagging. But obviously it's just an untyped flag. (My
    picture about the [assumed] implementation in the shell is that
    the type information may be just a bit-field representing { r/o,
    integer, float, ..., and 'tag' }; anything else would require a
    more complex data structure.)

    I have to correct that picture; there's already arguments
    available with certain typeset options that already need
    some special handling (-Z3, -i8, etc.).

    Janis

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