Idea for MAP function
-
- Posts: 11
- Joined: Wed Apr 07, 2010 12:18 am
Idea for MAP function
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.
-
- Posts: 2038
- Joined: Tue Nov 29, 2005 8:28 pm
- Location: latiitude 50N longitude 3W
- Contact:
Re: Idea for MAP function
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
I thought some functions.
Which is corresponding ? or another function ?
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))
)