Pass by name and pass by value-result languages

≯℡__Kan透↙ 提交于 2019-12-07 01:53:38

问题


For my programming languages course, I'm trying to write some code snippets in languages that use pass by name or pass by value-result, preferably by default, but any language that even supports either of those would be fine. However, I haven't been able to find a single language that supports either of them. Does anyone know of a language that uses pass by value-result or pass by name? Preferably an imperative language.


回答1:


The wikipedia article on evaluation strategy suggests that call-by-value-result is supported by fortran. Call-by-name is supported by algol 68.




回答2:


I think C Macros are Pass-by-name (not the C language itself of course). I don't know of any pass-by-value-result languages I'm afraid (to be honest I had to do a web search to find out what it means!).




回答3:


if you pass a variable to a fortran function and you modify it there, you also modify it in the calling program:

psuedocode:

int j = 1
print j
addOne(j)
print j

would output:

1
2



回答4:


I think CLIPS expert system language would be pass by name.




回答5:


Both Java and C are pass-by-value language.

C is clearly a pass by value language.

Java is always been told "primitives are passed by value, objects are passed by reference". But since java object is a reference at anytime, so it is actually a reference value.

Java Language specification tells this: http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html#37472




回答6:


Algol supports pass-by-name as you can find some explanation here

I was told that Ada supports pass-by-value/result but haven't tried out yet.



来源:https://stackoverflow.com/questions/718140/pass-by-name-and-pass-by-value-result-languages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!