With Erlang I can do something like this:
"kapa" ++ D = "kapagama". % D now has a value "gama"
Is there a way to put the "variable" in left position? Something like
D ++ "gama" = "anyLengthStringgama".
For this expression shell returns an error:
* 1: illegal pattern
Bonus question: Can somebody explain why it doesn't work? What is the logic behind it?
"kapa" ++ D = "kapagama".
is just syntactic sugar for
[$k, $a, $p, $a | D] = "kapagama".
and this is just syntactic sugar for
[$k|[$a|[$p|[$a|D]]]] = "kapagama".
There is not any counterpart for this code:
D ++ "gama" = "kapagama".
which this can be syntactic sugar for. So as Steve Vinoski wrote, you have to do use lists:reverse/1
"amag" ++ D = lists:reverse("kapagama"), lists:reverse(D).
or use re
module.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With