Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[RFC] Consider adding callinfo for introspecting method calls #189

Open
Labels
feature-requestAny request for a new feature of the language. Includes both syntax and library features. syntaxAny issue relating to the syntax of Myst.

Description

callinfo would be a language-managed variable, similar to self, that provides some introspective information about the caller of a method. As a language variable, callinfo would also be added as a new keyword.

Having access to meta information about the caller of a method is primarily helpful for debugging and tooling inside of Myst. The most obvious usecases are the Spec and Assert libraries.

Most spec libraries provide location information about failing specs to help users locate them quickly and easily. In Myst, this isn't a practical possibility yet, because the library has no way of accessing that location information without requiring the user to pass in __FILE__ and __LINE__ values for every it block.

Adding callinfo would provide that location information to these modules automatically, without any burden on the user. It would also avoid having conditional semantics for the magic constants, which I've never particularly liked.

Semantics

Referencing callinfo outside of a method definition will always return nil.

Inside of a method definition, callinfo returns a Map with these entries:

  • :file: the file containing the call to this method.
  • :line: the line number of the call to this method.
  • :dir: the directory containing the file with the call to this method.

For simplicity, this Map is newly-created every time callinfo is invoked. This ensures both "psuedo-immutability", and that the values are accurate for the current call.

Example usage

Retrieving the location information of a Call using callinfo could look something like this:

def foo(a, b, c)
 {line: line, file: file} = callinfo
 STDOUT.puts("line <(line)>, file <(file)>")
end
foo(1, 2, 3) #=> line 6, file /Users/.../foo.mt

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature-requestAny request for a new feature of the language. Includes both syntax and library features. syntaxAny issue relating to the syntax of Myst.

    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

        AltStyle によって変換されたページ (->オリジナル) /