[Swift-devel] Re: folding/sequential-while/whatever and accessing data in files

Mihael Hategan hategan at mcs.anl.gov
Fri Sep 7 18:31:30 CDT 2007


On Fri, 2007-09-07 at 17:12 -0500, Mihael Hategan wrote:
> On Fri, 2007-09-07 at 22:04 +0000, Ben Clifford wrote:
> > 'v in a' doesn't get used at all... more complicated. the k I was 
> > intending to put in later on. in java/C style, a terminating cndition with 
> > at least one iteration guaranteed to happen
> 
> Not sure if that is a requirement here.

i.e. the differentiation is on whether the check happens before or after
the block. We don't need to make that distinction here, and whether or
not the loop executes once or not is a matter of the exact values. I
believe that it is unnecessary and perhaps counterintuitive to execute
the loop once if the initial value is the result of some computation
that may very well have yielded a good enough value to begin with.

QBasic, and perhaps others, too, had 'do' loops with 'while' and 'until'
placeable either at the end or beginning of the loop:
do while (x) begin end; do until(x) begin end; do begin end while(x); do
begin end until(x). Made it simple and consistently composable.

But more than anything else is the uniformity of the iteration
constructs that, to me, makes this more appealing.

> 
> >  goes at the end of the 
> > statement block, not the start.
> > 
> > On Fri, 7 Sep 2007, Mihael Hategan wrote:
> > 
> > > Why not
> > > 
> > > fold k, v in a until(@extractint(a[k]) <=2)) {
> > >   a[k + 1] = countstep(a[k]);
> > > }?
> > > 
> > > Would be closer to foreach, and it would not have the implicit variable
> > > "foo".
> > 
> > 
> > 
> > > 
> > > On Fri, 2007-09-07 at 20:48 +0000, Ben Clifford wrote:
> > > > So I fiddled a little and have this code that works ok:
> > > > 
> > > > iterate {
> > > >   a[foo+1] = countstep(a[foo]);
> > > >  print("extract int value ", at extractint(a[foo+1]));
> > > > } until (@extractint(a[foo+1]) <= 2);
> > > > 
> > > > (fully program at the end of this message)
> > > > 
> > > > which runs countstep in sequence until a convergence criteria is met.
> > > > 
> > > > countstep is simple app which counts the number of bytes in its input file 
> > > > and outputs that count to its output file (thus converges rapidly to 1)
> > > > 
> > > > What is different about this over previous repeat/while statements is 
> > > > that:
> > > >  
> > > >  there's an implicitly defined variable 'foo' that iterate{} makes 
> > > > available for each iteration. In the first iteration, the value of foo is 
> > > > 0, and the value is increased with each subsequent iteration, up to 
> > > > (Swift's version of) infinity.
> > > > 
> > > >  there's a function to move from file-content-space to 
> > > > swift-expression-space (the previously discussed @extractint)
> > > > 
> > > > This seems to be the right direction to be going for 
> > > > fold-like/iteration-like structures.
> > > > 
> > > > Full files follow:
> > > > 
> > > > $ cat fold2.swift:
> > > > 
> > > > type counterfile {}
> > > > 
> > > > (counterfile t) greeting(string m) { 
> > > >   app {
> > > >     echo m stdout=@filename(t);
> > > >   }
> > > > }
> > > > 
> > > > (counterfile t) countstep(counterfile i) {
> > > >   app {
> > > >     wcl @filename(i) @filename(t);
> > > >   }
> > > > }
> > > > 
> > > > counterfile startfile <"longstartint.txt">;
> > > > 
> > > > counterfile a[]  <fixed_array_mapper;files="a b c d e f g h i j k l m n o 
> > > > p q r 
> > > > s t u v w x y z">;
> > > > 
> > > > a[0] = greeting("793578934574893");
> > > > 
> > > > iterate {
> > > >   a[foo+1] = countstep(a[foo]);
> > > >  print("extract int value ", at extractint(a[foo+1]));
> > > > } until (@extractint(a[foo+1]) <= 2);
> > > > 
> > > > 
> > > > $ cat wcl
> > > > #!/bin/bash
> > > > 
> > > > echo $(wc -c < $1) > $2
> > > > 
> > > > _______________________________________________
> > > > Swift-devel mailing list
> > > > Swift-devel at ci.uchicago.edu
> > > > http://mail.ci.uchicago.edu/mailman/listinfo/swift-devel
> > > > 
> > > 
> > > 
> > 
> 
> _______________________________________________
> Swift-devel mailing list
> Swift-devel at ci.uchicago.edu
> http://mail.ci.uchicago.edu/mailman/listinfo/swift-devel
> 




More information about the Swift-devel mailing list