MAP: infer return type of mapping function

Bug #1720962 reported by Michał "phoe" Herda
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SBCL
Fix Released
Wishlist
Unassigned

Bug Description

As per https://markkarpov.com/post/lisp-and-haskell.html :

There is a function mentioned in the above blog post, the full body of which is:

(defun add-text-padding (str &key padding newline)
  "Add padding to text STR. Every line except for the first one, will be
prefixed with PADDING spaces. If NEWLINE is non-NIL, newline character will
be prepended to the text making it start on the next line with padding
applied to every single line."
  (let ((str (if newline
                 (concatenate 'string (string #\Newline) str)
                 str)))
    (with-output-to-string (s)
      (map 'string
           (lambda (x)
             (princ x s)
             (when (char= x #\Newline)
               (dotimes (i padding)
                 (princ #\Space s))))
           str))))

The troublesome part is the (MAP 'STRING (LAMBDA (X) ...) STR) call. The anonymous function ends with a WHEN/DOTIMES call, which causes it to always return NIL. MAP 'STRING, in turn, requires that its function returns characters.

This information can be utilized by SBCL to emit a compile-time warning about mismatched types: the type exected by MAP and actual return type of the function.

Tags: improvement
Stas Boukarev (stassats)
Changed in sbcl:
status: New → Triaged
importance: Undecided → Wishlist
assignee: nobody → Stas Boukarev (stassats)
Revision history for this message
Stas Boukarev (stassats) wrote :

In da13f47cceaacafa6f4f60917032c2cdb22add5e.

Changed in sbcl:
status: Triaged → Fix Committed
assignee: Stas Boukarev (stassats) → nobody
Revision history for this message
Michał "phoe" Herda (phoe-krk) wrote :

That was fast! Thank you!

Stas Boukarev (stassats)
Changed in sbcl:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.