[Swift-devel] returning primitive values from apps

Mihael Hategan hategan at mcs.anl.gov
Tue Sep 17 16:06:19 CDT 2013


On Tue, 2013-09-17 at 13:03 -0400, Glen Hocky wrote:
> Currently, schematically I would do something like this as
> 
> ------------------
> 
> struct outdata {
>     logfile l;
>     returnfile r;
> }
> 
> (outdata o) app ( a , b ,c ... ){
>     run "-logfile" @filename(o.l) "-returnfile" @filename(o.r)
> }
> 
> o = app(a,b,c)
> 
> int r = readData(o.r)
> 
> --------------
> 
> It wouldn't be as general as the options just suggested, but would one
> option be to have a meta-datatype like "intfile" "stringfile" "floatfile"
> and "booleanfile"
> that automatically performs a readdata to extract a single value from a
> file and store it in a variable of that standard type?

Thanks for the feedback Glen!

The swift compiler could be able to properly infer that in situations
like the one you describe where a file pointer is requested for a
primitive type, it really means that it should pass through
read/writeData. So I don't think separate types are necessary. 

What I'm looking for is an unambiguous and non-confusing way to express
this in the language. I'm not sure about filename(int) since it evokes
feelings of the int not being an int, but then it also makes it clear
that the app will not receive an int value on the command line, but a
file name instead. So maybe that is the way to go. It also has the
advantage that the parser doesn't need to be modified (and that is a BIG
advantage from my perspective).


Mihael




More information about the Swift-devel mailing list