Re: Questions on Using Python to Teach Data Structures and Algorithms



Bruno Desthuilliers wrote:
Brendon Towle wrote:
Some of your Lisp translations are subtly off...

Seems correct to me. Lisp lists are linked lists, not arrays.

Actually, Brendon was correct. In lisp / scheme:

(cons 1 '(2 3)) -> (1 2 3)
(car '(1 2 3)) -> 1
(cdr '(1 2 3)) -> (2 3)

But Brendon's code also needs a correction: [a].extend(b) is wrong,
because extend is in-place and returns None, and [a] is anonymous...it
needs to be something like:

def cons(a, b):
b.insert(0, a)
return b

Regards,
Jordan

.



Relevant Pages

  • Some Greenspuning
    ... I'm writing a C program that uses lisp lists as it's data file format. ... I've written it to use exactly the same read syntax as scheme, ...
    (comp.lang.scheme)
  • Re: [SOLUTION] Lisp Game (#49)
    ... >> I set up a LISPy environment and copied the LISP code as closely as ... >> possible, using Ruby procs, arrays and strings. ... > def inspect # (JUST FOR FUN, MAKE ARRAYS LOOK LIKE LISP LISTS) ...
    (comp.lang.ruby)
  • Re: [SOLUTION] Lisp Game (#49)
    ... possible, using Ruby procs, arrays and strings. ... def inspect # (JUST FOR FUN, MAKE ARRAYS LOOK LIKE LISP LISTS) ...
    (comp.lang.ruby)