MathGroup Archive 2001

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

Search the Archive

Re: = or := ???

  • To: mathgroup at smc.vnet.net
  • Subject: [mg30709] Re: [mg30668] = or := ???
  • From: Mianlai Zhou <lailai at nikhef.nl>
  • Date: Sat, 8 Sep 2001 02:55:36 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Hello, Oliver

In your program the problem is because you want to make the replacement
take effect immediately (so that you have to use Set instead of SetDelayed
to make sure the % refers to rule1). In this case, the right hand side
will be evaluated immediately. So it tried to evaluate list[[1]] and so on
even though list is still an uncertain name. That's caused by your Set.
In general, always use SetDelayed to define a function unless you know
exactly what you're doing. Otherwise it may be dangerous.

I don't know what you really want to do in this example. Do you want to
replace zzz by any specific names that you give when calling this
function? If so, it will not work anyway, because when you call this
function (later) the % will refer to something else, not the rule1. If you
stick to the point that % is rule1, then you have to give the replacement
explicitly.

I wish the above helps.

Good luck.

Mianlai Zhou
Theory Group, NIKHEF
Amsterdam, the Netherlands

On Mon, 3 Sep 2001, Oliver Friedrich wrote:

> Hallo,
>
> I'm in trouble with defining a function (in fact at the moment it works the
> way I wanted, but with horrible workarounds).
>
> I did some computations which led me to a list rule1={xxx->yyy} with a long
> expression.
>
> The next is, that I want to set up a function where expr is modified by
> rule1 and then by rule2
>
> function[s_,list_] :={{expr /.% /.zzz->list[[1]]},{expr /.%
> /.zzz->list[[2]]},{expr /.% /.zzz->list[[3]]}}
>
> Now for the traps: I want to use rule1 with the % because I don't want to
> give that Output a name (never need it again). Now if I define function with
> Set, I get the error that PartSpecification list[[_]] is longer than depth
> of object (I Know what this error means, no problem about this).
> If I define with SetDelayed, I can't use my % notation, because function is
> evaluated repeatedly from within any point in my sessions, and I can't rely
> on % anymore.
> It should work with Set, if I could tell Mathematica that the list_ argument
> in function represents a list. How can this be done (define the "type" of of
> what a symbol stands for?). I played around with some Hold[] stuff, but
> that's not the way, I want to have it.
>
> Any help appreciated !
>
> Oliver Friedrich
>
>
>
>
>
>



  • Prev by Date: Re: FindMinimum and least square minimization
  • Next by Date: Re: Extract coefs. and exponents from a list . Package problem
  • Previous by thread: Re: = or := ???
  • Next by thread: Re: convert graphics