why don't you just use (eval (read r)) instead of writing to a file?
I initially did that, but noticed that only the first function being evaluated, and not the rest.
I.E. for Sample #4 it won't load the helper functions (defun vL ..) and (defun MkPt ..)
_$
(eval (read "\r\n\r\n\r\n(defun C:test ( / p )\r\n (and \r\n (setq p (getpoint \"\\nPick a point: \"))\r\n (foreach v (vL 10)\r\n (MkPt (mapcar '+ p v))\r\n ); foreach \r\n )\r\n (princ)\r\n)\r\n(defun vL (n) (list '(0 0 0) (list n 0 0) (list 0 n 0) (list (- n) 0 0) (list 0 (- n) 0)))\r\n(defun MkPt (p) (entmake (list '(0 . \"POINT\") (cons 10 p))))\r\n(C:test)" ))C:TEST
So obviously after trying to call the loaded routine I will get no function definition error.
Another example of the problem is with Sample #5:
_$
(eval (read "\r\n\r\n\r\n '(any type of data can be loaded)\r\n \"Wherever it is string, number or symbol, function or an evaluation.\"\r\n 123\r\n 'abc\r\n lambda \r\n (mapcar '* '(1 2 3) '(4 5 6))"))(ANY
TYPE OF DATA CAN BE LOADED
)