Idea for MAP function

Started by JeremyDunn, July 22, 2010, 09:38:44 PM

Previous topic - Next topic

JeremyDunn

I was thinking of a new form of the MAP function that would be useful. I would like to have a form of it where you could write (map func list true) where instead of a second list you have a truth flg to denote the new form. In this arrangement what happens is that func is mapped onto list. The values of the mappings are compared to each other, if they are all equal then the value is returned else nil is. This doesn't break the current syntax and adds another useful feature but maybe others disagree.

cormullion

#1
Nice idea. A lot of existing functions append an optional function (func-compare) at the end. Not sure if that's useful here - but are there more general purpose applications than just a "is everything equal?" test?

johu

#2
I thought some functions.



(define (map+ func lst bool)
  (if bool
      (apply = (map func lst))
    (map func lst))
)

(define (map-compare func lst value)
  (apply = (cons value (map func lst)))
)

(define (map-predicate func lst bool)
  (if bool
      (for-all func lst)
    (map func lst))
)


Which is corresponding ? or another function ?