« first day (724 days earlier)      last day (1931 days later) » 

7:33 AM
@ngn Nice tip! Thanks.
How do you print a value in oK? I searched for 'print' and 'output' in github.com/JohnEarnest/ok/blob/gh-pages/docs/Manual.md but didn't see anything.
I'm looking for a function that prints something as a side effect, for debugging.
 
7:50 AM
In oK,

`
{*x}'(1 2;3,4)
1 3
`

But

`
*'(1 2;3,4)
(*[1 2;];*[3 4;])
`

Why? I'd expect them to do the same thing.
 
8:20 AM
My oK solution to https://projecteuler.net/problem=2 ("By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms"):

`nf:{(x@1),(*x)+(x@1)}`
`z@&~2!z:{*x}'{4000001>x@1}nf\1 1`

Anyone see a way to shorten it or otherwise improve it?
Hmm. The definition of nf can be shortened: nf:{a,*x+a:x@1}
Trying to get my code to work in the k that comes with the current q from kx systems. (What's a less verbose way to refer to this version of k?) How do I do mod (remainder) in that version of k? And how would I look this up for myself?
I think I figured out the answer to my earlier question about {*x}'a vs *'a. The "each" operator (a'b) behaves differently depending on whether a is monadic or dyadic. I guess it's defaulting to dyadic even when there's no left hand argument.
This seems to contradict the manual, which says: "Verbs behave as dyads if there is a noun immediately to their left, and otherwise they behave as a monad." There's nothing to the left of the * in *'(1 2;3 4) and yet the verb seems to behave as a dyad.
The manual goes on to say: "Sometimes it is necessary to disambiguate, so using a colon (:) as a suffix will force a verb to behave as a monad." So *:'(1 2;3 4) yields 1 3 as expected, but I don't see why the colon is necessary.
 
9:19 AM
Found a shorter solution to problem 2. Here it is (with nf inlined}: +/(~2!)#*:'{4000001>x@1}{a,*x+a:x@1}\1 1
 
ngn
9:56 AM
@jordancurve in k4 you can plug a 0N! in an expression to print an intermediate value, but unfortunately neither kona or oK support it
@jordancurve i too was wondering about that. i asked people who work on k and they mentioned (1, 2) consistency and k's need to know the valence of verbs in advance
in my implementation i chose to differ - *'(1 2;3 4) works like *:'(1 2;3 4), though *' in isolation would still create projections
@jordancurve you could use {|+\x} or (|+\) instead of {a,*x+a:x@1}, see fun.k
@jordancurve a less verbose way to refer to this version of k? - i don't know... "32-bit k4"? or just "k4" or maybe "kx k" if you want to emphasise comparison against other impls
"remainder" could be *|x\:y, i.e. last of the base-x encoding of y. there might be a better way to do it, i'm just not aware of it
 
 
5 hours later…
ngn
3:42 PM
@jordancurve now i notice i forgot to explain this. that statement from the manual is true. the verb in this case is a derivative one - a combination of something+adverb. adverbs are always postfix. verbs are infix or prefix. there is nothing to the left of *' so indeed, its only argument becomes (1 2;3 4). how ' applies its * is a different matter.
if you had (5 6;7 8) *' (1 2;3 4) then *' would have 2 arguments and ' would apply * to corrsponding pairs from them
 

« first day (724 days earlier)      last day (1931 days later) »