• one Liner: Lisprint(x) --> (a, b, c) instead of ['a', 'b', 'c']

    From Hen Hanna@21:1/5 to All on Sat Feb 25 23:45:01 2023
    def Lisprint(x): print( ' (' + ', '.join(x) + ')' , '\n')

    a= ' a b c ? def f x if zero? x 0 1 '
    a += ' A B C ! just an example '
    x= a.split()

    print(x)
    Lisprint(x)

    ['a', 'b', 'c', '?', 'def', 'f', 'x', 'if', 'zero?', 'x', '0', '1', 'A', 'B', 'C', '!', 'just', 'an', 'example']

    (a, b, c, ?, def, f, x, if, zero?, x, 0, 1, A, B, C, !, just, an, example)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Hen Hanna@21:1/5 to Hen Hanna on Sun Feb 26 01:54:02 2023
    On Saturday, February 25, 2023 at 11:45:12 PM UTC-8, Hen Hanna wrote:
    def Lisprint(x): print( ' (' + ', '.join(x) + ')' , '\n')

    a= ' a b c ? def f x if zero? x 0 1 '
    a += ' A B C ! just an example '
    x= a.split()

    print(x)
    Lisprint(x)

    ['a', 'b', 'c', '?', 'def', 'f', 'x', 'if', 'zero?', 'x', '0', '1', 'A', 'B', 'C', '!', 'just', 'an', 'example']

    (a, b, c, ?, def, f, x, if, zero?, x, 0, 1, A, B, C, !, just, an, example)


    For nested lists.... impossible to improve upon P.Norvig's code


    def Lisprint(x): print(lispstr(x))

    def lispstr(exp):
    "Convert a Python object back into a Lisp-readable string."
    if isinstance(exp, list):
    return '(' + ' '.join(map(lispstr, exp)) + ')'
    else:
    return str(exp)

    a= ' a b c '
    x= a.split()
    x += [['a', 'b', 'c']]
    x += x

    print(x)
    Lisprint(x)

    ['a', 'b', 'c', ['a', 'b', 'c'], 'a', 'b', 'c', ['a', 'b', 'c']]

    (a b c (a b c) a b c (a b c))


    ---------- Without the commas, the visual difference (concision) is striking !

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From avi.e.gross@gmail.com@21:1/5 to Hen Hanna on Sun Feb 26 22:05:33 2023
    I so rarely need to save a list in python in a form acceptable to LISP but here is a go with no visible recursion needed.

    nested = [1, 2, [3, 4, [5, 6, 7], 8], 9]

    print(nested)
    [1, 2, [3, 4, [5, 6, 7], 8], 9]

    # Just converting to a tuple does not change nested lists
    print(tuple(nested))
    (1, 2, [3, 4, [5, 6, 7], 8], 9)

    # But a function that typographically replaces [] with () needs no recursion >>> def p2b(nested_list): return repr(nested_list).replace('[','(').replace(']',')')

    print(p2b(nested))
    (1, 2, (3, 4, (5, 6, 7), 8), 9)

    People who speak python well do not necessarily lisp.

    -----Original Message-----
    From: Python-list <python-list-bounces+avi.e.gross=gmail.com@python.org> On Behalf Of Hen Hanna
    Sent: Sunday, February 26, 2023 4:54 AM
    To: python-list@python.org
    Subject: Re: one Liner: Lisprint(x) --> (a, b, c) instead of ['a', 'b', 'c']

    On Saturday, February 25, 2023 at 11:45:12 PM UTC-8, Hen Hanna wrote:
    def Lisprint(x): print( ' (' + ', '.join(x) + ')' , '\n')

    a= ' a b c ? def f x if zero? x 0 1 '
    a += ' A B C ! just an example '
    x= a.split()

    print(x)
    Lisprint(x)

    ['a', 'b', 'c', '?', 'def', 'f', 'x', 'if', 'zero?', 'x', '0', '1', 'A', 'B', 'C', '!', 'just', 'an', 'example']

    (a, b, c, ?, def, f, x, if, zero?, x, 0, 1, A, B, C, !, just, an, example)


    For nested lists.... impossible to improve upon P.Norvig's code


    def Lisprint(x): print(lispstr(x))

    def lispstr(exp):
    "Convert a Python object back into a Lisp-readable string."
    if isinstance(exp, list):
    return '(' + ' '.join(map(lispstr, exp)) + ')'
    else:
    return str(exp)

    a= ' a b c '
    x= a.split()
    x += [['a', 'b', 'c']]
    x += x

    print(x)
    Lisprint(x)

    ['a', 'b', 'c', ['a', 'b', 'c'], 'a', 'b', 'c', ['a', 'b', 'c']]

    (a b c (a b c) a b c (a b c))


    ---------- Without the commas, the visual difference (concision) is striking !
    --
    https://mail.python.org/mailman/listinfo/python-list

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Hen Hanna@21:1/5 to avi.e...@gmail.com on Mon Feb 27 19:24:14 2023
    On Sunday, February 26, 2023 at 7:06:00 PM UTC-8, avi.e...@gmail.com wrote:
    I so rarely need to save a list in python in a form acceptable to LISP but here is a go with no visible recursion needed.

    nested = [1, 2, [3, 4, [5, 6, 7], 8], 9]

    print(nested)
    [1, 2, [3, 4, [5, 6, 7], 8], 9]

    # Just converting to a tuple does not change nested lists
    print(tuple(nested))
    (1, 2, [3, 4, [5, 6, 7], 8], 9)

    # But a function that typographically replaces [] with () needs no recursion >>> def p2b(nested_list): return repr(nested_list).replace('[','(').replace(']',')')

    print(p2b(nested))
    (1, 2, (3, 4, (5, 6, 7), 8), 9)

    People who speak python well do not necessarily lisp.
    -----Original Message-----
    From: Python-list <python-list-bounces+avi.e.gross=gmai...@python.org> On Behalf Of Hen Hanna
    Sent: Sunday, February 26, 2023 4:54 AM
    To: pytho...@python.org
    Subject: Re: one Liner: Lisprint(x) --> (a, b, c) instead of ['a', 'b', 'c']

    On Saturday, February 25, 2023 at 11:45:12 PM UTC-8, Hen Hanna wrote:
    def Lisprint(x): print( ' (' + ', '.join(x) + ')' , '\n')

    a= ' a b c ? def f x if zero? x 0 1 '
    a += ' A B C ! just an example '
    x= a.split()

    print(x)
    Lisprint(x)

    ['a', 'b', 'c', '?', 'def', 'f', 'x', 'if', 'zero?', 'x', '0', '1', 'A', 'B', 'C', '!', 'just', 'an', 'example']

    (a, b, c, ?, def, f, x, if, zero?, x, 0, 1, A, B, C, !, just, an, example)


    For nested lists.... impossible to improve upon P.Norvig's code


    def Lisprint(x): print(lispstr(x))

    def lispstr(exp):
    "Convert a Python object back into a Lisp-readable string."
    if isinstance(exp, list):
    return '(' + ' '.join(map(lispstr, exp)) + ')'
    else:
    return str(exp)

    a= ' a b c '
    x= a.split()
    x += [['a', 'b', 'c']]
    x += x

    print(x)
    Lisprint(x)

    ['a', 'b', 'c', ['a', 'b', 'c'], 'a', 'b', 'c', ['a', 'b', 'c']]

    (a b c (a b c) a b c (a b c))


    ---------- Without the commas, the visual difference (concision) is striking !
    --
    https://mail.python.org/mailman/listinfo/python-list


    is it poss. to peek at the Python-list's messages without joining ?



    nice idea (approach)...


    but maybe when it's revised to handle ['a', 'b', 'c', ['a', 'b', 'c'], 'a', 'b', 'c', ['a', 'b', 'c']] etc.
    it'll converge to P.Norvig's code.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Greg Ewing@21:1/5 to Hen Hanna on Tue Feb 28 19:24:45 2023
    On 28/02/23 4:24 pm, Hen Hanna wrote:
    is it poss. to peek at the Python-list's messages without joining ?

    It's mirrored to the comp.lang.python usenet group, or
    you can read it through gmane with a news client.

    --
    Greg

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