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

Confusion over "mutators" in section 4 #13

Open
MattOates opened this issue Dec 5, 2015 · 4 comments
Open

Confusion over "mutators" in section 4 #13

MattOates opened this issue Dec 5, 2015 · 4 comments

Comments

@MattOates
Copy link
Contributor

http://perl6intro.com/#_functions_and_mutators this section is really quite confusing and has indeed caused confusion already https://www.reddit.com/r/perl6/comments/3vjuex/how_to_easily_tell_the_difference_between_a/

@hankache
Copy link
Owner

I was thinking of enhancing this section by replacing it with:
https://gist.github.com/hankache/66f43377f5a6393a11646beed748c0cc

@MattOates would it become less confusing?
@lizmat @zoffixznet can you kindly review?

@zoffixznet
Copy link
Contributor

Looks more or less right, depending on how pedantic you want to get; like "The number 3 [...] will never change over time" is not quite true for Rakudo:

<Zoffix___> m: BEGIN 3 does role { method Bridge { 42 } }; say 3 + 2e0
<camelia> rakudo-moar 639c6da0c: OUTPUT: «44␤»

The references explanation is very different from how all that stuff fits into my brain—not implying that it's wrong, just different.

I don't think in terms of mutable-immutable references (that's reminiscent of Rust's ownership), but in terms of containers. my $a = 42; $a = 42 works, because there's a Scalar container and I'm storing a new value in that container. my $a := 42; $a = 42 throws, because there's no container, so there's nothing to store the new value into. More in my containers article: https://perl6advent.wordpress.com/2017/12/02/


The one thing I do see as potential for confusion is sentence "Trying to change the value of a constant leads to an error" since it implies the constant offers some sort of mutability protection, but it doesn't. If I stick a container or a mutable object into a constant, I can change the value all I want:

<Zoffix___> m: constant FOO = $ = 42; say FOO; FOO = 100; say FOO
<camelia> rakudo-moar 639c6da0c: OUTPUT: «42␤100␤»
<Zoffix___> m: constant FOO = [<a b c>]; say FOO; FOO[1] = 'meows'; say FOO
<camelia> rakudo-moar 639c6da0c: OUTPUT: «[a b c]␤[a meows c]␤»

A constant is very much like a variable that doesn't auto-give a container (like my \foo) except its initializer is run at compile time. So it's fairly easy to get a constant isn't actually constant.

@hankache
Copy link
Owner

@zoffixznet I think you're right. This whole mutable/immutable feels alien to Perl 6. I should find a way to explain containers in a friendly manner to people new to Perl 6.

Thank you for your feedback.

@interlab
Copy link

interlab commented Jul 9, 2018

I suggest renaming the 4 section into "Methods and mutators"

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

4 participants