After deliberating over the matter, I’ve decided that it’d be best to write an extension for Copper that would enable file reading and writing. This would enable the language to finally be general purpose, putting it among the big boys like Python. While the current Copper VM is certainly not fast enough to compete, the ease, power, and syntax of the language make it a highly tempting alternative.

The file system itself will use the basic C File system. The reason being is two fold: The C++ libraries are both extra overhead and may conflict with other libraries I use with Copper.

So what will the syntax look like?

Since Copper enables us to pass around custom user objects, File objects will be wrapped as Copper objects and should be created using a simple function:

handle = open_file("./myfile.txt")

However, what about file open failure? Empty function could be returned, which is the default and easy enough to check for. However, an alternative method would be to pass in a function that receives a file handle and a file error signal.

open_file("./myfile.txt" [handle err] { if(are_empty(handle:)){ print(err.message:)} else { doFileActions(handle) } })

As you can imagine, writing and closing the file should be equally as easy.

write_file(handle: "Hello world")

Alternatively, the file could be closed at the end of the open_file() function and the handle be set to “closed” so no further writing could be done to the File object.

Why Not Built It In?

Copper is a scripting language meant for multipurpose use, not a general purpose language. By not including file reading and writing, Copper could be used in situations where file access is not available.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s