bakkdoor / fancy

Fancy is a dynamic, object-oriented programming language inspired by Smalltalk, Ruby, Io and Erlang that runs on the Rubinius VM.
http://www.fancy-lang.org
BSD 3-Clause "New" or "Revised" License
261 stars 22 forks source link

Experiment with indentation based parser. #33

Closed vic closed 13 years ago

vic commented 14 years ago

(This is just a WISH reminder for vic, but if you want to impl this, feel free to do so, also comment).

Fancy is an smalltalk' like language, in the sense of how messages are sent and message selectors having ":". One thing I don't like very much in many languages, is seeing lots of curly braces as code is being nested (ie. in ruby we face the same problem, and it's not un-common to see several trailing end end end end)

I've noticed the following... try { something } catch StdError => e { e println } finally { resources free }

with an indentation sensitive parser, could be written like this, notice the smalltalk-ish/pythonic flavor.

    try:
       something
    catch: StdError => e
       e println
    finally:
       resources free

Another example:

    def class Something {

        def hello { 
           "Hello World" println
        }

        def hello: name {
            "Hello " ++ name . println
        }
    }

Could be

    def class: Something                                 # or even simply..     class: Something

        def: hello 
            "Hello World" println

        def: hello: name
            "Hello " ++ name . println

We don't need to eliminate usage of { }, as they are useful for block literals

        { condition } if_true: 
           "The condition was true" println
        else:
           "Nope" println

A block literal without curly brackets might seem like:

         [1, 2, 3] each |a| 
            a println
            some large body(working with: a)

Need to study this further, and see if it would be plausible for fancy, and desirable by its users.