Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

There's a bunch of languages that automatically return the last value in a function (mostly functional) like Ruby, Haskell, Lisp, etc.

Does this feature (or what do you call it) affect the performance of these languages?

share|improve this question
    
What is the last value? In these languages shouldn't the functions will have only one value? –  Manoj R Nov 27 '12 at 8:26
    
@Manoj R: In Scala (and, AFAIK, in Ruby) a block (and, in particular, the body of a function) consists of a sequence of expressions. The return value of a block is the result of the last expression in the sequence. This might be valid for Lisp as well, but I do not know enough Lisp to confirm it. –  Giorgio Nov 27 '12 at 9:17
7  
It doesn't quite work that way in Haskell: A function never contains more than one expression, and its value is the return value. You may be thinking about monadic computations, where the last action in a do block becomes the return value, but if you desugar the do notation, you'll see that the entire do block is still one expression, and its value (the composed action) is the return value. –  tdammers Nov 27 '12 at 9:21
    
Haskell FTW. :) –  Manoj R Nov 27 '12 at 10:29
    
The class of languages that do this are Expression-oriented programming language –  MichaelT Nov 22 '13 at 3:24

1 Answer 1

In a word - no

With a compiler the emitted code would probably be identically anyway, with an interpreter it will be more or less be the same, if anything slightly quicker.

share|improve this answer
    
of course for a language where you can either use the value of the last expression or use return like TCL you could in theory write an implementation where return was much worse, but only as a pathological case. –  jk. Nov 27 '12 at 10:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.