Re: Keyword Arguments
Friedrich Dominicus <[email protected]> Thu, 14 Jun 2012 15:44:35 +0200
| Newsgroups | gmane.comp.lang.io |
|---|---|
| Organization | Q-Software Solutions GmbH |
| Message-ID | <[email protected]> |
Jeremy Tregunna <[email protected]> writes: > > This isn't true. You can write a sort function which iterates over your list, > applying a message which takes one argument (i.e., a comparator) to one element > and inserting the next element as its argument. For instance, a use case might > be: > > list(1, 5, 2) sort(<) # Would yield: list(1, 2, 5) Yes you're right it's however done so e.g. in Smalltalk. And yes I know it's done also like that in functional languages, but I think I still prefer having the arguments "explicit" but without doubt your solution has some elegance in it. It's still an area where I think a to argument block is more readable. YMMV of course. > > This uses higher order messaging and is entirely possible in Io. This would > work quite like Io's sortBy() which takes a block and two arguments at present. > This works great for simple comparators. For more complex comparators I can see > you needing a different solution however. However, if you always yielded an > "elements" name in the context sort evaluated its arguments in, or some other > name, you could write: > > list(1, 5, 2) sort(myComplexAction(elements at(0)) < myComplexAction(elements > at(1))) > > And pretty much solve your problem. You can set up symbolic names if you want, > but it's certainly doable and not so bad either. If it wasn't clear, "elements" > above is a tuple of two items in the list. I understand but I honestly dislike having it that way but you're right it's doable. Regards Friedrich -- Q-Software Solutions GmbH; Sitz: Bruchsal; Registergericht: Mannheim Registriernummer: HRB232138; Geschaeftsfuehrer: Friedrich Dominicus