views:

175

answers:

6

Don't have anything to add so, What languages other than Python have an explicit self?

[Edit]

Obviously all OO languages will have a this or a self for current instance. What I want to know is does any other ask you to explicitly pass this or self as all instance method arguments?

+4  A: 

By explicit, do you mean "explicitely passed as an argument to all the functions"? If so, then Python's the only one I know off-hand. Most OO languages support this or self in some form, but most of them let you define class methods without always defining self as the first argument.

linked
s/functions/methods
Virgil Dupras
+3  A: 

F# (presumably from its OCAML heritage) requires an explicit name for all self-references; though the name is any arbitrary identifier e.g.

 override x.BeforeAnalysis() = 
    base.BeforeAnalysis()
    DoWithLock x.AddReference

Here we're defining an overriding member function BeforeAnalysis which calls another member function AddReference. The identifier x here is arbitrary, but is required in both the declaration and any reference to members of the "this"/"self" instance.

Steve Gilham
+3  A: 

Depending on your point of view, Lua. To quote the reference: "A call v:name(args) is syntactic sugar for v.name(v,args), except that v is evaluated only once." You can also define methods using either notation. So you could say that Lua has an optional explicit self.

Boojum
how would you define a method `foo(self, a, b, **kwargs)` in lua?
uswaretech
I'm not really an expert in Lua. As far as I know, it doesn't have keyword arguments, but you could simulate their behavior by using the syntactic sugar for sending a table to the method. Tables have an array like part and a hashlike part.So define something like "function object:foo(args) a = args[1]; b = args[2]; self.argx = args.argx; end" and then call it with something like "object:foo{1, 2, argx=3}".If you want an explicit self, you can define "object.foo = function(self, args) a = args[1]; b = args[2]; self.argx = args.argx; end" and then call "object.foo(object, {1, 2, argx=3})
Boojum
+1  A: 

any Object-Oriented language has a notion of this or self within member functions.

Scott Evernden
+1  A: 

many object oriented languages if not all of them

for example c++ support "this" instead of "self"

but you dont have to pass it, it is passed passively

hope that helps ;)

Ahmad Dwaik
Not "passively" but "implicitly". Like Java, the C++ compiler reasons out where `this` belongs. Sometimes it will be unable to reason out if a `this` belongs in front of a variable reference, and you must put it in to resolve the ambiguous name.
S.Lott
+3  A: 

The programming language Oberon 2 has an explicitly named but not explicitly passed 'this' or 'self' argument for member functions of classes (known as type bound procedures in Oberon terminology)

The following example is an Insert method on a type Text, where the identifier 't' is specified to bind to the explicit 'this' or 'self' reference.

PROCEDURE (t: Text) Insert (string: ARRAY OF CHAR; pos: LONGINT);
BEGIN ...
END Insert;

More details on Object Orientation in Oberon are here.

grrussel