Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Evaluating user-defined template macros #730

Open
tgregg opened this issue Feb 21, 2024 · 0 comments
Open

Evaluating user-defined template macros #730

tgregg opened this issue Feb 21, 2024 · 0 comments
Labels
ion11 Related to Ion 1.1

Comments

@tgregg
Copy link
Contributor

tgregg commented Feb 21, 2024

Ion 1.1 allows users to define templates--reusable data shapes that can be invoked as many times as needed--that expand to zero or more Ion values.

This issue builds on #656 and #657, and tracks building the machinery needed to evaluate invocations of a user-defined template macro. Such invocations can appear in two places:

  1. In the data stream, encoded using an e-expression.
  2. In the body of another template, encoded as an s-expression.

The latter requires implementing the ability to pass named parameters (i.e. variables) from the host template's environment to the macro being invoked.

For example:

// Template definition
(macro
    greet              // Template name
    (part_of_day name) // Parameter names
    (make_string       // Template body
        "Good "
        part_of_day
        ", "
        name
        "."))

(:greet "morning" "Mr. Cartwright")

// Notionally expands to the intermediate equivalent:
(:make_string "Good " "morning" ", " "Mr. Cartwright" ".")

// Which evaluates to:
"Good morning, Mr. Cartwright." 

In this case, the named parameters part_of_day and name are passed from the environment of the greet invocation to the environment of the make_string invocation.

@tgregg tgregg converted this from a draft issue Feb 21, 2024
@tgregg tgregg moved this from Todo to Done in Ion 1.1 preview implementation Oct 15, 2024
@popematt popematt added the ion11 Related to Ion 1.1 label Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ion11 Related to Ion 1.1
Projects
Development

No branches or pull requests

2 participants