Skip to content

Commit b578b58

Browse files
committed
Distinguish listy ords/chrs from ord/chr
It will be too confusing to overload ord/chr with both scalar and list semantics. This will also give more information to the optimizer at compile time, since it cannot know whether .ord will be passed a single- or multi-character string
1 parent 493684e commit b578b58

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

S29-functions.pod

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ Synopsis 29: Builtin Functions
1919

2020
Created: 12 Mar 2005
2121

22-
Last Modified: 20 Nov 2010
23-
Version: 47
22+
Last Modified: 10 Dec 2010
23+
Version: 48
2424

2525
The document is a draft.
2626

@@ -293,27 +293,29 @@ C<BUILDALL> routine for the current class, which initializes the object in
293293
least-derived to most-derived order. See L<S12/Objects>
294294
for more detailed information on object creation.
295295

296+
=item chrs
297+
298+
=item ords
299+
296300
=item chr
297301

298302
=item ord
299303

304+
multi sub chrs( Int *@grid --> List of Char )
305+
multi method ords( Str $string: --> List of Int ) is export
300306
multi method chr( Int $grid: --> Char ) is export
301-
multi sub chr( Int *@grid --> Char )
302307
multi method ord( Str $string: --> Int ) is export
303308

304-
C<chr> takes zero or more integer grapheme ids and returns the
309+
C<chrs> takes zero or more integer grapheme ids and returns the
305310
corresponding characters as a string. If any grapheme id is used
306311
that represents a higher abstraction level than the current
307312
lexical scope supports, that grapheme is converted to the
308313
corresponding lower-level string of codepoints/bytes that would
309314
be appropriate to the current pragmatic context, just as any other Str
310315
would be downgraded in context.
311316

312-
C<ord> goes the other direction; it takes a string value and returns
313-
character values as integers. In item context, the return value
314-
is the just the integer value of the first character in the string. In
315-
list context, the return value is the list of integers representing
316-
the entire string. The definition of character is pragma dependent.
317+
C<ords> goes the other direction; it takes a string value and returns
318+
character values as integers. The definition of character is pragma dependent.
317319
Normally it's a grapheme id, but under codepoints or bytes scopes,
318320
the string is coerced to the appropriate low-level view and interpreted
319321
as codepoints or bytes. Hence, under "use bytes" you will never see a
@@ -329,6 +331,10 @@ context knows its normalization preferences, and every byte's context
329331
also knows its encoding preferences. (These are knowable in the
330332
lexical scope via the $?NF and $?ENC compile-time constants).)
331333

334+
The C<chr> and C<ord> variants are restricted to processing a single
335+
character. As is customary, you may pass a longer string to C<ord>,
336+
but only the first character will be translated.
337+
332338
=item item
333339

334340
our Item multi item ( $item )

0 commit comments

Comments
 (0)