Skip to content

Support user-defined functions #142

@hendrikvanantwerpen

Description

@hendrikvanantwerpen

TSG does not support the definition of functions in the TSG source. As a result, common patterns are often written out in multiple places, making sources harder to read and maintain.

It should be possible to define functions in the source. Something like:

function (foo node names*) {
    for name in names {
        // ...
    }
}

Questions and challenges:

  • How do we deal with localness of arguments inside a functions?

    • We can start with requiring all arguments to be local, and try to relax later (e.g. by inferring from the use in the function body).
  • Should functions have return values?

    • This could be useful for e.g. a function introducing a module name, which may introduce multiple nodes, and the final node is returned.
  • Are functions treated the same as builtin functions, i.e. called as (foo ...), and can they appear in the same places?

    • I'd prefer if expressions were pure, and these functions certainly are not. Alternatively we clearly separate them using e.g. an apply foo ... statement. However, it would get a bit awkward if they return values: would we have to forms, let var = expr and apply var = foo ... or something?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    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