|
From: | Elias Mårtenson |
Subject: | Re: [Bug-apl] Error handling and IO |
Date: | Mon, 11 Apr 2016 11:27:45 +0800 |
Hi,
In Dyalog APL there is a mechanism similar to try/catch in other
languages:
R←f X
:Trap 0
R←1÷X
:Else
⎕←'Error happened'
R←0
:EndTrap
f 0
Error happened
0
For details see the Mastering Dyalog Apl
(http://www.dyalog.com/uploads/documents/MasteringDyalogAPL.pdf) Chapter M: Event Handling
--
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
>
Br,
/Alexey
[Prev in Thread] | Current Thread | [Next in Thread] |