What's the difference between generating a value and returning avalue?

G

grocery_stocker

Taken from the url....

http://openbookproject.net/thinkCSpy/ch05.xhtml#index15

"The built-in functions we have used, such as abs,
pow, and max, have produced results. Calling each of
these functions generates a value, which we usually assign to a
variable or
use as part of an expression.


biggest = max(3, 7, 2, 5)
x = abs(3 - 11) + 10

But so far, none of the functions we have written has returned a
value.

In this chapter, we are going to write functions that return values,
which
we will call fruitful functions,"

So what's the difference between generating a value and returning a
value?
 
A

Alan G Isaac

http://openbookproject.net/thinkCSpy/ch05.xhtml#index15

"The built-in functions we have used, such as abs,
pow, and max, have produced results. Calling each of
these functions generates a value, which we usually assign to a
variable or
use as part of an expression.


biggest = max(3, 7, 2, 5)
x = abs(3 - 11) + 10

But so far, none of the functions we have written has returned a
value.



I do not think this distinction is intended.
The key point is that the user-*written* functions
up to then do not include and explicit return statement.
(Actually, they still return None, which can in fact
be bound to a name.)

However it might (?) be that they are trying to
allow that some callable objects are not function types.
(E.g., creating an instance by calling the class,
which some of the builtins do.) If so, this terminology
would not be a standard way of making that distinction.

Alan Isaac
(*not* a CS type)
 
J

John Yeung

So what's the difference between generating a value and returning a
value?

I agree with Alan's first thought, which is that no distinction was
intended. In my opinion, it's especially poor form to use the term
"generate" in that context when the language you are using to explain
these concepts has very specific things called "generators".

(Until I followed the link, I thought the person was talking about the
difference between functions with "return" and functions with
"yield".)

John
 
A

alex23

In my opinion, it's especially poor form to use the term
"generate" in that context when the language you are using to explain
these concepts has very specific things called "generators".

In its defense, I'm pretty sure 'How to Think Like a Computer
Scientist' predates the introduction of generators to Python.
 
D

Daniel Dalton

So what's the difference between generating a value and returning a
value?

Well when you return, you would use the "return" keyword, I would
imagine... I guess generating could mean many things, you can generate a
value by operating on something, but I guess this does imply returning a
value, because the function returning the value is generating a new
value... But, I know for sure that when you return a value it is the
information the function returns to the caller after operating on either
no, or some arguments.

Daniel.
 
D

Dave Angel

Clearly, there's no difference, from the wording you quoted. He uses
three words more or less interchangeably, "produced", "generated" and
"returned."

The distinction he's making is not between these words, but between the
built-in functions, which are already returning values, and the ones
that he has had the user write so far, that do not.

DaveA
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,079
Latest member
ElidaWarin

Latest Threads

Top