POV-Ray : Newsgroups : povray.general : Macro with variable number of parameters... Server Time
29 Jul 2024 14:18:40 EDT (-0400)
  Macro with variable number of parameters... (Message 1 to 10 of 19)  
Goto Latest 10 Messages Next 9 Messages >>>
From: connerc
Subject: Macro with variable number of parameters...
Date: 18 Jun 1999 14:12:11
Message: <376a8bf8$1$pbaarep$mr2ice@news.povray.org>
Is it possible to create a macro with a variable number of
parameters?


I'm trying to create a macro that counts the number of
parameters passed to it and then issue the #macro definition.

Is this possible?

I want a way to make it so the user doesn't have to provide
information that isn't necessary.  Based on the value of the
first parameter, the second is always needed, but the third
may not be.  I'd like to allow the user to do the following.

myMacro(0,"a")

or

myMacro(1,"a","b")

The first and second parameter are needed, but if the first is a 0
(instead of a 1) the third value isn't necessary.

Anyone have any ideas?

-- 
============================================================
  Suburbia is where the developer bulldozes out the trees,
  then names the streets after them.
  
  -- Bill Vaughn
============================================================
   Friday, June 18, 1999 - 02:06 PM (EDT) 
============================================================

_-~-_-~-_-~-_-~-_-~-_-~-_-~-_-~-_-~-_-~~~~~~~~~~-_
+                                   +            +
+   Chris C. Conner                 +    This    +
+   cco### [at] amerisurecom-NOSPAM    +    space   +
+   con### [at] geocitiescom-NOSPAM    +    for     +
+   con### [at] usanet-NOSPAM          +    rent    +
+                                   +            +
~-_-~-_-~-_-~-_-~-_-~-_-~-_-~-_-~-_-~-__________-~


Post a reply to this message

From: Margus Ramst
Subject: Re: Macro with variable number of parameters...
Date: 18 Jun 1999 15:33:19
Message: <376a9eff@news.povray.org>
I'd say it's not possible. Aside from the fact that a called #macro always
expects the same number of params specified in the original, there is a
problem of ambiquity. Let's say, out of 5 parameters the 3rd isn't
necessary. How would you go about omitting it?
The best I've managed was to have long parameters (strings or vectors) take
the value 0 as an alternative meaning "do not use". This, of course, is not
always applicable for vectors. Another thing is to make it possible to use,
for example, "3" instead of "<3,3,3>" by manually promoting the float to a
vector (#local Vector=Float+<0,0,0>;)
But what you want, I think is impossible.

Margus

con### [at] geocitiescom wrote in message
<376a8bf8$1$pbaarep$mr2ice@news.povray.org>...
>Is it possible to create a macro with a variable number of
>parameters?
>
>
>I'm trying to create a macro that counts the number of
>parameters passed to it and then issue the #macro definition.
>
>Is this possible?
>
>I want a way to make it so the user doesn't have to provide
>information that isn't necessary.  Based on the value of the
>first parameter, the second is always needed, but the third
>may not be.  I'd like to allow the user to do the following.
>
>myMacro(0,"a")
>
>or
>
>myMacro(1,"a","b")
>
>The first and second parameter are needed, but if the first is a 0
>(instead of a 1) the third value isn't necessary.
>
>Anyone have any ideas?
>
>--
>============================================================
>  Suburbia is where the developer bulldozes out the trees,
>  then names the streets after them.
>
>  -- Bill Vaughn
>============================================================
>   Friday, June 18, 1999 - 02:06 PM (EDT)
>============================================================
>
>_-~-_-~-_-~-_-~-_-~-_-~-_-~-_-~-_-~-_-~~~~~~~~~~-_
>+                                   +            +
>+   Chris C. Conner                 +    This    +
>+   cco### [at] amerisurecom-NOSPAM    +    space   +
>+   con### [at] geocitiescom-NOSPAM    +    for     +
>+   con### [at] usanet-NOSPAM          +    rent    +
>+                                   +            +
>~-_-~-_-~-_-~-_-~-_-~-_-~-_-~-_-~-_-~-__________-~
>


Post a reply to this message

From: Cliff Bowman
Subject: Re: Macro with variable number of parameters...
Date: 19 Jun 1999 00:45:10
Message: <376b20bc.13826741@news.povray.org>
On Fri, 18 Jun 1999 14:06:39 -0400, con### [at] geocitiescom wrote:

>Is it possible to create a macro with a variable number of
>parameters?
>
>
>I'm trying to create a macro that counts the number of
>parameters passed to it and then issue the #macro definition.
>
>Is this possible?
Is it possible to pass an array? If yes then that's one possible way
round it.


Cheers,

Cliff Bowman
Why not pay my 3D Dr Who site a visit at
http://www.geocities.com/Area51/Dimension/7855/
PS change ".duffnet" to ".net" if replying via e-mail


Post a reply to this message

From: Nieminen Mika
Subject: Re: Macro with variable number of parameters...
Date: 19 Jun 1999 11:15:34
Message: <376bb416@news.povray.org>
In povray.general con### [at] geocitiescom wrote:
: myMacro(0,"a")

: or

: myMacro(1,"a","b")

#macro myMacro(itemsAmount, stringArray)
  ...
#end

-- 
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):5;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/


