Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2001
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2001

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

Search the Archive

Re: Collecting multiple function arguments into a List?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg30533] Re: Collecting multiple function arguments into a List?
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Tue, 28 Aug 2001 04:54:37 -0400 (EDT)
  • References: <9m6tm1$l8r$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

One possibility is

vars =
Block[{x},Sequence@@Table[ToExpression["x"<>ToString[i]<>"_"],{i,1,8}]];

f[vars]:= {x1,x3}

Definition[f]

f[x1_, x2_, x3_, x4_, x5_, x6_, x7_, x8_] := {x1, x3}

But this will require eight inputs for every function.

--
Allan
---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565

"aes" <siegman at stanford.edu> wrote in message
news:9m6tm1$l8r$1 at smc.vnet.net...
> I have a problem with 8 input variables, call 'em  x1, x2, ... , x8, and
> I want to define a bunch of functions (using :=, not =) that depend on
> various subsets of these variables, e.g.
>
>    f1[ x1_, x2_, x4_] :=  << stuff involving x1, x2, x4 >>
>
>    f2[ x1_, x3_] :=  << stuff involving  x1 and x3 only >>
>
>    f3[[x2_, x3_, x5_, x8_} := << stuff involving x2, x3, x5, x8 >>
>
> To minimize typing and bookkeeping I'd like to define a list of the
> input variables, e.g.
>
>    vars = {x1, x2, x3, x4, x5, x6, x7, x8}
>
> and then write all the function definitions in the simplified syntax
>
>    f1[vars_] := << same stuff as above >>
>    f2[vars_] := << same stuff as above >>
>    f3[vars_] := << same stuff as above >>
>
> Can I do this?  What's the required syntax?
>
>    vars = {x1, x2, x3 ...} ??   OR   vars = {x1_, x2_, x3_} ??
>
>    fn[vars] :=  << >> ??   OR   fn[vars_] := << >>??
>
> Thanks,  siegman at stanford.edu
>


  • Prev by Date: Re: Random often fails to return a result
  • Next by Date: RE: Collecting multiple function arguments into a List?
  • Previous by thread: Collecting multiple function arguments into a List?
  • Next by thread: RE: Collecting multiple function arguments into a List?