Skip to content

Improved function syntax #32

@cowboyd

Description

@cowboyd

The current function syntax $(arg): body is not sufficient for two reasons:

  1. it is confusing because $ is the sigil reserved for dereferencing (which is used in function invocation), but the definition of a function is not a dereference.
  2. Only being able to define function properties in terms of an anonymous function is cumbersome and prone to right-ward drift.

For example, to define an <AboutCard> react component, it looks like

<AboutCard>:
  $(props):
    $<>:
      - $<span>: Hello
      - $<span>: Goodbye

The first change, would be to use ()=> for anonymous functions:

<AboutCard>:
  (props)=>:
    $<>:
      - $<span>: Hello
      - $<span>: Goodbye

This clearly marks that there is no de-referencing happening, but rather this is a static value.

The second is the ability to define a function property in a single place:

<AboutCard>(props):
  $<>:
    - $<span>: Hello
    - $<span>: Goodbye

Open Questions

We've talked about using rest options mappings to provide local bindings as a stand-in for destructuring (#15). E.g.

greet:
  (person)=>: Hello %($name)
  name: "%($person.first) %($person.last)"

Would this be possible with "method syntax" where you have multiple function properties in the same map? At first appearance it does not seem so. You could always use $let/$do but then you have a tension of "do I want a convenient function body", or "do I want a convenient function declaration syntax?"

If we were to define this same function using method syntax:

greet(person):
  $let:
    name: "%($person.first) %($person.last)"
  $do: Hello %($name)

Is there a way to have it both ways?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions