A few minor issues


#1

Hi,

Here are a few miscellaneous issues that I encountered while trying L.

The compiler does not warn about functions missing return values. I hope that can be improved.

The parser requires braces in if-then-elses, unlike if statements. I didn’t see it mentioned in the documentation.

The function pointer typedef examples in the reference guide are missing ampersands:

typedef int str_compar_t(string a, string b);
typedef int compar_t(int a, int b);

I thought (wished!) system/spawn with an argument vector passed through the arguments without interpretation, like C exec, but unfortunately they expose the special argument handling of tcl exec (that I read about later). Other users might also find this comment misleading:

// Same thing but no quoting issues, like execve(2).
ret = system(argv);

Peter


#2

Can you provide an example where the compiler doesn’t warn about missing return values because the trivial test case shows it does (I believe you, just need to see how to reproduce).

Add a “braces” section.

The function pointer typedefs don’t include the ampersand, they are added in the calls:

string[] bubble_sort(string a[], str_compar_t &compar)

On the exec stuff, yeah, agreed, we’ll see if we can add that. Or if you’re a C programmer see if there is a way to do it. I bet [exec --exact {/bin/cat $file}] would be a neat addition.


#3

It looks like the compiler only checks for missing return values at runtime. If the function is not called there is no warning.

#!/usr/local/bin/L

int sum (int a, int b) {
    int s;
    s = a+b;
}

void main() {
    puts("I didn't call sum");
}

EDIT: Maybe the compiler only check in function calls but not in function definitions.


#4

Oddly enough this is valid in C:

#include<stdio.h>

int sum(int a, int b) {
    int s;
    s = a+b;
}

int main() {
    printf("%d", sum(1, 2));
}

Tcl also returns the last evaluated value.

proc sum {a b} {
    expr {$a + $b}
}

puts [sum 1 2]

#5

That is not valid C, it just happens to do the right thing.

$ gcc -Wall example.c 
example.c: In function ‘sum’:
example.c:4:9: warning: variable ‘s’ set but not used [-Wunused-but-set-variable]
     int s;
         ^
example.c:6:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^

#6

This is what I get:

% cat typedef.l 
typedef int str_compar_t(string a, string b);
% L typedef.l 
typedef.l:1: L Error: syntax error, unexpected (, expecting ;
typedef int str_compar_t(
                        ^

It parses only with the ampersand.