ChimeraCoder / MLang

Other
4 stars 0 forks source link

Implement read-file and write-file functions #2

Closed ChimeraCoder closed 12 years ago

ChimeraCoder commented 12 years ago

MLang needs to be able to accept other MLang programs as input and produce them as output - that's the whole point of the program! :-)

(Read-file FILENAME ) should work like Lisp's 'read' function, except it accepts a filename (relative/absolute path).

(write-file FILENAME FOO) should be equivalent to capturing the output of (print FOO) and redirecting that to FILENAME.

[Remember that the printed form of an expression is the sae as the expression required to create the value itself; that is, the output of (print FOO) should be an s-expression that, when read, recreates FOO in memory]

tinkcode commented 12 years ago

The Read file is already implemented. It works as (FILE ..) We can change the name to READ_FILE for better clarity. The Write file is also being implemented. Do we need another explicit WRITE-FILE method?

ChimeraCoder commented 12 years ago

Yeah, I think read-file would be better than read, since (on CL at least) read refers to a stream, not a file, so we should emphasize the difference. What does write do, though? If it writes to a file, we might want to make it write-file for symmetry between read-file and write-file, but the naming isn't a huge concern at this point.

tinkcode commented 12 years ago

I've pushed the code for Read file and write file. Do check it up and let me know if its okay.. The syntax is (READ-FILE filename) (WRITE-FILE (Filename some-mlang-command)) - this will store the evaluated expression in the file

tinkcode commented 12 years ago

I'm reading the file just the way we're reading it from the console. The problem with that is that it considers " " and "\n" as end of line or end of command. So at command line if we currently enter - (QUOTE A) (QUOTE B) it will evaluate to only A. only ((QUOTE A) (QUOTE B)) gives (A B). the same way for the read file if we give ((LABEL L1 (QUOTE A)) (LABEL L2 (QUOTE B)) it will store both the labels in the symbol table. Do we just keep it this way or do we have to modify it so its not all one list?

sarda-nikhil commented 12 years ago

Works fine. No need to modify.