Ask Your Question
1

Changed max function?

asked Dec 15 '11

Harm van den Hoven gravatar image Harm van den Hoven flag of Netherlands
23 2 5

updated Dec 19 '11

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)
delete close flag offensive retag edit

Comments

head(reverse(sort( ... ))); is less efficient, but works for now.

Harm van den Hoven (Dec 15 '11)edit

1 Answer

Sort by ยป oldest newest most voted
0

answered Dec 17 '11

Atze gravatar image Atze
211 2 6

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));
link delete flag offensive edit

Your answer

Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
[hide preview]
Also see the Rascal Tutor.

Question tools

Follow

subscribe to rss feed

Stats

Asked: Dec 15 '11

Seen: 28 times

Last updated: Dec 19 '11