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

Implement zero-arg functions in eval.rs #5

Closed
namin opened this issue Oct 10, 2021 · 12 comments
Closed

Implement zero-arg functions in eval.rs #5

namin opened this issue Oct 10, 2021 · 12 comments
Assignees

Comments

@namin
Copy link
Contributor

namin commented Oct 10, 2021

No description provided.

@namin namin self-assigned this Oct 10, 2021
@porcuquine
Copy link
Collaborator

porcuquine commented Oct 10, 2021

This should get you started:

Comments in code at least intend to point to where this should happen:
https://github.com/lurk-lang/lurk-rs/blob/master/src/eval.rs#L481-L485
https://github.com/lurk-lang/lurk-rs/blob/master/src/eval.rs#L551

And here is how it's done in lang.lisp:
https://github.com/lurk-lang/lurk/blob/master/impl/lang.lisp#L805-L813
https://github.com/lurk-lang/lurk/blob/master/impl/lang.lisp#L877-L885

Note that Continuation::Tail is (for now) called CALL3-CONTINUATION in lang.lisp.

@namin
Copy link
Contributor Author

namin commented Oct 11, 2021

I can think of at least two ways of doing it:

  • have a new kind of call continuation for zero-arg functions
  • transform (lambda () ...) to (lambda (dummy) ...). This seems in the spirit of the auto-currying that is currently done.

Any thoughts?

@porcuquine
Copy link
Collaborator

I think the most economical thing (both conceptually and in terms of computation) is to use Continuation::Tail. This is exactly a continuation awaiting no more values. That's why it used to be called Call3: it's what comes after the second value (the argument, first was the function) has been supplied.

Although the context of the code there may have drifted, I think that (just use Tail) is what this comment is trying to communicate: https://github.com/lurk-lang/lurk-rs/blob/master/src/eval.rs#L763-L765

@namin
Copy link
Contributor Author

namin commented Oct 11, 2021

I am not sure what you have in mind for distinguishing the zero-arg case from the one-arg case when matching on Continuation::Call.
https://github.com/lurk-lang/lurk-rs/blob/master/src/eval.rs#L535

@namin
Copy link
Contributor Author

namin commented Oct 11, 2021

Sounds like we need to change handling of lambda too:
https://github.com/lurk-lang/lurk-rs/blob/master/src/eval.rs#L307

@porcuquine
Copy link
Collaborator

Ah, I think that if it turns out we can use Continuation::Tail for the zero-arg case, then we actually won't need to add anything there. In that case, the change will just be to delete the comment, as the implementation will be a no-op.

I think this is where we have parsed the input and know we need to handle a zero-arg function. https://github.com/lurk-lang/lurk-rs/blob/master/src/eval.rs#L473

@namin
Copy link
Contributor Author

namin commented Oct 11, 2021

We still have two steps: we need to evaluate the fun_form, and then we need to invoke it. It's not just the invocation part.

@porcuquine
Copy link
Collaborator

Right, I agree with that. Am just paging this in. If my previous makes sense as far as it goes, then I think you're on track here.

@namin
Copy link
Contributor Author

namin commented Oct 11, 2021

Yeah, sorry if it would be faster for you to implement than to explain what you had in mind :D

I am not convinced we can do it with one Continuation::Tail because how are we going to get the body out of the fun_form?

Thanks.

@namin
Copy link
Contributor Author

namin commented Oct 11, 2021

I think using the one-arg translation of zero-arg functions might be the most economical, since it's just a syntactic change.

@porcuquine
Copy link
Collaborator

I think you might be right. I don't have time to trace this all down right now, and I suspect that if I do I will end up with the same conclusion. So… I think it's probably worthwhile for you to go ahead and implement that way. If a viable competitor emerges, we can look at it, but if you have a line on this, feel free to proceed.

@namin
Copy link
Contributor Author

namin commented Oct 11, 2021

Sounds good, thanks!

namin added a commit that referenced this issue Oct 11, 2021
The implementation simply desugars each zero-arg function into
a one-argument function taking nil.
arthurpaulino pushed a commit that referenced this issue Sep 7, 2023
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

No branches or pull requests

2 participants