Page 1 of 1

partial paths

Posted: Fri Jul 01, 2011 2:01 pm
by murali
CAN ANY ONE HELP
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))

Re: partial paths

Posted: Fri Jul 01, 2011 2:06 pm
by Indecipherable
I'm tired now, lol. May I also suggest the #lisp IRC channel? It is very useful for real-time responses\help.

Re: partial paths

Posted: Fri Jul 01, 2011 2:08 pm
by murali
k thank u very much for u r help my friend

Re: partial paths

Posted: Fri Jul 01, 2011 2:55 pm
by I X Code X 1
I'm not exactly sure what this code is supposed to be doing, could you elaborate on it a bit more?

Re: partial paths

Posted: Fri Jul 01, 2011 4:02 pm
by murali
i got some code like this

(define (partialpaths X Y)

(cond

((null? X) Y)

((member1 (car(car X)) Y) (partialpaths (cdr X) Y))

(#t (cons (car(car X)) Y))

)

)

(define (member1 X Y)

(cond

((null? X) #f)

((eq? Z (car X)) #t)

(#t (member1 Z (cdr X)))

)

)
but i am not sure this code by using lisp.

Re: partial paths

Posted: Fri Jul 01, 2011 5:54 pm
by I X Code X 1
You want that code converted into Common Lisp code? To me it looks like it is currently in Racket, or a language much like that. Might I suggest a bit of formatting when you write lisp code. Do not have parenthesis alone on a line.

Don't do this:

Code: Select all

(defun hello ()
  (print "hello")
  )


Do this:

Code: Select all

(defun hello ()
  (print "hello"))
Makes it easier on the eyes.

Re: partial paths

Posted: Sat Jul 02, 2011 6:54 am
by Indecipherable
define would be defun, the parameters are in their own brackets after the name, then the body, then the final end-function brackets.
null? would be null, #t => t, eq? => eq or eql or equal, and I think #f means false(?) which would be nil in CL.

Re: partial paths

Posted: Sat Jul 02, 2011 7:27 pm
by murali
what would we replace set!