[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Issue: MAP-INTO (version 1)



This is a new issue.  It arose from an investigation of features
that are plausibly needed but missing from draft ANSI Common Lisp.
This issue seems sufficiently simple and noncontroversial that
I would like to see it on the agenda for the June X3J13 meeting.
Let's use the cleanup subcommittee to test the assertion that this
is a simple and noncontroversial issue.  If it's controversial,
let's just drop it, otherwise let's give X3J13 a chance to vote
for or against it.

Issue:          MAP-INTO
References:     none
Related issues: BIT-ARRAY-FUNCTIONS
Category:       ADDITION
Edit history:   23-May-89, version 1 by Moon

Problem description:

  The function MAP is very useful but can be a source of inefficiency
  because it conses the result.  Sometimes the user has storage
  already allocated in which the result could be stored.

Proposal (MAP-INTO:ADD-FUNCTION):

  Add the following function:

    MAP-INTO result-sequence function &rest sequences		[Function]

    Destructively modifies the result-sequence to contain the results of
    applying function to each element in the argument sequences in turn.
    Returns result-sequence.

    MAP-INTO differs from MAP in that it modifies an existing sequence
    rather than creating a new one.

    The arguments result-sequence and each element of sequences can each be
    either a list or a vector (one-dimensional array).  Note that nil is
    considered to be a sequence, of length zero.  If result-sequence and
    each element of sequences are not all the same length, the iteration
    terminates when the shortest sequence is exhausted.

    If BIT-ARRAY-FUNCTIONS:NO-NEW-FUNCTIONS passes, then MAP-INTO will
    allow result-sequence and each element of sequences to be mappables
    all of the same rank.

    The function must take at least as many arguments as there are
    sequences provided, and at least one sequence must be provided.

    If function has side effects, it can count on being called first on all
    of the elements with index 0, then on all of those numbered 1, and so
    on.

Examples:

  (map-into x #'+ x y)
  (map-into q #'cons keys vals)

Rationale:

  MAP-INTO is a simple way to express reuse of storage that is
  stylistically consistent with the rest of Common Lisp.

Current practice:

  Symbolics Genera 7.2 implements the proposal.

Cost to Implementors:

  Small.

Cost to Users:

  None.

Cost of non-adoption:

  Small.

Performance impact:

  None.

Benefits:

  More expressive language.

Esthetics:

  User programs won't have to write the above examples as

   (loop for xx on x and yy in y do
      (setf (car xx) (+ (car xx) yy)))

  or something else about equally horrible.

Discussion:

  None.