POV-Ray : Newsgroups : povray.general : Function of a function, or function as a function parameter Server Time
23 Nov 2024 16:46:32 EST (-0500)
  Function of a function, or function as a function parameter (Message 1 to 5 of 5)  
From: Bald Eagle
Subject: Function of a function, or function as a function parameter
Date: 11 Jan 2024 11:40:00
Message: <web.65a018e58349df571f9dae3025979125@news.povray.org>
So, I'm working on some other patterns, and I have some general functions that I
want to use.

The problem is that those functions are things like derivatives, which are
functions OF other functions.

Is there a way that I can cleanly and elegantly implement a function declaration
that will allow me to do this?

Otherwise it seems that I'm going to have to either
a) write a macro to #undef the f'(x) function and redefine it for every function
that I want to operate on

and/or

b) wind up defining individual functions for every function I want to take the
function OF - which leads to the morass of multiple functions that I need to
keep track of - so I can remember which one I need, avoid copy-paste errors, and
avoid name collisions - I _disdain_.

Because if I need multiple derivatives at render time, then the macro
work-around is out.

- BE


Post a reply to this message

From: Chris R
Subject: Re: Function of a function, or function as a function parameter
Date: 12 Jan 2024 09:50:00
Message: <web.65a151569ff14ccc17021f505cc1b6e@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
> So, I'm working on some other patterns, and I have some general functions that I
> want to use.
>
> The problem is that those functions are things like derivatives, which are
> functions OF other functions.
>
> Is there a way that I can cleanly and elegantly implement a function declaration
> that will allow me to do this?
>
> Otherwise it seems that I'm going to have to either
> a) write a macro to #undef the f'(x) function and redefine it for every function
> that I want to operate on
>
> and/or
>
> b) wind up defining individual functions for every function I want to take the
> function OF - which leads to the morass of multiple functions that I need to
> keep track of - so I can remember which one I need, avoid copy-paste errors, and
> avoid name collisions - I _disdain_.
>
> Because if I need multiple derivatives at render time, then the macro
> work-around is out.
>
> - BE

I'm not sure I completely understand what you are trying to avoid, but here's an
example of a function-manipulating macro I created that takes a function as a
parameter:

//-----------------------------------------------------------------------------
// Translate_fn(FN,T)
//
#macro Translate_fn(FN,T)
    #local _t   = <1,1,1>*T;
    #local _tx  = _t.x;
    #local _ty  = _t.y;
    #local _tz  = _t.z;

    function {
        FN(x-_tx,y-_ty,z-_tz)
    }
#end

// End Translate_fn
//-----------------------------------------------------------------------------

Usage:
#local _my_function = function(x,y,z) { x*y - z }
#local _my_trans_function = Translate_fn(_my_function, <1,1,1>)

Obviously translation is a lot simpler than taking a derivative, so I may be
missing your point here.

-- Chris R.
-- Happily rendering since 2014


Post a reply to this message

From: Bald Eagle
Subject: Re: Function of a function, or function as a function parameter
Date: 12 Jan 2024 10:35:00
Message: <web.65a15bf19ff14ccc1f9dae3025979125@news.povray.org>
I think that might actually work.
Sometimes I just have those programming blind spots.

I'll try it later and see how it all works out.

Thanks!

- BW


Post a reply to this message

From: kurtz le pirate
Subject: Re: Function of a function, or function as a function parameter
Date: 14 Jan 2024 05:42:10
Message: <65a3ba82$1@news.povray.org>
On 12/01/2024 15:48, Chris R wrote:

> //-----------------------------------------------------------------------------
> // Translate_fn(FN,T)
> //
> #macro Translate_fn(FN,T)
>     #local _t   = <1,1,1>*T;
>     #local _tx  = _t.x;
>     #local _ty  = _t.y;
>     #local _tz  = _t.z;
> 
>     function {
>         FN(x-_tx,y-_ty,z-_tz)
>     }
> #end
> 
> // End Translate_fn
> //-----------------------------------------------------------------------------
> 
> Usage:
> #local _my_function = function(x,y,z) { x*y - z }
> #local _my_trans_function = Translate_fn(_my_function, <1,1,1>)


Hello,


Yes, this works well for functions.
But what about macro in parameter of a macro ?


I explain what I want to do :

* I have several macros :

#macro M1 (a,b,c) ... #end
#macro M2 (a,b,c) ... #end
#macro M2 (a,b,c) ... #end

 * And an other :

#macro MACRO (V1, V2, Macro)
  #local X = ...;
  #local Y = ...;
  #local C = ...,
  Macro(X,Y,C)
#end


I'd like to be able to give at MACRO, M1, M2, ... like that :
MACRO (P, Q, M1) or MACRO (R, S, M2)


Parse_String(String) doesn't seem to be usable, but I'm not sure I
understand how it works ;)


-- 
Kurtz le pirate
Compagnie de la Banquise


Post a reply to this message

From: jr
Subject: Re: Function of a function, or function as a function parameter
Date: 14 Jan 2024 06:55:00
Message: <web.65a3caac9ff14ccc7f6d9cf76cde94f1@news.povray.org>
hi,

kurtz le pirate <kur### [at] gmailcom> wrote:
> ..., this works well for functions.
> But what about macro in parameter of a macro ?

will passing in its string name do ?


> ...
> I'd like to be able to give at MACRO, M1, M2, ... like that :
> MACRO (P, Q, M1) or MACRO (R, S, M2)
>
> Parse_String(String) doesn't seem to be usable, but I'm not sure I
> understand how it works ;)

the result of calling a Parse_String is the literal replacement of that call
(code) with the contents of the file written.  I'd be likely to adapt the
existing Parse_String() to my needs.  fwiw, my Foreach() macro uses
user-supplied "payload" macros to process array data; though no use to you as
is, perhaps the '__cmdStr()' code may provide ideas.


regards, jr.


Post a reply to this message

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