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
Document contexts #1225
Comments
|
FWIW, I don't think the concept of contexts is as fundamental as it is in Perl 5. Even “void context” is not really a thing (it's just something returning a value nowhere). |
|
In a certain view there are as many contexts for an object as there are types that you can coerce that object to. currently all of them just call a method of the same name on the object if it isn't already of that type. There is also enum coercion, which turns a value into a value of that enum
There are 4 array argument types An itemized value doesn't flatten when using |
|
Regarding the type coercions listed above, I would say these are not actually contexts. Typically, it's an explicit coercion (+$foo, ?$bar, $baz.Str) There are some language constructs that enforce a coercion - that could be considered a context, like the expression in "if", but I would prefer "implicit coercion", as context has some baggage coming from p5. |
|
There are situations in which "implicit coercions" happen. That's the definition of "context". "Coercion" is the action, "context" is the situation that triggers it. The Perl 6 design docs and other docs use "context" frequently. From S01:
And, the search results for "context" in this repo: https://github.com/perl6/doc/search?utf8=✓&q=context But, choose your term (I will continue to call it "context"). Whatever you label it, the language recognizes some situations and does different things in those situations. No matter the label, people need to know how Perl 6 is going to act on their behalf in these situations. |
|
The concept of "context" is overloaded sightly differently between Perl 5 and Perl 6. Really, what Perl 5 calls context, is multi dispatch in Perl 6, at least for the scalar and list contexts. E.G. a subroutine can follow different code paths depending on if the passed arguments are singular or collective. That is exactly what Perl 6 multi dispatch does, it just has much finer definitions than just a single item or collection, with the ability to follow different code paths for each defined type if desired. On the other hand, when things are said to be in a certain context in Perl 6, they are usually referring to the type of object that is expected in a certain situation rather than how an object is being interpreted. It is perhaps confusing that void was lumped in as a 'context' in Perl 5 because is has a different connotation and effect than 'scalar' or 'list'. 'Sink' context in Perl 6 is very close to the meaning of 'void' context in Perl 5; both mean that values are being thrown away. Coercion is often conflated with multi dispatch ( and context ) in Perl 6 but they are actually almost opposites. Coercers convert / reinterpret one type of thing to another type. Multi dispatch put constraints on what will be accepted by a particular callable and allows for the different code paths for different type parameters. It seems to be a common point of confusion that constraints are not coercers and coercers are not constraints. Adding more confusion is the fact that many CORE operators DO have built in coercers to allow things to just DWIM. (You pay for every DWIM with a WAT somewhere else.) |
|
See also: #732 |
|
So what is the right place to put this stuff into? For |
|
@AlexDaniel Your question is answered just at the start of the ticket: "needs to have a section (somewhere) devoted just to context". |
|
@rafaelschipiura which means? https://docs.perl6.org/language/context ? This ticket is a bit stuck, I'm trying to get better directions :) As for |
|
@AlexDaniel What about expanding https://docs.perl6.org/language/typesystem#Coercion ? It should also link to the multi-dispatch explanation to say that sometimes things aren't actually coerced by signatures and instead are dispatched to different places based on type, which will look like a coercion. |
|
Would the last proposal by @rafaelschipiura be acceptable to everyone? |
|
This is the first result when you look for "sink context perl6". We should definitely have at least that one... |
Refs #114 and #1225. There are still many contexts to go, but these are the three most important. I'll also revise #1225 to close it when enough meaningful contexts done. In general, most of them will be like * context Turns the object into * if possible, throws warning. So there's not much to them...
|
I have eliminated a number of contexts that are no longer apparently in the documentation, or for which I could find no mention or reference. There's a .hash coercion for objects, but an explicit coercion does not imply a context, except the obvious one. So if there's any context I'm missing please add it to the issue. |
|
Well, there's another context to go... |
|
The only reference I can find for "iterable context" (the last item unchecked on @briandfoy's original list) is an article by @JJ linking... to this ticket. Re-closing ticket. |
#1255 As with #1223 (and #732), I find that the idea of concept of context is diffuse. I think Perl 6 needs to have a section (somewhere) devoted just to context since this is a fundamental language concept.
I don't have all the info that would need. Here are some notes I'm working on.
First, a list of words in front of context in various docs, including synopses:
Some other bugs this impacts, as I run across them:
The text was updated successfully, but these errors were encountered: