Need Help 
Author Message
 Need Help

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.*-*-*.com/
Before you buy.



Sat, 20 Jul 2002 03:00:00 GMT  
 Need Help

Quote:

>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?

--

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.



Sat, 20 Jul 2002 03:00:00 GMT  
 Need Help
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:



Quote:


> >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?

> --

> 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.


Sat, 20 Jul 2002 03:00:00 GMT  
 Need Help

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

Quote:

> 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) )



Sat, 20 Jul 2002 03:00:00 GMT  
 Need Help
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 ))))))



Quote:

> 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


> > 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.


Sun, 21 Jul 2002 03:00:00 GMT  
 Need Help

Quote:

> I still try

This is good!

Quote:
> but can't do

See, you already got closer yourselves.

Quote:
> (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:

Quote:
> (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 {*filter*} bugs.  Or
better yet, write down how _you_ would do it and write your program
based on that.

Robert



Sun, 21 Jul 2002 03:00:00 GMT  
 Need Help

Quote:

> (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.



Sun, 21 Jul 2002 03:00:00 GMT  
 Need Help


Quote:
> 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 ))))))


> > > 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..)



Sun, 21 Jul 2002 03:00:00 GMT  
 Need Help
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 ))))))



Quote:



> > 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 ))))))


> > > > 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.


Sun, 21 Jul 2002 03:00:00 GMT  
 Need Help
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


Quote:

> 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 ))))))





> > > 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 ))))))


> > > > > 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.


Mon, 22 Jul 2002 03:00:00 GMT  
 Need Help
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.



Mon, 22 Jul 2002 03:00:00 GMT  
 Need Help

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



Mon, 22 Jul 2002 03:00:00 GMT  
 
 [ 12 post ] 

 Relevant Pages 

1. Need help launching external non rexx command using VXREXX (VIO support needed) in OS/2

2. Java in VRML code...need help...or need a piano/keyborad.wrl

3. Need help to grok c extension that needs to use callbacks with data

4. HELP - I need help

5. HELP!! Need help with browse window

6. Help Files, Need Help

7. help i need help

8. HELP! NON-PROGRAMMER NEEDS HELP

9. HELP: Need help with Ms-Dos batch lang..

10. I need help........programming help!

11. Need Help How Can Help me

12. Need Help How can Help ?

 

 
Powered by phpBB® Forum Software