[Swift-user] assigning file variables

Mihael Hategan hategan at mcs.anl.gov
Wed Feb 25 09:40:22 CST 2009


I think we cannot look at a solution without considering mapping. In
other words, there is a semantic distinction between file t; and file m
<"a.txt">;. One says "I don't care how it's named" and the other says
different.

So based on that, we can probably derive a few rules:
t = m -> aliasing
t = t -> aliasing
m = t -> copy; it would be preferable to map t to what m is mapped to
from the start
m = m -> copy.

Mihael

On Wed, 2009-02-25 at 15:32 +0000, Ben Clifford wrote:
> The semantics of file assignments have been discussed on and of for some 
> years.
> 
> Those discussions have left two different ideas floating around in my 
> head:
> 
> i) = as copy
> 
>  The code file a <"foo">; file b<"bar">; a = b; behaves something like cp 
> bar foo.
> 
> Thats pretty straightforward, bu to implement and understandt unclear to 
> me if thats the right thing to do in many cases - for example, when 
> assigning into an array of files, you would end up with the members of the 
> array still being mapped to the filenames that the mapper associated with 
> the array gives, not the filenames of the rhs file in the assignment.
> 
> Its not clear to me if this behaviour, for example, would be useful in the 
> use case you specify. Why do you want to construct the filenames in a 
> difficult way? Is it because you want them to end up with that filename, 
> or because your application wants to generate them that way? In the 
> former, this model doesn't work, though in the latter, if you don't care 
> what they end up being called, thats fine.
> 
> ii) assignment-as-aliasing
> 
> file a; file b<"bar">; a= b turns a into an alias for b, mapped still to 
> the file "bar"; no copying takes place.
> 
> In your case, you'd then end up with an array of aliases to files that are 
> mapped by a bunch of single-file-mappers.
> 
> I haven't really thought this second model through a huge amount but I 
> probably should sit down and play with it.
> 
> In your specific case, can you show the code that your trying to make 
> work? If you are running a foreachwhere the cardinality is known before 
> hand (i.e. you know how many iterations you want, before the start of the 
> loop) you can perhaps programatically construct a string[] array with your 
> constructed filenames, and then use an array mapper to use that array of 
> strings as the filenames for an array.
> 
> So one foreach loop to make string[] arraynames, then a statement to use 
> arraynames to map an entire array, and then your original foreach loop.
> 
> In the case of an iterate where the cardinality is not known before hand, 
> that method probably doesn't work.
> 




More information about the Swift-user mailing list