Re: Local iterator
- To: mathgroup at smc.vnet.net
- Subject: [mg29436] Re: Local iterator
- From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
- Date: Tue, 19 Jun 2001 05:35:51 -0400 (EDT)
- Organization: Universitaet Leipzig
- References: <9gclnf$357$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Hi,
may be it is to trivial but
SetAttributes[myfun, HoldAll]
myfun[f_, iter : {_Symbol, _Integer ..}] :=
Table[f, iter]
works fine.
If you need the For[] function
SetAttributes[myfunFor, HoldAll]
myfunFor[f_, {iter_Symbol, bgn_Integer, end_Integer, step_Integer}] :=
Module[{i},
For[i = bgn, i <= end, i += step,
ReleaseHold[Hold[f] /. iter -> i]
]
]
should work.
Regards
Jens
Vincenzo Vasta wrote:
>
> I would like to write a function like Table, or Do, that takes an iterator
> and invokes a specified function for each value in the iterator interval, I
> could write something working without iterator:
>
> SetAttributes[myfun,HoldAll];
> myfun[fun_, it_, vmin_, vmax_] := Block[{it},
> For[it = vmin, it <= vmax, ++it, Print[fun]]
> ]
>
> myfun[N[Log[x]],x,1,10]
>
> How can I write a function like myfun[f,{i,mix,max,step}] ?
>
> Thanks
> Vincenzo