Find Jobs
Hire Freelancers

Scheme Small task

$30-250 USD

Suljettu
Julkaistu noin 3 vuotta sitten

$30-250 USD

Maksettu toimituksen yhteydessä
;; ===== 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.
Projektin tunnus (ID): 29706903

Tietoa projektista

1 ehdotus
Etäprojekti
Aktiivinen 3 vuotta sitten

Haluatko ansaita rahaa?

Freelancerin tarjouskilpailun edut

Aseta budjettisi ja aikataulu
Saa maksu työstäsi
Kuvaile ehdotustasi
Rekisteröinti ja töihin tarjoaminen on ilmaista
1 freelancerit tarjoavat keskimäärin $200 USD tätä projektia
Käyttäjän avatar
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 7 päivässä
5,0 (3 arvostelua)
3,0
3,0

Tietoja asiakkaasta

Maan UNITED STATES lippu
albuquerque, United States
0,0
0
Maksutapa vahvistettu
Liittynyt jouluk. 6, 2019

Asiakkaan vahvistus

Kiitos! Olemme lähettäneet sinulle sähköpostitse linkin, jolla voit lunastaa ilmaisen krediittisi.
Jotain meni pieleen lähetettäessä sähköpostiasi. Yritä uudelleen.
Rekisteröitynyttä käyttäjää Ilmoitettua työtä yhteensä
Freelancer ® is a registered Trademark of Freelancer Technology Pty Limited (ACN 142 189 759)
Copyright © 2024 Freelancer Technology Pty Limited (ACN 142 189 759)
Ladataan esikatselua
Lupa myönnetty Geolocation.
Kirjautumisistuntosi on vanhentunut ja sinut on kirjattu ulos. Kirjaudu uudelleen sisään.