I'm working through what you have done here, and am trying to understand
your reasoning:
Volume =: 3 : '''Volume is :'', (": l*w*h), '' for length '', (": l) , ''
width '' , (": w) , '' and height '' , (": h) [''l w h'' =. y'
This is a verb which only makes sense to use monadically. Also, it's mostly
dealing with lists of characters, many of them quoted. I think I'd instead
go with:
Volume =: 3 : 0
volume=. ": */y
'l w h'=. ":&.> y
'Volume is ',volume,', for length ',l,', width ',w,' and height ',h
)
The one-liner approach is great for experimenting, but not always so good
for other people. (And, I have probably offended on the wrong side of that
line, too often).
Next, we have:
hook =: 2 : '([: u v) : (u v) '
itemamend =: 4 : '((2}.$y) $"1 0 x)} y'
filtermodA =: 1 : 'u itemamend ] ,: (#inv~ u)'
curry =: 4 : '(boxopen y) (a: = ]) filtermodA x'
curryB=: 2 : 'u hook (n&curry)'
Studying this... the only left argument for 'hook' is Volume, which is
monadic. So what this will achieve is needless duplication. Furthermore,
what it's used for is not a hook but a hook-like concatenation mechanism.
So what I think is needed here is a better name. Also, since the
monadic/dyadic character of 'hook' is both irrelevant and distracting in
this context, I think I'd go with a simpler definition.
after=: 2 :'([ u v)'
Or, actually
after=: @:
Or, actually, since at this point it's just a primitive, I'd not bother
inventing another name for it. I am also tempted to use @ instead of @:
because the right argument will always have infinite rank, but for this
stage of this exercise I will refrain from that approach.
itemamend =: 4 : '((2}.$y) $"1 0 x)} y'
filtermodA =: 1 : 'u itemamend ] ,: (#inv~ u)'
curry =: 4 : '(boxopen y) (a: = ]) filtermodA x'
curryB=: 2 : 'u @: (n&curry)'
And, with that change, the result of
Volume curryB ( a:, a:,<4) curryB (3;a:) f.
is somewhat readable. Looking at it, I expect that I should be able to do
Volume curryB ( a:, a:,<4) curryB (3;a:) 5
but that gives me a domain error. So perhaps a different approach would be
good?
I guess what I think I would want is something which curries the leftmost
or rightmost argument in a list. So I would want to generate
Volume@(,&4)@(3&,)
And, honestly, that is good enough as it is. However, if I wanted to get
fancy, I could define
curryR=: 2 :'u@(,&n)'
curryL=: 2 :'u@(n&,)'
Note that I am explicitly ignoring the possibility of a left argument for
u. If I need a left argument, that's not an obstacle: I can curry ] and use
that curried verb to provide the right argument of my dyadic verb. And I
think that that approach is fine and good, if I am really trying to define
useful modules.
Of course, another approach would be to define something like:
Volume@(3,],4:)
But if I am going to go that route, I do not think that the abstract
concept of "currying" adequately describes what I am doing. So I'd want to
come up with a better name as my first step.
But maybe I have misunderstood what you were driving at here? I seem to be
good at that, sometimes.
Anyways, I hope this helps.
Thanks,
--
Raul
On Mon, Nov 17, 2014 at 2:35 PM, 'Pascal Jasmin' via Programming <
[email protected]> wrote:
> as a test function
>
> Volume =: 3 : '''Volume is :'', (": l*w*h), '' for length '', (": l) , ''
> width '' , (": w) , '' and height '' , (": h) [''l w h'' =. y'
>
> Volume 3 4 5
> Volume is :60 for length 3 width 4 and height 5
>
> some functions for currying arbitrary parameters
>
> hook =: 2 : '([: u v) : (u v) '
> itemamend =: 4 : '((2}.$y) $"1 0 x)} y'
> filtermodA =: 1 : 'u itemamend ] ,: (#inv~ u)'
> curry =: 4 : '(boxopen y) (a: = ]) filtermodA x'
> curryB=: 2 : 'u hook (n&curry)'
>
> This works: curry height to 4, and then in returned function, curry length
> to 3
> Volume curryB ( a:, a:,<4) curryB (3;a:)
> ([: ([: Volume ((0$0);(0$0);4)&curry) :(Volume ((0$0);(0$0);4)&curry)
> (3;0$0)&curry) :(([: Volume ((0$0);(0$0);4)&curry) :(Volume
> ((0$0);(0$0);4)&curry) (3;0$0)&curry)
>
>
> calling with remaining parameter (width) 2 returns as desired
>
> Volume curryB ( a:, a:,<4) curryB (3;a:) 2
> Volume is :24 for length 3 width 2 and height 4
>
> it also works as a dyadic call
>
> Volume@:] curryB ( a:, a:,<4) curryB (3;a:) 2
> Volume is :24 for length 3 width 2 and height 4
> 2 Volume@:] curryB ( a:, a:,<4) curryB (3;a:) 2
> Volume is :24 for length 3 width 2 and height 4
>
>
> If you look back to the returned function, it includes 3 : conjunctions to
> separate monad and dyad calls. I don't understand how multiple : works,
> and if you look closely, only the dyadic sides appear to be complete
> expressions that curry both the 4 and the 3
>
> actually upon closer inspection of parentheses matching, at the top level,
> only the middle : exists. On a monadic call the left of that would be
> executed, but within that left side, only the right side of : provides the
> "right" answer.
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm