Re: C++ sucks for games
From: Frank Buss (fb_at_frank-buss.de)
Date: 10/28/04
- Next message: Svein Ove Aas: "Re: Challenge for lisp lovers...."
- Previous message: Maahes: "Re: Garbage Collection for games is moot"
- In reply to: Maahes: "Re: C++ sucks for games"
- Next in thread: Maahes: "Re: C++ sucks for games"
- Reply: Maahes: "Re: C++ sucks for games"
- Reply: Kalle Olavi Niemitalo: "Re: C++ sucks for games"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 28 Oct 2004 13:58:42 +0000 (UTC)
I don't think that one language is better than the other, it depends on
many factors, like available programmers and good compilers for the
platform you want to write for, but perhaps someone is interested in Lisp,
so I'll try to correct bad Lisp examples.
"Maahes" <maahes@internode.on.net> wrote:
> For instance (an example someone posted).
>
> C:
> for (int i=0; i<=10; i++) list.push(i);
> list.reverse();
>
>
> List:
you mean "Lisp".
>
> (let ((lst 0))
this must be (lst nil)
> (dotimes (i 11)
> (push i lst))
> (reverse lst))
> In the C version, I am typing straight out of my head in left -> right
> fashion and appending new work as I go along. In the Lisp one, it
> seems you have to group the (push i lst), the (i 11), as they are the
> bottom level actions. Then wrap that in a (dotimes a b) framework,
> then wrap that in a let (a b) framework.
your Lisp example is not the same as the C example, because in your C code
you didn't wrote the initialization of the "list" variable. In Lisp the
"let" is used for local variable bindings, which are visible in the block
after the variable declarations (and in closures). If you want a global
list variable, you can write it like this (*name* is the convention in Lisp
for global variables, but you don't need to write it like this):
(defparameter *list* nil)
(loop for i from 0 to 10 do (push i *list*))
(setf *list* (nreverse *list*))
But of course, no Lisp programmer would write it this way. If you want a
list, which contains all elements from n to 0, you can write it like this:
(defun make-down-list (n)
(when (>= n 0)
(cons n (make-down-list (1- n)))))
most Lisp implementations optimizes the tail-recursion to a jump, so
chances are good, that it is as fast as a normal loop.
If you don't like recursions, there are many other ways to create a list
from 10 to 0. I think the simplest one is this:
(loop for i from 10 downto 0 collect i)
> I'm not even sure why there
> are 2 brackets around the lst 0. This seems to make a mockery of Lisp
> having consistent syntax.
you have 2 brackets, because you can initialize more than one variable:
(let ((x 1)
(y 2))
(+ x y))
-- Frank Buß, fb@frank-buss.de http://www.frank-buss.de, http://www.it4-systems.de
- Next message: Svein Ove Aas: "Re: Challenge for lisp lovers...."
- Previous message: Maahes: "Re: Garbage Collection for games is moot"
- In reply to: Maahes: "Re: C++ sucks for games"
- Next in thread: Maahes: "Re: C++ sucks for games"
- Reply: Maahes: "Re: C++ sucks for games"
- Reply: Kalle Olavi Niemitalo: "Re: C++ sucks for games"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|