Idea for MAP function

Pondering the philosophy behind the language
Locked
JeremyDunn
Posts: 11
Joined: Wed Apr 07, 2010 12:18 am

Idea for MAP function

Post 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.

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Re: Idea for MAP function

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

johu
Posts: 143
Joined: Mon Feb 08, 2010 8:47 am

Re: Idea for MAP function

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

Locked