POV-Ray : Newsgroups : povray.beta-test : [doc] concat with one parameter Server Time
29 Jul 2024 12:18:14 EDT (-0400)
  [doc] concat with one parameter (Message 1 to 10 of 16)  
Goto Latest 10 Messages Next 6 Messages >>>
From: Felix Wiemann
Subject: [doc] concat with one parameter
Date: 21 May 2002 05:13:24
Message: <3cea0fb4@news.povray.org>
RC5 for Unix

#debug concat("POV")

works fine, but the doc says:

concat(S1,S2,...)

IMO the doc and not the function should be changed because this is a useful 
feature to give an RVALUE (and not an IDENTIFIER) as parameter to a macro. 
Or is there a better (shorter) way?
-- 
Felix Wiemann


Post a reply to this message

From: Warp
Subject: Re: [doc] concat with one parameter
Date: 21 May 2002 06:36:28
Message: <3cea232b@news.povray.org>
Felix Wiemann <Fel### [at] gmxnet> wrote:
> IMO the doc and not the function should be changed because this is a useful 
> feature to give an RVALUE (and not an IDENTIFIER) as parameter to a macro. 
> Or is there a better (shorter) way?

  I don't understand why you can't give the value directly.

-- 
#macro N(D)#if(D>99)cylinder{M()#local D=div(D,104);M().5,2pigment{rgb M()}}
N(D)#end#end#macro M()<mod(D,13)-6mod(div(D,13)8)-3,10>#end blob{
N(11117333955)N(4254934330)N(3900569407)N(7382340)N(3358)N(970)}//  - Warp -


Post a reply to this message

From: Felix Wiemann
Subject: Re: [doc] concat with one parameter
Date: 21 May 2002 11:07:48
Message: <3cea62c4@news.povray.org>
Warp wrote:
>   I don't understand why you can't give the value directly.

If the string is modified inside the macro but the original string is 
needed after execution, it's necessary to use concat. For example:


#macro M(S)
        #debug "\n"  // linefeed
        #debug S     // "POV-Ray"
        #debug "\n"
        #declare S = substr(S, 5, 3)  // S = "Ray"
        #debug S     // "Ray"
        #debug "\n"
        #end

#declare S = "POV-Ray"
M(concat(S))
#debug substr(S, 1, 3)  // "POV" or "Ray"


The output is:

POV-Ray
Ray
POV

but if you change M(concat(S)) to M(S) the output is:

POV-Ray
Ray
Ray

-- 
Felix Wiemann


Post a reply to this message

From: Christopher James Huff
Subject: Re: [doc] concat with one parameter
Date: 21 May 2002 11:51:57
Message: <pan.2002.05.21.10.54.53.841372.2143@mac.com>
On Tue, 21 May 2002 11:13:40 -0500, Felix Wiemann wrote:

> Warp wrote:
>>   I don't understand why you can't give the value directly.
> 
> If the string is modified inside the macro but the original string is
> needed after execution, it's necessary to use concat. For example:

In that case, either the macro is written wrong or you are using it
wrong. The concat() function is for concatenating strings, not making
temporary copies. I don't see any reason to document that use, it is
basically a hack and should be discouraged because it leads to code that
appears to do something other than what it really does.

If you don't want to declare a temporary variable, a macro is a better
solution than misusing the concat() function. Something like:

#macro clonestring(String)
    #local tmpString = String
    tmpString
#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

From: Felix Wiemann
Subject: Re: [doc] concat with one parameter
Date: 22 May 2002 07:53:39
Message: <3ceb86c2@news.povray.org>
Christopher James Huff wrote:
> In that case, either the macro is written wrong or you are using it
> wrong. The concat() function is for concatenating strings, not making
> temporary copies. I don't see any reason to document that use, it is
> basically a hack and should be discouraged because it leads to code that
> appears to do something other than what it really does.

Where's the problem with concat? It works fine. Aren't POVers (and computer 
users in general) known for using a function for something totally 
different than it was designed for? And I don't see any possibility that's 
as short as concat.

> If you don't want to declare a temporary variable, a macro is a better
                                                                  ^^^^^^
Why?

> solution than misusing the concat() function. Something like:
> 
> #macro clonestring(String)
>     #local tmpString = String
>     tmpString
> #end

Is much longer. So not better but worse.
-- 
Felix Wiemann


Post a reply to this message

From: Warp
Subject: Re: [doc] concat with one parameter
Date: 22 May 2002 09:22:18
Message: <3ceb9b89@news.povray.org>
Felix Wiemann <Fel### [at] gmxnet> wrote:
> Where's the problem with concat?

  Have you tried just enclosing the string in parentheses?

>> #macro clonestring(String)
>>     #local tmpString = String
>>     tmpString
>> #end

> Is much longer. So not better but worse.

  Perhaps you should learn some basics of (modular) programming.
  "It's much longer" is a really poor excuse for making bad code.
  You have to write one #local more - so what? The alternative is to write
an extra 'concat()' several times, which makes the code quite obfuscated
and longer.

