Julian and Henry (and Devon whose ideas extends Henry's, I think),

Both of your solutions seem to require 'a' not just a.
But still they might work for me.

My examples below are meant to show that I get to the 'Got here' line when
a is defined and its # is not zero.
I was hoping there was an easier way.

First is based on Henry's ifdefined and it works for me.
   ifundefined_z_ =: 0 > [: 4!:0 <
   tallyH =: monad define
if. ifundefined  'a'   do. return. end.
if.  0=#a do. return. end.
'Got here'
)
   erase<'a'
1
   tallyH ''
   #a =. i. 0
0
   tallyH ''
   #a =. i. 2 3
2
   tallyH ''
Got here


Next is tally based on Julian's idea, but I could not make it work. My bad.
   tallyJ =: monad define
try.  'a'~
catch. return. end.
if. 0=#a do. return. end.
'Got here'
)

   erase<'a'
1
   tallyJ''
|syntax error: tally
|       0=#a
   'a'~
|value error: a

Finally, here is an alternative of mine which seems to work, too.
   tallyB =: monad define
try. if. 0=#a do. return. end.
catch. return. end.
'Got here'
)

   a
|value error: a
   tallyB''
   a =. i. 0
   tallyB''
   a =. i. 2 3
   tallyB''
Got here



On Mon, Aug 3, 2020 at 1:07 PM Julian Fondren <jfond...@minimaltype.com>
wrote:

> On 2020-08-03 11:52, Brian Schott wrote:
> > This thread hints at a problem I am having.
> > In particular the link suggested by Henry
> > https://code.jsoftware.com/wiki/Vocabulary/ErrorMessages#value
> >
> > My problem is that I want to detect an error caused  by an undefined
> > noun
> > but my attempt does not produce the desired error using :: .
> > For example in the example below, although `a` is undefined, I do not
> > get
> > the desired result, 0, from my verb `tally` when I execute `tally a`.
> > How can I define tally to produce 0 for an undefined argument. Or how
> > do I
> > detect an undefined argument, in general? I have considered using a
> > try.
> > ... catch. in an explicit definition, but to me that seems unnecessary.
> >
> >    a
> > |value error: a
> >    tally =: # :: 0:
> >    tally i. 4
> > 4
> >    tally a
> > tally a
>
> Is it important to catch it interactively like this?
>
> If you're being given variable names from untrusted input that might
> be wrong, then you can evoke the names (m~) instead of doing them (".n)
> to get an error:
>
>     a =: i.5
>     'a'~
> 0 1 2 3 4
>     clear''
>     'a'~
> |value error: a
>
> >
> > On Wed, Nov 6, 2019 at 5:11 AM Henry Rich <henryhr...@gmail.com> wrote:
> >
> >> https://code.jsoftware.com/wiki/Vocabulary/ErrorMessages#value
> >>
> >> Henry Rich
> >>
> >> On 11/6/2019 4:26 AM, Arnab Chakraborty wrote:
> >> > Dear all,
> >> >
> >> >      Here is a behavior that I noticed only recently, and it puzzles
> me a
> >> > lot:
> >> >
> >> >    Let's say abc and xyz are not defined in my J session, and type
> just
> >> abc
> >> > by itself in a line. Of course, I get a value error. But if I type
> >> >
> >> > xyz abc
> >> >
> >> > then J does not produce any error, but simply echos back what I have
> >> typed!
> >> > I expected that J would start executing from the right, encounter abc,
> >> and
> >> > produce a value error. If I now define abc (say abc=. 0), then
> >> >
> >> > xyz abc
> >> >
> >> > produces a value error (expected) about xyz.
> >> >
> >> > But why does J become silent in presence of multiple undefined
> symbols?
> >>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>


-- 
(B=) <-----my sig
Brian Schott
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to