Skip to content
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

andthen acts differently on a return #4534

Closed
p6rt opened this issue Sep 13, 2015 · 4 comments
Closed

andthen acts differently on a return #4534

p6rt opened this issue Sep 13, 2015 · 4 comments

Comments

@p6rt
Copy link

p6rt commented Sep 13, 2015

Migrated from rt.perl.org#126050 (status was 'rejected')

Searchable as RT126050$

@p6rt
Copy link
Author

p6rt commented Sep 13, 2015

From @lizmat

[23​:19​:47] <lizmat> m​: sub a { .Int with $^a }; a(Str).perl.say # somehow I expect this to say Str instead of ()
[23​:19​:48] <+camelia> rakudo-moar 0d47a4​: OUTPUT«()␤»
[23​:21​:29] <vendethiel> m​: say Str.Int.perl
[23​:21​:29] <+camelia> rakudo-moar 0d47a4​: OUTPUT«Invocant requires an instance of type Str, but a type object was passed. Did you forget a .new?␤ in block <unit> at /tmp/yFKn3e0pMl​:1␤␤»
[23​:22​:10] <vendethiel> lizmat​: the "with" is not traversed, that's correct, right? I don't think it should return its operand in the other case
[23​:23​:37] <lizmat> vendethiel​: I was thinking about this​:
[23​:23​:41] <lizmat> .lines(​:close, |c) with self.open(|c)
[23​:23​:59] <lizmat> if the open fails, I would like to see it returned
[23​:23​:59] <vendethiel> lizmat​: wouldn't .given be more useful there?
[23​:24​:11] <lizmat> .given ???
[23​:24​:20] <vendethiel> uhm. I mean given{} :P
[23​:24​:31] <vendethiel> well, I guess you could invent a .given...
[23​:25​:20] <lizmat> given self.open(|c) { .... and then ?
[23​:27​:20] <vendethiel> lizmat​: you can "cling onto" the result with it (and just end the block with $_ I guess). But I was actually thinking of some closing mechanism (python-like "with"), so disregard my comment
[23​:28​:43] <lizmat> I think .method with $a returning the value of $a if not defined, would be a useful idiom
[23​:29​:08] <vendethiel> lizmat​: seems a bit like andthen, in some way, maybe?
[23​:29​:35] <vendethiel> m​: say Str andthen .Int
[23​:29​:36] <+camelia> rakudo-moar 655a45​: OUTPUT«(Str)␤»
[23​:29​:41] <vendethiel> m​: say "3" andthen .Int
[23​:29​:42] <+camelia> rakudo-moar 655a45​: OUTPUT«3␤»
[23​:31​:09] <lizmat> vendethiel++
[23​:32​:23] <lizmat> m​: sub a { $^a andthen .Int }; a(Str).perl.say; a(42).perl.say # still not quite what I want :-(
[23​:32​:24] <+camelia> rakudo-moar 655a45​: OUTPUT«()␤42␤»
[23​:32​:43] vendethiel wats
[23​:33​:03] <vendethiel> m​: sub a { say $^a.perl; $^a }; a(Str).perl.say
[23​:33​:03] <+camelia> rakudo-moar 655a45​: OUTPUT«Str␤Str␤»
[23​:33​:14] <vendethiel> m​: sub a { say $^a.perl; $^a andthen 1 }; a(Str).perl.say
[23​:33​:15] <+camelia> rakudo-moar 655a45​: OUTPUT«Str␤()␤»
[23​:33​:32] <lizmat> bug?
[23​:33​:38] <vendethiel> m​: sub a { say $^a.perl; say $^a andthen 1 }; a(Str).perl
[23​:33​:38] <+camelia> rakudo-moar 655a45​: OUTPUT«Str␤(Str)␤»
[23​:33​:47] <vendethiel> lizmat​: ...looks like a part of it isn't returned? idk
[23​:33​:53] <vendethiel> m​: sub a { say $^a.perl; return $^a andthen 1 }; a(Str).perl.say
[23​:33​:53] <+camelia> rakudo-moar 655a45​: OUTPUT«Str␤Str␤»
[23​:33​:56] <vendethiel> lizmat​: ^
[23​:33​:58] <vendethiel> seems like a bug
[23​:34​:17] <lizmat> m​: sub a { return $^a andthen .Int }; a(Str).perl.say; a(42).perl.say
[23​:34​:18] <+camelia> rakudo-moar 655a45​: OUTPUT«Str␤42␤»
[23​:34​:20] <lizmat> aha...
[23​:34​:22] <lizmat> bug indeed
[23​:34​:36] <vendethiel> lizmat++ # golfing

@p6rt
Copy link
Author

p6rt commented Sep 14, 2015

From @jnthn

On Sun Sep 13 14​:39​:28 2015, elizabeth wrote​:

[23​:19​:47] <lizmat> m​: sub a { .Int with $^a }; a(Str).perl.say #
somehow I expect this to say Str instead of ()
[23​:19​:48] <+camelia> rakudo-moar 0d47a4​: OUTPUT«()␤»
[23​:21​:29] <vendethiel> m​: say Str.Int.perl
[23​:21​:29] <+camelia> rakudo-moar 0d47a4​: OUTPUT«Invocant requires
an instance of type Str, but a type object was passed. Did you forget
a .new?␤ in block <unit> at /tmp/yFKn3e0pMl​:1␤␤»
[23​:22​:10] <vendethiel> lizmat​: the "with" is not traversed,
that's correct, right? I don't think it should return its operand in
the other case
[23​:23​:37] <lizmat> vendethiel​: I was thinking about this​:
[23​:23​:41] <lizmat> .lines(​:close, |c) with self.open(|c)
[23​:23​:59] <lizmat> if the open fails, I would like to see it
returned
[23​:23​:59] <vendethiel> lizmat​: wouldn't .given be more useful
there?
[23​:24​:11] <lizmat> .given ???
[23​:24​:20] <vendethiel> uhm. I mean given{} :P
[23​:24​:31] <vendethiel> well, I guess you could invent a
.given...
[23​:25​:20] <lizmat> given self.open(|c) { .... and then ?
[23​:27​:20] <vendethiel> lizmat​: you can "cling onto" the
result with it (and just end the block with $_ I guess). But I was
actually thinking of some closing mechanism (python-like "with"), so
disregard my comment
[23​:28​:43] <lizmat> I think .method with $a returning the value of
$a if not defined, would be a useful idiom
[23​:29​:08] <vendethiel> lizmat​: seems a bit like andthen, in
some way, maybe?
[23​:29​:35] <vendethiel> m​: say Str andthen .Int
[23​:29​:36] <+camelia> rakudo-moar 655a45​: OUTPUT«(Str)␤»
[23​:29​:41] <vendethiel> m​: say "3" andthen .Int
[23​:29​:42] <+camelia> rakudo-moar 655a45​: OUTPUT«3␤»
[23​:31​:09] <lizmat> vendethiel++
[23​:32​:23] <lizmat> m​: sub a { $^a andthen .Int };
a(Str).perl.say; a(42).perl.say # still not quite what I want :-(
[23​:32​:24] <+camelia> rakudo-moar 655a45​: OUTPUT«()␤42␤»
[23​:32​:43] vendethiel wats
[23​:33​:03] <vendethiel> m​: sub a { say $^a.perl; $^a };
a(Str).perl.say
[23​:33​:03] <+camelia> rakudo-moar 655a45​: OUTPUT«Str␤Str␤»
[23​:33​:14] <vendethiel> m​: sub a { say $^a.perl; $^a andthen 1
}; a(Str).perl.say
[23​:33​:15] <+camelia> rakudo-moar 655a45​: OUTPUT«Str␤()␤»
[23​:33​:32] <lizmat> bug?
[23​:33​:38] <vendethiel> m​: sub a { say $^a.perl; say $^a
andthen 1 }; a(Str).perl
[23​:33​:38] <+camelia> rakudo-moar 655a45​: OUTPUT«Str␤(Str)␤»
[23​:33​:47] <vendethiel> lizmat​: ...looks like a part of it
isn't returned? idk
[23​:33​:53] <vendethiel> m​: sub a { say $^a.perl; return $^a
andthen 1 }; a(Str).perl.say
[23​:33​:53] <+camelia> rakudo-moar 655a45​: OUTPUT«Str␤Str␤»
[23​:33​:56] <vendethiel> lizmat​: ^
[23​:33​:58] <vendethiel> seems like a bug
[23​:34​:17] <lizmat> m​: sub a { return $^a andthen .Int };
a(Str).perl.say; a(42).perl.say
[23​:34​:18] <+camelia> rakudo-moar 655a45​: OUTPUT«Str␤42␤»
[23​:34​:20] <lizmat> aha...
[23​:34​:22] <lizmat> bug indeed
[23​:34​:36] <vendethiel> lizmat++ # golfing

Not a bug, just a misremembering that andthen has very loose precedence.

09​:34 < jnthn> m​: sub a { return $^a andthen .Int }; a(Str).perl.say;
  a(42).perl.say
09​:34 <+camelia> rakudo-moar 1bd727​: OUTPUT«Str␤42␤»
09​:34 < jnthn> m​: sub a { return ($^a andthen .Int) }; a(Str).perl.say;
  a(42).perl.say
09​:34 <+camelia> rakudo-moar 1bd727​: OUTPUT«()␤42␤»
09​:34 * jnthn rejects RT #​126050 with a reminder about precedence :)

@p6rt
Copy link
Author

p6rt commented Sep 14, 2015

The RT System itself - Status changed from 'new' to 'open'

@p6rt p6rt closed this as completed Sep 14, 2015
@p6rt
Copy link
Author

p6rt commented Sep 14, 2015

@jnthn - Status changed from 'open' to 'rejected'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant