Addition of a standardError OutputStream


(Saagar Jha) #1

Currently, it’s rather annoying to print to standard error, requiring
either something low-level like fputs. I was wondering if a standardError
OutputStream could be added to the standard library, so we could write
something like print(“foo”, &standardError).

···

--
-Saagar Jha


(Erica Sadun) #2

Right now it's more like "foo".write(to: &stream) but I agree that having to implement
a custom stream is kind of irritating for stderr and stdout.

import Cocoa

var str = "Hello, playground"

struct StderrStream: OutputStream {
    static var shared = StderrStream()
    func write(_ string: String) { fputs(string, stderr) }
}

str.write(to: &StderrStream.shared)

-- E

···

On Jul 8, 2016, at 4:41 PM, Saagar Jha via swift-evolution <swift-evolution@swift.org> wrote:

Currently, it’s rather annoying to print to standard error, requiring either something low-level like fputs. I was wondering if a standardError OutputStream could be added to the standard library, so we could write something like print(“foo”, &standardError).

--
-Saagar Jha
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


(Saagar Jha) #3

What is the process for smaller issues like these? I’m guessing that this doesn’t need a proposal; where should it go? On bugs.swift.org <http://bugs.swift.org/>?

···

On Jul 8, 2016, at 16:33, Erica Sadun <erica@ericasadun.com> wrote:

Right now it's more like "foo".write(to: &stream) but I agree that having to implement
a custom stream is kind of irritating for stderr and stdout.

import Cocoa

var str = "Hello, playground"

struct StderrStream: OutputStream {
    static var shared = StderrStream()
    func write(_ string: String) { fputs(string, stderr) }
}

str.write(to: &StderrStream.shared)

-- E

On Jul 8, 2016, at 4:41 PM, Saagar Jha via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:

Currently, it’s rather annoying to print to standard error, requiring either something low-level like fputs. I was wondering if a standardError OutputStream could be added to the standard library, so we could write something like print(“foo”, &standardError).

--
-Saagar Jha
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org <mailto:swift-evolution@swift.org>
https://lists.swift.org/mailman/listinfo/swift-evolution


(Dave Abrahams) #4

If it adds an API, it needs a proposal. Doesn't necessarily have to be
a big proposal, and the review period can be short, but we don't add
APIs without the evolution process.

Thanks,
Dave

···

on Sun Jul 10 2016, Saagar Jha <swift-evolution@swift.org> wrote:

What is the process for smaller issues like these? I’m guessing that
this doesn’t need a proposal; where should it go? On bugs.swift.org
<http://bugs.swift.org/>?

--
Dave


(Saagar Jha) #5

Thanks, I’ll write it up.

···

On Jul 11, 2016, at 11:20, Dave Abrahams via swift-evolution <swift-evolution@swift.org> wrote:

on Sun Jul 10 2016, Saagar Jha <swift-evolution@swift.org> wrote:

What is the process for smaller issues like these? I’m guessing that
this doesn’t need a proposal; where should it go? On bugs.swift.org
<http://bugs.swift.org/>?

If it adds an API, it needs a proposal. Doesn't necessarily have to be
a big proposal, and the review period can be short, but we don't add
APIs without the evolution process.

Thanks,
Dave

--
Dave

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


(Erica Sadun) #6

Just throwing this here. Unfortunately `Stream` is already taken (and tied to Foundation).

public struct StdStream {
    public struct StderrStream: OutputStream {
        public func write(_ string: String) { fputs(string, Darwin.stderr) }
    }
    
    public struct StdoutStream: OutputStream {
        public func write(_ string: String) { fputs(string, Darwin.stdout) }
    }
    
    public static var err = StderrStream()
    public static var out = StdoutStream()
}

So in use, it would look something like

str.write(to: &StdStream.out)
str.write(to: &StdStream.err)

I also considered DarwinStream (seemed too on the nose), UnixStream, Streamfd, BSDStream, etc. Didn't like any of them.

-- E, have paintbrush will bikeshed

···

On Jul 11, 2016, at 12:58 PM, Saagar Jha via swift-evolution <swift-evolution@swift.org> wrote:

Thanks, I’ll write it up.

On Jul 11, 2016, at 11:20, Dave Abrahams via swift-evolution <swift-evolution@swift.org> wrote:

on Sun Jul 10 2016, Saagar Jha <swift-evolution@swift.org> wrote:

What is the process for smaller issues like these? I’m guessing that
this doesn’t need a proposal; where should it go? On bugs.swift.org
<http://bugs.swift.org/>?

If it adds an API, it needs a proposal. Doesn't necessarily have to be
a big proposal, and the review period can be short, but we don't add
APIs without the evolution process.

Thanks,
Dave

--
Dave

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


(Zachary Waldowski) #7

`Process` might be a good place for namespacing these. You'll also note
that `print` can take an OutputStream to make this even more idiomatic.
Straw man example at
https://gist.github.com/zwaldowski/4ed2fd48da2af3193b0cbd3ec1883c9d.

Cheers!
  Zachary Waldowski
  zach@waldowski.me

···

On Mon, Jul 11, 2016, at 12:24 PM, Erica Sadun via swift-evolution wrote:

Just throwing this here. Unfortunately `Stream` is already taken (and
tied to Foundation).

public struct StdStream {
public struct StderrStream: OutputStream {
public func write(_ string: String) { fputs(string, Darwin.stderr) }
    }

public struct StdoutStream: OutputStream {
public func write(_ string: String) { fputs(string, Darwin.stdout) }
    }

public static var err = StderrStream()
public static var out = StdoutStream()
}

So in use, it would look something like

str.write(to: &StdStream.out)
str.write(to: &StdStream.err)

I also considered DarwinStream (seemed too on the nose), UnixStream,
Streamfd, BSDStream, etc. Didn't like any of them.

-- E, have paintbrush will bikeshed

On Jul 11, 2016, at 12:58 PM, Saagar Jha via swift-evolution <swift- >> evolution@swift.org> wrote:

Thanks, I’ll write it up.

On Jul 11, 2016, at 11:20, Dave Abrahams via swift-evolution <swift- >>> evolution@swift.org> wrote:

on Sun Jul 10 2016, Saagar Jha <swift-evolution@swift.org> wrote:

What is the process for smaller issues like these? I’m
guessing that
this doesn’t need a proposal; where should it go? On bugs.swift.org
<http://bugs.swift.org/>?

If it adds an API, it needs a proposal. Doesn't necessarily
have to be
a big proposal, and the review period can be short, but we don't add
APIs without the evolution process.

Thanks,
Dave

--
Dave

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_________________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


(Xiaodi Wu) #8

Why not just OutputStream.stderr?

···

On Mon, Jul 11, 2016 at 14:25 Erica Sadun via swift-evolution < swift-evolution@swift.org> wrote:

Just throwing this here. Unfortunately `Stream` is already taken (and tied
to Foundation).

public struct StdStream {
    public struct StderrStream: OutputStream {
        public func write(_ string: String) { fputs(string, Darwin.stderr)
}
    }

    public struct StdoutStream: OutputStream {
        public func write(_ string: String) { fputs(string, Darwin.stdout)
}
    }

    public static var err = StderrStream()
    public static var out = StdoutStream()
}

So in use, it would look something like

str.write(to: &StdStream.out)
str.write(to: &StdStream.err)

I also considered DarwinStream (seemed too on the nose), UnixStream,
Streamfd, BSDStream, etc. Didn't like any of them.

-- E, have paintbrush will bikeshed

On Jul 11, 2016, at 12:58 PM, Saagar Jha via swift-evolution < > swift-evolution@swift.org> wrote:

Thanks, I’ll write it up.

On Jul 11, 2016, at 11:20, Dave Abrahams via swift-evolution < > swift-evolution@swift.org> wrote:

