|
From: | Juergen Sauermann |
Subject: | Re: [Bug-apl] Error handling and IO |
Date: | Tue, 21 Jun 2016 16:57:11 +0200 |
User-agent: | Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 |
Hi coming back to an earlier discussion, I have added ⎕EB ("Execute Both") to GNU APL. A ⎕EB B is similiar to A ⎕EA B in that it first executes B. However, unlike ⎕EA which executes A only when B fails, ⎕EB always executes A regardless of failures in B. For example: '⎕←"CLEAN-UP"' ⎕EB '⍳4' CLEAN-UP 1 2 3 4 '⎕←"CLEAN-UP"' ⎕EB '⍳4.5' CLEAN-UP DOMAIN ERROR '⎕←"CLEAN-UP"' μ-Z__A_Quad_EB_B '⍳4.5' ^ ^ SVN 750. All EOC stuff is gone now. /// Jürgen Elias Mårtenson <address@hidden> writes: Yesterday, I participated in the Google Code Jam (programming competition). For one of the tasks, APL was a very good fit. The question is here: https://code.google.com/codejam/contest/6254486/dashboard#s=p1 My solution (which I will not post right now, since one of you might want to give it a shot first) was terse and simple. A very simple APL _expression_. However, reading the input a file and formatting the result took many lines of very ugly code. This attempt at using APL to solve a real-world programming problem illustrated two separate issues that, needs to be handled: Firstly, the FILE_IO library is way too low-level. For example, in the Codejam tasks, one usually have to read a whitespace-limited sequence of numbers. When I solve the problems in Lisp, all I need to do is to call READ. A flextible IO probrary that makes these kinds of this simple would be nice. I could (and indeed have considered to) write such functions in APL, but this causes a second problem: Error handling in GNU APL is very bad. In particular, there is nothing similar to UNWIND-PROTECT (or try/finally in Java). There is no way to safely write code that opens a file, works on it and then closes it. If an error occurs, there is no way to ensure that the filehandle is closed. When I developed my solution to the Codejam problem, I ended up leaking a lot of file handles. Does anyone know how Dyalog and other vendors handle this? Do they have a full exception system? Regards, Elias |
[Prev in Thread] | Current Thread | [Next in Thread] |