|
|
|
|
|
|
| |
| |
|
|
|
|
| |
| |
|
|
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
|
|
| |
| |
|
|
|
|
| |
| |
|
|
"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
|
|
| |
| |
|
|
|
|
| |
| |
|
|
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
|
|
| |
| |
|
|
|
|
| |
| |
|
|
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
|
|
| |
| |
|
|
|
|
| |
|
|