on Sun Jul 10 2016, Saagar Jha <swift-evolution@swift.org> wrote:

What is the process for smaller issues like these? I’m guessing that
this doesn’t need a proposal; where should it go? On bugs.swift.org
<http://bugs.swift.org/>?

If it adds an API, it needs a proposal. Doesn't necessarily have to be
a big proposal, and the review period can be short, but we don't add
APIs without the evolution process.

Thanks,
Dave

--
Dave

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


(Xiaodi Wu) #9

Sorry, I don't really see how these are related to "process". Can you
explain?

···

On Mon, Jul 11, 2016 at 15:08 Zach Waldowski via swift-evolution < swift-evolution@swift.org> wrote:

`Process` might be a good place for namespacing these. You'll also note
that `print` can take an OutputStream to make this even more idiomatic.
Straw man example at
https://gist.github.com/zwaldowski/4ed2fd48da2af3193b0cbd3ec1883c9d.

Cheers!
  Zachary Waldowski
  zach@waldowski.me

On Mon, Jul 11, 2016, at 12:24 PM, Erica Sadun via swift-evolution wrote:

Just throwing this here. Unfortunately `Stream` is already taken (and tied
to Foundation).

public struct StdStream {
public struct StderrStream: OutputStream {
public func write(_ string: String) { fputs(string, Darwin.stderr) }
    }

public struct StdoutStream: OutputStream {
public func write(_ string: String) { fputs(string, Darwin.stdout) }
    }

public static var err = StderrStream()
public static var out = StdoutStream()
}

So in use, it would look something like

str.write(to: &StdStream.out)
str.write(to: &StdStream.err)

I also considered DarwinStream (seemed too on the nose), UnixStream,
Streamfd, BSDStream, etc. Didn't like any of them.

-- E, have paintbrush will bikeshed

On Jul 11, 2016, at 12:58 PM, Saagar Jha via swift-evolution < > swift-evolution@swift.org> wrote:

Thanks, I’ll write it up.

On Jul 11, 2016, at 11:20, Dave Abrahams via swift-evolution < > swift-evolution@swift.org> wrote:

on Sun Jul 10 2016, Saagar Jha <swift-evolution@swift.org> wrote:

What is the process for smaller issues like these? I’m guessing that
this doesn’t need a proposal; where should it go? On bugs.swift.org
<http://bugs.swift.org/>?

If it adds an API, it needs a proposal. Doesn't necessarily have to be
a big proposal, and the review period can be short, but we don't add
APIs without the evolution process.

Thanks,
Dave

--
Dave

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

*_______________________________________________*
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


(Erica Sadun) #10

Why not just OutputStream.stderr?

Can you do an extension like that with state for a protocol?

-- E

···

On Jul 11, 2016, at 1:29 PM, Xiaodi Wu <xiaodi.wu@gmail.com> wrote:

On Mon, Jul 11, 2016 at 14:25 Erica Sadun via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:
Just throwing this here. Unfortunately `Stream` is already taken (and tied to Foundation).

public struct StdStream {
    public struct StderrStream: OutputStream {
        public func write(_ string: String) { fputs(string, Darwin.stderr) }
    }
    
    public struct StdoutStream: OutputStream {
        public func write(_ string: String) { fputs(string, Darwin.stdout) }
    }
    
    public static var err = StderrStream()
    public static var out = StdoutStream()
}

So in use, it would look something like

str.write(to: &StdStream.out)
str.write(to: &StdStream.err)

I also considered DarwinStream (seemed too on the nose), UnixStream, Streamfd, BSDStream, etc. Didn't like any of them.

-- E, have paintbrush will bikeshed


(Xiaodi Wu) #11

You're right. It's at least tricky, if not currently impossible. I take it
back then.

I'd be happy with a `StandardStream` type (though I'd advocate, in the
spirit of Swiftiness, to have it spelled out), with static `output` and
`error`. This might be one of those rare cases where a reference type might
be most appropriate, though, with perhaps a singleton design?