Post a reply to this message

From: Ron Parker
Subject: Re: Macro with variable number of parameters...
Date: 19 Jun 1999 12:53:39
Message: <376dcac4.120103227@news.povray.org>
On 19 Jun 1999 11:15:34 -0400, Nieminen Mika <war### [at] cctutfi> wrote:

>In povray.general con### [at] geocitiescom wrote:
>: myMacro(0,"a")
>
>: or
>
>: myMacro(1,"a","b")
>
>#macro myMacro(itemsAmount, stringArray)
>  ...
>#end

Or just pass the array and use dimension_size.


Post a reply to this message

From: Matthias
Subject: Re: Macro with variable number of parameters...
Date: 21 Jun 1999 11:21:08
Message: <376e5864@news.povray.org>
Ron Parker <par### [at] fwicom> schrieb in im Newsbeitrag:
376dcac4.120103227@news.povray.org...
> On 19 Jun 1999 11:15:34 -0400, Nieminen Mika <war### [at] cctutfi> wrote:
>
> >In povray.general con### [at] geocitiescom wrote:
> >: myMacro(0,"a")
> >
> >: or
> >
> >: myMacro(1,"a","b")
> >
> >#macro myMacro(itemsAmount, stringArray)
> >  ...
> >#end
>
> Or just pass the array and use dimension_size.
>


