[Swift-user] iterate doesn't stop

Ben Clifford benc at hawaga.org.uk
Wed Mar 26 20:43:17 CDT 2008


On Wed, 26 Mar 2008, Luciano Piccoli wrote:

> However, if the number of iterations N is read from the command line it does
> not stop:
> 
>    -- iterate.swift -------
>    int N=@arg("N");
>    iterate i {
>      print (i);
>    } until (i == N);

> Any ideas why?

That shouldn't even compile because the types aren't correct.

@args returns a String, "5"; which is never the same as the number 5.

Not enough type checking going on there - it should fail here:

>    int N=@arg("N");                                                           

However, it doesn't because the compiler doesn't type check enough.

I just committed (in r1772) a function, @toint, that you can use like 
this:

int N=@toint(@arg("N"));

I've used it in the past for exactly this purpose.

-- 




More information about the Swift-user mailing list