I work with a list of tuples, where the first element is an integer value so I can use the max() function to get the object/file/method with the highest value (e.g. for complexity or LOC).
The following code worked, until the last update (12-dec). Is there a workaround or another approach?
rascal>max([<10,"demo.Dup2.Dummy4()">,<3,"demo.Dup2.Dummy5()">,<8,"demo.Dup1.Dummy2()">]);
std:///List.rsc:90,14: The called signature: max(tuple[int,str], tuple[int,str]),
does not match any of the declared (overloaded) signature patterns:
max(int n, int m)
max(list[&T] lst)
Indeed a bug, the problem was that max for a list was implemented with max for 2 elements, but a general max for 2 elements did not exist (only for 2 integers). I fixed this in the trunk of rascal, it will be in the next release. In the meantime, put this in your code:
public &T max(&T n, &T m) = n > m ? n : m;
public &T min(&T n, &T m) = n < m ? n : m;
public &T max(list[&T] lst) = (head(lst) | max(e,it) | e <- tail(lst));
public &T min(list[&T] lst) = (head(lst) | min(e,it) | e <- tail(lst));
Asked: Dec 15 '11
Seen: 28 times
Last updated: Dec 19 '11
Copyright CWI, 2010-2012. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.
head(reverse(sort( ... ))); is less efficient, but works for now.
Harm van den Hoven (Dec 15 '11)edit