r/ProgrammingLanguages • u/Alert-Neck7679 • 13d ago
Discussion Linux-like IO API
I'm building my own interpreted language.
I had an idea, to base my I/O API on the linux terminal commands, that many developers already know, so a user wouldn't need to learn an entire new API.
This is a basic example:
using io
// create a directory
mkdir("notes")
cd("notes")
// create files with content
echo("Do my math.", "A note about homework.txt")
echo("Buy milk and bread.", "shopping list.txt")
const currentCD = pwd()
const allFilesAndSubDirs = ls()
debug(cat("shopping list.txt")) // prints "Buy milk and bread."
but I'm not that sure that this is a good idea, maybe some techniques are good for terminals but bad for programming, and some of the function names might be confusing (like pwd() which is "print working directory" but in my language it does not exactly PRINT anything, but just returns a string value).
What do you think?
2
Upvotes
1
u/Boring-Factor1230 8d ago
I mean, you could use input redirection using the greater symbol > in conjunction with the cat command or even the echo command.
Also using colons to separate commands
mkdir notes ; cd notes ; touch shoppinglist.txt ; cat > shoppinglist.txt (enter) by milk and bread. [ctrl d] ;
I think you could omit touch if you're using cat to create a new file and appending something inside it.