Find Jobs
Hire Freelancers

Scheme Small task

$30-250 USD

Imefungwa
Imechapishwa about 3 years ago

$30-250 USD

Kulipwa wakati wa kufikishwa
;; ===== Procedural Abstraction ===== ;; Using the instructions provided on LEARN, give a defintion for fold-tree (define fold-tree '() ) ;; Using the instructions provided on LEARN, give a defintion for depth (define depth '() ) ;; Using the instructions provided on LEARN, give a defintion for count (define count '() ) Procedural Abstraction Consider the following five functions: (define add (lambda (sexpr) (cond ((null? sexpr) 0) ((pair? sexpr) (+ (add (car sexpr)) (add (cdr sexpr)))) (else sexpr)))) (define copy (lambda (sexpr) (cond ((null? sexpr) ’()) ((pair? sexpr) (cons (copy (car sexpr)) (copy (cdr sexpr)))) (else sexpr)))) (define size (lambda (sexpr) (cond ((null? sexpr) 0) ((pair? sexpr) (+ (size (car sexpr)) (size (cdr sexpr)))) (else 1)))) (define depth (lambda (sexpr) (cond ((null? sexpr) 0) ((pair? sexpr) (add1 (max (depth (car sexpr)) (depth (cdr sexpr))))) (else 0)))) (define count (lambda (pred sexpr) (cond ((null? sexpr) 0) ((pair? sexpr) (+ (count pred (car sexpr)) (count pred (cdr sexpr)))) ((pred sexpr) 1) (else 0)))) These functions can be used as follows: > (add '((1 . 2) . (3 . 4))) 10 > (copy '(a b c d)) (a b c d) > (size '(a b c d)) 4 > (depth '((1 . 2) . (3 . 4))) 2 > (count even? '((1 . 2) . (3 . 4))) 2 Demonstrate your mastery of procedural abstraction by defining a function fold-tree which abstracts the pattern of the five functions. When you are finished, use fold-tree to defined Give a definition of depth. Give a definition of count. Hint: You may not be able to make count fit the pattern because it has an extra case and takes an extra argument. You can curry count and use count-c to implement count. You can use a helper function to combine the last two cases and rewrite count using the helper-function. These two tricks will make it look more like the others. Fold Tree The function fold-tree can be used to define new functions. For example, > (flatten-tree '((1 . 2) . (3 . 4))) (1 2 3 4) > (flatten-tree '((a) ((b)) (((c))))) (a b c) > (map-tree add1 '((1 . 2) . (3 . 4))) ((2 . 3) . (4 . 5)) > (map-tree even '((1 . 2) . (3 . 4))) ((#f . #t) . (#f . #t)) Demonstrate your ability to use the fold-tree abstraction by using it to Define flatten-tree. Define map-tree.
Kitambulisho cha mradi: 29706903

Kuhusu mradi

pendekezo 1
Mradi wa mbali
Inatumika 3 yrs ago

Unatafuta kupata pesa?

Faida za kutoa zabuni kwenye Freelancer

Weka bajeti yako na muda uliopangwa
Pata malipo kwa kazi yako
Eleza pendekezo lako
Ni bure kujiandikisha na kutoa zabuni kwa kazi
1 mfanyakazi huru ana zabuni kwa wastani $200 USD kwa kazi hii
Picha ya Mtumiaji
hello , i just read task discription and it really jumped out on me , i can deliver it perfectly . i am a developer having 5 years of experience , although I am a new reelancer and being a new freelancer doesn't describe my tech skills just give me a chance I will give my 100% and will provide a neat and nice solution. just message me the timings when we can talk . Best Regards, Rohit Angira
$200 USD ndani ya siku 7
5.0 (3 hakiki)
3.0
3.0

Kuhusu mteja

Bedera ya UNITED STATES
albuquerque, United States
0.0
0
Njia ya malipo imethibitishwa
Mwanachama tangu Des 6, 2019

Uthibitishaji wa Mteja

Asante! Tumekutumia kiungo cha kudai mkopo wako bila malipo kwa barua pepe.
Hitilafu fulani imetokea wakati wa kutuma barua pepe yako. Tafadhali jaribu tena.
Watumiaji Waliosajiliwa Jumla ya Kazi Zilizochapishwa
Freelancer ® is a registered Trademark of Freelancer Technology Pty Limited (ACN 142 189 759)
Copyright © 2024 Freelancer Technology Pty Limited (ACN 142 189 759)
Onyesho la kukagua linapakia
Ruhusa imetolewa kwa Uwekaji wa Kijiografia.
Muda wako wa kuingia umeisha na umetoka nje. Tafadhali ingia tena.