Re: Commands Writing To Binary File
- Posted by Andy Mar 27, 2009
- 833 views
This is just a crude example of what I want do. Is there something wrong that I am doing, cause I get an error when I do this, or rather when I go to try it, it crashes on me.
Andy, there are few problems with that example. write_file takes a sequence of data, not just one atom/integer. You could fix that portion by writing write_file(handle, { data }).
The second problem is write_file returns an integer, 1 for success, -1 for failure. You are assigning that result to file which is a sequence, not an integer. I would probably do something like:
procedure SaveFile(sequence filename, object data) if atom(data) then data = { data } end if if write_file(filename, data) = -1 then puts(1, "Cannot write to file!\n") end if end procedure SaveFile("hello.bin", 1)
The above code also gets rid of external states, and external globals both of which are troublesome once an application gets to be more than a few hundred lines of code.
Jeremy
OK, thanks, this is starting to make more sense to me.