Search code examples
eiffellanguage-concepts

In Eiffel, what is the difference between entities, variables, fields and arguments?


I've seen the terms entity, variable, and argument used to describe things about Eiffel, that look quite similar to me, and I wanted to understand what is the intention behind using either term instead of the other.

Arguments — Some routines require some data in order to run. Imagine a fictitious feature foo (x, y: INTEGER; z: BOOLEAN). This routine takes 3 arguments: x, y, and z. When you call the routine, you must give it three valid arguments, for instance foo(6, 92, False). These values we passed to the routine are called actual arguments, while the placeholders defined in the definition are called formal arguments.

I've read of object fields, which specify the place inside the object structure where values are stored (either references or expanded objects).

I think the only time I saw the term variables was for local variables, inside features.

And entity seems to be a generic term for denoting a data-container with a name, so local variables, arguments, and querys (features that return some data) are all examples of entities.

And in what category would Current and Result fall? Local variables?

Could someone help me with the terminology?


Solution

  • Specification

    According to ISO/IEC 25436:2006(E) and newly added language constructs:

    Syntax-based terms

    Local variable is any of the following:

    • an identifier declared in a Local_declarations part (of a feature body, including inline agents)
    • predefined entity Result

    Formal argument:

    • an identifier to represent information passed by callers

    Actual argument:

    • an expression in a particular call to the routine

    Variable attribute is a feature declaration satisfying all of the following:

    • there are no formal arguments
    • there is a query mark (i.e. it has a type)
    • there is no explicit value (i.e. it is not a constant)
    • if there is a body, it is of Attribute kind

    Constant attribute is a feature declaration satisfying all of the following:

    • there are no formal arguments
    • there is a query mark (i.e. it has a type)
    • there is an explicit value

    Collective terms

    Variable is any of the following:

    • a final name of a variable attribute
    • local variable (including Result)

    Read-only entity is any of the following:

    • formal argument
    • object test local
    • cursor local (in Iteration_part of a loop)
    • separate local (in Separate_instruction)
    • constant attribute
    • Current

    Entity is any of the following:

    • variable
    • read-only entity

    Query is any of the following:

    • attribute
    • function

    I.e. a query is a feature that has a type and can be used to get a value at run-time.

    Semantics terms

    Field:

    • a value in a direct instance of a non-basic type, corresponding to an attribute

    Example

    class C feature
       pi: REAL_32 = 3.14
       double (x: LIST [INTEGER]): LIST [INTEGER]
          local
             r: ARRAYED_LIST [INTEGER]
          do
             create r.make (x.count)
             across x as c loop
                r.extend (c.item * 2)
             end
             Result := r
          end
       average_age: NATURAL
       count: NATURAL
       print_list (x: LIST [PERSON])
          do
             average_age := 0
             count := 0
             x.do_all (agent (p: PERSON)
                do
                   if attached p.name as n then
                      io.put_string (n + ": " + p.age.out + "%N")
                      average_age := average_age + p.age
                      count := count + 1
                   end
                end)
              if count > 0 then
                 average_age := average_age // count
              end
          end
    end
    

    Syntax-based terms

    Local variable: r, Result.

    Object test local: n.

    Cursor local: c.

    Formal argument: x, p.

    Actual argument: x.count, 2 (this is an argument for multiplication), c.item * 2, ": " (in string concatenation), p.age.out, "%N", n + ": " + p.age.out + "%N", p.age, 1, 0, count (in division).

    Variable attribute: average_age, count.

    Constant attribute: pi.

    Collective terms

    Variable: r, Result, average_age, count.

    Read-only entity: pi, n, c, x, p.

    Entity: pi, r, Result, average_age, count, n, c, x, p.

    Query: pi, double, average_age, count.