-
Notifications
You must be signed in to change notification settings - Fork 174
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
feat: Adds defn-
and def-
macros
#1174
Conversation
Adding these macros as a shortand for declaring a def or defn and making them `hidden` and `private`, useful to keep things internal to a module.
Thinking of adding some example of using |
Sounds great! We should add some tests for these too. |
Yeah I was thinking about the tests yesterday. Would you expect some "error message" tests? |
I’d say so! We can use the |
Added the tests a few minutes before your message. Doing docs next. |
…eGuide Trying to introduce concepts in the same order they are referred to in the examples: structs > modules > interfaces.
Took me weeks to find the time to make this simple PR but I think it's finally ready for review 😄 |
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.
I realized about halfway through that the docs I was annotating weren’t new but rearranged. My comments still hold, I think 😆
@@ -227,6 +156,88 @@ These can only be used at the REPL and during macro evaluation. Here's a subset | |||
|
|||
To see all functions available in the `Dynamic` module, enter `(info Dynamic)` at the REPL. | |||
|
|||
|
|||
### Structs | |||
Any structure type defined in Carp has an init method that can be used to create a new instance. It must be called with all the arguments in the order they are defined. |
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 we wrap init
in backticks here?
Also, maybe "in the order in which they are defined" or "in definition order" might be better?
(Right [b])) | ||
``` | ||
|
||
A Variant can be created with the same syntax as call expression: |
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.
A variant can be created through a function call
?
_ (logic-other))) | ||
``` | ||
|
||
Note that match works with *values* (not references) takes ownership over the value being matched on. If you instead want to match on a reference, you can use `match-ref`: |
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.
I think backticks around match
would be good here, and that there is an and
missing after the parentheses.
I think it would be good to use these forms in stdlib in a follow-up PR, since this could remove a lot of code and test the forms at the same time. |
The follow up PR sounds like a good idea. About the comments you've added I was thinking of making a refractor PR for the language guide, the style is not very consistent and some of it seems straight up wrong with the changes in the language since it was written, so I could put your suggested changes it that. |
Sounds like a good plan! I’ll be happy to help and/or review :) |
Once/if this is merged I'll open a draft PR with your suggested changes and we can comment on it on what we add to that. |
Looks good! The changes to the language guide is a bit hard to follow though, has anything been deleted or have things just moved around? |
Sorry the merged diff looks really messy, it's easier to follow if you go commit by commit. I moved the module and interface section after the struct section first, and then I added a section about |
@TimDeve Alright, thanks I'll do that! |
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.
@hellerve had some comments that you can choose to address, apart from that I think we're good to go!
@TimDeve Maybe you already discussed that and this should just go in as-is now? |
Yeah the comments where on existing docs so we're going to address them in a different PR. |
Great work! |
Macros introduced in carp-lang#1174
Adding these macros as a shortand for declaring a def or defn and making them
hidden
andprivate
, useful to keep things internal to a module. Similar to Clojure'sdefn-
.