[Jprogramming] Strange behavior of 0x1

Erling Hellenäs erling at erlinghellenas.se
Sat Dec 16 19:12:20 UTC 2017


I was not aware of these results being strange. They seemed correct to 
me. Just wanted to help

Dmitry Khalansky as soon as possible, that's all.

/Erling

On 2017-12-16 17:36, Eric Iverson wrote:
> Erling,
>
> Jx is NOT J!
>
> Please do not report 'strange results' from Jx to the J programming forum!
>
> This can cause all kinds of unnecessary confusion.
>
> You can report strange Jx results to the chat forum.
>
> On Sat, Dec 16, 2017 at 7:15 AM, Erling Hellenäs <erling at erlinghellenas.se>
> wrote:
>
>> Hi !
>>
>> I get
>>
>>     0x1
>> 0
>>     eu=:2.71828
>>     0*eu^0
>> 0
>>
>>   This is J8.06 with Jx patches.
>>
>> Cheers,
>> Erling Hellenäs
>>
>>
>> On 2017-12-16 12:19, rouanth at gmail.com wrote:
>>
>>> Hi.
>>>
>>> Could someone please shed some light on the following behavior:
>>>
>>>      1p1
>>> 3.14159
>>>      0p1
>>> 0
>>>      0p0
>>> 0
>>>      1x1
>>> 2.71828
>>>      0x1
>>> 2.71828
>>>      0x0
>>> 0
>>>
>>> I don't understand why 0x1 isn't the same as 0 * ^1 even though
>>> other constants seem to obey this form. I haven't found any
>>> explanation in
>>> http://www.jsoftware.com/docs/help806/dictionary/dcons.htm .
>>>
>>> <information irrelevant to the question>
>>>
>>> I am new to J and am yet to write a useful script in it, but
>>> I've already been greatly impressed by how consistent the
>>> language felt in most cases. For example, just the other day
>>> I wrote a monadic verb which took $n$ as an argument and
>>> returned $\sum_k {n \choose 3k}$. The verb was the following:
>>>
>>>       a =: [:+/(3*i.)!]
>>>
>>> But if you try to pass it not a single $n$ but a list, the
>>> verb doesn't work. Which is a shame because the intended use
>>> was to examine the series. And so I started searching for
>>> something akin to Haskell's `map`. After half an hour of
>>> sifting through J tutorials that expressed delight in the
>>> fact that J lifts operations to arrays of arbitrary ranks
>>> by default and therefore doesn't need `map`, I've finally
>>> found what I was looking for, namely `a "0 i.50`, the rank
>>> operator, and it turned out that `map` isn't magic after
>>> all and is just a single case of a more general operation.
>>> I hadn't seen the rank operator in any language before and
>>> was thrilled to feel the potential that this operator holds.
>>>
>>> So the language is great, and it seems that common use cases
>>> are handled by elegant general solutions, that is, the
>>> language is designed to be mostly free from corner cases.
>>>
>>> That's why the unintuitive handling of 0x1 seems to me
>>> especially weird. I could ignore it if Python did it, if
>>> C++ did it, but J simply doesn't look like a language that
>>> intoduces inconsistencies for no reason. So it is highly
>>> probable that it's me who doesn't understand higher purpose
>>> of the construct. And so I came here hoping that someone
>>> explains it to me. The J community has a reputation of
>>> being tolerant to uninsightful questions of beginners.
>>>
>>> </information irrelevant to the question>
>>>
>>> Sorry if my English has some mistakes or is in the wrong
>>> tone. The reason isn't negligence, it's just that English
>>> isn't my native language.
>>>
>>> Regards,
>>> Dmitry Khalansky.
>>> ----------------------------------------------------------------------
>>> 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




More information about the Programming mailing list