···

On Mon, Jul 11, 2016 at 2:30 PM, Erica Sadun <erica@ericasadun.com> wrote:

On Jul 11, 2016, at 1:29 PM, Xiaodi Wu <xiaodi.wu@gmail.com> wrote:

Why not just OutputStream.stderr?

Can you do an extension like that with state for a protocol?

-- E

On Mon, Jul 11, 2016 at 14:25 Erica Sadun via swift-evolution < > swift-evolution@swift.org> wrote:

Just throwing this here. Unfortunately `Stream` is already taken (and
tied to Foundation).

public struct StdStream {
    public struct StderrStream: OutputStream {
        public func write(_ string: String) { fputs(string, Darwin.stderr)
}
    }

    public struct StdoutStream: OutputStream {
        public func write(_ string: String) { fputs(string, Darwin.stdout)
}
    }

    public static var err = StderrStream()
    public static var out = StdoutStream()
}

So in use, it would look something like

str.write(to: &StdStream.out)
str.write(to: &StdStream.err)

I also considered DarwinStream (seemed too on the nose), UnixStream,
Streamfd, BSDStream, etc. Didn't like any of them.

-- E, have paintbrush will bikeshed


(David Hart) #12

It makes some sense:

- Each process has its own Input/Output/Error streams.
- Processes are piped through their streams.
- C# has `StandardError`, `StandardInput`, `StandardOutput` properties on the `Process` class.

On the other hand:

- Java has them defined on `System`
- Python is very similar to Java `sys.stdout`

···

On 11 Jul 2016, at 22:10, Xiaodi Wu via swift-evolution <swift-evolution@swift.org> wrote:

Sorry, I don't really see how these are related to "process". Can you explain?
On Mon, Jul 11, 2016 at 15:08 Zach Waldowski via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:
`Process` might be a good place for namespacing these. You'll also note that `print` can take an OutputStream to make this even more idiomatic. Straw man example at https://gist.github.com/zwaldowski/4ed2fd48da2af3193b0cbd3ec1883c9d.

Cheers!
  Zachary Waldowski
  zach@waldowski.me <mailto:zach@waldowski.me>

On Mon, Jul 11, 2016, at 12:24 PM, Erica Sadun via swift-evolution wrote:

Just throwing this here. Unfortunately `Stream` is already taken (and tied to Foundation).

public struct StdStream {
public struct StderrStream: OutputStream {
public func write(_ string: String) { fputs(string, Darwin.stderr) }
    }
    
public struct StdoutStream: OutputStream {
public func write(_ string: String) { fputs(string, Darwin.stdout) }
    }
    
public static var err = StderrStream()
public static var out = StdoutStream()
}

So in use, it would look something like

str.write(to: &StdStream.out)
str.write(to: &StdStream.err)

I also considered DarwinStream (seemed too on the nose), UnixStream, Streamfd, BSDStream, etc. Didn't like any of them.

-- E, have paintbrush will bikeshed

On Jul 11, 2016, at 12:58 PM, Saagar Jha via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:

Thanks, I’ll write it up.

On Jul 11, 2016, at 11:20, Dave Abrahams via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:

on Sun Jul 10 2016, Saagar Jha <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:

What is the process for smaller issues like these? I’m guessing that
this doesn’t need a proposal; where should it go? On bugs.swift.org <http://bugs.swift.org/>
<http://bugs.swift.org/>?

If it adds an API, it needs a proposal. Doesn't necessarily have to be
a big proposal, and the review period can be short, but we don't add
APIs without the evolution process.

Thanks,
Dave

--
Dave

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org <mailto:swift-evolution@swift.org>
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org <mailto:swift-evolution@swift.org>
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org <mailto:swift-evolution@swift.org>
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org <mailto:swift-evolution@swift.org>
https://lists.swift.org/mailman/listinfo/swift-evolution
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution