Jump to content

Recommended Posts

Posted

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.

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

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

 

 

 

 

Thank you for your help

Posted

Ah, Scheme. Very fun. Are you taking SICP?

Posted

Yes scheme issue, I don't know what does SICP stand for, but it's for compiler's course, can you help me with this problem ??

Posted

SCIP = Structure and Interpretation of Computer programs.

( http://mitpress.mit.edu/sicp/full-text/book/book.html )

 

Compiler course? School or something like the Digital Mars Compiler weekend seminar thing? I'm not a CS. I'm self taught. Ive taken the SCIP course when MIT put it up on the Free courseware section and read a lot of books on programing but...

 

Its been a long time since ive done scheme and or taken that course. I know we touched on that in one of the chapters...but the only help i would be able to offer you help now a days would be general and or broad in nature (academic if you would) on this kinda problem. Well, do you need actual code or just theory?

 

BTW, you found a site which has users that use AutoLisp. AL is Scheme like but not really. AL is based upon a language called XLisp which was like a striped down version of Common lisp.

 

This would be a translation from Scheme to Autolisp so you can see the different syntax's.

Scheme:

(define (atom? x) 
 (not (list? x)) )

 

AutoLisp:

(defun atom? ( x / )
 (not (eq (type x) 'LIST)) )

 

Of course this is a direct translation and there are other ways of doing this same task in AutoLisp but you get the idea.

 

I would recommend that you find a newsgroup for Scheme instead of here because I think I may be the only one who has taken a Scheme class.

 

I gotta run now so good luck and i hope to talk to you later.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...