还有哪些编程语言具有类似Smalltalk的消息传递语法?

时间:2021-01-11 22:27:30

What languages are there with a message-passing syntax similar to Smalltalk's? Objective-C is the only one I'm familiar with. Specifically, I was wondering if any other language implementations exist which allow for syntax in a form like: [anObject methodWithParam:aParam andParam:anotherParam], having messages that allow for named parameters as part of method definitions.

哪些语言的消息传递语法类似于Smalltalk? Objective-C是我唯一熟悉的。具体来说,我想知道是否存在任何其他语言实现允许以下形式的语法:[anObject methodWithParam:aParam andParam:anotherParam],具有允许命名参数作为方法定义的一部分的消息。

In general I find that this syntax can be conducive to more consistent method names that more clearly show the methods' intent, and that the price you pay in wordiness is generally worth it. I would love to know if there are any other languages that support this.

一般来说,我发现这种语法可以有助于更一致的方法名称,更清楚地显示方法的意图,并且你付出的单词价格通常是值得的。我很想知道是否有任何其他语言支持这一点。

7 个解决方案

#1


14  

Here is a list of languages supporting keyword messages syntax similar to Smalltalk:

以下是支持与Smalltalk类似的关键字消息语法的语言列表:

  • Objective-J, Objective-Modula-2. These are language extensions similar to Objective-C.
  • Objective-J,Objective-Modula-2。这些是与Objective-C类似的语言扩展。
  • Strongtalk, a Smalltalk dialect with optional strong-typing
  • Strongtalk,一种可选择强类型的Smalltalk方言
  • F-script, an embeddable Smalltalk dialect with APL-inspired array operations extensions.
  • F脚本,一种可嵌入的Smalltalk方言,具有APL启发的阵列操作扩展。
  • Self
  • Newspeak
  • 新语
  • Slate
  • 石板
  • Atomo, an embeddable language for Haskell
  • Atomo,Haskell的嵌入式语言

#2


5  

In addition to the other languages mentioned here, Fancy:

除了这里提到的其他语言,Fancy:

osna = City new: "Osnabrück"
p = Person new: "Christopher" age: 23 city: osna
p println

berlin = City new: "Berlin"
p go_to: berlin
p println

#3


3  

See e.g. Self.

见例如自。

Also, many languages support optional named parameters, e.g. Python or C# (starting with v4).

此外,许多语言支持可选的命名参数,例如Python或C#(从v4开始)。

#4


2  

Python and Common Lisp (probably among others) allow for keyword arguments. You can make calls to functions which include the parameter names.

Python和Common Lisp(可能包括其他)允许关键字参数。您可以调用包含参数名称的函数。

These are not equivalent to Obj-C's method names, because the keyword args ignore position, but they answer your question about readability.*

这些不等同于Obj-C的方法名称,因为关键字args忽略位置,但它们回答了关于可读性的问题。*

make_an_omelet(num_eggs=2, cheese=u"Gruyère", mushrooms=True)

(make-a-salad :greens 'boston-lettuce 
              :dressing 'red-wine-vinaigrette 
              :other-ingredients '(hazelnuts dried-apricots))

This is not, of course, message passing, just plain old function calling.

当然,这不是消息传递,只是简单的旧函数调用。


*They have other uses than this, such as specifying default values.

*除此之外还有其他用途,例如指定默认值。

#5


0  

Ada supports named parameters.

Ada支持命名参数。

function Minimum (A, B : Integer) return Integer is
begin
   if A <= B then
      return A;
   else
      return B;
   end if;
end Minimum;

Then call:

然后打电话:

Answer := Minimum (A=>100, B=>124);

#6


-1  

Ruby can send messages to objects in order to call their methods, pretty much like objc does:

Ruby可以向对象发送消息以调用它们的方法,就像objc一样:

class Foo
  def bar a,b
    a + b
  end
end

f = Foo.new
f.send(:bar, a=4, b=5)
>> 9

Indeed, among other things, this makes possible the integration between Cocoa and Ruby in MacRuby

事实上,除此之外,这使得MacRuby中Cocoa和Ruby之间的集成成为可能

#7


-1  

Erlang do not claim to be object oriented but message passing is a key concept in that language.

Erlang并不声称是面向对象的,但消息传递是该语言的关键概念。

#1


14  

Here is a list of languages supporting keyword messages syntax similar to Smalltalk:

以下是支持与Smalltalk类似的关键字消息语法的语言列表:

  • Objective-J, Objective-Modula-2. These are language extensions similar to Objective-C.
  • Objective-J,Objective-Modula-2。这些是与Objective-C类似的语言扩展。
  • Strongtalk, a Smalltalk dialect with optional strong-typing
  • Strongtalk,一种可选择强类型的Smalltalk方言
  • F-script, an embeddable Smalltalk dialect with APL-inspired array operations extensions.
  • F脚本,一种可嵌入的Smalltalk方言,具有APL启发的阵列操作扩展。
  • Self
  • Newspeak
  • 新语
  • Slate
  • 石板
  • Atomo, an embeddable language for Haskell
  • Atomo,Haskell的嵌入式语言

#2


5  

In addition to the other languages mentioned here, Fancy:

除了这里提到的其他语言,Fancy:

osna = City new: "Osnabrück"
p = Person new: "Christopher" age: 23 city: osna
p println

berlin = City new: "Berlin"
p go_to: berlin
p println

#3


3  

See e.g. Self.

见例如自。

Also, many languages support optional named parameters, e.g. Python or C# (starting with v4).

此外,许多语言支持可选的命名参数,例如Python或C#(从v4开始)。

#4


2  

Python and Common Lisp (probably among others) allow for keyword arguments. You can make calls to functions which include the parameter names.

Python和Common Lisp(可能包括其他)允许关键字参数。您可以调用包含参数名称的函数。

These are not equivalent to Obj-C's method names, because the keyword args ignore position, but they answer your question about readability.*

这些不等同于Obj-C的方法名称,因为关键字args忽略位置,但它们回答了关于可读性的问题。*

make_an_omelet(num_eggs=2, cheese=u"Gruyère", mushrooms=True)

(make-a-salad :greens 'boston-lettuce 
              :dressing 'red-wine-vinaigrette 
              :other-ingredients '(hazelnuts dried-apricots))

This is not, of course, message passing, just plain old function calling.

当然,这不是消息传递,只是简单的旧函数调用。


*They have other uses than this, such as specifying default values.

*除此之外还有其他用途,例如指定默认值。

#5


0  

Ada supports named parameters.

Ada支持命名参数。

function Minimum (A, B : Integer) return Integer is
begin
   if A <= B then
      return A;
   else
      return B;
   end if;
end Minimum;

Then call:

然后打电话:

Answer := Minimum (A=>100, B=>124);

#6


-1  

Ruby can send messages to objects in order to call their methods, pretty much like objc does:

Ruby可以向对象发送消息以调用它们的方法,就像objc一样:

class Foo
  def bar a,b
    a + b
  end
end

f = Foo.new
f.send(:bar, a=4, b=5)
>> 9

Indeed, among other things, this makes possible the integration between Cocoa and Ruby in MacRuby

事实上,除此之外,这使得MacRuby中Cocoa和Ruby之间的集成成为可能

#7


-1  

Erlang do not claim to be object oriented but message passing is a key concept in that language.

Erlang并不声称是面向对象的,但消息传递是该语言的关键概念。