malloydata / malloy

Malloy is an experimental language for describing data relationships and transformations.
http://www.malloydata.dev
MIT License
2.01k stars 76 forks source link

Parameters Experiment (MVP) #1785

Closed christopherswenson closed 3 months ago

christopherswenson commented 4 months ago

Introduces a new experiment: ##! experimental.parameters

TL;DR:

Documentation: https://docs.malloydata.dev/documentation/experiments/parameters

For known bugs, see below.

New Syntax

Sources can be declared with parameters:

Declared parameters may have a type and/or a default value:

Source usages may specify parameters:

New Semantics

Parameters are only inherited from one source to an extended source explicitly:

source: my_source(param is 1) is ...
source: ext_source_1 is my_source(param is 1) // No parameters
source: ext_source_2(param::number) is my_source(param) // One parameter, but without default value

Constant expressions are allowed anywhere where sources can be invoked

Parameters can only be used in a few limited places:

Parameters cannot be used in the following places (and likely will not in the future):

Parameters cannot be used in the following places (but likely will in the future):

Parameters cannot currently be annotated (but they likely will be in the future)

  source: my_source(
    # param_tag=1 // <— syntax error
    param::string
  ) is ...

Parameters of a source are not included in index: * or select: *

For the time being, shadowing of parameters by fields or vice versa is illegal

   source: my_source(param::string) is ... extend {
     dimension: param is ... // Error
   }
   source: base_source is ... extend {
     dimension: param
   }
   source: my_source(param::string) is base_source // Error

Likely in the future this will be legal, but there will be some other syntax to help navigate conflicts

Known Bugs