# How to make Mathematica to assemble components we already have like a regular input

Suppose we have the following list:

{5, 3}


I want to add the -> to the end of the first element in the list in Mathematica programmatically and then add the list of {2,3} to the end of it.

What I want to achieve is to have something that I would have if I typed it directly as the following:

{5->{2,3},3}


Actually, I have the components, and I want to have them assembled in a way that Mathematica understands as an input command.

• The answers below yield your specific case. Are they general enough, or are there things that you need that won't be covered by those examples? – march Jul 24 '15 at 16:41
• @march What is provided is just an example. I want to make Mathematica to behave like it has been typed as a command. – Qaher Jul 24 '15 at 16:48
• The answers below give you an output that can be used as an input, so I'm confused by your clarification. Can you give more details as to what you're doing? – march Jul 24 '15 at 17:00
• There are several ways: Replace/ReplaceAll, ReplacePart, MapAt, Delete+Insert, etc. – Szabolcs Jul 24 '15 at 17:02
• Did one of the solutions below answer your question? If so, please accept one so that we can take it off the unanswered list. If not, please let us know why it doesn't work, and we will attempt to fix the answer. – march Aug 20 '15 at 5:07

Is this the sort of thing you meant?

   mix[{a_, b_}, lis_] := {a -> lis, b}
mix[{5, 3}, {2, 3}]
(* {5 -> {2, 3}, 3} *)


Or did you have in mind some relationship between the argument I denoted lis and the pair constituting the first argument?

createRule[x_, y_] := MapAt[# -> y &, x, 1]


then

createRule[{5, 3}, {2, 3}]


results in

{5 -> {2, 3}, 3}