title: Kotlin Data Structures and Algorithms
body: <pre><code>fun main() {
  &quot;creating and linking nodes&quot; example {
      val node1 = Node(value = 1)
      val node2 = Node(value = 2)
      val node3 = Node(value = 3)
      node1.next = node2
      node2.next = node3
      println(node1)
  }
  
  &quot;push&quot; example {
      val list = LinkedList&lt;Int&gt;()
      list.push(3)
      list.push(2)
      list.push(1)
      println(list)
  }
  </code></pre>
  <p>}</p>
  <p>So, I'm following Data Structures and Algorithms for Kotlin, First Edition (there's now a Second).</p>
  <p>What does the &quot;creating and linking nodes&quot; example {} or the &quot;push&quot; example {} do, exactly?  It is being rejected by the IDE and is definitely not syntax I've seen.  Is this old syntax, deprecated?  If I just remove it, and keep the code contained within the example{}, it appears to work fine, as intended.  Can anyone tell me why I should or would want to keep this?</p>
  <p>The following works fine, as far as I can tell, and... for now.</p>
  <pre><code>fun main() {
  // &quot;creating and linking nodes&quot; example {}
      val node1 = Node(value = 1)
      val node2 = Node(value = 2)
      val node3 = Node(value = 3)
      node1.next = node2
      node2.next = node3
      println(node1)
  
  
  // &quot;push&quot; example {}
      val list = LinkedList&lt;Int&gt;()
      list.push(3)
      list.push(2)
      list.push(1)
      println(list)
  </code></pre>
  <p>}</p>
  <p><a href="https://i.stack.imgur.com/pmnQr.png" rel="nofollow noreferrer">https://i.stack.imgur.com/pmnQr.png</a>
  <a href="https://i.stack.imgur.com/2vIpR.png" rel="nofollow noreferrer">https://i.stack.imgur.com/2vIpR.png</a></p>
  <p><strong>EDIT:</strong>  Currently the code looks like this, per the suggestion below.  What am I still missing?</p>
  <pre><code>fun main() {
  
  infix fun String.example(block: () -&gt; Unit) : block()
  
  &quot;creating and linking nodes&quot; example {
      val node1 = Node(value = 1)
      val node2 = Node(value = 2)
      val node3 = Node(value = 3)
      node1.next = node2
      node2.next = node3
      println(node1)
  }
  
  
  &quot;push&quot; example {
      val list = LinkedList&lt;Int&gt;()
      list.push(3)
      list.push(2)
      list.push(1)
      println(list)
  }
  </code></pre>
  <p>}</p>
  <p><a href="https://i.stack.imgur.com/ckPjN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ckPjN.png" alt="enter image description here" /></a></p>
  <p><a href="https://i.stack.imgur.com/3SFk3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3SFk3.png" alt="enter image description here" /></a></p>