From: holly-cam.com
Subject: Re: simpler question  :-)   help!?
Date: 
Message-ID: <20010521131252.03938.00000475@ng-cl1.aol.com>
I tried running it... 
It appears it spit out the same binary number... (I put it below)

I'm so new at this I didn't really know the cdr and car stuff yet... 
I was trying to do it with using 
last * 1 + butlast *2 + butlast (butlast) *2*2 ya know?

But I cant figure out how to do it

But if yours worked I can use it because I need to learn how to do two's
compliment addition and subraction and division and a few other things... 

Anyway this is my interaction from my LISP prompts 

>(defun bin-to-dec (b &optional (n 0))
  (if b
    (bin-to-dec (cdr b) (+ (* 2 n) (car b)))
    n))

BIN-TO-DEC

>(BIN-TO-DEC '(011010))

11010 

From: holly-cam.com
Subject: Re: simpler question  :-)   help!?
Date: 
Message-ID: <20010521135053.03961.00000454@ng-cl1.aol.com>
I just can't seem to get this... does this make sense?

(defun s-todec (binnum)
 (let (num 0)
      (p 2)
      (L (length '(binnum))))

  (if (null '(binnum))
    num
    (setf num (* 1 (first (reverse '(binnum))))
    (setf L (- L 1))
     (when (> 0 L))
      (setf num (* p (first (rest (reverse '(binnum))))))
       (setf p (*p 2))  
       (setf L (- L 1)) )  )   )
                    ***********************************
                           www.holly-cam.com
From: Barry Margolin
Subject: Re: simpler question  :-)   help!?
Date: 
Message-ID: <bNdO6.9$oZ4.1049@burlma1-snr2>
In article <·····························@ng-cl1.aol.com>,
holly-cam.com <········@aol.comnospam> wrote:
>I just can't seem to get this... does this make sense?

It appears that you have some big confusion regarding quoting, as you have
"'(binnum)" in several places where you presumably just mean "binnum".

There's another big in your IF.  In Common Lisp, an IF can have at most 3
sub-forms: the condition, a then-clause, and an optional else-clause.  But
your IF has several expressions after the else-clause.  Presumably they
were intended to be part of the else-clause as well, but you need to put
them in a PROGN.

Your WHEN expression also looks wrong, since you didn't put any expressions
after the condition.

(*p 2) should be (* p 2)

You don't have any looping or recursion in your function.  All it does is
look at the first two elements of binnum and then return.

>
>(defun s-todec (binnum)
> (let (num 0)
>      (p 2)
>      (L (length '(binnum))))
>
>  (if (null '(binnum))
>    num
>    (setf num (* 1 (first (reverse '(binnum))))
>    (setf L (- L 1))
>     (when (> 0 L))
>      (setf num (* p (first (rest (reverse '(binnum))))))
>       (setf p (*p 2))  
>       (setf L (- L 1)) )  )   )
>                    ***********************************
>                           www.holly-cam.com


-- 
Barry Margolin, ······@genuity.net
Genuity, 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: holly-cam.com
Subject: Re: simpler question  :-)   help!?
Date: 
Message-ID: <20010521152154.03946.00000424@ng-cl1.aol.com>
ok how about this one?
I changed some things assuming that each recursive call will go deeper in
through the (butlast list) so that the next time it'll be (butlast (butlast
list))

Let me know if it looks like I'm getting any kind of a good start?  :-)

Thank you for helping me... I need help so bad!

(setf (num 0)
      (ex 0))

(defun s-todec (binnum)

  (if (null '(binnum))
    nil
      (setf num (+ num (* (last '(binnum)) (expt 2 ex))));;num=num+last
digit*2^ex
      (setf ex (+ ex 1)) ;;exponent++
      (s-todec (butlast '(binnum)))))
                    ***********************************
                           www.holly-cam.com
From: Barry Margolin
Subject: Re: simpler question  :-)   help!?
Date: 
Message-ID: <nceO6.10$oZ4.953@burlma1-snr2>
In article <·····························@ng-cl1.aol.com>,
holly-cam.com <········@aol.comnospam> wrote:
>ok how about this one?
>I changed some things assuming that each recursive call will go deeper in
>through the (butlast list) so that the next time it'll be (butlast (butlast
>list))
>
>Let me know if it looks like I'm getting any kind of a good start?  :-)
>
>Thank you for helping me... I need help so bad!

You still have '(binnum) all over the place.  Why?  You want to evaluate
the binnum variable, so why are you putting it in a list and quoting it?
That just evaluates to the list containing the symbol, not the value of the
variable.

>(setf (num 0)
>      (ex 0))
>
>(defun s-todec (binnum)
>
>  (if (null '(binnum))
>    nil
>      (setf num (+ num (* (last '(binnum)) (expt 2 ex))));;num=num+last
>digit*2^ex

You shouldn't use global variables like this.  You should pass num and ex
as parameters if they're needed in the recursive calls.

>      (setf ex (+ ex 1)) ;;exponent++
>      (s-todec (butlast '(binnum)))))
>                    ***********************************
>                           www.holly-cam.com


-- 
Barry Margolin, ······@genuity.net
Genuity, 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: holly-cam.com
Subject: Re: simpler question  :-)   help!?
Date: 
Message-ID: <20010521162813.03910.00000603@ng-cl1.aol.com>
I'm sorry... I've just never used lisp before and I didn't know how else to do
it?

My book has it this way too so I must be missing something...

Well the book examples are lists of letters just for sake of simple examples to
show us the uses of first, rest and stuff

binnum is my list of 1's and 0's


                    ***********************************
                           www.holly-cam.com
From: Barry Margolin
Subject: Re: simpler question  :-)   help!?
Date: 
Message-ID: <H1fO6.15$oZ4.1293@burlma1-snr2>
In article <·····························@ng-cl1.aol.com>,
holly-cam.com <········@aol.comnospam> wrote:
>I'm sorry... I've just never used lisp before and I didn't know how else to do
>it?

You're talking about '(binnum)?

>My book has it this way too so I must be missing something...

>Well the book examples are lists of letters just for sake of simple examples to
>show us the uses of first, rest and stuff

Yes, you're missing the fact that those examples were using constant lists
just to show what first and rest do.  Somewhere else in your book it must
talk about using variables to hold data.  When you're using a variable, you
don't quote it.

(setf binnum '(1 2 3))
(first '(binnum)) => BINNUM
(first binnum) => 1

(setf binnum '())
(null '(binnum)) => NIL
(null binnum) => T

See the differences?

-- 
Barry Margolin, ······@genuity.net
Genuity, 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: holly-cam.com
Subject: Re: simpler question  :-)   help!?
Date: 
Message-ID: <20010521170241.03931.00000528@ng-cl1.aol.com>
Yeah I do see now... 

I tried it the other way and I still get the error

>(setf num 0)
(setf ex 0)



(defun s-todec (binnum)

  (if (null binnum)
    nil
      (setf num (+ num (* (last binnum) (expt 2 ex)))) ;;num=num+last
digit*2^ex
      (setf ex (+ ex 1)) ;;exponent++
      (s-todec (butlast binnum))))
0

>
0

>

S-TODEC

>(s-todec '(1 0 1 1))

Error: Too many arguments.
Fast links are on: do (si::use-fast-links nil) for debugging
Error signalled by IF.
Broken at IF.  Type :H for Help.  
                    ***********************************
                           www.holly-cam.com
From: Kent M Pitman
Subject: Re: simpler question  :-)   help!?
Date: 
Message-ID: <sfwr8xi8oqe.fsf@world.std.com>
········@aol.comnospam (holly-cam.com) writes:

> ok how about this one?
> I changed some things assuming that each recursive call will go deeper in
> through the (butlast list) so that the next time it'll be (butlast (butlast
> list))
> 
> Let me know if it looks like I'm getting any kind of a good start?  :-)
> 
> Thank you for helping me... I need help so bad!
> 
> (setf (num 0)
>       (ex 0))
> 
> (defun s-todec (binnum)
> 
>   (if (null '(binnum))

This condition will always yield true.

What is this '(binnum) stuff?  That's a list containing a symbol.  Lists
containing anything are not null.

The quote says to stop evaluation.  If you want the value of the variable
binnum, you don't want quote.  The parens mean something always; never insert
parens where you don't know what they are doing.  If you remove the quotes,
and write just (binnum), you are asking to call a function binnum with no
arguments, not to read the variable binnum.

As nearly as I can tell, you are consistently writing '(binnum) where you
want just binnum. e.g.,
 (null binnum)
and
 (last binnum)
Incidentally, (last binnum) will yield the last cons on the backbone of
a list, not the last element in the list. You probably want 
(car (last binnum)) to get the last element. e.g.,
 
 (last '(a b c d)) => (D)
 (car (last '(a b c d))) => D

>     nil
>       (setf num (+ num (* (last '(binnum)) (expt 2 ex))));;num=num+last
> digit*2^ex
>       (setf ex (+ ex 1)) ;;exponent++
>       (s-todec (butlast '(binnum)))))
>                     ***********************************
>                            www.holly-cam.com
From: holly-cam.com
Subject: Re: simpler question  :-)   help!?
Date: 
Message-ID: <20010521164125.03910.00000605@ng-cl1.aol.com>
 (last '(a b c d)) => (D)
 (car (last '(a b c d))) => D

Oh... you mean last just gives me a list of D and car last will give me D

We are actually told we can do all of this without car and cdr but I don't know
enough about it to figure out the technicalities... 

I'll keep trying

All I know is that I keep getting the error of "too many arguments" when I use
the function with a list like 1 0 1 1
or whatever... 

Does it know that I'm telling it binnum is a list and not just an expression or
even an integer?
                    ***********************************
                           www.holly-cam.com
From: Barry Margolin
Subject: Re: simpler question  :-)   help!?
Date: 
Message-ID: <I9fO6.17$oZ4.1272@burlma1-snr2>
In article <·····························@ng-cl1.aol.com>,
holly-cam.com <········@aol.comnospam> wrote:
> (last '(a b c d)) => (D)
> (car (last '(a b c d))) => D
>
>Oh... you mean last just gives me a list of D and car last will give me D

Right.  LAST returns the last cons, not the last element.

>We are actually told we can do all of this without car and cdr but I don't know
>enough about it to figure out the technicalities... 

You know that car and cdr are the same as first and rest, don't you?

>I'll keep trying
>
>All I know is that I keep getting the error of "too many arguments" when I use
>the function with a list like 1 0 1 1
>or whatever... 

The "too many arguments" error is coming from your misuse of IF.  I told
you that several messages ago.

-- 
Barry Margolin, ······@genuity.net
Genuity, 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: holly-cam.com
Subject: Re: simpler question  :-)   help!?
Date: 
Message-ID: <20010521170655.03931.00000530@ng-cl1.aol.com>
Ok... I tried your progn one... 
I think I am reposting this so if I am I apologize!

>(setf num 0)
(setf ex 0)



(defun s-todec (binnum)

  (if (null binnum)
    nil
      (progn (setf num (+ num (* (last binnum) (expt 2 ex)))) ;;num=num+last
dig
it*2^ex
      (setf ex (+ ex 1)) ;;exponent++
      (s-todec (butlast binnum)))))
0

>
0

>

S-TODEC

>(s-todec '(1 0 1 1))

Error: (1) is not of type NUMBER.
Fast links are on: do (si::use-fast-links nil) for debugging
Error signalled by *.
Broken at *.  Type :H for Help.  
                    ***********************************
                           www.holly-cam.com