Content-Length: 375466 | pFad | http://github.com/sicmutils/sicmutils/pull/391

31 Replace numsymb with pattern matching versions [in progress] by adamhaber · Pull Request #391 · sicmutils/sicmutils · GitHub
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

Replace numsymb with pattern matching versions [in progress] #391

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

adamhaber
Copy link
Contributor

Addresses sicmutils/placeholder#70 . Currently, the pattern-matching versions of numsymb live in a different namespace numsymb-rules. Only tan, atan, gcd and not are currently implemented - thought it would be good to ask for feedback in an initial stage to make sure I'm doing this right.

Very basic testing throughout the code, presumably these should go somewhere in the /test/sicmutils folder?

Copy link
Member

@sritchie sritchie left a comment

Choose a reason for hiding this comment

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

Nice start!

src/sicmutils/numsymb-rules Outdated Show resolved Hide resolved
src/sicmutils/numsymb-rules Outdated Show resolved Hide resolved
negation of `x`. For boolean `x`, returns the negation of `x`."
[x]
(let [RS (r/ruleset
(? ?x true?) r/=> false
Copy link
Member

Choose a reason for hiding this comment

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

I would import => directly so you don't need the slash. If you are matching a literal you can do true => false, or you can write (? ?x boolean?) => (: #(not (% '?x))), I believe.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

do you mean (? #(not (% '?x))) (? instead of :) ?

?x r/=> (not ?x))]
(RS x)))

;; basic tests - these should probavbly live elsewhere?
Copy link
Member

Choose a reason for hiding this comment

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

see the convention for other namespaces. Put these in tests, same namespace with -test appended.

(RS x)))

;; basic tests - these should probavbly live elsewhere?
(let [v [true false 1 0 'a '() ()]]
Copy link
Member

Choose a reason for hiding this comment

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

(doseq [v ...]
  (is (= (sym:not v) ((sym/symbolic-operator 'not) v))))

(? ?x n:pi-over-4-mod-pi?) r/=> 1
(? ?x n:-pi-over-4-mod-pi?) r/=> -1
(? ?x n:pi-over-2-mod-pi?) r/=> (u/illegal "Undefined: tan")
(? ?x v/number?) r/=> (?? #(Math/tan (% '?x)))
Copy link
Member

Choose a reason for hiding this comment

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

single ? , not ??, since you are not splicing in a result

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 a little confused by the difference; is ?? used for binding collections, whereas ? is for binding "single" variables?

src/sicmutils/numsymb-rules Outdated Show resolved Hide resolved
@sritchie sritchie force-pushed the main branch 3 times, most recently from afa6dd7 to c33ef42 Compare February 15, 2022 22:57
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.

2 participants








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/sicmutils/sicmutils/pull/391

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy