unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Difference between pipes and ports
@ 2021-08-11  1:14 Zelphir Kaltstahl
  2021-08-11  3:16 ` Mikael Djurfeldt
  0 siblings, 1 reply; 3+ messages in thread
From: Zelphir Kaltstahl @ 2021-08-11  1:14 UTC (permalink / raw)
  To: guile-user

Hello Guile users,

I recently came across
https://www.draketo.de/software/guile-capture-stdout-stderr.html
<https://www.draketo.de/software/guile-capture-stdout-stderr.html> and wrote a
commented version at
https://notabug.org/ZelphirKaltstahl/guile-examples/src/master/input-output/stdout-stderr.scm
<https://notabug.org/ZelphirKaltstahl/guile-examples/src/master/input-output/stdout-stderr.scm>.

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
https://www.gnu.org/software/guile/manual/html_node/Pipes.html
<https://www.gnu.org/software/guile/manual/html_node/Pipes.html> 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: https://notabug.org/ZelphirKaltstahl




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Difference between pipes and ports
  2021-08-11  1:14 Difference between pipes and ports Zelphir Kaltstahl
@ 2021-08-11  3:16 ` Mikael Djurfeldt
  2021-08-11  9:48   ` Zelphir Kaltstahl
  0 siblings, 1 reply; 3+ messages in thread
From: Mikael Djurfeldt @ 2021-08-11  3:16 UTC (permalink / raw)
  To: Zelphir Kaltstahl; +Cc: guile-user

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
opened.

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,
Mikael

Den ons 11 aug. 2021 03:14Zelphir Kaltstahl <zelphirkaltstahl@posteo.de>
skrev:

> Hello Guile users,
>
> I recently came across
> https://www.draketo.de/software/guile-capture-stdout-stderr.html
> <https://www.draketo.de/software/guile-capture-stdout-stderr.html> and
> wrote a
> commented version at
>
> https://notabug.org/ZelphirKaltstahl/guile-examples/src/master/input-output/stdout-stderr.scm
> <
> https://notabug.org/ZelphirKaltstahl/guile-examples/src/master/input-output/stdout-stderr.scm
> >.
>
> 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
> https://www.gnu.org/software/guile/manual/html_node/Pipes.html
> <https://www.gnu.org/software/guile/manual/html_node/Pipes.html> 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: https://notabug.org/ZelphirKaltstahl
>
>
>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Difference between pipes and ports
  2021-08-11  3:16 ` Mikael Djurfeldt
@ 2021-08-11  9:48   ` Zelphir Kaltstahl
  0 siblings, 0 replies; 3+ messages in thread
From: Zelphir Kaltstahl @ 2021-08-11  9:48 UTC (permalink / raw)
  To: mikael; +Cc: guile-user

Hello Mikael!

Thank you, that makes it clearer. Different levels of abstraction and pipes of
the OS level are represented as ports in Guile. I think I understand now. I
quite like the ports concept with its many uses.

Best regards,
Zelphir

On 8/11/21 5:16 AM, Mikael Djurfeldt wrote:
> 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 opened.
>
> 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,
> Mikael
>
> Den ons 11 aug. 2021 03:14Zelphir Kaltstahl <zelphirkaltstahl@posteo.de
> <mailto:zelphirkaltstahl@posteo.de>> skrev:
>
>     Hello Guile users,
>
>     I recently came across
>     https://www.draketo.de/software/guile-capture-stdout-stderr.html
>     <https://www.draketo.de/software/guile-capture-stdout-stderr.html>
>     <https://www.draketo.de/software/guile-capture-stdout-stderr.html
>     <https://www.draketo.de/software/guile-capture-stdout-stderr.html>> and
>     wrote a
>     commented version at
>     https://notabug.org/ZelphirKaltstahl/guile-examples/src/master/input-output/stdout-stderr.scm
>     <https://notabug.org/ZelphirKaltstahl/guile-examples/src/master/input-output/stdout-stderr.scm>
>     <https://notabug.org/ZelphirKaltstahl/guile-examples/src/master/input-output/stdout-stderr.scm
>     <https://notabug.org/ZelphirKaltstahl/guile-examples/src/master/input-output/stdout-stderr.scm>>.
>
>     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
>     https://www.gnu.org/software/guile/manual/html_node/Pipes.html
>     <https://www.gnu.org/software/guile/manual/html_node/Pipes.html>
>     <https://www.gnu.org/software/guile/manual/html_node/Pipes.html
>     <https://www.gnu.org/software/guile/manual/html_node/Pipes.html>> 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: https://notabug.org/ZelphirKaltstahl
>     <https://notabug.org/ZelphirKaltstahl>
>
>
-- 
repositories: https://notabug.org/ZelphirKaltstahl



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-08-11  9:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-11  1:14 Difference between pipes and ports Zelphir Kaltstahl
2021-08-11  3:16 ` Mikael Djurfeldt
2021-08-11  9:48   ` Zelphir Kaltstahl

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).