4 ms·
All languages have different semantics. Otherwise they would've been one language. Python has an explicit self that is unbound. Other languages have it implici
by spion 9y ago
All languages have different semantics. Otherwise they would've been one language.
Python has an explicit self that is unbound. Other languages have it implicit and bound... Etc
- twic 9y agoWhat do you mean by "unbound"? Some Python: >>> class Foo: >>> def __init__(self, x): self.x = x ... ... def bar(self): print('x =', self.x) ... ... >>> f = Foo(23) >>> b = f.bar >>> b() x = 23 Note that when you extract the method from the object as a callable, it hangs onto the right self. Same deal as Java: class Foo { private int x; Foo(int x) { this.x = x; } void bar() { System.out.println("x = " + x); } } public static void main(String[] args) { Foo f = new Foo(23); Runnable b = f::bar; b.run(); // prints x = 23 }
- spion 9y agoI meant "bound", sorry. Funny that you mention "::" in Java. ES7/ES8 was going to have a bind operator "::" that extracts a bound method with a slightly different syntax. i.e. `::f.bar`