1. What do you mean by "an object is string"?
This might do it:
isString=: ' '= 1{.0{.,
But note that this approach ignores the number of dimensions of the
value (and don't get me started on "objects").
2. You can perform side effects to your heart's content, and you can
return a value like EMPTY if you do not want to see a value, if that's
what you are trying to do.
EMPTY
isString EMPTY
0
3. Try this:
fun=: dyad define
'num vec str'=. y
echo num
echo vec
echo str
sideeffect=: vec + num * isString str
EMPTY
)
'' fun 1;2 3 4;'string'
Thanks,
--
Raul
On Fri, Dec 1, 2017 at 8:04 PM, Dabrowski, Andrew John
<[email protected]> wrote:
> 1. How does one test whether an object is string?
>
> 2. I now know that J doesn't support nullary functions. It also seems
> that J doesn't allow functions that don't return any value (i.e. for the
> side effects), correct?
>
> 3. Suppose I want to define a dyadic function in which the y variable
> contains three values: a number, a vector, and a string. One way to do
> this would be to have y be a list of three boxes, say y = 13 ; 2 3 4 ;
> 'abcd' and parse y by
>
> fun =: dyad define
> 'num vec str' =. y
> num =. > num
> vec =. > vec
> str =. > str
> ...
> )
>
> Is this the idiomatic way to do it? Is there a better way?
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm