Computer said:
"André Thieme" <
[email protected]> wrote in
message news:
[email protected] years go. All we could seem to do is have lots of brackets with calls
to functions embedded..don't like them. In fact most Lispers even love them. The brackets (or
any other mechanism that tells the compiler where an expression starts
and ends) make many things easy.
Quite nice I suppose... Although I don't really mind adding those
extra +'s.... Then again I can't really imagine just adding alot of
variables together.
This was just an example regarding infix operators. The most common use
for infix operators are functions which work on two arguments, like the
addition.
In CL the + has no special meaning like it has in C++, where it is an
operator - in CL it is just a name. The could have called it also "add".
Then it would look more common: add(100, 25);
To make it shorter they called it +:
+(100, 25);
Now remove the , and the ; and move the + inside the brackets and you
have CL.
That CL does not treat mathematical functions (which are usually written
infix) different has the disadvantage that you need two brackets if you
want to do it only one time, but on the other hand the advantage that it
is a function which accepts any amount of arguments and saves some typing.
you need to do a lot of math then don't hesitate to use a math module,
so you can write mathematical expressions like you are used to.
That's horrible... What if 'x' was also a function name etc...
Image a C++ program where f and x are functions. What would happen if
you do:
f(x, y, z);
Something "horrible".
If you wanted to do f(x(), y, z); then it would be in Lisp: (f (x) y z)
It just doesn't seem good to have the function name inside the ()'s
to me.
This does not really mean much. In mathematics some people also write
everything postfix:
(x, y, z)f; [a "postfix C++"]
(x y z f) [a "postfix Lisp"]
Use this five days and you don't see anything bad about it. In fact it
is not the expression which is wrong.. it is the human brain which is so
slow with adopting that. Your computer will accept any expression when
you explain him how it is built. So in that way we can learn from our
machines ;-)
like the Lisp version; f(x y (g z))
Having the function name inside AND outside ()'s... I'll stick to the
most common "always outside ()'s" thanks.
As others pointed it out: it was a typo from my side.
The special thing about Lisp is, that if you know that (nearly always)
the first thing in brackets is the name of a function and the rest are
the arguments, then you nearly know all basics.
curly braces... as long they did not close a struct", etc...
I don't remember that at all... I just put ','s in between the passed
parameters. Just emphasises the difference between a space and a change
of parameter.
Say I wanted this in C++
func(1, 2 + 3, a, "- b")
while in Lisp is seems it would be:
(func 1 (+ 2 3) a "- b")
but it's probably a tiny bit different.
Congrats to your first Lisp program! *g*
What if I had forgotten the ()'s
What if you had forgotten them in C++?
func(1, add 2, 3, a, "-b"); instead of
func(1, add(2, 3), a, "-b");
If you are not using an infix operator in an expression then C++ always
needs the same amout of brackets.
And Common Lisps way to make +, -, *, etc NOT an operator but just
normal functions is *good*.
Why? Because you can just pass it as arguments to other functions!
Imagine you have a function foo which accepts three arguments:
one function and two arguments which will be passed to that function.
Something similar happens in quicksort() functions. You give them an
array of objects (of a class) to sort and a function which does decide
which object is "bigger" and which one is "smaller".
But back to the "+" example: if you want to call foo with an addition
function and two numbers in Lisp you could simply do that:
(foo '+ 10 15)
But imagine to do this in C++:
foo(+, 10, 15);
inside and just had "func 1 + 2 3 a..." ,'s just "seperate" the
parameters.
Spaces also separate them. Look at this:
inta;
int,a;
int a;
André