[Swift-user] Variable Declaration

Michael Wilde wilde at mcs.anl.gov
Sat Mar 9 17:55:10 CST 2013


Jay,

An app() function's body is restricted to contain a single command line template and nothing else.  So instead of:

app (messagefile t) parse(messagefile n) {
   string v =  @regexp("abcdefghi", "c(def)g","monkey");  
   echo @extractint(n) stdout=@filename(t);
}

...you need create a separate ("compound") function to do things like string v=().  You can embed arbitrary expressions in the app() body, but it can only have one semicolon-terminated command.  Thats the likely cause of the syntax error.

Also note that your statement "string v = ..." is creating a value that as far as I can see is not used anywhere, so you may want to re-examine that logic.

- Mike

----- Original Message -----
> From: "Jay Lee" <jlee734 at gmail.com>
> To: swift-user at ci.uchicago.edu
> Sent: Saturday, March 9, 2013 5:48:17 PM
> Subject: [Swift-user] Variable Declaration
> 
> 
> Hello,
> 
> I just started with swift today, so excuse my lack of knowledge. I
> have the following code:
> 
> type messagefile;
> type string;
> 
> app (messagefile t) parse(messagefile n) {
> string v = @regexp("abcdefghi", "c(def)g","monkey");
> echo @extractint(n) stdout=@filename(t);
> }
> 
> app (messagefile t) greeting() {
> echo "Hello, world!" stdout=@filename(t);
> }
> 
> messagefile outfile <"hello.txt">;
> messagefile input <"compile.txt">;
> 
> outfile = parse(input);
> 
> 
> 
> I get an error: Could not compile SwiftScript source: line 6:10:
> expecting a semicolon, found '='
> 
> I found that there are mappers that can be used to declare variables
> (namely files), but are these required?
> 
> 
> 
> _______________________________________________
> Swift-user mailing list
> Swift-user at ci.uchicago.edu
> https://lists.ci.uchicago.edu/cgi-bin/mailman/listinfo/swift-user



More information about the Swift-user mailing list