Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am programming in Scheme, I am trying to make a function where you take a list of numbers, reverse the list, throw out the

I am programming in Scheme, I am trying to make a function where you take a list of numbers, reverse the list, throw out the negative numbers and summation the non-negatives. Here is my code:
(define (sum n)
(if (eq?n 0)
0
(+n (sum (-n 1)))))
(define (ReverseEm elems)
(if (null?elems)
'()
(append (ReverseEm (cdr elems))
(list (car elems)))))
(define (nonNegative num)
(if (>=num 0)
num
0))
(define (JustDoIt lst)
(if (nonNegative (ReverseEm (sum lst))))
If I run (JustDoIt '(3-14602-5))it say Ill-formed special form: if
The correct output should be (30216)
Because summation of 3is 1+2+3=6,-14gets thrown out, 1+2+3+4+5+6=21,0=0,1+2=3,-5gets thrown out, the list gets reversed: (30216),I feel I am close, but I can't get the form right in scheme because I am unfimiliar with it,can you help me?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Current Trends In Database Technology Edbt 2004 Workshops Edbt 2004 Workshops Phd Datax Pim P2panddb And Clustweb Heraklion Crete Greece March 2004 Revised Selected Papers Lncs 3268

Authors: Wolfgang Lindner ,Marco Mesiti ,Can Turker ,Yannis Tzitzikas ,Athena Vakali

2005th Edition

3540233059, 978-3540233053

More Books

Students also viewed these Databases questions