POV-Ray : Newsgroups : povray.programming : this : Re: this Server Time
28 Jul 2024 18:17:42 EDT (-0400)
  Re: this  
From: Christopher James Huff
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

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