[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Difference between pipes and ports

From: Mikael Djurfeldt
Subject: Re: Difference between pipes and ports
Date: Wed, 11 Aug 2021 05:16:40 +0200

Hi Zelphir!

A port is a scheme level concept which represents input and output devices.

Stdin, stdout and stderr are file descriptors which is an OS level concept.

A pipe is also an OS level concept. It is a communication stream between
two processes. In the OS, it is represented as a file descriptor once

The function open-input-pipe creates a child process and opens a pipe from
it. In the OS, the pipe is represented as a file descriptor. This is
represented as a port at the scheme level.

In Guile, this port also has some extra information: It has a type, #{read
pipe}, and also carries (i believe) some extra information, such as the
process identifier of the child process.

Best regards,

Den ons 11 aug. 2021 03:14Zelphir Kaltstahl <>

> Hello Guile users,
> I recently came across
> <> and
> wrote a
> commented version at
> <
> >.
> While looking at the code, I was starting to wonder, what the difference
> between
> a pipe and a port is. The reference manual does not say much about any
> definition of what a pipe is at
> <> and pipe
> procedure return values are also named port.
> However, in the REPL, they look not the same:
> ~~~~
> scheme@(guile-user)> (import (ice-9 popen))
> scheme@(guile-user)> (open-input-pipe "ls -al")
> $2 = #<input: #{read pipe}# 13>
> ~~~~
> And here for ports:
> ~~~~
> scheme@(guile-user)> (call-with-output-string
>                        (λ (port)
>                          (display port)))
> #<output: file 7fa2a99471c0>$6 = ""
> ~~~~
> Is a pipe just a special kind of port? Does it wrap a port? Or is it
> perhaps
> merely a different terminology used in different contexts in the reference
> manual?
> Best regards,
> Zelphir
> --
> repositories:

reply via email to

[Prev in Thread] Current Thread [Next in Thread]