0

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?

g4v3
  • 133
  • 2
  • 10
  • I'll mark @Alexander Kogtenkov's answer as accepted. That answer shows in detail how the terminology is defined by the language specification. I found it *very* clear, and easy to follow. `@Emmanuel Stapf's answer feels more like a wrap-up, complementing the other answer. Reading it right afterwards feels nice, but is not essential for understanding the terminology. – g4v3 Jun 16 '17 at 11:03
  • @Emmanuel Stapf, see the previous comment. – g4v3 Jun 16 '17 at 11:03

2 Answers2

1

You will see clear definitions for those terms in the ECMA Eiffel specification (Standard ECMA-367, section 8: Language specification).

To summarize:

An entity is either: argument, local, attribute (including constant attribute), Current or Result.

A variable is a local or an attribute (not including constant attribute). However, we often count Result as if it was a pseudo locals so it would be ok to call it also a variable, but the standard doesn't.

Note that none of the above includes routines (i.e. procedures or functions, also known as commands and queries in the Eiffel terminology).

g4v3
  • 133
  • 2
  • 10
Emmanuel Stapf
  • 213
  • 1
  • 7
  • In *ECMA-367 (2nd Edition / June 2006)*, in section *"8.8.9 Definition: Local variable"*, it says that *"The local variables of a routine include [...], if it is a query, the predefined entity **Result**."* See also the *Informative text* that follows, for more details. Would you please update your answer? – g4v3 Jun 16 '17 at 11:31
1

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.

Alexander Kogtenkov
  • 5,770
  • 1
  • 27
  • 35
  • Did you forget to include **constant attributes** under **read-only entities**? — I presume that *ISO/IEC 25436:2006(E)* and *ECMA-367 (2nd Edition / June 2006)* have very little difference in content, if any. If section *"8.19.7 Definition: Entity, variable, read-only"* is equal in both documents, then *"Constant attributes [...] are **read-only** entities."* (sic for **bold**). – g4v3 Jun 11 '17 at 03:57
  • @g4v3, yes, thank you for the catch. The text is fixed now, including the example. – Alexander Kogtenkov Jun 11 '17 at 08:28