Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*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 2005

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

Search the Archive

Re: Thread

  • To: mathgroup at smc.vnet.net
  • Subject: [mg53247] Re: [mg53238] Thread
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Mon, 3 Jan 2005 04:29:23 -0500 (EST)
  • Reply-to: hanlonr at cox.net
  • Sender: owner-wri-mathgroup at wolfram.com

ThreadOptions[f_[args___,opts___?OptionQ]]:=
    Thread[Thread/@f[args,opts]];

ThreadOptions[f[{1,2},Opt1->{a,b},Opt2->{x,y}]]

{f[1, Opt1 -> a, Opt2 -> x], f[2, Opt1 -> b, Opt2 -> y]}


Bob Hanlon

> 
> From: Carlo Teubner <"see signature."@example.com>
To: mathgroup at smc.vnet.net
> Date: 2005/01/02 Sun AM 04:12:47 EST
> To: mathgroup at smc.vnet.net
> Subject: [mg53247] [mg53238] Thread
> 
> I'm trying to write a variant of Thread which takes into account 
> options. That is, I want
> 
>   ThreadOptions[ f[{1,2}, Opt1 -> {a,b}, Opt2 -> {x,y}] ]
> 
> to give
> 
>   {f[1, Opt1 -> a, Opt2 -> x], f[2, Opt1 -> b, Opt2 -> y]}.
> 
> A first approximation I've come up with is
> 
>   ThreadOptions[f_[args___, opts___?OptionQ]] :=
>     Thread[f[args, Inner[Rule, Sequence@@Thread[{opts}, Rule], List]]]
> 
> Now I get
> 
>   {f[1, {Opt1 -> a, Opt2 -> x}], f[2, {Opt1 -> b, Opt2 -> y}]}
> 
> which is close. I need to get rid of the {}. The following works:
> 
>   ThreadOptions[f_[args___, opts___?OptionQ]] :=
>     Thread[f[args, Inner[Rule, Sequence@@Thread[{opts}, Rule], seq]]] /.
>      seq -> Sequence
> 
> However, there is a problem: now f gets evaluated before replacing the 
> seq with Sequence objects. To get around this, I tried using Unevaluated:
> 
>   ThreadOptions[f_[args___, opts___?OptionQ]] :=
>     Unevaluated[Thread[f[args, Inner[Rule, Sequence@@Thread[{opts},
>     Rule], seq]]] /. seq -> Sequence
> 
> But it doesn't work; I get:
> 
>   Thread::tdlen : Objects of unequal length in f[{1, 2}, {Opt1 -> a,
>   Opt2 -> x, Opt1 -> b, Opt2 -> y}] cannot be combined.
> 
>   f[{1, 2}, {Opt1 -> a, Opt2 -> x, Opt1 -> b, Opt2 -> y}]
> 
> I assume what's happened is that ReplaceAll has been applied to the 
> Unevaluated expression, which has not been evaluated.
> 
> Is there any way at all of Thread'ing a function, but then not 
> evaluating it? Are there other ways of creating a ThreadOptions function?
> 
> Thanks for any help.
> 
> Carlo
> 
> 
> -- 
> C   Teubner   t      offline   de
>   dot        at  minus       dot
>    ...oops: "on" not "off" :)
> 
> 


  • Prev by Date: Re: Thread
  • Next by Date: Re: Re: Slowdown
  • Previous by thread: Re: Thread
  • Next by thread: Re: Thread