Hash of structs, declaration of function return


#1

Hi again,

Is it normal that I fail declaring a function that returns a hash of structs? I mean, declaring it directly fails, but I can make a typedef and then it works.

Example:

#!/usr/local/bin/L

struct mystruct {
	int i;
	string s;
};

typedef struct mystruct mystruct_t;

/*
// Won't compile:
//  L Error: syntax error, unexpected }, expecting & or id or type name
//  struct mystruct{string}
//                        ^
struct mystruct{string} build_struct(string string_list[]) {
*/

mystruct_t{string} build_type(string string_list[]) {
	struct mystruct res{string};
	string s;
	int i=0;

	foreach(s in string_list) {
		res{s}={i, s};
		i++;
	}
	return res;
}

/*
// Anonymous prototype won't compile:
//  L Error: syntax error, unexpected }, expecting & or id or type name
//  void show(struct mystruct{string}
//                                  ^
void show(struct mystruct{string});
*/

void show(struct mystruct hs{string}) {
	string key;
	struct mystruct val;

	foreach(key=>val in hs) {
		puts("${key} => ${val.i} : ${val.s}");
	}
}

void main() {
	struct mystruct strB{string}=build_type({"first", "second", "last"});
	mystruct_t typeB{string}=build_type({"first", "second", "last"});

	show(strB);
	show(typeB);
}

See, I can declare variables as hashes of structs, but I cannot declare functions returns in the same way, I must use a typedef.

Is this expected?