Re: I need help with IO.e
On 2020-05-18 17:14, Peter Pentchev wrote: On Mon, May 18, 2020 at 04:53:31PM -0700, ToddAndMargo via perl6-users wrote: In 2020-05-18 16:11, Peter Pentchev wrote: As an exercise for the reader: once the above sinks in, what exactly will "say if 'h:/'.IO.d" do? It returns the the result of the expression that "if" evaluated. OK, so why does it give you an error message if you run it? :) Not quite. say if 'h:/'.IO.d ...is equivalent to: if 'h:/'.IO.d { say; } which would have been valid in Perl (apart from the parentheses around the condition of the "if", Raku allows you to omit those), but it is not valid Raku. Run it and see what it says. Once again you thought that "if" returns a value. "If" does not return a value, it is not a function, it is a statement. Just the same as "for" does not return a value, and "while" does not return a value. G'luck, Peter Hi Peter, Of course! I am not arguing with anyone that they are not right! I am doing what I am doing to make things easier for me to read in the future. Since I am already using a very high level language, what is one more affront to my CPU? :-) -T
Re: I need help with IO.e
On Mon, May 18, 2020 at 04:53:31PM -0700, ToddAndMargo via perl6-users wrote: > In 2020-05-18 16:11, Peter Pentchev wrote: > > As an exercise for the reader: once the above sinks in, what exactly > > will "say if 'h:/'.IO.d" do? > > It returns the the result of the expression that > "if" evaluated. OK, so why does it give you an error message if you run it? :) Not quite. say if 'h:/'.IO.d ...is equivalent to: if 'h:/'.IO.d { say; } which would have been valid in Perl (apart from the parentheses around the condition of the "if", Raku allows you to omit those), but it is not valid Raku. Run it and see what it says. Once again you thought that "if" returns a value. "If" does not return a value, it is not a function, it is a statement. Just the same as "for" does not return a value, and "while" does not return a value. G'luck, Peter -- Peter Pentchev r...@ringlet.net r...@debian.org p...@storpool.com PGP key:http://people.FreeBSD.org/~roam/roam.key.asc Key fingerprint 2EE7 A7A5 17FC 124C F115 C354 651E EFB0 2527 DF13 signature.asc Description: PGP signature
Re: I need help with IO.e
In 2020-05-18 16:11, Peter Pentchev wrote: As an exercise for the reader: once the above sinks in, what exactly will "say if 'h:/'.IO.d" do? It returns the the result of the expression that "if" evaluated. I do know all this. It is easier for me to read the other way.
Re: I need help with IO.e
On 2020-05-18 16:01, Tom Browder wrote: Since you don't like to listen to advice I give up. Tom! I listen to your advice ALL-THE-TIME. I was just interested in something else. And when I did not understand the result, your way or my way, I abandoned the effort, especially since I did not need the information. It was just a curiosity. Don't for a second think I do not value your advice! -T
Re: I need help with IO.e
On Mon, May 18, 2020 at 03:51:30PM -0700, ToddAndMargo via perl6-users wrote: > On 2020-05-18 15:44, Tom Browder wrote: > > On Mon, May 18, 2020 at 16:19 ToddAndMargo via perl6-users > > mailto:perl6-users@perl.org>> wrote: > > > > On 2020-05-18 13:28, Tom Browder wrote: > > > > ... > > > > > Try: > > > > > > 'say so "test".IO.d' > > > > > > Todd, you didn't try what I suggested. Once again, look a the line above^^ > > > > There is no "if" there. > > > > -Tom > > > > It was the "if" I was interested in. "if" has to change > a True or "useless text message" into a True or False. No, that's not what "if" does. "If" in Raku works pretty much the same way as "if" in Perl: it takes an expression as an argument, checks whether the expression is true or false (that's the part where it takes any value and does a .Bool on it - by itself - and then looks at the result), and then, if it was true, the "if" statement runs another part of the code. So: if 'h:/'.IO.d { say 'It is a directory!'; } ...will take the string 'h:/', the .IO method will convert it to a path, the .d method will check whether the path corresponds to a valid directory at this moment, and then the "if" statement will check the result of this whole thing and decide whether to run the { say... } block. If the path is a directory, it will tell you that it is a directory. If the expression is true, it runs the code. The postfix "if" also works in pretty much the same way as in Perl: it allows you to shorten this: if 'h:/'.IO.d { say 'It is a directory!'; } ...to this: say 'It is a directory!' if 'h:/'.IO.d; Now you will note that in my example I did *not* write "say if 'h:/'.IO.d", because I did not expect the "if" to return a value; I wrote "say 'foo' if 'h:/'.IO.d" since I expected the "if" statement to make Raku check whether 'h:/'.IO.d returns something that looks like truth and, if it does, to execute the "say 'foo'" part. I'm sorry, I assumed that you were familiar with the postfix "if" form (something if something-else). Maybe you did not recognize it as such, sorry. As an exercise for the reader: once the above sinks in, what exactly will "say if 'h:/'.IO.d" do? :) G'luck, Peter -- Peter Pentchev r...@ringlet.net r...@debian.org p...@storpool.com PGP key:http://people.FreeBSD.org/~roam/roam.key.asc Key fingerprint 2EE7 A7A5 17FC 124C F115 C354 651E EFB0 2527 DF13 signature.asc Description: PGP signature
Re: I need help with IO.e
On Mon, May 18, 2020 at 17:51 ToddAndMargo via perl6-users < perl6-users@perl.org> wrote: > On 2020-05-18 15:44, Tom Browder wrote: > > On Mon, May 18, 2020 at 16:19 ToddAndMargo via perl6-users > > mailto:perl6-users@perl.org>> wrote: > > > > On 2020-05-18 13:28, Tom Browder wrote: > > > > ... > > > > > Try: > > > > > > 'say so "test".IO.d' > > > > > > Todd, you didn't try what I suggested. Once again, look a the line > above^^ > > > > There is no "if" there. > > > > -Tom > > > > It was the "if" I was interested in. "if" has to change > a True or "useless text message" into a True or False. Since you don't like to listen to advice I give up. The 'so' I was taught by lizmat (or some other expert) a long time ago does the pretty much the same thing execpt it makes a valid statement, whereas I'm not sure the other way does (hard to read your emails with all the superflous output).
Re: I need help with IO.e
On 2020-05-18 15:44, Tom Browder wrote: On Mon, May 18, 2020 at 16:19 ToddAndMargo via perl6-users mailto:perl6-users@perl.org>> wrote: On 2020-05-18 13:28, Tom Browder wrote: ... > Try: > > 'say so "test".IO.d' Todd, you didn't try what I suggested. Once again, look a the line above^^ There is no "if" there. -Tom It was the "if" I was interested in. "if" has to change a True or "useless text message" into a True or False. Anyway, since I don't understand anything that came back, I am going to give up. And besides, any extra work I am giving the compiler with my coercing a Bool into a Bool so I don't remember which IO.someletter give back an actual Boolean and which ones don't, is SWAMPED by my use of a high level language. This is not Assembly.
Re: Different return values with "say" vs "put" (Nil representation... )
On Mon, May 18, 2020 at 10:18 AM Brad Gilbert wrote: > > You are misunderstanding what `put` does. > > It does not print the internal representation. > > What it does do is turn the value into a `Str` object, then print it with a > trailing newline. > > It just so happens that objects will by default return something that looks > like an internal representation when you coerce it to a `Str`. > > class Point { > has ($.x, $.y); > } > put Point.new( x => 1, y => 2 ).Str > # Point<94102525076384> > > put Point.new( x => 1, y => 2 ).gist > # Point.new(x => 1, y => 2) > > put Point.new( x => 1, y => 2 ).raku > # Point.new(x => 1, y => 2) > > Unless they have a `.Str` method that returns something more sensible. > > class Point { > has ($.x, $.y); > method Str () { > "[$!x,$!y]" > } > } > put Point.new( x => 1, y => 2 ).Str > # [1,2] > > put Point.new( x => 1, y => 2 ).gist > # Point.new(x => 1, y => 2) > > put Point.new( x => 1, y => 2 ).raku > # Point.new(x => 1, y => 2) > > Note that the default of `.gist` is do the same thing as calling `.raku`. > (Many/Most built-in objects have a `.gist` method that returns something > different.) > > --- > > `s///` and `S///` are both intended as working on `Str` objects. So when you > give them something that is not a `Str`, they turn it into a `Str` first. > Actually all operations that are `Str` operations will turn it into a `Str` > first. > Like `.starts-with`, `.ends-with`, `.chars`, `.codes`, `.index`, `.substr`, > `print`, and `put` > > What `say` does, is that instead of calling `.Str` it calls `.gist` > > `.gist` is defined as giving enough information for a human to be able to > figure out what object was printed. > (Which is why the default is to return the same thing as `.raku` for defined > objects) > > Actually almost all operations are intended for one type of object, and will > coerce to that type. > > > say ['a', 'b', 'c'] + %( d => 10, e => 20 ) > 5 > > --- > > Many objects will throw an error if you call `.Str` on them when they are > undefined. > > > Bool.Str > Use of uninitialized value of type Bool in string context. > Methods .^name, .raku, .gist, or .say can be used to stringify it to > something meaningful. > in block at line 1 > > > Nil.Str > Use of Nil in string context > in block at line 1 > > Which means they also throw an error if you try to use one of the methods > intended for `Str` objects on them. > > > Bool.substr(0,1) > Use of uninitialized value of type Bool in string context. > Methods .^name, .raku, .gist, or .say can be used to stringify it to > something meaningful. > in block at line 1 > > > Bool.^name.substr(0,1) > B > > The reason for it generating an error is that generally when you try to turn > an undefined object into a Str, there is likely a bug somewhere. > > --- > > Since `.gist` is for a human, it doesn't matter if the returned value is a > little wrong, so it doesn't fail. > (A human can notice if something is wrong. A program that only does what you > told it to, generally doesn't.) > > > Bool.gist > (Bool) > > Note that the reason it puts ( and ) around the name of the object is so that > you know that you might have a problem somewhere in your code. > > --- > > Further, Nil is actually the most basic of the Failure objects. > > > for Failure.^mro { say .^name } > Failure > Nil > Cool > Any > Mu > > If you get a Nil, there is probably some sort of failure somewhere. > > > say ( 1, 2, 3, 4 ).first( 'one' ) > Nil > > Which means that if you try to use a Nil as a Str, there is definitely a bug > in your code. > Thank you very much, Brad. --Bill.
Re: Different return values with "say" vs "put" (Nil representation... )
On Mon, May 18, 2020 at 4:03 AM Patrick R. Michaud wrote: > > "say $x" is essentially equivalent to "put $x.gist". > > Since Nil is undefined (roughly equivalent to a type object), Nil.gist has a > string value of "Nil" and can be printed. However, attempting to convert Nil > directly into a Str throws an error because that's attempting to stringify an > undefined object. > > You can see this with the following: > > $ rakudo > To exit type 'exit' or '^D' > > say Nil > Nil > > put Nil > Use of Nil in string context > in block at line 1 > > say Nil.Str > Use of Nil in string context > in block at line 1 > > put Nil.gist > Nil > > So, the difference in your example is that when the result of s/.../.../ is > Nil (representing a failed Match), C calls .gist on Nil which produces a > printable string, while C attempts to stringify the Nil object directly > and that throws an error. > > Pm > Thank you very much, Patrick. --Bill.
Re: I need help with IO.e
On Mon, May 18, 2020 at 16:19 ToddAndMargo via perl6-users < perl6-users@perl.org> wrote: > On 2020-05-18 13:28, Tom Browder wrote: ... > > Try: > > > > 'say so "test".IO.d' Todd, you didn't try what I suggested. Once again, look a the line above^^ There is no "if" there. -Tom
Re: I need help with IO.e
On 2020-05-18 15:38, Peter Pentchev wrote: On Mon, May 18, 2020 at 03:18:26PM -0700, ToddAndMargo via perl6-users wrote: On 2020-05-18 14:35, Peter Pentchev wrote: My point is that you put a bare "say" without telling it*what* to say, which does something quite specific in both Perl and Raku. That should, at least, explain the error-like message. G'luck, Peter What I was after was to see what impact I had coercing a Bool to a Bool verses coercing a half a Bool and unless text message to a Bool. [snip another explanation of why you use .Bool, which I already said that I am not commenting on; my point is something entirely different] All I was trying to say was to explain that "say if something" and "say 'foo' if something" do different things, to answer your question from a previous message why "say if something" told you something about undefined values. That's all I was trying to help you with :) G'luck, Peter I got it. I was only rambling on. I tend to do that.
Re: I need help with IO.e
On Mon, May 18, 2020 at 03:18:26PM -0700, ToddAndMargo via perl6-users wrote: > On 2020-05-18 14:35, Peter Pentchev wrote: > > My point is that you put a bare "say" without telling it*what* to say, > > which does something quite specific in both Perl and Raku. That should, > > at least, explain the error-like message. > > > > G'luck, > > Peter > > What I was after was to see what impact I had coercing a > Bool to a Bool verses coercing a half a Bool and unless > text message to a Bool. [snip another explanation of why you use .Bool, which I already said that I am not commenting on; my point is something entirely different] All I was trying to say was to explain that "say if something" and "say 'foo' if something" do different things, to answer your question from a previous message why "say if something" told you something about undefined values. That's all I was trying to help you with :) G'luck, Peter -- Peter Pentchev r...@ringlet.net r...@debian.org p...@storpool.com PGP key:http://people.FreeBSD.org/~roam/roam.key.asc Key fingerprint 2EE7 A7A5 17FC 124C F115 C354 651E EFB0 2527 DF13 signature.asc Description: PGP signature
Re: I need help with IO.e
On 2020-05-18 14:35, Peter Pentchev wrote: My point is that you put a bare "say" without telling it*what* to say, which does something quite specific in both Perl and Raku. That should, at least, explain the error-like message. G'luck, Peter What I was after was to see what impact I had coercing a Bool to a Bool verses coercing a half a Bool and unless text message to a Bool. But, you know, I am using a (very) high lever language for a reason. I can get to the final product twice as fast. If I wanted to optimize the use of my CPU, I would program in C, or if I was REALLY masochistic, I program in Assembly. (Done that, don't want to do it again!) So my little coercing Bool to Bool so I do not have to remember which IO.soemletter is or is not returning an actual Boolean is a mute point. I am already wasting a ton of CPU by being in a high level language to start with. And I don't care. My computer is a bazillion times more powerful than any thing I waste on a high level language. It hardly notices my "indiscretion" An gee wiz, Raku is a TON more human readable than C, which gives me a migraine if I stare at it too long. Raku is far more maintainable. But that is just my opinion
Re: I need help with IO.e
On Mon, May 18, 2020 at 02:32:49PM -0700, ToddAndMargo via perl6-users wrote: > On 2020-05-18 14:22, Peter Pentchev wrote: > > Please note that in my example a couple of messages ago I did not write > > "say if 'h:/'.IO.d", I wrote "say 'yes' if 'h:/'.IO.d". The difference > > is very important and leads directly to the error-like message you got. > > > Hi Peter, > > I as interested in the .d difference, so I put that > in instead. > > But it does not matter. I can't tell what I am looking at > so it does not matter anyway My point is that you put a bare "say" without telling it *what* to say, which does something quite specific in both Perl and Raku. That should, at least, explain the error-like message. G'luck, Peter -- Peter Pentchev r...@ringlet.net r...@debian.org p...@storpool.com PGP key:http://people.FreeBSD.org/~roam/roam.key.asc Key fingerprint 2EE7 A7A5 17FC 124C F115 C354 651E EFB0 2527 DF13 signature.asc Description: PGP signature
Re: I need help with IO.e
On 2020-05-18 14:22, Peter Pentchev wrote: Please note that in my example a couple of messages ago I did not write "say if 'h:/'.IO.d", I wrote "say 'yes' if 'h:/'.IO.d". The difference is very important and leads directly to the error-like message you got. Hi Peter, I as interested in the .d difference, so I put that in instead. But it does not matter. I can't tell what I am looking at so it does not matter anyway Thank you for all the wonderful help! -T
Re: I need help with IO.e
On Tue, May 19, 2020 at 12:22:55AM +0300, Peter Pentchev wrote: > On Mon, May 18, 2020 at 12:35:47PM -0700, ToddAndMargo via perl6-users wrote: > > On 2020-05-17 22:28, Paul Procacci wrote: > > > Don't 'say' anything. Just let the optimizer spit out the QAST that you > > > are interested in looking at. > > > The following spits out a diff after optimization: > > > > > > # diff -u <(perl6 --target=optimize -e '"test".IO.e') <(perl6 > > > --target=optimize -e '"test".IO.e.Bool') > > > > > > >> Huh. Not sure what I am looking at > > > > > > You aren't specific. Is it the error message you received because you > > > used 'say' improperly or is it the QAST? > > > - How to use 'say' is in the documentation. > > > - A QAST is pretty close to an AST and I'd start there on wikipedia or > > > something. > > > > I was looking for the difference between > > > > 'say if "test".IO.d', and > > Please note that in my example a couple of messages ago I did not write > "say if 'h:/'.IO.d", I wrote "say 'yes' if 'h:/'.IO.d". The difference > is very important and leads directly to the error-like message you got. > > > 'say "test".IO.d.Bool' > > > > This is were 'if" has to unscramble a "True" or > > "text message" return. > > > > But, I have no idea what all that stuff is that comes > > back anyway, so I think I will give up. > > It's the internal representation of the program you told Raku to parse > and execute; the truth is that, just like in a sci-fi story about > a machine that is supposed to answer any question, but only comes back > with "the question has not been asked correctly", ... In case anybody is curious, http://www.gutenberg.org/cache/epub/33854/pg33854.txt G'luck, Peter -- Peter Pentchev r...@ringlet.net r...@debian.org p...@storpool.com PGP key:http://people.FreeBSD.org/~roam/roam.key.asc Key fingerprint 2EE7 A7A5 17FC 124C F115 C354 651E EFB0 2527 DF13 signature.asc Description: PGP signature
Re: I need help with IO.e
On Mon, May 18, 2020 at 12:35:47PM -0700, ToddAndMargo via perl6-users wrote: > On 2020-05-17 22:28, Paul Procacci wrote: > > Don't 'say' anything. Just let the optimizer spit out the QAST that you > > are interested in looking at. > > The following spits out a diff after optimization: > > > > # diff -u <(perl6 --target=optimize -e '"test".IO.e') <(perl6 > > --target=optimize -e '"test".IO.e.Bool') > > > > >> Huh. Not sure what I am looking at > > > > You aren't specific. Is it the error message you received because you > > used 'say' improperly or is it the QAST? > > - How to use 'say' is in the documentation. > > - A QAST is pretty close to an AST and I'd start there on wikipedia or > > something. > > I was looking for the difference between > > 'say if "test".IO.d', and Please note that in my example a couple of messages ago I did not write "say if 'h:/'.IO.d", I wrote "say 'yes' if 'h:/'.IO.d". The difference is very important and leads directly to the error-like message you got. > 'say "test".IO.d.Bool' > > This is were 'if" has to unscramble a "True" or > "text message" return. > > But, I have no idea what all that stuff is that comes > back anyway, so I think I will give up. It's the internal representation of the program you told Raku to parse and execute; the truth is that, just like in a sci-fi story about a machine that is supposed to answer any question, but only comes back with "the question has not been asked correctly", and just as with using low-level debugging tools like strace on Unix-like systems, to ask the right question one already needs to know most of the answer. The QAST is most useful to those who already have some idea how a compiler generally works, how a pseudocode virtual machine works, how a just-in-time compiler works, and how they all handle different expressions and the relationships between different types. G'luck, Peter -- -- Peter Pentchev r...@ringlet.net r...@debian.org p...@storpool.com PGP key:http://people.FreeBSD.org/~roam/roam.key.asc Key fingerprint 2EE7 A7A5 17FC 124C F115 C354 651E EFB0 2527 DF13 signature.asc Description: PGP signature
Re: I need help with IO.e
On 2020-05-18 13:28, Tom Browder wrote: On Mon, May 18, 2020 at 14:36 ToddAndMargo via perl6-users mailto:perl6-users@perl.org>> wrote: On 2020-05-17 22:28, Paul Procacci wrote: ... 'say if "test".IO.d', and 'say "test".IO.d.Bool' Try: 'say so "test".IO.d' I have mo clue that this says $ diff -u <(perl6 --target=optimize -e 'so if "test".IO.d') <(perl6 --target=optimize -e 'so "test".IO.d.Bool') ===SORRY!=== Error while compiling -e Undeclared routine: if used at line 1 WARNINGS for -e: Useless use of "so " in expression "so \"test\".IO.d.Bool" in sink context (line 1) --- /dev/fd/63 2020-05-18 14:17:32.731286061 -0700 +++ /dev/fd/62 2020-05-18 14:17:32.732286043 -0700 @@ -0,0 +1,98 @@ +- QAST::CompUnit :W :UNIT :CAN_LOWER_TOPIC + [pre_deserialize] +- QAST::Stmt + - QAST::Stmt +- QAST::Op(loadbytecode) + - QAST::VM +[moar] + - QAST::SVal(ModuleLoader.moarvm) +[jvm] + - QAST::SVal(ModuleLoader.class) +[js] + - QAST::SVal(ModuleLoader) +- QAST::Op(callmethod load_module) + - QAST::Op(gethllsym) +- QAST::SVal(nqp) +- QAST::SVal(ModuleLoader) + - QAST::SVal(Perl6::ModuleLoader) + - QAST::Op(forceouterctx) +- QAST::BVal(2) +- QAST::Op(callmethod load_setting) + - QAST::Op(getcurhllsym) +- QAST::SVal(ModuleLoader) + - QAST::SVal(CORE.d) + [post_deserialize] +- QAST::Stmts + - QAST::Op(bind) +- QAST::Var(attribute $!do) + - QAST::WVal(Block) + - QAST::WVal(Code) +- QAST::BVal(1) +- QAST::Op(bindcurhllsym) + - QAST::SVal(GLOBAL) + - QAST::WVal(GLOBAL) + [load] +- QAST::Op(call) + - QAST::BVal(2) + [children] +- QAST::Block(:cuid(2)) :in_stmt_mod so \"test\".IO.d.Bool +│ - QAST::Var(local __args__ :decl(param)) +│ - QAST::Stmts so \"test\".IO.d.Bool +│ - QAST::Op(call) +│ - QAST::Block(:cuid(1) :blocktype(declaration_static)) :outer :in_stmt_mod :code_object :IN_DECL +│ │ - QAST::Stmts so \"test\".IO.d.Bool +│ │ - QAST::Var(lexical $¢ :decl(contvar)) +│ │ - QAST::Var(lexical $! :decl(contvar)) +│ │ - QAST::Var(lexical $/ :decl(contvar)) +│ │ - QAST::Op(null) +│ │ - QAST::Var(lexical GLOBALish :decl(static)) +│ │ - QAST::Var(lexical EXPORT :decl(static)) +│ │ - QAST::Var(lexical $?PACKAGE :decl(static)) +│ │ - QAST::Var(lexical ::?PACKAGE :decl(static)) +│ │ - QAST::Var(lexical $=finish :decl(static)) +│ │ - QAST::Var(lexical $=pod :decl(static)) +│ │ [value] +│ │ - +│ │ - QAST::Var(lexical !UNIT_MARKER :decl(static)) +│ │ - QAST::Stmts +│ │ - QAST::Op(bind) +│ │ - QAST::Var(local ctxsave :decl(var)) +│ │ - QAST::Var(contextual $*CTXSAVE) +│ │ - QAST::Op(unless) +│ │ - QAST::Op(isnull) +│ │ - QAST::Var(local ctxsave) +│ │ - QAST::Op(if) +│ │ - QAST::Op(can) +│ │ - QAST::Var(local ctxsave) +│ │ - QAST::SVal(ctxsave) +│ │ - QAST::Op(callmethod ctxsave) +│ │ - QAST::Var(local ctxsave) +│ │ - QAST::Stmts +│ │ - QAST::WVal(Array) +│ │ - QAST::Stmt so \"test\".IO.d.Bool +│ │ - QAST::Want +│ │ - QAST::Op(callstatic :) :statement_id<1> so +│ │ - QAST::Op(hllize) +│ │ - QAST::Op(callmethod Bool) Bool +│ │ - QAST::Op(hllize) +│ │ - QAST::Op(callmethod d) d +│ │ - QAST::Op(hllize) +│ │ - QAST::Op(callmethod IO) IO +│ │ - QAST::Want test +│ │ - QAST::WVal(Str) +│ │ - Ss +│ │ - QAST::SVal(test) +│ │ - v +│ │ - QAST::Op(p6sink) +│ │ - QAST::Op(callstatic :) :statement_id<1> so +│ │ - QAST::Op(hllize) +│ │ - QAST::Op(callmethod Bool) Bool +│ │ - QAST::Op(hllize) +│ │ - QAST::Op(callmethod d) d +│ │ - QAST::Op(hllize) +│ │ - QAST::Op(callmethod IO) IO +│ │ - QAST::Want test +│ │ - QAST::WVal(Str) +│ │ - Ss +│ │ - QAST::SVal(test) +│ │ - QAST::WVal(Nil)
Re: I need help with IO.e
On Mon, May 18, 2020 at 14:36 ToddAndMargo via perl6-users < perl6-users@perl.org> wrote: > On 2020-05-17 22:28, Paul Procacci wrote: ... > 'say if "test".IO.d', and > 'say "test".IO.d.Bool' Try: 'say so "test".IO.d'
Re: I need help with IO.e
On 2020-05-17 22:28, Paul Procacci wrote: Don't 'say' anything. Just let the optimizer spit out the QAST that you are interested in looking at. The following spits out a diff after optimization: # diff -u <(perl6 --target=optimize -e '"test".IO.e') <(perl6 --target=optimize -e '"test".IO.e.Bool') >> Huh. Not sure what I am looking at You aren't specific. Is it the error message you received because you used 'say' improperly or is it the QAST? - How to use 'say' is in the documentation. - A QAST is pretty close to an AST and I'd start there on wikipedia or something. I was looking for the difference between 'say if "test".IO.d', and 'say "test".IO.d.Bool' This is were 'if" has to unscramble a "True" or "text message" return. But, I have no idea what all that stuff is that comes back anyway, so I think I will give up. Thank you for all the help! -T
Re: Different return values with "say" vs "put" (Nil representation... )
You are misunderstanding what `put` does. It does not print the internal representation. What it does do is turn the value into a `Str` object, then print it with a trailing newline. It just so happens that objects will by default return something that looks like an internal representation when you coerce it to a `Str`. class Point { has ($.x, $.y); } put Point.new( x => 1, y => 2 ).Str # Point<94102525076384> put Point.new( x => 1, y => 2 ).gist # Point.new(x => 1, y => 2) put Point.new( x => 1, y => 2 ).raku # Point.new(x => 1, y => 2) Unless they have a `.Str` method that returns something more sensible. class Point { has ($.x, $.y); method Str () { "[$!x,$!y]" } } put Point.new( x => 1, y => 2 ).Str # [1,2] put Point.new( x => 1, y => 2 ).gist # Point.new(x => 1, y => 2) put Point.new( x => 1, y => 2 ).raku # Point.new(x => 1, y => 2) Note that the default of `.gist` is do the same thing as calling `.raku`. (Many/Most built-in objects have a `.gist` method that returns something different.) --- `s///` and `S///` are both intended as working on `Str` objects. So when you give them something that is not a `Str`, they turn it into a `Str` first. Actually all operations that are `Str` operations will turn it into a `Str` first. Like `.starts-with`, `.ends-with`, `.chars`, `.codes`, `.index`, `.substr`, `print`, and `put` What `say` does, is that instead of calling `.Str` it calls `.gist` `.gist` is defined as giving enough information for a human to be able to figure out what object was printed. (Which is why the default is to return the same thing as `.raku` for defined objects) Actually almost all operations are intended for one type of object, and will coerce to that type. > say ['a', 'b', 'c'] + %( d => 10, e => 20 ) 5 --- Many objects will throw an error if you call `.Str` on them when they are undefined. > Bool.Str Use of uninitialized value of type Bool in string context. Methods .^name, .raku, .gist, or .say can be used to stringify it to something meaningful. in block at line 1 > Nil.Str Use of Nil in string context in block at line 1 Which means they also throw an error if you try to use one of the methods intended for `Str` objects on them. > Bool.substr(0,1) Use of uninitialized value of type Bool in string context. Methods .^name, .raku, .gist, or .say can be used to stringify it to something meaningful. in block at line 1 > Bool.^name.substr(0,1) B The reason for it generating an error is that generally when you try to turn an undefined object into a Str, there is likely a bug somewhere. --- Since `.gist` is for a human, it doesn't matter if the returned value is a little wrong, so it doesn't fail. (A human can notice if something is wrong. A program that only does what you told it to, generally doesn't.) > Bool.gist (Bool) Note that the reason it puts ( and ) around the name of the object is so that you know that you might have a problem somewhere in your code. --- Further, Nil is actually the most basic of the Failure objects. > for Failure.^mro { say .^name } Failure Nil Cool Any Mu If you get a Nil, there is probably some sort of failure somewhere. > say ( 1, 2, 3, 4 ).first( 'one' ) Nil Which means that if you try to use a Nil as a Str, there is definitely a bug in your code. On Mon, May 18, 2020 at 2:00 AM William Michels via perl6-users < perl6-users@perl.org> wrote: > Hello, > > I'm interested in knowing the differences between the return values > when "say" is used compared to "put". My understanding is that "put" > returns Raku's internal representation of a value held by a variable, > while "say" is merely "put" with the .gist method called on it (a > "human readable", often-abbreviated return value). > > Below I do "S///" (non-destructive) and "s///" (destructive) text > replacement on a three line text file in bash line [1]. In bash line > [2], the full substituted text file is correctly returned; in bash > line [3] using "say" only the $/ match string is returned. So far so > good. However, a virtually-identical call in bash line [4] using "put" > instead of "say" returns an error for the first line of the target > text file: "Use of Nil in string context in block at -e line 1". > > [1] homedir$ cat demo1.txt > this is a test, > I love Unix, > I like Linux too, > > [2] homedir$ perl6 -ne 'say S/love|like/admire/;' demo1.txt > this is a test, > I admire Unix, > I admire Linux too, > > [3] homedir$ perl6 -ne 'say s/love|like/admire/;' demo1.txt > Nil > 「love」 > 「like」 > > [4] homedir$ perl6 -ne 'put s/love|like/admire/;' demo1.txt > Use of Nil in string context > in block at -e line 1 > > love > like > > [5] homedir$ > > I'm really trying to understand this error message: doesn't Raku know > that this is a text
Re: Different return values with "say" vs "put" (Nil representation... )
"say $x" is essentially equivalent to "put $x.gist". Since Nil is undefined (roughly equivalent to a type object), Nil.gist has a string value of "Nil" and can be printed. However, attempting to convert Nil directly into a Str throws an error because that's attempting to stringify an undefined object. You can see this with the following: $ rakudo To exit type 'exit' or '^D' > say Nil Nil > put Nil Use of Nil in string context in block at line 1 > say Nil.Str Use of Nil in string context in block at line 1 > put Nil.gist Nil So, the difference in your example is that when the result of s/.../.../ is Nil (representing a failed Match), C calls .gist on Nil which produces a printable string, while C attempts to stringify the Nil object directly and that throws an error. Pm On Sun, May 17, 2020 at 11:59:18PM -0700, William Michels via perl6-users wrote: > Hello, > > I'm interested in knowing the differences between the return values > when "say" is used compared to "put". My understanding is that "put" > returns Raku's internal representation of a value held by a variable, > while "say" is merely "put" with the .gist method called on it (a > "human readable", often-abbreviated return value). > > Below I do "S///" (non-destructive) and "s///" (destructive) text > replacement on a three line text file in bash line [1]. In bash line > [2], the full substituted text file is correctly returned; in bash > line [3] using "say" only the $/ match string is returned. So far so > good. However, a virtually-identical call in bash line [4] using "put" > instead of "say" returns an error for the first line of the target > text file: "Use of Nil in string context in block at -e line 1". > > [1] homedir$ cat demo1.txt > this is a test, > I love Unix, > I like Linux too, > > [2] homedir$ perl6 -ne 'say S/love|like/admire/;' demo1.txt > this is a test, > I admire Unix, > I admire Linux too, > > [3] homedir$ perl6 -ne 'say s/love|like/admire/;' demo1.txt > Nil > 「love」 > 「like」 > > [4] homedir$ perl6 -ne 'put s/love|like/admire/;' demo1.txt > Use of Nil in string context > in block at -e line 1 > > love > like > > [5] homedir$ > > I'm really trying to understand this error message: doesn't Raku know > that this is a text replacement operation? How can a 'Nil' be > correctly represented when called by "say", but throw an error when > called by "put"? If the value is absent at the Raku representational > level and throws an error, wouldn't it be reasonable to assume that > the same case would hold for "say"? And finally, does this "say / put" > difference mean that some textual information will be lost from return > values (because "say" will have to be used instead of "put" to avoid > errorring-out)? > > Any enlightenment appreciated, > > TIA, Bill.
Different return values with "say" vs "put" (Nil representation... )
Hello, I'm interested in knowing the differences between the return values when "say" is used compared to "put". My understanding is that "put" returns Raku's internal representation of a value held by a variable, while "say" is merely "put" with the .gist method called on it (a "human readable", often-abbreviated return value). Below I do "S///" (non-destructive) and "s///" (destructive) text replacement on a three line text file in bash line [1]. In bash line [2], the full substituted text file is correctly returned; in bash line [3] using "say" only the $/ match string is returned. So far so good. However, a virtually-identical call in bash line [4] using "put" instead of "say" returns an error for the first line of the target text file: "Use of Nil in string context in block at -e line 1". [1] homedir$ cat demo1.txt this is a test, I love Unix, I like Linux too, [2] homedir$ perl6 -ne 'say S/love|like/admire/;' demo1.txt this is a test, I admire Unix, I admire Linux too, [3] homedir$ perl6 -ne 'say s/love|like/admire/;' demo1.txt Nil 「love」 「like」 [4] homedir$ perl6 -ne 'put s/love|like/admire/;' demo1.txt Use of Nil in string context in block at -e line 1 love like [5] homedir$ I'm really trying to understand this error message: doesn't Raku know that this is a text replacement operation? How can a 'Nil' be correctly represented when called by "say", but throw an error when called by "put"? If the value is absent at the Raku representational level and throws an error, wouldn't it be reasonable to assume that the same case would hold for "say"? And finally, does this "say / put" difference mean that some textual information will be lost from return values (because "say" will have to be used instead of "put" to avoid errorring-out)? Any enlightenment appreciated, TIA, Bill.