Skip to content

For templating purposes, consider allowing ... as the parameter list of a function #1335

Open
@blerner

Description

@blerner

In looking at some of the starter code provided to students, Joe and I have noticed "code" using ... like this:

fun update-x(...):
  ...
end

This code does not currently parse, because ... can't be used as a parameter list. Consequently, the entire starter file --- even if it's got some working code up at the top! --- is unusable just by clicking Run, which is not an ideal experience.

I don't know what I'd like the semantics of this to be, exactly, but my hunch is:

  1. it should be syntactically allowed,

  2. it should be a well-formedness error for such a function to not have at least one ... in the body of the function --- if you've figured out the body, I'd hope you've figured out the signature.

    • I'm wondering whether we should allow the body to be
      fun update-x(...):
        ... x + foobar + baz ...
      end
      
      with unknown names in the body, and not do scope-checking on such functions, since the idea might be to allow students to sketch out expressions and ideas they might think are relevant, and not penalize them for being incomplete so far.
  3. it should be a dynamic error to call such a function, obviously, but I don't think it should be an arity error to call it with different numbers of arguments, since the whole point is the signature isn't well-defined yet. Probably something along the lines of the unfinished-template error we already have.

  4. I don't know whether this will interact badly with a hypothetical future extension of Pyret that allows a varargs parameter in functions (since it's giving a semantics to ... in the parameter list), but I think it won't technically be ambiguous since a varargs list still needs a name preceding those dots.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions