Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

The more they over-think the plumbing the easier it is to stop up the drain.


devel / comp.lang.misc / Re: OO object layout - method-table pointer or tag

SubjectAuthor
* OO object layout - method-table pointer or tagJames Harris
+* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
|`* Re: OO object layout - method-table pointer or tagJames Harris
| +* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
| |`* Re: OO object layout - method-table pointer or tagJames Harris
| | `* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
| |  `* Re: OO object layout - method-table pointer or tagJames Harris
| |   +* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
| |   |`* Re: OO object layout - method-table pointer or tagJames Harris
| |   | `* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
| |   |  `* Re: OO object layout - method-table pointer or tagJames Harris
| |   |   `* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
| |   |    `* Re: OO object layout - method-table pointer or tagJames Harris
| |   |     `* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
| |   |      `* Re: OO object layout - method-table pointer or tagJames Harris
| |   |       `* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
| |   |        `- Re: OO object layout - method-table pointer or tagJames Harris
| |   `* Re: OO object layout - method-table pointer or tagBart
| |    `* Re: OO object layout - method-table pointer or tagJames Harris
| |     `* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
| |      `* Re: OO object layout - method-table pointer or tagJames Harris
| |       `* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
| |        +* Re: OO object layout - method-table pointer or tagBart
| |        |`* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
| |        | `* Re: OO object layout - method-table pointer or tagBart
| |        |  `* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
| |        |   `* Re: OO object layout - method-table pointer or tagBart
| |        |    `* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
| |        |     `* Re: OO object layout - method-table pointer or tagBart
| |        |      +- Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
| |        |      `* Re: OO object layout - method-table pointer or tagBart
| |        |       `* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
| |        |        `* Re: OO object layout - method-table pointer or tagBart
| |        |         `* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
| |        |          `* Re: OO object layout - method-table pointer or tagBart
| |        |           `* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
| |        |            `- Re: OO object layout - method-table pointer or tagBart
| |        `* Re: OO object layout - method-table pointer or tagJames Harris
| |         `* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
| |          `* Re: OO object layout - method-table pointer or tagJames Harris
| |           `* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
| |            `* Re: OO object layout - method-table pointer or tagJames Harris
| |             `* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
| |              `* Re: OO object layout - method-table pointer or tagJames Harris
| |               `* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
| |                `* Re: OO object layout - method-table pointer or tagJames Harris
| |                 `* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
| |                  `* Re: OO object layout - method-table pointer or tagJames Harris
| |                   `* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
| |                    `* Re: OO object layout - method-table pointer or tagJames Harris
| |                     `* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
| |                      `* Re: OO object layout - method-table pointer or tagJames Harris
| |                       `* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
| |                        `- Re: OO object layout - method-table pointer or tagJames Harris
| `* Re: OO object layout - method-table pointer or tagluserdroog
|  `- Re: OO object layout - method-table pointer or tagJames Harris
+- Re: OO object layout - method-table pointer or tagDavid Brown
`* Re: OO object layout - method-table pointer or tagBart
 `* Re: OO object layout - method-table pointer or tagJames Harris
  +* Re: OO object layout - method-table pointer or tagDavid Brown
  |+- Re: OO object layout - method-table pointer or tagBart
  |`- Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
  `* Re: OO object layout - method-table pointer or tagBart
   `* Re: OO object layout - method-table pointer or tagJames Harris
    `* Re: OO object layout - method-table pointer or tagBart
     +- Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
     `* Re: OO object layout - method-table pointer or tagJames Harris
      `* Re: OO object layout - method-table pointer or tagBart
       `* Re: OO object layout - method-table pointer or tagJames Harris
        `* Re: OO object layout - method-table pointer or tagBart
         `* Re: OO object layout - method-table pointer or tagJames Harris
          +- Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
          `* Re: OO object layout - method-table pointer or tagBart
           +* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
           |`* Re: OO object layout - method-table pointer or tagBart
           | +* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
           | |`* Re: OO object layout - method-table pointer or tagBart
           | | `* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
           | |  `* Re: OO object layout - method-table pointer or tagBart
           | |   `* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
           | |    `* Re: OO object layout - method-table pointer or tagBart
           | |     `* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
           | |      +* Re: OO object layout - method-table pointer or tagBart
           | |      |`* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
           | |      | `* Re: OO object layout - method-table pointer or tagBart
           | |      |  `* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
           | |      |   +* Re: OO object layout - method-table pointer or tagBart
           | |      |   |`* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
           | |      |   | `* Re: OO object layout - method-table pointer or tagBart
           | |      |   |  `* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
           | |      |   |   `* Re: OO object layout - method-table pointer or tagBart
           | |      |   |    `* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
           | |      |   |     `* Re: OO object layout - method-table pointer or tagBart
           | |      |   |      +- Re: OO object layout - method-table pointer or tagMike Austin
           | |      |   |      `- Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
           | |      |   `* Re: OO object layout - method-table pointer or tagJames Harris
           | |      |    `* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
           | |      |     `* Re: OO object layout - method-table pointer or tagJames Harris
           | |      |      `* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
           | |      |       +* Re: OO object layout - method-table pointer or tagJames Harris
           | |      |       |+* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
           | |      |       |`- Re: OO object layout - method-table pointer or tagDavid Brown
           | |      |       `* Re: OO object layout - method-table pointer or tagBart
           | |      `* Re: OO object layout - method-table pointer or tagJames Harris
           | `* Re: OO object layout - method-table pointer or tagJames Harris
           +* Re: OO object layout - method-table pointer or tagDavid Brown
           `* Re: OO object layout - method-table pointer or tagJames Harris

Pages:123456
Re: OO object layout - method-table pointer or tag

<958f462c-96c9-4761-97da-a2a55fe21951n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=848&group=comp.lang.misc#848

  copy link   Newsgroups: comp.lang.misc
X-Received: by 2002:a05:620a:559:: with SMTP id o25mr6532309qko.200.1632193732223;
Mon, 20 Sep 2021 20:08:52 -0700 (PDT)
X-Received: by 2002:a05:622a:202:: with SMTP id b2mr9720103qtx.158.1632193732035;
Mon, 20 Sep 2021 20:08:52 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.misc
Date: Mon, 20 Sep 2021 20:08:51 -0700 (PDT)
In-Reply-To: <sgi9gc$d35$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=97.87.183.68; posting-account=G1KGwgkAAAAyw4z0LxHH0fja6wAbo7Cz
NNTP-Posting-Host: 97.87.183.68
References: <sggjdi$trv$1@dont-email.me> <sggnc4$o9c$2@gioia.aioe.org> <sgi9gc$d35$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <958f462c-96c9-4761-97da-a2a55fe21951n@googlegroups.com>
Subject: Re: OO object layout - method-table pointer or tag
From: mijoryx@yahoo.com (luserdroog)
Injection-Date: Tue, 21 Sep 2021 03:08:52 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 23
 by: luserdroog - Tue, 21 Sep 2021 03:08 UTC

On Monday, August 30, 2021 at 4:47:58 AM UTC-5, James Harris wrote:
> On 29/08/2021 20:32, Dmitry A. Kazakov wrote:
> > On 2021-08-29 20:24, James Harris wrote:
> >
> >> Ignoring the length part (as some objects would have their own length
> >> and some would not but that difference is immaterial here) how would a
> >> 'tag' system be laid out in memory and how would one use that to
> >> locate a method?
> >
> > You must consider the following inheritance variants:
> ...
>
> Thanks for the information, Dmitry. I might come back to you about some
> of that. But for this thread I was wondering how the memory might be
> laid out under the tag model that you mentioned. What form does a tag
> take and how does the runtime get from the tag to a method?
>
> If it depends on which model is in use then what about single
> inheritance and the Full MI model you mentioned?

For TMI on tags and tagging, see Representing Type Information in
Dynamically Typed Languages by David Gudeman.

http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.39.4394&rep=rep1&type=pdf

Re: OO object layout - method-table pointer or tag

<sifeaa$fk2$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=849&group=comp.lang.misc#849

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: james.harris.1@gmail.com (James Harris)
Newsgroups: comp.lang.misc
Subject: Re: OO object layout - method-table pointer or tag
Date: Wed, 22 Sep 2021 15:24:08 +0100
Organization: A noiseless patient Spider
Lines: 144
Message-ID: <sifeaa$fk2$1@dont-email.me>
References: <sggjdi$trv$1@dont-email.me> <sgh09l$r5k$1@dont-email.me>
<sgibii$r5q$1@dont-email.me> <sgihn6$44q$1@dont-email.me>
<sh0ls6$qn6$1@dont-email.me> <sh0ori$cs9$1@dont-email.me>
<shdg1h$k84$1@dont-email.me> <shdima$753$1@dont-email.me>
<shdjv3$g9k$1@dont-email.me> <shdsts$fce$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 22 Sep 2021 14:24:10 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="943cb59ac2f93b94ae46b877a47ee9b3";
logging-data="16002"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/m1x27pLT9kM9Y8z2/zLxnWRtDqkyveXc="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
Cancel-Lock: sha1:tX0Bg0VSVyzMwnWiPqawta4u/3c=
In-Reply-To: <shdsts$fce$1@dont-email.me>
Content-Language: en-GB
 by: James Harris - Wed, 22 Sep 2021 14:24 UTC

On 09/09/2021 22:04, Bart wrote:
> On 09/09/2021 19:32, James Harris wrote:
>> On 09/09/2021 19:10, Bart wrote:
>>> On 09/09/2021 18:25, James Harris wrote:
>>>> On 04/09/2021 22:35, Bart wrote:
>>>>> On 04/09/2021 21:44, James Harris wrote:

....

>>>>>>    type A
>>>>>>      |
>>>>>>    type B

....

>>>> An object of type B has all of A's fields and some of its own.

....

>> So the offsets
>> would not change, and a type B could appear to be a type A.
>
> Where is that written?

Try the following set of slides. They are part of a compilers course and
show how such objects could be implemented, including how they could be
laid out in memory.

http://openclassroom.stanford.edu/MainFolder/courses/Compilers/docs/slides/12-06-object-layout-annotated.pdf

Keeping the fields is a natural consequence of the "is a" relationship
when using static typing. An object of type B _is_ also an object of
type A so it has to be usable wherever an object of type A is usable
and/or has been declared. That's the case even if type B provides new
methods to manipulate A's fields or adds some fields of its own.

To stress, this is about /static/ typing. If using dynamic typing then
the field types /could/ be overridden, and IIUC that's how the
dynamically typed Python works.

There are various permutations but you should find the above slides to
be really helpful in detailing the fundamentals. The full lectures are
probably findable on line, too.

....

> Exactly how different can variant types be? Maybe X is an int, and maybe
> X is an array of structs. Or an array of Variants. What are the
> limitations?

I don't see the need for any limitation on what types could be used but
the permissible types would have to be specified. For example,

