beelang / specification

0 stars 0 forks source link

Functions #4

Open krainboltgreene opened 7 years ago

krainboltgreene commented 7 years ago

Defining a function will return a Function object. A Function can only take one argument, but that argument can be an Index List or Pair List.

Single line function definitions are expressed thusly:

ƒ(x): x +(1)

For multiple arguments you can express it thusly:

ƒ({x, z}): x +(z)

Defaults can be expressed as such:

ƒ(x: 0): x +(1)

Multiline functions are expressed thusly (Only the last line is returned):

ƒ(x):
  log("Hello, World.")
  x +(1)

Function invocation is expressed thusly:

increment: ƒ(x): x +(1)
increment(1)

For multiple arguments you would express it thusly:

increment: ƒ({value, by}): x +(z)
increment({value: 1, by: 1})

Of course for currying you would express thusly:

ƒ(x): ƒ(y): x +(y)

And currying with multiline is express thusly:

ƒ(x):
  ƒ(y):
    x +(y)
krainboltgreene commented 7 years ago

Now I'm starting to like arrows:

point: (x) -> (y) -> [x, y]

Hmm, also I think:

point: (x) ƒ (y) ƒ [x, y]

or

point: (x) ƒ (y) ƒ
  [x, y]
krainboltgreene commented 7 years ago

Also, calling functions maybe force the argument to have the name?

point(x: 4)(y: 3)

vs

point(4)(3)
krainboltgreene commented 7 years ago

I've seen a lot of languages do pipe operators so you can do:

a(b(c))

as

a
  |> b
  |> c

But I'm wondering how this would look in bee, this a first pass:

>- pullAccounts >- mapValues(path(["attributes", "created-at")) >- moment
>- pullAccounts
>- mapValues(path(["attributes", "created-at")) 
>- moment

This is interesting because it's the opposite of ->.

krainboltgreene commented 7 years ago

Oh, also, with that we can also do promises as >>- and actors as >>>-

krainboltgreene commented 6 years ago

Type annotations for functions

# store_printer: UUID -> String -> Cookies -> String
store_printer:
  id ->
  station ->
  cookies ->
    cookies fetch(station) fetch(id)