E01084: prefix operator used in suffix position - place BEFORE expression

Category: E01xxx Parsing and excluded constructs · Reported in phase: PARSING · Classification: PREFIX_OPERATOR_WRONG_POSITION · All error codes

What went wrong

You're using a PREFIX operator in SUFFIX position. PREFIX operators must come BEFORE the expression they operate on.

EK9 has several prefix operators that extract values or transform expressions:

  • #< (first/prefix) - extracts first element: #< list
  • #> (last/suffix) - extracts last element: #> list
  • $ (string) - converts to string: $value
  • $$ (JSON) - converts to JSON: $$value
  • #? (hashcode) - gets the hash code: #? value (the length is 'length')
  • #^ (promote) - type promotion: #^ value
  • ~ (negate/reverse) - negates or reverses: ~ list
  • not (boolean negate) - negates boolean: not condition
  • abs (absolute) - absolute value: abs number
  • sqrt (square root) - square root: sqrt number
  • empty (empty check) - checks if empty: empty collection
  • length (length) - gets length: length collection

Worked examples

Compilable examples demonstrating this error and the correct fix:

  • ek9 -q 794 (Why does EK9 care about operator placement (prefix vs suf...)

Common causes

  • Coming from languages where such operators are postfix (Ruby's .first, .last)
  • Confusing '#<' (prefix/first) naming with its syntactic position
  • Muscle memory from other operator positions

How to fix it

Move the operator to BEFORE the expression:

  • list#< --> #< list
  • value$ --> $value
  • collection#? --> #? collection

Or use the equivalent method call if available.

See also

Examples

Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.

Fails with E01084: prefix operator used in suffix position - place BEFORE expression

#!ek9
defines module error.e01084.bad

  defines function

    firstLetter()
      -> name as String
      <- rtn as Character: name #<

Fixed: Put the prefix operator before the expression: #< name

#!ek9
defines module error.e01084.good

  defines function

    firstLetter()
      -> name as String
      <- rtn as Character: #< name

Questions and answers

These Q&A entries show E01084 and its fix:

Found a problem?

If EK9 reported E01084 for a program you think is valid, or did not report it where it should have, use the compiler form with the smallest program that shows it. If this page is wrong or unclear, use the documentation form. Both are at github.com/ek9lang/ek9-issues.