Raja gopalan wrote in post #1147633:
I asked whether [] is a function call, but you said that’s an expression
which returns the value and then I asked what’s the difference between
function and expression and you said function would be created in the
side effect of ‘def’ and expression is anything it returns the value.
I said in Ruby everything is an expression because there are no
statements, i.e. things which do not have a resulting value.
I
understood correctly ,right? Or Am I missing something? Or Are you meant
to say the different kind of syntax to create expression here is this
a=[]?
Honestly, I lost track of the discussion. Your initial question was,
whether [] produces new objects or returns a predefined object. It was
demonstrated that it is the former.
Then you thought that an expression needs inputs to produce outputs
which I denied. Then you asked for a general definition of expression.
Here’s the Wikipedia version:
http://en.wikipedia.org/wiki/Statement_(programming)#Expressions
Then you asked whether function and expression are the same which I
denied and tried to explain in what ways both are related. I also
mentioned that everything you see written in Ruby code constitutes an
expression because everything yields a value. Maybe that was the
confusing bit.
Then you asked whether [] was a kind of function and where the
difference to a regular function invocation was and I said it’s just the
different syntax. And it’s the syntax you have been asking about right
in your first posting.
“It has a different syntax for invocation than other functions.”
Is this a=[]?
No, it’s “[]” or “[9,2,4,7]” whereas for any function it’s “fun”,
“fun()”, “fun 9,2,4,7” or “fun(9,2,4,7)”. “a={any expression}” is an
assignment.
With the current state of the discussion I suggest you get yourself a
textbook or other media introducing programming. That should help get
the basic concepts right.