From: ···········@my-deja.com
Subject: Need Help
Date: 
Message-ID: <875a8q$f3o$1@nnrp1.deja.com>
Hello programmers:

I want to make a lisp program to take list (- 6 (/ 1 9) ) )
and make list (6 - (1 * 9) ). I new to lisp and this is what I make so
far. I will only work with binary operators.

(DEFUN MAKEIN( L )
  (COND(NULL L) NIL)
  (CONS(NTH 1 L)(CONS(NTH 0 L)(CONS(NTH 2 L) NIL))))

I do not know how to make recursive. Thanks for time.




Sent via Deja.com http://www.deja.com/
Before you buy.

From: Barry Margolin
Subject: Re: Need Help
Date: 
Message-ID: <XjDl4.12$xI3.233@burlma1-snr2>
In article <············@nnrp1.deja.com>,  <···········@my-deja.com> wrote:
>Hello programmers:
>
>I want to make a lisp program to take list (- 6 (/ 1 9) ) )
>and make list (6 - (1 * 9) ). I new to lisp and this is what I make so
>far. I will only work with binary operators.
>
>(DEFUN MAKEIN( L )
>  (COND(NULL L) NIL)
>  (CONS(NTH 1 L)(CONS(NTH 0 L)(CONS(NTH 2 L) NIL))))
>
>I do not know how to make recursive. Thanks for time.

Before we answer: is this your homework?

-- 
Barry Margolin, ······@bbnplanet.com
GTE Internetworking, Powered by BBN, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
From: ···········@my-deja.com
Subject: Re: Need Help
Date: 
Message-ID: <877pth$914$1@nnrp1.deja.com>
Hello:
  my homework is to go from infix to prefix. i want to go prefix to
infix to see how.

(- 6 (/ 1 9) ) ) to

(6 - (1 / 9) )


thanks for time:

In article <················@burlma1-snr2>,
  Barry Margolin <······@bbnplanet.com> wrote:
> In article <············@nnrp1.deja.com>,  <···········@my-deja.com>
wrote:
> >Hello programmers:
> >
> >I want to make a lisp program to take list (- 6 (/ 1 9) ) )
> >and make list (6 - (1 * 9) ). I new to lisp and this is what I make
so
> >far. I will only work with binary operators.
> >
> >(DEFUN MAKEIN( L )
> >  (COND(NULL L) NIL)
> >  (CONS(NTH 1 L)(CONS(NTH 0 L)(CONS(NTH 2 L) NIL))))
> >
> >I do not know how to make recursive. Thanks for time.
>
> Before we answer: is this your homework?
>
> --
> Barry Margolin, ······@bbnplanet.com
> GTE Internetworking, Powered by BBN, Burlington, MA
> *** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to
newsgroups.
> Please DON'T copy followups to me -- I'll assume it wasn't posted to
the group.
>


Sent via Deja.com http://www.deja.com/
Before you buy.
From: Robert Monfera
Subject: Re: Need Help
Date: 
Message-ID: <38977343.18B33BA9@fisec.com>
Because c.l.l. has a good heart, someone will eventually give you the
final solution so that you don't have to think and solve the homework
yourselves - this takes time though.

Why don't you just go to http://www.alu.com and find CGOL, which already
does what you want?

Robert

···········@my-deja.com wrote:
>
> Hello:
>   my homework is to go from infix to prefix. i want to go prefix to
> infix to see how.
>
> (- 6 (/ 1 9) ) ) to
>
> (6 - (1 / 9) )
From: ···········@my-deja.com
Subject: Re: Need Help
Date: 
Message-ID: <878d7t$mme$1@nnrp1.deja.com>
I still try but can't do

(defun makein( l )
  (cond
     (( null l) nil)
     (( listp (car l))
	(cond
 	  (( symbolp (car l)) (append (makein (car l))))

          (( atom (car l)) (cons(makein (car l)))
			   	( makein( cdr l)))))
        (t (cons (car l) ( makein( cdr l ))))))

In article <·················@fisec.com>,
  Robert Monfera <·······@fisec.com> wrote:
>
> Because c.l.l. has a good heart, someone will eventually give you the
> final solution so that you don't have to think and solve the homework
> yourselves - this takes time though.
>
> Why don't you just go to http://www.alu.com and find CGOL, which
already
> does what you want?
>
> Robert
>
> ···········@my-deja.com wrote:
> >
> > Hello:
> >   my homework is to go from infix to prefix. i want to go prefix to
> > infix to see how.
> >
> > (- 6 (/ 1 9) ) ) to
> >
> > (6 - (1 / 9) )
>


Sent via Deja.com http://www.deja.com/
Before you buy.
From: Robert Monfera
Subject: Re: Need Help
Date: 
Message-ID: <38983080.E5806ACC@fisec.com>
···········@my-deja.com wrote:
>
> I still try

