Page 1 of 1

Idea for MAP function

Posted: Fri Jul 23, 2010 4:38 am
by 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.

Re: Idea for MAP function

Posted: Sat Jul 24, 2010 6:06 pm
by cormullion
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?

Re: Idea for MAP function

Posted: Sat Jul 24, 2010 11:39 pm
by johu
I thought some functions.

Code: Select all

(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 ?