title: Is it possible to distinguish identical function calls in Kotlin?
body: <p>I'm building a library and I want the library to be able to distinguish the different times when the user in his code calls the functions in my library. For example, if I have a function <code>sayHello()</code> defined like so:</p>
  <pre class="lang-kotlin prettyprint-override"><code>fun sayHello() {
      when(idOfFunctionCall) {
          0 -&gt; println(&quot;First call!&quot;)
          1 -&gt; println(&quot;Second call!&quot;)
          else -&gt; println(&quot;Some other call!&quot;)
      }
  }
  </code></pre>
  <p>I want this function to be able to detect the different places in the user's code where this function was called.</p>
  <pre class="lang-kotlin prettyprint-override"><code>// user's code
  fun main() {
      sayHello()
      
      repeat(3) {
        sayHello()
      }
      
      sayHello()
  }
  </code></pre>
  <p>This code should print:</p>
  <pre><code>First call!
  Second call!
  Second call!
  Second call!
  Some other call!
  </code></pre>
  <p>Is that even possible? I'm planning on using the Kotlin Reflection set of tools but I'm not sure if it is possible.</p>