Skip to content

Commit f46f16a

Browse files
committed
stdlib: implement new print() API
rdar://20775683 Swift SVN r28309
1 parent 6dfbd87 commit f46f16a

File tree

504 files changed

+3233
-3115
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

504 files changed

+3233
-3115
lines changed

docs/Arrays.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ copies of that array::
9898
var a = [1, 2, 3]
9999
let b = a
100100
a[1] = 42
101-
println(b[1]) // prints "42"
101+
print(b[1]) // prints "42"
102102

103103
This implies that the elments of an array are notionally not part of
104104
the array's value, and indeed subscript assignment is a non-mutating
@@ -125,7 +125,7 @@ array to ensure unique ownership before mutating it::
125125
var a = [1, 2, 3]
126126
let b = a
127127
a[1] = 42
128-
println(b[1]) // prints "42"
128+
print(b[1]) // prints "42"
129129

130130
Shared Subscript Assignment and ``NSArray``
131131
-------------------------------------------

docs/LangRef.html

+10-10
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ <h4 id="func-signature">Function signatures</h4>
323323
func accuseSuspect(suspect:PersonOfInterest)
324324
inRoom(room:Room)
325325
withWeapon(weapon:Weapon) {
326-
println("It was \(suspect) in the \(room) with the \(weapon)")
326+
print("It was \(suspect) in the \(room) with the \(weapon)")
327327
}
328328

329329
<i>// Calling a selector-style function.</i>
@@ -816,14 +816,14 @@ <h4 id="attribute-inout"><tt>inout</tt> Attribute</h4>
816816
var x = 219
817817
var f = foo(&x)
818818
// x is updated to the value of foo's local x at function exit.
819-
println("global x = \(x)")
819+
print("global x = \(x)")
820820
// These calls only update the captured local 'x', which is now independent
821821
// of the inout parameter.
822-
println("local x = \(f())")
823-
println("local x = \(f())")
824-
println("local x = \(f())")
822+
print("local x = \(f())")
823+
print("local x = \(f())")
824+
print("local x = \(f())")
825825

826-
println("global x = \(x)")
826+
print("global x = \(x)")
827827
</pre>
828828

829829
will print:
@@ -1581,7 +1581,7 @@ <h4 id="expr-ternary">Ternary operator</h4>
15811581
x += a ? b ? y : z : w
15821582

15831583
for i in 1...101 {
1584-
println(i % 15 ? "fizzbuzz"
1584+
print(i % 15 ? "fizzbuzz"
15851585
: i % 3 == 0 ? "fizz"
15861586
: i % 5 == 0 ? "buzz"
15871587
: "\(i)")
@@ -1731,7 +1731,7 @@ <h3 id="expr-literal">Literals</h3>
17311731
func log(message:String,
17321732
file:String = __FILE__,
17331733
line:Int = __LINE__) {
1734-
println("\(file):\(line): \(message)")
1734+
print("\(file):\(line): \(message)")
17351735
}
17361736

17371737
log("Orders received")
@@ -1807,7 +1807,7 @@ <h4 id="expr-generic-disambiguation">Generic disambiguation</h4>
18071807
infix func +-+ &lt;T, U&gt;(t:T.Type, u:U.Type) -&gt; Foo { }
18081808

18091809
var foo = (Dict&lt;String, Int&gt;) +-+ (Array&lt;UnicodeScalar&gt;)
1810-
println(foo)
1810+
print(foo)
18111811
</pre>
18121812

18131813
<p>On the other hand, some expressions involving <tt>&lt;</tt> and
@@ -2495,7 +2495,7 @@ <h3 id="stmt-for-each">'for-each' Statement</h3>
24952495

24962496
<pre class="example">
24972497
for i in 0...100 {
2498-
println(String(i));
2498+
print(String(i));
24992499
}
25002500
</pre>
25012501

docs/LangRefNew.rst

+28-28
Original file line numberDiff line numberDiff line change
@@ -908,7 +908,7 @@ of the parameter is the ``set-name``, if provided, or ``value`` otherwise.
908908
var vec = BitVector64()
909909
vec[2] = true
910910
if vec[3] {
911-
println("third bit is set")
911+
print("third bit is set")
912912
}
913913

914914
.. _langref.decl.attribute_list:
@@ -977,21 +977,21 @@ of :ref:`switch statements <langref.stmt.switch>`. Some examples::
977977
// Extract the elements of the "point" tuple and bind them to
978978
// variables x, y, and z.
979979
var (x, y, z) = point
980-
println("x=\(x) y=\(y) z=\(z)")
980+
print("x=\(x) y=\(y) z=\(z)")
981981

982982
// Dispatch on the elements of a tuple in a "switch" statement.
983983
switch point {
984984
case (0, 0, 0):
985-
println("origin")
985+
print("origin")
986986
// The pattern "_" matches any value.
987987
case (_, 0, 0):
988-
println("on the x axis")
988+
print("on the x axis")
989989
case (0, _, 0):
990-
println("on the y axis")
990+
print("on the y axis")
991991
case (0, 0, _):
992-
println("on the z axis")
992+
print("on the z axis")
993993
case (var x, var y, var z):
994-
println("x=\(x) y=\(y) z=\(z)")
994+
print("x=\(x) y=\(y) z=\(z)")
995995
}
996996

997997

@@ -1061,13 +1061,13 @@ bindings are immutable.
10611061
switch point {
10621062
// Bind x, y, z to the elements of point.
10631063
case (var x, var y, var z):
1064-
println("x=\(x) y=\(y) z=\(z)")
1064+
print("x=\(x) y=\(y) z=\(z)")
10651065
}
10661066

10671067
switch point {
10681068
// Same. 'var' distributes to the identifiers in its subpattern.
10691069
case var (x, y, z):
1070-
println("x=\(x) y=\(y) z=\(z)")
1070+
print("x=\(x) y=\(y) z=\(z)")
10711071
}
10721072

10731073
Outside of a <tt>var</tt> pattern, an identifier behaves as an :ref:`expression
@@ -1080,9 +1080,9 @@ pattern <langref.pattern.expr>` referencing an existing definition.
10801080
// x and z are bound as new variables.
10811081
// zero is a reference to the existing 'zero' variable.
10821082
case (var x, zero, var z):
1083-
println("point off the y axis: x=\(x) z=\(z)")
1083+
print("point off the y axis: x=\(x) z=\(z)")
10841084
default:
1085-
println("on the y axis")
1085+
print("on the y axis")
10861086
}
10871087

10881088
The left-hand pattern of a :ref:`var declaration <langref.decl.var>` and the
@@ -1151,11 +1151,11 @@ appear in declarations.
11511151
for b in bs {
11521152
switch b {
11531153
case is B:
1154-
println("B")
1154+
print("B")
11551155
case is D1:
1156-
println("D1")
1156+
print("D1")
11571157
case is D2:
1158-
println("D2")
1158+
print("D2")
11591159
}
11601160
}
11611161

@@ -1183,11 +1183,11 @@ type, the value of that type can be matched against an optional subpattern.
11831183

11841184
switch tag {
11851185
case .BR:
1186-
println("<br>")
1186+
print("<br>")
11871187
case .IMG(var src, var alt):
1188-
println("<img src=\"\(escape(src))\" alt=\"\(escape(alt))\">")
1188+
print("<img src=\"\(escape(src))\" alt=\"\(escape(alt))\">")
11891189
case .A(var href):
1190-
println("<a href=\"\(escape(href))\">")
1190+
print("<a href=\"\(escape(href))\">")
11911191
}
11921192

11931193
Enum element patterns are refutable and thus cannot appear in declarations.
@@ -1213,12 +1213,12 @@ operator may be overloaded like any function.
12131213
switch point {
12141214
// Equality comparison.
12151215
case (0, 0, 0):
1216-
println("origin")
1216+
print("origin")
12171217
// Range comparison.
12181218
case (-10...10, -10...10, -10...10):
1219-
println("close to the origin")
1219+
print("close to the origin")
12201220
default:
1221-
println("too far away")
1221+
print("too far away")
12221222
}
12231223

12241224
// Define pattern matching of an integer value to a string expression.
@@ -1229,9 +1229,9 @@ operator may be overloaded like any function.
12291229
// Now we can pattern-match strings to integers:
12301230
switch point {
12311231
case ("0", "0", "0"):
1232-
println("origin")
1232+
print("origin")
12331233
default:
1234-
println("not the origin")
1234+
print("not the origin")
12351235
}
12361236

12371237
The order of evaluation of expressions in patterns, including whether an
@@ -1347,22 +1347,22 @@ otherwise empty cases in switch statements.
13471347
func classifyPoint(point: (Int, Int)) {
13481348
switch point {
13491349
case (0, 0):
1350-
println("origin")
1350+
print("origin")
13511351

13521352
case (_, 0):
1353-
println("on the x axis")
1353+
print("on the x axis")
13541354

13551355
case (0, _):
1356-
println("on the y axis")
1356+
print("on the y axis")
13571357

13581358
case (var x, var y) where x == y:
1359-
println("on the y = x diagonal")
1359+
print("on the y = x diagonal")
13601360

13611361
case (var x, var y) where -x == y:
1362-
println("on the y = -x diagonal")
1362+
print("on the y = -x diagonal")
13631363

13641364
case (var x, var y):
1365-
println("length \(sqrt(x*x + y*y))")
1365+
print("length \(sqrt(x*x + y*y))")
13661366
}
13671367
}
13681368

docs/SequencesAndCollections.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ end. For example::
174174
}
175175

176176
let s = String(array("Swift", withSeparator: "|"))
177-
println(s) // "S|w|i|f|t"
177+
print(s) // "S|w|i|f|t"
178178

179179
Because sequences may be volatile, though, you can—in general—only
180180
make a single traversal. This capability is quite enough for many

