Hi,
in the following code, the procedure s behaves differently on the second
and subsequent iterations than the first .. the cpp code looks like it's
turned the routine into a thread or something ... does it always do that
to procs?
cheers,
Jonathan.
#import <flx.flxh>;
open List;
open C_hack;
struct DLL_List[T] {
next : &DLL_List[T];
prev : &DLL_List[T];
item : T;
}
fun eq[T]: T * T -> bool = "$1==$2";
fun eq[T] (x:T) (y:T):bool =
{
return eq[T](x, y);
}
fun new_DLL_List[T] (n:T):&DLL_List[T] =
{
var x : DLL_List[T];
x.next = &x;
x.prev = &x;
x.item = n;
return &x;
}
proc add_Link[T] (nxt:&DLL_List[T], lst:&DLL_List[T])
{
(*nxt).prev = lst;
(*nxt).next = (*lst).next;
(*((*lst).next)).prev = nxt;
(*lst).next = nxt;
}
proc print[T]:T="std::cout << $1;";
proc pr_list[T](lst : &DLL_List[T], been: list[&DLL_List[T]])
{
print "List(";
print[T] (*lst).item;
print ")->";
if (mem (eq lst) been) == false do
pr_list ((*lst).next, Cons[&DLL_List[T]](lst, been));
else
print "Loop\n";
done;
}
proc s (n:int, m:int, root:&DLL_List[int])
{
if n <= m do
var x = Cstdlib::rand() % 101;
print x;
endl;
var y = new_DLL_List[int](x);
add_Link[int](y, root);
pr_list[int](root, Empty[&DLL_List[int]]);
s (n + 1, m, root);
done;
}
Cstdlib::srand(101u);
var lst1 = new_DLL_List[int](1);
var lst2 = new_DLL_List[int](2);
var lst3 = new_DLL_List[int](3);
pr_list[int](lst1, Empty[&DLL_List[int]]);
add_Link[int](lst2, lst1);
pr_list[int](lst1, Empty[&DLL_List[int]]);
add_Link[int](lst3, lst1);
pr_list[int](lst1, Empty[&DLL_List[int]]);
endl;
s(1, 1, lst1);
s(1, 1, lst1);
s(1, 1, lst1);
endl;
s(1, 3, lst1);
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Felix-language mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/felix-language