Loki Kira
Loki Kira

Reputation: 19

how to Implement in Scheme this function

The Maple computer algeba system has a command seq(f, i = m..n, step), which returns the sequence fm,...fn, where fi is the expression f with all occurrences of the symbol i replaced by the numeric value of i in the sequence of integers from m to n. Implement a scheme function (seq f (start step end)), and produces a list of values (f(start),f(start+step),...,f(start+n*step)), where n is the largest integer such that start+n*step <= end and start+(n+1)*step > end.

I thought this would work: (seq (lambda (x) (* x x)) '(0 2 7)) => (0 4 16 36)

Upvotes: 0

Views: 164

Answers (1)

C. K. Young
C. K. Young

Reputation: 223183

The basic solution to this is to implement iota and map, and combine the two:

  • iota generates a list of numbers given the start, stop, and step
  • map invokes a given function on all the elements of the given list, and returns a new list containing the returned values

You have to write those functions, but once you have, your seq function is a simple matter of piecing the two together.

Upvotes: 2

Related Questions