Hacker News new | ask | show | jobs
by jimmychangas 2635 days ago
Kotlin is great, but I think the "it" syntax was derived from Groovy.
2 comments

I'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).

The 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.")))
Anaphoric macros have been used in common lisp since forever.
Thanks for the name! Here's a wikipedia article about them: https://en.wikipedia.org/wiki/Anaphoric_macro
Is 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.
The latter.
Actually, it can be called a language feature, since it's the macro is defined in arc.arc, the arc lib.
PGs On Lisp details these macros from common lisp. I'm unsure how old they are.
Sounds 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