elements used in it (which makes the same as just typing an unused
parameter.
My idea is to use a macro with two Parameters. the first is a usual float.
the second could be a float or a vector; like this
#macro(bool,data)
    #if bool
        #declare u.data = a;
        #declare v.data =b;
    #else
        #declare data = a;
    #end
#end

this of course assumes that the user enters the maco correctly (using only
two parameters if bool = 1 )

hope Icould help you
maesju **


Post a reply to this message

From: Rainer Mager
Subject: Re: Macro with variable number of parameters...
Date: 21 Jun 1999 21:36:14
Message: <376ee88e@news.povray.org>
This probably isn't ideal but how about...

#macro myMacro2( val1, val2 )
    myRealMacro( val1, val2, "" )
#end

#macro myMacro3( val1, val2, val3 )
    myRealMacro( val1, val2, val3 )
#end

#macro myRealMacro( val1, val2, val3 )
    ...
#end

...and use they both as...

myMacro2( val1, val2 )
myMacro3( val1, val2, val3 )


--Rainer

<con### [at] geocitiescom> wrote in message
news:376a8bf8$1$pbaarep$mr2ice@news.povray.org...
> Is it possible to create a macro with a variable number of
> parameters?
>
>
> I'm trying to create a macro that counts the number of
> parameters passed to it and then issue the #macro definition.
>
> Is this possible?
>
> I want a way to make it so the user doesn't have to provide
> information that isn't necessary.  Based on the value of the
> first parameter, the second is always needed, but the third
> may not be.  I'd like to allow the user to do the following.
>
> myMacro(0,"a")
>
> or
>
> myMacro(1,"a","b")
>
> The first and second parameter are needed, but if the first is a 0
> (instead of a 1) the third value isn't necessary.
>
> Anyone have any ideas?
>
> --
> ============================================================
>   Suburbia is where the developer bulldozes out the trees,
>   then names the streets after them.
>
>   -- Bill Vaughn
> ============================================================
>    Friday, June 18, 1999 - 02:06 PM (EDT)
> ============================================================
>
> _-~-_-~-_-~-_-~-_-~-_-~-_-~-_-~-_-~-_-~~~~~~~~~~-_
> +                                   +            +
> +   Chris C. Conner                 +    This    +
> +   cco### [at] amerisurecom-NOSPAM    +    space   +
> +   con### [at] geocitiescom-NOSPAM    +    for     +
> +   con### [at] usanet-NOSPAM          +    rent    +
> +                                   +            +
> ~-_-~-_-~-_-~-_-~-_-~-_-~-_-~-_-~-_-~-__________-~
>


Post a reply to this message

From: Matt Giwer
Subject: Re: Macro with variable number of parameters...
Date: 4 Jul 1999 17:17:03
Message: <377FCF6D.E5B49458@giwersworld.org>
> Is it possible to create a macro with a variable number of
> parameters?
> 
> I'm trying to create a macro that counts the number of
> parameters passed to it and then issue the #macro definition.
> 
> Is this possible?
> 
> I want a way to make it so the user doesn't have to provide
> information that isn't necessary.  Based on the value of the
> first parameter, the second is always needed, but the third
> may not be.  I'd like to allow the user to do the following.
> 
> myMacro(0,"a")
> 
> or
> 
> myMacro(1,"a","b")
> 
> The first and second parameter are needed, but if the first is a 0
> (instead of a 1) the third value isn't necessary.
> 
> Anyone have any ideas?

	IF it is possible, it remains poor programming practice. Either
the first parameter is the number of additional parameters to be
passed or write two macros. Your examples would then pass (1,"a")
and (2,"a","b") Alternatively the passing routine can pass an end
of list marker. 

	It is also a dangerous language that would permit what you want.
FORTH comes to mind. 

-- 
<blink>-------please--don't-----------------</blink>

http://www.giwersworld.org/artii/
http://www.giwersworld.org/artiii/

Finally up on 99/06/22 updated 06/30


Post a reply to this message


Attachments:
Download 'us-ascii' (1 KB)

From: Ron Parker
Subject: Re: Macro with variable number of parameters...
Date: 4 Jul 1999 17:58:41
Message: <3780d89d.19745903@news.povray.org>
On Sun, 04 Jul 1999 17:17:33 -0400, Matt Giwer
<mgi### [at] giwersworldorg> wrote:

>	It is also a dangerous language that would permit what you want.
>FORTH comes to mind. 

C and C++ come to mind too.  I couldn't live without varargs.


Post a reply to this message

From: Jon A  Cruz
Subject: Re: Macro with variable number of parameters...
Date: 4 Jul 1999 19:08:44
Message: <377FE9AB.68BBED2D@geocities.com>
Ron Parker wrote:

> On Sun, 04 Jul 1999 17:17:33 -0400, Matt Giwer
> <mgi### [at] giwersworldorg> wrote:
>
> >       It is also a dangerous language that would permit what you want.
> >FORTH comes to mind.
>
> C and C++ come to mind too.  I couldn't live without varargs.

No no no no no no.......... Argh................

So, does your code have lots of GOTO's also? Functions named things like
"function1()" and "func2()"? Void pointers cast all over the place?   ;-)

I never got into FORTH much, but I agree that C and C++ are very dangerous.
That's why I'm glad basic programming courses are switching over to Java.


Post a reply to this message

Goto Latest 10 Messages Next 9 Messages >>>

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