Re: C++ sucks for games

From: Frank Buss (fb_at_frank-buss.de)
Date: 10/28/04


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


Relevant Pages

  • Re: CollabRx seeks brilliant engineers for an excellent e-science adventure
    ... belief that lisp programmers are smarter/better. ... Java or PHP programmers. ... a type of language that attracts a personality that meets my perceptions ...
    (comp.lang.lisp)
  • Re: why not enough lisp libraries?
    ... by the elegance of the language, ... Lisp programmers because Lisp is not the most popular thing. ... Since this discussion was obstensibly about libraries, ...
    (comp.lang.lisp)
  • Re: I finally understand why Im not allowed to use Lisp
    ... language is powerful syntax and abstractions. ... I heard it when I used Lisp for ANYTHING. ... author of that bit of code was one of their /best/ programmers and I would do ... Management assumes that any software will have high maintenance costs. ...
    (comp.lang.lisp)
  • Re: CollabRx seeks brilliant engineers for an excellent e-science adventure
    ... belief that lisp programmers are smarter/better. ... but I suspect they would have been good using any language. ... under criticism lisp community have formed a defensive ...
    (comp.lang.lisp)
  • Re: (Prolog + LISP + Erlang) with integration issues versus C++
    ... advantage by always using appropriate tools, instead of C++/Java all the time, then you'd better deal with hiring some more language-open programmers. ... Ask Lisp compilers how "supercede" is spelt. ... That means writing everything in one language at all practical. ... My ideal for the future is to develop a filesystem remote interface and then have it implemented across the Internet as the standard rather than HTML. ...
    (comp.lang.lisp)