-
-
Notifications
You must be signed in to change notification settings - Fork 70
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
Enable use-function-output-syntax
for ISL[+]. Fixes #208.
#229
base: master
Are you sure you want to change the base?
Conversation
Another approach would be to simply (or conditionally) remove this test. It isn't clear to me what value there is in checking the current namespace as the program executes. (Indeed, I wonder if built-executables will produce different results than running from inside DrRacket, due to this check.) Maybe @mfelleisen knows the rationale for this check and whether or not we can just simply skip it for the |
I don’t think I ever touched this file. (I recall looking at it, I think.)
|
I @mfelleisen 'd because of the semantics not because of the implementation. To ask the question more better, I'm wondering under what conditions do you think we should see the name of a function and under what conditions should we see something Right now the criteria is a bit wonky, using the current namespace. That strikes me as unlikely to be the best criteria (although it may have been reasonable in the 1990s). In particular, I wonder if lambdas that are bound locally should get the name or not? Or only top-level definitions? Or is there some other way to decide which ones get printed with names and which don't? |
The semantics matches the pedagogy. So:
From the perspective of a BSL programmer, always use the name of a function. Period.
For an ISL+ programmer, it should be `(lambda …)`.
For an ISL programmer, it’s an open question:
`(local ((define (f x) …)) …)`
is lifted to the top level with a minor renaming of `f` because it could be lifted more than once. Indeed, when kids make the usual mistake an call the outer function from the inner one and something goes wrong, they might understand that f13 means “f was lifted 13 times” — but this depends a lot on the capabilities of the instructor and most of them aren’t capable. Period. Meaning we should sadly go with just the plain name `f`.
Makes sense?
|
In BSL/BSL+, I think printing functions are mostly impossible, so only ISL/ISL+ are within the scope. Currently ISL prints things as In ISL+, should functions like |
Semantically yes.
Pragmatically — context! means students comprehending the error message and acting on it — no, all functions with a name (not anonymous `lambda`s) should print-by-name not print-by-value.
|
Testing if an object has a name does not differentiate bound lambdas from anonymous ones since all lambdas have names like " |
Some tests are added to |
So: rather than setting the namespace, directly matching lambda's name against the pattern @mfelleisen @rfindler Is this an acceptable fix?
|
Yeah, I think we can go with this.
|
I'm a little bit suspicious of using a regular expression on the name. There might be a better way: can you clarify a little bit why just using object-name isn't okay? |
Because all lambda functions in a (saved) file have names. |
Ah, right! Thanks to a tip from @mflatt it turns out that this doesn't have to be true. Here's how to make a function without a name:
So if we can adjust the expansion of the teaching language lambda to be like this one then we can add a parameter to print convert that lets us avoid the namespace check entirely. |
That's not bad but say we have a program like this (very contrived):
We get a strange error. (I also recommend stepping through this. The stepper shows way too much of the expanded code in check-satisfied. But see the names it gives to f.) |
Earlier, what you wrote, @mfelleisen, implies that the result of |
What I am getting at is this:
Thinking aloud here, so let's try @jbclements See stepper for the above program. This should be fixed. |
d9486ca
to
6674ca6
Compare
use-function-output-syntax
for ISL[+]. Fixes #208.
2f91396
to
f89af9c
Compare
Updated with a new solution. As it seems, enable The tests are available from racket/drracket@c60fc6a in: |
Oops, it is still not fixed for unnamed lambdas in files. The tests do not save buffers to files so they did not capture the bug. |
Nice find! Even looking at the diff, I'm remembering nothing about that!
Along those lines, it seems to me that a source-location-based name might actually be useful in some situations to help debugging. |
f89af9c
to
76e5360
Compare
@mikesperber this PR is ready. Do you see any obvious issues with turning on the @rfindler The code has to be saved to disk when testing. From the documentation,
|
@shhyou hm; thanks for noticing that! I see that we could use an applicable struct and |
It looks like we need to strip the source location from the syntax object too, eg:
(we would also need to do this conditionally, I think, so that there is an enclosing |
…racket#208. The printer for ISL, ISL+ and ASL relies on use-named/undefined-handler and named/undefined-handler to correctly print named lambdas. In particular, use-named/undefined-handler checks whether the option use-function-output-syntax is set. If use-function-output-syntax is not enabled, then during module instantiation, user-written functions like my-add1 would be printed differently. This also affects the error message from the check-expects. #lang htdp/isl+ (define (my-add1 n) (+ n 1)) my-add1 (check-expect my-add1 2) Output: Welcome to DrRacket. (lambda (a1) ...) Ran 1 test. 0 tests passed. check-expect ... error ... :: first argument of equality cannot be a function, given (lambda (a1) ...) > my-add1 my-add1
76e5360
to
c9bda14
Compare
Done! Removing source locations solves the problem. |
(htdp-err/rt-test (map (lambda (x y) (+ x y)) (list 2 3 4)) | ||
(exn-type-and-msg | ||
exn:fail:contract? | ||
#rx"intm-lam.rktl")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test has been moved to racket/drracket@4eaf30c.
Fixes #208.
The printer for ISL, ISL+ and ASL relies on
use-named/undefined-handler
andnamed/undefined-handler
to correctly print named lambdas instead of outputting(lambda (a1 a2 ...) ...)
. In particular,use-named/undefined-handler
checks whether the optionuse-function-output-syntax
is set.If use-function-output-syntax is not enabled, then during module instantiation, user-written functions like my-add1 would be printed differently. This also affects the error message from the check-expects.
Before:
This PR parameterize the
current-namespace
to the current module'snamespace during the printing process.