<div dir="ltr"><div><div><div><div><div><div><div><div><div><div><div><div>There is a little about this topic in the Swift/T user guide, but I thought that I could dmore concisely describe them by relating them to Swift/K mappers. The tl;dr version is:<br>
<ol><li>Swift/T uses plain old vanilla functions to do everything that input mappers can do.</li><li>We only support output mapping individual file variables, but you can provide arbitrary string expressions, so it's very flexible.</li>
<li>Mapping arrays is feasible and on the radar, but doesn't seem to be blocking anything and will be some work.<br></li></ol></div><b>Input mappers<br></b></div>Input mappers don't exist as a distinct feature in Swift/T. Instead you just declare an unmapped file variable, and assign it. Swift/T provides some functions to initialise arrays of files that achieve the same purpose as input mappers in Swift/K. <br>
E.g.<br><br></div>file f = input_file("a_single_file.txt");<br></div>file fs[] = glob("file*.txt");<br><br>I preferred doing things this way as you can do the same things without a special language concept of input mapping. It also makes semantics more consistent (e.g. a
variable is only assigned a value via. the assignment operator, rather
than implicitly as in the input mappers).<br><br></div><b>Output mappers<br></b></div>The general concept of output mappers is the same as Swift/K afaict. The way I interpret it is that, if a programmer maps a variable, then assigns to that variable, then a side-effect of the assignment is that the file contents are created at or copied to that path in the file system. We only support mapping individual files.<br>
<br></div>file f<"output.txt">;<br></div>f = some_function();<br><br></div>You can provide arbitrary string expressions as the mapping, which gives you some flexibility. E.g. if you want to create files result.1.txt, result.2.txt, ..., result.n.txt.<br>
<br></div>file results[];<br>foreach i in [1:N] {<br></div> file f<"result." + fromint(i) + ".txt"> = some_function();<br></div> results[i] = f;<br><div><div>}<br><div><div><div><div><div><br></div>
<div>We don't have support for mapping arrays of files. I don't think there's any difficulty for language semantics, but it will need some implementation work and decisions about what mappers to support. Lack of other mappers hasn't blocked any applications so far, so it hasn't been prioritised. The current obstacles are:<br>
<ul><li>We need runtime/compiler support for attaching mappers to arrays. Fitting that logic into the STC IR will be a little convoluted but should be possible.<br></li><li>It seems like there is opportunity to streamline interfaces/naming of the Swift/K mappers, but I'm not sure exactly how.</li>
</ul><p>- Tim<br></p></div></div></div></div></div></div></div></div>