File: string-map

package info (click to toggle)
scheme9 2025.08.12-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,080 kB
  • sloc: lisp: 16,752; ansic: 11,869; sh: 806; makefile: 237; sed: 6
file content (19 lines) | stat: -rw-r--r-- 612 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
S9 LIB  (string-map procedure^1 string ...)   ==>  string
        (string-map! procedure^1 string ...)  ==>  unspecific

        (load-from-library "string-map.scm")

Map a procedure over a string, giving a new string

      (string (f (string-ref s i)) ...)

where F is the given PROCEDURE and S is the string to map.
STRING-MAP is to strings what MAP is to lists.

STRING-MAP! does not create a fresh string, but changes the
given one in situ.

(string-map char-downcase "HELLO")  ==>  "hello"
(let ((s (string-copy "HELLO!")))
  (string-map! char-downcase s)
  s)                                ==>  "hello!"