On Fri, Mar 26, 2010 at 2:52 PM, Sprague, Webb (OFM)
<[email protected]> wrote:
> readfile =: 3 : 0
>        if. fexist y do.
>                out .= fread y
>        else.
>                ('readfile: ', y, ' does not exist')
>                this_is_supposed_to_bomb .=
>        end.
>        out
> )

This has several problems.

out .= probably does not do what you think it does.
You probably meant out=.

The line
   ('readfile: ', y, ' does not exist')
would produce a value which is ignored since it is not the
last line to be executed (and an error would ignore any
produced value).

The line
   this_is_supposed_to_bomb .=
is syntactically invalid, which prevents the function from executing.

Here is a variation which I think will do what you want:

readfile =: 3 : 0
       if. fexist y do.
              fread y
       else.
              ('readfile: ', y, ' does not exist') 13!:8(24)
       end.
)

Note that 24 is the error number which corresponds to
'file name error', which was my best guess as to the
error semantics you were after.  But, of course, the
message you get from this error is the one supplied on
the left of 13!:8.

Note that I did not bother with an 'out' variable, since
the fread will be the last executed line...

FYI,

-- 
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to