-- 
#macro N(D)#if(D>99)cylinder{M()#local D=div(D,104);M().5,2pigment{rgb M()}}
N(D)#end#end#macro M()<mod(D,13)-6mod(div(D,13)8)-3,10>#end blob{
N(11117333955)N(4254934330)N(3900569407)N(7382340)N(3358)N(970)}//  - Warp -


Post a reply to this message

From: Felix Wiemann
Subject: Re: [doc] concat with one parameter
Date: 22 May 2002 09:46:44
Message: <3ceba144@news.povray.org>
Warp wrote:
> Felix Wiemann wrote:
>> Where's the problem with concat?
> 
>   Have you tried just enclosing the string in parentheses?

What do you mean? Enclose the variable name in parentheses? That of course 
won't work. Note that the string itself is normally not available before 
parsing so it's necessary to use a variable.

>> Is much longer. So not better but worse.
> 
>   Perhaps you should learn some basics of (modular) programming.
>   "It's much longer" is a really poor excuse for making bad code.

Hmmm... The SDL is actually not very modularized. It's more a description 
language than a programming language. Macros and functions are possible but 
structures or even classes aren't supported. When I want to write a program 
for POV-Ray, I write a C++ program which generates SDL code.

>   You have to write one #local more - so what? The alternative is to write
> an extra 'concat()' several times, which makes the code quite obfuscated
> and longer.

OK, normally it's better to write well understandable code, but I'm 
currently working on my signature, so in this case it's very important to 
save even a few bytes.
And IMHO it's not a problem to understand what concat with one parameter 
does.
-- 
Felix Wiemann


Post a reply to this message

From: Warp
Subject: Re: [doc] concat with one parameter
Date: 22 May 2002 09:53:48
Message: <3ceba2ec@news.povray.org>
Felix Wiemann <Fel### [at] gmxnet> wrote:
>>   Have you tried just enclosing the string in parentheses?

> What do you mean? Enclose the variable name in parentheses?

  I said "string", not "variable name".

  When you call your macro, do: MyMacro(("The string"))

>>   Perhaps you should learn some basics of (modular) programming.
>>   "It's much longer" is a really poor excuse for making bad code.

> Hmmm... The SDL is actually not very modularized.

  That doesn't mean you shouldn't make your code as modular as the language
allows.

-- 
#macro N(D)#if(D>99)cylinder{M()#local D=div(D,104);M().5,2pigment{rgb M()}}
N(D)#end#end#macro M()<mod(D,13)-6mod(div(D,13)8)-3,10>#end blob{
N(11117333955)N(4254934330)N(3900569407)N(7382340)N(3358)N(970)}//  - Warp -


Post a reply to this message

From: Christopher James Huff
Subject: Re: [doc] concat with one parameter
Date: 22 May 2002 14:05:54
Message: <pan.2002.05.22.13.08.54.207328.2163@mac.com>
On Wed, 22 May 2002 07:59:33 -0500, Felix Wiemann wrote:

> Where's the problem with concat? It works fine. Aren't POVers (and
> computer users in general) known for using a function for something
> totally different than it was designed for? And I don't see any
> possibility that's as short as concat.

It's common so it must be good?
I already explained the problem with using concat(). It is intended for
concatenating strings, not cloning them. To anyone reading the code, it
looks like you made a mistake: the code does not do what it says it does.
That is a bad thing.


>> If you don't want to declare a temporary variable, a macro is a better
>                                                                   ^^^^^^
> Why?

If you really can't tell...I give up.


>> solution than misusing the concat() function. Something like:
>> 
>> #macro clonestring(String)
>>     #local tmpString = String
>>     tmpString
>> #end
> 
> Is much longer. So not better but worse.

I hope I never have to maintain anything you write...

It is longer by 5 characters, because its name says what it does. That is
a good thing. If the extra 5 characters is that bad, rename it: call it
clnstr() or something. And if you are using it multiple times, it would be
better to skip the macro completely and just use a temporary variable...in
that case, it is shorter than your misuse of the concat() function: the
usual naming convention just adds "tmp" or something similar, which is 5
characters shorter than a call to concat().


-- 
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: Felix Wiemann
Subject: Re: [doc] concat with one parameter
Date: 22 May 2002 14:08:26
Message: <3cebde99@news.povray.org>
Warp wrote:
> Felix Wiemann wrote:
>>>   Have you tried just enclosing the string in parentheses?
> 
>> What do you mean? Enclose the variable name in parentheses?
> 
>   I said "string", not "variable name".
> 
>   When you call your macro, do: MyMacro(("The string"))

Sorry, I thought of quotation marks.
In this example it doesn't make sense. MyMacro((S)) doesn't work either, 
error: "Expected 'numeric expression', string identifier found instead"

>> Hmmm... The SDL is actually not very modularized.
> 
>   That doesn't mean you shouldn't make your code as modular as the
>   language
> allows.

You're right. As I said, I need it for a signature, so it's important that 
it's very short.

INGO, could you perhaps update the doc?
| concat(S1,S2,...)
to
| concat(S1,...)
or something similar.
-- 
Felix Wiemann


Post a reply to this message

Goto Latest 10 Messages Next 6 Messages >>>

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