From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id 64D1C7EEBF for ; Thu, 6 Aug 2015 21:51:33 +0200 (CEST) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of mmatalka@gmail.com) identity=pra; client-ip=209.85.212.182; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="mmatalka@gmail.com"; x-sender="mmatalka@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of mmatalka@gmail.com designates 209.85.212.182 as permitted sender) identity=mailfrom; client-ip=209.85.212.182; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="mmatalka@gmail.com"; x-sender="mmatalka@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-wi0-f182.google.com) identity=helo; client-ip=209.85.212.182; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="mmatalka@gmail.com"; x-sender="postmaster@mail-wi0-f182.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0DHAAD+ucNVm7bUVdFbhEkPxRwCgUhMAQEBAQEBEgEBAQEBBgsLCSEuhCQBAQMBEhUZARsdAQMBCwYFCxYlDwEEDQIRAQUBIhMih3YBAwoIBAGqMIEuPjGNK4J5i0UKGScNV4RVAQEBAQEFAQEBAQEBFgEFDoRLhnaCT4I6B4QsBZUBimyBa4hQiW6FZTWBFxeEDG8BgksBAQE X-IPAS-Result: A0DHAAD+ucNVm7bUVdFbhEkPxRwCgUhMAQEBAQEBEgEBAQEBBgsLCSEuhCQBAQMBEhUZARsdAQMBCwYFCxYlDwEEDQIRAQUBIhMih3YBAwoIBAGqMIEuPjGNK4J5i0UKGScNV4RVAQEBAQEFAQEBAQEBFgEFDoRLhnaCT4I6B4QsBZUBimyBa4hQiW6FZTWBFxeEDG8BgksBAQE X-IronPort-AV: E=Sophos;i="5.15,624,1432591200"; d="scan'208";a="172892694" Received: from mail-wi0-f182.google.com ([209.85.212.182]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 06 Aug 2015 21:51:33 +0200 Received: by wibxm9 with SMTP id xm9so38303647wib.1 for ; Thu, 06 Aug 2015 12:51:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-type; bh=KzOQWD4YYerEXLuAauOcdAwX9B6RU2Qz052NJaPse7A=; b=Np6X+eOuDMFOm/UB7z2gvhtT3giib8A+wRX2LZNF3/dgGaJUBt2v+/UDUSKlyJ+mMI b4ilB/NHhwEdPqhrG7RWNYuLk8oj5O2VGZlHrQFNDkP1CvDq2YBDlBH7UhSc4TbEwE+P tNrqJsOfCnOEL/gzHk0OyIDfOFryxhI2y3WOsTI4d/cg2NhrdFmOCBMp9fnca50I9GEh WSNPLfXHwzrWvmhxlK+YV7g2dEbqz2WaLfGjMfYWXs2GTlj27NDmu7q2sVcQzISqgqIo uWQw7yik7iwS3K82psC8lazT6c4vMp4eQsRewi2D+uU5YY6OJ+jkwGWP/3GYTzRF5r/R 9hpw== X-Received: by 10.180.218.227 with SMTP id pj3mr9280373wic.59.1438890692840; Thu, 06 Aug 2015 12:51:32 -0700 (PDT) Received: from localhost (li195-236.members.linode.com. [178.79.139.236]) by smtp.gmail.com with ESMTPSA id yu4sm11026206wjc.43.2015.08.06.12.51.32 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Aug 2015 12:51:32 -0700 (PDT) From: Malcolm Matalka To: Nicolas Ojeda Bar Cc: Goswin von Brederlow , caml-list@inria.fr References: <20150806094030.GE16477@frosties> Date: Thu, 06 Aug 2015 19:50:38 +0000 In-Reply-To: (Nicolas Ojeda Bar's message of "Thu, 6 Aug 2015 11:48:07 +0200") Message-ID: <864mkcci29.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (berkeley-unix) MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Caml-list] Destructive use of file descriptors Nicolas Ojeda Bar writes: > Hi, > > No magic needed in OCaml: > > let with_open path f = > let oc = open_out path in > match f oc with > | x -> close_out_noerr oc; x > | exception e -> close_out_noerr oc; raise e > > and then use it as > > with_open "foo" (fun oc -> output_string oc str) > > Cheers > > Nicolas > The weakness with this (which I'm not sure if Python offers protection) is returning something that references the file created. It can lead to some confusing error messages.