Hauke is right. $: does not apply to explicit functions.
I expect there will be requests for more features in DDs. Until there
is a recur. control word, you will have to name the function you are
calling.
Henry Rich
On 10/27/2020 5:27 PM, Hauke Rehr wrote:
afaik, $: was never meant to be used with explicit code
In NuVoc, one use with explicit code is explicitly mentioned
as an exception to $:’s tacit only use:
This kind of default can also be used when the dyadic valence is defined
explicitly:
EDIT: there’s another line which states it more directly:
3. In no case does $: refer to a larger unit than the sentence it
appears in, for example an explicit definition in which it appears.
So I’d say, if you want to be explicit, be explicit.
Which entails calling oneself by one’s name rather than ‘me’.
Am 27.10.20 um 22:01 schrieb 'Michael Day' via Programming:
OK - not extended arithmetic...
Having been keen on direct definition in APL for many years, I've just
started looking back at
the late John Scholes' description of his Dfns in Dyalog APL, to be
found at
https://www.dyalog.com/uploads/documents/Papers/dfns.pdf
I tried coding a couple of simple recursive examples as DDs in J, namely
sieve (Primes) and fac(torial):
sieve =: {{)v
'' sieve y
:
nxt =. {. y
msk =. 0~: nxt | y
if. */ }. msk do.
x, y
else.
(x,nxt) sieve msk#y
end.
}}
fac =: {{)v
1 fac y
:
if. y = 0 do.
x
else.
(x * y) fac y - 1
end.
}}
They work fine:
sieve 2}.i.21
2 3 5 7 11 13 17 19
fac 8
40320
BUT - Dfns allows self-reference of anonymous functions with the delta
symbol, ∇,
which _might_ display ok here. SO, where I've got "sieve" or "fac"
within the dyadic sections of
these definitions, John had ∇ (delta). (He allowed ambivalent
functions by having an optional
default assignment of ⍺, alpha, ie x for J users.)
However, replacing (x * y) fac y - 1 by (x * y) $: y - 1 results in, eg:
fac 8
|stack error: fac
| (x*y) $:y-1
Is this my poor understanding of $: - I don't use it much - or is it
an instance of the problem with
$: that Henry noted in "Re: [Jbeta] Error with $:" on 11/Oct/20, or
something else?
Thanks again,
Mike
PS - In case the APL displays reasonably well, here are copies of these
2 Dyalog Dfns:
(The line numbers are not part of the definitions.)
Lines sieve[4] and factorial[2] are examples of "Guards" which are sort of
if. test then. value return. end.
sieve←{ ⍝ Sieve of Eratosthenes.
[1] ⍺←⍬ ⍝ Default no primes yet.*
[2] nxt←1↑⍵ ⍝ Next prime, and
[3] msk←0≠nxt|⍵ ⍝ ... mask of non-multiples.
[4] ∧/1↓msk:⍺,⍵ ⍝ All non multiples - finished.
[5] (⍺,nxt)∇ msk/⍵ ⍝ Sieve remainder.
[6] }
factorial←{ ⍝ Tail recursive factorial.
[1] ⍺←1 ⍝ *
[2] ⍵=0:⍺
[3] (⍺×⍵)∇ ⍵-1
[4] }
* examples of default value of left argument if applied monadically.
--
This email has been checked for viruses by AVG.
https://www.avg.com
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm