HI Massimiliano,
I have written a very nice slash function that covers many cases and placed it in the openlilylib repository. Do take a look at it. No point re-inventing that wheel!
Openlilylib is a project for things that probably should be in the baseline lilypond but for various reasons are not as yet (it's complicated!).
The openlilylib code is on github:
It's a good idea to pull the snippets using git instead of just cutting and pasting into your code. That way you can keep up to date with changes and improvements.
I also have there a very nice beam slash function too.
I think these are quite flexible, and they have been extensively debugged.
Andrew