POV-Ray : Newsgroups : povray.programming : this Server Time
28 Jul 2024 16:31:05 EDT (-0400)
  this (Message 21 to 30 of 34)  
<<< Previous 10 Messages Goto Latest 10 Messages Next 4 Messages >>>
From: Christopher James Huff
Subject: Re: this
Date: 25 Jun 2002 13:38:43
Message: <pan.2002.06.25.12.38.23.999649.635@mac.com>
On Tue, 25 Jun 2002 12:20:58 -0500, Thorsten Froehlich wrote:

> You just don't need it.  If you think about it, what is the "this"
> pointer in C++ for?  To access members without having to use lengthy
> specification of the exact scope you are working on.  But why would you
> want to have to write "self.radius = 1" if you could just as well
> implement it such that you can write "radius = 1"?

But that's not what it is for. In all the examples that have been given,
it is just the addition of the symbol in order to pass the object to a
function. Nobody suggested the example you gave or the syntax changes
needed for it, but you need a "self" symbol to do "min_extent(self)"
without declaring the object first. Allowing "self.radius = 1" would be a
completely separate addition. (I did use "self.min_extent() while talking
about another way of doing that, technically the "self." wouldn't be
necessary, but it was just an example of using min_extent() as a method
instead of a separate function.)


> Or do you always write "this->foo_member" inside a C++ member function?

I actually did for a time with method calls, to make the difference
between calling a method and calling an ordinary function clearer, but I
eventually abandoned it...too much work.


> Given an intelligent enough parser it is even be possible to allow
> substitution of any block-level element with "code like a function" (I
> intentionally want to leave the specific definition of this open).  As
> it woudl effectively allow substitution of anything in an object by
> aosmething declared, there would be no more need for a "self" or "this"
> because as soon as you insert the function it automatically knows which
> context it is in.

That sounds like my understanding of a functional language (I haven't
coded in one and don't know any in detail, but I've read some about them,
and the next language I learn after Ruby will probably be one). A "shape
definition" would be a function that would be called by the renderer with
some parameters given by the renderer and others by the user, and the
parameters themselves could be function calls. An if statement would be a
function with one value if the condition is true and another value if it
is false. Loops seem to be done mainly by recursion.

From the comp.lang.functional FAQ:
"A functional language is a style of programming that emphasizes the
evaluation of expressions, rather than execution of commands. The
expressions in these languages are used by using functions to combine
basic values. A functional language is a language that supports and
encourages programming in a functional style."
http://www.cs.nott.ac.uk/~gmh//faq.html

It sounds similar to an "evaluator" system I've been working on for my own
raytracer, basically a bunch of "evaluators" (basically function objects)
that are plugged together to do shading. I didn't recognize it at the
time, but I was doing a form of functional programming by linking up
functors. POV already does this a bit with things like deeply nested
pigments or textures and the ability to use equations, patterns, and
pigments in functions, though it could be made much more flexible and
simpler.


-- 
Christopher James Huff <chr### [at] maccom>
POV-Ray TAG e-mail: <chr### [at] tagpovrayorg>
WWW: http://homepage.mac.com/chrishuff/


Post a reply to this message

From: Thorsten Froehlich
Subject: Re: this
Date: 25 Jun 2002 15:34:57
Message: <3d18c5e1@news.povray.org>
In article <pan### [at] maccom> , Christopher James
Huff <chr### [at] maccom>  wrote:

>> You just don't need it.  If you think about it, what is the "this"
>> pointer in C++ for?  To access members without having to use lengthy
>> specification of the exact scope you are working on.  But why would you
>> want to have to write "self.radius = 1" if you could just as well
>> implement it such that you can write "radius = 1"?
>
> But that's not what it is for. In all the examples that have been given,
> it is just the addition of the symbol in order to pass the object to a
> function.

Yu still inherit a bunch of problems from pointers/references which are not
necessary.  After all, there is still no real need.  A function simply
operates on whatever object it was called by.  It couldn't access any other
object anyway...

> That sounds like my understanding of a functional language

No, it would not because POV-Ray SDL itself describes a state and still
would after such an extension.  The function would be nothing else but a
user-defined type of texture, pattern, media, vector, float, matrix etc.

    Thorsten

____________________________________________________
Thorsten Froehlich, Duisburg, Germany
e-mail: tho### [at] trfde

Visit POV-Ray on the web: http://mac.povray.org


Post a reply to this message

From: Thorsten Froehlich
Subject: Re: this
Date: 25 Jun 2002 15:38:44
Message: <3d18c6c4@news.povray.org>
In article <Xns### [at] 204213191226> , "Rafal 'Raf256' 
Maj" <raf### [at] raf256com> wrote:

>> specification of the exact scope you are working on.  But why would
>> you want to have to write "self.radius = 1" if you could just as well
>> implement it such that you can write "radius = 1"?
>
> because this is needed to pass current object (this) to other function.
> same as in C++ you would write draw(this);  and not :
> temporary_object = { ... };
> draw(temporary_object);

Not really.  As you cannot reference other objects than the current one
anyway you would not need to pass that information, it would already be
known.

    Thorsten

____________________________________________________
Thorsten Froehlich, Duisburg, Germany
e-mail: tho### [at] trfde

Visit POV-Ray on the web: http://mac.povray.org


Post a reply to this message

From: Rafal 'Raf256' Maj
Subject: Re: this
Date: 25 Jun 2002 15:48:01
Message: <Xns9238DD41336F7raf256com@204.213.191.226>
"Thorsten Froehlich" <tho### [at] trfde> wrote in 
news:3d18c6c4@news.povray.org:

>> because this is needed to pass current object (this) to other function.
>> same as in C++ you would write draw(this);  and not :
>> temporary_object = { ... };
>> draw(temporary_object);
> Not really.  As you cannot reference other objects than the current one
> anyway you would not need to pass that information, it would already be
> known.

