haasn / -g-pl

/g/ programming language
13 stars 2 forks source link

OP function (aka main) #10

Closed haasn closed 13 years ago

haasn commented 13 years ago

As per the current draft, this would look something like

>implying OP isn't >function (
    >implying x isn't 5
    >implying y isn't 3

    >mfw >add x y
    gb2

    inane This will never execute:
    >mfw "foobar"
)

How does that look?

graydude commented 13 years ago

Looks good, but where would you define the arguments for tgis function? Or is it: no statement, no arguments? In that case, how do we separate (arguments) and (body) if they both use ()'s?

Sent via Hubroid

graydude commented 13 years ago

Nevermind that, I just saw that the draft says function{}(). I'm used to it being the other way around, I like it.

Sent via Hubroid

haasn commented 13 years ago

I have not worked lists into the spec yet but once they're in, it will be something like

>implying OP isn't >function{args} (
    >mfw >len args
    >mfw args[0]
)

Of course, if you can find a way to make this more /g/ related, I'm open to suggestions.

haasn commented 13 years ago

The reasoning why I swapped them, {} and (), is because the () is not just used for functions. () is used for all blocks and can be omitted if not needed.

For example, a function which only performs a single statement could look like:

>implying foo isn't >function{x} >mfw x

That being said, one potentially confusing thing could be the fact that () denotes blocks (which are statements), but statements are not expressions, so an unfamiliar user could accidentally try something like >mul 3 (>add 2 5) which is of course illegal. We could also swap them, as this would probably get rid of this ambiguity (and free up parentheses for other tasks, eg. grouping math if we're going to add infix operators)

If we swapped them, functions would look a bit more familiar:

>implying OP isn't >function(args) {
    >mfw args[0]
}

I'll leave this up for debate.

Ps. I added you to the contributors list so you can push commits to this repository directly.

haasn commented 13 years ago

I've swapped them around for now, since it probably does make more sense this way.