f python?
Rainer Weikusat
rweikusat at mssgmbh.com
Mon Apr 9 16:44:14 EDT 2012
Rainer Weikusat <rweikusat at mssgmbh.com> writes:
> Shmuel (Seymour J.) Metz <spamtrap at library.lspace.org.invalid> writes:
>
> [...]
>
>>>For one thing, if s is a non-empty null terminated string then,
>>>cdr(s) is also a string representing the rest of that string
>>>without the first character,
>>
>> Are you really too clueless to differentiate between C and LISP?
>
> In LISP, a list is a set of conses (pairs) whose car (first element of
> the pair) contains a value and whose cdr (second element of the pair)
> links to the next cons that's part of the list. The end of a list is
> marked by a cdr whose value is nil.
Addition: This can also be implemented very neatly in Perl by using
two element array references as 'cons cells', toy example
-----------
sub car
{
return $_[0][0];
}
sub cdr
{
return $_[0][1];
}
sub list
{
@_ && [shift, &list];
}
$l = list(0 .. 100);
while ($l) {
print(car($l), ' ');
$l = cdr($l);
}
print("\n");
-----------
and for algorithms which are well-suited for linked lists, this can
even outperform (when suitably implemented) an equivalent algorithm
using arrays.
More information about the Python-list
mailing list