[Jprogramming] Tacit argument checking
Roger Hui
rhui000 at shaw.ca
Tue May 26 23:10:01 HKT 2009
http://www.jsoftware.com/jwiki/Essays/The%20Ball%20Clock%20Problem
assert=: 13!:8@(12"_)^:-.
Addition effects can be obtained by composition with [ or ]
----- Original Message -----
From: Henry Rich <HenryHRich at nc.rr.com>
Date: Tuesday, May 26, 2009 7:46
Subject: Re: [Jprogramming] Tacit argument checking
To: Programming forum <programming at jsoftware.com>
> Viktor's way is OK, but I have had performance trouble with `@.
> especially on rank 0.
>
> I would use
>
> ^.@:([:^:(errorcondition))"0
>
> or, better, if you don't need the verb to be rank 0,
>
> ^.@([:^:(errorcondition))
>
> where you can do everything on arrays
>
> errorcondition =. 0&>: +. _&<: +. 0 ~: 11&o. NB. scalar
> errorcondition =. [: +./@, 0&>: +. _&<: +. 0 ~: 11&o.
> NB. array
>
> If you want a custom error, use 13!:8 instead of [:
>
> untested.
>
> Henry Rich
>
>
> Kip Murray wrote:
> > How do you check arguments for a tacit verb? Say it's
> monadic"0 and I
> > want the argument to be real and positive excluding _
> (infinity). If
> > no, halt with an error message; if yes, process the argument,
> say take
> > the natural logarithm. /Kip Murray
More information about the Programming
mailing list