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

Add match-λ[*][*]. #4989

Merged
merged 9 commits into from
May 21, 2024
Merged

Add match-λ[*][*]. #4989

merged 9 commits into from
May 21, 2024

Conversation

NoahStoryM
Copy link
Contributor

Checklist
  • Feature
  • Documentation

Description of change

This PR introduces Unicode variants of common lambda forms in Racket. A previous PR #1301 suggested similar changes but was closed. This PR revives that idea.

match-define match-define-values
match-letrec match-letrec-values
match/values match/derived match*/derived match-define-values
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the original code, match-define-values is provided twice.

@@ -200,6 +200,8 @@
(rename new-prop:procedure prop:procedure)
(rename #%app #%plain-app)
(rename lambda #%plain-lambda)
(rename λ #%plain-λ)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure if it should be (rename λ #%plain-λ) or (rename lambda #%plain-λ).

@@ -200,6 +200,8 @@
(rename new-prop:procedure prop:procedure)
(rename #%app #%plain-app)
(rename lambda #%plain-lambda)
(rename λ #%plain-λ)
(rename case-lambda case-λ)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure if case-λ should be defined in '#%kernel. I don't know how to add operators in '#%kernel, so I rename case-lambda to case-λ in pre-base.rkt.

Copy link
Collaborator

@sorawee sorawee left a comment

Choose a reason for hiding this comment

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

Changes to match-λ[*][*] is nice.

I really doubt that #%plain-λ is a good idea. No one will use #%plain-lambda anyway, since it's inferior than the regular lambda. It's only used inside the Racket internals, and also when people want to pattern match against expanded code. But in those two cases, #%plain-λ won't have much value.

My personal opinion is that this PR should be restricted to only changes in match-related form.

@@ -331,8 +331,9 @@
(append
(kernel-form-identifier-list)
(list
(quote-syntax #%app) ; racket/base app, as opposed to #%plain-app
(quote-syntax #%app) ; racket/base #%app, as opposed to #%plain-app
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please revert all changes to this file. free-identifier=? already takes renaming into account. There's no need to test against another renamed form.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This file already handles similar processes for λ, as seen in: (or (free-identifier=? #'lam #'lambda) (free-identifier=? #'lam #'λ)). I assumed the relationship between lambda and λ was similar to that between case-lambda and case-λ, which is why I treated #%plain-λ and case-λ in the same manner. If supporting case-λ is considered, do we still need to revert all changes to this file?

Copy link
Collaborator

Choose a reason for hiding this comment

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

If case-λ is created via the renaming mechanism, then free-identifier=? will work fine on it. So yes, you should still revert all changes to this file.

Apparently λ is not created via the renaming mechanism from lambda, so that's why only one free-identifier=? would not suffice.

#lang racket

(module sub racket
  (provide my-case-lambda
           (rename-out [my-case-lambda my-case-λ]))
  (define my-case-lambda 1))

(require syntax/parse/define
         'sub)

(define-syntax-parse-rule (test a b)
  #:do [(println (free-identifier=? #'a #'b))]
  (void))

(test my-case-lambda my-case-λ) ;=> #t
(test lambda λ) ;=> #f

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I read the code, and if I understand correctly, lambda and λ in racket/base are respectively new-lambda and new-λ in kw.rkt:

   (define-syntaxes (new-lambda new-λ)
     (let ([new-lambda ...])
       (values new-lambda new-lambda)))

Is it necessary to create a new PR and define new-λ through the renaming mechanism?

Copy link
Collaborator

Choose a reason for hiding this comment

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

For any big change like this (including this PR actually), I think it makes sense to get preliminary feedback from https://racket.discourse.group/ first. For example, it could be that people are somehow relying on lambda and λ not being free-identifier=? for some reasons, and the change would break their code.

But I agree that ideally lambda should be free-identifier=? to λ.

Copy link
Member

Choose a reason for hiding this comment

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

It seems unlikely that changing how lambda and λ are bound is going to work but before a discussion, just checking to see if racket (and a bunch of packages, maybe starting with main-distribution) builds would be informative.

@NoahStoryM
Copy link
Contributor Author

I really doubt that #%plain-λ is a good idea. No one will use #%plain-lambda anyway, since it's inferior than the regular lambda. It's only used inside the Racket internals, and also when people want to pattern match against expanded code. But in those two cases, #%plain-λ won't have much value.

Initially, I added the λ forms based on search results for L:racket -lambda. I have never used #%plain-lambda, so removing #%plain-λ is fine by me.

My personal opinion is that this PR should be restricted to only changes in match-related form.

case-λ is likely to be widely used, and the related code change is just a single line: (rename case-lambda case-λ). Is it necessary to split this PR? Of course, restricting this PR to only include changes to match-related forms is also acceptable to me.

@racket-discourse-github-bot

This pull request has been mentioned on Racket Discourse. There might be relevant details there:

https://racket.discourse.group/t/adding-more-unicode-forms-to-racket/2911/1

@NoahStoryM NoahStoryM changed the title Add case-λ, #%plain-λ, match-λ[*][*]. Add match-λ[*][*]. May 9, 2024
@racket-discourse-github-bot

This pull request has been mentioned on Racket Discourse. There might be relevant details there:

https://racket.discourse.group/t/renaming-mechanism-for-unicode-in-racket/2910/3

Copy link
Member

@mflatt mflatt left a comment

Choose a reason for hiding this comment

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

I think this will be ready after adding history notes to the documentation. You could also squash the commits, or I can squash when merging. Thanks!

@mflatt mflatt merged commit 9afc560 into racket:master May 21, 2024
7 checks passed
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.

None yet

6 participants