caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Alessandro Baretta <a.baretta@barettadeit.com>
To: Florian Hars <hars@bik-gmbh.de>
Cc: Hendrik Tews <tews@tcs.inf.tu-dresden.de>, Ocaml <caml-list@inria.fr>
Subject: Re: [Caml-list] Camlp4 in a Unix pipe
Date: Wed, 23 Nov 2005 12:27:39 +0100	[thread overview]
Message-ID: <4384522B.3010309@barettadeit.com> (raw)
In-Reply-To: <4383605A.7030309@bik-gmbh.de>

Florian Hars wrote:
> Alessandro Baretta wrote:
> 
>> Cool command line! How did you discover the '-' option? 
> 
> 
> Out of habit? In the the unix shell monad, "foo >>= bar" happens to be 
> written
> as "foo | bar -" ("return" is written "cat", in case you wondered. So "Hey,
> that is a useless use of cat!" really means 'Hey, you ignored the monad 
> laws!")
> 
> Yours, Florian (time to go home, I know).
> 

I'm not sure I understand your point.

My original attempt at this problem was the following:

cat - | camlp4 pa_o.cmo pr_o.cmo

but it did not work: here's what happens.

alex@alex:~/void$ cat - | camlp4 pa_o.cmo pr_r.cmo
let 1 = 1;;
alex@alex:~/void$

Nothing at all. This seemed strange to me, because, according the camlp4 manpage

> DESCRIPTION
>        camlp4  is  a  Pre-Processor-Pretty-Printer for OCaml, parsing a source
>        file and printing some result on standard output.

I would expect to see the result of camlp4 actions somewhere. But, apparently, 
although camlp4 uses stdout as its default output descriptor, it does not use 
stdin as its default input descriptor. Hence, the following attempt:

alex@alex:~/void$ cat - | camlp4 pa_o.cmo pr_r.cmo -impl /dev/stdin
let 1 = 1;;
I/O error: Illegal seek
alex@alex:~/void$

Here, I tried to force camlp4 to explicitely use stdin as its input file. I have 
no clue as why campl4 would use the Unix.seek syscall on this descriptor, but 
apparently it does, and this fails if it is a pipe. Given the described 
experience, I am completely bewildered by the fact that Hendrik's proposal 
works, yet it does.

alex@alex:~/void$ cat - | camlp4 pa_o.cmo pr_r.cmo -impl -
let 1 = 1;;
value _ = match 1 with [ 1 -> () ];
alex@alex:~/void$

The '-' option to camlp4 is undocumented, as far as I can see from the camlp4 
manpage, so I was asking Hendrik to explain to me where he found this clue. 
Also, if '-' means to read from stdin, as is the case with many command line 
tools, why should this work any better than reading from /dev/stdin?

Alex


  reply	other threads:[~2005-11-23 11:27 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-17 14:20 Alessandro Baretta
2005-11-21  9:39 ` [Caml-list] " Hendrik Tews
2005-11-22 16:42   ` Alessandro Baretta
2005-11-22 18:15     ` Florian Hars
2005-11-23 11:27       ` Alessandro Baretta [this message]
2005-11-24 11:30         ` Hendrik Tews
2005-11-22 22:34     ` Christophe Raffalli
2005-11-23  9:05     ` Hendrik Tews

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4384522B.3010309@barettadeit.com \
    --to=a.baretta@barettadeit.com \
    --cc=caml-list@inria.fr \
    --cc=hars@bik-gmbh.de \
    --cc=tews@tcs.inf.tu-dresden.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).