Which languages ​​other than Python have an explicit self?

It seems a little strange that Python requires explicitly passing selfas the first argument to all the functions of the class. Are there other languages ​​that require something like this?

+3
source share
8 answers

In explicit form, do you mean "explicitly passed as an argument to each function of the class"? If so, then Python is the only one I know outside of the game.

Most OO languages ​​support thiseither selfin one form or another, but most of them allow you to define class functions, not always defining selfas the first argument.

+5
source

, Lua. : " v: name (args) v.name(v, args), , v ". . , , Lua .

+4

F # ( OCAML) ; - , .

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

- BeforeAnalysis, - AddReference. x , , "this"/ "self".

+3

Oberon 2 , 'this' 'self' - ( )

- Insert Text, 't' 'this' 'self'.

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

.

+3

any - -.

+1
+1

- ,

, ++ "this" "self"

,

, ;)

0

Clojure , : "self" ( ) - . , :

(defprotocol MyProtocol
  (foo [this that]))

(extend-protocol MyProtocol String
  (foo [this that]
    (str this " and " that)))

(extend-protocol MyProtocol Long
  (foo [this that]
    (* this that)))

(foo "Cat" "Dog")
=> "Cat and Dog"

(foo 10 20)
=> 200

, , , . :

(conj [1 2 3] 4)
=> [1 2 3 4]
0
source

Source: https://habr.com/ru/post/1725021/


All Articles