Hacker News new | ask | show | jobs
by todd8 3850 days ago
Grace's method names allow one to say:

    circle.at(x,y) radius(5) fill("solid")
where in Python one might say:

    circle.at(x,y, radius=5, fill="solid")
Objective C also allows multipart method names that help document the arguments.

For you young whippersnappers, this idea goes back over half a century to Algol-60 where the commas that delimit parameters to functions can be optionally replaced by ") text: (". So our procedure call in Algol-60 could be written:

    draw(circle) at: (x,y) radius: (5) fill: (1.0)
or as:

    draw(circle, x, y, 5, 1.0)
1 comments

Well, Objective-C's message names came from Smalltalk:

    context circleWithFill:'solid' at:x@y radius:5.
These keyword messages actually go a long way towards bridging the gap between API and DSL.

What Grace does is based on this approach, but goes significantly beyond it in closing the gap further by allowing the parameter parts to be regular languages. So as a somewhat silly example you could have a single method that draws circles of the same size and fill at many different locations:

    context circlWithFill:'solid' at:20@30 at:30@30 at: 100@20 radius:5.
Depending on the definition of the method, the 'at:' part could be repeated 0-n times. It's pretty amazing.

https://michael.homer.nz/Publications/DLS2015/paper.pdf