Groups | Search | Server Info | Login | Register


Groups > de.alt.folklore.computer > #50123

Re: COMAL

From ram@zedat.fu-berlin.de (Stefan Ram)
Newsgroups de.alt.folklore.computer
Subject Re: COMAL
Date 2025-05-22 09:10 +0000
Organization Stefan Ram
Message-ID <Python-20250522095735@ram.dialup.fu-berlin.de> (permalink)
References (4 earlier) <slrn102msu9.hp9q.hjp-usenet4@trintignant.hjp.at> <1t682cb016i265761n3e8%sfroehli@Froehlich.Priv.at> <slrn102pigt.1mav1.hjp-usenet4@trintignant.hjp.at> <11t682e0e0ai7803en3e8%sfroehli@Froehlich.Priv.at> <slrn102tgq2.3du8m.hjp-usenet4@trintignant.hjp.at>

Show all headers | View raw


"Peter J. Holzer" <hjp-usenet4@hjp.at> schrieb oder zitierte:
>On 2025-05-21 19:43, Stefan Froehlich <Stefan+Usenet@Froehlich.Priv.at> wrote:
>> #v+
>> if (true):
>> 	print("a");
>> 	print("b");
>>
>> print("c");
>> #v-
>> ...so und nur so geschrieben werden kann
>Wie würdest Du es denn gern anders schreiben? Mir fällt keine andere
>sinnvolle Einrückung ein.

  Für Leute, die Python nicht kennen, sollte man sagen, daß
  die Tiefe der Einrückung (zum Beispiel, ob zwei oder vier
  Leerzeichen) in Python frei festgelegt werden kann, und daß
  "true" in Python ein Name ist (der Wahrheitswert wäre "True")
  und nicht eingeklammert werden muß. Leerzeilen können frei
  hinzugefügt oder entfernt werden. Man könnte auch schreiben:

if true: print( "a" ); print( "b" )
print( "c" )

  oder

print( end = "a\nb\nc\n" if true else "c\n" )

  oder

print( end = true and """a
b
c
""" or """c
""" )

  oder

execute("""
if( true )
{ print("a");
  print("b"); }
print("c");
""")

  .
 
>Naja, Python hat keine Klammern für Blöcke.

  SERP-Ausschnitt:

|brackets · PyPI pypi.org › project › brackets
|
|Brackets is a yet-another, a not just a pre-processor, a
|language built on top of Python, allowing to use {} instead
|of indentation in Python.

  . Anhang: Definition von "execute":

import re

def execute(code):
    # Remove leading/trailing whitespace
    code = code.strip()

    # Replace if( ... ) with if ... :
    def if_replacer(match):
        condition = match.group(1).strip()
        # Remove outer parentheses if present
        if condition.startswith('(') and condition.endswith(')'):
            condition = condition[1:-1].strip()
        return f'if {condition}:'
    code = re.sub(r'if\s*\((.*?)\)', if_replacer, code)

    # Split code into tokens, keeping braces
    tokens = re.split(r'(\{|\})', code)

    # Prepare for indentation
    indent = 0
    lines = []

    for token in tokens:
        token = token.strip()
        if not token:
            continue
        if token == '{':
            indent += 1
        elif token == '}':
            indent -= 1
        else:
            # Split token into statements by semicolon
            statements = [stmt.strip() for stmt in token.split(';') if stmt.strip()]
            for stmt in statements:
                # Skip empty statements
                if not stmt:
                    continue
                lines.append('    ' * indent + stmt)

    py_code = '\n'.join(lines)
    exec(py_code, globals())

Back to de.alt.folklore.computer | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

