Dan, thank you for your answers
2007/11/9, Dan Bron <[EMAIL PROTECTED]>:
>
>
> Danil,
>
> The short answer to your question is that a fundamental difference between
> tacit and explicit code is that the former can *not* assign
> variables. That
> is more or less the definition of tacit code.
>
> It is not true that this means you cannot see intermediate values. There
> are several different ways to produce these; but usually only one is
> applicable in a given situation.
>
> For example:
>
> +/ \ i.10
> 0 1 3 6 10 15 21 28 36 45
>
> +:^:(<4) 1
> 1 2 4 8
Not all of the tasks can be expressed without the use of temp variables (at
least efficiently or naturally). To put an example, write a tacit version of
verb which checks if parenthesises in a string are balanced. My best version
(*) in the case of a longs string (1M) involve a lot of array copying and
are slow. Algorithmically effective explicit code (using a list as a stack)
is intolerantly slow.
(*)
br=: 0=[:#[:,`([:}.])@.(3=[-[:{.])/ '])}[({'&([i.e.~#])
br '{}()'
1
br ' 9({}()'
0
It is also not true that explicit code is neccesarily slower than tacit
> code. In fact, certain forms of assignment are supported by special,
> optimized code (and, as I said, assignment can only occur in explicit
> code).
This also makes me feel uneasy. Why I can not use special amend form from
the tacit code (in the place were I really want things to go fast)?
Further, explicit code can embed tacit code, so nothing is lost. However,
> explicit verbs should not be used with a small rank.
>
> But your question isn't really about tacit-vs-explicit, it's about
> scalar-vs-array:
>
> But the answer to your basic question is:
> > Should one really always stretch his brain
> > for the pure tacit solutions without use of 'temp variables'?
>
> Yes. Or, rather, no. You're going to have to stop "thinking small". But
> this will come naturally, with time and practice, and eventually array (as
> opposed to scalar) solutions will no more stretch your brain than "temp
> variables" do now. Less, maybe. Certainly they'll stretch your fingers
> less.
>
> -Dan
>
> PS: By the way, it is possible to use "temp variables" in tacit code;
> they'll just be anonymous. That is, you'll address them by location, not
> by
> name.
I'm interested in this, but I have no time right now. Will look at it later.
Does it involve consructing a structure kept on a one side of a dyadic verb
with keeping temps in it? This is the kind of trickery I would like to
avoid.
See, for example, Arie's message earlier today:
>
>
> http://www.jsoftware.com/pipermail/programming/2007-November/008726.html
>
> where he stores a temp variable (a loop counter) in his left-hand
> argument.
> He updates it on every iteration. But note that while it's possible to do
> this, it's not desirable. In fact, the purpose of Arie's message was to
> find a way to remove this artifact.
>
> Compare it to my later versions:
>
>
> http://www.jsoftware.com/pipermail/programming/2007-November/008738.html
>
> http://www.jsoftware.com/pipermail/programming/2007-November/008742.html
>
> And you'll see the advantage of array thinking.
> --
regards,
Danil
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm