Re: Please explain this to me
In answer to "why the : between Str:D and Cool:D and why Int(Cool:D) ?" can I just point out the video I linked (or the slides) which answer both of these questions. On Wed, 12 Sep 2018 at 06:29 ToddAndMargo wrote: > On 09/11/2018 03:09 AM, ToddAndMargo wrote: > > multi method contains(Str:D: Cool:D $needle, Int(Cool:D) $pos) > > > > Okay, I know that > > Str is a string > > Cool is an object that can be treated as both a string and a number > > $needle is the second optional parameter > > > > What is "D"? > > > > $needle is optional, why is it not stated as "$needle?" > > > > How is both Str:D: and Cool:D the first parameter? > > > > Why does "Str:D:" have a colon on the end and "Cool:D" does not? > > > > What is Int(Cool:D) ? > > > > What is $pos ? > > > > Where is it stated that it has a return a value? > > > > Where is it state that the return value is a boolean? > > > > Yours in confusion, > > -T > > First off, I band the heck out of "contains" all over my code. > I know how it works. What I don't know is how the documentation > got there. > > Okay I am making progress. > > "multi method contains" means that it is a "method" (.foo). > Perl 6 has "methods" `.foo` and subroutines `sub foo(...){...}` > > "Str:D" means it reads a string Str.contains(...) and > that the string is mandatory (constrained). > > Okay, foul! > Str:D: Cool:D $needle > why is there not a comma between "Str:D:" and "Cool:D"? > And what is with the extra ":". By chance is the extra ":" > a confusing way of using a comma for a separator? > > "Cool:D $needle" means that sub string or number you are > looking for. And it is constrained. You must enter a value. > > Foul again! > Int(Cool:D) $pos > Why "Int(Cool:D)"? Why is type Int being redefined > as type "Cool" (number or any type or a string). > > $pos is the starting position to check for a match, > start at zero. > > Foul! > $pos is optional. But there is a "D" in its definition > making it constrained and not optional. > > And another foul! > There is no stating what the return value is. It > should be of single value of type Bool. > > I am getting there. Thank you all for the help. > > -T > > > > > > > > > > -- > ~~ > Computers are like air conditioners. > They malfunction when you open windows > ~~ > -- Simon Proctor Cognoscite aliquid novum cotidie
Re: Nil ?
If you don't define the type of a Scalar and don't assign to it you'll have an undefined Any (the Parent class of all the other types). If you assign Nil to it then you have the same effect. You can make $x to be Nil by iether casting it : my Nil $x; or binding it to Nil; my $x; $x := Nil; Basically Nil is special, slippery and a bit hard to catch. On Wed, 12 Sep 2018 at 06:56 ToddAndMargo wrote: > What am, I missing? > > $ p6 'my $x; if $x =:= Nil { say "Nil" } else { say "Not Nil"; };' > Not Nil > > $ p6 'my $x = Nil; if $x =:= Nil { say "Nil" } else { say "Not Nil"; };' > Not Nil > -- Simon Proctor Cognoscite aliquid novum cotidie
Re: Nil ?
Also: my $a is default(Nil); > On 12 Sep 2018, at 09:25, Simon Proctor wrote: > > If you don't define the type of a Scalar and don't assign to it you'll have > an undefined Any (the Parent class of all the other types). If you assign Nil > to it then you have the same effect. > > You can make $x to be Nil by iether casting it : my Nil $x; or binding it to > Nil; my $x; $x := Nil; > > Basically Nil is special, slippery and a bit hard to catch. > > > > On Wed, 12 Sep 2018 at 06:56 ToddAndMargo wrote: > What am, I missing? > > $ p6 'my $x; if $x =:= Nil { say "Nil" } else { say "Not Nil"; };' > Not Nil > > $ p6 'my $x = Nil; if $x =:= Nil { say "Nil" } else { say "Not Nil"; };' > Not Nil > -- > Simon Proctor > Cognoscite aliquid novum cotidie
Re: Nil ?
O learn something new everyday :) On Wed, 12 Sep 2018 at 08:46 Elizabeth Mattijsen wrote: > Also: > > my $a is default(Nil); > > > On 12 Sep 2018, at 09:25, Simon Proctor wrote: > > > > If you don't define the type of a Scalar and don't assign to it you'll > have an undefined Any (the Parent class of all the other types). If you > assign Nil to it then you have the same effect. > > > > You can make $x to be Nil by iether casting it : my Nil $x; or binding > it to Nil; my $x; $x := Nil; > > > > Basically Nil is special, slippery and a bit hard to catch. > > > > > > > > On Wed, 12 Sep 2018 at 06:56 ToddAndMargo wrote: > > What am, I missing? > > > > $ p6 'my $x; if $x =:= Nil { say "Nil" } else { say "Not Nil"; };' > > Not Nil > > > > $ p6 'my $x = Nil; if $x =:= Nil { say "Nil" } else { say "Not Nil"; };' > > Not Nil > > -- > > Simon Proctor > > Cognoscite aliquid novum cotidie > -- Simon Proctor Cognoscite aliquid novum cotidie
Re: Nil ?
When you assign Nil to a string or any object, it takes its default value. Cheers El mié., 12 sept. 2018 a las 10:23, Simon Proctor () escribió: > O learn something new everyday :) > > On Wed, 12 Sep 2018 at 08:46 Elizabeth Mattijsen wrote: > >> Also: >> >> my $a is default(Nil); >> >> > On 12 Sep 2018, at 09:25, Simon Proctor >> wrote: >> > >> > If you don't define the type of a Scalar and don't assign to it you'll >> have an undefined Any (the Parent class of all the other types). If you >> assign Nil to it then you have the same effect. >> > >> > You can make $x to be Nil by iether casting it : my Nil $x; or binding >> it to Nil; my $x; $x := Nil; >> > >> > Basically Nil is special, slippery and a bit hard to catch. >> > >> > >> > >> > On Wed, 12 Sep 2018 at 06:56 ToddAndMargo >> wrote: >> > What am, I missing? >> > >> > $ p6 'my $x; if $x =:= Nil { say "Nil" } else { say "Not Nil"; };' >> > Not Nil >> > >> > $ p6 'my $x = Nil; if $x =:= Nil { say "Nil" } else { say "Not Nil"; };' >> > Not Nil >> > -- >> > Simon Proctor >> > Cognoscite aliquid novum cotidie >> > -- > Simon Proctor > Cognoscite aliquid novum cotidie > -- JJ
Re: how do I do this index in p6?
Built-in constants: pi, tau, e, i perl6 -e 'say pi ~ " " ~ tau ~ " " ~ e ~ " " ~ i'; 3.141592653589793 6.283185307179586 2.718281828459045 0+1i (tau is 2pi, useful if you want to calculate the circumference of your tuits. Pi and tau can also be accessed as the Unicode characters. User-defined constant answer = 42; Scope is lexical: constant where = "outer"; say where; { constant where = "inner"; say where; } say where;
Re: how do I do this index in p6?
Just for giggles, say e**(i*pi) + 1 prints 0+1.2246467991473532e-16i which isn't exactly right, but close enough for government work. (You could call it really right, the error is imaginary. :-)* ) On 9/12/18, Parrot Raiser <1parr...@gmail.com> wrote: > Built-in constants: > pi, tau, e, i > > perl6 -e 'say pi ~ " " ~ tau ~ " " ~ e ~ " " ~ i'; > > 3.141592653589793 6.283185307179586 2.718281828459045 0+1i > (tau is 2pi, useful if you want to calculate the circumference of your > tuits. > Pi and tau can also be accessed as the Unicode characters. > > User-defined > constant answer = 42; > > Scope is lexical: > constant where = "outer"; > say where; { > constant where = "inner"; > say where; > } > say where; >
Re: how do I do this index in p6?
Patched :-) say (e**(i*pi)+1).round(10⁻¹²) On Wed, Sep 12, 2018 at 4:28 PM Parrot Raiser <1parr...@gmail.com> wrote: > Just for giggles, say e**(i*pi) + 1 prints 0+1.2246467991473532e-16i > which isn't exactly right, but close enough for government work. > (You could call it really right, the error is imaginary. :-)* ) > > > On 9/12/18, Parrot Raiser <1parr...@gmail.com> wrote: > > Built-in constants: > > pi, tau, e, i > > > > perl6 -e 'say pi ~ " " ~ tau ~ " " ~ e ~ " " ~ i'; > > > > 3.141592653589793 6.283185307179586 2.718281828459045 0+1i > > (tau is 2pi, useful if you want to calculate the circumference of your > > tuits. > > Pi and tau can also be accessed as the Unicode characters. > > > > User-defined > > constant answer = 42; > > > > Scope is lexical: > > constant where = "outer"; > > say where; { > > constant where = "inner"; > > say where; > > } > > say where; > > > -- Fernando Santagata
Re: how do I do this index in p6?
Neat. The answer's round about right. On 9/12/18, Fernando Santagata wrote: > Patched :-) > say (e**(i*pi)+1).round(10⁻¹²) > > On Wed, Sep 12, 2018 at 4:28 PM Parrot Raiser <1parr...@gmail.com> wrote: > >> Just for giggles, say e**(i*pi) + 1 prints 0+1.2246467991473532e-16i >> which isn't exactly right, but close enough for government work. >> (You could call it really right, the error is imaginary. :-)* ) >> >> >> On 9/12/18, Parrot Raiser <1parr...@gmail.com> wrote: >> > Built-in constants: >> > pi, tau, e, i >> > >> > perl6 -e 'say pi ~ " " ~ tau ~ " " ~ e ~ " " ~ i'; >> > >> > 3.141592653589793 6.283185307179586 2.718281828459045 0+1i >> > (tau is 2pi, useful if you want to calculate the circumference of your >> > tuits. >> > Pi and tau can also be accessed as the Unicode characters. >> > >> > User-defined >> > constant answer = 42; >> > >> > Scope is lexical: >> > constant where = "outer"; >> > say where; { >> > constant where = "inner"; >> > say where; >> > } >> > say where; >> > >> > > > -- > Fernando Santagata >
Re: Nil ?
Basically, ignore any advice to treat Nil as a normal value, because it really is intended to represent the *absence* of a value as much as possible. It's a bit like the way solid-state electronics treats "holes" as if they were real particles, and gets away with it much of the time. But not all the time, because the hole isn't real; it's the collective behavior of everything around a thing that's missing. So while you can test explicitly for Nil if you try hard enough, it's better not to try at all, because lots of places internally are using that Nil to select some kind of default behavior that might or might not look like Nil afterwards. It was probably a mistake to put Nil into the type hierarchy underneath the Any type in the first place. It's more of a concept type like Junction, so probably belongs outside of Any, which sits the top of the "normal" object hierarchy. These types are deeply magical. Whenever you find yourself trying to use Nil or Junction as a normal value, you have to ask yourself whether you're just Mickey Mouse falling into the Sorcerer's Apprentice trap. Unless you're a wizard, with Nil and Junction it's better to cargo cult a few common usages and stay the heck away the rest of the time. Larry
Re: Please explain this to me
On Tue, Sep 11, 2018 at 10:28:27PM -0700, ToddAndMargo wrote: : Okay, foul! :Str:D: Cool:D $needle : why is there not a comma between "Str:D:" and "Cool:D"? : And what is with the extra ":". By chance is the extra ":" : a confusing way of using a comma for a separator? Well, "confusing" is kind of a value judgement, but yes, that is precisely how the parser is parsing it, as a funny-looking kind of comma. You could write it "Str:D :" with a space and it would still work. You can't just replace any old comma with a colon though. Replacing the comma with a colon is only allowed on the first argument, since we can have only one invocant for the current object. And in fact we MUST have an invocant in a method, so if you accidentally put comma instead of colon, the parser will assume you left the invocant out, and that the first argument is really the second argument. Arguably this is "confusing" if you don't know it's going to happen, but it's a great convenience for the vast majority of methods that don't care about the invocant, and where the user will just refer to the invocant as "self" if they do want to talk about it. : "Cool:D $needle" means that sub string or number you are : looking for. And it is constrained. You must enter a value. : : Foul again! :Int(Cool:D) $pos : Why "Int(Cool:D)"? Why is type Int being redefined : as type "Cool" (number or any type or a string). That is the wrong direction to think about it. Int is not being redefined as Cool:D there. The basic type there is just Int, and when the $pos comes in, it will end up being a simple Int. This syntax is called a "coercion type", and it just says that we can also accept anything that matches Cool:D and turn it into an Int. But the inside of the method knows nothing about the Cool:D part. Think of Int(Cool:D) as the signature matcher automatically applying the normal Int($coolthing) coercer for you to make sure you have an Int, precisely so that you *don't* have to worry about the Cool:D part inside the routine, but know that it simply an Int for any part of the routine after the signature. : $pos is the starting position to check for a match, : start at zero. : : Foul! : $pos is optional. But there is a "D" in its definition : making it constrained and not optional. No, that D is not part of its definition, which is simply Int. The D is part of the coercion type's signature. The coercion is only applied if there actually an argument passed. So Int(Cool:D) is allowed to default to an undefine Int to indicate no value was passed. You'd have to write Int:D(Cool) to mean the other thing, and then yes, it couldn't be optional. : And another foul! : There is no stating what the return value is. It : should be of single value of type Bool. Indeed, the signature should include --> Bool to indicate that. Larry
Re: Functions and subroutines?
> they were all just subs. With perl5 code, I've gravitated to talking about "routines" when I don't want to worry about whether something is technically a function or a method. It doesn't seem to confuse anyone. (On the other hand, I've had people make fun of me for using the word "subroutine", because it sounds too much like jargon from Basic... CS snobbery has been around for quite some time.) With perl6, I find myself stumbling over what to call the built-ins... "functions", "commands", "keywords"? On Tue, Sep 11, 2018 at 10:40 AM, Trey Harris wrote: > To get directly at your question: in Perl 6, this is not an important > delineation, so there are no simple names for the two Pascal/Modula > concepts. Perl's never made a distinction between "procedures" and > "functions" in the Pascal sense; they were all just subs. Eventually Perl > gained classes and blessed objects and so we got "methods", but in Perl 5 > they were just gussied-up subs. > > The delineations that matter in Perl 6 are subs vs. methods vs. blocks (as > yary and Simon have said previously in the thread). > > Perl allows you to do very naughty things, such as define a method that > modifies its invocant, some of its parameters, returns a result that can > indicate a failure, and throws exceptions. Doing all these things is > allowed but would almost certainly be quite unwise. But when you try to > find the 1:1 mapping of some other language's construct to another's, you > always get one of four answers: > > 1. There is a thing exactly like the other language's thing at the same > level of complexity using similar syntax and semantics. > 2. There is a analogous thing in semantics, but it's not very similar in > syntax. > 3. There is a thing that's similar in syntax, but very different in > semantics. > 4. There is no thing like the other language's thing in syntax or > semantics. > > The issue you get into in Perl 6 is that it's _such_ a flexible language > that it pretty much never says number 4. It usually says both 2 and 3. The > old joke went that you could write FORTRAN in any language. Well, you can > write any language in Perl 6. That doesn't mean it's a good idea. > > My suggestion would be: if you call it with a dot, it's a method. If you > don't, it's a sub. Whether a sub returns something or not should be obvious > from the purpose and how you name it. Whether a sub alters something or not > should also be obvious from how you call it. The signatures are different, > but the names don't matter. > > On Tue, Sep 11, 2018 at 11:31 Simon Proctor > wrote: > >> There are also Blocks like : my $a = do { 5 }; say $a; (Gives 5); >> >> Blocks turn up all over the place big different between blocks and >> Routines (Sub or Method) is you can't return from them. They will return >> the last thing evaluated within them though. But a return statement inside >> one raises and Expection. (Might be a Failure)... >> >> On Tue, 11 Sep 2018 at 16:24 yary wrote: >> >>> And looking at questions in other threads- there are subroutines >>> declared with "sub", those get called without an invocant. >>> >>> sub i-am-a-sub() { say "Hi from subroutine land!" } >>> >>> i-am-a-sub; # says "Hi from subroutine land!" >>> >>> and methods are declared inside a class, and are called with an invocant >>> of that class type. >>> >>> class sample-class { >>> method speak-to-me {say "We are classy"} >>> } >>> my sample-class $object; >>> $object. speak-to-me; # Guess what it says >>> >>> ... subroutines and methods, in the perl6 class hierarchy, are both >>> subclasses "Routine" >>> maybe that's the word your looking for! >>> >>> -y >>> >>> On Tue, Sep 11, 2018 at 8:12 AM, yary wrote: >>> I would call them subroutines, since that's the long form of "sub" -y On Tue, Sep 11, 2018 at 3:47 AM, ToddAndMargo wrote: > Hi All, > > I use subs like ducks use water. It is about time > I learned what to properly call them. > > I come from Modula2 and Pascal (as well as bash), "functions" > return a value outside the declared parameters and "(sub)routines" > only can modify values through the declarations parameters. > > Sort of like > function: sub add($a, $b){return $a+$b} > routine:sub add($a, $b, rw $c){$c = $a+$b} > > In Perl, what is the proper terminology? > > Many thanks, > -T > > I no longer use "rw $c". I always use "return". > The guys told me this was the best way on the > chat line, so I adopted it. > >>> -- >> Simon Proctor >> Cognoscite aliquid novum cotidie >> >
Re: Functions and subroutines?
> On 12 Sep 2018, at 22:56, Joseph Brenner wrote: > With perl6, I find myself stumbling over what to call the built-ins... > "functions", "commands", "keywords”? perhaps “builtins"? Liz
Re: A comparison between P5 docs and p6 docs
The signatures in the docs are often the exact same signatures as the code they are documenting. > Str.^lookup('contains').candidates.map: *.signature.say (Str:D: Cool:D $needle, *%_) (Str:D: Str:D $needle, *%_) (Str:D: Cool:D $needle, Cool:D $pos, *%_) (Str:D: Str:D $needle, Int:D $pos, *%_) So the name of the positional parameters tend to be whatever the person who wrote the code decided to call them. If you have a better idea, you could create an issue or pull-request. --- The real problem is that someone has to be able to see it from the beginner's perspective, but also has to know how it actually works. They also have to have the time and ambition to go through them. If you create a detailed issue, or pull-request, at least people will know where their work is needed. --- There have been cases where documenting something lead to the discovery of a bug in the implementation. On Tue, Sep 11, 2018 at 7:05 PM ToddAndMargo wrote: > > On 09/11/2018 08:17 AM, Laurent Rosenfeld via perl6-users wrote: > > Hi Todd, > > > > I fully agree with Tom B.'s message that you should really set out to > > read a Perl 6 book. Many of the things you asked are covered in most of > > the available books. And the available books are easier than the > > official documentation for a beginner to start understand the basic > > underlying concepts. > > > > I should add that you don't even have to /buy/ one book, since my own > > /Think Perl 6/ book is freely available on the Internet (Creative > > Commons license): https://greenteapress.com/wp/think-perl-6/. Well, if > > you are interested in reading it, I'd suggest you look for the PDF on my > > Github repository > > (https://github.com/LaurentRosenfeld/thinkperl6/tree/master/PDF), > > because it is more up-to-date (number of small corrections made > > following comments from readers). > > > > So it would take you just a few minutes (at no cost) to download it and > > start enjoying it. > > > > Cheers, > > Laurent. > > > Hi Laurent, > > Ordinarily I would agree with you. But I know my own brain and > how it works. I only learn by doing. Have tried to change that > and can't. > > When I "dive in", I open up the reference docs and bang away. > I also use Google, but that is next to useless in Perl 6 as Perl 5 > hits drowned Perl 6 out. > > I am 62 years old, have a bachelors degree in Electronic and > Computer Engineering, Cum Laude and have been programming > things all my life. I live with the reference page open > while pounding out code. > > Perl 6's document are next to useless for me. This is the first > time I have come across references that were so badly done. > And programming of the Automated Test Equipment I did > had some documents to behold. CP-M was not fun either. > > Do not misunderstand, I ADORE Perl 6. It is a wonderful clean > up of Perl 5, especially the subroutine definitions and regex's. > The only step backward is the docs. > > The developers have their own specification/documentation. > The reference docs need to be written for the rest of us. > > By the way, I never mastered Perl 5's regex's. I used them, > but could never figure out exactly what I did. In Perl 6 > I now can throw them together off the top of my head. It > is kind of fun. > > -T > > -- > ~~ > Computers are like air conditioners. > They malfunction when you open windows > ~~
Re: A comparison between P5 docs and p6 docs
Ordinarily I would agree with you. But I know my own brain and how it works. I only learn by doing. Have tried to change that and can't. A good tutorial book *will* make you "do." The brian d foy book does exactly that with things to try, and questions to explore in your own code. It takes you on a structured, pre-thought-out journey through the concepts and features in an optimal order.