Gentlemen... BEHOLD!

Published February 18, 2012
Advertisement
I give you Epoch, now with a much better function definition syntax:

//
// FUNCTIONS.EPOCH
//
// Compiler test for higher-order functions
//

entrypoint :
{
apply("test", debugwritestring)
debugwritestring(apply("test", mutate))
}


apply : string param, (thefunction : string)
{
thefunction(param)
}

apply : string param, (thefunction : string -> string) -> string(ret, thefunction(param))

mutate : string param -> string(ret, param ; " foo")


Next up: improving the variable initialization syntax... that one could get interesting.
0 likes 9 comments

Comments

swiftcoder
This is a little offtopic, but since you are working on syntax... :)

I have a lot of conversations with coworkers, students, etc. that end up somewhere like "python would be a better language if it had curly braces", or "Erlang is a interesting concept, but the syntax is unusable" - anyway, you get the idea.

My first thought on glancing at your example above was that the syntax is a little opaque. There appears to be a lot of magic going on: why does the semi-colon concatenate strings? Why does the first apply not need an explicit return specification, while the second does? What's the meaning of the magic parameter 'ret'?

Now, I'm sure I could answer all these questions by spending a few more minutes going over the documentation. But my question is this: how much of a barrier do you think a fairly opaque syntax might be to the eventual adoption of a language? Or in other words, should we go out of our way to make every new language look like C or Python, because those are what people are most familiar/comfortable with?
February 18, 2012 04:20 PM
Telastyn
Personally, I think that having a similar/comfortable syntax is good for adoption, but there's a number of places when doing design where it doesn't work, or fit with the changes.
February 18, 2012 05:08 PM
nolongerhere
Magic within this, there is. Confused, I am.
February 18, 2012 06:44 PM
Washu
[quote name='swiftcoder' timestamp='1329582033']
This is a little offtopic, but since you are working on syntax... :)
[/quote]
Hardly off topic, while the syntax of the language is in flux, any sort of commentary on the "syntax" elements of a language is on topic.
[quote]I have a lot of conversations with coworkers, students, etc. that end up somewhere like "python would be a better language if it had curly braces", or "Erlang is a interesting concept, but the syntax is unusable" - anyway, you get the idea.[/quote]
I've never found the lack of brackets in python to be a detriment, but then again, when I picked it up I was hardly a beginner. That being said, most people who feel that way have been exposed to C or C++ and are thinking of scope in terms of closing brackets. I.e. they haven't fully realized that well formatted code is at the heart of scope in python :)
[quote]My first thought on glancing at your example above was that the syntax is a little opaque. There appears to be a lot of magic going on: why does the semi-colon concatenate strings? Why does the first apply not need an explicit return specification, while the second does? What's the meaning of the magic parameter 'ret'?[/quote]
Semi-colon is just an overload of operators. Kind of randomly chosen. The "ret" parameter is the name of the variable. Which is a bit confusing, since the variable name is then followed by the parameters of the constructor, which in this case is the result of the concatenation of param and " foo". Its something that is still in flux
[quote]Now, I'm sure I could answer all these questions by spending a few more minutes going over the documentation. But my question is this: how much of a barrier do you think a fairly opaque syntax might be to the eventual adoption of a language? Or in other words, should we go out of our way to make every new language look like C or Python, because those are what people are most familiar/comfortable with?
[/quote]
Most functional languages I've used and looked at were HELL to get into for a beginner, simply because the syntax of most functional languages are very opaque. C's syntax is quite simple, honestly, its just the language its self that's such a bitch to get into. THe same is really true of python, the syntax is darned simple to understand.
February 18, 2012 11:07 PM
Washu
We can break this bit of code down a bit for a bit of clarity about what is going on:
[code]
apply : string param, (thefunction : string)
[/code]
This declares a function 'apply' which takes two parameters, and returns nothing:[list]
[*]param, which is of type string
[*]thefunction, which is of type "function that takes a string and returns nothing"
[*]returns: nothing
[/list]
[CODE]apply : string param, (thefunction : string -> string) -> string(ret, thefunction(param))[/CODE]
This is an overload of apply which takes the following parameters, and returns a string constructed from the result of calling the function parameter:[list]
[*]param, which is of type string
[*]thefunction, which is a function that takes a string and returns a string.
[*]returns: 'ret', containing the result of the call to thefunction with the first parameter.
[/list]
[CODE]mutate : string param -> string(ret, param ; " foo")[/CODE]
This is a function that takes a parameter of type string and returns another string 'ret' containing param concatenated with " foo"
February 18, 2012 11:12 PM
Washu
On the syntax of return parameters...

My personal preference would be something similar to parameter decleration:
[CODE]
//
// FUNCTIONS.EPOCH
//
// Compiler test for higher-order functions
//
entrypoint :
{
apply("test", debugwritestring)
debugwritestring(apply("test", mutate))
}

apply : string param, (thefunction : string)
{
thefunction(param)
}
apply : string param, (thefunction : string -> string) -> string ret(thefunction(param))
mutate : string param -> string ret(param ; " foo")
[/CODE]

or, in otherwords (in EBNF)...
[code]
returnType = typeName identifier ( OPENPAREN expression CLOSEPAREN )?
[/code]
February 18, 2012 11:16 PM
swiftcoder
Ok, that makes things a lot clearer. But the return specification is a little weird - I like your suggestion better.
February 19, 2012 05:49 AM
Washu
I too liked my suggestion better, until I noticed that the editor added like a hundred million spaces.
February 19, 2012 08:23 AM
ytinasni_
Your current function syntax/variable syntax difference is kinda odd.

I think variables (and fields, and parameters) should look more like how functions look - e.g.
example_field1 : string = "pie"
example_field2 := "pizza" // short form, type = typeof(initializer-expression)

example_function : param : string, (thefunction : string -> string) -> ret : string(thefunction(param))

On the other hand, this highlights how weird your parameter syntax is. (an extra set of parentheses changes a string parameter into a string->void function? thanks, but no thanks.)
February 20, 2012 08:03 PM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement