bug-apl
[Top][All Lists]
Advanced

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

Re: [Bug-apl] Error handling and IO


From: Kacper Gutowski
Subject: Re: [Bug-apl] Error handling and IO
Date: Tue, 12 Apr 2016 02:10:52 +0200

If I understand correctly, Elias wants to have something that would
ensure that every file opened is eventually closed (only more general so
it can be applied to any external resources not only files).  That is in
a code similar to the following, to ensure the line 3 is always run even
if there's an error in FUN.

[1] FD←⎕FIO[3]STH
[2] FUN FD
[3] ⎕FIO[4]FD

This can be ensured by wrapping FUN call with ⎕EA or ⎕EC.  They return
to the caller instead of suspending execution if error happens and this
is correct and expected behaviour.  But the intention is to have the
file closed, not making the function unsuspendable, so this would be
a side effect of the solution of using ⎕EA rather than the intended
behaviour.  But this doesn't mean there's anything wrong with ⎕EA or
⎕EC, of course.

My understanding is that requested is some way to associate some kind of
clean up code with )SI entry that would be run upon that entry being
cleared from )SI regardless of how that happens.

The way I imagine it, it could look like this (using an imaginary
function ‘defer’ with a name borrowed from Golang; not an actual
transcript):

      ∇ FOO
[1] FD←⎕FIO[3]STH
[2] defer '⎕FIO[4]FD'
[3] FUN FD
[4] other stuff ∇

      STH←'filename'
      ⎕FX 'FUN F' '1+'

      FOO
SYNTAX ERROR
FUN[1]  1+
        ^^
      ⍝ here situation can be examined
      )VARS
F   FD
      )SIS
FUN[1]  1+
        ^^
FOO[3]  FUN FD
        ^
⋆  FOO
   ^
      →
      ⍝ here ⎕FIO[4]FD is executed

-k



reply via email to

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