Message Boards Message Boards

0
|
3180 Views
|
2 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Use output of the Position function to modify an expression?

Posted 4 years ago

Hello

In the following expression

 exp = HoldForm[#1^2 "+"] & /@ {4, 1, 7}

I want to remove the last "+". Its position I get with:

pos = Last[Position[exp, "+"]] 

I know it's correct because :

exp[[##]] &  @@  pos == "+"  (* True*)

But

exp[[##]] &  @@  pos = ""

will not work. I cannot understand it since

exp[[3, 1, 2]] = ""

works OK.

Please explain what is going on ? Thanks

POSTED BY: Jan Potocki
2 Replies
Posted 4 years ago
POSTED BY: Jan Potocki
Posted 4 years ago

ReplacePart is probably a better way to do this

exp // ReplacePart[pos -> ""]
POSTED BY: Rohit Namjoshi
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract