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: [mg53252] Re: Thread
  • From: Carlo Teubner <"see signature."@example.com>
  • Date: Mon, 3 Jan 2005 04:29:29 -0500 (EST)
  • References: <cr8eem$r86$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

I have found a solution that works. My original problem with premature 
evaluation of f is easily solved by doing Thread[F[...]] /. F -> f 
instead of Thread[f[...]].

There were some other problems however. In case anyone is interested, 
this is what I've now come up with.

ThreadOptions[f_[args___, opts___?OptionQ], spec___] :=
  Module[{fth=Thread[F[args], spec], oth},
   If[Head[fth]===F, F[args,opts],
    oth = Inner[#2->#1&, Thread[{opts}[[All,2]], {opts}[[All,1]], seq];
    Which[ Head[oth]===seq, Append[#, oth]& /@ fth,
           Length[oth]==Length[fth], Inner[Append, fth, oth, List],
           True, ERROR
         ]  /. seq -> Sequence
    ]
   ] /. F -> f

I realise one could possibly do this in a less cumbersome way by 
transforming, e.g.,

  f[a, {b,c}, Opt -> {1,2}]

to

  f[a, {b,c}, {1,2}],

then applying Thread, and then putting the "Opt ->" rules back in. 
However, in that case one couldn't honour the optional parameters in 
Thread; and also then f[a, Opt->{1,2}] would become
{f[a, Opt->1], f[a, Opt->2]} which I don't really want (i.e. a function 
will thread over only its options, even if it doesn't thread over its 
other arguments).

Carlo

-- 
C   Teubner  t     offline   de
  dot       at minus       dot
   ...oops: "on" not "off" :)


  • Prev by Date: Re: Slowdown
  • Next by Date: Re: For to Map to Increase Speed
  • Previous by thread: Re: Thread
  • Next by thread: Re: Thread