POV-Ray : Newsgroups : povray.off-topic : Programming language discussion Server Time
3 Sep 2024 23:29:19 EDT (-0400)
  Programming language discussion (Message 28 to 37 of 47)  
<<< Previous 10 Messages Goto Latest 10 Messages Next 10 Messages >>>
From: Darren New
Subject: Re: Programming language discussion
Date: 23 Oct 2010 19:04:34
Message: <4cc36a02$1@news.povray.org>
Kevin Wampler wrote:
> Upon actually reading the article, 
> yeah, it's quite obvious that it's not real.

OK. You had me worried there for a minute. :-)

-- 
Darren New, San Diego CA, USA (PST)
   Serving Suggestion:
     "Don't serve this any more. It's awful."


Post a reply to this message

From: Mike Raiford
Subject: Re: Programming language discussion
Date: 26 Oct 2010 10:03:00
Message: <4cc6df94$1@news.povray.org>
On 10/22/2010 12:16 PM, Warp wrote:
> Darren New<dne### [at] sanrrcom>  wrote:
>> Warp wrote:
>>>    'union' in C is basically a construct which exists to save some bytes
>>> of memory in some rare circumstances.
>
>> I have also seen it used for typecasting, but nowadays I think casting the
>> address of the thing to the "wrong" pointer type and then indirecting it
>> gets used more.  I.e.;  { long x = ...; float f = *(float*)&x; }
>
>    The most clever use of 'union' I have seen was like this:
>
> union Matrix4x4
> {
>      double m[4][4];
>      struct
>      {
>          double m11, m12, m13, m14,
>              m21, m22, m23, m24,
>              m31, m32, m33, m34,
>              m41, m42, m43, m44;
>      };
> };
>
>    This means you can access the matrix like "transform.m[1][2] = 5;"
> or like "transform.m23 = 5;";
>
>    Of course in this case this is just a trick to have two naming
> conventions to access the same data (rather than to save memory).

As they call it, Syntactic sugar.

I've seen unions as a means of assisting with reading binary file data, 
but generally stored in a struct.

the Variant data type used by COM is a union. again, it has a field that 
tells what the variant is, but it basically is there to allow data of 
any type to be passed around. Not exactly type safe, but necessary for 
programs written in VB that insist on not declaring any variable as a 
particular type. Or for when you don't know what data type you will be 
handing off (e.g. the clipboard)




-- 
~Mike


Post a reply to this message

From: Invisible
Subject: Re: Programming language discussion
Date: 26 Oct 2010 10:26:57
Message: <4cc6e531$1@news.povray.org>
On 26/10/2010 02:59 PM, Mike Raiford wrote:

> As they call it, Syntactic sugar.

Depends on your language.

In an object-oriented language, you generally don't need it, since 
anything declared to be of class X can actually be of class X *or* any 
subclass thereof.

In Haskell, "unions" are a fundamental part of the language. One of the 
fundamental branching primitives is based on them. Nullable fields use 
unions, lists are unions, trees are unions, just about everything ends 
up being a union. [Insert witty Thatcher jokes here.]


Post a reply to this message

From: Warp
Subject: Re: Programming language discussion
Date: 27 Oct 2010 13:00:16
Message: <4cc85aa0@news.povray.org>
Invisible <voi### [at] devnull> wrote:
> In Haskell, "unions" are a fundamental part of the language. One of the 
> fundamental branching primitives is based on them. Nullable fields use 
> unions, lists are unions, trees are unions, just about everything ends 
> up being a union. [Insert witty Thatcher jokes here.]

  I'm not exactly sure if your concept of "union" is the same as C's
concept of "union". A union in C has a fixed size. It's not a dynamic
data container, like a list or a tree.

-- 
                                                          - Warp


Post a reply to this message

From: Darren New
Subject: Re: Programming language discussion
Date: 27 Oct 2010 14:27:33
Message: <4cc86f15$1@news.povray.org>
Warp wrote:
> It's not a dynamic data container, like a list or a tree.

Remember that in Haskell these are defined recursively. So a "tree" in this 
case is union { struct { tree*left, tree*right }, struct { node data } }

A list is
union { struct {node data, list* next} , struct {node data} }

I.e., what he's calling "tree" would be "node of a tree" in C.

-- 
Darren New, San Diego CA, USA (PST)
   Serving Suggestion:
     "Don't serve this any more. It's awful."


Post a reply to this message

From: Orchid XP v8
Subject: Re: Programming language discussion
Date: 27 Oct 2010 17:15:47
Message: <4cc89683$1@news.povray.org>
On 27/10/2010 07:27 PM, Darren New wrote:

> I.e., what he's calling "tree" would be "node of a tree" in C.

Yeah, I should have been clearer about that. A list *node* is a union. A 
tree *node* is a union.

-- 
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*


Post a reply to this message

From: Warp
Subject: Re: Programming language discussion
Date: 28 Oct 2010 11:38:40
Message: <4cc998ff@news.povray.org>
Orchid XP v8 <voi### [at] devnull> wrote:
> On 27/10/2010 07:27 PM, Darren New wrote:

> > I.e., what he's calling "tree" would be "node of a tree" in C.

> Yeah, I should have been clearer about that. A list *node* is a union. A 
> tree *node* is a union.

  What would the harm be if eg. list nodes were structs instead?

-- 
                                                          - Warp


Post a reply to this message

From: Invisible
Subject: Re: Programming language discussion
Date: 28 Oct 2010 11:46:52
Message: <4cc99aec$1@news.povray.org>
>>> I.e., what he's calling "tree" would be "node of a tree" in C.
>
>> Yeah, I should have been clearer about that. A list *node* is a union. A
>> tree *node* is a union.
>
>    What would the harm be if eg. list nodes were structs instead?

Nothing. It's just that in Haskell, you can't implement it that way. 
[Correction: You can't implement *finite* lists that way.] And, with 
unions being a fundamental part of the language, you don't need to.


Post a reply to this message

From: Darren New
Subject: Re: Programming language discussion
Date: 28 Oct 2010 13:36:45
Message: <4cc9b4ad$1@news.povray.org>
Warp wrote:
>   What would the harm be if eg. list nodes were structs instead?

Since "null" is a union in Haskell to (i.e., it either has data in it or it 
has no data in it), this wouldn't really save you anything.

-- 
Darren New, San Diego CA, USA (PST)
   Serving Suggestion:
     "Don't serve this any more. It's awful."


Post a reply to this message

From: Warp
Subject: Re: Programming language discussion
Date: 28 Oct 2010 13:41:26
Message: <4cc9b5c6@news.povray.org>
Darren New <dne### [at] sanrrcom> wrote:
> Warp wrote:
> >   What would the harm be if eg. list nodes were structs instead?

> Since "null" is a union in Haskell to (i.e., it either has data in it or it 
> has no data in it), this wouldn't really save you anything.

  It saves checking the node type for each single operation you do to any
node in the list. It the node is a struct, its contents are fixed and thus
you don't have to check anything.

-- 
                                                          - Warp


Post a reply to this message

<<< Previous 10 Messages Goto Latest 10 Messages Next 10 Messages >>>

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.