[Swift-devel] Question: Reading from keyboard

Michael Wilde wilde at anl.gov
Sun Jul 13 17:40:38 CDT 2014


Delf,

If you are asking about Apple's Swift language, please refer to 
https://developer.apple.com/swift/

If you are asking about the Swift parallel scripting language 
(http://swift-lang.org), you should join the swift-user email list and 
ask this question there.

Having said that, in our Swift language there is seldom a reason to read 
from stdin, although one could envision such cases.

You can read from stdin in a limited manner like this:

$ cat stdin.swift
type file;

string s = readData("/dev/stdin");
trace(s);

$ swift stdin.swift
Swift 0.94.1 swift-r7114 cog-r3803

RunID: 20140713-2234-4r8sfd3b
Progress:  time: Sun, 13 Jul 2014 22:34:59 +0000
This is my input on stdin.
^D
SwiftScript trace: This is my input on stdin.
Final status: Sun, 13 Jul 2014 22:35:11 +0000
$

All of stdin until an EOF (^D) is read by readData( ).
There is no line separation if you read into a scalar.

If you read into a string array, each line of stdin is assigned to an 
element of the array.

One could envision a read function that reads stdin a line at a time, to 
enable an interactive Swift script, but to date this need has not arisen.

- Mike

On 7/13/14, 5:22 PM, Delf Egge HCU wrote:
> Dear people!
>
> Could you please help me and let me know
>
> how to input characters (strings) from the keyboard with Swift?
>
> I am only aware of the C language "scanf".
>
> Thank you very much in advance.
>
> Kind regards,
> Delf Egge
>
> delf.egge at hcu-hamburg.de
>
> Sent from my iPhone.
>
>> Am 14.07.2014 um 00:05 schrieb swift-devel-request at ci.uchicago.edu:
>>
>> Send Swift-devel mailing list
> Rest deleted.
> _______________________________________________
> Swift-devel mailing list
> Swift-devel at ci.uchicago.edu
> https://lists.ci.uchicago.edu/cgi-bin/mailman/listinfo/swift-devel

-- 
Michael Wilde
Mathematics and Computer Science          Computation Institute
Argonne National Laboratory               The University of Chicago




More information about the Swift-devel mailing list