8000 Replace import with more general includes · Issue #109 · ruuda/rcl · GitHub
[go: up one dir, main page]

Skip to content

Replace import with more general includes #109

Open

Description

@ruuda

Background

When you define a function that calls std.read_file_utf8, how the path resolves depends on where the function is called from, not where the function is defined. This is a bit of a footgun. For imports we sidestep this by forcing import statements to be string literals, which is possible because import is a separate construct, not a regular function.

It has bugged me for a while that import is special, it also prevents loading json data at runtime, for example when json contains nested json.

Possible solution

How about:

  • We split import (which loads a file and evaluates it) into a "load file" part and a separate "evaluate" part.
  • The load file part now becomes useful as a replacement for read_file_utf8 with a way to refer to paths independent of call site.
  • The evaluate part could be used to evaluate runtime-generated strings.

This also restores the property that the entire dependency graph can be determined only after parsing, without the need to evaluate. Currently this is true for the RCL import graph, but not for the full dependency graph (used by --output-depfile).

To still enable good error reporting, strings would need to carry some kind of provenance that tracks where the string came from (a file, or generated at runtime in a particular expression). I was thinking it may be nice to have that for values anyway, but for strings it will be especially important if eval replaces import.

Possible syntax ideas:

// @ to import from a file path, though this is not readable to new users.
let util = std.import(@"util.rcl");

// Keyword like current `import`, but looks a bit awkward? Hmm …
let util = std.eval(include "util.rcl");
let util = std.load(embed "util.rcl");
let util = std.import(fetch "util.rcl"):

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0