docs/StoredAndComputedVariables.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ A computed variable may also be overridden with another computed variable::
215215
}
216216
}
217217
set {
218-
println("Sorry, we choose our own colors here.")
218+
print("Sorry, we choose our own colors here.")
219219
}
220220
}
221221
}
@@ -231,7 +231,7 @@ A subclass may override the superclass's variable with a new computed variable::
231231
class ColorBase {
232232
var color : Color {
233233
didSet {
234-
println("I've been painted \(color)!")
234+
print("I've been painted \(color)!")
235235
}
236236
}
237237
}

docs/StringDesign.rst

+4-4
Original file line numberDiff line numberDiff line change
@@ -350,18 +350,18 @@ end, strings support properties for more-specific segmentations:
350350
has some advice for us.
351351

352352
.. parsed-literal::
353-
|swift| for c in s { println("Extended Grapheme Cluster: \(c)") }
353+
|swift| for c in s { print("Extended Grapheme Cluster: \(c)") }
354354
`Extended Grapheme Cluster: f`
355355
`Extended Grapheme Cluster: o`
356356
`Extended Grapheme Cluster: o`
357357
|swift| for c in s.collationCharacters {
358-
println("Collation Grapheme Cluster: \(c)")
358+
print("Collation Grapheme Cluster: \(c)")
359359
}
360360
`Collation Grapheme Cluster: f`
361361
`Collation Grapheme Cluster: o`
362362
`Collation Grapheme Cluster: o`
363363
|swift| for c in s.searchCharacters {
364-
println("Search Grapheme Cluster: \(c)")
364+
print("Search Grapheme Cluster: \(c)")
365365
}
366366
`Search Grapheme Cluster: f`
367367
`Search Grapheme Cluster: o`
@@ -406,7 +406,7 @@ Strings are **Encoded as UTF-8**
406406

407407
.. parsed-literal::
408408
|swift| for x in "bump"\ **.bytes** {
409-
println(x)
409+
print(x)
410410
}
411411
98
412412
117

docs/TextFormatting.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ CustomStringConvertible Types
6363
-----------------------------
6464

6565
``CustomStringConvertible`` types can be used in string literal interpolations,
66-
printed with ``print(x)`` and ``println(x)``, and can be converted to
67-
``String`` with ``x.toString()``.
66+
printed with ``print(x)``, and can be converted to ``String`` with
67+
``x.toString()``.
6868

6969
The simple extension story for beginners is as follows:
7070

docs/proposals/Enums.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ only the currently inhabited type is ever used::
3333
var p : Pattern = .Checkers(.Black, .White)
3434
switch p {
3535
case .Solid(var c):
36-
println("solid \(c)")
36+
print("solid \(c)")
3737
case .Outline(var c):
38-
println("outlined \(c)")
38+
print("outlined \(c)")
3939
case .Checkers(var a, var b):
40-
println("checkered \(a) and \(b)")
40+
print("checkered \(a) and \(b)")
4141
}
4242

4343
Given the choice between two familiar keywords, we decided to use 'enum' to

docs/proposals/KVO2_Omnibus.rst

+7-7
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ capturing closures that get and set the property, e.g.::
4949
var x = 0
5050
let xRef = Ref(getter: { x }, setter: { x = $0 })
5151
xRef.value = 2
52-
println(x)
52+
print(x)
5353

5454
which no one would ever want to write by hand. I propose that we extend the
5555
``inout`` modifier so that it can also be applied to return types, and
@@ -63,7 +63,7 @@ capturing local variables in the process::
6363
var x = 0
6464
let xRef = { &x }
6565
xRef() = 2
66-
println(x)
66+
print(x)
6767

6868
When combined with our existing ``@autoclosure`` and ``assignment``
6969
operator features, we can write a "bind" operator with implicit capture
@@ -287,10 +287,10 @@ semantics::
287287
// ...or methods with specific arguments...
288288
button2.setTarget(button2=>.setTitle("Click me again, I dare you"))
289289
// ...or free functions...
290-
button3.setTarget(message=>println)
290+
button3.setTarget(message=>print)
291291
// ...or (context-free) blocks of code!
292292
button4.setTarget(message => {
293-
println("The button so nice, it prints twice: \($0) \($0)")
293+
print("The button so nice, it prints twice: \($0) \($0)")
294294
})
295295

296296
A further refinement on ``@thin`` would be to have ``@static`` function values,
@@ -363,10 +363,10 @@ chaining operator ``?``::
363363

364364
This has the added power of letting you chain closures or free functions::
365365

366-
x ¿ .sorted(<) ¿ println // prints "[1, 2, 3]"
367-
y ¿ .sorted(<) ¿ println // does nothing
366+
x ¿ .sorted(<) ¿ print // prints "[1, 2, 3]"
367+
y ¿ .sorted(<) ¿ print // does nothing
368368

369-
x ¿ .sorted(<) ¿ { println($0[0]) } // prints "1"
369+
x ¿ .sorted(<) ¿ { print($0[0]) } // prints "1"
370370

371371
Key Paths
372372
---------

docs/proposals/ValueSemantics.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ classes:
222222
}
223223
224224
RandomNumberGenerator x = new MersenneTwister()
225-
println(
225+
print(
226226
cycle_length(x, (x : [inout] RandomNumberGenerator) { x.nextValue() })
227227
)
228228

0 commit comments

Comments
 (0)