COMAL "F. W." <me@home.invalid> - 2025-05-16 07:53 +0200
  Re: COMAL Marc Haber <mh+usenetspam1118@zugschl.us> - 2025-05-16 10:45 +0200
    Re: COMAL "F. W." <me@home.invalid> - 2025-05-19 07:59 +0200
      Re: COMAL Marc Haber <mh+usenetspam1118@zugschl.us> - 2025-05-19 09:36 +0200
        Re: COMAL "F. W." <me@home.invalid> - 2025-05-19 11:27 +0200
        Re: COMAL Eric Bruecklmeier <u@5i7.de> - 2025-05-19 11:40 +0200
          Re: COMAL Marc Haber <mh+usenetspam1118@zugschl.us> - 2025-05-19 14:59 +0200
            Re: COMAL Eric Bruecklmeier <u@5i7.de> - 2025-05-19 15:58 +0200
              Re: COMAL Marc Haber <mh+usenetspam1118@zugschl.us> - 2025-05-19 16:37 +0200
          Re: COMAL Thomas Koenig <tkoenig@netcologne.de> - 2025-05-31 10:16 +0000
            Re: COMAL Eric Bruecklmeier <u@5i7.de> - 2025-06-01 17:19 +0200
              Re: COMAL Kay Martinen <usenet@martinen.de> - 2025-06-01 23:57 +0200
                Re: COMAL Eric Bruecklmeier <u@5i7.de> - 2025-06-02 08:16 +0200
                Re: COMAL "Peter J. Holzer" <hjp-usenet4@hjp.at> - 2025-06-02 12:56 +0200
                Re: COMAL ram@zedat.fu-berlin.de (Stefan Ram) - 2025-06-02 11:17 +0000
                Re: COMAL Eric Bruecklmeier <u@5i7.de> - 2025-06-02 17:10 +0200
                Re: COMAL Kay Martinen <usenet@martinen.de> - 2025-06-04 11:54 +0200
                Re: COMAL Eric Bruecklmeier <u@5i7.de> - 2025-06-04 13:16 +0200
                Re: COMAL Kay Martinen <usenet@martinen.de> - 2025-06-08 22:19 +0200
                Re: COMAL Eric Bruecklmeier <u@5i7.de> - 2025-06-09 09:47 +0200
                Re: COMAL Kay Martinen <usenet@martinen.de> - 2025-06-09 16:38 +0200
                Re: COMAL Thomas Koenig <tkoenig@netcologne.de> - 2025-06-09 12:06 +0000
                Re: COMAL Eric Bruecklmeier <u@5i7.de> - 2025-06-09 14:59 +0200
                Re: COMAL Thomas Koenig <tkoenig@netcologne.de> - 2025-06-09 14:02 +0000
                Re: COMAL Eric Bruecklmeier <nil@nil.nil> - 2025-06-10 08:08 +0200
                Re: COMAL Stefan+Usenet@Froehlich.Priv.at (Stefan Froehlich) - 2025-06-10 09:36 +0000
                Re: COMAL Eric Bruecklmeier <u@5i7.de> - 2025-06-10 12:10 +0200
                Re: COMAL "Peter J. Holzer" <hjp-usenet4@hjp.at> - 2025-06-10 18:41 +0200
                Re: COMAL "Peter J. Holzer" <hjp-usenet4@hjp.at> - 2025-06-10 18:37 +0200
                Re: COMAL Stefan+Usenet@Froehlich.Priv.at (Stefan Froehlich) - 2025-06-10 06:18 +0000
        Re: COMAL "Peter J. Holzer" <hjp-usenet4@hjp.at> - 2025-05-19 20:09 +0200
          Re: COMAL Kay Martinen <usenet@martinen.de> - 2025-05-19 22:19 +0200
            Re: COMAL "Peter J. Holzer" <hjp-usenet4@hjp.at> - 2025-05-19 23:40 +0200
              Re: COMAL ram@zedat.fu-berlin.de (Stefan Ram) - 2025-05-20 08:41 +0000
          Re: COMAL Stefan+Usenet@Froehlich.Priv.at (Stefan Froehlich) - 2025-05-20 16:41 +0000
            Re: COMAL Stefan+Usenet@Froehlich.Priv.at (Stefan Froehlich) - 2025-05-20 16:49 +0000
              Re: COMAL Kay Martinen <usenet@martinen.de> - 2025-05-20 20:33 +0200
                Re: COMAL "Peter J. Holzer" <hjp-usenet4@hjp.at> - 2025-05-20 20:54 +0200
            Re: COMAL Marc Haber <mh+usenetspam1118@zugschl.us> - 2025-05-20 19:44 +0200
            Re: COMAL "Peter J. Holzer" <hjp-usenet4@hjp.at> - 2025-05-20 20:29 +0200
              Re: COMAL ram@zedat.fu-berlin.de (Stefan Ram) - 2025-05-20 19:00 +0000
                Re: COMAL ram@zedat.fu-berlin.de (Stefan Ram) - 2025-05-20 19:10 +0000
                Re: COMAL Kay Martinen <usenet@martinen.de> - 2025-05-20 21:33 +0200
              Re: COMAL Stefan+Usenet@Froehlich.Priv.at (Stefan Froehlich) - 2025-05-21 17:43 +0000
                Re: COMAL Gerrit Heitsch <gerrit@laosinh.s.bawue.de> - 2025-05-21 20:52 +0200
                Re: COMAL Marc Haber <mh+usenetspam1118@zugschl.us> - 2025-05-21 21:37 +0200
                Re: COMAL Gerrit Heitsch <gerrit@laosinh.s.bawue.de> - 2025-05-21 22:55 +0200
                Re: COMAL Eric Bruecklmeier <u@5i7.de> - 2025-05-22 09:17 +0200
                Re: COMAL Marc Haber <mh+usenetspam1118@zugschl.us> - 2025-05-22 09:42 +0200
                Re: COMAL Gerrit Heitsch <gerrit@laosinh.s.bawue.de> - 2025-05-22 09:46 +0200
                Re: COMAL Marc Haber <mh+usenetspam1118@zugschl.us> - 2025-05-22 10:37 +0200
                Re: COMAL Christian Corti <use@reply.to> - 2025-05-22 11:15 +0200
                Re: COMAL Gerrit Heitsch <gerrit@laosinh.s.bawue.de> - 2025-05-22 11:52 +0200
                Re: COMAL Marc Haber <mh+usenetspam1118@zugschl.us> - 2025-05-22 12:35 +0200
                Re: COMAL Gerrit Heitsch <gerrit@laosinh.s.bawue.de> - 2025-05-22 13:08 +0200
                Re: COMAL Marc Haber <mh+usenetspam1118@zugschl.us> - 2025-05-22 15:27 +0200
                Re: COMAL Christian Corti <use@reply.to> - 2025-05-22 16:14 +0200
                Re: COMAL "Peter J. Holzer" <hjp-usenet4@hjp.at> - 2025-05-22 14:11 +0200
                Re: COMAL ram@zedat.fu-berlin.de (Stefan Ram) - 2025-05-22 12:24 +0000
                Re: COMAL ram@zedat.fu-berlin.de (Stefan Ram) - 2025-05-22 15:38 +0000
                Re: COMAL ram@zedat.fu-berlin.de (Stefan Ram) - 2025-05-22 15:46 +0000
                Re: COMAL Kay Martinen <usenet@martinen.de> - 2025-05-31 15:38 +0200
                Re: COMAL Eric Bruecklmeier <u@5i7.de> - 2025-05-22 09:44 +0200
                Re: COMAL Gerrit Heitsch <gerrit@laosinh.s.bawue.de> - 2025-05-22 09:48 +0200
                Re: COMAL Eric Bruecklmeier <u@5i7.de> - 2025-05-22 10:11 +0200
                Re: COMAL Eric Bruecklmeier <u@5i7.de> - 2025-05-22 10:12 +0200
                Re: COMAL "Peter Heitzer" <peter.heitzer@rz.uni-regensburg.de> - 2025-05-22 08:24 +0000
                Re: COMAL Marc Haber <mh+usenetspam1118@zugschl.us> - 2025-05-22 10:38 +0200
                Re: COMAL Stefan Reuther <stefan.news@arcor.de> - 2025-05-22 18:45 +0200
                Re: COMAL Stefan+Usenet@Froehlich.Priv.at (Stefan Froehlich) - 2025-05-22 10:22 +0000
                Re: COMAL Eric Bruecklmeier <u@5i7.de> - 2025-05-22 09:16 +0200
                Re: COMAL "Peter J. Holzer" <hjp-usenet4@hjp.at> - 2025-05-22 08:25 +0200
                Re: COMAL ram@zedat.fu-berlin.de (Stefan Ram) - 2025-05-22 09:10 +0000
                Re: COMAL Dietrich Clauss <dietrich@clauss-it.com> - 2025-05-22 11:34 +0200
                Re: COMAL Marc Haber <mh+usenetspam1118@zugschl.us> - 2025-05-22 12:36 +0200
                Re: COMAL "Peter Heitzer" <peter.heitzer@rz.uni-regensburg.de> - 2025-05-22 12:43 +0000
                Re: COMAL "Peter J. Holzer" <hjp-usenet4@hjp.at> - 2025-05-22 15:13 +0200
                Re: COMAL Gerrit Heitsch <gerrit@laosinh.s.bawue.de> - 2025-05-22 16:36 +0200
                Re: COMAL "Peter J. Holzer" <hjp-usenet4@hjp.at> - 2025-05-22 16:51 +0200
                Re: COMAL ram@zedat.fu-berlin.de (Stefan Ram) - 2025-05-22 15:01 +0000
                Re: COMAL Gerrit Heitsch <gerrit@laosinh.s.bawue.de> - 2025-05-22 17:18 +0200
                Re: COMAL Dietrich Clauss <dietrich@clauss-it.com> - 2025-05-22 20:31 +0200
                Re: COMAL ram@zedat.fu-berlin.de (Stefan Ram) - 2025-05-22 19:47 +0000
                Re: COMAL "Peter J. Holzer" <hjp-usenet4@hjp.at> - 2025-05-23 03:54 +0200
                Re: COMAL ram@zedat.fu-berlin.de (Stefan Ram) - 2025-05-23 08:43 +0000
                Re: COMAL "Peter J. Holzer" <hjp-usenet4@hjp.at> - 2025-05-23 13:56 +0200
                Re: COMAL Hermann Riemann <nospam.ng@hermann-riemann.de> - 2025-05-23 15:04 +0200
                Re: COMAL ram@zedat.fu-berlin.de (Stefan Ram) - 2025-05-23 13:25 +0000
                Re: COMAL "Peter J. Holzer" <hjp-usenet4@hjp.at> - 2025-05-23 16:23 +0200
                Re: COMAL Christian Corti <use@reply.to> - 2025-05-26 11:59 +0200
                Re: COMAL Hermann Riemann <nospam.ng@hermann-riemann.de> - 2025-05-23 11:29 +0200
          Re: COMAL "F. W." <me@home.invalid> - 2025-05-26 09:27 +0200
        Re: COMAL Stefan Reuther <stefan.news@arcor.de> - 2025-05-20 18:47 +0200
          Re: COMAL Andreas Eder <a_eder_muc@web.de> - 2025-05-27 21:56 +0200
    Re: COMAL Thomas Koenig <tkoenig@netcologne.de> - 2025-05-31 13:19 +0000
  Re: COMAL Eric Bruecklmeier <u@5i7.de> - 2025-05-16 11:53 +0200
    Re: COMAL "F. W." <me@home.invalid> - 2025-05-19 08:01 +0200
      Re: COMAL Eric Bruecklmeier <u@5i7.de> - 2025-05-19 08:14 +0200
        Re: COMAL "F. W." <me@home.invalid> - 2025-05-19 08:51 +0200
          Re: COMAL Eric Bruecklmeier <u@5i7.de> - 2025-05-19 09:05 +0200
        Re: COMAL Kay Martinen <usenet@martinen.de> - 2025-05-19 09:02 +0200
          Re: COMAL "F. W." <me@home.invalid> - 2025-05-19 09:20 +0200
          Re: COMAL "Peter J. Holzer" <hjp-usenet4@hjp.at> - 2025-05-19 19:59 +0200
            Re: COMAL ram@zedat.fu-berlin.de (Stefan Ram) - 2025-05-19 18:16 +0000
              Re: COMAL ram@zedat.fu-berlin.de (Stefan Ram) - 2025-05-19 18:36 +0000
              Re: COMAL Eric Bruecklmeier <nil@nil.nil> - 2025-05-20 07:57 +0200
            Re: COMAL Eric Bruecklmeier <nil@nil.nil> - 2025-05-20 07:48 +0200

csiph-web