I guess you have to define the adverb 'in' beforehand otherwise J
interpreter will threat any undefined name as a verb when compiling an
expression.
'
Срд, 03 Ноя 2010, Ian Clark писал(а):
> Hi Ric,
>
> Thanks for helping to extend calc.ijs.
> I've been developing in parallel with yours, but have raided some of
> your verbs, which are neater than mine. The result is uploaded same
> place as yours (attachments: JinaDay) as: calcic2.ijs
>
> It has a full range of + - * / buttons, implemented with (verb):
> setop, which I feel is a little clunky. Out of interest I've tried a
> neater alternative, an adverb called: in, so I can use +in, -in, etc.
> It would be a nice demo of adverbs returning verbs. But I think I've
> hit a J bug...
>
> This works fine:
> calc_times_button=: doit
>
> ...where doit is defined, as in the script, _after_ the definition of: in as:
> doit =: *in
>
> But this doesn't (it upsets the gui somehow):
> calc_times_button=: * in
>
> Nor does this:
> doit =: *in
> calc_times_button=: doit
>
> Can you see what I'm doing wrong? I can't.
>
> Ian
>
>
> On Wed, Nov 3, 2010 at 1:10 AM, Sherlock, Ric <[email protected]>
> wrote:
> > Further update to calc2.ijs:
> >
> > Altered button order/layout.
> >
> > Moved NEWNUMBER=: 1 to update rather than repeating in each operation
> > button.
> >
> > Ends up highlighting another gotcha for new users:
> > If you define a verb whose result is a verb, adverb or conjunction then J
> > will report a syntax error when the verb runs. If no result is required
> > then a common solution is to add an extra line that returns "empty" (i.0 0)
> >
> >> From: Sherlock, Ric
> >> Sent: Wednesday, 3 November 2010 12:55
> >>
> >> Yes, when I got around to testing in a clean session I had noticed that
> >> too.
> >> The latest version on the wiki initializes them.
> >>
> >> > From: Ian Clark
> >> > Sent: Wednesday, 3 November 2010 12:52
> >> >
> >> > I get value errors for op and acc on starting up, unless I initialise
> >> > them in calc_run.
> >> >
> >> > On Tue, Nov 2, 2010 at 9:55 PM, Sherlock, Ric
> >> > <[email protected]> wrote:
> >> > > I've made some more "improvements" to calc2.ijs. Includes "-"
> >> button.
> >> > > Adding additional operations should be trival.
> >> > > Renamed the verb "clear" to "clr" so that clear_z_ is still easily
> >> > useable.
> >> > >
> >> > > I use the TortoiseMerge app to do diffs between similar versions of
> >> a
> >> > script. I'm sure you have your own favourite.
> >> > >
> >> > > Ric
> >> > >
> >> > >> From: Of Ian Clark
> >> > >> Sent: Tuesday, 2 November 2010 17:12
> >> > >>
> >> > >> Thanks for calc2, Ric.
> >> > >>
> >> > >> I'll have to study it closely because it's much like my own
> >> > extension,
> >> > >> but not exactly so.
> >> > >>
> >> > >> I also feel that buttons for the remaining ops are needed now, and
> >> > >> that this needn't complicate the demo too much. In fact with the
> >> use
> >> > >> of 'bind' (and I was confusing 'bind' and Bond but you didn't say
> >> > >> anything) my demo has become if anything too simple to illustrate
> >> > what
> >> > >> I originally wanted to.
> >> > >>
> >> > >> Ian
> >> > >>
> >> > >>
> >> > >> On Tue, Nov 2, 2010 at 2:15 AM, Sherlock, Ric
> >> > >> <[email protected]> wrote:
> >> > >> >> From: Ian Clark
> >> > >> >> Sent: Tuesday, 2 November 2010 09:33
> >> > >> >>
> >> > >> >> > I agreed with Brian that I missed the "equals" button in the
> >> > >> original
> >> > >> >> calc.ijs. Now I miss the "plus" button. It seems unintuitive to
> >> > >> press
> >> > >> >> "=" when you want to add.
> >> > >> >>
> >> > >> >> Hahaha! (Can't please everybody.) Can I interest you in a more
> >> > >> >> advanced calculator? It's called J ... :-)
> >> > >> >>
> >> > >> >> I'm just glad I wasn't on the design team of the original
> >> pocket
> >> > >> >> calculator. It's subtler than it looks.
> >> > >> >>
> >> > >> >> Providing both '+' and '=' buttons means adding a whole row or
> >> > >> column
> >> > >> >> of buttons or it looks untidy. I've a calc with the
> >> conventional
> >> > >> >> look'n'feel -- but IMO it's too complex to serve as a good
> >> demo.
> >> > >> >>
> >> > >> >
> >> > >> > I've attached an alternative layout to the JinaDay wiki page
> >> > (named
> >> > >> calc2.ijs) that includes separate '=' and '+' buttons. There are
> >> > also
> >> > >> some minor changes to some of the verbs to make it work more like
> >> my
> >> > >> calculator and make it easier for users to add other operation
> >> > buttons.
> >> > >> See if you think that works/looks OK.
> >> > >> >
> >> > >> >> > The current phrasing of your "blasphemous comment" has more
> >> > impact
> >> > >> >> but I get the feeling that your actual message is more like:
> >> > "There
> >> > >> is
> >> > >> >> no need to get your head around tacit definition". The fact is
> >> > that
> >> > >> >> many of the button handlers in the calc script use tacit code!
> >> I
> >> > >> >> suppose it comes down to whether you think that being
> >> provocative
> >> > >> >> rather than reassuring will help get your message across best.
> >> > >> >>
> >> > >> >> "Here Be Dragons..."
> >> > >> >>
> >> > >> >> I meant to be reassuring by being provocative. Reassuring (to
> >> > >> APLers)
> >> > >> >> by being (or, rather, risking being) provocative to J-ers.
> >> > >> >>
> >> > >> >> De-mystifying a topic is never free from the insinuation that
> >> the
> >> > >> >> mystery is intentional: or at the very least, serving someone's
> >> > >> >> purpose. People are quite smart, you know. If a mystery serves
> >> no
> >> > >> >> purpose -- or no one's purpose -- it soon gets cleared up. It
> >> > >> follows
> >> > >> >> that de-mystification is apt be viewed as de-bunking.
> >> > >> >>
> >> > >> >> It wasn't my intention to debunk. Simply to cast some light.
> >> > Maybe
> >> > >> to
> >> > >> >> let in some fresh air.
> >> > >> >>
> >> > >> >> On first encountering APL my initial response was to feel
> >> > >> inadequate.
> >> > >> >> I should have felt humble, but instead I felt humiliated.
> >> Because
> >> > at
> >> > >> >> the time I was masquerading as a "computer scientist", ie an
> >> > expert.
> >> > >> >> This was back in 1973, when the industry was less fragmented.
> >> It
> >> > was
> >> > >> >> "IBM and the Seven Dwarfs" -- and I was IBM.
> >> > >> >>
> >> > >> >> So I looked for holes. For excuses to label APL as mad, not
> >> > >> brilliant.
> >> > >> >> Then I'd be exposed as sane, not stupid. It reassured me to
> >> swap
> >> > sly
> >> > >> >> remarks about the language, especially as others felt the same
> >> as
> >> > I.
> >> > >> >>
> >> > >> >> On first encountering J, I experienced the selfsame feeling I
> >> had
> >> > on
> >> > >> >> first meeting APL. It largely revolved around "tacit
> >> > programming".
> >> > >> >> Attempts by those who'd Seen The Light to motivate me by saying
> >> > >> "it's
> >> > >> >> really quite easy" -- or -- "it's far better than APL doing it
> >> > this
> >> > >> >> way" simply provoked hostility. And not just in me, I observed.
> >> > >> >>
> >> > >> >> So there was a barrier to surmount, before I could contemplate
> >> J
> >> > >> >> equably, let alone consider using it myself for a serious task.
> >> > >> >>
> >> > >> >> Tacit programming _isn't_ "really quite easy". In principle,
> >> > >> maybe...
> >> > >> >> But in practice it's as much a strain as coding in 68000 ASM.
> >> > (Yes,
> >> > >> >> done that -- and sold the result).
> >> > >> >>
> >> > >> >> And that, I think, is the way to look at it. Those who can do
> >> it
> >> > can
> >> > >> >> justly be proud of their skill. But nobody is ashamed of not
> >> > being
> >> > >> >> able to compose 68000 machine code in their heads without
> >> > computer
> >> > >> >> assistance, so why should they be when it's tacit J?
> >> > >> >>
> >> > >> >> There is this difference. Machine-code is best kept beneath the
> >> > >> >> covers. But tacit J beneficially seeps out. As you observe,
> >> > there's
> >> > >> >> tacit code in calc.ijs.
> >> > >> >>
> >> > >> >> IMO the issue over tacit J is not whether we should banish
> >> > (digit&1)
> >> > >> >> from calc.ijs, but whether we should aim to make novices
> >> ashamed
> >> > of
> >> > >> >> writing:
> >> > >> >> quo=: 3 : 'Q,(":>y),Q' NB. place datum in quotes
> >> > >> >> instead of:
> >> > >> >> quo=: Q , Q ,~ [: ": >
> >> > >> >> because that, I think, has been counter-productive.
> >> > >> >>
> >> > >> >> They'll do so in the end... and like as not they won't know
> >> > they're
> >> > >> >> doing it.
> >> > >> >
> >> > >> > I agree that it is counterproductive to denigrate the use of
> >> > explicit
> >> > >> definition. I don't think that happens really, although I know
> >> that
> >> > a
> >> > >> lot of code on the forums is tacit. As I said recently on
> >> > comp.lang.apl
> >> > >> I think this is really just a side effect of more experienced
> >> users
> >> > >> thinking and working more in tacit mode.
> >> > >> >
> >> > >> > I remember when I started learning J that I pretty much
> >> "ignored"
> >> > >> trying to create tacit verbs - I was content to stick with
> >> explicit.
> >> > I
> >> > >> found the tacit code on the forum hard to read/understand. I think
> >> > my
> >> > >> biggest hurdle in coming to terms with tacit was being able to
> >> > reliably
> >> > >> identify the parts of speech for J's various primitives (verb vs
> >> > adverb
> >> > >> vs conjunction). Without that knowledge it is hard to identify the
> >> > >> composed verbs and correctly separate the hooks from the forks. As
> >> I
> >> > >> learnt the J primitives and their parts of speech, suddently tacit
> >> > >> didn't seem so hard after all, and now I find myself using it in
> >> > >> preference to explicit for many sentences.
> >> > >> >
> >> > >> > Having said that I'd be more inclined to promote the use this
> >> form
> >> > >> than the one liner string form above. Otherwise things can get
> >> messy
> >> > >> when dealing with strings.
> >> > >> > quo=: 3 : 0
> >> > >> > Q,(":>y),Q
> >> > >> > )
> >> > >> >
> >> > >> > Ric
> >> > >> > ----------------------------------------------------------------
> >> --
> >> > ---
> >> > >> -
> >> > >> > For information about J forums see
> >> > >> http://www.jsoftware.com/forums.htm
> >> > >> >
> >> > >> ------------------------------------------------------------------
> >> --
> >> > --
> >> > >> For information about J forums see
> >> > http://www.jsoftware.com/forums.htm
> >> > > -------------------------------------------------------------------
> >> --
> >> > -
> >> > > For information about J forums see
> >> > http://www.jsoftware.com/forums.htm
> >> > >
> >> > ---------------------------------------------------------------------
> >> -
> >> > For information about J forums see
> >> http://www.jsoftware.com/forums.htm
> >> ----------------------------------------------------------------------
> >> For information about J forums see http://www.jsoftware.com/forums.htm
> > ----------------------------------------------------------------------
> > For information about J forums see http://www.jsoftware.com/forums.htm
> >
> NB. elementary calculator demo
> NB. by Ian Clark and
>
> NB. a slightly more elaborate form of: calc.ijs
>
> cocurrent 'calc'
> erase names''
>
> CALC=: noun define
> pc calc;
> xywh 30 125 30 12;cc cancel button;cn "Quit";
> xywh 4 5 80 12;cc result edit;
> xywh 5 20 18 18;cc func1 button;cn "?";
> xywh 25 20 18 18;cc func2 button;cn "?";
> xywh 45 20 18 18;cc func3 button;cn "?";
> xywh 65 20 18 18;cc divid button;cn "/";
> xywh 5 40 18 18;cc num7 button;cn "7";
> xywh 25 40 18 18;cc num8 button;cn "8";
> xywh 45 40 18 18;cc num9 button;cn "9";
> xywh 65 40 18 18;cc times button;cn "X";
> xywh 5 60 18 18;cc num4 button;cn "4";
> xywh 25 60 18 18;cc num5 button;cn "5";
> xywh 45 60 18 18;cc num6 button;cn "6";
> xywh 65 60 18 18;cc minus button;cn "-";
> xywh 5 80 18 18;cc num1 button;cn "1";
> xywh 25 80 18 18;cc num2 button;cn "2";
> xywh 45 80 18 18;cc num3 button;cn "3";
> xywh 65 80 18 18;cc plus button;cn "+";
> xywh 5 100 18 18;cc num0 button;cn "0";
> xywh 25 100 18 18;cc dott button;cn ".";
> xywh 45 100 18 18;cc clear button;cn "C";
> xywh 65 100 18 18;cc equal button;cn "=";
> pas 6 6;pcenter;
> rem form end;
> )
>
> calc_cancel_button=: calc_close
> NB. ...handlers can be just assigned.
> calc_clear_button=: clr
> calc_equal_button=: equals
> calc_plus_button=: setop bind '+'
> calc_minus_button=: setop bind '-'
> calc_times_button=: doit NB. --but won't work with: (*in)
> calc_divid_button=: setop bind '%'
> calc_dott_button=: dotted
> calc_num1_button=: digit bind 1
> calc_num2_button=: digit bind 2
> calc_num3_button=: digit bind 3
> calc_num4_button=: digit bind 4
> calc_num5_button=: digit bind 5
> calc_num6_button=: digit bind 6
> calc_num7_button=: digit bind 7
> calc_num8_button=: digit bind 8
> calc_num9_button=: digit bind 9
> calc_num0_button=: digit bind 0
>
> NB. Original run/close verbs (*--they've been altered!)
>
> calc_run=: verb define
> calc_close''
> wd CALC
> NB. initialize form here
> op =: +
> acc=: 0
> clr''
> wd 'setreadonly result;'
> NB. next line is RGB for: text bkgnd bkgnd --enable if reqd
> NB. wd 'setcolor result 255 128 128 0 0 0 0 0 0;'
> wd 'pshow;'
> )
>
> calc_close=: verb define
> wd ::0: 'psel calc; pclose;' NB. failsafe version
> )
>
> NB. More fns (in alphabetical order)
>
> clr=: verb define
> update '0'
> op=: +
> NEWNUMBER=: 1
> )
>
> decimal=: verb define
> NB. converts number being built to a valid decimal
> NB. y -- numeral in a string (eg as in
> if. 0=#y do. y=. '0.' end.
> if. '.' e. y do. y else. y,'.' end.
> )
>
> digit=: verb define
> d=. {. ":y
> if. NEWNUMBER do. result=: '' [ NEWNUMBER=: 0 end.
> put result,d
> )
>
> dotted=: verb define
> if. NEWNUMBER do. result=: '' [ NEWNUMBER=: 0 end.
> put decimal result
> )
>
> equals=: monad define
> update result
> acc=: 0
> op=: +
> NB. NEWNUMBER=: 1 NB. else acc is cleared if new digit typed after =
> empty''
> )
>
> eval=: verb define
> ". y
> )
>
> NB. Equivalent 1-liner defining verb: eval ...
> NB. eval=: 3 : '". ''0'',y'
> NB. Tacit definition of verb: eval ...
> NB. eval=: [: ". '0' , ]
>
> put=: verb define
> wd 'set result *',y
> )
>
> NB. HANDLER EXPERIMENT...
> in=: adverb define
> update result
> op=: u
> NB. trace'in'
> NEWNUMBER=: 1
> empty y NB. y must be mentioned for this to work!
> )
>
> doit=: *in
> NB. END OF HANDLER EXPERIMENT
>
> setop=: verb define
> NB. y=right arg: arithmetic op (scalar char)
> update result
> select. y
> case. '+' do. op=: +
> case. '-' do. op=: -
> case. '*' do. op=: *
> case. '%' do. op=: %
> end.
> trace'setop'
> NEWNUMBER=: 1
> )
>
> trace=: verb define
> OP=. 5!:5 <'op'
> smoutput y ; 'acc' ; acc ; 'op' ; OP ; 'result' ; result ; 'NEWNUMBER' ;
> NEWNUMBER
> )
>
> update=: verb define
> z=. ": acc=: acc op eval y
> put '-' (I. z='_') }z
> )
>
> calc_run''
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
--
regards,
====================================================
GPG key 1024D/4434BAB3 2008-08-24
gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm