This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

partial paths

8 posts · 1921 views

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

I'm tired now, lol. May I also suggest the #lisp IRC channel? It is very useful for real-time responses\help.
Don't take the FUN out of DEFUN !

Re: partial paths

k thank u very much for u r help my friend

Re: partial paths

I'm not exactly sure what this code is supposed to be doing, could you elaborate on it a bit more?

Re: partial paths

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

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:
(defun hello ()
  (print "hello")
  )


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

Last edited by I X Code X 1 on , edited 1 time in total.

Re: partial paths

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.
Don't take the FUN out of DEFUN !

Re: partial paths

what would we replace set!