Wanting to Learn

J

Jeremy Yallop

Dik said:
In what way does C fail here?

In that the connection between object and type in C is very weak.
Objects are almost typeless: the type of the expression used to access
the object is the important thing. This is particularly apparent in
the case of the objects for which malloc allocates space:

int max(int x, int y) { return x > y ? x : y; }

void *pv = malloc(max(sizeof(double), sizeof(int)));
sin(*(double *)pv = 3.5); /* the object "has" type double */
abs(*(int *)pv = 3); /* the object "has" type int */

Jeremy.
 
B

Bruno Desthuilliers

Dik said:
Would make Algol 68 a weakly-typed language if you add the following
declaration:
'op'('int','string') + = (('int' i, 'string' s): i);
(Darn, I am forgetting the syntax, the above is probably not entirely
correct.)

Sorry, but Algol 68 is not part of my (small) knowledge !-)

Interesting link, thanks
, I personally
prefer definition 8.

"A language is strongly typed if the type of its data objects is fixed
and does not vary over the lifetime of the object. If the type of a
datum can change, the language is weakly typed."

Well... Almost true for Python ('almost' because it's technically
possible to change the class of an object at runtime, but this is more
of a trick than common use).
>Python does not satisfy quite a few of those 8
definitions.

Is there any way that a language could satisfy the 8 (more or less
mutually exclusives) definitions ?

Language & type theory is really a domain worth of interest. Could
anyone here recommend some good online resource on that subject, so I
have a chance to become a little less stupid before I die ?

Bruno
 
D

Dik T. Winter

> Dik T. Winter wrote: ....
>
> "A language is strongly typed if the type of its data objects is fixed
> and does not vary over the lifetime of the object. If the type of a
> datum can change, the language is weakly typed."
>
> Well... Almost true for Python ('almost' because it's technically
> possible to change the class of an object at runtime, but this is more
> of a trick than common use).

Certainly not true for Python:
a = "1234"
a = 1.5
is valid, it would not be when it was strongly typed according to
definition 8.
 
S

Sidney Cadot

Dik said:
Certainly not true for Python:
a = "1234"
a = 1.5
is valid, it would not be when it was strongly typed according to
definition 8.

You seem to equate "data object" with "variable", no? I'd call "1234"
and 1.5 data objects (that have fixed types). An assignment in Python
just provides a binding of a name to a data object, at least that's how
I view it.

Best regards,

sidney
 
B

Bruno Desthuilliers

Dik said:
Certainly not true for Python:
a = "1234"
a = 1.5
is valid, it would not be when it was strongly typed according to
definition 8.


Yes it is :
"A language is strongly typed if the type of its data objects is fixed,
and does not vary over the lifetime of the object."

The definition does say 'object', not 'identifier referencing an object'.

Python 2.3.2 (#1, Oct 27 2003, 01:23:54)<type 'str'>

As you see, neither the type of "foo" nor the type of 42 have changed.
In Python type info are bound to the object itself, the identifier being
nothing more than... you guessed, an identifier. This does not mean that
the object itself is typeless.

But with your permission, I'll stop here because this is totally OT on
clc !-)
 
D

Dik T. Winter

> Dik T. Winter wrote:
>
>
> You seem to equate "data object" with "variable", no?

No. It depends on how you define "data object", but that is another
discussion. Algol 68 had the clearest distinction between what was
a variable and what was a constant, this distinction is a bit blurred
in other languages. So if I wrote 1, it would be an object of type
int. If I wrote the declaration "int" a;, 'a' would be an object of
type "ref" "int". (Actually, "int" a; was a short-cut for the more
formal "ref" "int" a = "loc" "int", meaning that 'a' was a variable that
could hold values of type int, local to the enclosing construct.) (And
such would make all discussion about l-value irrelevant.) So in this,
the Python statement:
a = "1234"
creates a data object of type "ref" "string" to which is assigned an
object of type "string". Stating later
a = 1.5
makes 'a' a data object of type "ref" "float", a change of type.

This reference stuff in Algol 68 made it abundantly clear which assignments
were allowed and which were not. But we are seriously getting off-topic.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top