Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #8267

Re: Function Doesn't Evaluate Local Variables?

From Brentt <brenttnewman@gmail.com>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Function Doesn't Evaluate Local Variables?
Date 2012-01-31 10:38 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <jg8gbc$113$1@smc.vnet.net> (permalink)
References <CAFJC7Xr9ACFiAvBapMcyxMzXgpwRymVc_XMTKkXFeu=MbQi3rw@mail.gmail.com>

Show all headers | View raw


I figured out that the issue is that Function has HoldAll attribute. But
for some reason Release Hold and Evaluate will not work to get those bits
to evaluate. At least not the way I know how to use them. Is there a way to
release the hold on things inside a pure function?

On Mon, Jan 30, 2012 at 10:38 AM, Brentt <brenttnewman@gmail.com> wrote:

> Sorry this
>
> ReplacePart[#1, n -> p #1[[n]] + q #1[[m]]&
>
> should be this
>
>
> ReplacePart[#1, n -> p #1[[n]] + q #1[[m]]]&
>
> On Mon, Jan 30, 2012 at 10:37 AM, Brentt <brenttnewman@gmail.com> wrote:
>
>> Hello, this result is puzzling me.
>> I'm trying to make a function that outputs a pure function.
>>
>> The inputs are two expressions of the form
>>
>> input1: p r[n] + q r[m]
>> input2: r[n]
>>
>> And the output should be a pure function of the form:
>> ReplacePart[#1, n -> p #1[[n]] + q #1[[m]]&
>>
>>
>> This was my attempt:
>>
>> row[n_] := Hold[Part[Slot[1], n]];
>> rpl[old_, new_] := Block[{index, newrow},
>>    index = new[[1]];
>>    newrow = old /. r -> row;
>>    ReplacePart[#1, index -> newrow] &
>>    ];
>>
>> But when using rpl,  for some reason doesn't evaluate index and newexp,
>> and just gives me this
>>
>> In[1]:= rpl[2 r[1] + 3 r[2] , r[1]]
>> Out[1]= ReplacePart[#1, index -> newrow] &
>>
>> Why did it not give the appropriate expressions for "new row" and "index"
>> but instead just output the names of the variables?
>>
>> In case you are curious, I'm trying to write a program that takes a list
>> of elementary row opeartion, specified by a list of the form
>> operationSequence ={
>> 1 r[1] + 2 r[2] -> r[1],
>> r[1] <-> r[2],
>> 2 r[1] -> r[1]
>> }
>> and transforms each row operation in the list into a function, and uses
>> compose list to output a nicely formatted sequence of row operations to
>> Latex. Any pointers for a more elegant way to do this would be most
>> welcome.
>>
>>
>>
>>
>>
>

Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread


Thread

Re: Function Doesn't Evaluate Local Variables? Brentt <brenttnewman@gmail.com> - 2012-01-31 10:38 +0000

csiph-web