Mailing List Archive

word1.word2 notation
I've noticed in various languages, there is a construction
of expressions with a dot in the middle. It is a construction
because the name with a dot in the middle is never explicitly
declared, as in

int foo.bar = 42; // doesn't happen this way

but rather foo is declared in one place and method (or some other
type of entity) bar was declared somewhere else and foo.bar was
always available implicitly as a latent method (or as something).

What is the name of this technique and the name of methods
(or variables ?) so constructed ?

Sorry if this is horribly unclear. Perhaps an example or two would help:

Here's a python example; datfile.readline() is the thing I'm talking about.

> datafile = open("/tmp/words", "r");
> line = datafile.readline()

Here's a visual basic example:

> From MS Word VB Help: SaveAs
> =====
> Saves the specfied document with a new name or format. The arguments for
> this method correspond to the options in the Save As dialog box (File menu).
>
> Syntax
>
> expression.SaveAs(FileName, FileFormat, LockComments, Password,
> AddToRecentFiles, WritePassword, ReadOnlyRecommended, EmbedTrueTypeFonts,
> SaveNativePictureFormat, SaveFormsData, SaveAsAOCELetter)
>
> expression Required. An expression that returns a Document object.
>
> FileName Optional Variant. The name for the document.
> FileFormat Optional Variant. The format in which the document is saved.


squid.
word1.word2 notation [ In reply to ]
In python, 'bar' is called an "attribute" of 'foo' (in the general case).
Note that in python, it *is* possible, and perfectly normal, to write
"foo.bar = 42". This will create attribute 'bar' if it doesn't already
exist, and will hide any inherited binding of 'bar' if 'foo' is a subclass
or an instance.

Yeoh Yiu <squid@panix.com> wrote in message
news:oxgbtbxejea.fsf@panix7.panix.com...
> I've noticed in various languages, there is a construction
> of expressions with a dot in the middle. It is a construction
> because the name with a dot in the middle is never explicitly
> declared, as in
>
> int foo.bar = 42; // doesn't happen this way
>
> but rather foo is declared in one place and method (or some other
> type of entity) bar was declared somewhere else and foo.bar was
> always available implicitly as a latent method (or as something).
>
> What is the name of this technique and the name of methods
> (or variables ?) so constructed ?
word1.word2 notation [ In reply to ]
Yeoh Yiu <squid@panix.com> writes:

> I've noticed in various languages, there is a construction
> of expressions with a dot in the middle. It is a construction
> because the name with a dot in the middle is never explicitly
> declared, as in
>
> int foo.bar = 42; // doesn't happen this way
>
> but rather foo is declared in one place and method (or some other
> type of entity) bar was declared somewhere else and foo.bar was
> always available implicitly as a latent method (or as something).
>
> What is the name of this technique and the name of methods
> (or variables ?) so constructed ?

Hm. Maybe I'm missing something here... But if this question is as
basic as I think, then maybe this will be an adequate answer:

The construction you are referring to is a "member reference". In the
example above, you refer to the member variable "bar" of the object
"bar". In cases in which the member is a function (of - actually, a
method) which is called in the reference, it is called a "method
call", as in:

foo.bar()

You might want to look into how object-oriented programming works in
general to further appreciate the meaning of this.

>
> squid.
>

--

Magnus Making no sound / Yet smouldering with passion
Lie The firefly is still sadder / Than the moaning insect
Hetland : Minamoto Shigeyuki
word1.word2 notation [ In reply to ]
Yeoh Yiu wrote in message ...
>I've noticed in various languages, there is a construction of
expressions with a dot in the middle...
There are also some constructions with a "::" (C++), a "'" (Ada)
and a "!" (Visual Basic). These are similar that they provide a
kind of attribute, but with some sort of variation. As far as I
can remember:
C++ ns::a provides an identifier in a namespace (i.e. the "::" is
resolved at compile time).
Ada x'max [I think] provides a static attribute of "x" such as
the largest value it can take (i.e. the "'" is also resolved at
compile time).
Visual Basic rs!v is used for (among other things?) accessing a
value retrieved from a database. rs.EOF would provide an
attribute of the whole read (whether it is at end).
Hope this helps.

Martin
word1.word2 notation [ In reply to ]
Yeoh Yiu <squid@panix.com> writes:

> I've noticed in various languages, there is a construction
> of expressions with a dot in the middle.
>
> int foo.bar = 42; // doesn't happen this way
>
> What is the name of this technique and the name of methods
> (or variables ?) so constructed ?

The dot construction is merely syntax, and, as you have observed, is
used in different languages. The syntax indicates different semantics
in different languages and therefore has different names.

-paul-
--
Paul E. Black (p.black@acm.org)