3 ms·
After spending a lot of time with Scheme (which is both relatively clean, and strong at syntactic extension), but doing iOS SwiftUI work at the moment, some of
by neilv 6y ago
After spending a lot of time with Scheme (which is both relatively clean, and strong at syntactic extension), but doing iOS SwiftUI work at the moment, some of the Swift sugar is a reminder that Swift is a very different language.
But I'm not above playing with sugar, including Smalltalk-inspired ones. In Racket, as an exercise, I implemented a straightforward way to do Smalltalk-like syntax for procedure calls.
If the head of a list expression is a symbol that ends in a colon, then it was assumed to be the Smalltalk-ish procedure name sugar. A syntax like this:
(foo: bar from: (+ 1 2) to: (funky 3))
would be translated by the reader to this procedure application:
(foo:from:to: bar (+ 1 2) (funky 3))
You'd probably define the procedure in the usual Scheme way, like this:
(define (foo:from:to: source start end)
...)
Of course, I wouldn't use this complicating sugar in real code without a good reason.