4 ms·
Simply, because they are not unrelated. It would be duplication to have two separate functions to do two tasks that have so much in common.
by atakan_gurkan 4y ago
Simply, because they are not unrelated. It would be duplication to have two separate functions to do two tasks that have so much in common.
- xigoi 4y agoWhat does formatting a string and sending a string to a file have in common?
- atakan_gurkan 4y agoI was replying to your original post, did not notice you posted something different here. Formatting a string and then either returning it or sending it to stdout (or any other stream) has too much in common. The work is done in the formatting, sending is just an after thought. In a sense, this is similar to the parentheses and the prefix notation: it can be distracting if you are not used to it, but after a while it becomes very convenient. And I do not mean to sound snobbish, but you can easily write a couple macros to have different syntax for these two tasks if it really bothers you.
- lispm 4y agoFORMAT does not send a string to a file. It executes a program in a domain specific language which creates output to a stream. This does a bunch of operations. The print functions are being executed on an output stream. If the ARG is NIL, then FORMAT creates a string output stream and later returns the generated string. (format nil "~a" 3) is just short for: (with-output-to-string (stream) (format stream "~a" 3)) ~a is then an operation which writes the argument 3 to the output stream.
- dreamcompiler 4y ago#'format knows nothing about files; it only knows about streams, which is what its first argument designates. A point I try to stress with new CL programmers is that if you write new I/O functions to expect a stream designator they're much more flexible than if they expect a pathname.