24

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.

jscs
  • 63,694
  • 13
  • 151
  • 195
donalbain
  • 1,158
  • 15
  • 31

7 Answers7

14

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

Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
Nekuromento
  • 2,147
  • 2
  • 16
  • 17
  • What about languages that provide a thin layer over some more popular ones to allow this syntax. I'm thinking of things like Bistro (http://en.wikipedia.org/wiki/Bistro_(programming_language)) for Java. I think this project is pretty old though. – donalbain May 27 '11 at 04:47
  • 1
    News section at [Bistro website](http://bistro.sourceforge.net/) says last release was 14 October 2010. So this project is not really dead. – Nekuromento May 27 '11 at 14:23
  • 1
    Objective-J is a layer over JavaScript. – Sherm Pendley May 27 '11 at 20:06
5

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
munificent
  • 11,946
  • 2
  • 38
  • 55
3

See e.g. Self.

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

elder_george
  • 7,849
  • 24
  • 31
  • 3
    Objective-C explicitly does *not* allowed optional named parameters which, I think, is relevant to OP's question. – bbum May 26 '11 at 22:57
2

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.

jscs
  • 63,694
  • 13
  • 151
  • 195
  • 1
    Keyword argument based message passing also often allows some of the keywords to be omitted and/or default argument values to be specified. – bbum May 26 '11 at 22:56
  • Well, though I'm not excellent at English very much, but I think word order is very important to make accurate expression in English. And should be also important in *readability* problem. – eonil Jan 10 '13 at 16:01
0

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);
mamboking
  • 4,559
  • 23
  • 27
-1

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

HyLian
  • 4,999
  • 5
  • 33
  • 40
  • I'm definitely finding many popular languages that support the optional named parameters. But...and I think I'm having trouble putting a name to the concept of smalltalk-like method names...that type of explicitness seems to be missing. – donalbain May 26 '11 at 22:42
  • 3
    Yah -- named parameters and keyword parameters are **not at all like Objective-C's message passing scheme**. – bbum May 26 '11 at 22:55
-1

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

Vijay Mathew
  • 26,737
  • 4
  • 62
  • 93