partial paths

Discussion of Common Lisp

partial paths

Postby murali » Fri Jul 01, 2011 2:01 pm

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))
murali
 
Posts: 15
Joined: Fri Jul 01, 2011 10:11 am

Re: partial paths

Postby Indecipherable » Fri Jul 01, 2011 2:06 pm

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 !
User avatar
Indecipherable
 
Posts: 47
Joined: Fri Jun 03, 2011 5:30 am
Location: Behind you.

Re: partial paths

Postby murali » Fri Jul 01, 2011 2:08 pm

k thank u very much for u r help my friend
murali
 
Posts: 15
Joined: Fri Jul 01, 2011 10:11 am

Re: partial paths

Postby I X Code X 1 » Fri Jul 01, 2011 2:55 pm

I'm not exactly sure what this code is supposed to be doing, could you elaborate on it a bit more?
User avatar
I X Code X 1
 
Posts: 59
Joined: Sun May 29, 2011 8:52 pm
Location: NY

Re: partial paths

Postby murali » Fri Jul 01, 2011 4:02 pm

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.
murali
 
Posts: 15
Joined: Fri Jul 01, 2011 10:11 am

Re: partial paths

Postby I X Code X 1 » Fri Jul 01, 2011 5:54 pm

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.
Last edited by I X Code X 1 on Sat Jul 02, 2011 9:16 pm, edited 1 time in total.
User avatar
I X Code X 1
 
Posts: 59
Joined: Sun May 29, 2011 8:52 pm
Location: NY

Re: partial paths

Postby Indecipherable » Sat Jul 02, 2011 6:54 am

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 !
User avatar
Indecipherable
 
Posts: 47
Joined: Fri Jun 03, 2011 5:30 am
Location: Behind you.

Re: partial paths

Postby murali » Sat Jul 02, 2011 7:27 pm

what would we replace set!
murali
 
Posts: 15
Joined: Fri Jul 01, 2011 10:11 am


Return to Common Lisp

Who is online

Users browsing this forum: Google [Bot] and 1 guest

cron