From: Chris Riesbeck on
Barry Margolin wrote:
> This is comp.lang.lisp. Comp.lang.scheme is over that way. -->
>

|
Odd -- it's | on my reader...
V

From: Thomas A. Russ on
sharkman <a.lasfar(a)aui.ma> writes:


> a)Write a function simplify which evaluates as much of an arithmetic
> expression as possible. For example,
> (simplify '(* 2 (+ (* a (+ 3 5)) (+ 1 4)))) should return
> (* 2 (+ (* a 5)))

Really?

Are you sure you didn't leave something out?

--
Thomas A. Russ, USC/Information Sciences Institute
From: Alan Malloy on
Thomas A. Russ wrote:
> sharkman <a.lasfar(a)aui.ma> writes:
>
>
>> a)Write a function simplify which evaluates as much of an arithmetic
>> expression as possible. For example,
>> (simplify '(* 2 (+ (* a (+ 3 5)) (+ 1 4)))) should return
>> (* 2 (+ (* a 5)))
>
> Really?
>
> Are you sure you didn't leave something out?
>

Left something out *and* made some bizarre errors on the way. Seems to
me that the best answer is (+ (* a 16) 10).

--
Cheers,
Alan (San Jose, California, USA)
From: Pascal J. Bourguignon on
pjb(a)informatimago.com (Pascal J. Bourguignon) writes:

> sharkman <a.lasfar(a)aui.ma> writes:
>
>> This problem involves arithmetic expressions, which may or may not be
>> numbered. You may need to use the following help functions in addition
>> to the buit-in functions including eval which evaluates an arithmetic
>> expression. For example, (eval '(+ 1 2)) returns 3.
>> Code:
>
>
>> (define (atom? x) (not (list? x)))
>> (define build-aexp
>> (lambda (op sub1 sub2)
>> (cons op (cons sub1 (cons sub2 '())))))
>>
>> (define numbered? (lambda (aexp)
>> (cond
>> ((atom? aexp) (number? aexp))
>> (else (and (numbered? (cadr aexp))
>> (numbered? (caddr aexp)))))))
>
> The indentation is wrong. Use emacs to have your code indented
> correctly automatically, and to send it to usenet!
>
>
>> (define (atom? x) (not (list? x)))
>>
>> (define build-aexp
>> (lambda (op sub1 sub2)
>> (cons op (cons sub1 (cons sub2 '())))))
>
> This can be written simply as:
>
> (define build-aexp list)
>
>
>> (define numbered? (lambda (aexp)
>> (cond
>> ((atom? aexp) (number? aexp))
>> (else (and (numbered? (cadr aexp))
>> (numbered? (caddr aexp)))))))
>
> This lacks abstraction. cadr and caddr don't mean anything for an aexp.
> You should write:
>
> (define operator car)
> (define left-argument cadr)
> (define right-argument caddr)
> ; (These functions could be generated automatically by a define-structure
> ; macro, but this is beyond the scope of this answer).
>
>
>
> (define numbered?
> (lambda (aexp)
> (cond
> ((atom? aexp) (number? aexp))
> (else (and (numbered? (left-argument aexp))
> (numbered? (right-argument aexp)))))))
>
>
>> a)Write a function simplify which evaluates as much of an arithmetic
>> expression as possible. For example,
>> (simplify '(* 2 (+ (* a (+ 3 5)) (+ 1 4)))) should return (* 2 (+ (* a
>> 5))
>
> Yes.
>
>> b)Write a function remove-noops which eliminates any additions of 0 or
>> multiplications by 1. For example, both
>> (remove-noops '(* 3 (* 1 (+ a 0)))) and (remove-noops (simplify '(* 3
>> (* 1 (+ a (- 1 1)))))) should return (* 3 a).
>
> Ok.
>
>
> So what's the difficulty?

I mean, what difficulty do _you_ encounter?

--
__Pascal Bourguignon__
http://www.informatimago.com