This is good!

> but can't do

See, you already got closer yourselves.

> (defun makein( l )
>   (cond
>      (( null l) nil)
>      (( listp (car l))
>         (cond
>           (( symbolp (car l)) (append (makein (car l))))
>
>           (( atom (car l)) (cons(makein (car l)))
>                                 ( makein( cdr l)))))
>         (t (cons (car l) ( makein( cdr l ))))))

Start with a function that does what you want for the simplest case:

> (makein '(- 1 1))

(1 - 1)

Another useful thing is to write down what your program is doing,
strictly based on your program - you may find some nasty bugs.  Or
better yet, write down how _you_ would do it and write your program
based on that.

Robert
From: Stig Hemmer
Subject: Re: Need Help
Date: 
Message-ID: <ekvya93wsrx.fsf@iq.pvv.ntnu.no>
···········@my-deja.com writes:
> (defun makein( l )
>   (cond
>      (( null l) nil)
>      (( listp (car l))
> 	(cond
>  	  (( symbolp (car l)) (append (makein (car l))))
> 
>           (( atom (car l)) (cons(makein (car l)))
> 			   	( makein( cdr l)))))
>         (t (cons (car l) ( makein( cdr l ))))))

Is (listp (car l)) really what you mean?
At this point you don't really know that L _has_ a CAR, do you?

E.g., at one point you call (makein (car l)) after making sure that
(atom (car l)).  In the recursive call, L will be an atom and (car l)
will not work very well.

The inner COND doesn't have a final (t ...) clause.  This means that
if both tests fail, the inner COND will return NIL. This will also
then be returned from the outer COND. Is that what you want in this
case?

The (t ...) clause of the outher COND is indented as if it belongs to
the inner COND.  While the lisp system doesn't care about indentation,
human readers do.

Now, it seems to me that this function is needlessly complex.  It just
might be that this problem can be seen in a less complex way than you
see it. (read other articles in thread...)

Stig Hemmer,
Jack of a Few Trades.
From: Coby Beck
Subject: Re: Need Help
Date: 
Message-ID: <949515998699@NewsSIEVE.cs.bonn.edu>
<···········@my-deja.com> wrote in message
·················@nnrp1.deja.com...
> I still try but can't do
>
> (defun makein( l )
>   (cond
>      (( null l) nil)
>      (( listp (car l))
> (cond
>     (( symbolp (car l)) (append (makein (car l))))
>
>           (( atom (car l)) (cons(makein (car l)))
>    ( makein( cdr l)))))
>         (t (cons (car l) ( makein( cdr l ))))))
>
> > ···········@my-deja.com wrote:
> > >
> > > Hello:
> > >   my homework is to go from infix to prefix. i want to go prefix to
> > > infix to see how.
> > >
> > > (- 6 (/ 1 9) ) ) to
> > >
> > > (6 - (1 / 9) )
> >
>
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.

I believe you said that you will only work with binary operators?  If you
are allowed to assume the input list and its sublist parts are always three
elements and the first element is the operator then you only need two parts
in your cond form.  The first part is the "stopper", the second does the
stuff you want done and makes the recursive calls.

eg.  cond1 - this is an atom, so just return it
       cond2 - t so assemble your new list which will be element 2, element
1 and element 3 - element 2 and 3 must additionally be passed to your
function first.

Try it from there!  I have a solution i can post later if you're still
stuck....

Coby

(if those assumptions are not ok, it just takes a couple of additional lines
to trap an error..)
From: ···········@my-deja.com
Subject: Re: Need Help
Date: 
Message-ID: <87adl2$7fl$1@nnrp1.deja.com>
Hello:
This is what i make. less hard now, but still does not work.

(defun makein( l )
  (cond
     (( null l) nil)
	((symbolp (car l)) (cons (car l) nil) (makein (cdr l)) )
        (t (cons (car l) ( makein( cdr l ))))))



In article <············@NewsSIEVE.cs.bonn.edu>,
  "Coby Beck" <·····@mercury.bc.ca> wrote:
>
> <···········@my-deja.com> wrote in message
> ·················@nnrp1.deja.com...
> > I still try but can't do
> >
> > (defun makein( l )
> >   (cond
> >      (( null l) nil)
> >      (( listp (car l))
> > (cond
> >     (( symbolp (car l)) (append (makein (car l))))
> >
> >           (( atom (car l)) (cons(makein (car l)))
> >    ( makein( cdr l)))))
> >         (t (cons (car l) ( makein( cdr l ))))))
> >
> > > ···········@my-deja.com wrote:
> > > >
> > > > Hello:
> > > >   my homework is to go from infix to prefix. i want to go
prefix to
> > > > infix to see how.
> > > >
> > > > (- 6 (/ 1 9) ) ) to
> > > >
> > > > (6 - (1 / 9) )
> > >
> >
> >
> > Sent via Deja.com http://www.deja.com/
> > Before you buy.
>
> I believe you said that you will only work with binary operators?  If
you
> are allowed to assume the input list and its sublist parts are always
three
> elements and the first element is the operator then you only need two
parts
> in your cond form.  The first part is the "stopper", the second does
the
> stuff you want done and makes the recursive calls.
>
> eg.  cond1 - this is an atom, so just return it
>        cond2 - t so assemble your new list which will be element 2,
element
> 1 and element 3 - element 2 and 3 must additionally be passed to your
> function first.
>
> Try it from there!  I have a solution i can post later if you're still
> stuck....
>
> Coby
>
> (if those assumptions are not ok, it just takes a couple of
additional lines
> to trap an error..)
>
>


