From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 4B3F0BB9C for ; Wed, 23 Nov 2005 12:27:43 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id jANBRgGT028305 for ; Wed, 23 Nov 2005 12:27:42 +0100 Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id MAA01913 for ; Wed, 23 Nov 2005 12:27:42 +0100 (MET) Received: from mail.barettadeit.com (h213-255-109-130.albacom.net [213.255.109.130] (may be forged)) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id jANBRejm019899 for ; Wed, 23 Nov 2005 12:27:41 +0100 Received: from [10.1.0.20] (unknown [10.1.0.20]) by mail.barettadeit.com (Postfix) with ESMTP id 7FE8F354293; Wed, 23 Nov 2005 12:27:37 +0100 (CET) Message-ID: <4384522B.3010309@barettadeit.com> Date: Wed, 23 Nov 2005 12:27:39 +0100 From: Alessandro Baretta User-Agent: Debian Thunderbird 1.0.7 (X11/20051017) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Florian Hars Cc: Hendrik Tews , Ocaml Subject: Re: [Caml-list] Camlp4 in a Unix pipe References: <437C91B0.9030507@barettadeit.com> <43834A5C.3050109@barettadeit.com> <4383605A.7030309@bik-gmbh.de> In-Reply-To: <4383605A.7030309@bik-gmbh.de> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 4384522E.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 4384522C.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; baretta:01 baretta:01 barettadeit:01 caml-list:01 camlp:01 hars:01 foo:01 foo:01 camlp:01 cmo:01 cmo:01 manpage:01 ocaml:01 parsing:01 stdout:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.1 required=5.0 tests=FORGED_RCVD_HELO autolearn=disabled version=3.0.3 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