[plt-scheme] append!?

From: Majorinc, Kazimir (kazimir at chem.pmf.hr)
Date: Sun Oct 21 22:22:43 EDT 2007

Robert Nikander wrote:
>
> On Oct 21, 2007, at 6:45 PM, Majorinc, Kazimir wrote:
>>
>> type list is record
>>   next: (pointer to node) or NIL;
>> end
>> type node is record
>>  data: pointer to anything;
>>  next: (pointer to node) or NIL
>> end
>>
> It sounds like the problems you are talking about come from trying to 
> write imperative style in the functional language.
>
> The type above is a problem for recursive functions because "next" is 
> not a list, so you can't process the first item and recurse on the rest.
L.next is not a list, but I think one can easily define procedure like 
(rest L) that does equivalent to what it does now in Scheme and can 
serve as the base of recursion. This rest procedure would have to create 
new list record each time it is called, but I do not see anything 
particularly wrong in that. In the case I misunderstood you and you 
suggest this one:

type list is record
  next: (pointer to node) or NIL;
end
type node is record
 data: pointer to anything;
 rest: list;
end

right, its even more powerful. With such implementation (empty! (rest 
L)) would be equivalent to (set-rest! L ()). wow!











Posted on the users mailing list.