[Swift-devel] New built-in system, request for comments
Mihael Hategan
hategan at mcs.anl.gov
Sat Apr 5 11:39:44 CDT 2014
On Sat, 2014-04-05 at 10:56 -0500, Michael Wilde wrote:
> On 4/4/14, 5:47 PM, Mihael Hategan wrote:
> > I think that from a language design perspective there two important
> > questions to ask:
> >
> > 1. Can you reasonably achieve the same with existing swift features?
> No, not "reasonably". We do this to date by calling sh as an app. You
> need to obtain the cwd first, then pass that to the app to get it to cd
> to the swift working dir. All told, a lot of code and cognitive
> dissonance for a simple task.
I see and agree.
> > 2. Where else would system() be useful?
> Whenever a Swift script needs to perform shell-like operations relative
> to its current environment. Same reason C and virtually every other
> language provides a system( ) function. Eg, directory setup, cleanup, etc.
Right, but I'm not sure many of these make sense in swift. There is no
directory setup and there is no cleanup.
>
> But yes, a driving motivation here was to separate the task of finding
> the set of files that to be mapped from the semantics of mapping, and to
> provide the arbitrary flexibility to filter such lists that is often
> needed. And which should not in my opinion be hardwired into mappers.
But then let's address the issue instead of providing an escape to
semantics that we were trying to get away from in the first place.
>
> I feel that Swift users would be best served by a very simple set of
> minimal mapping constructs, that would be used with powerful flexible
> functions like system( ) and glob( ) to let users do anything they would
> need or imagine.
I'm worried that this might happen:
file out <"out.txt">;
out = someApp();
file files[] <ArrayMapper; files = system("cat out.txt")>;
system("rm out.txt");
Which is broken in many ways.
Mihael
More information about the Swift-devel
mailing list