# Behaviour of prepend!() with SymPy

**URL:** <https://discourse.julialang.org/t/behaviour-of-prepend-with-sympy/8921>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [February 8, 2018, 9:23am UTC](https://discourse.julialang.org/t/behaviour-of-prepend-with-sympy/8921 "2018-02-08T09:23:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![moesphere](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/moesphere/32/3348_2.png) [@moesphere](https://discourse.julialang.org/u/moesphere)\
**Post date:** [February 8, 2018, 9:23am UTC](https://discourse.julialang.org/t/behaviour-of-prepend-with-sympy/8921/1 "2018-02-08T09:23:40Z")

</div>

Is the following behaviour intended?

```julia
prepend!([Sym("A"),Sym("B")],Sym("C")) # returns Vector{SymPy.Sym}: [C,B]
prepend!([Sym("A"),Sym("B")],"C") # returns Vector{SymPy.Sym}: [67,A,B]

```

In the first case, A is replaced by C.  
For the second case: Is there a prepend function without conversion to get a Vector{Any}?

---

<div class="post-metadata">

**Author:** ![j\_verzani](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/j_verzani/32/8551_2.png) [@j\_verzani](https://discourse.julialang.org/u/j_verzani)\
**Post date:** [February 8, 2018, 1:47pm UTC](https://discourse.julialang.org/t/behaviour-of-prepend-with-sympy/8921/2 "2018-02-08T13:47:51Z")

</div>

`prepend!` eventually iterates over the object passed to it in the second position. When the string “C” is iterated over, you get `Char` values that don’t convert to symbolic objects. Try instead to call with `["C"]` in place of `"C"`. BTW, you’d see the same issue if you just used string objects.

---

<div class="post-metadata">

**Author:** ![moesphere](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/moesphere/32/3348_2.png) [@moesphere](https://discourse.julialang.org/u/moesphere)\
**Post date:** [February 8, 2018, 3:28pm UTC](https://discourse.julialang.org/t/behaviour-of-prepend-with-sympy/8921/3 "2018-02-08T15:28:34Z")

</div>

Thanks for the info!

`prepend!([Sym("A"),Sym("B")],[Sym("C")])` works.

Before, I used this “workaround”: `a = [Sym("C"), a]`

---

<div class="post-metadata">

**Author:** ![j\_verzani](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/j_verzani/32/8551_2.png) [@j\_verzani](https://discourse.julialang.org/u/j_verzani)\
**Post date:** [February 8, 2018, 3:55pm UTC](https://discourse.julialang.org/t/behaviour-of-prepend-with-sympy/8921/4 "2018-02-08T15:55:24Z")

</div>

For a single term, you should consider `unshift!`, as it is less verbose: `unshift(a, "C")`

---

<div class="post-metadata">

**Author:** ![moesphere](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/moesphere/32/3348_2.png) [@moesphere](https://discourse.julialang.org/u/moesphere)\
**Post date:** [February 8, 2018, 4:44pm UTC](https://discourse.julialang.org/t/behaviour-of-prepend-with-sympy/8921/5 "2018-02-08T16:44:52Z")

</div>

Thanks again!

Side note: `unshift!()` has been renamed to `pushfirst!()` in v0.7, see [https://github.com/JuliaLang/julia/issues/23902](https://github.com/JuliaLang/julia/issues/23902)