typedef T = variant (int # array float # boolean)

(where # separates alternatives and "array float" means an array of
floats).

>
> Staying with my X[i] where X's type is array of Variant elements, they
> could be ints, floats or strings. And maybe i is a 32-int, or 64-bit
> int, or a float.
>
> You need to analyse it each time is is accessed to see if conversion is
> needed.
>
> Also, Variants could presumably be assigned something else of a
> different type? Then you can't even assume it will stay the same type.

Wouldn't code which handles variants typically include a switch on the
type as in the following?

switch T.type
case int:
/* Handle int */
case array float:
/* Handle array of float */
end switch /* Ignoring other cases */

>
>
>>>
>>> Or maybe write some C++ code and see what the compiler generates.
>>
>> Why would I want to do that?!
>
> To see what limitations it places on the possibilities. Or maybe there
> are no limitations and the resulting code is horrendous.

The problem with looking at how another language handles matters is that
it can limit the scope for creativity and tend to lead to the same ideas.

Wouldn't it be better to come up with designs based on how objects and
structures might be laid out and used?

>
> I don't quite understand why you seem to think that dealing with variant
> types is straightforward.

I don't think I ever said it was straightforward.

In fact, IMO the opposite is the case. There's a big language-design
challenge, here. Designers have come up with many ways to match objects
with code:

coercion
overloading
variants
polymorphism
generics
metatypes
macros

It may be better to get rid of some of them and absorb what they can do
into a common approach - as long as it makes programming easier rather
than harder.

>
>
>>>> Frankly, I'd like the programmer to be able to work purely in terms
>>>> of the logic of his algorithm and for the compiler to pick the
>>>> implementation.
>>>
>>> You might be on the verge of switching to a dynamically typed language!
>>>
>>
>> Not me!
>
> If you have a fully flexible Variant type with no limitations, then you
> will de facto have a language that supports dynamic typing.

Indeed! Variants effectively allow a programmer to use dynamically typed
objects in a statically typed language. But variants have the advantage
of letting a programmer restrict which types can be used.

BTW, if anyone is wondering why I haven't yet replied to some other
message in this group I should say it's probably your own fault! You
shouldn't raise so many big issues!

--
James Harris

Re: OO object layout - method-table pointer or tag

<sifimt$pme$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=850&group=comp.lang.misc#850

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!aioe.org!x6YkKUCkj2qHLwbKnVEeag.user.46.165.242.91.POSTED!not-for-mail
From: mailbox@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.misc
Subject: Re: OO object layout - method-table pointer or tag
Date: Wed, 22 Sep 2021 17:39:11 +0200
Organization: Aioe.org NNTP Server
Message-ID: <sifimt$pme$1@gioia.aioe.org>
References: <sggjdi$trv$1@dont-email.me> <sgh09l$r5k$1@dont-email.me>
<sgibii$r5q$1@dont-email.me> <sgihn6$44q$1@dont-email.me>
<sh0ls6$qn6$1@dont-email.me> <sh0ori$cs9$1@dont-email.me>
<shdg1h$k84$1@dont-email.me> <shdima$753$1@dont-email.me>
<shdjv3$g9k$1@dont-email.me> <shdsts$fce$1@dont-email.me>
<sifeaa$fk2$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="26318"; posting-host="x6YkKUCkj2qHLwbKnVEeag.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.14.0
Content-Language: en-US
X-Notice: Filtered by postfilter v. 0.9.2
 by: Dmitry A. Kazakov - Wed, 22 Sep 2021 15:39 UTC

On 2021-09-22 16:24, James Harris wrote:

> Try the following set of slides. They are part of a compilers course and
> show how such objects could be implemented, including how they could be
> laid out in memory.
>
> http://openclassroom.stanford.edu/MainFolder/courses/Compilers/docs/slides/12-06-object-layout-annotated.pdf

A quite poor introduction that does not even cover multiple inheritance.

> Keeping the fields is a natural consequence of the "is a" relationship
> when using static typing. An object of type B _is_ also an object of
> type A so it has to be usable wherever an object of type A is usable
> and/or has been declared.

Not quite. Is-a = substitutable, is a member of same class. B is not A,
it can fake A.

The means of substitutution may differ. If B contains a representation
of A, then substitution could be a mere reference shift. This why
languages tend to limit inheritance to extension only and pass tagged
objects by reference.

Otherwise, to achieve substitution you would need to create a new object
A from B. In C and C++ implicit conversions are that sort of is-a
relationship, e.g. float is-a double.

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

Re: OO object layout - method-table pointer or tag

<sig193$u9$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=851&group=comp.lang.misc#851

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: bc@freeuk.com (Bart)
Newsgroups: comp.lang.misc
Subject: Re: OO object layout - method-table pointer or tag
Date: Wed, 22 Sep 2021 20:47:41 +0100
Organization: A noiseless patient Spider
Lines: 72
Message-ID: <sig193$u9$1@dont-email.me>
References: <sggjdi$trv$1@dont-email.me> <sgh09l$r5k$1@dont-email.me>
<sgibii$r5q$1@dont-email.me> <sgihn6$44q$1@dont-email.me>
<sh0ls6$qn6$1@dont-email.me> <sh0ori$cs9$1@dont-email.me>
<shdg1h$k84$1@dont-email.me> <shdima$753$1@dont-email.me>
<shdjv3$g9k$1@dont-email.me> <shdsts$fce$1@dont-email.me>
<sifeaa$fk2$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 22 Sep 2021 19:47:48 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="86123b6b6f4b8e647c202aca75c927f6";
logging-data="969"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19ecmbvWnnLq5rAf+4diByHJ0uM9/7eIso="
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:lP/gIWvmRqayvMACWHasgVi/EI4=
In-Reply-To: <sifeaa$fk2$1@dont-email.me>
X-Antivirus-Status: Clean
Content-Language: en-GB
X-Antivirus: AVG (VPS 210922-2, 22/9/2021), Outbound message
 by: Bart - Wed, 22 Sep 2021 19:47 UTC

On 22/09/2021 15:24, James Harris wrote:
> On 09/09/2021 22:04, Bart wrote:

>> Also, Variants could presumably be assigned something else of a
>> different type? Then you can't even assume it will stay the same type.
>
> Wouldn't code which handles variants typically include a switch on the
> type as in the following?
>
>   switch T.type
>     case int:
>       /* Handle int */
>     case array float:
>       /* Handle array of float */
>   end switch /* Ignoring other cases */

You need to show an example of source code where such types are used,
and see that the generated code might be like.

But let's take your example:

type U = int |[]float

U a, b, c

a := b + c

Here, it knows that b and c are both of type U, but doesn't know - at
compile-time - whether they are ints or arrays.

So just to do b+c, it will need 2-way dispatch:

int temp
if b.type=c.type=int then # Hey, a chained compare example!
temp = b.ivalue+c.ivalue
else
.... # error? Unless "+" is defined for float arrays, array+iny
end

Now to assign result to a:

if a.type=float_array then
// destroy resources, or decr reference count for array
end

a.type = int
a.ivalue = temp

And that's just for one valid combination, and one type of temp, so that
'a' is only ever going to be assigned an int. How about:

type U = int32 | int64 | float32 | float64

U a, b, c, d, e

a = b*c + d*e

All 16 combinations of types should be valid, but do you want to try
writing the switch statements for them?

I don't think this amount of boilerplate is practical to write as inline
code.

You should however try doing so for example fragments of code to see as
I suggested to see what is involved.

This type of variant means that:

a := a[i]

could be legal. Anything goes.

Re: OO object layout - method-table pointer or tag

<sig81s$132j$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=852&group=comp.lang.misc#852

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!aioe.org!x6YkKUCkj2qHLwbKnVEeag.user.46.165.242.91.POSTED!not-for-mail
From: mailbox@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.misc
Subject: Re: OO object layout - method-table pointer or tag
Date: Wed, 22 Sep 2021 23:43:26 +0200
Organization: Aioe.org NNTP Server
Message-ID: <sig81s$132j$1@gioia.aioe.org>
References: <sggjdi$trv$1@dont-email.me> <sgh09l$r5k$1@dont-email.me>
<sgibii$r5q$1@dont-email.me> <sgihn6$44q$1@dont-email.me>
<sh0ls6$qn6$1@dont-email.me> <sh0ori$cs9$1@dont-email.me>
<shdg1h$k84$1@dont-email.me> <shdima$753$1@dont-email.me>
<shdjv3$g9k$1@dont-email.me> <shdsts$fce$1@dont-email.me>
<sifeaa$fk2$1@dont-email.me> <sig193$u9$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="35923"; posting-host="x6YkKUCkj2qHLwbKnVEeag.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.14.0
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: en-US
 by: Dmitry A. Kazakov - Wed, 22 Sep 2021 21:43 UTC

On 2021-09-22 21:47, Bart wrote:
> On 22/09/2021 15:24, James Harris wrote:
>> On 09/09/2021 22:04, Bart wrote:
>
>>> Also, Variants could presumably be assigned something else of a
>>> different type? Then you can't even assume it will stay the same type.
>>
>> Wouldn't code which handles variants typically include a switch on the
>> type as in the following?
>>
>>    switch T.type
>>      case int:
>>        /* Handle int */
>>      case array float:
>>        /* Handle array of float */
>>    end switch /* Ignoring other cases */
>
> You need to show an example of source code where such types are used,

Come on, is that a joke?

https://docs.microsoft.com/en-us/windows/win32/api/oaidl/ns-oaidl-variant

http://documentation.unified-automation.com/uasdkcpp/1.5.2/html/structOpcUa__Variant.html

https://en.wikipedia.org/wiki/Tagged_union

https://zone.ni.com/reference/en-XX/help/371361R-01/lvhowto/variants/

Next you will ask for examples of loops?

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

Re: OO object layout - method-table pointer or tag

<sig9qd$s98$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=853&group=comp.lang.misc#853

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: bc@freeuk.com (Bart)
Newsgroups: comp.lang.misc
Subject: Re: OO object layout - method-table pointer or tag
Date: Wed, 22 Sep 2021 23:13:26 +0100
Organization: A noiseless patient Spider
Lines: 91
Message-ID: <sig9qd$s98$1@dont-email.me>
References: <sggjdi$trv$1@dont-email.me> <sgh09l$r5k$1@dont-email.me>
<sgibii$r5q$1@dont-email.me> <sgihn6$44q$1@dont-email.me>
<sh0ls6$qn6$1@dont-email.me> <sh0ori$cs9$1@dont-email.me>
<shdg1h$k84$1@dont-email.me> <shdima$753$1@dont-email.me>
<shdjv3$g9k$1@dont-email.me> <shdsts$fce$1@dont-email.me>
<sifeaa$fk2$1@dont-email.me> <sig193$u9$1@dont-email.me>
<sig81s$132j$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 22 Sep 2021 22:13:33 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="5587deda23d0b50a5b9d72dcb063de09";
logging-data="28968"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/1WZUD+PC0+p/Ca2rc2Cwq1+4w+DtJQSc="
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:vWCxNtAAwBpMoLIRiw8nMZoh9Ps=
In-Reply-To: <sig81s$132j$1@gioia.aioe.org>
X-Antivirus-Status: Clean
Content-Language: en-GB
X-Antivirus: AVG (VPS 210922-8, 22/9/2021), Outbound message
 by: Bart - Wed, 22 Sep 2021 22:13 UTC

On 22/09/2021 22:43, Dmitry A. Kazakov wrote:
> On 2021-09-22 21:47, Bart wrote:
>> On 22/09/2021 15:24, James Harris wrote:
>>> On 09/09/2021 22:04, Bart wrote:
>>
>>>> Also, Variants could presumably be assigned something else of a
>>>> different type? Then you can't even assume it will stay the same type.
>>>
>>> Wouldn't code which handles variants typically include a switch on
>>> the type as in the following?
>>>
>>>    switch T.type
>>>      case int:
>>>        /* Handle int */
>>>      case array float:
>>>        /* Handle array of float */
>>>    end switch /* Ignoring other cases */
>>
>> You need to show an example of source code where such types are used,
>
> Come on, is that a joke?
>
> https://docs.microsoft.com/en-us/windows/win32/api/oaidl/ns-oaidl-variant
>
> http://documentation.unified-automation.com/uasdkcpp/1.5.2/html/structOpcUa__Variant.html
>
>
> https://en.wikipedia.org/wiki/Tagged_union
>
> https://zone.ni.com/reference/en-XX/help/371361R-01/lvhowto/variants/
>
> Next you will ask for examples of loops?
>

So where are the actual examples of using those variants? What are the
capabilities? How are those capabilities implemented: what code is
generated, how much is generated, and how efficient is it?

'Variants' seem to be mean lots of different things.

I've used them for 35 years within dynamic scripting languages, so I
know the answers for my own code. But I assume the context here is for a
static language or perhaps one with type inference.

That Switch example is meaningless without knowing what operation is
being performed in the source code, hence the request for the
corresponding fragment of source code.

Or perhaps you can tell just from the example?

I'm played with variants in my static language, but they have now been
dropped; they were too difficult to deal with in the general case (eg.
arbitrary lists of elements that can be variants and also arbitrary
lists....).

But this fragment of code from an old version, where 'variant' can be
any /object/ type (ie. one implemented as a reference to a
reference-counted descriptor):

variant a, b, c
a := b + c

generated this x64 code (not ABI-compliant):

lea D0, [Dframe+-8]
push D0
call [L5] # init a
lea D0, [Dframe+-16]
push D0
call [L5] # init b
lea D0, [Dframe+-24]
push D0
call [L5] # init c

mov D0, [Dframe+-16] # 'push b'
inc word32 [D0] # step ref count
mov D1, [Dframe+-24] # 'push c'
inc word32 [D1] # step ref count
push D0
push D1
call [L6] # addvar(b, c)
lea D1, [Dframe+-8] # &a
push D0
push D1
call [L7] # 'pop 'a'

So it's all done with function calls; little inline code. And it's
inefficient.

But that's how /I/ did it. This might not be what James has in mind.

Re: OO object layout - method-table pointer or tag

<sih996$1jj$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=854&group=comp.lang.misc#854

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: david.brown@hesbynett.no (David Brown)
Newsgroups: comp.lang.misc
Subject: Re: OO object layout - method-table pointer or tag
Date: Thu, 23 Sep 2021 09:10:30 +0200
Organization: A noiseless patient Spider
Lines: 142
Message-ID: <sih996$1jj$1@dont-email.me>
References: <sggjdi$trv$1@dont-email.me> <sgh09l$r5k$1@dont-email.me>
<sgibii$r5q$1@dont-email.me> <sgihn6$44q$1@dont-email.me>
<sh0ls6$qn6$1@dont-email.me> <sh0ori$cs9$1@dont-email.me>
<shdg1h$k84$1@dont-email.me> <shdima$753$1@dont-email.me>
<shdjv3$g9k$1@dont-email.me> <shdsts$fce$1@dont-email.me>
<sifeaa$fk2$1@dont-email.me> <sig193$u9$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 23 Sep 2021 07:10:30 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="df1de3da7f3d53b744f0694117cccf7f";
logging-data="1651"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+0BDkiLjpx/1iQxu03Wpwx7owH3ACqBF4="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:hDBPrHwTlqUiDyM99GZvJjsXWEI=
In-Reply-To: <sig193$u9$1@dont-email.me>
Content-Language: en-GB
 by: David Brown - Thu, 23 Sep 2021 07:10 UTC

On 22/09/2021 21:47, Bart wrote:
> On 22/09/2021 15:24, James Harris wrote:
>> On 09/09/2021 22:04, Bart wrote:
>
>>> Also, Variants could presumably be assigned something else of a
>>> different type? Then you can't even assume it will stay the same type.
>>
>> Wouldn't code which handles variants typically include a switch on the
>> type as in the following?
>>
>>    switch T.type
>>      case int:
>>        /* Handle int */
>>      case array float:
>>        /* Handle array of float */
>>    end switch /* Ignoring other cases */
>
> You need to show an example of source code where such types are used,
> and see that the generated code might be like.
>

Variant types are typically implemented by having a "type" field - an
integer that says which of the allowed types is currently valid. In
C++, this is std::variant. In Pascal, it is a "tagged union" or
"variant record".

In C, you might have :

typedef struct {
enum { T_is_int, T_is_float } type_index;
union {
int int_value;
float float_value;
}
} T;
switch (t.type_index) {
case T_is_int :
// Use t.int_value
break;
case T_is_float :
// Use t.float_value
break;
}

You can produce similar code in any language. Variant types are not
magic, but of course there is plenty of scope for making them neater and
safer than in C! (It doesn't have to be part of the language - with a
powerful enough language, they can be part of the library.)

And compilers can optimise their knowledge of the type stored to reduce
storing or checking "type_index" as much as possible.

> But let's take your example:
>
>    type U = int |[]float
>
>    U a, b, c
>
>    a := b + c
>
> Here, it knows that b and c are both of type U, but doesn't know - at
> compile-time - whether they are ints or arrays.
>
> So just to do b+c, it will need 2-way dispatch:
>
>
>   int temp
>   if b.type=c.type=int then        # Hey, a chained compare example!
>      temp = b.ivalue+c.ivalue
>   else
>     .... # error? Unless "+" is defined for float arrays, array+iny
>   end
>
> Now to assign result to a:
>
>   if a.type=float_array then
>      // destroy resources, or decr reference count for array
>   end
>
>   a.type = int
>   a.ivalue = temp
>
> And that's just for one valid combination, and one type of temp, so that
> 'a' is only ever going to be assigned an int. How about:
>
>   type U = int32 | int64 | float32 | float64
>
>   U a, b, c, d, e
>
>   a = b*c + d*e
>
> All 16 combinations of types should be valid, but do you want to try
> writing the switch statements for them?
> > I don't think this amount of boilerplate is practical to write as inline
> code.

If you write impractical code, you must expect inefficient results.

It is not common for constructed types to automatically inherit support
for operations or functions from their parts. An array of floats does
not inherit addition from float, a struct of 3 ints does not inherit
multiplication from its constituent ints. A variant or tagged union
does not (in most languages or libraries) inherit arithmetic operations
from its parts even if they all support them individually.

So the programmer who makes the U type, decides what is sensible to do
with elements of the type. /They/ decide which combinations are
allowed, and how they are implemented.

(A helpful language might also generate some of the boilerplate code
automatically.)

Of course, a variant like your example here is unlikely to be found in
real code. Some more likely examples could be a type that can hold a
valid result or an error number:

type Result = Value int | Error int

A binomial "Tree" might be a leaf with a string, or a node with two
branches :

type Tree = Leaf string | Node Tree Tree

In more theoretical programming (such as with functional programming
languages), such "sum types" are as important as "product types", which
you know of as structs or records.

>
> You should however try doing so for example fragments of code to see as
> I suggested to see what is involved.
>
> This type of variant means that:
>
>    a := a[i]
>
> could be legal. Anything goes.

Anything the programmer decides to allow and support, goes.

Re: OO object layout - method-table pointer or tag

<sihgh0$bsr$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=855&group=comp.lang.misc#855

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!aioe.org!x6YkKUCkj2qHLwbKnVEeag.user.46.165.242.91.POSTED!not-for-mail
From: mailbox@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.misc
Subject: Re: OO object layout - method-table pointer or tag
Date: Thu, 23 Sep 2021 11:14:08 +0200
Organization: Aioe.org NNTP Server
Message-ID: <sihgh0$bsr$1@gioia.aioe.org>
References: <sggjdi$trv$1@dont-email.me> <sgh09l$r5k$1@dont-email.me>
<sgibii$r5q$1@dont-email.me> <sgihn6$44q$1@dont-email.me>
<sh0ls6$qn6$1@dont-email.me> <sh0ori$cs9$1@dont-email.me>
<shdg1h$k84$1@dont-email.me> <shdima$753$1@dont-email.me>
<shdjv3$g9k$1@dont-email.me> <shdsts$fce$1@dont-email.me>
<sifeaa$fk2$1@dont-email.me> <sig193$u9$1@dont-email.me>
<sig81s$132j$1@gioia.aioe.org> <sig9qd$s98$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="12187"; posting-host="x6YkKUCkj2qHLwbKnVEeag.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.14.0
Content-Language: en-US
X-Notice: Filtered by postfilter v. 0.9.2
 by: Dmitry A. Kazakov - Thu, 23 Sep 2021 09:14 UTC

On 2021-09-23 00:13, Bart wrote:

> That Switch example is meaningless without knowing what operation is
> being performed in the source code, hence the request for the
> corresponding fragment of source code.

The predefined operations should be:

1. Equality/inequality
2. Access to the constraint (the selector value, read-only)
3. Member access (the variant value, read/write)
4. Aggregate (literal value)
5. Assignment as a whole, IFF variant is definite, otherwise, no assignment.

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

Re: OO object layout - method-table pointer or tag

<sihhun$qpj$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=856&group=comp.lang.misc#856

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: bc@freeuk.com (Bart)
Newsgroups: comp.lang.misc
Subject: Re: OO object layout - method-table pointer or tag
Date: Thu, 23 Sep 2021 10:38:23 +0100
Organization: A noiseless patient Spider
Lines: 98
Message-ID: <sihhun$qpj$1@dont-email.me>
References: <sggjdi$trv$1@dont-email.me> <sgh09l$r5k$1@dont-email.me>
<sgibii$r5q$1@dont-email.me> <sgihn6$44q$1@dont-email.me>
<sh0ls6$qn6$1@dont-email.me> <sh0ori$cs9$1@dont-email.me>
<shdg1h$k84$1@dont-email.me> <shdima$753$1@dont-email.me>
<shdjv3$g9k$1@dont-email.me> <shdsts$fce$1@dont-email.me>
<sifeaa$fk2$1@dont-email.me> <sig193$u9$1@dont-email.me>
<sig81s$132j$1@gioia.aioe.org> <sig9qd$s98$1@dont-email.me>
<sihgh0$bsr$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 23 Sep 2021 09:38:31 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="5587deda23d0b50a5b9d72dcb063de09";
logging-data="27443"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19OlX0LtJssWB+jZYRjKGI3JdS+uU1Nt/s="
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:uvkB7RXzd6oBIM1kK1qsGvD+mCE=
In-Reply-To: <sihgh0$bsr$1@gioia.aioe.org>
X-Antivirus-Status: Clean
Content-Language: en-GB
X-Antivirus: AVG (VPS 210923-0, 23/9/2021), Outbound message
 by: Bart - Thu, 23 Sep 2021 09:38 UTC

On 23/09/2021 10:14, Dmitry A. Kazakov wrote:
> On 2021-09-23 00:13, Bart wrote:
>
>> That Switch example is meaningless without knowing what operation is
>> being performed in the source code, hence the request for the
>> corresponding fragment of source code.
>
> The predefined operations should be:
>
> 1. Equality/inequality
> 2. Access to the constraint (the selector value, read-only)
> 3. Member access (the variant value, read/write)
> 4. Aggregate (literal value)
> 5. Assignment as a whole, IFF variant is definite, otherwise, no
> assignment.

But you can't do A+B? See, this is the sort of information which needs
to be explicitly stated: what sort of 'variant' are we talking about;
what are the possibilities, and what even source code might look like.

What do you have to do in a language with YOUR idea of a variant, in
order to evaluate A+B? Assuming it can be done, what goes on behind the
scenes?

If you have a variant which can include suitable types, tell me why any
of the following operations, which I generally allow, should not apply
to variants.

In your first link, there is a variant record shown with 50 different
types. A user-defined one could have more than that, including user
defined types.

add
sub
mul
div
idiv
irem
iand
ior
ixor
and
or
shl
shr
eq
ne
lt
le
ge
gt
neg
abs
inot
not
sqrt
sin
cos etc
conversions
indexing
slicing
bit indexing
bitfield slicing
member selection
call
len
lwb/upb
minvalue/maxvalue
switch index
in/not in
min/max

addto (augmented assignmnt)
subto
multo
divto
idivto
iremto
iandto
iorto
ixorto
andto
orto
shlto
shrto
negto
absto
inotto
notto
incr
decr
minto/maxto

Oh, and assignment. And sort(). And dozens of other operations usually
implemented as library functions rather than as built-in ops.

Re: OO object layout - method-table pointer or tag

<sihist$15j$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=857&group=comp.lang.misc#857

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: bc@freeuk.com (Bart)
Newsgroups: comp.lang.misc
Subject: Re: OO object layout - method-table pointer or tag
Date: Thu, 23 Sep 2021 10:54:29 +0100
Organization: A noiseless patient Spider
Lines: 78
Message-ID: <sihist$15j$1@dont-email.me>
References: <sggjdi$trv$1@dont-email.me> <sgh09l$r5k$1@dont-email.me>
<sgibii$r5q$1@dont-email.me> <sgihn6$44q$1@dont-email.me>
<sh0ls6$qn6$1@dont-email.me> <sh0ori$cs9$1@dont-email.me>
<shdg1h$k84$1@dont-email.me> <shdima$753$1@dont-email.me>
<shdjv3$g9k$1@dont-email.me> <shdsts$fce$1@dont-email.me>
<sifeaa$fk2$1@dont-email.me> <sig193$u9$1@dont-email.me>
<sih996$1jj$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 23 Sep 2021 09:54:37 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="5587deda23d0b50a5b9d72dcb063de09";
logging-data="1203"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/5B4DvOAU8Z1rJdnWUNPWkjTELkpyR0Zk="
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:g299TMjzoM8Bo0zbxt+mCXzJFD4=
In-Reply-To: <sih996$1jj$1@dont-email.me>
X-Antivirus-Status: Clean
Content-Language: en-GB
X-Antivirus: AVG (VPS 210923-0, 23/9/2021), Outbound message
 by: Bart - Thu, 23 Sep 2021 09:54 UTC

On 23/09/2021 08:10, David Brown wrote:
> On 22/09/2021 21:47, Bart wrote:
>> On 22/09/2021 15:24, James Harris wrote:
>>> On 09/09/2021 22:04, Bart wrote:
>>
>>>> Also, Variants could presumably be assigned something else of a
>>>> different type? Then you can't even assume it will stay the same type.
>>>
>>> Wouldn't code which handles variants typically include a switch on the
>>> type as in the following?
>>>
>>>    switch T.type
>>>      case int:
>>>        /* Handle int */
>>>      case array float:
>>>        /* Handle array of float */
>>>    end switch /* Ignoring other cases */
>>
>> You need to show an example of source code where such types are used,
>> and see that the generated code might be like.
>>
>
> Variant types are typically implemented by having a "type" field - an
> integer that says which of the allowed types is currently valid. In
> C++, this is std::variant. In Pascal, it is a "tagged union" or
> "variant record".
>
> In C, you might have :
>
> typedef struct {
> enum { T_is_int, T_is_float } type_index;
> union {
> int int_value;
> float float_value;
> }
> } T;
>
> switch (t.type_index) {
> case T_is_int :
> // Use t.int_value
> break;
> case T_is_float :
> // Use t.float_value
> break;
> }
>

No one has yet explained exactly what kind of variant they are talking
about.

You're assuming it is just a tagged union or sumtype, where all you can
do is write explicit code to extract one of the possible values.

Or if you try and use one of those values directly (t.int_value) the
compiler will perform a behind the scenes check that it is an int.

The C++ variant might do a little bit more.

The kind of variant I've used in dynamic code is considerably more powerful:

for x in (100, 23.4, "cat", 50..60, [7,8,9], (100,110,120)) do
println x.type, "\t", x
end

Here, 'x' is a variant type (actually, everything is), and can store
/anything/. The output of this program is:

int 100
real 23.400000
string cat
range 50..60
set [7..9]
list (100,110,120)

I assumed James was talking about the kind of variant which can only
represent a predefined set of types, and which was to be implemented in
static code.

Re: OO object layout - method-table pointer or tag

<sihkhe$53k$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=858&group=comp.lang.misc#858

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!aioe.org!x6YkKUCkj2qHLwbKnVEeag.user.46.165.242.91.POSTED!not-for-mail
From: mailbox@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.misc
Subject: Re: OO object layout - method-table pointer or tag
Date: Thu, 23 Sep 2021 12:22:38 +0200
Organization: Aioe.org NNTP Server
Message-ID: <sihkhe$53k$1@gioia.aioe.org>
References: <sggjdi$trv$1@dont-email.me> <sgh09l$r5k$1@dont-email.me>
<sgibii$r5q$1@dont-email.me> <sgihn6$44q$1@dont-email.me>
<sh0ls6$qn6$1@dont-email.me> <sh0ori$cs9$1@dont-email.me>
<shdg1h$k84$1@dont-email.me> <shdima$753$1@dont-email.me>
<shdjv3$g9k$1@dont-email.me> <shdsts$fce$1@dont-email.me>
<sifeaa$fk2$1@dont-email.me> <sig193$u9$1@dont-email.me>
<sig81s$132j$1@gioia.aioe.org> <sig9qd$s98$1@dont-email.me>
<sihgh0$bsr$1@gioia.aioe.org> <sihhun$qpj$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="5236"; posting-host="x6YkKUCkj2qHLwbKnVEeag.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.14.0
Content-Language: en-US
X-Notice: Filtered by postfilter v. 0.9.2
 by: Dmitry A. Kazakov - Thu, 23 Sep 2021 10:22 UTC

On 2021-09-23 11:38, Bart wrote:
> On 23/09/2021 10:14, Dmitry A. Kazakov wrote:
>> On 2021-09-23 00:13, Bart wrote:
>>
>>> That Switch example is meaningless without knowing what operation is
>>> being performed in the source code, hence the request for the
>>> corresponding fragment of source code.
>>
>> The predefined operations should be:
>>
>> 1. Equality/inequality
>> 2. Access to the constraint (the selector value, read-only)
>> 3. Member access (the variant value, read/write)
>> 4. Aggregate (literal value)
>> 5. Assignment as a whole, IFF variant is definite, otherwise, no
>> assignment.
>
> But you can't do A+B?

Because it is not defined. If the programmer wants "+", Foo, Boo he can
declare and implement them as with any other type.

> What do you have to do in a language with YOUR idea of a variant, in
> order to evaluate A+B? Assuming it can be done, what goes on behind the
> scenes?

Nothing. What you see is what you get.

> If you have a variant which can include suitable types, tell me why any
> of the following operations, which I generally allow, should not apply
> to variants.

Tell me why they should. Days of PL/1 are gone.

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

Re: OO object layout - method-table pointer or tag

<sihkuo$h1j$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=859&group=comp.lang.misc#859

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!aioe.org!x6YkKUCkj2qHLwbKnVEeag.user.46.165.242.91.POSTED!not-for-mail
From: mailbox@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.misc
Subject: Re: OO object layout - method-table pointer or tag
Date: Thu, 23 Sep 2021 12:29:44 +0200
Organization: Aioe.org NNTP Server
Message-ID: <sihkuo$h1j$1@gioia.aioe.org>
References: <sggjdi$trv$1@dont-email.me> <sgh09l$r5k$1@dont-email.me>
<sgibii$r5q$1@dont-email.me> <sgihn6$44q$1@dont-email.me>
<sh0ls6$qn6$1@dont-email.me> <sh0ori$cs9$1@dont-email.me>
<shdg1h$k84$1@dont-email.me> <shdima$753$1@dont-email.me>
<shdjv3$g9k$1@dont-email.me> <shdsts$fce$1@dont-email.me>
<sifeaa$fk2$1@dont-email.me> <sig193$u9$1@dont-email.me>
<sih996$1jj$1@dont-email.me> <sihist$15j$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="17459"; posting-host="x6YkKUCkj2qHLwbKnVEeag.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.14.0
Content-Language: en-US
X-Notice: Filtered by postfilter v. 0.9.2
 by: Dmitry A. Kazakov - Thu, 23 Sep 2021 10:29 UTC

On 2021-09-23 11:54, Bart wrote:

> You're assuming it is just a tagged union or sumtype, where all you can
> do is write explicit code to extract one of the possible values.

Why there should be more?

If you want more, you must tell that in the language. For this you need
subtypes (that pesky polymorhpism), e.g. variant being a subtype of the
type of some/all of its members.

It is the stuff you are unwilling to support, telling us that you do not
need it. Why asking then?

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

Re: OO object layout - method-table pointer or tag

<sihlib$j6l$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=860&group=comp.lang.misc#860

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: bc@freeuk.com (Bart)
Newsgroups: comp.lang.misc
Subject: Re: OO object layout - method-table pointer or tag
Date: Thu, 23 Sep 2021 11:40:03 +0100
Organization: A noiseless patient Spider
Lines: 67
Message-ID: <sihlib$j6l$1@dont-email.me>
References: <sggjdi$trv$1@dont-email.me> <sgh09l$r5k$1@dont-email.me>
<sgibii$r5q$1@dont-email.me> <sgihn6$44q$1@dont-email.me>
<sh0ls6$qn6$1@dont-email.me> <sh0ori$cs9$1@dont-email.me>
<shdg1h$k84$1@dont-email.me> <shdima$753$1@dont-email.me>
<shdjv3$g9k$1@dont-email.me> <shdsts$fce$1@dont-email.me>
<sifeaa$fk2$1@dont-email.me> <sig193$u9$1@dont-email.me>
<sig81s$132j$1@gioia.aioe.org> <sig9qd$s98$1@dont-email.me>
<sihgh0$bsr$1@gioia.aioe.org> <sihhun$qpj$1@dont-email.me>
<sihkhe$53k$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 23 Sep 2021 10:40:11 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="5587deda23d0b50a5b9d72dcb063de09";
logging-data="19669"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19GF8LeA4d4+lEliCAPPXdJmBF3psAB0AI="
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:Ex3esby5eBcpzAX09sh8n3En1wI=
In-Reply-To: <sihkhe$53k$1@gioia.aioe.org>
X-Antivirus-Status: Clean
Content-Language: en-GB
X-Antivirus: AVG (VPS 210923-0, 23/9/2021), Outbound message
 by: Bart - Thu, 23 Sep 2021 10:40 UTC

On 23/09/2021 11:22, Dmitry A. Kazakov wrote:
> On 2021-09-23 11:38, Bart wrote:
>> On 23/09/2021 10:14, Dmitry A. Kazakov wrote:
>>> On 2021-09-23 00:13, Bart wrote:
>>>
>>>> That Switch example is meaningless without knowing what operation is
>>>> being performed in the source code, hence the request for the
>>>> corresponding fragment of source code.
>>>
>>> The predefined operations should be:
>>>
>>> 1. Equality/inequality
>>> 2. Access to the constraint (the selector value, read-only)
>>> 3. Member access (the variant value, read/write)
>>> 4. Aggregate (literal value)
>>> 5. Assignment as a whole, IFF variant is definite, otherwise, no
>>> assignment.
>>
>> But you can't do A+B?
>
> Because it is not defined. If the programmer wants "+", Foo, Boo he can
> declare and implement them as with any other type.

Show me. Let's say with a variant that can be an Integer, or a String.

And let's say that "+" is defined between two such variants when they
contain integers.

What does the source code look like to make it possible. And what will
the behind-the-scenes code be?

Assume that what the user wants to do is something like this:

Variant (String | Int) a, b, c

b := 200
c := 300
.... undisclosed code
a := b + c

print a

Would that be possible? What should it do when 'c' is set to a string?

>> What do you have to do in a language with YOUR idea of a variant, in
>> order to evaluate A+B? Assuming it can be done, what goes on behind
>> the scenes?
>
> Nothing. What you see is what you get.
>
>> If you have a variant which can include suitable types, tell me why
>> any of the following operations, which I generally allow, should not
>> apply to variants.
>
> Tell me why they should. Days of PL/1 are gone.

Most languages allows all those ops, or a big subset.

You seem to be saying that A+B is allowed when A and B are both int types.

But not when A and B are variant types, even if that type is (Int |
Real), not without a lot of work.

Then that's not a Variant type as I understand it. It's just a union or
tagged union, a much cruder type.

Re: OO object layout - method-table pointer or tag

<sihnke$1qln$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=861&group=comp.lang.misc#861

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!aioe.org!x6YkKUCkj2qHLwbKnVEeag.user.46.165.242.91.POSTED!not-for-mail
From: mailbox@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.misc
Subject: Re: OO object layout - method-table pointer or tag
Date: Thu, 23 Sep 2021 13:15:26 +0200
Organization: Aioe.org NNTP Server
Message-ID: <sihnke$1qln$1@gioia.aioe.org>
References: <sggjdi$trv$1@dont-email.me> <sgh09l$r5k$1@dont-email.me>
<sgibii$r5q$1@dont-email.me> <sgihn6$44q$1@dont-email.me>
<sh0ls6$qn6$1@dont-email.me> <sh0ori$cs9$1@dont-email.me>
<shdg1h$k84$1@dont-email.me> <shdima$753$1@dont-email.me>
<shdjv3$g9k$1@dont-email.me> <shdsts$fce$1@dont-email.me>
<sifeaa$fk2$1@dont-email.me> <sig193$u9$1@dont-email.me>
<sig81s$132j$1@gioia.aioe.org> <sig9qd$s98$1@dont-email.me>
<sihgh0$bsr$1@gioia.aioe.org> <sihhun$qpj$1@dont-email.me>
<sihkhe$53k$1@gioia.aioe.org> <sihlib$j6l$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="60087"; posting-host="x6YkKUCkj2qHLwbKnVEeag.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.14.0
Content-Language: en-US
X-Notice: Filtered by postfilter v. 0.9.2
 by: Dmitry A. Kazakov - Thu, 23 Sep 2021 11:15 UTC

On 2021-09-23 12:40, Bart wrote:
> On 23/09/2021 11:22, Dmitry A. Kazakov wrote:
>> On 2021-09-23 11:38, Bart wrote:
>>> On 23/09/2021 10:14, Dmitry A. Kazakov wrote:
>>>> On 2021-09-23 00:13, Bart wrote:
>>>>
>>>>> That Switch example is meaningless without knowing what operation
>>>>> is being performed in the source code, hence the request for the
>>>>> corresponding fragment of source code.
>>>>
>>>> The predefined operations should be:
>>>>
>>>> 1. Equality/inequality
>>>> 2. Access to the constraint (the selector value, read-only)
>>>> 3. Member access (the variant value, read/write)
>>>> 4. Aggregate (literal value)
>>>> 5. Assignment as a whole, IFF variant is definite, otherwise, no
>>>> assignment.
>>>
>>> But you can't do A+B?
>>
>> Because it is not defined. If the programmer wants "+", Foo, Boo he
>> can declare and implement them as with any other type.
>
> Show me. Let's say with a variant that can be an Integer, or a String.

function "+" (Left, Right : Variant) return Variant;

>>> If you have a variant which can include suitable types, tell me why
>>> any of the following operations, which I generally allow, should not
>>> apply to variants.
>>
>> Tell me why they should. Days of PL/1 are gone.
>
> Most languages allows all those ops, or a big subset.

None I know of.

> You seem to be saying that A+B is allowed when A and B are both int types.
>
> But not when A and B are variant types, even if that type is (Int |
> Real), not without a lot of work.

Again, what is the reason why?

> Then that's not a Variant type as I understand it. It's just a union or
> tagged union, a much cruder type.

You confuse a variant type with an ad-hoc class of types. A variant type
is not a class of its member types. These are semantically different
types, though they might have similar representations.

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

Re: OO object layout - method-table pointer or tag

<sihonk$8q0$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=862&group=comp.lang.misc#862

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: bc@freeuk.com (Bart)
Newsgroups: comp.lang.misc
Subject: Re: OO object layout - method-table pointer or tag
Date: Thu, 23 Sep 2021 12:34:03 +0100
Organization: A noiseless patient Spider
Lines: 84
Message-ID: <sihonk$8q0$1@dont-email.me>
References: <sggjdi$trv$1@dont-email.me> <sgh09l$r5k$1@dont-email.me>
<sgibii$r5q$1@dont-email.me> <sgihn6$44q$1@dont-email.me>
<sh0ls6$qn6$1@dont-email.me> <sh0ori$cs9$1@dont-email.me>
<shdg1h$k84$1@dont-email.me> <shdima$753$1@dont-email.me>
<shdjv3$g9k$1@dont-email.me> <shdsts$fce$1@dont-email.me>
<sifeaa$fk2$1@dont-email.me> <sig193$u9$1@dont-email.me>
<sig81s$132j$1@gioia.aioe.org> <sig9qd$s98$1@dont-email.me>
<sihgh0$bsr$1@gioia.aioe.org> <sihhun$qpj$1@dont-email.me>
<sihkhe$53k$1@gioia.aioe.org> <sihlib$j6l$1@dont-email.me>
<sihnke$1qln$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 23 Sep 2021 11:34:12 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="5587deda23d0b50a5b9d72dcb063de09";
logging-data="9024"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+oc3g3OWurP0zltwLuAP/zHuZ8hKxTnZ8="
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:bgNeIpcLFDg7dpNweStZvMhTVEs=
In-Reply-To: <sihnke$1qln$1@gioia.aioe.org>
X-Antivirus-Status: Clean
Content-Language: en-GB
X-Antivirus: AVG (VPS 210923-0, 23/9/2021), Outbound message
 by: Bart - Thu, 23 Sep 2021 11:34 UTC

On 23/09/2021 12:15, Dmitry A. Kazakov wrote:
> On 2021-09-23 12:40, Bart wrote:
>> On 23/09/2021 11:22, Dmitry A. Kazakov wrote:
>>> On 2021-09-23 11:38, Bart wrote:
>>>> On 23/09/2021 10:14, Dmitry A. Kazakov wrote:
>>>>> On 2021-09-23 00:13, Bart wrote:
>>>>>
>>>>>> That Switch example is meaningless without knowing what operation
>>>>>> is being performed in the source code, hence the request for the
>>>>>> corresponding fragment of source code.
>>>>>
>>>>> The predefined operations should be:
>>>>>
>>>>> 1. Equality/inequality
>>>>> 2. Access to the constraint (the selector value, read-only)
>>>>> 3. Member access (the variant value, read/write)
>>>>> 4. Aggregate (literal value)
>>>>> 5. Assignment as a whole, IFF variant is definite, otherwise, no
>>>>> assignment.
>>>>
>>>> But you can't do A+B?
>>>
>>> Because it is not defined. If the programmer wants "+", Foo, Boo he
>>> can declare and implement them as with any other type.
>>
>> Show me. Let's say with a variant that can be an Integer, or a String.
>
>    function "+" (Left, Right : Variant) return Variant;

So, what does that do? Does it magically allow A+B?

If not, then what's the point?

If it does, then we're back to square one: if A+B is now allowed in user
code, how is it implemented?

(Also, what is the 'Variant' in your example; is it the name of a
specific user type, so N such declarations are needed, or is it a
generic 'variant' so that this declaration suffices for all possible types?)

Suppose, also, that variant A is (int | real), and variant B is (real |
string)'; can I do A+B? (Here A,B represent types.)

I'm not expecting any actual concrete answers. I'm just interested in
how you will avoid answering the question this time.

>
>>>> If you have a variant which can include suitable types, tell me why
>>>> any of the following operations, which I generally allow, should not
>>>> apply to variants.
>>>
>>> Tell me why they should. Days of PL/1 are gone.
>>
>> Most languages allows all those ops, or a big subset.
>
> None I know of.
>
>> You seem to be saying that A+B is allowed when A and B are both int
>> types.
>>
>> But not when A and B are variant types, even if that type is (Int |
>> Real), not without a lot of work.
>
> Again, what is the reason why?

Why what? Why I should be able to do A+B?

If not, then what is the purpose of a Variant type, other than as a
glorified union.

>
>> Then that's not a Variant type as I understand it. It's just a union
>> or tagged union, a much cruder type.
>
> You confuse a variant type with an ad-hoc class of types.

James' proposal looks to me like an ad-hoc collection of types, within
an umbrella type.

It might also be specifically created to get away from terms like class,
and member and inheritance!

Re: OO object layout - method-table pointer or tag

<sihref$1j3m$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=863&group=comp.lang.misc#863

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!aioe.org!x6YkKUCkj2qHLwbKnVEeag.user.46.165.242.91.POSTED!not-for-mail
From: mailbox@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.misc
Subject: Re: OO object layout - method-table pointer or tag
Date: Thu, 23 Sep 2021 14:20:32 +0200
Organization: Aioe.org NNTP Server
Message-ID: <sihref$1j3m$1@gioia.aioe.org>
References: <sggjdi$trv$1@dont-email.me> <sgh09l$r5k$1@dont-email.me>
<sgibii$r5q$1@dont-email.me> <sgihn6$44q$1@dont-email.me>
<sh0ls6$qn6$1@dont-email.me> <sh0ori$cs9$1@dont-email.me>
<shdg1h$k84$1@dont-email.me> <shdima$753$1@dont-email.me>
<shdjv3$g9k$1@dont-email.me> <shdsts$fce$1@dont-email.me>
<sifeaa$fk2$1@dont-email.me> <sig193$u9$1@dont-email.me>
<sig81s$132j$1@gioia.aioe.org> <sig9qd$s98$1@dont-email.me>
<sihgh0$bsr$1@gioia.aioe.org> <sihhun$qpj$1@dont-email.me>
<sihkhe$53k$1@gioia.aioe.org> <sihlib$j6l$1@dont-email.me>
<sihnke$1qln$1@gioia.aioe.org> <sihonk$8q0$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="52342"; posting-host="x6YkKUCkj2qHLwbKnVEeag.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.14.0
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: en-US
 by: Dmitry A. Kazakov - Thu, 23 Sep 2021 12:20 UTC

On 2021-09-23 13:34, Bart wrote:
> On 23/09/2021 12:15, Dmitry A. Kazakov wrote:
>> On 2021-09-23 12:40, Bart wrote:
>>> On 23/09/2021 11:22, Dmitry A. Kazakov wrote:
>>>> On 2021-09-23 11:38, Bart wrote:
>>>>> On 23/09/2021 10:14, Dmitry A. Kazakov wrote:
>>>>>> On 2021-09-23 00:13, Bart wrote:
>>>>>>
>>>>>>> That Switch example is meaningless without knowing what operation
>>>>>>> is being performed in the source code, hence the request for the
>>>>>>> corresponding fragment of source code.
>>>>>>
>>>>>> The predefined operations should be:
>>>>>>
>>>>>> 1. Equality/inequality
>>>>>> 2. Access to the constraint (the selector value, read-only)
>>>>>> 3. Member access (the variant value, read/write)
>>>>>> 4. Aggregate (literal value)
>>>>>> 5. Assignment as a whole, IFF variant is definite, otherwise, no
>>>>>> assignment.
>>>>>
>>>>> But you can't do A+B?
>>>>
>>>> Because it is not defined. If the programmer wants "+", Foo, Boo he
>>>> can declare and implement them as with any other type.
>>>
>>> Show me. Let's say with a variant that can be an Integer, or a String.
>>
>>     function "+" (Left, Right : Variant) return Variant;
>
> So, what does that do?

Whatever the programmer puts inside it.

> Does it magically allow A+B?

Yes, when you declare a function you can magically call it.

> If not, then what's the point?

No idea, you asked how to declare a function "+". The point is up to you.

> (Also, what is the 'Variant' in your example; is it the name of a
> specific user type, so N such declarations are needed, or is it a
> generic 'variant' so that this declaration suffices for all possible
> types?)

Read the link I posted:

https://en.wikipedia.org/wiki/Tagged_union

> Suppose, also, that variant A is (int | real), and variant B is (real |
> string)'; can I do A+B? (Here A,B represent types.)

Nope.

>>> But not when A and B are variant types, even if that type is (Int |
>>> Real), not without a lot of work.
>>
>> Again, what is the reason why?
>
> Why what? Why I should be able to do A+B?

Yes, why should you be able to call arbitrary operations on arbitrary types.

> If not, then what is the purpose of a Variant type, other than as a
> glorified union.

None, variant is exactly a tagged union AKA variant record.

>>> Then that's not a Variant type as I understand it. It's just a union
>>> or tagged union, a much cruder type.
>>
>> You confuse a variant type with an ad-hoc class of types.
>
> James' proposal looks to me like an ad-hoc collection of types, within
> an umbrella type.

That is not variant, that is an ad-hoc class with inheritance and all
bells and whistles. He may not understand that or be in denial, but that
is his problem.

> It might also be specifically created to get away from terms like class,
> and member and inheritance!

He has his delusions you have yours.

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

Re: OO object layout - method-table pointer or tag

<sii0ib$vsn$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=864&group=comp.lang.misc#864

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: bc@freeuk.com (Bart)
Newsgroups: comp.lang.misc
Subject: Re: OO object layout - method-table pointer or tag
Date: Thu, 23 Sep 2021 14:47:46 +0100
Organization: A noiseless patient Spider
Lines: 65
Message-ID: <sii0ib$vsn$1@dont-email.me>
References: <sggjdi$trv$1@dont-email.me> <sgh09l$r5k$1@dont-email.me>
<sgibii$r5q$1@dont-email.me> <sgihn6$44q$1@dont-email.me>
<sh0ls6$qn6$1@dont-email.me> <sh0ori$cs9$1@dont-email.me>
<shdg1h$k84$1@dont-email.me> <shdima$753$1@dont-email.me>
<shdjv3$g9k$1@dont-email.me> <shdsts$fce$1@dont-email.me>
<sifeaa$fk2$1@dont-email.me> <sig193$u9$1@dont-email.me>
<sig81s$132j$1@gioia.aioe.org> <sig9qd$s98$1@dont-email.me>
<sihgh0$bsr$1@gioia.aioe.org> <sihhun$qpj$1@dont-email.me>
<sihkhe$53k$1@gioia.aioe.org> <sihlib$j6l$1@dont-email.me>
<sihnke$1qln$1@gioia.aioe.org> <sihonk$8q0$1@dont-email.me>
<sihref$1j3m$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 23 Sep 2021 13:47:55 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="5587deda23d0b50a5b9d72dcb063de09";
logging-data="32663"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX182ovhWhAjzcMHIUvav6sjrdaOx4W5XyW0="
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:Le0EgKGrFojsd3ilgPVoTREEkqU=
In-Reply-To: <sihref$1j3m$1@gioia.aioe.org>
X-Antivirus-Status: Clean
Content-Language: en-GB
X-Antivirus: AVG (VPS 210923-2, 23/9/2021), Outbound message
 by: Bart - Thu, 23 Sep 2021 13:47 UTC

On 23/09/2021 13:20, Dmitry A. Kazakov wrote:
> On 2021-09-23 13:34, Bart wrote:

>> If not, then what is the purpose of a Variant type, other than as a
>> glorified union.
>
> None, variant is exactly a tagged union AKA variant record.

Then we're talking at cross purposes.

This was entirely the point of my request for usage examples in source
code, then the kind of variant people had in mind would become more
apparent.

In my language, if I implemented the type of variant I assumed this was,
A+B (and EVERY operation normally allowed for fixed static types) would
be allowed for any two variants, provided it was meaningful between at
least two combinations of types from each side.

But it would be horrendous to implement in a static language.

This is the proposed feature in action:

type T = int | real | string

function biggerof (T a, b)=>T =
if a>b then
return a
else
return b
fi
end

println biggerof(100, 200) # 200
println biggerof(pi, 2) # 3.14159...
println biggerof("two","three") # two (alphatical ordering)
println biggerof(23, "45") # error (runtime or compiletime)

Note that this is not generics, so 'biggerof' is not a template for
multiple instantiations of 'biggerof'; it is just one function.

(This is the kind of example that would have made things clear.)

>
>>>> Then that's not a Variant type as I understand it. It's just a union
>>>> or tagged union, a much cruder type.
>>>
>>> You confuse a variant type with an ad-hoc class of types.
>>
>> James' proposal looks to me like an ad-hoc collection of types, within
>> an umbrella type.
>
> That is not variant, that is an ad-hoc class with inheritance and all
> bells and whistles. He may not understand that or be in denial, but that
> is his problem.
>
>> It might also be specifically created to get away from terms like
>> class, and member and inheritance!
>
> He has his delusions you have yours.

We're both implementing actual languages.

Re: OO object layout - method-table pointer or tag

<sii110$3b4$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=865&group=comp.lang.misc#865

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!paganini.bofh.team!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: david.brown@hesbynett.no (David Brown)
Newsgroups: comp.lang.misc
Subject: Re: OO object layout - method-table pointer or tag
Date: Thu, 23 Sep 2021 15:55:43 +0200
Organization: A noiseless patient Spider
Lines: 88
Message-ID: <sii110$3b4$1@dont-email.me>
References: <sggjdi$trv$1@dont-email.me> <sgh09l$r5k$1@dont-email.me>
<sgibii$r5q$1@dont-email.me> <sgihn6$44q$1@dont-email.me>
<sh0ls6$qn6$1@dont-email.me> <sh0ori$cs9$1@dont-email.me>
<shdg1h$k84$1@dont-email.me> <shdima$753$1@dont-email.me>
<shdjv3$g9k$1@dont-email.me> <shdsts$fce$1@dont-email.me>
<sifeaa$fk2$1@dont-email.me> <sig193$u9$1@dont-email.me>
<sih996$1jj$1@dont-email.me> <sihist$15j$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 23 Sep 2021 13:55:44 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="df1de3da7f3d53b744f0694117cccf7f";
logging-data="3428"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+aAb8CQTAivHUm4GVCnivaVyAuVAtaRjc="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:Bxe5a7K2xQpfvzi/A2NAXT3jmzE=
In-Reply-To: <sihist$15j$1@dont-email.me>
Content-Language: en-GB
 by: David Brown - Thu, 23 Sep 2021 13:55 UTC

On 23/09/2021 11:54, Bart wrote:
> On 23/09/2021 08:10, David Brown wrote:
>> On 22/09/2021 21:47, Bart wrote:
>>> On 22/09/2021 15:24, James Harris wrote:
>>>> On 09/09/2021 22:04, Bart wrote:
>>>
>>>>> Also, Variants could presumably be assigned something else of a
>>>>> different type? Then you can't even assume it will stay the same type.
>>>>
>>>> Wouldn't code which handles variants typically include a switch on the
>>>> type as in the following?
>>>>
>>>>     switch T.type
>>>>       case int:
>>>>         /* Handle int */
>>>>       case array float:
>>>>         /* Handle array of float */
>>>>     end switch /* Ignoring other cases */
>>>
>>> You need to show an example of source code where such types are used,
>>> and see that the generated code might be like.
>>>
>>
>> Variant types are typically implemented by having a "type" field - an
>> integer that says which of the allowed types is currently valid.  In
>> C++, this is std::variant.  In Pascal, it is a "tagged union" or
>> "variant record".
>>
>> In C, you might have :
>>
>>     typedef struct {
>>         enum { T_is_int, T_is_float } type_index;
>>         union {
>>             int int_value;
>>             float float_value;
>>         }
>>     } T;
>>     
>>     switch (t.type_index) {
>>         case T_is_int :
>>             // Use t.int_value
>>             break;
>>         case T_is_float :
>>             // Use t.float_value
>>             break;
>>     }
>>
>
> No one has yet explained exactly what kind of variant they are talking
> about.
>
> You're assuming it is just a tagged union or sumtype, where all you can
> do is write explicit code to extract one of the possible values.

That is almost exactly what a variant /is/. But you are missing a few
operations - you can also read which type is contained in some manner
(perhaps by reading a field, perhaps by pattern matching or a special
type of switch, perhaps by trial-and-error and exceptions), and of
course you can assign values to it.

You seem to be mixing up variants with dynamic typing. Perhaps you have
been playing with Visual Basic, and copied MS's misuse of the term.

>
> Or if you try and use one of those values directly (t.int_value) the
> compiler will perform a behind the scenes check that it is an int.
>
> The C++ variant might do a little bit more.
>
> The kind of variant I've used in dynamic code is considerably more
> powerful:
>
>    for x in (100, 23.4, "cat", 50..60, [7,8,9], (100,110,120)) do
>        println x.type, "\t", x
>    end
>

It is not "more powerful". It is /different/. You can do some things
with it that you can't do with a real variant (as the term is normally
used), but it has other limitations.

Basically, what you are talking about is a void* pointer. That is
flexible, but has severe disadvantages in being sure your code is
correct. (Python uses a similar idea - it is great for writing quick
and dirty scripts or simple code, but terrible when you want to work
with large code bases and where you need to /know/ the code is correct,
not just run some tests.)

Re: OO object layout - method-table pointer or tag

<sii13g$hga$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=866&group=comp.lang.misc#866

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!aioe.org!x6YkKUCkj2qHLwbKnVEeag.user.46.165.242.91.POSTED!not-for-mail
From: mailbox@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.misc
Subject: Re: OO object layout - method-table pointer or tag
Date: Thu, 23 Sep 2021 15:57:04 +0200
Organization: Aioe.org NNTP Server
Message-ID: <sii13g$hga$1@gioia.aioe.org>
References: <sggjdi$trv$1@dont-email.me> <sgh09l$r5k$1@dont-email.me>
<sgibii$r5q$1@dont-email.me> <sgihn6$44q$1@dont-email.me>
<sh0ls6$qn6$1@dont-email.me> <sh0ori$cs9$1@dont-email.me>
<shdg1h$k84$1@dont-email.me> <shdima$753$1@dont-email.me>
<shdjv3$g9k$1@dont-email.me> <shdsts$fce$1@dont-email.me>
<sifeaa$fk2$1@dont-email.me> <sig193$u9$1@dont-email.me>
<sig81s$132j$1@gioia.aioe.org> <sig9qd$s98$1@dont-email.me>
<sihgh0$bsr$1@gioia.aioe.org> <sihhun$qpj$1@dont-email.me>
<sihkhe$53k$1@gioia.aioe.org> <sihlib$j6l$1@dont-email.me>
<sihnke$1qln$1@gioia.aioe.org> <sihonk$8q0$1@dont-email.me>
<sihref$1j3m$1@gioia.aioe.org> <sii0ib$vsn$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="17930"; posting-host="x6YkKUCkj2qHLwbKnVEeag.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.14.0
Content-Language: en-US
X-Notice: Filtered by postfilter v. 0.9.2
 by: Dmitry A. Kazakov - Thu, 23 Sep 2021 13:57 UTC

On 2021-09-23 15:47, Bart wrote:

> This is the proposed feature in action:
>
>    type T = int | real | string
>
>    function biggerof (T a, b)=>T =
>        if a>b then
>           return a
>        else
>           return b
>        fi
>     end

Type inference, when the interfaces of the class members are somehow
combined = non-starter.

It is impossible to infer semantics from interfaces. No need to discuss.

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

Re: OO object layout - method-table pointer or tag

<sii34p$iuj$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=867&group=comp.lang.misc#867

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: bc@freeuk.com (Bart)
Newsgroups: comp.lang.misc
Subject: Re: OO object layout - method-table pointer or tag
Date: Thu, 23 Sep 2021 15:31:44 +0100
Organization: A noiseless patient Spider
Lines: 64
Message-ID: <sii34p$iuj$1@dont-email.me>
References: <sggjdi$trv$1@dont-email.me> <sgh09l$r5k$1@dont-email.me>
<sgibii$r5q$1@dont-email.me> <sgihn6$44q$1@dont-email.me>
<sh0ls6$qn6$1@dont-email.me> <sh0ori$cs9$1@dont-email.me>
<shdg1h$k84$1@dont-email.me> <shdima$753$1@dont-email.me>
<shdjv3$g9k$1@dont-email.me> <shdsts$fce$1@dont-email.me>
<sifeaa$fk2$1@dont-email.me> <sig193$u9$1@dont-email.me>
<sig81s$132j$1@gioia.aioe.org> <sig9qd$s98$1@dont-email.me>
<sihgh0$bsr$1@gioia.aioe.org> <sihhun$qpj$1@dont-email.me>
<sihkhe$53k$1@gioia.aioe.org> <sihlib$j6l$1@dont-email.me>
<sihnke$1qln$1@gioia.aioe.org> <sihonk$8q0$1@dont-email.me>
<sihref$1j3m$1@gioia.aioe.org> <sii0ib$vsn$1@dont-email.me>
<sii13g$hga$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 23 Sep 2021 14:31:53 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="5587deda23d0b50a5b9d72dcb063de09";
logging-data="19411"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/a1A6y4VbMm1k2Xahxb3/T6yr8fhrkc6E="
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:baBQw4Njs7Eyx/qOcHm7xttto3Y=
In-Reply-To: <sii13g$hga$1@gioia.aioe.org>
X-Antivirus-Status: Clean
Content-Language: en-GB
X-Antivirus: AVG (VPS 210923-2, 23/9/2021), Outbound message
 by: Bart - Thu, 23 Sep 2021 14:31 UTC

On 23/09/2021 14:57, Dmitry A. Kazakov wrote:
> On 2021-09-23 15:47, Bart wrote:
>
>> This is the proposed feature in action:
>>
>>     type T = int | real | string
>>
>>     function biggerof (T a, b)=>T =
>>         if a>b then
>>            return a
>>         else
>>            return b
>>         fi
>>      end
>
> Type inference, when the interfaces of the class members are somehow
> combined = non-starter.
>
> It is impossible to infer semantics from interfaces. No need to discuss.
>

I don't really know what you're talking about. Such a feature works fine
in dynamic code:

function biggerof (a, b) =
if a>b then
return a
else
return b
fi
end

println biggerof(100, 200) ! 200
println biggerof(pi, 2) ! 3.14159...
println biggerof("two","three") ! two (alphatical ordering)
println biggerof(23, "45") ! error (runtime or compiletime)

Output is:

200
3.141593
two
PC Error:
Types not supported: comparemixed : int/string

What it doesn't do is restrict the types to int/real/string. I'd have to
do that manually to emulate my proposal more closely:

var T := (int, real, string) # just a list, not a type

function biggerof (a, b) =
unless a.type in T and b.type in T then
abort("Illegal types")
end
...

Now a call like: 'println biggerof(10..20, 30..40)' will fail ('range'
is not one of int, real, string).

So it is viable in static. But in my view not practical without
implementing most of a dynamic type system.

(Note that my biggerof() function does the same job as the built-in
max() operator; I couldn't think of a better example off-hand.)

Re: OO object layout - method-table pointer or tag

<sii42v$v9$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=868&group=comp.lang.misc#868

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!aioe.org!x6YkKUCkj2qHLwbKnVEeag.user.46.165.242.91.POSTED!not-for-mail
From: mailbox@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.misc
Subject: Re: OO object layout - method-table pointer or tag
Date: Thu, 23 Sep 2021 16:48:00 +0200
Organization: Aioe.org NNTP Server
Message-ID: <sii42v$v9$1@gioia.aioe.org>
References: <sggjdi$trv$1@dont-email.me> <sgh09l$r5k$1@dont-email.me>
<sgibii$r5q$1@dont-email.me> <sgihn6$44q$1@dont-email.me>
<sh0ls6$qn6$1@dont-email.me> <sh0ori$cs9$1@dont-email.me>
<shdg1h$k84$1@dont-email.me> <shdima$753$1@dont-email.me>
<shdjv3$g9k$1@dont-email.me> <shdsts$fce$1@dont-email.me>
<sifeaa$fk2$1@dont-email.me> <sig193$u9$1@dont-email.me>
<sig81s$132j$1@gioia.aioe.org> <sig9qd$s98$1@dont-email.me>
<sihgh0$bsr$1@gioia.aioe.org> <sihhun$qpj$1@dont-email.me>
<sihkhe$53k$1@gioia.aioe.org> <sihlib$j6l$1@dont-email.me>
<sihnke$1qln$1@gioia.aioe.org> <sihonk$8q0$1@dont-email.me>
<sihref$1j3m$1@gioia.aioe.org> <sii0ib$vsn$1@dont-email.me>
<sii13g$hga$1@gioia.aioe.org> <sii34p$iuj$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="1001"; posting-host="x6YkKUCkj2qHLwbKnVEeag.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.14.0
Content-Language: en-US
X-Notice: Filtered by postfilter v. 0.9.2
 by: Dmitry A. Kazakov - Thu, 23 Sep 2021 14:48 UTC

On 2021-09-23 16:31, Bart wrote:
> On 23/09/2021 14:57, Dmitry A. Kazakov wrote:
>> On 2021-09-23 15:47, Bart wrote:
>>
>>> This is the proposed feature in action:
>>>
>>>     type T = int | real | string
>>>
>>>     function biggerof (T a, b)=>T =
>>>         if a>b then
>>>            return a
>>>         else
>>>            return b
>>>         fi
>>>      end
>>
>> Type inference, when the interfaces of the class members are somehow
>> combined = non-starter.
>>
>> It is impossible to infer semantics from interfaces. No need to discuss.
>
> I don't really know what you're talking about. Such a feature works fine
> in dynamic code:

You just have illustrated the point by providing a broken program that
has a type error at run time.

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

Re: OO object layout - method-table pointer or tag

<sii655$93v$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=869&group=comp.lang.misc#869

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: bc@freeuk.com (Bart)
Newsgroups: comp.lang.misc
Subject: Re: OO object layout - method-table pointer or tag
Date: Thu, 23 Sep 2021 16:23:09 +0100
Organization: A noiseless patient Spider
Lines: 65
Message-ID: <sii655$93v$1@dont-email.me>
References: <sggjdi$trv$1@dont-email.me> <sgh09l$r5k$1@dont-email.me>
<sgibii$r5q$1@dont-email.me> <sgihn6$44q$1@dont-email.me>
<sh0ls6$qn6$1@dont-email.me> <sh0ori$cs9$1@dont-email.me>
<shdg1h$k84$1@dont-email.me> <shdima$753$1@dont-email.me>
<shdjv3$g9k$1@dont-email.me> <shdsts$fce$1@dont-email.me>
<sifeaa$fk2$1@dont-email.me> <sig193$u9$1@dont-email.me>
<sig81s$132j$1@gioia.aioe.org> <sig9qd$s98$1@dont-email.me>
<sihgh0$bsr$1@gioia.aioe.org> <sihhun$qpj$1@dont-email.me>
<sihkhe$53k$1@gioia.aioe.org> <sihlib$j6l$1@dont-email.me>
<sihnke$1qln$1@gioia.aioe.org> <sihonk$8q0$1@dont-email.me>
<sihref$1j3m$1@gioia.aioe.org> <sii0ib$vsn$1@dont-email.me>
<sii13g$hga$1@gioia.aioe.org> <sii34p$iuj$1@dont-email.me>
<sii42v$v9$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 23 Sep 2021 15:23:17 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="5587deda23d0b50a5b9d72dcb063de09";
logging-data="9343"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+vUwsULs8Iim0Gv8a3l5a6HoW45B7FCrk="
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:soL/BEJFEW1qAfbeEzYfpCSXtBg=
In-Reply-To: <sii42v$v9$1@gioia.aioe.org>
X-Antivirus-Status: Clean
Content-Language: en-GB
X-Antivirus: AVG (VPS 210923-2, 23/9/2021), Outbound message
 by: Bart - Thu, 23 Sep 2021 15:23 UTC

On 23/09/2021 15:48, Dmitry A. Kazakov wrote:
> On 2021-09-23 16:31, Bart wrote:
>> On 23/09/2021 14:57, Dmitry A. Kazakov wrote:
>>> On 2021-09-23 15:47, Bart wrote:
>>>
>>>> This is the proposed feature in action:
>>>>
>>>>     type T = int | real | string
>>>>
>>>>     function biggerof (T a, b)=>T =
>>>>         if a>b then
>>>>            return a
>>>>         else
>>>>            return b
>>>>         fi
>>>>      end
>>>
>>> Type inference, when the interfaces of the class members are somehow
>>> combined = non-starter.
>>>
>>> It is impossible to infer semantics from interfaces. No need to discuss.
>>
>> I don't really know what you're talking about. Such a feature works
>> fine in dynamic code:
>
> You just have illustrated the point by providing a broken program that
> has a type error at run time.
>

It has an /error/ at runtime. Lots of programs have errors which occur
then, such as input errors. The language might deal with that by
generating an exception, which can be checked for, or just checking the
inputs, then it can issue a message, or do something else.

The program below does arithmetic on user input, so the compiler won't
know what types are being added (since they are dynamic).

Are you saying this program is broken?

const expr_error=10

do
print "Enter A and B> "
readln a, b # a,b can be numbers, or strings
stop when a=""

try
c := dosum(a,b)
fprintln "# + # is #", a, b, c

except expr_error then
fprintln "Can't add # and #", a, b

end
od

function dosum(a,b)=
unless a.isnumber and b.isnumber then
raise exprerror
end
return a+b
end

(This language can actually add strings or numbers, but it can't mix
them. The example allows only numbers.)

Re: OO object layout - method-table pointer or tag

<sii7ir$1ss4$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=870&group=comp.lang.misc#870

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!aioe.org!x6YkKUCkj2qHLwbKnVEeag.user.46.165.242.91.POSTED!not-for-mail
From: mailbox@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.misc
Subject: Re: OO object layout - method-table pointer or tag
Date: Thu, 23 Sep 2021 17:47:39 +0200
Organization: Aioe.org NNTP Server
Message-ID: <sii7ir$1ss4$1@gioia.aioe.org>
References: <sggjdi$trv$1@dont-email.me> <sgh09l$r5k$1@dont-email.me>
<sgibii$r5q$1@dont-email.me> <sgihn6$44q$1@dont-email.me>
<sh0ls6$qn6$1@dont-email.me> <sh0ori$cs9$1@dont-email.me>
<shdg1h$k84$1@dont-email.me> <shdima$753$1@dont-email.me>
<shdjv3$g9k$1@dont-email.me> <shdsts$fce$1@dont-email.me>
<sifeaa$fk2$1@dont-email.me> <sig193$u9$1@dont-email.me>
<sig81s$132j$1@gioia.aioe.org> <sig9qd$s98$1@dont-email.me>
<sihgh0$bsr$1@gioia.aioe.org> <sihhun$qpj$1@dont-email.me>
<sihkhe$53k$1@gioia.aioe.org> <sihlib$j6l$1@dont-email.me>
<sihnke$1qln$1@gioia.aioe.org> <sihonk$8q0$1@dont-email.me>
<sihref$1j3m$1@gioia.aioe.org> <sii0ib$vsn$1@dont-email.me>
<sii13g$hga$1@gioia.aioe.org> <sii34p$iuj$1@dont-email.me>
<sii42v$v9$1@gioia.aioe.org> <sii655$93v$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="62340"; posting-host="x6YkKUCkj2qHLwbKnVEeag.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.14.0
Content-Language: en-US
X-Notice: Filtered by postfilter v. 0.9.2
 by: Dmitry A. Kazakov - Thu, 23 Sep 2021 15:47 UTC

On 2021-09-23 17:23, Bart wrote:
> On 23/09/2021 15:48, Dmitry A. Kazakov wrote:
>> On 2021-09-23 16:31, Bart wrote:
>>> On 23/09/2021 14:57, Dmitry A. Kazakov wrote:
>>>> On 2021-09-23 15:47, Bart wrote:
>>>>
>>>>> This is the proposed feature in action:
>>>>>
>>>>>     type T = int | real | string
>>>>>
>>>>>     function biggerof (T a, b)=>T =
>>>>>         if a>b then
>>>>>            return a
>>>>>         else
>>>>>            return b
>>>>>         fi
>>>>>      end
>>>>
>>>> Type inference, when the interfaces of the class members are somehow
>>>> combined = non-starter.
>>>>
>>>> It is impossible to infer semantics from interfaces. No need to
>>>> discuss.
>>>
>>> I don't really know what you're talking about. Such a feature works
>>> fine in dynamic code:
>>
>> You just have illustrated the point by providing a broken program that
>> has a type error at run time.
>
> It has an /error/ at runtime.

Not an error, a type error = the language's type system is broken, as
expected.

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

Re: OO object layout - method-table pointer or tag

<sii8kt$rfg$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=871&group=comp.lang.misc#871

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: bc@freeuk.com (Bart)
Newsgroups: comp.lang.misc
Subject: Re: OO object layout - method-table pointer or tag
Date: Thu, 23 Sep 2021 17:05:41 +0100
Organization: A noiseless patient Spider
Lines: 44
Message-ID: <sii8kt$rfg$1@dont-email.me>
References: <sggjdi$trv$1@dont-email.me> <sgh09l$r5k$1@dont-email.me>
<sgibii$r5q$1@dont-email.me> <sgihn6$44q$1@dont-email.me>
<sh0ls6$qn6$1@dont-email.me> <sh0ori$cs9$1@dont-email.me>
<shdg1h$k84$1@dont-email.me> <shdima$753$1@dont-email.me>
<shdjv3$g9k$1@dont-email.me> <shdsts$fce$1@dont-email.me>
<sifeaa$fk2$1@dont-email.me> <sig193$u9$1@dont-email.me>
<sig81s$132j$1@gioia.aioe.org> <sig9qd$s98$1@dont-email.me>
<sihgh0$bsr$1@gioia.aioe.org> <sihhun$qpj$1@dont-email.me>
<sihkhe$53k$1@gioia.aioe.org> <sihlib$j6l$1@dont-email.me>
<sihnke$1qln$1@gioia.aioe.org> <sihonk$8q0$1@dont-email.me>
<sihref$1j3m$1@gioia.aioe.org> <sii0ib$vsn$1@dont-email.me>
<sii13g$hga$1@gioia.aioe.org> <sii34p$iuj$1@dont-email.me>
<sii42v$v9$1@gioia.aioe.org> <sii655$93v$1@dont-email.me>
<sii7ir$1ss4$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 23 Sep 2021 16:05:50 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="5587deda23d0b50a5b9d72dcb063de09";
logging-data="28144"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+cYAGCvWiF++wynbwv+d5GItNpua7eFvs="
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:A6aXrRlU9cgpmwAbppXwFq2XKac=
In-Reply-To: <sii7ir$1ss4$1@gioia.aioe.org>
X-Antivirus-Status: Clean
Content-Language: en-GB
X-Antivirus: AVG (VPS 210923-2, 23/9/2021), Outbound message
 by: Bart - Thu, 23 Sep 2021 16:05 UTC

On 23/09/2021 16:47, Dmitry A. Kazakov wrote:
> On 2021-09-23 17:23, Bart wrote:
>> On 23/09/2021 15:48, Dmitry A. Kazakov wrote:
>>> On 2021-09-23 16:31, Bart wrote:
>>>> On 23/09/2021 14:57, Dmitry A. Kazakov wrote:
>>>>> On 2021-09-23 15:47, Bart wrote:
>>>>>
>>>>>> This is the proposed feature in action:
>>>>>>
>>>>>>     type T = int | real | string
>>>>>>
>>>>>>     function biggerof (T a, b)=>T =
>>>>>>         if a>b then
>>>>>>            return a
>>>>>>         else
>>>>>>            return b
>>>>>>         fi
>>>>>>      end
>>>>>
>>>>> Type inference, when the interfaces of the class members are
>>>>> somehow combined = non-starter.
>>>>>
>>>>> It is impossible to infer semantics from interfaces. No need to
>>>>> discuss.
>>>>
>>>> I don't really know what you're talking about. Such a feature works
>>>> fine in dynamic code:
>>>
>>> You just have illustrated the point by providing a broken program
>>> that has a type error at run time.
>>
>> It has an /error/ at runtime.
>
> Not an error, a type error = the language's type system is broken, as
> expected.
>

The language has one type: a 'variant'. A and B will ALWAYS be variants,
so they can never have the wrong type.

The tagged type-code is effectively runtime data.

You clearly don't like it, and anything you don't like, is broken in
your eyes.

Re: OO object layout - method-table pointer or tag

<siiff9$1roi$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=872&group=comp.lang.misc#872

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!aioe.org!x6YkKUCkj2qHLwbKnVEeag.user.46.165.242.91.POSTED!not-for-mail
From: mailbox@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.misc
Subject: Re: OO object layout - method-table pointer or tag
Date: Thu, 23 Sep 2021 20:02:18 +0200
Organization: Aioe.org NNTP Server
Message-ID: <siiff9$1roi$1@gioia.aioe.org>
References: <sggjdi$trv$1@dont-email.me> <sgh09l$r5k$1@dont-email.me>
<sgibii$r5q$1@dont-email.me> <sgihn6$44q$1@dont-email.me>
<sh0ls6$qn6$1@dont-email.me> <sh0ori$cs9$1@dont-email.me>
<shdg1h$k84$1@dont-email.me> <shdima$753$1@dont-email.me>
<shdjv3$g9k$1@dont-email.me> <shdsts$fce$1@dont-email.me>
<sifeaa$fk2$1@dont-email.me> <sig193$u9$1@dont-email.me>
<sig81s$132j$1@gioia.aioe.org> <sig9qd$s98$1@dont-email.me>
<sihgh0$bsr$1@gioia.aioe.org> <sihhun$qpj$1@dont-email.me>
<sihkhe$53k$1@gioia.aioe.org> <sihlib$j6l$1@dont-email.me>
<sihnke$1qln$1@gioia.aioe.org> <sihonk$8q0$1@dont-email.me>
<sihref$1j3m$1@gioia.aioe.org> <sii0ib$vsn$1@dont-email.me>
<sii13g$hga$1@gioia.aioe.org> <sii34p$iuj$1@dont-email.me>
<sii42v$v9$1@gioia.aioe.org> <sii655$93v$1@dont-email.me>
<sii7ir$1ss4$1@gioia.aioe.org> <sii8kt$rfg$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="61202"; posting-host="x6YkKUCkj2qHLwbKnVEeag.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.14.0
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: en-US
 by: Dmitry A. Kazakov - Thu, 23 Sep 2021 18:02 UTC

On 2021-09-23 18:05, Bart wrote:
> On 23/09/2021 16:47, Dmitry A. Kazakov wrote:
>> On 2021-09-23 17:23, Bart wrote:
>>> On 23/09/2021 15:48, Dmitry A. Kazakov wrote:
>>>> On 2021-09-23 16:31, Bart wrote:
>>>>> On 23/09/2021 14:57, Dmitry A. Kazakov wrote:
>>>>>> On 2021-09-23 15:47, Bart wrote:
>>>>>>
>>>>>>> This is the proposed feature in action:
>>>>>>>
>>>>>>>     type T = int | real | string
>>>>>>>
>>>>>>>     function biggerof (T a, b)=>T =
>>>>>>>         if a>b then
>>>>>>>            return a
>>>>>>>         else
>>>>>>>            return b
>>>>>>>         fi
>>>>>>>      end
>>>>>>
>>>>>> Type inference, when the interfaces of the class members are
>>>>>> somehow combined = non-starter.
>>>>>>
>>>>>> It is impossible to infer semantics from interfaces. No need to
>>>>>> discuss.
>>>>>
>>>>> I don't really know what you're talking about. Such a feature works
>>>>> fine in dynamic code:
>>>>
>>>> You just have illustrated the point by providing a broken program
>>>> that has a type error at run time.
>>>
>>> It has an /error/ at runtime.
>>
>> Not an error, a type error = the language's type system is broken, as
>> expected.
>
> The language has one type: a 'variant'. A and B will ALWAYS be variants,
> so they can never have the wrong type.

They do since you infer operations from member types. That cannot work
and it does not.

Properly designed languages inherit interfaces rather than infer them.
Interface lists operations applicable to the type.

This allows to ensure existence of implementations of all operations at
compile time, statically, so that no type error (AKA "operation not
understood") may ever occur.

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


devel / comp.lang.misc / Re: OO object layout - method-table pointer or tag

Pages:123456
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor