[Swift-user] assigning file variables

Ben Clifford benc at hawaga.org.uk
Wed Feb 25 09:32:27 CST 2009


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