hmm ? this is simple - example :


#declare tempObj = union { 
  ........
 }
#declare tempObj = object { tempObj translate max_extent(tempObj).x*3 }
object { tempObj rotate y*3 }
#declare tempObj = object { tempObj translate max_extent(tempObj)*9 }

wouldn't it be nicer to write above just as :

union {
 ........
 translate max_extent( this ).x*3
 rotate y*3
 translate max_extent( this )*9
}

?

it IS easy to implement - as I shown few posts before, even I can myself 
write it, but as pre-procesor function (because I dont have now time/skill 
to modify POV sources itself)

-- 


Post a reply to this message

From: Rafal 'Raf256' Maj
Subject: Re: this
Date: 25 Jun 2002 15:51:07
Message: <Xns9238DDC7C463Craf256com@204.213.191.226>
"Thorsten Froehlich" <tho### [at] trfde> wrote in
news:3d18c5e1@news.povray.org: 

>> But that's not what it is for. In all the examples that have been
>> given, it is just the addition of the symbol in order to pass the
>> object to a function.

> function simply operates on whatever object it was called by.  It

and 'this' will give possibility to pass object it was called by o MACROS - 
with is now impossible without a work-around.

Work around is :
1. tak all statements before 'this'
2. put them togeather into #declare tempIbj = ...
3. repleace 'this' with 'tempObj' 

that's all :)

why not do this automaticly using 'this' ?


-- 


Post a reply to this message

From: Rafal 'Raf256' Maj
Subject: Re: this
Date: 25 Jun 2002 15:53:11
Message: <Xns9238DE21D7CF6raf256com@204.213.191.226>
"Rafal 'Raf256' Maj" <raf### [at] raf256com> wrote in
news:Xns### [at] 204213191226: 

> #declare tempObj = union { 
>   ........
>  }
> #declare tempObj = object { tempObj translate max_extent(tempObj).x*3
> } object { tempObj rotate y*3 }
> #declare tempObj = object { tempObj translate max_extent(tempObj)*9 }

#declare tempObj = union { 
  ........
 }
#declare tempObj = object { tempObj translate max_extent(tempObj).x*3 }
#declare tempObj = object { tempObj rotate y*3 }
object { tempObj translate max_extent(tempObj)*9 }

sorry for mistake

-- 


Post a reply to this message

From: Thorsten Froehlich
Subject: Re: this
Date: 25 Jun 2002 17:10:42
Message: <3d18dc52@news.povray.org>
In article <Xns### [at] 204213191226> , "Rafal 'Raf256' 
Maj" <raf### [at] raf256com> wrote:

> wouldn't it be nicer to write above just as :
>
> union {
>  ........
>  translate max_extent( this ).x*3
>  rotate y*3
>  translate max_extent( this )*9
> }

Yes, but

 translate max_extent.x*3
 rotate y*3
 translate max_extent*9

would be completely sufficient!  No "this" or "self" necessary.

    Thorsten

____________________________________________________
Thorsten Froehlich, Duisburg, Germany
e-mail: tho### [at] trfde

Visit POV-Ray on the web: http://mac.povray.org


Post a reply to this message

From: Rafal 'Raf256' Maj
Subject: Re: this
Date: 25 Jun 2002 17:16:45
Message: <Xns9238EC4CC6811raf256com@204.213.191.226>
"Thorsten Froehlich" <tho### [at] trfde> wrote in 
news:3d18dc52@news.povray.org:

>> union {
>>  ........
>>  translate max_extent( this ).x*3
>>  rotate y*3
>>  translate max_extent( this )*9
>> }
> Yes, but

>  translate max_extent.x*3
>  rotate y*3
>  translate max_extent*9
> would be completely sufficient!  No "this" or "self" necessary.

and if I use some 

#macro fun(obj)
  (max_extent(obj)+min_extent(obj)+sin(....)+....)
#end

instead of just max_extent ?

-- 


Post a reply to this message

From: Thorsten Froehlich
Subject: Re: this
Date: 25 Jun 2002 18:37:31
Message: <3d18f0ab$1@news.povray.org>
In article <Xns### [at] 204213191226> , "Rafal 'Raf256' 
Maj" <raf### [at] raf256com> wrote:

> and if I use some
>
> #macro fun(obj)
>   (max_extent(obj)+min_extent(obj)+sin(....)+....)
> #end
>
> instead of just max_extent ?

You would do

 #macro fun(obj)
   (obj.max_extent+obj.min_extent+sin(....)+....)
 #end

instead.

    Thorsten

____________________________________________________
Thorsten Froehlich, Duisburg, Germany
e-mail: tho### [at] trfde

Visit POV-Ray on the web: http://mac.povray.org


Post a reply to this message

From: Christopher James Huff
Subject: Re: this
Date: 25 Jun 2002 22:09:05
Message: <pan.2002.06.25.21.06.11.222457.378@mac.com>
On Tue, 25 Jun 2002 18:37:22 -0500, Thorsten Froehlich wrote:

> You would do
> 
>  #macro fun(obj)
>    (obj.max_extent+obj.min_extent+sin(....)+....)
>  #end

I think he meant something like:

xxx {xxxx
    fun(self)
}

The macro might be written that way, but it wouldn't be useable without
declaring a temporary version of the object first.

This version should work fine with that syntax though, but only because a
macro isn't a function:
#macro fun()
    (max_extent + min_extent + sin(...) + ...)
#end

-- 
Christopher James Huff <chr### [at] maccom>
POV-Ray TAG e-mail: <chr### [at] tagpovrayorg>
WWW: http://homepage.mac.com/chrishuff/


Post a reply to this message

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

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