Got it.
I thought with functional programming all kinds of side effects
are best avoided – including assignments.
But there’s a tradeoff against readability (and maybe performance)
and I agree that’s more important at least in this case.
I take your advice (the assignment part) as a Wise Man’s Judgement
I should follow until I know the language much better myself.
Thanks for all the responses.
Am 03.06.20 um 15:40 schrieb Henry Rich:
Write it using x and y, and assignment of intermediate results.
Henry Rich
On 6/3/2020 3:35 AM, Hauke Rehr wrote:
Once again, starting with my example “onsub”
I said I could use (u;[;]) for what I wanted
I should have done this in order to make you
see what I’m after
So this is a cloumsy implementation based on
Raul’s approach below
NB. long line, may span several lines on your screen
onsub2 =: 2 : '(3&{:: ;~ (0&{:: {. 1&{::) , (0&{:: ([ }. {."1)
1&{::) ,. 2&{::)@:([;];([: (u;v) [ }."1 }.))'
Now I can
2 |. onsub2 # mat
and get the desired result.
Here |. and # are two operands but it’s
a simple matter of juggling syntactic
elements around.
2 (|.;#) onsub3 mat
is a trivial substitution and
2 |.`# onsub4 mat
isn’t hard to get done either.
I don’t care that much about these details.
What I do care about is all those parens and {::’s.
It’s a hell of a mess not showing what’s going on.
Too far away from Raul’s short readable “onsb” adverb.
I thought there must be a clean way, still without
any kind of assignment (other than to onsubN).
And of course it’s only an example. In no way should
the solution depend on |. and # as values for u and v
Apologies again for my flood of rapidly thrown together
posts. This time I think it should be possible to see
what I want, how I tried to get it, and in which way
I consider myself to have failed.
Am 02.06.20 um 10:28 schrieb Raul Miller:
It's might be worth noting that
|. onsub 2 mat
4 14 10 14 7 13
6 9 15 10 18 1
3 5 9 9 7 16
8 12 11 18 16 18
5 6 1 1 9 10
can be replaced with
onsb=: 1 :0
{., ([ }. {."1) ,. [: u [ }."1 }.
)
2 |. onsb mat
4 14 10 14 7 13
6 9 15 10 18 1
3 5 9 9 7 16
8 12 11 18 16 18
5 6 1 1 9 10
And there's tricks you can use even nowadays to rephrase an explicit
one line adverb like this into a tacit adverb. though in my opinion
they do not help its readability -- that said, this might be overcome
through the use of meaningful names for the components. You can do
that even here, though:
toprows=: {.
leftrows=: [ }. {."1
bodyrows=: [ }."1 }.
onsb=: 1 :0
toprows, leftrows,. [: u bodyrows
)
But... that said, there can be a problem in production code with this
approach, which has to do with stepping on names. If you go fully
tacit, you can remove the intermediate verb names from the result,
which lets you assemble code which avoids verb name collision issues.
(It also can make it a representation of the code harder to read,
which might be seen as an advantage in intellectual property contexts.
However, there aren't a lot of J programmers, and in international
contexts ... there have been ... bigger problems.)
But the big win, here, is that you can take the implementation of
onsb, and turn it into a conjunction (introducing a v) and thus
perform an arbitrary operation on more than the 'bodyrows'.
I hope this helps,
--
Raul
On Mon, Jun 1, 2020 at 10:30 PM Hauke Rehr <[email protected]>
wrote:
I usually do tacit programming with J,
but what I mean by this is I don’t use x or y
that is I can write tacit _verbs_ only.
I know one can be tacit on modifier level etc
but I didn’t ever learn how.
1. is there any good place to start learning?
if not, would anyone mind putting together
some material on this?
2. here is an example of something that in terms
of data manipulation is not very J-ish
but let’s assume I need to do it this way
for some reason:
onsub =: 2 : 'n&{. , n&}.@:(n&{."1) ,. u@:(n&}."1)@(n&}.)'
(
first I wrote it as an adverb without all the 'n&' parts,
then I generalized by adding them – it’s repetitive
but it does what I want it to do
)
usage is like
|. onsub 2 mat =: ? 5 6 $ 20
reversing (mirror) the 3 by 4 lower right submatrix
(a) how to write this without reference to u or n?
(b) what if I wanted to use it like this:
(|.;#) onsub 2 mat
with the result like everything happening in onsub
after application of u will work on its >@{.
and after everything is done its }. will be ;ed.
btw feel free to alter this thread’s subject, I just don’t know
what direction this will take so I picked the broad 'tacit' key
--
----------------------
mail written using NEO
neo-layout.org
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
--
----------------------
mail written using NEO
neo-layout.org
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm