[plt-scheme] creating nested lists in DrScheme
I suggest you think about the *process* you need to implement BEFORE
deciding to use do or set! in your code.
The process you need to implement seems fairly easy. You need to
extract from the graph the neighbors of the first node in
the partial path and then create a list with all the new paths
produced by adding each neighbor to the partial path you are given.
I see no need for a do expression nor for set!
On Fri, May 7, 2010 at 10:42 PM, Aniket Karmarkar
<akarmarkar at mail.bradley.edu> wrote:
> This is what I am trying to do.
> Write the function partialpaths, of two arguments. The first argument is a
> list of lists, representing a graph(adjacency list representation of a
> graph). The second argument is a partial path in the reverse order, for
> example the path "from a to b to c" is represented by the list (c b a). The
> function should return a list of sublists containing all possible expansions
> of this partial path by one node. For example: (partialpaths '( (a b c) (b c
> d) (c d a) (d)) '(b a)) should return: ( (c b a) (d b a))
> I get the (b c d) part now I need to attach the cdr of this to b a multiple
> times so I try putting it in a loop.
> Here's what I have:
> (define nod ())
> (define ma '('()))
> (define (partialpaths L1 L2)
> (set! nod (equal L1 L2))
> (do()
> ;exit test
> ((null? (cdr nod)))
> (list ma (attach(cdr nod)L2))
> (set! nod (cdr nod))
> )
> ma
> )
> (define (attach List1 List2)
> (list (car List1) List2)
> )
> (define (equal L1 L2)
> (cond
> ((eq? (caar L1) (car L2)) (car L1))
> (else (equal (cdr L1) L2))
> )
> )
> On Fri, May 7, 2010 at 9:29 PM, Jon Rafkind <rafkind at cs.utah.edu> wrote:
>>
>> (list 1 (list 2))
>>
>> On 05/07/2010 08:29 PM, Aniket Karmarkar wrote:
>>
>> I am really stuck. I want to create a nested list.
>> Thanks,
>> Aniket
>>
>>
>>
>> _________________________________________________
>> For list-related administrative tasks:
>> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>>
>
>
> _________________________________________________
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
>
--
Cheers,
Marco