-
-
Notifications
You must be signed in to change notification settings - Fork 50
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
[GSoC'21] Convenience methods for objects #356
[GSoC'21] Convenience methods for objects #356
Conversation
Codecov Report
@@ Coverage Diff @@
## master #356 +/- ##
==========================================
+ Coverage 95.99% 96.20% +0.21%
==========================================
Files 27 35 +8
Lines 1372 1449 +77
==========================================
+ Hits 1317 1394 +77
Misses 55 55
Continue to review full report at Codecov.
|
@TheCedarPrince @Wikunia I can use a review at this point :) |
@TheCedarPrince I remember us talking about what if someone wants to define some custom anonymous functions that are much detailed in functionality. Eg: the For that I have created a macro viz.
|
JShape
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.
Thanks for creating this PR @Sov-trotter I think it will simplify a lot of things in the future. Especially the JShape
is a great addition. Is it possible to maybe make that accept keyword arguments as well? For example
@JShape begin
....
end color=:black radius=20
@JLayer begin
....
end color=:black radius=20
I think you meant JShape here? 😅 Yeah. That is possible. But I am not sure how we can use those arguments inside since we just evaluate the expression inside the anonymous function. https://github.com/Wikunia/Javis.jl/pull/356/files#diff-357a561d1b0f8639d39256acccb59064e0cdde58dc13775c9d8f9e3bcefbbf01R18 A better workaround would be if the one can do something like moving those arguments in the block so that the variables can be used inside long declarations. @JShape begin
color=:black
radius=20
.........
end |
Oh yeah I meant macro JShape(body::Expr, expr)
kwargs = (; expr.args[1] = expr.args[2])
expr = quote
(args...) -> begin
esc(
for (key, value) in enumerate($kwargs)
@eval (($key) = ($value))
end
)
eval($body)
end
end
esc(expr)
end which obviously doesn't work 😄 In your case one would need to parse the vars and values out of the |
I think this should work. @JShape begin
sethue(color)
circle(radius)
line(O)
end color=:black radius=20 Is that what you have in mind? |
No. The arguments go inside the begin end block and are parsed along with the expression. So they are not essentially arguments but expressions. |
yes that's what I thought. |
But one would need to extract them to write the |
@JShape begin
sethue(color)
circle(radius)
line(O)
end color=:black radius=20
So one thing with this is that macros can't have keyword arguments, so it's not super useful to have fixed arguments(the only possible I can think of is color and action). I mean if one has longer code decrlaring variables inside the begin .. end block is much useful |
I like your way of having it inside but assumed it's harder. One can parse them as keyword arguments though, so that shouldn't be the biggest problem |
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.
Experimenting a bit with this and ODEs a bit. Have just one small request for JLine for now. I can add that myself though as well.
@TheCedarPrince that is the start of what I was telling you about
The code: https://gist.github.com/Wikunia/4ca58b4c08da90978c0dcdee5b0c908a
src/shorthands/JLine.jl
Outdated
(args...; color = color, p1 = p1, p2 = p2) -> _JLine(p1, p2, color) | ||
|
||
""" | ||
JLine(pt::Point) |
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.
the color is missing in this docstring. I would also like to have linewidth
for setline
default should be 1.
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.
Looks really great! I edited the Tutorial some to make it a bit less technical but kept the same outline and general content. Also, the only major comment I left is I would just like to see a few tests for J-Objects being used with a Layer. Otherwise, when done, I think this is ready for merging!
src/shorthands/JShape.jl
Outdated
Creates a custom shape based on the luxor instructions in the begin...end block | ||
```julia | ||
somepath1 = Object(@JShape begin | ||
sethue(color) | ||
poly(points, action, close= true) | ||
end action = :stroke color ="red" radius = 8 | ||
) | ||
``` |
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.
Could you run JuliaFormatter on the code in this example? Somehow seems a bit off to me.
Would be lovely if you could check my docstring changes and overall structural change of some methods @TheCedarPrince |
973e95c#diff-d35b42f4d138de274461c0f7ed00bfc89a3e90294bc64e30feae10a1f3ef2e84R13-R46 this is a really interesting way of using convenience functions. |
Haha yeah I really like that way to be honest. For this one it's a bit basic but can get quite handy sometimes. |
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.
Looks good to me! One thing I am curious about is if we can do something down the road similar to matplotlib
to handle the kwargs found in different functions - especially the J-Objects here (see **kwargs here: https://matplotlib.org/devdocs/api/_as_gen/matplotlib.pyplot.plot.html). I wonder if Documenter is smart enough to render documentation for a function's kwargs. I'll investigate.
Also, I was going to say that I wasn't exactly a fan of the 1., 2., etc. docstrings at first, but I think they make a lot of sense now. Especially looking at JEllipse
- it makes a lot of sense. I think this is set to merge - great work @Sov-trotter and @Wikunia !
P.S. Made a small commit to fix the docstring of the @JShape
macro.
Thanks for the review. Can you clarify a bit what you mean by the keyword argument thing? |
PR Checklist
If you are contributing to
Javis.jl
, please make sure you are able to check off each item on this list:CHANGELOG.md
with whatever changes/features I added with this PR?Project.toml
+ set an upper bound of the dependency (if applicable)?test
directory (if applicable)?Link to relevant issue(s)
Closes #313 #130 #141
How did you address these issues with this PR? What methods did you use?
For now I have implemented abstractions for basics objects like,
....
So these objects basically wrap the
(args...)->func
declarations. It would be useful to have a method for a vector of such shapes.This also has some potential in the direction of having internal flow of metadata.
For avoiding conflicts with luxor's and javis' already existing basic shapes, the methods have been named
J<SHAPE>
eg:JCircle
,JStar