New to scheme here. I’m trying to compile a scheme function, range. It’s very simple – it takes a start, step and stop list L and makes a new list where every element = stepAmt + curStep.
For example: (range ‘(0 2 7)) => (0 2 4 6), (range ‘(2 2 0)) => ()
When I try to compile
(define (helper2(start stepAmt stop curStep newList)
(if (> start stop)
'()
(if (> (+ stepAmt curStep) stop)
newList
(helper2 (start stepAmt stop (+ stepAmt curStep) (concat newList (+stepAmt curStep))))))))
I get the error
Ill-formed special form: (define helper2 (start stepamt stop curstep newlist) (if … … …))
I’m not sure what it means. I’ve double checked my logic and parentheses and can’t figure it out.
This is the function that will call that function:
(define (example L)
(let (
(start (car L))
(curStep (car (cdr L)))
(step (car (cdr L)))
(stop (car (cdr (cdr L))))
)
(helper2 (start step stop curStep '()))
)
)
Any pointers would be great. I’m not sure if it’s a typo or a logical error. Thank you!
You need not
but
The way to remember this is that what goes after
definelooks just like a call to the function you’re defining. “Here’s how to deal with a call like(helper2 some arguments go here): …”