fleabitdev / glsp

The GameLisp scripting language
https://gamelisp.rs/
Apache License 2.0
393 stars 13 forks source link

bracket readability #5

Open chayleaf opened 4 years ago

chayleaf commented 4 years ago

(Note that I'm not a lisp programmer, it's the first time I'm reading lisp, however I am interested in using scripting for games and lisp's powerful data model)

Lisp's opening brackets look readable. However, the closing brackets - )))))), are hard to understand without coloring each bracket pair differently. When I saw it, I immediately thought - can't more bracket types be used? As it turns out, they can - for example, Racket lang accepts all bracket types. Can the same be applied here? I think it would greatly improve general readability, at least for beginners.

fleabitdev commented 4 years ago

In GameLisp, unlike most Lisps, the different bracket types have different semantic meanings. () is general-purpose, [] is for accessing an element of a collection, and {} is for string escaping.

(let x [ar -1])
(prn "the last element is {x}")

)))))) is a very real problem, so I'm going to leave this issue open to gather suggestions for how the problem might be mitigated. So far, I'm considering:

(defclass Class
  (fsm
    (state State

      (quite-indented-clause
        (first
          (second
            (third))))

      ; end of State
      #n)

    ; end of fsm
    #n))
yurapyon commented 4 years ago

There are also plenty of Lisp editing tools that make the task of working with parens less of a hastle. One such that I use is parinfer, https://github.com/shaunlebron/parinfer, which allows me to never really worry about parens and just deal with indentation. Emac's ParEdit is ubiquitous in helping deal with parens. I used to use the method of splitting up brackets, but parinfer has changed that haha. I really can't recommend it enough.

As a frequent Scheme user, I'd argue that only allowing parens enhances readability. The more acquainted you get with it, the more the plain syntax of just atoms and parens starts to read like English. Lispers have dealt with the strings of parens since its inception, its just a matter of getting used to them, which - I'll be the first to admit - is a big change.