Commit b7ac97c7 authored by Duncan White's avatar Duncan White

bugfix: was applying length(intlist) to length(illist) - and by a miracle of...

bugfix: was applying length(intlist) to length(illist) - and by a miracle of structural equivalence it was working:-)  ansi prototypes stopped this, so now two length() functions..
parent 62989cb6
......@@ -6,11 +6,8 @@ EXPORT {
@@
#ifdef HASPROTOS
extern int length( intlist );
#else
extern int length();
#endif
extern int lengthil( illist );
/* bye now */
......@@ -21,7 +18,7 @@ GLOBAL {
@@
int length( l ) intlist l;
int length( intlist l )
{
int len = 0;
int hd;
......@@ -35,6 +32,20 @@ int length( l ) intlist l;
} /* length */
int lengthil( illist l )
{
int len = 0;
intlist hd;
while( l != illist_nil() )
{
get_illist_cons( l, &hd, &l );
len++;
}
return len;
} /* lengthil */
}
......@@ -48,9 +59,9 @@ TYPE {
first = a | b | c | d | e;
second = a( int aa );
third = a | b;
fourth = a | b | c(int cc) | d | e;
fifth = a | b | c(int cc) | d( string dd) | e;
sixth = a(int aa) | b | c | d | e;
fourth = a | b | c(char cc) | d | e;
fifth = a | b | c(BOOL cc) | d( string dd) | e;
sixth = a(int aa, BOOL ab, -string ac) | b | c | d | e;
intlist = nil "nil"
| cons( int first, intlist next ) 1 " , " 2
......
......@@ -32,10 +32,10 @@ void test_illist( void )
il4 = illist_cons( int3, il3 );
printf( "illists:\n" );
printf( "\n il1: len %d, ", length(il1) ); print_illist( stdout, il1 );
printf( "\n il2: len %d, ", length(il2) ); print_illist( stdout, il2 );
printf( "\n il3: len %d, ", length(il3) ); print_illist( stdout, il3 );
printf( "\n il4: len %d, ", length(il4) ); print_illist( stdout, il4 );
printf( "\n il1: len %d, ", lengthil(il1) ); print_illist( stdout, il1 );
printf( "\n il2: len %d, ", lengthil(il2) ); print_illist( stdout, il2 );
printf( "\n il3: len %d, ", lengthil(il3) ); print_illist( stdout, il3 );
printf( "\n il4: len %d, ", lengthil(il4) ); print_illist( stdout, il4 );
printf( "\n\n" );
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment