The verb round, using under, can't be written tacitly, because tacit verbs
can only compose and manipulate nouns, but using under tacitly would
require round to compose and use a verb.  In particular, the right argument
to &.: must be a monadic verb, and in the case of round the value of that
verb depends on the arguments to round (the left argument of round must be
bonded to the dyad % to produce the monad x&%, whence passed to &.:). Now,
there are ways to achieve this (essentially, writing a tacit verb that
first generates and then executes another tacit verb), but none are
satisfying in this case [1]. 

But an adverb is a whole different kettle of fish.  Adverbs can easily
generate verbs (that's their primary use), and J offers a number of tools
to write adverbs tacitly.  The most important are the bonded conjunction
and adverb trains.  And in this case, that's all we require:

           Round =: (%&) (<.@:(1r2+])&.:) 
        
           assert 1 -: Round 1.2
           assert 1.25 -: 0.25 Round 1.2

I've always liked bonded conjunctions because normal J programming
conditions us to expect a noun when we encounter, for example, %& .  Seeing
the bonded conjunction just bare like that is a bit startling: it looks
incomplete.  Subconsciously, we wonder "what's missing? what should go
there?", and then realize /the code/ is asking /us/.  In other words, a
bonded conjunction is a code template, and it looks like it [2].  Similarly
for adverb trains:  +/\ is "running sum" and */\ is "running product" and
/\ is just "running".

However, in more complex adverbs, these elegant patterns sometimes break
down.  For example, because of J's precedence rules, tacit adverbs often
have to be written "backwards", and Round is an victim of this effect.
Notice that in round (the desired tacit verb), %&x is on the right, but in
Round (the tacit adverb), it's on the left.

Anyway, for a slightly more detailed guide to writing tacit adverbs, check
out http://www.jsoftware.com/pipermail/programming/2010-
November/021172.html  .

-Dan

[1]  Tacit verbs can produce any effect, but if the actual structure of a
production (a sentence to be executed) depends on its own arguments, we
might have to produce it through dynamic program generation and evaluation.


For example, in this case, we could write:

           round =: ('<.@:(1r2+])&.:(%&' , ":@[ , ')'"_) 128!:2 ]
           1.25 -: 0.25 round  1.2
        1

or a moral equivalent (e.g. gerund construction and execution through `:6
or @. or ^: etc).   

But then, the simplest moral equivalent is the original, explicit 4 :
'<.@:(1r2+])&.:(%&x) y'  . After all, substituting values into J code
templates is what explicit programming is all about.  If a tacit verb needs
to quote as much code as the explicit equivalent, then it's no simpler or
more elegant (in fact, it's likely uglier and more complicated), so you
might as well write it explicitly in the first place.

That said, finding sneaky tricks to write such things tacitly can be fun!

[2] Speaking of code templates, another good example of a bonded
conjunction which seems almost to plead for an argument is  D.1  , which
means "the first derivative".  The first derivative of WHAT?  Exactly.

My favorite examples of this kind of appealing code come from J4, when we
had a richer set of metaprogramming tools (primarily the now-obsolete F.
Trains Table [3]).  Consider that you could then express "the derivative of
the composite" as  @ D.1 . We could even tacitly express the derivative
chain rule as  @ D.1 ↔ [.D.1 @]. x ].D.1   where x=:+/ .* (matrix
multiplication)!

But my all-time favorite template of this type comes from the useful
definition of  }  which allows us to replace one scalar with another, e.g.
A with B by ('A'&=)`(,:&'B')} 'A AINT WHAT IT USED TO BE' .  What if we
wanted to generalize this?  Just delete A and B! So: 

        sr=: ( &=)`(,:& )}                      NB. Deleted the parameters
..
        'T' sr 'G' 'A AINT WHAT IT USED TO BE'  NB. .. so now we have to
fill them back in

Look at sr: ( &=)`(,:& ) is symmetric. The left side is "missing" a
parameter on the left (calling for a left argument), the right side is
"missing" a parameter on the right (calling for a right argument), and when
you supply the arguments, they end up adjacent to the &s, where they are
needed.  They fill in the blanks.

Now that's tacit programming!  But that was the good old days.  Today, we'd
have to use actual, explicit parameters, as in 2 : 'm&=`(,:&n)}' .

[3]  J4 trains table, with many more rules like "bonded conjunction" (C0
V1) and "adverb train" (A0 A1):
     http://www.cs.trinity.edu/About/The_Courses/cs2322/jdoc/dict/dictf.htm




-----Original Message-----
From: [email protected] [mailto:programming-
[email protected]] On Behalf Of David Ward Lambert
Sent: Tuesday, January 22, 2013 11:56 AM
To: programming
Subject: [Jprogramming] tacit version of round

   round =: 1&$: : (dyad def '<.@:(1r2+])&.:(%&x) y')
   assert 1 -: round 1.2
   assert 1.25 -: 0.25 round 1.2

   Round =: adverb def '<.@:(1r2+])&.:(%&m) y'

Is there a tacit definition of round using under?
What is the tacit definition of adverb Round?
Thanks, Dave.



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

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

Reply via email to