Seeing that this section currently has no active threads, I thought I'd start one. If you have already seen the question before, please don't give out the answer immediately.
*****
Problem: Write a programme that prints out its own source file.
Seeing that this section currently has no active threads, I thought I'd start one. If you have already seen the question before, please don't give out the answer immediately.
*****
Problem: Write a programme that prints out its own source file.
Mind if I do my entry in Perl?
Here it is:
I can do it in two statements of active code
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
Last edited by Dave_Sinkula; 01-10-2006 at 11:40 PM.
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*
Ha ha ha! I should have stated the question as follows: "Write a non-trivial programme that prints out its source code."
*****
Anyway, the solution I have is:
I suppose you could say that I have cheated by using "cat" instead of writing my own "cat." But I'll live with that charge!Code:#include <stdio.h> #include <stdlib.h> int main() { system("cat <insert_filename_here>"); return 0; }
*****
By the way, is the Scheme function given above correct? I mean, the output of that empty list is nothing--right? The output is not a pair of matching parentheses with nothing in between, is it?
Well, outputting an empty list would output a formatted empty list - which is an empty pair of parentheses.
Reisswolf, point one, how isn't that trivial? Point two, have you tried running that on Windows?
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
CornedBee, I am perfectly aware that my programme is specifically for *NIX systems.
Well, I only meant trivial in the sense that it contained a non-zero number of lines of code. Conceptually, it is pretty trivial. (Hence my caveat that the problem might be too easy for experts.)
Do you mean to say that a program with no lines of code is the most complex of all?Originally Posted by Reisswolf
Current Setup: Win 10 with Code::Blocks 17.12 (GNU GCC)
That's not syntactically valid.Originally Posted by webmaster
how is that not valid scheme (or even lisp), it looks valid to me, a nil list in lisp and nothing in scheme.
() may be accepted by some (or many) Scheme implementations, but it is not a valid Scheme expression at least as defined by R5RS.
http://www.schemers.org/Documents/St...ml#%_sec_4.1.3Note: In many dialects of Lisp, the empty combination, (), is a legitimate expression. In Scheme, combinations must have at least one subexpression, so () is not a syntactically valid expression.