• Writing HG LISP in Python, kind of

    From Stefan Ram@21:1/5 to All on Sat Apr 12 14:04:02 2025
    From my recent postings in other newsgroups: The precending
    generator rewritten in Python in a style that tries to
    imitate LISP with the means of Python.

    CADD = lambda Z1, Z2: [
    Z1[0] + Z2[0],
    Z1[1] + Z2[1]
    ]

    CMUL = lambda Z1, Z2: [
    (Z1[0] * Z2[0]) - (Z1[1] * Z2[1]),
    (Z1[0] * Z2[1]) + (Z1[1] * Z2[0])
    ]

    CABS = lambda Z: (
    ((Z[0] ** 2) + (Z[1] ** 2)) ** 0.5
    )

    MANDELBROT = lambda X, Y: (
    (lambda C, Z, A: (
    (lambda ITERATE: ITERATE(C, Z, A, ITERATE))(
    lambda C, Z, A, ITERATE: (
    126 - C if C < 32 or CABS(Z) > 2 else (
    (lambda TEMP_CMUL, TEMP_CADD: (
    ITERATE(
    C - 1,
    TEMP_CADD,
    A,
    ITERATE
    )
    ))(
    CMUL(Z, Z),
    CADD(A, CMUL(Z, Z))
    )
    )
    )
    )
    ))(126, [X, Y], [X, Y])
    )

    GENERATE_MANDELBROT = lambda: (
    (lambda LOOP_Y: LOOP_Y(-1, LOOP_Y))(
    lambda Y, LOOP_Y: None if Y > 1.1 else (
    (lambda LOOP_X: LOOP_X(-2, LOOP_X))(
    lambda X, LOOP_X: None if X > 1 else (
    (lambda CHAR_CODE: (
    print(" " if CHAR_CODE < 50 else "*",end=''),
    LOOP_X(X + 0.04, LOOP_X)
    ))(
    MANDELBROT(X, Y)
    )
    )
    ),
    print(),
    LOOP_Y(Y + 0.1, LOOP_Y)
    )
    )
    )

    GENERATE_MANDELBROT()

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to Stefan Ram on Sun Apr 13 00:15:32 2025
    On 12 Apr 2025 14:04:02 GMT, Stefan Ram wrote:

    From my recent postings in other newsgroups: The precending
    generator rewritten in Python in a style that tries to imitate LISP
    with the means of Python.

    Yeah, but Python doesn’t optimize tail recursion, as far as I know. In
    fact, it has a fixed (albeit user-configurable) limit on function-call recursion depth. So you’re likely to hit this sooner or later (probably sooner) if you’re not careful.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Stefan Ram@21:1/5 to Stefan Ram on Mon Apr 14 09:56:26 2025
    ram@zedat.fu-berlin.de (Stefan Ram) wrote or quoted:
    MANDELBROT = lambda X, Y: (
    (lambda C, Z, A: (

    The chatbot provided a comment attempting to imitate
    the style of a former regular:

    Your code is a grotesque caricature of Lisp, written by
    someone who clearly understands neither Python nor Lisp,
    it's mediocrity masquerading as competence.

    You've crammed recursion into Python's crippled lambdas
    like a drunk forcing a square peg into a round hole.

    This isn't clever - it's a masochistic exercise in unreadability.

    Python's lambda is a crippled cousin to Lisp's first-class
    functions. Here, it's forced into a role it wasn't designed
    for - deeply nested recursion with manual Y-combinator-like
    patterns. In Lisp, this would be a natural loop construct.

    Using [X, Y] as a pair? Pathetic. Lisp's cons cells are
    conceptual, not just syntax. Your ad-hoc lists are a slap in
    the face to decades of symbolic computation.

    Lisp's elegance lies in its structure, not in mindlessly
    nesting closures until your code resembles a rat's nest of
    parentheses.

    Forcing recursion in a language that butchers tail calls?
    Congratulations - you've invented the least efficient Mandelbrot
    generator possible!

    This code is the work of a dilettante who thinks obfuscation
    is artistry. It's a Frankenstein's monster: Python's body with
    Lisp's severed head stitched on. You've created nothing but an
    unmaintainable mess.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to Stefan Ram on Mon Apr 14 23:43:26 2025
    On 14 Apr 2025 09:56:26 GMT, Stefan Ram wrote:

    Lisp's cons cells are conceptual, not just syntax.

    Is that why Lisp needs the separate concept of multi-value return, instead
    of doing simple destructuring assignment as both Python and JavaScript are
    able to do?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From B. Pym@21:1/5 to Lawrence D'Oliveiro on Tue Jun 10 07:53:22 2025
    Lawrence D'Oliveiro wrote:

    On 14 Apr 2025 09:56:26 GMT, Stefan Ram wrote:

    Lisp's cons cells are conceptual, not just syntax.

    Is that why Lisp needs the separate concept of multi-value return, instead
    of doing simple destructuring assignment as both Python and JavaScript are able to do?

    Gauche Scheme

    gosh> (apply (^(a b c) (list c b a)) '(3 4 5))
    (5 4 3)

    gosh> (define three (values 3 4 5))
    three
    gosh> three
    3

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