4 ms·
Kotlin is great, but I think the "it" syntax was derived from Groovy.
by jimmychangas 8y ago
Kotlin is great, but I think the "it" syntax was derived from Groovy.
- zbentley 8y agoI'm not positive, but Groovy may in turn have been inspired by Perl's $_, as in 'map { $_ + 1 } (1..10);'. If I recall correctly, the canonical name for that parameter is 'it' as well (though I've never met a Perl programmer that calls it that . . . er, calls it 'it' . . . er, you get the idea).
- dchest 8y agoThe first time I saw `it` in a similar construction was in Arc language's aif macro: (mac aif (expr . body) `(let it ,expr (if it ,@(if (cddr body) `(,(car body) (aif ,@(cdr body))) body)))) HN uses it quite a lot, e.g.: (defop logout req (aif (get-user req) (do (logout-user it) (pr "Logged out.")) (pr "You were not logged in.")))
- bjoli 8y agoAnaphoric macros have been used in common lisp since forever.
- dchest 8y agoThanks for the name! Here's a wikipedia article about them: https://en.wikipedia.org/wiki/Anaphoric_macro https://en.wikipedia.org/wiki/Anaphoric_macro
- emidln 8y agoPGs On Lisp details these macros from common lisp. I'm unsure how old they are.
- zbentley 8y agoIs it a language feature in that example, or a user defined function/macro? It looks like the latter, but I don't speak Lisp, so I may be wrong.
- icebraining 8y agoThe latter.
- dchest 8y agoActually, it can be called a language feature, since it's the macro is defined in arc.arc, the arc lib.
- deleted 8y ago[deleted]
- np_tedious 8y agoSounds a lot like Scala's underscore (or at least one usage underscore can mean a few things depending on context). Haven't used Kotlin myself, but I'd agree that sounds like a good thing