Skip to content
This repository has been archived by the owner on May 23, 2021. It is now read-only.

Implement Builtin Expander (Macro System) #15

Open
1 task
spy16 opened this issue Sep 9, 2020 · 8 comments
Open
1 task

Implement Builtin Expander (Macro System) #15

spy16 opened this issue Sep 9, 2020 · 8 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@spy16
Copy link
Owner

spy16 commented Sep 9, 2020

  • Implement BuiltinExpander that expands Seq based macro-invocation forms.

Need to figure out how a symbol/value would be identified as a macro (Clojure uses a ^:macro tag)

@lthibault lthibault added this to the 1.0 Release milestone Sep 11, 2020
@lthibault
Copy link
Collaborator

Perhaps we could use an interface to "tag" values as macros?

type Macro interface{
    Macro()
}

We would then wrap a Seq in something like this:

type macro struct{ Seq }

func (macro) Macro() {}

Then we can just type-assert against the Macro type to determine whether macro expansion is required.

@spy16
Copy link
Owner Author

spy16 commented Sep 21, 2020

No, we need to tag the value of the operator to indicate macro or not. We don't need to tag the entire Seq form.

For example, in the invocation form (my-macro arg1 arg2), expander need to be able to figure out that my-macro is a macro and then do expansion.

We could introduce a Macro type:

type Macro struct {
    Name string    // macro name.
    Args   []string // argument names.
    Body  Any
}

In above example,

  1. Expander would resolve my-macro symbol to get a value of type Macro. (If it's not of that type, skip expansion)
  2. Create bindings for parameters and the corresponding invocation arguments in the Env. (symbol collision needs to be handled. See gensym).
  3. Then evaluate the m.Body in current Env.
  4. Return the result as the new form.

@lthibault
Copy link
Collaborator

Ah gotcha!

Ok this makes sense. I’ll have a think.

@lthibault
Copy link
Collaborator

@spy16 I'm going to start working on your proposed implementation. Just a heads up so that we don't duplicate any work 🙂.

@lthibault lthibault self-assigned this Sep 28, 2020
@lthibault lthibault added the enhancement New feature or request label Sep 28, 2020
@lthibault
Copy link
Collaborator

@spy16 Ok, so as much as I hate to admit it, I think I've bitten off more than I can chew! I think you probably have a much more complete picture of how macro expansion fits into our current architecture, whereas every attempt I've made so far ends up requiring major changes in other parts of the codebase ... a sure sign that I'm Doing It Wrong! 😅

I'm unassigning myself from this issue, and letting you take over. My latest attempt can be found in the feature/macro branch. If you have a moment to look, I'd welcome your feedback about what I'm doing incorrectly.

Sorry about this 😞

@lthibault lthibault assigned spy16 and unassigned lthibault Sep 29, 2020
@spy16
Copy link
Owner Author

spy16 commented Sep 30, 2020

No worries. Let me take a stab at this. 🙂

@spy16
Copy link
Owner Author

spy16 commented Oct 9, 2020

I will try to do this over this weekend. sorry for the slow progress here. have been extremely busy.

@lthibault
Copy link
Collaborator

No worries, and thanks for the update! 🙂

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants