Encountered usage of 为 接受函数为参数，返回值为函数


I can vaguely translate this as 


  Gets function as parameter, return value is function.


but that's only due to my domain knowledge. I am confused by the use of 为 here. The only 为 I know is when I want to say for someone or something such as


  汉语水平考试是一个考试为了外国人。(HSK is a test for foreigners) - I am not quite sure if it's grammatically correct to append 为 at the very end as such.
接受函数为参数，返回值为函数

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.