[Swift-devel] Re: folding/sequential-while/whatever and accessing data in files
Ben Clifford
benc at hawaga.org.uk
Fri Sep 7 17:04:01 CDT 2007
'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 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
> >
>
>
More information about the Swift-devel
mailing list