Actually, there's no problem with doing an in-place amend in tacit
code.  For example:

   2 (99999}) ?~1e7

If something goes wrong, you have trashed the right argument being
passed in to the tacit amend, but it wasn't stored anywhere else so it
would have been lost anyways.

The problem occurs when you want an in-place amend of an explicitly
named value and you want tacit code to do that.

  y=. 2 (99999}) y

Here, you have to trash the value in the named variable. That works
fine when things go as expected, but you can wind up throwing away a
lot of work in the error cases.

And I've seen that happen.

In other words, what you really get is:

  y=. 2 (99999}) (y=.i.0 0)]y

Except, J trashes the variable for you, so you don't have to.

Thanks,

-- 
Raul


On Tue, Jul 22, 2014 at 12:39 PM, Jose Mario Quintana
<[email protected]> wrote:
> Don wrote:
> "I think it would be impossible to do an amendment in place in tacit code"
>
> It is not possible to amend in place tacitly in the official version of J.
> However, tacit versions of amend, and append, in-place have been
> implemented in an special version of J.  These are definitively not for the
> faint of heart because the tacit writer has to assume full responsibility
> and unexpected consequences might (will eventually) happen.
>
> The following is a comparison between a tacit implementation of a Turing
> machine (utm) (for details, see the link of my talk in
> http://www.jsoftware.com/jwiki/Community/Conference2012#Schedule) and an (a
> partial) in-place (utmIP) version where only the sentence,
>
>     T h( amend o (PRINT f ; P f ; T f ) ) f.
> <@:((0: 0&({::)@:]`(<@:(1&({::))@:])`(2&({::)@:])} ])@:(7&({::) ; 3&({::) ;
> 2&({::))) 2} ]
>
> in the utm was replaced by,
>
>    (PRINT,P,T) Amend
> 7 3 2&(102!:0)
>
> in the utmIP; the array (the tape referred by T) grows to a maximum tally
> of just 1965 in this example, nevertheless,  the in-place amendment makes a
> difference (Surface 2 Pro timings running on battery):
>
>    st
> (] , <@:(1&({::) * 2&({::)))@:(] ; 7!:2@:] ; 6!:2)
>
>    NB. http://www.drb.insel.de/~heiner/BB/bb-list (similar to Uhing's)
>
>    NB.        0         1      Tape Symbol Scan
>    NB. S   p  m  g   p  m  g
>
>    QS=. (noun _) ; 0 NB. Reading the transition table and setting the state
>     0   1 _1  1   1 _1  3
>     1   1  1  2   0  1  4
>     2   0 _1  0   0  1  1
>     3   1 _1  4   1  0 _1
>     4   1  1  2   1 _1  2
> )
>
>
>    TPF=. 0 ; 0 ; _                              NB. Setting the tape, its
> pointer and the display frequency
>
>
>    st'TPF smoutput@:utm   QS NB. (not in-place)'
> 0 0:0
> 0  :^
> 3 1
> :11010101010101110111011101110111011101110111011101110111011101110111011101110111011101110111011101110111011101110111011101110111011101110111011101110111011101110111011101110111011101110111011101110111011101110111011101110111011101110111011101110111...
> 2358064:^
> ...
> 0 0:0
> 0  :^
> 3 1
> :11010101010101110111011101110111011101110111011101110111011101110111011101110111011101110111011101110111011101110111011101110111011101110111011101110111011101110111011101110111011101110111011101110111011101110111011101110111011101110111011101110111...
> 2358064:^
> ...
> ┌─────────────────────────────────────────┬──────┬──────────┬──────────┐
> │TPF smoutput@:utm   QS NB. (not in-place)│219648│78.6351039│17272043.3│
> └─────────────────────────────────────────┴──────┴──────────┴──────────┘
>
>
>    st'TPF smoutput@:utmIP QS NB. (in-place)'
> 0 0:0
> 0  :^
> 3 1
> :11010101010101110111011101110111011101110111011101110111011101110111011101110111011101110111011101110111011101110111011101110111011101110111011101110111011101110111011101110111011101110111011101110111011101110111011101110111011101110111011101110111...
> 2358064:^
> ...
> 0 0:0
> 0  :^
> 3 1
> :11010101010101110111011101110111011101110111011101110111011101110111011101110111011101110111011101110111011101110111011101110111011101110111011101110111011101110111011101110111011101110111011101110111011101110111011101110111011101110111011101110111...
> 2358064:^
> ...
> ┌─────────────────────────────────────┬──────┬──────────┬──────────┐
> │TPF smoutput@:utmIP QS NB. (in-place)│216064│62.9319836│13597336.1│
> └─────────────────────────────────────┴──────┴──────────┴──────────┘
>
>
>
>
> On Tue, Jul 8, 2014 at 6:28 PM, Don Guinn <[email protected]> wrote:
>
>> I think it would be impossible to do an amendment in place in tacit code,
>> but amendment should still work in a tacit expression, just not in place.
>> But if the result were assigned back to the original variable what will
>> happen? Would the tacit expression prevent it from recognizing the
>> operation as an amendment in place?
>>
>>
>> On Tue, Jul 8, 2014 at 4:21 PM, Jose Mario Quintana <
>> [email protected]> wrote:
>>
>> > Erling wrote: "It's obviously not possible to do any amendments in tacit
>> > code?"  Adding after wards: "A principle of functional programming is you
>> > never modify a variable?"
>> >
>> >
>> >
>> > From my perspective those (rhetorical?) questions are separate.
>>  Regarding
>> > the first question, consider the verb (v) that produces the squares of an
>> > amendment produced by the verb amend.  For example,
>> >
>> >
>> >
>> >    ( v=. *: @: amend f. )
>> >
>> > *:@:(_: 0&({::)@]`(1&({::)@])`(2&({::)@])} ])
>> >
>> >
>> >
>> >    v (0 1 2 ; 2 3 5 ; 7#9)
>> >
>> > 81 81 0 1 81 4 81
>> >
>> >
>> >
>> > The verb (v) is tacitly defined (is it not?) and amendment is performed
>> via
>> > } (is it not?); thus the answer to the first question is that it is
>> > possible.  Furthermore, the conclusion is reached regardless of what the
>> > meanings of “functional programming” and “variable” might, or might not,
>> > be.  (Am I missing something?).
>>
>> ----------------------------------------------------------------------
>> For information about J forums see http://www.jsoftware.com/forums.htm
>>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to