Jump to content

Break OO privacy: Difference between revisions

Rename Perl 6 -> Raku, alphabetize, minor clean-up
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 296:
-9172774392245257468
</lang>
 
=={{header|Common Lisp}}==
 
Line 405 ⟶ 406:
( scratchpad ) { 1 2 3 } { 1 2 4 } intersect length .
2</lang>
 
 
=={{header|Forth}}==
Line 1,014:
<pre>I am ostensibly private
I am ostensibly private</pre>
 
=={{header|Perl 6}}==
{{works with|Rakudo|2015.12}}
We may call into the MOP (Meta-Object Protocol) via the <tt>.^</tt> operator, and the MOP knows all about the object, including any supposedly private bits. We ask for its attributes, find the correct one, and get its value.
<lang perl6>class Foo {
has $!shyguy = 42;
}
my Foo $foo .= new;
 
say $foo.^attributes.first('$!shyguy').get_value($foo);</lang>
{{out}}
<pre>42</pre>
 
=={{header|Phix}}==
Line 1,052 ⟶ 1,040:
"this breaks privacy"
</pre>
 
=={{header|PicoLisp}}==
PicoLisp uses [http://software-lab.de/doc/ref.html#transient "transient symbols"] for variables, functions, methods etc. inaccessible from other parts of the program. Lexically, a transient symbol is enclosed by double quotes.
The only way to access a transient symbol outside its namespace is to search for its name in other (public) structures. This is done by the '[http://software-lab.de/doc/refL.html#loc loc]' function.
<lang PicoLisp>(class +Example)
# "_name"
 
(dm T (Name)
(=: "_name" Name) )
 
(dm string> ()
(pack "Hello, I am " (: "_name")) )
 
(====) # Close transient scope
 
(setq Foo (new '(+Example) "Eric"))</lang>
Test:
<lang PicoLisp>: (string> Foo) # Access via method call
-> "Hello, I am Eric"
 
: (get Foo '"_name") # Direct access doesn't work
-> NIL
 
: (get Foo (loc "_name" +Example)) # Locating the transient symbol works
-> "Eric"
 
: (put Foo (loc "_name" +Example) "Edith")
-> "Edith"
 
: (string> Foo) # Ditto
-> "Hello, I am Edith"
 
: (get Foo '"_name")
-> NIL
 
: (get Foo (loc "_name" +Example))
-> "Edith"</lang>
 
=={{header|PHP}}==
Line 1,150 ⟶ 1,101:
}
</pre>
 
=={{header|PicoLisp}}==
PicoLisp uses [http://software-lab.de/doc/ref.html#transient "transient symbols"] for variables, functions, methods etc. inaccessible from other parts of the program. Lexically, a transient symbol is enclosed by double quotes.
The only way to access a transient symbol outside its namespace is to search for its name in other (public) structures. This is done by the '[http://software-lab.de/doc/refL.html#loc loc]' function.
<lang PicoLisp>(class +Example)
# "_name"
 
(dm T (Name)
(=: "_name" Name) )
 
(dm string> ()
(pack "Hello, I am " (: "_name")) )
 
(====) # Close transient scope
 
(setq Foo (new '(+Example) "Eric"))</lang>
Test:
<lang PicoLisp>: (string> Foo) # Access via method call
-> "Hello, I am Eric"
 
: (get Foo '"_name") # Direct access doesn't work
-> NIL
 
: (get Foo (loc "_name" +Example)) # Locating the transient symbol works
-> "Eric"
 
: (put Foo (loc "_name" +Example) "Edith")
-> "Edith"
 
: (string> Foo) # Ditto
-> "Hello, I am Edith"
 
: (get Foo '"_name")
-> NIL
 
: (get Foo (loc "_name" +Example))
-> "Edith"</lang>
 
=={{header|Python}}==
Line 1,169 ⟶ 1,157:
123
>>> </lang>
 
=={{header|Raku}}==
(formerly Perl 6)
{{works with|Rakudo|2015.12}}
We may call into the MOP (Meta-Object Protocol) via the <tt>.^</tt> operator, and the MOP knows all about the object, including any supposedly private bits. We ask for its attributes, find the correct one, and get its value.
<lang perl6>class Foo {
has $!shyguy = 42;
}
my Foo $foo .= new;
 
say $foo.^attributes.first('$!shyguy').get_value($foo);</lang>
{{out}}
<pre>42</pre>
 
=={{header|Ruby}}==
10,327

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.