gavr123456789 / Niva

Smalltalk like programming language
https://gavr123456789.github.io/niva-site
41 stars 2 forks source link

@TopLevelOnly pragma #295

Open gavr123456789 opened 4 weeks ago

gavr123456789 commented 4 weeks ago

Many langs have effects now, nothing like this in niva(
But at least std doesnt provide any IO.
So there can be a @TopLevelOnly that u put inside of bindings to some IO:

// okio.bind.niva
@TopLevelOnly
type FileSystem
FileSystem readFile:path -> String
//---main.niva
fileSystem = FileSystem new
reader = CSVReader fs: fileSystem
// csvreader.niva
CSVReader read = [
    fs = FileSystem new // ERROR, FileSystem can be created only on top level 
]

Now its only possible to create FileSystem instance in the top level, not inside some other method.
So you need to send FileSystem instance to each place where IO is needed.