towerofnix / tlnccuwagnf

The Language Nobody Could Come Up With A Good Name For
MIT License
18 stars 3 forks source link

Why `fn() {}`? #13

Closed bates64 closed 8 years ago

bates64 commented 8 years ago

Why do we use

foo => fn(bar, baz) {
  # code #
}

rather than, for example

foo => (bar, baz) {
  # this is shorter! #
}

It's something I've been thinking about it and calling fn and then passing variable definitions... it just seems to me like calling a function to create one seems a bit dodgey - it doesn't do what is expected.

towerofnix commented 8 years ago

fn(args) {code} seems a bit more explicit, but there are lots of times when I want to use fn as a parameter or variable.. discussion needed! :P

I get it looks kind of like a function call. Hmm..

bates64 commented 8 years ago

I have two ideas:

# 1
foo => (bar, baz) {
  # code code code #
}

# 2
foo => {
  (bar, baz) # hell if we can; ommit the brackets alltogether!
  # code code code #
}

Thoughts?

towerofnix commented 8 years ago

I prefer #1 there.

bates64 commented 8 years ago

Also I think typed arguments should exist, builtin? For example:

foo => (bar@str) {
  print('yay')
}

foo(123) # foo(...): Argument 1 must be a string
towerofnix commented 8 years ago

Also I think typed arguments should exist, builtin?

I kind of dislike using static typing..

If you need a string, change the input to a string. (Wait, we don't have a function for that? Oops..) If you really need some fancy prototype thingy, check if it's of that class manually -- that's how I do it..

if (!(x instanceof FancyClass)) {
  throw new Error('Argument must be instance of FancyClass');
}

EDIT: Plus static typing belongs in a different issue!

bates64 commented 8 years ago

I guess so :) Although then we need some sort of type() function in Tulun!

towerofnix commented 8 years ago

Apparently people like this.

foo => (bar): *(bar, 2);
baz => (bar) { return(*(bar, 3)); };
bates64 commented 8 years ago

And also this @liam4.

# single argument, ommit brackets (may be hard to implement?) #
foo => bar {...};

# no arguments, ommit brackets altogether #
foo => {...};
towerofnix commented 8 years ago

single argument, ommit brackets (may be hard to implement?)

Probably not hard to implement. Not sure I like it though.

no arguments, ommit brackets altogether

Oops, yeah, that too.

bates64 commented 8 years ago

Probably not hard to implement. Not sure I like it though.

Same here. Just implement the others first? :package: