rascal icon indicating copy to clipboard operation
rascal copied to clipboard

No syntax for keyword parameter types in function type signatures

Open jurgenvinju opened this issue 1 year ago • 1 comments

This is a language design bug that makes it impossible to provide keyword parameters to functions that are passed as values.

For example this constructor encapsulates two closures, one of which has a optional keyword parameter duration:

data RascalRuntime
  = evaluator(
      PathConfig pcfg,
      void () reset,
      Result[&T] (type[&T] typ, str command /*, int duration=-1 */) eval
  );
  • The commented out code is not valid syntax. parse error at the = sign.
  • Default values make no sense in function type signatures because they are part of the definition of functions and not of their type. Even if we would type them in, those defaults would never be used/executed.
  • However, the name and the type of the keyword parameter is a part of the signature of a function.
  • But we can't type it in.

We probably need a notation for listing keyword parameters without their defaults, as:

Examples with different syntactical solutions:

  • Result[&T] (type[&T] typ, str command, int duration=...) (uses ... to make a placeholder for the missing default.
    • this is most consistent with the other occurrences of keyword parameters in the language (constructors, common keyword parameters in data-types and function definitions)
  • Result[&T] (type[&T] typ, str command, keyword int duration) uses keyword (which is already a reserved keyword)
    • repurposes a keyword that is used in another part of the language for something completely different. confusing.
  • Result[&T] (type[&T] typ, str command; int duration), uses ; to separate normal parameters from keyword parameters.
    • this would be good if we'd also enforce the same ; everywhere we define keyword parameters
    • I don't like it for the empty positional parameter case: (;int duration)

This is probably cause for a small Rascal Amendment Proposal.

jurgenvinju avatar May 31 '24 09:05 jurgenvinju

BTW: The compiler produces currently "undefined keyword argument" (as an error not a warning), while the interpreter executes the code regardsless of the missing declaration.

jurgenvinju avatar May 31 '24 10:05 jurgenvinju