Find: symbols

Text mode searches the file's text; Symbols mode asks the last compile for names of the kinds you choose. total here is a class, a field, a method (subtotal), a local, and words inside a comment and a String - only the compiler-known ones survive the switch. To play it in the IDE: Help > Lessons > Finding…, or ek9 -ide -lesson find-symbols.

The EK9 IDE as the lesson opens

Start from

The code the lesson starts from: copy it into a file of your own and follow the steps.

shop.ek9

#!ek9
defines module lesson.finding.shop

  defines class

    Total
      total as Integer: 0

      addItem()
        -> price as Integer
        //total grows by one item's price
        total += price

      subtotal() as pure
        <- rtn as Integer: total

      default operator ?

  defines function

    priceLabel() as pure
      -> price as Integer
      <- rtn as String: `Total: ${price}`

    doubled() as pure
      -> price as Integer
      <- rtn as Integer: price * 2

  defines program

    ShowTotal()
      stdout <- Stdout()
      total <- Total()
      total.addItem(5)
      total.addItem(10)
      stdout.println(priceLabel(total.subtotal()))
      stdout.println("The running total is shown above")

//EOF

receipt.ek9

#!ek9
defines module lesson.finding.shop

  defines function

    receiptFooter() as pure
      -> grandTotal as Integer
      <- rtn as String: `Grand total: ${grandTotal}`

  defines program

    ShowReceipt()
      stdout <- Stdout()
      total <- Total()
      total.addItem(20)
      stdout.println(receiptFooter(total.subtotal()))

//EOF

till.ek9

#!ek9
defines module lesson.finding.till

  defines program

    ShowTill()
      stdout <- Stdout()
      total <- 0
      total += 15
      stdout.println(`Till total: ${total}`)

//EOF

Step 1: Text mode, for contrast

Choose Edit > Find…

The EK9 IDE once this is done: Choose Edit > Find…

Type total. In Text mode every one of the 15 places matches, comment and String included.

The EK9 IDE once this is done: Type total

Step 2: Switch to Symbols

Choose Symbols. The comment and the String drop out, and subtotal counts once, as the method it is, not as a text match on part of its name: 12 matches.

The EK9 IDE once this is done: Choose Symbols

Step 3: The three kind chips

Click the Constructs chip to turn it off - the class Total and the program ShowTotal no longer count: 11.

The EK9 IDE once this is done: Click the Constructs chip to turn it off - the class Total and the program ShowTotal no longer count

Click the Variables chip too, leaving only Members - the local total is gone: 7.

The EK9 IDE once this is done: Click the Variables chip too, leaving only Members - the local total is gone

Open the Members chip's own ▾ dropdown and untick constructor - every class shares its constructor's name and places, so this drops the double: the chip now reads Members 3/4, and the count is 5 - just the field and the method.

The EK9 IDE once this is done: Open the Members chip's own ▾ dropdown and untick constructor - every class shares its constructor's name and places, so this drops the double

Step 4: Declared, Read, Written

Turn off Read, leaving Declared and Written - the field's one read, and the method's own call, drop out: 3.

The EK9 IDE once this is done: Turn off Read, leaving Declared and Written - the field's one read, and the method's own call, drop out

Turn off Written too, leaving only Declared - the field's and the method's own declarations: 2.

The EK9 IDE once this is done: Turn off Written too, leaving only Declared - the field's and the method's own declarations

Choose the ✕ (or press Escape) to close the find bar.

The EK9 IDE once this is done: Choose the ✕ (or press Escape) to close the find bar

The result

That is Symbols mode: it asks the last compile, never the text, so a comment or a String never matches, and a name is found and classified by what it IS - a construct, a member or a variable - each with its own chip and dropdown, then narrowed by whether it is declared, read or written. Replace, next, renames what is found here.