Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Setting Attributes for Function Generated Parameters

  • To: mathgroup at smc.vnet.net
  • Subject: [mg110281] Re: Setting Attributes for Function Generated Parameters
  • From: "Carl K. Woll" <carlw at wolfram.com>
  • Date: Fri, 11 Jun 2010 07:58:12 -0400 (EDT)

On 6/11/2010 2:09 AM, telefunkenvf14 wrote:
> Group:
>
> My goal is to generate a list of symbolic parameters that other
> functions in a package can Map[] over. For sake of example, suppose I
> define the following 'utility' function as part of a larger package.
>
> In[1]:= ClearAll["Global`*"]
> In[2]:= shares[n_?IntegerQ/;n>0,s_Symbol:
> s]:=Module[{i},Table[Symbol[ToString[s]<>ToString[i]],{i,n}]]
> In[3]:= shares[2]
>
> Out[3]= {s1,s2}
>
> I would now like to include the attribute Constant to each of the
> s1, ..., sn generated. What is the best way to do this?
> My gut tells me that ideally I'd want to do this inside the shares[]
> function itself, but I couldn't figure out how. The workaround I've
> been toying with is to define another utility function:
>
> In[4]:= setConstants[vars_]:=SetAttributes[#,Constant]&@vars
>
> This seems to work ok...But does anyone see potential pitfalls with
> this approach?
>
> In[5]:= setConstants[shares[2]]
> In[6]:= Attributes[s1]
> In[7]:= Attributes[s2]
>
> Out[6]= {Constant}
> Out[7]= {Constant}
>
> -RG
>
>    

If the symbol you are creating already has a value, then SetAttributes 
won't work.

Do the symbols need to always start with 1? If not, then using something 
like:

Table[ Unique["s", Constant], {10}]

might be a possibility.

Carl Woll
Wolfram Research


  • Prev by Date: Re: Setting Attributes for Function Generated Parameters
  • Next by Date: Re: Setting Attributes for Function Generated Parameters (with package
  • Previous by thread: Re: Setting Attributes for Function Generated Parameters
  • Next by thread: Re: can't get ListVectorPlot3D to work.