donalbain
donalbain

Reputation: 1168

What other programming languages have a Smalltalk-like message-passing syntax?

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.

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.

Upvotes: 24

Views: 5398

Answers (7)

Nekuromento
Nekuromento

Reputation: 2235

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

Upvotes: 14

munificent
munificent

Reputation: 12364

In addition to the other languages mentioned here, 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

Upvotes: 5

Vijay Mathew
Vijay Mathew

Reputation: 27174

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

Upvotes: -1

mamboking
mamboking

Reputation: 4637

Ada supports named parameters.

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);

Upvotes: 0

jscs
jscs

Reputation: 64002

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

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

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.

Upvotes: 2

HyLian
HyLian

Reputation: 5093

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

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

Upvotes: -1

elder_george
elder_george

Reputation: 7879

See e.g. Self.

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

Upvotes: 3

Related Questions