# Let us make a quine maker!

You are to create a program, that, given another program, and a position, will make it a quine. Namely, it needs to insert an expression at that point that evaluates to a string that is the programs input. For example:

main=do
putStrLn "Welcome to the open source program, would you like my source code?"
(ans:_) <- getLine
case ans of
'y' -> putStrLn  --Quine goes here
'n' -> putStrLn "Okay, Good bye"
_  -> putStrLn "Unrecongnized command. Try again." >> main


Now if I told it to put the source code at (5,24) the result would be.

main=do
putStrLn "Welcome to the open source program, would you like my source code?"
(ans:_) <- getLine
case ans of
'y' -> putStrLn ((\a b->a++(show a)++" "++(show b)++b) "main=do\n    putStrLn \"Welcome to the open source program, would you like my source code?\"\n    (ans:_) <- getLine\n    case ans of\n        'y' -> putStrLn ((\\a b->a++(show a)++\" \"++(show b)++b) " ")--Quine goes here\n        'n' -> putStrLn \"Okay, Good bye\"\n        _  -> putStrLn \"Unrecongnized command. Try again.\" >> main\n")--Quine goes here
'n' -> putStrLn "Okay, Good bye"
_  -> putStrLn "Unrecongnized command. Try again." >> main


Clarifications:

• The program you make and the type of programs it act upon may be different if you like.
• Your program may get the position in the program and its source code however it sees fit. You may put the new source code where ever you see fit.
• Obviously, the new program can't simply grab its source code from its file
• You may only insert things at the position the user specifies (so you may not be able to include any new modules in the new program depending on target language)

This is code golf, so shortest answer wins! Let us see how many different languages we can make quine makers for as well.

# J - 73 char

Takes input on stdin, as the 0-origin index in characters and the source, separated by a newline. Introduces a copy of the program at the specified point as a string.

((".@{.~({.,}.,~'(',')',~(LF;''',LF,''')rplc~quote@])(}.~>:))i.&LF)1!:1]3


Explained by explosion:

(                                  )1!:1]3  NB. stdin
(                           )i.&LF         NB. find the first newline
{.~                                    NB. the index part of input
".@                                       NB. convert index to integer
(}.~>:)               NB. the source program part
({.,}.,~     )                      NB. program before and after index
...@]                       NB. program quoted properly


For example, given input

3
abcdef'ghij'
kl mn 0p1


the output is

abc('abcdef''ghij''',LF,'kl mn 0p1')def'ghij'
kl mn 0p1


because J uses Pascal-style strings: 'Isn''t this great?'

import System.Environment
import Data.List
main = do
[p] <- getArgs