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

Changes necessary to get pmatch to work #47

Merged
merged 12 commits into from
May 6, 2020

Conversation

david-christiansen
Copy link
Collaborator

This is the equivalent of Racket/Scheme's make-syntax-introducer and generate-temporaries.

This is the equivalent of Racket's make-syntax-introducer and
generate-temporaries.
This makes debugging much easier.
@david-christiansen david-christiansen changed the title Temporary name generation in macros Changes necessary to get pmatch to work Apr 23, 2020
@david-christiansen
Copy link
Collaborator Author

There's now a pmatch that seems to work (fixes #36).

@david-christiansen
Copy link
Collaborator Author

This exposed a strange bug that I had to fix as well :-)

@david-christiansen
Copy link
Collaborator Author

Do you think this is ready for a merge?

@gelisam
Copy link
Owner

gelisam commented Apr 27, 2020

Do you think this is ready for a merge?

If you want, but I haven't reviewed much of it yet. I multi-task, so the lack of new comments doesn't mean I'm done reviewing, it just means I got distracted by something else. I use GitHub's "Approve / Request Changes" button when I'm done.

@david-christiansen
Copy link
Collaborator Author

david-christiansen commented Apr 27, 2020 via email


(example (pmatch (zero) (else 't)))
(example (pmatch (zero) ((else x) 't)))
(example (pmatch (zero) (x 't)))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(else x) and x both match anything? why do we need both?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I bet I'm going to accidentally write the pattern zero instead of (zero) all the time. only having ,x bind variables would be a lot less error-prone, I think (and would match the original algorithm)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

else unambiguously binds the variable x, while x alone may be a macro that expands to a pattern case using the normal case machinery.

As far as the comma goes, I am not a fan of the aesthetics of using an antiquotation operator for something that really isn't antiquotation...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to be clear - x does not presently get to be a macro invocation, but this syntax at least does not rule that out!

[ppat
(lambda (stx)
(syntax-case stx
[(list (_ tgt pat ks kf))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

earlier the continuation function was called fk and now it's called kf. which is it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be pedantic, the earlier thing is a function, while this is a local name for a piece of code. But I'll call them all "kf".

(syntax-case stxs
[() (none)]
[(cons e es)
(bind 'internal-x e (abstract es))])))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Abstracted, none, and bind aren't used anywhere, I'm guessing this is a leftover from a previous implementation?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep! Will delete.

[(cons c cs)
(syntax-case c
[(list (pat rhs))
(>>= (else-case pat)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the else cases treated separately? I would have expected them to be handled by ppat, just like every other pattern.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Else cases are only valid at the top of a given pattern, while ppat is invoked recursively.

[(:: id-and-stx rest)
`(ppat ,(fst id-and-stx) ,(snd id-and-stx) ,(combine rest) ,kf)]))
(pure `(case ,tgt
[,(cons-list-syntax what (the Syntax (list->syntax temp-names pat)) pat)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of the the Syntax type annotation? The name list->syntax already communicates quite clearly that it is returning a Syntax. I am guessing that this is leftover from a previous debugging session?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On that note, I had completely forgotten that Klister was a typed language while reading this code. How about defining versions of define, let and flet which encourages including a type signature?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The annotation is going away - it was for sanity while I was afflicted by #48.

For the define etc, we would need a way to annotate type schemes, which we don't yet have. See #60 for a design sketch.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

deriving (Eq, Show)

instance Show MacroAction where
show _ = "MacroAction..."
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meh, if these Show instances aren't going to give any information, should we even bother giving them a Show instance at all?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because other things that include a MacroAction do have useful Show instances that are derived.

@david-christiansen david-christiansen merged commit 76033ed into master May 6, 2020
@langston-barrett langston-barrett deleted the generate-temporary branch August 26, 2020 00:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants