• Re: Weak Type Ability for Python

    From Chris Angelico@21:1/5 to ali.mohseniroodbari@gmail.com on Thu Apr 13 03:11:35 2023
    On Thu, 13 Apr 2023 at 03:05, Ali Mohseni Roodbari <ali.mohseniroodbari@gmail.com> wrote:

    Hi all,
    Please make this command for Python (if possible):

    x=1
    y='a'
    wprint (x+y)
    1a

    In fact make a new type of print command which can print and show strings
    and integers together.


    Try:

    print(x, y)

    ChrisA

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ali Mohseni Roodbari@21:1/5 to All on Wed Apr 12 11:33:13 2023
    Hi all,
    Please make this command for Python (if possible):

    x=1
    y='a'
    wprint (x+y)
    1a

    In fact make a new type of print command which can print and show strings
    and integers together.

    Sincerely yours,
    Ali.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mats Wichmann@21:1/5 to Chris Angelico on Wed Apr 12 12:57:39 2023
    On 4/12/23 11:11, Chris Angelico wrote:
    On Thu, 13 Apr 2023 at 03:05, Ali Mohseni Roodbari <ali.mohseniroodbari@gmail.com> wrote:

    Hi all,
    Please make this command for Python (if possible):

    x=1
    y='a'
    wprint (x+y)
    1a

    In fact make a new type of print command which can print and show strings
    and integers together.


    Try:

    print(x, y)

    ChrisA


    To continue on, what do you want "addition" of dissimilar types to do -
    since that's what you have asked for above.

    You can write yourself an object which is happy with certain
    combinations, so you don't have this scenario:

    x + y
    Traceback (most recent call last):
    File "<input>", line 1, in <module>
    x + y
    ~~^~~
    TypeError: can only concatenate str (not "int") to str
    y + x
    Traceback (most recent call last):
    File "<input>", line 1, in <module>
    y + x
    ~~^~~
    TypeError: unsupported operand type(s) for +: 'int' and 'str'



    Or you can help out the print function by doing some of the fiddling
    yourself:

    print(f"{x}{y}")
    1a

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From MRAB@21:1/5 to Mats Wichmann on Wed Apr 12 20:11:32 2023
    On 2023-04-12 19:57, Mats Wichmann wrote:
    On 4/12/23 11:11, Chris Angelico wrote:
    On Thu, 13 Apr 2023 at 03:05, Ali Mohseni Roodbari
    <ali.mohseniroodbari@gmail.com> wrote:

    Hi all,
    Please make this command for Python (if possible):

    x=1
    y='a'
    wprint (x+y)
    1a

    In fact make a new type of print command which can print and show strings >>> and integers together.


    Try:

    print(x, y)

    ChrisA


    To continue on, what do you want "addition" of dissimilar types to do -
    since that's what you have asked for above.

    You can write yourself an object which is happy with certain
    combinations, so you don't have this scenario:

    >>> x + y
    Traceback (most recent call last):
    File "<input>", line 1, in <module>
    x + y
    ~~^~~
    TypeError: can only concatenate str (not "int") to str
    >>> y + x
    Traceback (most recent call last):
    File "<input>", line 1, in <module>
    y + x
    ~~^~~
    TypeError: unsupported operand type(s) for +: 'int' and 'str'
    >>>


    Or you can help out the print function by doing some of the fiddling yourself:

    >>> print(f"{x}{y}")
    1a

    Or:

    print(x, y, sep='')
    1a

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Thomas Passin@21:1/5 to Chris Angelico on Wed Apr 12 14:51:44 2023
    On 4/12/2023 1:11 PM, Chris Angelico wrote:
    On Thu, 13 Apr 2023 at 03:05, Ali Mohseni Roodbari <ali.mohseniroodbari@gmail.com> wrote:

    Hi all,
    Please make this command for Python (if possible):

    x=1
    y='a'
    wprint (x+y)
    1a

    In fact make a new type of print command which can print and show strings
    and integers together.


    Try:

    print(x, y)

    ChrisA

    It puts a space between "1" and "a", whereas the question does not want
    the space. print(f'{x}{y}') would do it, but only works for variables
    named "x" and "y".

    As happens so often, the OP has not specified what he actually wants to
    do so we can only answer the very specific question.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From 2QdxY4RzWzUUiLuE@potatochowder.com@21:1/5 to Thomas Passin on Wed Apr 12 15:17:17 2023
    On 2023-04-12 at 14:51:44 -0400,
    Thomas Passin <list1@tompassin.net> wrote:

    On 4/12/2023 1:11 PM, Chris Angelico wrote:
    On Thu, 13 Apr 2023 at 03:05, Ali Mohseni Roodbari <ali.mohseniroodbari@gmail.com> wrote:

    Hi all,
    Please make this command for Python (if possible):

    x=1
    y='a'
    wprint (x+y)
    1a

    In fact make a new type of print command which can print and show strings and integers together.


    Try:

    print(x, y)

    ChrisA

    It puts a space between "1" and "a", whereas the question does not want the space. print(f'{x}{y}') would do it, but only works for variables named "x" and "y".

    Or possibly print(x, y, sep='').

    As happens so often, the OP has not specified what he actually wants to do
    so we can only answer the very specific question.

    Agreed.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Grant Edwards@21:1/5 to Ali Mohseni Roodbari on Wed Apr 12 12:22:44 2023
    On 2023-04-12, Ali Mohseni Roodbari <ali.mohseniroodbari@gmail.com> wrote:
    Hi all,
    Please make this command for Python (if possible):

    x=1
    y='a'
    wprint (x+y)
    1a

    If that's what you want, use PHP or some other language. Don't try to ruin Python.

    In fact make a new type of print command which can print and show strings
    and integers together.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From avi.e.gross@gmail.com@21:1/5 to Chris Angelico on Wed Apr 12 22:12:27 2023
    As originally written, the question posed has way too many possible answers
    but the subject line may give a hint. Forget printing.

    The Python statement
    1 + "a"

    SHOULD fail. The first is an integer and the second is string. These two
    are native Python objects that neither define what to do if they are paired with an object of the other type on the left or the right.

    In any case, what should the answer be? Since "a" has no integer value, it presumably was intended to be the string "1a".

    So why NOT use the built-in conversion and instead of:

    print(x+y) # where x=1, y='a'

    It should be:

    print(str(x) + y)

    Could this behavior be added to Python? Sure. I wonder how many would not
    like it as it often will be an error not caught!

    If you defined your own object derived from string and added a __radd__() method then the method could be made to accept whatever types you wanted
    (such as integer or double or probably anything) and simply have code that converts it to the str() representation and then concatenates them with, or
    if you prefer without, any padding between.

    I suspect the OP is thinking of languages like PERL or JAVA which guess for
    you and make such conversions when it seems to make sense.

    Python does not generally choose that as it is quite easy to use one of so
    many methods, and lately an f-string is an easy way as others mentioned.


    -----Original Message-----
    From: Python-list <python-list-bounces+avi.e.gross=gmail.com@python.org> On Behalf Of Thomas Passin
    Sent: Wednesday, April 12, 2023 2:52 PM
    To: python-list@python.org
    Subject: Re: Weak Type Ability for Python

    On 4/12/2023 1:11 PM, Chris Angelico wrote:
    On Thu, 13 Apr 2023 at 03:05, Ali Mohseni Roodbari <ali.mohseniroodbari@gmail.com> wrote:

    Hi all,
    Please make this command for Python (if possible):

    x=1
    y='a'
    wprint (x+y)
    1a

    In fact make a new type of print command which can print and show strings
    and integers together.


    Try:

    print(x, y)

    ChrisA

    It puts a space between "1" and "a", whereas the question does not want
    the space. print(f'{x}{y}') would do it, but only works for variables
    named "x" and "y".

    As happens so often, the OP has not specified what he actually wants to
    do so we can only answer the very specific question.

    --
    https://mail.python.org/mailman/listinfo/python-list

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From MRAB@21:1/5 to avi.e.gross@gmail.com on Thu Apr 13 03:28:37 2023
    On 2023-04-13 03:12, avi.e.gross@gmail.com wrote:
    As originally written, the question posed has way too many possible answers but the subject line may give a hint. Forget printing.

    The Python statement
    1 + "a"

    SHOULD fail. The first is an integer and the second is string. These two
    are native Python objects that neither define what to do if they are paired with an object of the other type on the left or the right.

    In any case, what should the answer be? Since "a" has no integer value, it presumably was intended to be the string "1a".

    So why NOT use the built-in conversion and instead of:

    print(x+y) # where x=1, y='a'

    It should be:

    print(str(x) + y)

    Could this behavior be added to Python? Sure. I wonder how many would not like it as it often will be an error not caught!

    If you defined your own object derived from string and added a __radd__() method then the method could be made to accept whatever types you wanted (such as integer or double or probably anything) and simply have code that converts it to the str() representation and then concatenates them with, or if you prefer without, any padding between.

    I suspect the OP is thinking of languages like PERL or JAVA which guess for you and make such conversions when it seems to make sense.

    In the case of Perl, there are distinct operators for addition and
    string concatenation, with automatic type conversion (non-numeric
    strings have a numeric value of 0, which can hide bugs).

    Python does not generally choose that as it is quite easy to use one of so many methods, and lately an f-string is an easy way as others mentioned.


    -----Original Message-----
    From: Python-list <python-list-bounces+avi.e.gross=gmail.com@python.org> On Behalf Of Thomas Passin
    Sent: Wednesday, April 12, 2023 2:52 PM
    To: python-list@python.org
    Subject: Re: Weak Type Ability for Python

    On 4/12/2023 1:11 PM, Chris Angelico wrote:
    On Thu, 13 Apr 2023 at 03:05, Ali Mohseni Roodbari
    <ali.mohseniroodbari@gmail.com> wrote:

    Hi all,
    Please make this command for Python (if possible):

    x=1
    y='a'
    wprint (x+y)
    1a

    In fact make a new type of print command which can print and show strings >>> and integers together.


    Try:

    print(x, y)

    ChrisA

    It puts a space between "1" and "a", whereas the question does not want
    the space. print(f'{x}{y}') would do it, but only works for variables
    named "x" and "y".

    As happens so often, the OP has not specified what he actually wants to
    do so we can only answer the very specific question.


    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From MRAB@21:1/5 to Cameron Simpson on Thu Apr 13 03:36:22 2023
    On 2023-04-13 03:21, Cameron Simpson wrote:
    On 12Apr2023 22:12, avi.e.gross@gmail.com <avi.e.gross@gmail.com> wrote:
    I suspect the OP is thinking of languages like PERL or JAVA which guess
    for
    you and make such conversions when it seems to make sense.

    JavaScript guesses. What a nightmare. Java acts like Python and will
    forbid it on type grounds (at compile time with Java, being staticly
    typed).

    I thought that in Java you can, in fact, concatenate a string and an
    int, so I did a quick search online and it appears that you can.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Cameron Simpson@21:1/5 to avi.e.gross@gmail.com on Thu Apr 13 12:21:58 2023
    On 12Apr2023 22:12, avi.e.gross@gmail.com <avi.e.gross@gmail.com> wrote:
    I suspect the OP is thinking of languages like PERL or JAVA which guess
    for
    you and make such conversions when it seems to make sense.

    JavaScript guesses. What a nightmare. Java acts like Python and will
    forbid it on type grounds (at compile time with Java, being staticly
    typed).

    Cheers,
    Cameron Simpson <cs@cskk.id.au>

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From avi.e.gross@gmail.com@21:1/5 to Thomas Passin on Wed Apr 12 22:37:36 2023
    On closer reading, the OP may be asking how to make a function doing what
    they want, albeit without a plus.

    Here is a python function as a one-liner that takes exactly two arguments of any kind (including string and integer) and concatenates them into one
    string without anything between and prints them:

    def strprint(first, second): print(str(first) + str(second))

    strprint(5,1)
    51
    strprint("a5",1)
    a51
    strprint(12,"o'clock")
    12o'clock
    strprint(3.1415926535,complex(3,4))
    3.1415926535(3+4j)

    Want something similar for any number of arguments? Here is a slightly
    longer one-liner:

    def strprintall(*many): print(''.join([str(each) for each in many]))


    strprintall(1,"=egy\n",2,"=kettõ\n",3,"=három\n",4,"=négy\n",5,"=öt\n","in
    my childhood language.\n")
    1=egy
    2=kettõ
    3=három
    4=négy
    5=öt
    in my childhood language.

    Note my meager attempt is not using a plus sign as I addressed a sort of way that could be done using a __radd__ method or other ways like an f-string.

    I can not repeat this often enough. The easiest way to do something you want
    in a new language is to work within the existing language as-is and not to
    ask the language to change to be the way you want. That can take years or
    never happen, and especially if the designers did not want the feature you
    ask for.





    -----Original Message-----
    From: Python-list <python-list-bounces+avi.e.gross=gmail.com@python.org> On Behalf Of 2QdxY4RzWzUUiLuE@potatochowder.com
    Sent: Wednesday, April 12, 2023 3:17 PM
    To: python-list@python.org
    Subject: Re: Weak Type Ability for Python

    On 2023-04-12 at 14:51:44 -0400,
    Thomas Passin <list1@tompassin.net> wrote:

    On 4/12/2023 1:11 PM, Chris Angelico wrote:
    On Thu, 13 Apr 2023 at 03:05, Ali Mohseni Roodbari <ali.mohseniroodbari@gmail.com> wrote:

    Hi all,
    Please make this command for Python (if possible):

    x=1
    y='a'
    wprint (x+y)
    1a

    In fact make a new type of print command which can print and show
    strings
    and integers together.


    Try:

    print(x, y)

    ChrisA

    It puts a space between "1" and "a", whereas the question does not want
    the
    space. print(f'{x}{y}') would do it, but only works for variables named
    "x"
    and "y".

    Or possibly print(x, y, sep='').

    As happens so often, the OP has not specified what he actually wants to do
    so we can only answer the very specific question.

    Agreed.
    --
    https://mail.python.org/mailman/listinfo/python-list

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Dennis Lee Bieber@21:1/5 to All on Wed Apr 12 22:47:17 2023
    On Thu, 13 Apr 2023 12:21:58 +1000, Cameron Simpson <cs@cskk.id.au>
    declaimed the following:

    On 12Apr2023 22:12, avi.e.gross@gmail.com <avi.e.gross@gmail.com> wrote:
    I suspect the OP is thinking of languages like PERL or JAVA which guess
    for
    you and make such conversions when it seems to make sense.

    JavaScript guesses. What a nightmare. Java acts like Python and will
    forbid it on type grounds (at compile time with Java, being staticly
    typed).


    REXX -- where everything is considered a string until it needs to be something else.

    REXX-ooRexx_5.0.0(MT)_64-bit 6.05 23 Dec 2022
    rexxtry.rex lets you interactively try REXX statements.
    Each string is executed when you hit Enter.
    Enter 'call tell' for a description of the features.
    Go on - try a few... Enter 'exit' to end.
    x = 1;
    ........................................... rexxtry.rex on WindowsNT
    y = "a";
    ........................................... rexxtry.rex on WindowsNT
    say x||y;
    1a
    ........................................... rexxtry.rex on WindowsNT

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Julio Di Egidio@21:1/5 to Cameron Simpson on Wed Apr 12 20:38:44 2023
    On Thursday, 13 April 2023 at 04:22:32 UTC+2, Cameron Simpson wrote:
    On 12Apr2023 22:12, avi.e...@gmail.com <avi.e...@gmail.com> wrote:

    I suspect the OP is thinking of languages like PERL or JAVA which guess
    for you and make such conversions when it seems to make sense.

    JavaScript guesses. What a nightmare.

    Those who can't read the docs guess, and not just in JS.
    JavaScript, for the chronicle, is a *wonderful* language
    (just increasingly ruined by the latest revisions, but can't
    discuss with "the customer is always right").

    Java acts like Python and will

    Talking of awful languages proper...

    Julio

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Julio Di Egidio@21:1/5 to MRAB on Wed Apr 12 20:39:30 2023
    On Thursday, 13 April 2023 at 04:36:45 UTC+2, MRAB wrote:
    On 2023-04-13 03:21, Cameron Simpson wrote:

    I thought that in Java you can, in fact, concatenate a string and an
    int, so I did a quick search online and it appears that you can.

    Of course.

    Julio

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Cameron Simpson@21:1/5 to MRAB on Thu Apr 13 13:42:38 2023
    On 13Apr2023 03:36, MRAB <python@mrabarnett.plus.com> wrote:
    I thought that in Java you can, in fact, concatenate a string and an
    int, so I did a quick search online and it appears that you can.

    I stand corrected. I could have sworn it didn't, but it has been a long
    time. - Cameron Simpson <cs@cskk.id.au>

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From avi.e.gross@gmail.com@21:1/5 to MRAB on Thu Apr 13 01:38:58 2023
    Given the significant number of languages other than Python that have some version of a feature that allows implicit conversion of unlike operands to concatenate something like a "number" and a string into a string, the
    question may not be silly as to how or why Python chose as it chose.

    As I see it, python did put in quite a bit of customizability and
    flexibility including the ability to create your own object types that alter the behavior of an operator like plus. I have seen plenty of code that takes advantage and makes the user of the code assume that different types can interact seamlessly.

    But it is like many other things. Languages that support a wide variety of integer types such as signed and unsigned versions of integers in 8 bits, sixteen bits, 32 bits and even 64 bits or perhaps higher, will often look
    like they allow you to mix them in various combinations for not just
    addition. But underneath it all can be lots of hidden complexity. I have
    seen languages that make lots of functions with the same names but different signatures and then dispatch a call like add(int8, unsignedint32) to the
    right function that best matches their signature. The functions internally
    can do many things but often convert their arguments to a common format, perform the operations, then perhaps convert back to whatever result output
    was expected.

    In the case being discussed we might have to create something that looks
    like do_plus(int, int) and then do_plus(int, char) and so on.

    The other alternatives can include tables of "generality" and
    "convertibility" with rules that govern how to perform a calculation by changing or upgrading or downgrading things to make a match that can then be handled.

    The issue here is a sort of operator overloading. In Python, "+" does not
    mean plus at all. It means whatever the programmer wanted it to mean. An
    infix line of code that includes "obj1 + obj2" is supposed to investigate
    how to do it. I am not sure if some built-in objects may be different, but
    it does a sequence of operations till it finds what it needs and does it.

    I believe it looks a bit like this. The LHS object, obj1, is examined to see
    if it has defined a __add__() method. If found, it is called and either produces a result or signals it cannot handle obj2 for some reason. If that method is not found, or fails, then it looks to see if the RHS, obj2, has a __radd__() method defined. That can be given obj1 and return an answer or signal failure.

    If obj1 is 5 and obj2 is "pm" then we are using the built-in predefined
    classes that currently have no interest in concatenating or adding unlike
    types like this. If you could add or change these dunder methods (and note
    you may also need to deal with __iadd__() to handle the case where x=5 and
    you write "x += "pm" albeit that could weirdly change the type of x without
    a linter having a clue.

    I suggest the latter argument may be a good enough reason that Python did
    not implement this. There are many good reasons. Does anyone like a language that lets you type 2 + "three" and quietly makes that be 5? Sure, it can be made to work on a subset of number in say English, but will it work in other languages. It can be hard enough now to write code in UNICODE (I have seen some) that tries to determine if a code point represents a number in some language or representation and treats it as a numeral. I have seen the
    numeric bullets such as a dark circle containing a white nine be treated as
    if the user had put in a nine, for example.

    As was mentioned, some languages have different operators for addition
    versus concatenation and in that context, it may be intuitive that using the wrong object type is an implicit call to conversion. Python uses "+" for
    both purposes depending on context and potentially for many more purposes
    the programmer can devise.

    Consider the asterisk operator as a companion concept. It gladly accepts a string and a number in either order and does something somewhat intuitive
    with them by treating multiplication as a sort of repeated addition:

    5 * "6"
    '66666'
    "5" * 6
    '555555'
    3 * "Hello? "
    'Hello? Hello? Hello?

    But it will not handle float.

    "Hello" * 2.5
    TypeError: can't multiply sequence by non-int of type 'float'

    If you want to either truncate a float to an into or round it or take a ceiling, though, it will not guess for you and you must do something
    explicit like this:

    "Hello" * round(2.5)
    'HelloHello'
    "Hello" * round(2.6)
    'HelloHelloHello'
    "Hello" * int(2.6)
    'HelloHello'

    There is a parallel argument here in arguing it should accept a float and truncate it. But since you can easily cast a float to an int, in any of many ways, why have the program choose when it quite likely reflects an error in
    the code. And, no, I do not suggest 2.5 be interpreted as putting in an approximate percentage so that .8 * "Hello" should result in "Hell" ...




    -----Original Message-----
    From: Python-list <python-list-bounces+avi.e.gross=gmail.com@python.org> On Behalf Of Cameron Simpson
    Sent: Wednesday, April 12, 2023 11:43 PM
    To: python-list@python.org
    Subject: Re: Weak Type Ability for Python

    On 13Apr2023 03:36, MRAB <python@mrabarnett.plus.com> wrote:
    I thought that in Java you can, in fact, concatenate a string and an
    int, so I did a quick search online and it appears that you can.

    I stand corrected. I could have sworn it didn't, but it has been a long
    time. - Cameron Simpson <cs@cskk.id.au>
    --
    https://mail.python.org/mailman/listinfo/python-list

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Chris Angelico@21:1/5 to avi.e.gross@gmail.com on Thu Apr 13 17:01:41 2023
    On Thu, 13 Apr 2023 at 15:40, <avi.e.gross@gmail.com> wrote:
    And, no, I do not suggest 2.5 be interpreted as putting in an
    approximate percentage so that .8 * "Hello" should result in "Hell" ...

    $ pike
    Pike v8.1 release 15 running Hilfe v3.5 (Incremental Pike Frontend)
    Ok.
    "Hello, world! " * 2.5;
    (1) Result: "Hello, world! Hello, world! Hello, "
    "Hello, world! Hello, world! Hello, " / 10;
    (2) Result: ({ /* 3 elements */
    "Hello, wor",
    "ld! Hello,",
    " world! He"
    })
    "Hello, world! Hello, world! Hello, " % 10;
    (3) Result: "llo, "
    "Hello, world! Hello, world! Hello, " / 10.0;
    (4) Result: ({ /* 4 elements */
    "Hello, wor",
    "ld! Hello,",
    " world! He",
    "llo, "
    })


    Multiplying and dividing strings by floats makes perfect sense. (The
    ({ }) notation is Pike's array literal syntax; consider it equivalent
    to Python's square brackets for a list.)

    ChrisA

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From J. Pic@21:1/5 to ali.mohseniroodbari@gmail.com on Thu Apr 13 13:35:16 2023
    print(f'{x}{y}') ?

    On Wed, Apr 12, 2023 at 7:06 PM Ali Mohseni Roodbari < ali.mohseniroodbari@gmail.com> wrote:

    Hi all,
    Please make this command for Python (if possible):

    x=1
    y='a'
    wprint (x+y)
    1a

    In fact make a new type of print command which can print and show strings
    and integers together.

    Sincerely yours,
    Ali.
    --
    https://mail.python.org/mailman/listinfo/python-list



    --
    Personnel et confidentiel

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Thomas Passin@21:1/5 to avi.e.gross@gmail.com on Thu Apr 13 08:10:30 2023
    On 4/13/2023 1:38 AM, avi.e.gross@gmail.com wrote:
    In Python, "+" does not
    mean plus at all. It means whatever the programmer wanted it to mean. An infix line of code that includes "obj1 + obj2" is supposed to investigate
    how to do it. I am not sure if some built-in objects may be different, but
    it does a sequence of operations till it finds what it needs and does it.

    A really nice example of this is pathlib in the standard library. You
    can write things like this, overloading the "/" operator:

    from pathlib import PurePath
    pth = PurePath('c:/') / 'temp' / 'python'
    pth
    PureWindowsPath('c:/temp/python')
    str(pth)
    'c:\\temp\\python'

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Stefan Ram@21:1/5 to Thomas Passin on Thu Apr 13 11:50:29 2023
    Thomas Passin <list1@tompassin.net> writes:
    As happens so often, the OP has not specified what he actually wants to
    do so we can only answer the very specific question.

    If tomorrow Python would allow "string+int" and "int+string"
    in the sense of "string+str(int)" and "str(int)+string",
    what harm would be there?

    But for now, I think a typical approach would be to just use "str",
    i.e., "string+str(int)" and "str(int)+string".

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Grant Edwards@21:1/5 to Cameron Simpson on Thu Apr 13 08:25:51 2023
    On 2023-04-13, Cameron Simpson <cs@cskk.id.au> wrote:
    On 12Apr2023 22:12, avi.e.gross@gmail.com <avi.e.gross@gmail.com> wrote:

    I suspect the OP is thinking of languages like PERL or JAVA which guess
    for you and make such conversions when it seems to make sense.

    JavaScript guesses. What a nightmare.

    So does PHP. What's really impressive is that it never seems to guess correctly. :)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From avi.e.gross@gmail.com@21:1/5 to avi.e.gross@gmail.com on Thu Apr 13 12:05:53 2023
    Chris, I was not suggesting it for Python as one of many possible implementations.

    I do see perfectly valid uses in other contexts. For example, if I have a program that displays my text as pixels in some font and size, I may indeed want the text clipped at 2 1/2 repetitions. But as always, when there are choices to be made, you have to very clearly document the choice or offer
    ways to do it another way. In a non-fixed-width font, 2.5 may mean knowing
    how many pixels and adjusting so that a narrow letter "i" may be shown in
    one font and not another, for example.

    If you want completeness, sure, you can define fractional parts of a string
    in this context by the percentage of CHARACTERS in it. But as we have often seen, in other encodings you need to differentiate between varying numbers
    of bytes versus the underlying symbols they represent. Your example from
    the Pike language not only supports the multiplication of a string but
    division and mod. Python currently does not allow those.

    So why not extend it to allow complex numbers?

    "Hello" * complex(5,0)
    TypeError: can't multiply sequence by non-int of type 'complex'
    "Hello" * complex(0,5)
    TypeError: can't multiply sequence by non-int of type 'complex'

    The first one above is actually perfectly valid in the sense that the real
    part is 5 and there is no imaginary component. With a bit of effort, I can
    use the complexity to work:

    "Hello" * int(complex(5,0).real)
    'HelloHelloHelloHelloHello'

    Let me reiterate. There are languages that do all kinds of interesting
    things and some of what Python has done is seen by others as interesting.
    They regularly borrow from each other or use parts and innovate further. I
    have no serious objection to making well-thought-out changes if they are determined to be not only useful, but of higher priority than a long
    shopping list of other requests. I am wary of overly bloating a language by placing too many things in the core.

    It strikes me as doable to create a module that encapsulates a feature like this in a limited way. What may be needed is just a carefully constructed
    class that starts off as similar to str and adds some methods. Any user
    wanting to use the new feature would either start using the new class
    directly or cast their str to it when they want it to be useable.

    But the good news is that I am nowhere in the python hierarchy and have no ability to make any changes. This is purely academic for me. And, if I want such features and see tons of existing ways to get what I want or can roll
    it for myself, ...


    -----Original Message-----
    From: Python-list <python-list-bounces+avi.e.gross=gmail.com@python.org> On Behalf Of Chris Angelico
    Sent: Thursday, April 13, 2023 3:02 AM
    To: python-list@python.org
    Subject: Re: Weak Type Ability for Python

    On Thu, 13 Apr 2023 at 15:40, <avi.e.gross@gmail.com> wrote:
    And, no, I do not suggest 2.5 be interpreted as putting in an
    approximate percentage so that .8 * "Hello" should result in "Hell" ...

    $ pike
    Pike v8.1 release 15 running Hilfe v3.5 (Incremental Pike Frontend)
    Ok.
    "Hello, world! " * 2.5;
    (1) Result: "Hello, world! Hello, world! Hello, "
    "Hello, world! Hello, world! Hello, " / 10;
    (2) Result: ({ /* 3 elements */
    "Hello, wor",
    "ld! Hello,",
    " world! He"
    })
    "Hello, world! Hello, world! Hello, " % 10;
    (3) Result: "llo, "
    "Hello, world! Hello, world! Hello, " / 10.0;
    (4) Result: ({ /* 4 elements */
    "Hello, wor",
    "ld! Hello,",
    " world! He",
    "llo, "
    })


    Multiplying and dividing strings by floats makes perfect sense. (The
    ({ }) notation is Pike's array literal syntax; consider it equivalent
    to Python's square brackets for a list.)

    ChrisA
    --
    https://mail.python.org/mailman/listinfo/python-list

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Chris Angelico@21:1/5 to avi.e.gross@gmail.com on Fri Apr 14 02:11:45 2023
    On Fri, 14 Apr 2023 at 02:05, <avi.e.gross@gmail.com> wrote:
    So why not extend it to allow complex numbers?

    "Hello" * complex(5,0)
    TypeError: can't multiply sequence by non-int of type 'complex'
    "Hello" * complex(0,5)
    TypeError: can't multiply sequence by non-int of type 'complex'


    Clearly a missed opportunity to rotate the text through a specified angle.

    ChrisA

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From aapost@21:1/5 to Ali Mohseni Roodbari on Thu Apr 13 12:27:44 2023
    On 4/12/23 04:03, Ali Mohseni Roodbari wrote:

    On 4/13/23 07:50, Stefan Ram wrote:
    If tomorrow Python would allow "string+int" and "int+string"
    in the sense of "string+str(int)" and "str(int)+string",
    what harm would be there?

    But for now, I think a typical approach would be to just use "str",
    i.e., "string+str(int)" and "str(int)+string".


    I agree with Py Zen rule 2 in this case:
    Explicit is better than implicit.

    I hate when things try to guess what I am doing... It is why I can't use
    lxml.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From avi.e.gross@gmail.com@21:1/5 to avi.e.gross@gmail.com on Thu Apr 13 12:55:13 2023
    [THIS CLAIMER: a bit off a bit off a bit off topic, imagine that]

    Chris,

    You have a gift of taking things I think about but censor myself from
    including in my post and then blurting it out! LOL!

    The original question in this thread now seems a dim memory but we are now discussing not how to add a number to a string but how to multiply a string
    to make n combined copies and then what it means to have a fractional copy
    and finally a way to specify a rotation to the result. Argh!!!!

    But since you brought it up as a way of looking at what multiplying by an imaginary number might mean, as in rotating text, I am now going to throw in
    a May Tricks even if it is only April.

    So should I now extend a language so a rotation matrix is allowed to
    multiply text or even a nested list like:

    [ [ cos(theta), -sin(theta) ],
    [ sin(theta), cos(theta) ]

    While we are at it, why stop with imaginary numbers when you can imagine extensions thereof? Unfortunately, it has been proven there are and can only
    be two additional such constructs. Quaternions have three distinct imaginary axes called i,j,k and some see them as interesting to show multidimensional objects in all kinds of places such as computer vision or orbital mechanics. Octonions have seven such other imaginary axes and have uses in esoteric
    places like String Theory or Quantum Logic.

    And, yes, you can use these critters in python. You can add a quaternion
    type to numpy for example. Yep, octonions too. See modules like pyoctonion
    and pyquaternion and much more.

    The immoral moral of this story is that once you start opening some doors,
    you may find people clamoring to let in ever more things and features. You
    can easily bog down your code to the point where finding the commonly used parts becomes a chore as you trudge through lots of code that is rarely used but there for completeness.

    Oh, I want to make something clear before I get another message spelling out what I was thinking but chose to omit.

    I slightly misled you above. Yes, it has been proven no number higher than 8 (meaning one real dimension and seven distinct imaginary ones) can exist so octonions are the final part of that story. Well, not exactly. You lose commutativity when going from quaternions to octonions and you lose full associativity if you go higher. But you can make all kinds of mathematical constructs like sedenions with 16 dimensions.

    I cannot imagine ever trying to multiply a string by these critters but who knows? As I noted above, if you set some parts of each of the above to zero, they all can look like something with a real part like 3, and no (meaning
    zero point zero) imaginary parts. So you could argue you should support all kinds of things that MAY on examination turn out to be convertible to an integer or double.

    -----Original Message-----
    From: Python-list <python-list-bounces+avi.e.gross=gmail.com@python.org> On Behalf Of Chris Angelico
    Sent: Thursday, April 13, 2023 12:12 PM
    To: python-list@python.org
    Subject: Re: Weak Type Ability for Python

    On Fri, 14 Apr 2023 at 02:05, <avi.e.gross@gmail.com> wrote:
    So why not extend it to allow complex numbers?

    "Hello" * complex(5,0)
    TypeError: can't multiply sequence by non-int of type 'complex'
    "Hello" * complex(0,5)
    TypeError: can't multiply sequence by non-int of type 'complex'


    Clearly a missed opportunity to rotate the text through a specified angle.

    ChrisA
    --
    https://mail.python.org/mailman/listinfo/python-list

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From 2QdxY4RzWzUUiLuE@potatochowder.com@21:1/5 to Dennis Lee Bieber on Thu Apr 13 13:47:17 2023
    On 2023-04-12 at 22:47:17 -0400,
    Dennis Lee Bieber <wlfraed@ix.netcom.com> wrote:

    REXX -- where everything is considered a string until it needs to be something else.

    I see your REXX, and raise you an awk,¹ except that awk won't add a
    string to a number, or a number to string, but it will concatenate in
    both cases:

    $ echo 1 a | awk '{print $1 $2}{print $1 + $2}'
    1a
    1

    $ echo 1 a | awk '{print $2 $1}{print $2 + $1}'
    a1
    1

    $ echo 1 2 | awk '{print $1 $2}{print $2 + $1}'
    12
    3

    ¹ GNU Awk 5.2.1, API 3.2, PMA Avon 8-g1, (GNU MPFR 4.2.0, GNU MP 6.2.1)

    Dan

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Thomas Passin@21:1/5 to avi.e.gross@gmail.com on Thu Apr 13 15:04:02 2023
    On 4/13/2023 2:36 PM, avi.e.gross@gmail.com wrote:
    But having
    precedence rules and also allowing the other methods, should work fine for a good segment of people except perhaps the ones who like Reverse Polish Notation and insist on 5 4 3 + * instead.

    For *reading*, I prefer the usual 5 * (4 + 3) form. But for using a calculator, I much prefer RPN.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From avi.e.gross@gmail.com@21:1/5 to Ali Mohseni Roodbari on Thu Apr 13 14:36:47 2023
    This reminds me a bit of complaints that the parser does not do what you
    want when you do not supply parentheses in an expression like:

    5 * 4 + 3

    In many and maybe most languages it is seen as (5*4)+3 UNLESS you tell it
    you want 5*(4+3). There are precedence and associativity rules.

    Of course the computer might guess you meant the latter or could refuse to
    do it and offer you a choice before calculating it. Or the language may
    insist on parentheses always so you would need to also say ((5*4)+3) with no default behavior.

    The golden rule remains. If there is more than one way something can be
    done, then either the programmer must make the choice explicit OR the documentation must very clearly warn which path was chosen and perhaps point
    to ways to do other choices.

    Some people take more complex (but not Complex) arithmetic than the above
    and break it up into quite a few simple parts like:

    temp1 = 4 + 3
    result = 5 + temp1

    Of course, the latter can be hard to read and understand for some people,
    and some (others?) find fully parenthesized versions hard. But having precedence rules and also allowing the other methods, should work fine for a good segment of people except perhaps the ones who like Reverse Polish
    Notation and insist on 5 4 3 + * instead.


    -----Original Message-----
    From: Python-list <python-list-bounces+avi.e.gross=gmail.com@python.org> On Behalf Of aapost
    Sent: Thursday, April 13, 2023 12:28 PM
    To: python-list@python.org
    Subject: Re: Weak Type Ability for Python

    On 4/12/23 04:03, Ali Mohseni Roodbari wrote:

    On 4/13/23 07:50, Stefan Ram wrote:
    If tomorrow Python would allow "string+int" and "int+string"
    in the sense of "string+str(int)" and "str(int)+string",
    what harm would be there?

    But for now, I think a typical approach would be to just use "str",
    i.e., "string+str(int)" and "str(int)+string".


    I agree with Py Zen rule 2 in this case:
    Explicit is better than implicit.

    I hate when things try to guess what I am doing... It is why I can't use
    lxml.
    --
    https://mail.python.org/mailman/listinfo/python-list

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Chris Angelico@21:1/5 to avi.e.gross@gmail.com on Fri Apr 14 05:30:55 2023
    On Fri, 14 Apr 2023 at 02:55, <avi.e.gross@gmail.com> wrote:
    And, yes, you can use these critters in python. You can add a quaternion
    type to numpy for example. Yep, octonions too.

    Hang on hang on hang on. I can multiply a string by an onion? The
    possibilities of script-controlled culinary arts just became that much
    more awesome...

    ChrisA

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Chris Angelico@21:1/5 to Dennis Lee Bieber on Fri Apr 14 05:35:22 2023
    On Fri, 14 Apr 2023 at 03:29, Dennis Lee Bieber <wlfraed@ix.netcom.com> wrote:

    On Thu, 13 Apr 2023 12:21:58 +1000, Cameron Simpson <cs@cskk.id.au>
    declaimed the following:

    On 12Apr2023 22:12, avi.e.gross@gmail.com <avi.e.gross@gmail.com> wrote:
    I suspect the OP is thinking of languages like PERL or JAVA which guess >>for
    you and make such conversions when it seems to make sense.

    JavaScript guesses. What a nightmare. Java acts like Python and will
    forbid it on type grounds (at compile time with Java, being staticly >typed).


    REXX -- where everything is considered a string until it needs to be something else.

    REXX-ooRexx_5.0.0(MT)_64-bit 6.05 23 Dec 2022
    rexxtry.rex lets you interactively try REXX statements.
    Each string is executed when you hit Enter.
    Enter 'call tell' for a description of the features.
    Go on - try a few... Enter 'exit' to end.
    x = 1;
    ........................................... rexxtry.rex on WindowsNT
    y = "a";
    ........................................... rexxtry.rex on WindowsNT
    say x||y;
    1a
    ........................................... rexxtry.rex on WindowsNT

    REXX - where everything is a string, arithmetic can be done on
    strings, and data structures are done in the variable name instead of
    the value.

    I've seen quite a few strings-only languages, but I can't think of any
    other language than REXX where you create arrays and dictionaries by
    using computed variable names.

    It was quite the experience back in the day (as OS/2's native
    scripting language), and one that I'm truly glad to have had, as it
    taught me so much about the differences between languages.

    (It also taught me to treasure good documentation and value it as
    truly precious, because SysSetObjectData was an incredibly powerful
    function whose docs just referred to WinSetObjectData, and the window
    manager's docs weren't part of what I had available.)

    ChrisA

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Julio Di Egidio@21:1/5 to avi.e...@gmail.com on Thu Apr 13 15:07:32 2023
    On Thursday, 13 April 2023 at 18:56:00 UTC+2, avi.e...@gmail.com wrote:
    [THIS CLAIMER: a bit off a bit off a bit off topic, imagine that]

    I slightly misled you above. Yes, it has been proven no number higher than 8 (meaning one real dimension and seven distinct imaginary ones) can exist so octonions are the final part of that story. Well, not exactly.
    You lose
    commutativity when going from quaternions to octonions and you lose full associativity if you go higher. But you can make all kinds of mathematical constructs like sedenions with 16 dimensions.

    You literally don't know what you are talking about.
    Look up "GEOMETRIC ALGEBRA". It preserves all the
    properties we cherish, to the point that we can even
    do General Relativity with it, in flat space!!

    The immoral moral of this story is that once you start opening some doors,

    No worries, of course that's not something CNN or NASA
    or sci.physics.relativity or Quanta or Wired magazine or the
    CIA are gonna talk about any soon...

    HTH,

    Julio

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From gene heskett@21:1/5 to Dennis Lee Bieber on Thu Apr 13 19:15:17 2023
    On 4/13/23 13:34, Dennis Lee Bieber wrote:
    On Thu, 13 Apr 2023 12:21:58 +1000, Cameron Simpson <cs@cskk.id.au>
    declaimed the following:

    On 12Apr2023 22:12, avi.e.gross@gmail.com <avi.e.gross@gmail.com> wrote:
    I suspect the OP is thinking of languages like PERL or JAVA which guess
    for
    you and make such conversions when it seems to make sense.

    JavaScript guesses. What a nightmare. Java acts like Python and will
    forbid it on type grounds (at compile time with Java, being staticly
    typed).


    REXX -- where everything is considered a string until it needs to be something else.

    REXX-ooRexx_5.0.0(MT)_64-bit 6.05 23 Dec 2022
    rexxtry.rex lets you interactively try REXX statements.
    Each string is executed when you hit Enter.
    Enter 'call tell' for a description of the features.
    Go on - try a few... Enter 'exit' to end.

    You missed the best REXX, Dennis.

    ARexx for the amiga's. Bill Hawes wrote in a link to everything amigados
    had and we wrote, in ARexx, stuff that Amigados didn't have starting
    with a cron, a better cron than Paul Vixies. Worst, Bill never got a
    dime from commode-door for the best language it had, We served our WDTV
    web page with it in the middle 90's. Using ARexx and early php. Now its
    farmed out and 99% commercial junk.

    x = 1;
    ........................................... rexxtry.rex on WindowsNT
    y = "a";
    ........................................... rexxtry.rex on WindowsNT
    say x||y;
    1a
    ........................................... rexxtry.rex on WindowsNT

    Cheers, Gene Heskett.
    --
    "There are four boxes to be used in defense of liberty:
    soap, ballot, jury, and ammo. Please use in that order."
    -Ed Howdershelt (Author, 1940)
    If we desire respect for the law, we must first make the law respectable.
    - Louis D. Brandeis
    Genes Web page <http://geneslinuxbox.net:6309/>

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Julio Di Egidio@21:1/5 to avi.e...@gmail.com on Thu Apr 13 16:50:46 2023
    On Friday, 14 April 2023 at 01:26:12 UTC+2, avi.e...@gmail.com wrote:

    Can I bring a part of this discussion a bit closer to Python?

    You can do, you can undo.

    Unfortunately, if they BOTH are flexible, how do you decide whether
    to add them as numbers or concatenate them as strings?

    By reading the docs: the reference documentation in particular.
    (Except when the reference documentation itself is "flexible"...)

    Julio

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Alan Gauld@21:1/5 to Chris Angelico on Fri Apr 14 00:49:45 2023
    On 13/04/2023 20:35, Chris Angelico wrote:

    REXX - where everything is a string,

    It was quite the experience back in the day (as OS/2's native
    scripting language),

    I briefly met REXX on a mainframe, but I did play with OS/2 for
    a year or two. Back when it looked like it might be a rival to M$

    OS/2 running NeXTstep now that would have been a platform
    for the 90s... both so near yet so far.

    --
    Alan G
    Author of the Learn to Program web site
    http://www.alan-g.me.uk/
    http://www.amazon.com/author/alan_gauld
    Follow my photo-blog on Flickr at:
    http://www.flickr.com/photos/alangauldphotos

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From avi.e.gross@gmail.com@21:1/5 to All on Thu Apr 13 19:25:45 2023
    Can I bring a part of this discussion a bit closer to Python?

    I stipulate that quite a few languages, including fairly early ones, treated text often as numbers. Ultimately, much of programming is about taking in
    text and often segregating parts into various buckets either explicitly or
    by checking if it has a decimal point or looks like scientific notation or
    in how it seems to be used.

    Is there any concept in Python of storing information in some way, such as text, and implementing various ideas or interfaces so that you can query if
    the contents are willing and able to be viewed in one of many other ways?

    As an example, an object may store a fairly large number as a text string in decimal format. The number is big enough that it cannot be fully represented
    in an 8 bit storage as in a byte or in a signed or unsigned 16-bit integer
    but can be stored in something larger. It may be possible to store it in a double precision floating point but not smaller. Yes, I know Python by
    default uses indefinite length integers, but you get the idea.

    Or it may be storing text in some format but the object is willing to
    transform the text into one of several other formats when needed. The text
    may also have attributes such as whether it is in English or Hungarian or is mixed-language.

    So for some applications, perhaps leaving the object as a string all the
    time may be reasonable. If some operation wishes to use the contents, the interface can be queried to see what other formats it can be coerced into
    and perhaps a specified set of methods need to be included that perform your transition for you such as object.return_as_int64()

    This can have wider implications. Imagine an object holding text in French
    that has been tested by humans using a program like Google Translate and
    deemed reasonable for translating into a specific dozen languages such as Esperanto and not certified into others like Klingon or High Valyrian or
    ASL. The object could contain interfaces for the languages it supports but
    does not store the translations, especially when the content is dynamic,
    such as a form letter that has been instantiated with a name and address and perhaps a part detailing what is being billed or shipped. Instead, the
    object can present an interface that lets a user determine if it supports dynamic translation to one or more target, such as the Quebec version of
    French or a British versus American version of English.

    I am being quite general here and lots of programs out there already
    probably have their own way of providing such facilities on a case-by-case basis. But do some languages have some support within the language itself?

    I do note some languages allow objects to oddly belong to multiple classes
    at once and have used that feature as a way to check if an object has some capabilities. Some languages have concepts like a mix-in and Python does
    allow thing like multiple inheritance albeit it often is best not to use it much. It does have ideas about how to test if a class implements some things
    by seeing if various dunder methods are in place.

    My reason for asking, is based on the discussion. If I want to use plus with
    an integer and a string, it may be reasonable for the interpreter to ask one
    or the other operand if they are able to be seen another way. If an integer indicates it can be seen as text, great. If a string indicates it believes
    it can deliver a number, great.

    Unfortunately, if they BOTH are flexible, how do you decide whether to add
    them as numbers or concatenate them as strings?

    Sigh!


    -----Original Message-----
    From: Python-list <python-list-bounces+avi.e.gross=gmail.com@python.org> On Behalf Of Chris Angelico
    Sent: Thursday, April 13, 2023 3:35 PM
    To: python-list@python.org
    Subject: Re: Weak Type Ability for Python

    On Fri, 14 Apr 2023 at 03:29, Dennis Lee Bieber <wlfraed@ix.netcom.com>
    wrote:

    On Thu, 13 Apr 2023 12:21:58 +1000, Cameron Simpson <cs@cskk.id.au>
    declaimed the following:

    On 12Apr2023 22:12, avi.e.gross@gmail.com <avi.e.gross@gmail.com> wrote:
    I suspect the OP is thinking of languages like PERL or JAVA which guess >>for
    you and make such conversions when it seems to make sense.

    JavaScript guesses. What a nightmare. Java acts like Python and will
    forbid it on type grounds (at compile time with Java, being staticly >typed).


    REXX -- where everything is considered a string until it needs to
    be
    something else.

    REXX-ooRexx_5.0.0(MT)_64-bit 6.05 23 Dec 2022
    rexxtry.rex lets you interactively try REXX statements.
    Each string is executed when you hit Enter.
    Enter 'call tell' for a description of the features.
    Go on - try a few... Enter 'exit' to end.
    x = 1;
    ........................................... rexxtry.rex on WindowsNT
    y = "a";
    ........................................... rexxtry.rex on WindowsNT
    say x||y;
    1a
    ........................................... rexxtry.rex on WindowsNT

    REXX - where everything is a string, arithmetic can be done on
    strings, and data structures are done in the variable name instead of
    the value.

    I've seen quite a few strings-only languages, but I can't think of any
    other language than REXX where you create arrays and dictionaries by
    using computed variable names.

    It was quite the experience back in the day (as OS/2's native
    scripting language), and one that I'm truly glad to have had, as it
    taught me so much about the differences between languages.

    (It also taught me to treasure good documentation and value it as
    truly precious, because SysSetObjectData was an incredibly powerful
    function whose docs just referred to WinSetObjectData, and the window
    manager's docs weren't part of what I had available.)

    ChrisA
    --
    https://mail.python.org/mailman/listinfo/python-list

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Alan Gauld@21:1/5 to avi.e.gross@gmail.com on Fri Apr 14 01:13:56 2023
    On 14/04/2023 00:25, avi.e.gross@gmail.com wrote:

    Is there any concept in Python of storing information in some way, such as text, and implementing various ideas or interfaces so that you can query if the contents are willing and able to be viewed in one of many other ways?

    Are you talking about something like a C union type (or a Pascal
    variant record)? I'm not aware of any such feature in Python but
    have often thought it would be a nice to have for the rare cases
    where its useful.

    Or it may be storing text in some format but the object is willing to transform the text into one of several other formats when needed. The text may also have attributes such as whether it is in English or Hungarian or is mixed-language.

    Or are you meaning something like an extension to the
    struct module that can interpret a bytestring in any way
    defined by a format string?

    basis. But do some languages have some support within the language itself?

    The closest to what you seem to mean is, I think, the C union
    type, at least in my experience. But you have to define all
    the ways you can interpret the type up front in the type
    definition.

    My reason for asking, is based on the discussion. If I want to use plus with an integer and a string, it may be reasonable for the interpreter to ask one or the other operand if they are able to be seen another way.

    You can achieve that in a slightly different way in Tcl which
    allows you to redefine all the operators (commands in Tcl-speak)
    in the language so redefining plus is easy. Doing it based on
    type is more tricky but doable.

    Unfortunately, if they BOTH are flexible, how do you decide whether to add them as numbers or concatenate them as strings?

    Yes, that's where it becomes a designer's arbitrary choice.

    --
    Alan G
    Author of the Learn to Program web site
    http://www.alan-g.me.uk/
    http://www.amazon.com/author/alan_gauld
    Follow my photo-blog on Flickr at:
    http://www.flickr.com/photos/alangauldphotos

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Greg Ewing@21:1/5 to avi.e.gross@gmail.com on Fri Apr 14 12:54:45 2023
    On 14/04/23 4:55 am, avi.e.gross@gmail.com wrote:
    While we are at it, why stop with imaginary numbers when you can imagine extensions thereof? Unfortunately, it has been proven there are and can only be two additional such constructs.

    You can go beyond that if you broaden your horizons enough.
    There are Clifford algebras, Lie algebras, ...

    Not sure what any of those should do to strings, though. :-)

    --
    Greg

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Chris Angelico@21:1/5 to Alan Gauld on Fri Apr 14 10:19:03 2023
    On Fri, 14 Apr 2023 at 09:49, Alan Gauld <learn2program@gmail.com> wrote:

    On 13/04/2023 20:35, Chris Angelico wrote:

    REXX - where everything is a string,

    It was quite the experience back in the day (as OS/2's native
    scripting language),

    I briefly met REXX on a mainframe, but I did play with OS/2 for
    a year or two. Back when it looked like it might be a rival to M$

    OS/2 running NeXTstep now that would have been a platform
    for the 90s... both so near yet so far.


    OS/2 was the primary operating system in our house from about 1992ish
    until maybe the early 2000s - possibly 2010 even, depending on how you
    count things. After a while we needed to permit the occasional Windows
    system due to software that didn't work, and then I started deploying
    some Linux systems. Eventually the Linux boxes outnumbered the OS/2,
    and finally the last OS/2 system was virtualized under Linux,
    completing the transition.

    But along the way, I spent many years learning the way that OS/2
    works, and that's been so valuable to me ever since. The system was
    built from the ground up with threads in mind, so every programmer, as
    a matter of course, just learned about threads. It's that simple. Want
    to make a GUI app? The rule is, you respond to a window message within
    a very few milliseconds; if you can't do your processing in that much
    time, you spin off a thread. Easy. VX-REXX actually did that for every
    message automatically, running thread zero for the system GUI message
    loop, and feeding messages to a REXX message loop; you could, of
    course, still spawn your own REXX threads as needed.

    The entire Presentation Manager and Workplace Shell (broadly
    equivalent to a Linux "desktop manager", I think? Kinda?) were object
    oriented; you would have a WPDataFile for every, well, data file, but
    some of those might be subclasses of WPDataFile. And it was fairly straight-forward to write your own subclass of WPDataFile, and there
    was an API to say "if you would ever create a WPDataFile, instead
    create one of my class instead". This brilliant technique allowed
    anyone to enhance the desktop in any way, quite impressive especially
    for its time. I've yearned for that ever since, in various systems,
    although I'm aware that it would make quite a mess of Python if you
    could say "class EnhancedInt(int): ..." and then "any time you would
    create an int, create an EnhancedInt instead". A bit tricky to
    implement.

    Ahh, the memories. Clinging onto several old Realtek RTL8029 cards
    long past the days when ten megabit networking was considered
    adequate, because I knew that I could ALWAYS rely on them. Seriously,
    those things just never gave me issues. Problems with networking? Slap
    in an 8029 and see if it's the card or something else. Need to
    download the driver before your network card works? Grab an 8029, boot
    with that, fetch driver, try again. Good times.

    ChrisA

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Richard Damon@21:1/5 to avi.e.gross@gmail.com on Thu Apr 13 20:53:21 2023
    On 4/13/23 7:25 PM, avi.e.gross@gmail.com wrote:
    s there any concept in Python of storing information in some way, such as text, and implementing various ideas or interfaces so that you can query if the contents are willing and able to be viewed in one of many other ways?

    There is nothing that I know of built into Python that does this.

    There is no reason you can't write your own class to implement this.
    Something that by "default" looks like a string, but in some contexts
    (operated on by certain types) sees if its string could be treated as a
    value of some other type, and if so, converts its value to that type and
    does the operation.

    --
    Richard Damon

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Peter J. Holzer@21:1/5 to Grant Edwards on Fri Apr 14 02:19:27 2023
    On 2023-04-13 08:25:51 -0700, Grant Edwards wrote:
    On 2023-04-13, Cameron Simpson <cs@cskk.id.au> wrote:
    On 12Apr2023 22:12, avi.e.gross@gmail.com <avi.e.gross@gmail.com> wrote:

    I suspect the OP is thinking of languages like PERL or JAVA which guess >>for you and make such conversions when it seems to make sense.

    JavaScript guesses. What a nightmare.

    So does PHP.

    Not in this case. Like Perl (Not PERL) it has different operators for concatenation and addition. So $a + $b is always addition, never
    concatenation.

    Well, at least numbers and strings. For arrays its a (somewhat bizarre)
    union.

    hp

    --
    _ | Peter J. Holzer | Story must make more sense than reality.
    |_|_) | |
    | | | hjp@hjp.at | -- Charles Stross, "Creative writing
    __/ | http://www.hjp.at/ | challenge!"

    -----BEGIN PGP SIGNATURE-----

    iQIzBAABCgAdFiEETtJbRjyPwVTYGJ5k8g5IURL+KF0FAmQ4nAoACgkQ8g5IURL+ KF3Dcg/6A002I/jPPAC367x77t/JWd5yCO191UxFp1O/kE/hOij4/BgCNBHJu731 LpB0E9FqamypI31T8J4FedX1XQ29KJBVdcNP5JQ42Wivc4VsEiQRcdxg3it1zBi+ KpONUzupGnbZ22ZXokvm6eCzjioBwWbSeE101qFjVWv4RVgocFZpoLQbXPYa+X/M gPDPgwG0zioh0rX4DOUcV6jCUlYEE89mVJA7IvsusqoCUd5i2QMxMiF8voW7tO8J siGg73G+XluIm1A42UeHzPOtN+jeYEzh8+gRmv8l9xRA/ht+m97X6Ch+JNM4+A9T wdudpP4/J4Yg1mXq3BM6kh0A2IZsfdP2y/cpublw9qOzXuXO0Ep/E7ATUXJOJLyT L1nfF+4xgJXk40fjdWg8i0Ysl47cqVpwhD3rWuveFe4BhISMxhvDcif2t4aBeYt1 jwgJx5wEiUCe6qaH1BAI60usKVKXLDD9IbsFdqkh2vjmc6r7vSQKWaTggBMTgh+0 15598wJu+j7qyNOpPBTBSiIsv61XOncvm7EgXjAbmuE0IqrKNEvRskWZMKEgp44D AJhbaLe1HjVPyY0w58N1PnCsmUBPf/c4W6scrsUX5cax/1PMh+97lxljyEEHV2cc 0hUuZCfENZI0msbXyLd9AH6ejTqOtOuZt6X2WfZ
  • From avi.e.gross@gmail.com@21:1/5 to avi.e.gross@gmail.com on Thu Apr 13 22:14:25 2023
    Alan,

    Your guess is not quite what I intended.

    Something like a C union is just a piece of memory large enough to hold one of several kinds of content and some way to figure out which is currently in place.

    I am looking at a data structure that is an object of some class and stores the data in any way that it feels like. But it may be a bit of a chameleon that shows one face or another as needed. I can write code now that simply adds various access methods
    to the class used and also provides a way to query if it supports some interfaces.

    Consider a dumb example. I have an object that holds a temperature and stores it in say degrees Celsius. There are simple formulas that can convert it to Fahrenheit or Kelvin or Rankine. So you can create access methods like get_as_Rankine() but this
    will only be useful for some programs that know about the interface.

    So what if you had a variable in the class such as supported_formats that presented something like a list of scales supported using an official set of names? It may even be possible to get a reference to the function to call to get that functionality, or
    perhaps you have one access function that accepts any argument on the list and delivers what is wanted.

    The temperature would only need to be stored in one format but be available in many. Of course, you could choose to precalculate and store others, or cache them when one request has come in and so forth.

    Another example would be dates stored in some format in a class that can deliver the result in all kinds of formats. Yes, we have functions that do things like that. But can you see advantages to the class hiding lots of details internally?

    These are just examples but the point is motivated by some interfaces I have seen.

    How do you know if something can be used by a context manner such as in a "with" statement? There may be other ways, but it seems two dunder methods, if present, likely mean it is. They are __enter__() and __exit__().

    There are other interfaces like for iterators, that sometimes are more complex as when some things are not present, it uses others. Can you have a general function like is_iterator() or is_context_manager() that pretty much guarantees it is safe for the
    rest of the code to use the object in the way it wants?

    My comments about overloading plus were a sort of extra idea. I think we have discussed the general algorithm for how Python tries to resolve something like "obj1 op obj2" and not just for the plus operator. There are quite a few dunder methods that
    cover many such operators.

    What I was thinking about was a bit of a twist on that algorithm. I did something very vaguely like this years ago when I was working on how to translate documents from one format to another, such as WANG, Multimate, Wordperfect, plain text, etc. The
    goal was for a sender of an email to add an attachment and send it to many people at once. Each recipient would have a known preference for the type of document format they preferred. I wrote an algorithm in C++ which I got early access to as I was
    working at Bell Labs that effectively used a registered series of translator software along with info on how well or fast they worked, to do as few translations as possible and send each recipient the format they wanted.

    Yes, there were major incompatibilities and you sometimes ended up with some features being dropped or changed. But that is not the point. If format A had do direct translator to format Z, I would find the intersection of formats we had software for to
    translate to from A, and anther set of languages that could be used to translate from to Z. Sometimes it needed multiple hops. It worked fine but never saw the light of day as, weirdly, the project had been canceled months earlier and they were stalling
    while planning the next project and thus let me do what I wanted even though I was integrating my C++ code into a project that was otherwise al in C.

    Now back to Python in this regard. If I type alpha + beta then maybe after trying the methods we have described, if still failing, the algorithm could see if alpha and beta registered what types they could output and see if a match could be made. If a
    number object offered a string version, that would be a match. If the string offered a numeric version, again problem solved. And even if the match was not precise, sometimes the interpreter might know enough to do a bit more and say convert an integer
    into a double if the sizes of the contents allowed.

    The problem with this, and there are many, is that there is a certain nondeterministic aspect that may cause surprises and plenty of cost.

    It was just a academic thought that probably is not needed in the context albeit may be implemented in some projects to bridge things as described or in other novel ways.

    -----Original Message-----
    From: Alan Gauld <learn2program@gmail.com>
    Sent: Thursday, April 13, 2023 8:14 PM
    To: avi.e.gross@gmail.com; python-list@python.org
    Subject: Re: RE: Weak Type Ability for Python

    On 14/04/2023 00:25, avi.e.gross@gmail.com wrote:

    Is there any concept in Python of storing information in some way, such as text, and implementing various ideas or interfaces so that you can query if the contents are willing and able to be viewed in one of many other ways?

    Are you talking about something like a C union type (or a Pascal
    variant record)? I'm not aware of any such feature in Python but
    have often thought it would be a nice to have for the rare cases
    where its useful.

    Or it may be storing text in some format but the object is willing to transform the text into one of several other formats when needed. The text may also have attributes such as whether it is in English or Hungarian or is mixed-language.

    Or are you meaning something like an extension to the
    struct module that can interpret a bytestring in any way
    defined by a format string?

    basis. But do some languages have some support within the language itself?

    The closest to what you seem to mean is, I think, the C union
    type, at least in my experience. But you have to define all
    the ways you can interpret the type up front in the type
    definition.

    My reason for asking, is based on the discussion. If I want to use plus with an integer and a string, it may be reasonable for the interpreter to ask one or the other operand if they are able to be seen another way.

    You can achieve that in a slightly different way in Tcl which
    allows you to redefine all the operators (commands in Tcl-speak)
    in the language so redefining plus is easy. Doing it based on
    type is more tricky but doable.

    Unfortunately, if they BOTH are flexible, how do you decide whether to add them as numbers or concatenate them as strings?

    Yes, that's where it becomes a designer's arbitrary choice.

    --
    Alan G
    Author of the Learn to Program web site
    http://www.alan-g.me.uk/
    http://www.amazon.com/author/alan_gauld
    Follow my photo-blog on Flickr at:
    http://www.flickr.com/photos/alangauldphotos

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From 2QdxY4RzWzUUiLuE@potatochowder.com@21:1/5 to avi.e.gross@gmail.com on Thu Apr 13 22:26:53 2023
    On 2023-04-13 at 22:14:25 -0400,
    avi.e.gross@gmail.com wrote:

    I am looking at a data structure that is an object of some class and
    stores the data in any way that it feels like. But it may be a bit of
    a chameleon that shows one face or another as needed. I can write code
    now that simply adds various access methods to the class used and also provides a way to query if it supports some interfaces.

    Python dicts act mostly like hash tables. All by themselves, hash
    tables are unordered (and in return for giving up that order, you get
    O(1) access to an item if you know its key).

    But when you ask a Python dict for the keys, you always get them in the
    same order, skipping those that have been deleted since the last time
    you asked, and appending the new keys to the end of the list in the
    order in which you added them.

    There's your chameleon.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Thomas Passin@21:1/5 to avi.e.gross@gmail.com on Thu Apr 13 23:10:19 2023
    On 4/13/2023 10:14 PM, avi.e.gross@gmail.com wrote:
    Alan,

    Your guess is not quite what I intended.

    Something like a C union is just a piece of memory large enough to hold one of several kinds of content and some way to figure out which is currently in place.

    I am looking at a data structure that is an object of some class and stores the data in any way that it feels like. But it may be a bit of a chameleon that shows one face or another as needed. I can write code now that simply adds various access
    methods to the class used and also provides a way to query if it supports some interfaces.

    Consider a dumb example. I have an object that holds a temperature and stores it in say degrees Celsius. There are simple formulas that can convert it to Fahrenheit or Kelvin or Rankine. So you can create access methods like get_as_Rankine() but this
    will only be useful for some programs that know about the interface.

    So what if you had a variable in the class such as supported_formats that presented something like a list of scales supported using an official set of names? It may even be possible to get a reference to the function to call to get that functionality,
    or perhaps you have one access function that accepts any argument on the list and delivers what is wanted.

    Now you are starting to sound like COM. You ask an object for its
    IUnknown interface, and from that interface you can query what other
    interfaces it has available. You go on from there.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From avi.e.gross@gmail.com@21:1/5 to avi.e.gross@gmail.com on Thu Apr 13 23:44:56 2023
    Yes, Dave, there are many data structures that can be used to maintain a
    list of output types the class claims to support. Dictionaries have the interesting property that you can presumably have a value that holds a
    member function to access the way the key specifies.

    Ideally, the order is not important for what I am looking for. Generally, I would think that any class like the ones I have been discussing, would want
    to broadcast a fairly short list of output types it would support.

    Of course, if you look at my date example, the list could be quite big but
    if you simply use something like strftime() for many of the formats, perhaps you may not need to list all possible ones. Any valid format could be
    accepted as an argument and passed to such a utility function. Your
    dictionary might simply store some commonly used formats known to work.

    But I repeat. This is not a serious request. I know how to build limited functionality like this if I ever want it, but wonder if anyone has ever created a proposal for some protocols and perhaps helpers like say an
    embedded object that handles aspects of it once you have initialized your dictionary and also handles requests to show part of what is stored for any shoppers wondering if you are compatible with their needs.

    -----Original Message-----
    From: Python-list <python-list-bounces+avi.e.gross=gmail.com@python.org> On Behalf Of 2QdxY4RzWzUUiLuE@potatochowder.com
    Sent: Thursday, April 13, 2023 10:27 PM
    To: python-list@python.org
    Subject: Re: RE: Weak Type Ability for Python

    On 2023-04-13 at 22:14:25 -0400,
    avi.e.gross@gmail.com wrote:

    I am looking at a data structure that is an object of some class and
    stores the data in any way that it feels like. But it may be a bit of
    a chameleon that shows one face or another as needed. I can write code
    now that simply adds various access methods to the class used and also provides a way to query if it supports some interfaces.

    Python dicts act mostly like hash tables. All by themselves, hash
    tables are unordered (and in return for giving up that order, you get
    O(1) access to an item if you know its key).

    But when you ask a Python dict for the keys, you always get them in the
    same order, skipping those that have been deleted since the last time
    you asked, and appending the new keys to the end of the list in the
    order in which you added them.

    There's your chameleon.
    --
    https://mail.python.org/mailman/listinfo/python-list

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Dennis Lee Bieber@21:1/5 to All on Fri Apr 14 00:06:09 2023
    On Fri, 14 Apr 2023 05:35:22 +1000, Chris Angelico <rosuav@gmail.com>
    declaimed the following:

    It was quite the experience back in the day (as OS/2's native
    scripting language), and one that I'm truly glad to have had, as it
    taught me so much about the differences between languages.


    I still miss the Amiga ARexx implementation which piggy-backed on the Amiga IPC scheme* such that any application that opened a "RexxPort" could
    be the target for "ADDRESS <rexxport>", and hence scripted using ARexx (Did
    IBM ever get beyond the two choices of command-line and a line-editor?).


    * Granted, that IPC relied upon the fact that all applications shared one memory space, so there wasn't the overhead of copying data structures from sending application to the port's linked list and thence to the receiving application.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Dennis Lee Bieber@21:1/5 to All on Fri Apr 14 00:22:43 2023
    On Thu, 13 Apr 2023 20:53:21 -0400, Richard Damon
    <Richard@Damon-Family.org> declaimed the following:

    On 4/13/23 7:25 PM, avi.e.gross@gmail.com wrote:
    s there any concept in Python of storing information in some way, such as
    text, and implementing various ideas or interfaces so that you can query if >> the contents are willing and able to be viewed in one of many other ways?

    There is nothing that I know of built into Python that does this.

    There is no reason you can't write your own class to implement this. >Something that by "default" looks like a string, but in some contexts >(operated on by certain types) sees if its string could be treated as a
    value of some other type, and if so, converts its value to that type and
    does the operation.

    I sure don't want to see the documentation for that...

    a = thisType(3)
    b = thisType(7)
    c = 9 #plain integer

    print(a + b + c)

    (Since I presume left to right evaluation of equal level operations) Does
    this result in

    46 ("3" + "7" => "37", int("37") + 9 => 46)

    or

    19 (as int("3") + int("7") => 10, + 9 => 19)

    Worse... changing order of a/b/c would make completely different results...

    82 (b + a + c)
    127 (int(a) + c returning thisType(12) + b as strings)

    and does (c + a) result in returning an integer (a conforming to c); or a string (a coercing c to thisType).


    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Chris Angelico@21:1/5 to Dennis Lee Bieber on Fri Apr 14 17:22:47 2023
    On Fri, 14 Apr 2023 at 17:17, Dennis Lee Bieber <wlfraed@ix.netcom.com> wrote:

    On Fri, 14 Apr 2023 05:35:22 +1000, Chris Angelico <rosuav@gmail.com> declaimed the following:

    It was quite the experience back in the day (as OS/2's native
    scripting language), and one that I'm truly glad to have had, as it
    taught me so much about the differences between languages.


    I still miss the Amiga ARexx implementation which piggy-backed on the Amiga IPC scheme* such that any application that opened a "RexxPort" could
    be the target for "ADDRESS <rexxport>", and hence scripted using ARexx (Did IBM ever get beyond the two choices of command-line and a line-editor?).


    * Granted, that IPC relied upon the fact that all applications shared one
    memory space, so there wasn't the overhead of copying data structures from sending application to the port's linked list and thence to the receiving application.

    Yeah, the "ADDRESS" command has so much potential. Back in the day, I
    built a MUD with REXX scripting, and within those scripts, the default
    ADDRESS target was "send message to the invoker of the command", so
    you could do something like this:

    /* A bare string gets sent to the client */
    "Hello!"
    /* You can still invoke shell commands, if you actually need to */
    address cmd "do_a_thing"

    Rabid proponents of OOP say that it's all about sending messages to
    things. Well, the ADDRESS command truly lets you send messages, so....
    that means REXX is the most object oriented language there is, right?

    ChrisA

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Julio Di Egidio@21:1/5 to Chris Angelico on Fri Apr 14 04:40:23 2023
    On Friday, 14 April 2023 at 09:23:25 UTC+2, Chris Angelico wrote:

    Rabid proponents of OOP say that it's all about sending messages to
    things. Well, the ADDRESS command truly lets you send messages, so....
    that means REXX is the most object oriented language there is, right?

    No, that eventually is event-driven, while
    OO essentially is about encapsulation (of
    data and its operations: inheritance and
    polymorphism come later).

    Julio

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Dennis Lee Bieber@21:1/5 to All on Fri Apr 14 10:32:30 2023
    {one more entry in the thread drift, and then I think I'll shut up}

    On Fri, 14 Apr 2023 17:22:47 +1000, Chris Angelico <rosuav@gmail.com>
    declaimed the following:


    Yeah, the "ADDRESS" command has so much potential. Back in the day, I
    built a MUD with REXX scripting, and within those scripts, the default >ADDRESS target was "send message to the invoker of the command", so
    you could do something like this:

    I used to think (Open)VMS would have been a potential platform for an effective ADDRESS command. Where ARexx used a shared memory linked-list for
    the "port" (as I'd stated, avoiding copying of data), (Open)VMS had
    "mailboxes" (they would have to copy data -- or at best remap the virtual memory from one process to another) which could serve the same purpose; receiving application creates/owns the named mailbox, sending applications would provide the data packet including a return mailbox link.


    /* A bare string gets sent to the client */
    "Hello!"
    /* You can still invoke shell commands, if you actually need to */
    address cmd "do_a_thing"

    Yeah, that was the other feature -- anything that could not be parsed as a REXX statement was automatically sent to whatever the current ADDRESS
    host happened to be.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Julio Di Egidio@21:1/5 to Julio Di Egidio on Fri Apr 14 09:42:31 2023
    On Friday, 14 April 2023 at 13:40:33 UTC+2, Julio Di Egidio wrote:
    On Friday, 14 April 2023 at 09:23:25 UTC+2, Chris Angelico wrote:

    Rabid proponents of OOP say that it's all about sending messages to
    things. Well, the ADDRESS command truly lets you send messages, so....
    that means REXX is the most object oriented language there is, right?

    No, that eventually is event-driven, while
    OO essentially is about encapsulation (of
    data and its operations: inheritance and
    polymorphism come later).

    Of course that is not what you find in the
    WP entry for encapsulation: does anybody
    need explaining how wrong that is?

    Julio

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From avi.e.gross@gmail.com@21:1/5 to All on Fri Apr 14 16:16:00 2023
    Dennis,

    Before I reply, let me reiterate I am NOT making a concrete suggestion, just having a somewhat abstract discussion.

    The general topic is a sort of polymorphism I envisioned where a select group of classes/objects that can be seen as different aspects of an elephant can be handled to provide some functionality in a consistent way. We all agree much of the functionality
    can be done deliberately by individual programmers. The question was whether anyone had done a more general implementation or even saw any reason to do so.

    Fair enough?

    So let us assume I have an object, call it obj1, that encapsulates data the old fashioned way. Consider a classical case like an object holding information about a parallelopiped or something like a shoebox. How you store the info can vary, such as
    recording a height/width/depth, or a series of x,y,z coordinates representing some of the vertices. But no matter how you store the basic info, you can derive many things from them when asked to provide a volume or surface area or whether it will fit
    within another object of the same kind assuming the sides have no width. Or, you can ask it to return another instance object that has double the width or many other things.

    There are several ways to provide the functionality, actually quite a few, but one is to make a method for each thing it does such as obj1.get_surface_area(), obj1.get_volume() and obj1.does_it_fit_in(cl2) and of course you can have methods that change
    the orientation or ask what angles it is oriented at now and whatever else you want.

    Each such method will return something of a usually deterministic type. Volumes will be a double, for example. But what if you design a small language so you can type obj1.get_by_name("volume") and similar requests, or even a comma separated grouping of
    requests that returns a list of the answers? It now is not so deterministic-looking to a linter. But normal Python allows and often encourages such polymorphism so is this anything new?

    What I envisioned is a tad closer to the latter. Not this:

    a = thisType(3)
    b = thisType(7)
    c = 9 #plain integer
    print(a + b + c)

    Note the above example is standard. My thoughts are a bit more arcane and focused on convertibility of a single value into multiple forms.

    Say I have a data type that stores a number representing a temperature. It may have ways to initialize (or change) the temperature so it can be input as degrees centigrade or Fahrenheit or Kelvin or Rankine or even more indirect ways such as 10 degrees
    Fahrenheit above the freezing point of pure water at a particular atmospheric pressure and so on.

    What I want to add is a bit like this. Internally many methods may get created that may not be expected to be used except through a designated interface. Call them f1() and f2() ... fn() for now.

    Also in the class initialization or perhaps in the object dunder init, you create something like a dictionary consisting of key words matched by pointers to the aforementioned functions/methods. This structure will have some name designated by the
    protocol such as _VIEWS and may be visible to anyone looking at the object. The details can be worked out but this is a simplistic explanation.

    In this dictionary we may have words like "Celsius", "Fahrenheit" and so on, perhaps even several variants that point to the same functions. If a user wants the temperature in absolute terms, they may call a standard function like "obj1.as_type('Kelvin')"
    and that function will search the dictionary and get you the results using the appropriate conversion method. You may also support other accessors like 'obj1.supports_type("Fahrenheit451")' that reports as True/False whether the object can handle that
    output. It merely checks the internal dictionary. You may have another that returns a list of the data types as keys and whatever else is part of the design.

    You can, of course, have a second set of such directives that instead of returning a temperature as a double, will return a printable text version that includes ℃ or °K or °R or °F".

    A second example could be something holding a date with plenty of internal abilities to display it in a wide variety of formats or maybe just holds a day of the week that it will display as a string in any language it handles, such as Sunday being shown
    as:
    ×™×•Ö¹× ×¨Ö´×ש×וֹן
    Dimanĉo
    Vasárnap
    Sonntag
    Dimanche
    Zondag
    日曜日
    रविवार

    And so on. Again, it need not store the text for every language but can call translation software as needed and it can be more than the name of a day of the week. It could have a dictionary containing all the languages it handles as described for another
    example and access methods. Of course, if called on repeatedly and often for the same languages, it could cache results.

    My question, again, is not whether this can be done but whether some kind of protocol can be created that is published and suggests the names and so on to use in constructing your own implementation. And, it may be helpful if a module is made available
    that makes it even simpler to use.

    I think it is time for me to drop out of this discussion unless I hear something of interest. It is just an idea I have been pondering.

    -----Original Message-----
    From: Python-list <python-list-bounces+avi.e.gross=gmail.com@python.org> On Behalf Of Dennis Lee Bieber
    Sent: Friday, April 14, 2023 12:23 AM
    To: python-list@python.org
    Subject: Re: Weak Type Ability for Python

    On Thu, 13 Apr 2023 20:53:21 -0400, Richard Damon
    <Richard@Damon-Family.org> declaimed the following:

    On 4/13/23 7:25 PM, avi.e.gross@gmail.com wrote:
    s there any concept in Python of storing information in some way, such as
    text, and implementing various ideas or interfaces so that you can query if >> the contents are willing and able to be viewed in one of many other ways?

    There is nothing that I know of built into Python that does this.

    There is no reason you can't write your own class to implement this. >Something that by "default" looks like a string, but in some contexts >(operated on by certain types) sees if its string could be treated as a
    value of some other type, and if so, converts its value to that type and >does the operation.

    I sure don't want to see the documentation for that...

    a = thisType(3)
    b = thisType(7)
    c = 9 #plain integer

    print(a + b + c)

    (Since I presume left to right evaluation of equal level operations) Does
    this result in

    46 ("3" + "7" => "37", int("37") + 9 => 46)

    or

    19 (as int("3") + int("7") => 10, + 9 => 19)

    Worse... changing order of a/b/c would make completely different results...

    82 (b + a + c)
    127 (int(a) + c returning thisType(12) + b as strings)

    and does (c + a) result in returning an integer (a conforming to c); or a string (a coercing c to thisType).

    --
    https://mail.python.org/mailman/listinfo/python-list

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Julio Di Egidio@21:1/5 to avi.e...@gmail.com on Sat Apr 15 00:18:58 2023
    On Friday, 14 April 2023 at 22:16:30 UTC+2, avi.e...@gmail.com wrote:
    Dennis,

    Before I reply, let me reiterate I am NOT making a concrete suggestion,
    just having a somewhat abstract discussion.

    You keep talking nonsense, and vile arrogant nonsense at that: and I resent *both* parts, since we all drink from the same pond.

    The general topic is a sort of polymorphism I envisioned where a select group of classes/objects that can be seen as different aspects of an elephant can be handled to provide some functionality in a consistent way. We all agree much of the
    functionality can be done deliberately by individual programmers. The question was whether anyone had done a more general implementation or even saw any reason to do so.

    Fair enough?

    No, you insist in reinventing the wheel, and you insist in reinventing it wrong.

    Does anybody need explaining what OO is and is not actually about?

    Julio

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Peter J. Holzer@21:1/5 to MRAB on Sat Apr 15 13:23:54 2023
    On 2023-04-13 03:28:37 +0100, MRAB wrote:
    On 2023-04-13 03:12, avi.e.gross@gmail.com wrote:
    I suspect the OP is thinking of languages like PERL or JAVA which guess for you and make such conversions when it seems to make sense.

    In the case of Perl, there are distinct operators for addition and string concatenation, with automatic type conversion (non-numeric strings have a numeric value of 0, which can hide bugs).

    You get a warning for that, though.

    hp

    --
    _ | Peter J. Holzer | Story must make more sense than reality.
    |_|_) | |
    | | | hjp@hjp.at | -- Charles Stross, "Creative writing
    __/ | http://www.hjp.at/ | challenge!"

    -----BEGIN PGP SIGNATURE-----

    iQIzBAABCgAdFiEETtJbRjyPwVTYGJ5k8g5IURL+KF0FAmQ6iUoACgkQ8g5IURL+ KF0oTQ//XYu8gTMN3v80Lo9FMUhz1aihLBA/B96ro2cKkkyB7FoITs/UbyXVZG2p l3ovQG6hRFMUU05DuEXszruTNYxgsm5HISWdmRQvAm/CN1J+EGZlwi4NokR8Bt0B geNHWPwkaP7XqGn/L1OBoDzdKO+ZeBoj0XkIClEwIqpyJ8+sflYxfncw7ceS/nMy vPUTS4o5u8faoy4E7wRE7zLXEzoykmdYttymwOT/NOOSZhcOzb9pq6WzsLE3LVVC PxEqK6jXn4H15Pu8/i3V+obfXzM6fX19XHVcJ7XfXfb6lwan23ddrpsQ8FPw9NXA yrWrZtXtSjMU4gXd7D/pzC0J34CdggmXhnEq04BeU8tMYSiTfxaWe9O36WtMBhiB dC3DFx8JYYIsulfsL7NQzEFLiidWB3RrZ5FIrNltQ9BJUZV+uiidzL40JV3vapCa trajMm8ahMH/37PTcXMXac34+tmgHBnIX+svxmS8RFNCNKev4BrdzTe1yVeQ5p0K o90e8Z45ngSe6YZwa3pYlZA1f3gbchRqYbT3Oo3DJJcT/Q6NOejW1KZtwuFkw9e3 AfhMF9Rx7i7aTfTY6ZLU8qZ0zuDpeI4TJxzrRKZHk/58mSZaAQ39DNRMWoqOaaMt ++VJWhPncm723x+6CHu1TAs8vmpAnWBD0rlom4C
  • From Peter J. Holzer@21:1/5 to Chris Angelico on Sat Apr 15 13:22:24 2023
    On 2023-04-14 10:19:03 +1000, Chris Angelico wrote:
    The entire Presentation Manager and Workplace Shell (broadly
    equivalent to a Linux "desktop manager", I think? Kinda?) were object oriented; you would have a WPDataFile for every, well, data file, but
    some of those might be subclasses of WPDataFile. And it was fairly straight-forward to write your own subclass of WPDataFile, and there
    was an API to say "if you would ever create a WPDataFile, instead
    create one of my class instead". This brilliant technique allowed
    anyone to enhance the desktop in any way, quite impressive especially
    for its time. I've yearned for that ever since, in various systems,
    although I'm aware that it would make quite a mess of Python if you
    could say "class EnhancedInt(int): ..." and then "any time you would
    create an int, create an EnhancedInt instead". A bit tricky to
    implement.

    Or alternatively you might be able to add or replace methods on the
    existing int class. So 5 is still just an int, but now (5 + "x") calls
    the modified __add__ method which knows how add a string to an int.

    Might make even more of a mess ;-).

    hp

    --
    _ | Peter J. Holzer | Story must make more sense than reality.
    |_|_) | |
    | | | hjp@hjp.at | -- Charles Stross, "Creative writing
    __/ | http://www.hjp.at/ | challenge!"

    -----BEGIN PGP SIGNATURE-----

    iQIzBAABCgAdFiEETtJbRjyPwVTYGJ5k8g5IURL+KF0FAmQ6iOsACgkQ8g5IURL+ KF0aRg//flVb5+QcwQKvzaHxbKZGXPcuBCugqPFL0vKLFqnmpE+1hBSYfi02uJMg jT5T8jqdy5OoRUV3rOj1oBZPUIf1imFVDC8xiSFVrrShnLu2qZaALi35PR0h8Tn6 Wm/J7U78hIQ3Kqk8abRYhBC1U5ttHgB348plnqsOsLocv79fNxjVlIB4G7HfUgFP vagaZQ9630TODR/Y7x8tIurMSV3GIlONWJB0ks3d3r0xEGd85eD9wgoYJCqDc8F9 YPda/bKgyNw7EJIgvT8Fuz/KYDFDiKf4mCLoP3YYIYMeRjo+BaxMGXRp6R9a0tGU hmDZBfV20LrceIgjcaNID2SxJGIafdOOsyovAEKsZn4QGPKV/f4D56+VUgro/76j 9Ceg3DtQCIekXKzdtlBGQfVsRmpGdMHLNhXjg9skpVcCNO3WZfGk/w5NxbkWS9HU cDo7YpWjRbtw8gEFxZSXlv3USkpwnX55tAQQ1rlWRm/nE4k34fOdjGnl7H5IvAZh ACchT0o1etWLY3nq2L0Bwz/DCbDxQl77FkGxw501D0zRFNORi00aa/XUnBoYtsyh KH+zFGz+1c4odvF4pObuOFCgp084XlFID98YkHMIDMAKDvqUs1w9d6pMZQYbZRAk fFvVJYMllm44WdOJRPomr+Tq+MHpELl5wMuhLSA