Sent via Deja.com http://www.deja.com/
Before you buy.
From: ···········@my-deja.com
Subject: Re: Need Help
Date: 
Message-ID: <87agmo$9lr$1@nnrp1.deja.com>
i trying to do what you say

(defun makein( l )
  (cond
     ((null l) nil)    ; no list stop
     ((atom l) l)      ; atom return
     (t (cons (cadr l) (makein (cdr l)))  ))) ;make 2 1 3


In article <············@nnrp1.deja.com>,
  ···········@my-deja.com wrote:
> Hello:
> This is what i make. less hard now, but still does not work.
>
> (defun makein( l )
>   (cond
>      (( null l) nil)
> 	((symbolp (car l)) (cons (car l) nil) (makein (cdr l)) )
>         (t (cons (car l) ( makein( cdr l ))))))
>
> In article <············@NewsSIEVE.cs.bonn.edu>,
>   "Coby Beck" <·····@mercury.bc.ca> wrote:
> >
> > <···········@my-deja.com> wrote in message
> > ·················@nnrp1.deja.com...
> > > I still try but can't do
> > >
> > > (defun makein( l )
> > >   (cond
> > >      (( null l) nil)
> > >      (( listp (car l))
> > > (cond
> > >     (( symbolp (car l)) (append (makein (car l))))
> > >
> > >           (( atom (car l)) (cons(makein (car l)))
> > >    ( makein( cdr l)))))
> > >         (t (cons (car l) ( makein( cdr l ))))))
> > >
> > > > ···········@my-deja.com wrote:
> > > > >
> > > > > Hello:
> > > > >   my homework is to go from infix to prefix. i want to go
> prefix to
> > > > > infix to see how.
> > > > >
> > > > > (- 6 (/ 1 9) ) ) to
> > > > >
> > > > > (6 - (1 / 9) )
> > > >
> > >
> > >
> > > Sent via Deja.com http://www.deja.com/
> > > Before you buy.
> >
> > I believe you said that you will only work with binary operators?
If
> you
> > are allowed to assume the input list and its sublist parts are
always
> three
> > elements and the first element is the operator then you only need
two
> parts
> > in your cond form.  The first part is the "stopper", the second does
> the
> > stuff you want done and makes the recursive calls.
> >
> > eg.  cond1 - this is an atom, so just return it
> >        cond2 - t so assemble your new list which will be element 2,
> element
> > 1 and element 3 - element 2 and 3 must additionally be passed to
your
> > function first.
> >
> > Try it from there!  I have a solution i can post later if you're
still
> > stuck....
> >
> > Coby
> >
> > (if those assumptions are not ok, it just takes a couple of
> additional lines
> > to trap an error..)
> >
> >
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>


Sent via Deja.com http://www.deja.com/
Before you buy.
From: ···········@my-deja.com
Subject: Re: Need Help
Date: 
Message-ID: <87aia3$atf$1@nnrp1.deja.com>
i did make simplest case

( makein '( + 9 8))

(defun makein( l )
  (cond
     ((null l) nil)
     ((atom l) l)
     (t (cons (cadr l)(cons (car l) (cons(caddr l) nil)) ))))


Sent via Deja.com http://www.deja.com/
Before you buy.
From: Marco Antoniotti
Subject: Re: Need Help
Date: 
Message-ID: <lwg0vav8gh.fsf@parades.rm.cnr.it>
Your function has many formatting problems.  Using Emacs would help
immensely and you would see that

(defun makein (l)
  (cond ((null l) nil)

	((listp (car l))
	 (cond ((symbolp (car l))
		(append (makein (car l))))    ; <==== Append needs two args.

	       ((atom (car l))
		(cons (makein (car l)))       ; <==== Problem!!!!!
		(makein(cdr l)))))

        (t (cons (car l) (makein (cdr l))))))



-- 
Marco Antoniotti ===========================================
PARADES, Via San Pantaleo 66, I-00186 Rome, ITALY
tel. +39 - 06 68 10 03 17, fax. +39 - 06 68 80 79 26
http://www.parades.rm.cnr.it/~marcoxa