接受函数为参数,返回值为函数
Your translation is quite right. The sentence seems to be a description of a function; which takes a function as the parameter, and its return value is a function too.
To be more precise, the first 为 means
(充当) serve as; act as; play the part of:
call a stag a horse;
指鹿为马
This will serve as a proof.
以此为凭。
The 2nd 为 means
(是) be; mean:
One kilometre is equivalent to two li.
1公里为2华里。
One hundred centimetres make one metre.
100厘米为一米。
为 in 汉语水平考试是一个考试为了外国人 (especially used as 为了) is used for describing the purpose.
介词
(表示目的):
work hard for realizing the four modernizations;
为实现四个现代化而努力工作
write for a living
为生活而写作
BTW: The correct syntax should be 汉语水平考试是一个为了外国人的考试; because 为了外国人 is the modifier of 考试 so it should be put before of 考试 (i.e. the object). More naturally you can say 汉语水平考试是一个面向外国人的考试. Because 为了外国人 is broad and then might be confusing, the specific purpose is hard to get.