(define what 44)
(define (add a b ) ( + b a))
(define my-procedure (lambda (x y) (add x what)))
(my-procedure 2 (+ 3 4))
Using the substitution model and starting at the last line, show the
sequence of evaluations performed using applicative-order evaluation
and then normal-order evaluation.
(sum-square-duplicates 1 2 4 ) => 0
(sum-square-duplicates 1 1 4 ) => 2
(sum-square-duplicates 1 1 1 ) => 3
(sum-square-duplicates 1 3 3 ) => 18
(sum-square-duplicates 5 2 2 ) => 8
DO NOT use built-in ref functions like list-ref or string-ref.
(((double (double double)) increment) 4)
(define zero (lambda (f) (lambda(x) x)))
(define (add-1 n)
(lambda (f) (lambda(x) (f ((n f ) x )))))
This representation is know as Church numerals after its inventor Alonzo Church the logician who invented Lamda Calculus.
Define one and two directly (not in terms of zero and add-1) (Hint: Use substitution to evaluate (add-1 zero)
(define (special-cons x y)
(lambda (m)
(m x y)))
What are the corresponding definitions of car and cdr? Use news names for the procedures so as to not conflict with the existing ones. For this representation, verify that (special-car (special-cons x y) yields x for any objects x and y and (special-cdr (special-cons x y)) yields y.
(my-equal? '(a (b c (d e ) f)) '(a (b c (d e ) f)))
=> #t
(my-equal? '(a (( b d ) c) e) '( a (b d) c e)) =>
#f
(my-equal? '( a (( b d ) c ) e ) '( a (( d b ) c)
e)) => #f
Do not use Scheme's built-in procedure equal? in your procedure.
(define (f x y . z) ?body> )
the procedure f can be called with two or more arguments. If we evaluate
(f 1 2 3 4 5 6)
then in the body of f, x will be 1, y will be 2, and z will be the list (3 4 5 6).
Given the definition:
(define (g . w) ?body>)
the procedure g can be called with 1 or more arguments. If we evaluate
(g 1 2 3 4 5 6)
then in the body of g, w will be the list ( 1 2 3 4 5 6).
Use this notation to write a procedure unique-count
that takes one or more integers and returns a list unqiue (no duplicates)
integer in the list. For
example:
(unique-count 1 2 3 1 2 1) => ( 3 )
(unique-count 1 1 1 1 2 2 4 2
3 3 3 1 2 3 6 ) => ( 4 6)
Be sure to test your procedures thoroughly and make sure to pick meaningful test cases. It is up to you to make up a convincing test plan (i.e. convince the TAs that your procedures work properly). Make sure you test all your procedures.
Submission:
Submit a printout of all of your procedures and along with a copy of the output generated from the testing. Be sure to include comments where appropriate in your code and make sure that all output is clearly explained. Testing will be marked! It is always a good idea to highlight the beginning of the procedure on the printout. Place your name, student #, course#, and assignment # on the top of each page. Put all printouts in one unsealed envelope, with this same information clearly marked on the envelope. You should also include a diskette containing the procedures and test output files you generated for the assignment. All of these files should be stored in the directory A:\ASS1 (actually B:\ASS1 when in the labs here). Finally, hand in your assignment in class. Don't forget that the assignment will be marked for style, testing and your solutions.