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

Rewrite rule for equal? #649

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jpellegrini
Copy link
Contributor

@jpellegrini jpellegrini commented May 30, 2024

Hi @egallesio !
Maybe this one is interesting? :)

  • If none of the arguments is constant, then keep the expression as is;
  • If one of the arguments is an eq?-comparable object, rewrite into (eq? a b)
  • If both arguments are constant, then we compute (equal? a b)

This is the result:

stklos> (disassemble-expr '(equal? a b))

000:  GLOBAL-REF-PUSH      0
002:  GLOBAL-REF           1
004:  IN-EQUAL

stklos> (disassemble-expr '(equal? a #eof))

000:  GLOBAL-REF-PUSH      0
002:  CONSTANT             1
004:  IN-EQ

stklos> (disassemble-expr '(equal? 25 #eof))

000:  IM-FALSE

And maybe the same could be done for eqv?...

- If none of the arguments is constant, then keep the expression as
  is;
- If one of the arguments is an eq?-comparable object, rewrite into
  (eq? a b)
- If both arguments are constant, then we compute (equal? a b)

This is the result:

```
stklos> (disassemble-expr '(equal? a b))

000:  GLOBAL-REF-PUSH      0
002:  GLOBAL-REF           1
004:  IN-EQUAL

stklos> (disassemble-expr '(equal? a #eof))

000:  GLOBAL-REF-PUSH      0
002:  CONSTANT             1
004:  IN-EQ

stklos> (disassemble-expr '(equal? 25 #eof))

000:  IM-FALSE
```
@jpellegrini jpellegrini changed the title Rewrite rule for equal? Rewrite rule for equal? May 30, 2024
@jpellegrini
Copy link
Contributor Author

jpellegrini commented May 31, 2024

And maybe the same could be done for eqv?...

And member, and memv, maybe?

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.

1 participant