Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider semicolons for one-liners #56

Open
gilch opened this issue May 14, 2021 · 1 comment
Open

Consider semicolons for one-liners #56

gilch opened this issue May 14, 2021 · 1 comment

Comments

@gilch
Copy link
Owner

gilch commented May 14, 2021

Python allows a semicolon for joining statements on one line, so there's precedent. It's mostly considered bad style in production code, but is useful for shell commands, although the inability to join certain statement types limits its usefulness.

for i in range(3): print(i); print(i*i)  # Python allows this.
print('hi'); for i in range(3): print(i)  # SyntaxError
for i in range(3): for j in range(3): print(i, j)  # SyntaxError
class Foo(object): def: foo(self, x): print(x)  # SyntaxError

Hebigo can do some of these already.

for: i :in range:3 print:i print: (i*i)
print:'hi' for: i :in range:3 print:i
for: i :in range:3 for j :in range:3 print: i j

But the class doesn't quite work:

class: Foo:object def: foo: self x print:x  # print in params
class: Foo:object def: foo: self x
  print:x  # print in class

But with a semicolon acting like a Lisp closing parenthesis,

class: Foo:object def: foo: self x; print:x

It's almost never used at the end of a line in Python (although this is technically allowed) and it would tend to be a long train in a Lisp, so I'd rather not allow it in Hebigo. But even internal-only, you can get doubled semicolons for reasonable use cases:

class: Foo:object
 def: foo: self x y
  print: x y
 def: bar: self a b
  print: a b

# one-liner version
class: Foo: object; def: foo: self x y; print: x y;; def: bar: self a b; print: a b

Maybe this is OK for shell commands, but it does require more careful thinking than the usual indentation-based notation.
If you think of x:/; as parentheses, the Lispiness becomes more apparent. Both forms at once to show where the double came from:

class:
  Foo:
    object;
  def:
    foo:
      self x y;
    print:
      x y;;
  def:
   bar:
     self a b;
   print:
     a b;;;

You can see a train of three at the end. This wouldn't be allowed of course, but it does show the structure.

It could also make normal code more compact, but I find this less readable:

class: Foo:object
 def: foo: self x y; print: x y
 def: bar: self a b; print: a b

So, as in Python, I think they should be considered bad style in source code. I can't think of a case where it reads better, but it would make any expression possible as a one-liner, a capability that Python lacks but has some compromise support for. You can theoretically do all of your one-liners in Lissp anyway, so I'm not sure if this is worth it.

@gilch
Copy link
Owner Author

gilch commented Sep 5, 2022

I'm wondering if this would help readability at all for a complex let destructure. I'd have to see it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant