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

define definitions recomputed on every call #134

Open
wilbowma opened this issue Jun 25, 2020 · 5 comments
Open

define definitions recomputed on every call #134

wilbowma opened this issue Jun 25, 2020 · 5 comments

Comments

@wilbowma
Copy link
Owner

wilbowma commented Jun 25, 2020

I think this is because we implement define with a variable transformer instead of actually expanding to a variable de-reference. It surprised me in my attempt at a staged programming example. This has to do with how we implement normalization; we'd need a way to delta reduce variables at compile-time.

#lang cur

(require cur/stdlib/nat)
(require racket/trace)
(require cur/debug/syntax-trace)

(trace-define-syntax run
                     (lambda (stx)
                       (syntax-parse stx
                         [(_ expr)
                          (cur-normalize #'expr)])))

(define one (run (plus 1 0)))
one

Should print

> (run '(run (plus 1 0)))
<'(s z)
(s z)

But actually

> (run '(run (plus 1 0)))
<'(s z)
> (run '(run (plus 1 0)))
<'(s z)
'(s z)

and we see run executed on every call use of one.

stchang added a commit to stchang/cur that referenced this issue Jun 25, 2020
@stchang
Copy link
Collaborator

stchang commented Jun 25, 2020

Yes, it's a problem.

We can't get rid of the variable-transformer (because then ids wont have types), but define in coc.rkt should be using the expanded e. It doesnt right now as a workaround to the old stxprop + modules problem.

As a start, I've submitted #135, which fixes your problem, but breaks many tests, which I'm still working through.

(If your demo works ok with #135 then feel free to use it.)

@wilbowma
Copy link
Owner Author

Thanks! I just cut that part of the demo. I can do with out it.

@stchang
Copy link
Collaborator

stchang commented Jul 2, 2020

dupe of #37 and #90?

@wilbowma
Copy link
Owner Author

wilbowma commented Jul 2, 2020

I wouldn't say dupe, but it is related. #37 and #90 are dupes. I consider that related to implementing things like Coq's cbn and cbv tactics, which let the user control evaluation.

wilbowma pushed a commit that referenced this issue Aug 27, 2020
Adds two versions of define:
- `define`, which does not perform \delta-reduction.
- `define-for-export`, which eagerly performs \delta-reduction.

The eager \delta-reduction is a necessary workaround for Racket module issues
and syntax-properties, and thus, needed when exporting a definition.
@wilbowma
Copy link
Owner Author

Partially addressed, but the issue is we need lazy (by-need) \delta-reduction, I think.

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