That is an interesting difference, that shows problem well:
+: 2 : ('([: u v)';':';'(u v)') +:
+: +:
but, the "right answer":
hook =: 2 : '([: u v) : (u v)'
+: hook +:
([: +: +:) :(+: +:)
does not pre-assume dyad:
2 + (hook+:) 2 3
6 8
+: (hook+:) 2 3
8 12
2 +: (+hook) 2 3
6 8
Here is a cool haskell like error handling system:
mkerr
=: (0&boxeach@:)( ::((13!:11 ; 13!:12)@:(''"_)))
chkerrA =: ((hook;)(hook}.))(^:(0 = >@{.@:]))
+: mkerr 4 5 6
┌─┬───────┐
│0│8 10 12│
└─┴───────┘
2 +: mkerr 4 5 6
┌─┬─────────────────────────────────────┐
│3│|domain error | 2 +:mkerr 4 5 6 │
└─┴─────────────────────────────────────┘
mkerr behaves much like sdcheck (sockets). Either returns 0 and result, or err
number ; err text
+: chkerrA +: mkerr 4 5 6
16 20 24
+: chkerrA 2 +: mkerr 4 5 6
┌─┬───────────────────────────────────────────────┐
│3│|domain error | +:chkerrA 2 +:mkerr 4 5 6 │
└─┴───────────────────────────────────────────────┘
chkerrA either runs the u verb with the argument, or if argument is error,
returns the error.
2 + mkerr chkerrA +: mkerr 4 5 6
┌─┬────────┐
│0│10 12 14│
└─┴────────┘
----- Original Message -----
From: Aai <[email protected]>
To: [email protected]
Cc:
Sent: Tuesday, April 29, 2014 2:13:19 PM
Subject: Re: [Jprogramming] prob with redefining hook
Follow me:
+: (hook +:)(hook +:)
(+: +:) +:
((+: +:) +:) y
y (+: +:) +: y
2 3 (+: +:) +: 2 3
2 3 (+: +:) 4 6
2 3 +: 8 12
|domain error
| 2 3 +:8 12
ah! dyadic +: needs binary arguments
0 1 +: 1 0
0 0
... and the dyadic case works because it ends up with:
4 + 8 12
12 16
On 29-04-14 15:09, 'Pascal Jasmin' via Programming wrote:
> hook =: 2 : ('([: u v)';':';'(u v)')
>
> no problems with dyad:
>
> 4 + (hook +:)(hook +:) 2 3
> 12 16
>
> but why does this not work?
> +: (hook +:)(hook +:) 2 3
> |domain error
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
--
Met vriendelijke groet,
@@i = Arie Groeneveld
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm