kevinlawler / kona

Open-source implementation of the K programming language
ISC License
1.36k stars 138 forks source link

sample does not seem to work #589

Closed loganmhb closed 4 years ago

loganmhb commented 4 years ago

Attempting to sample a random item from a list and it does not look like it is working as documented:

  1 ? 1 2 3
domain error
1 ? 1 2 3
   ^

The problem is: https://github.com/kevinlawler/kona/blob/5e796e63364f7499ebab8d9708013fc707ff4e75/src/vq.c#L148. It looks like the function returns an error when x is an integer, but a couple of lines later checks whether x is an integer in order to call sample() (vs find()).

This looks like an intentional change, according to #503 , so perhaps the issue is simply that the documentation needs to be updated?

tavmem commented 4 years ago

Hi loganmhb --- Thanks, you are correct ... the documentation needs to be updated.

There are lots of ways that kona could be extended to "improve" the capabilaties of the original k. However, each of these extensions would come at the cost of compatibility.

The result in k2.8 is

$ cd k2.8
$ rlwrap -n ./k
K 2.8 2000-10-10 Copyright (C) 1993-2000 Kx Systems
Evaluation. Not for commercial use. 
\ for help. \\ to exit.

  1 ? 1 2 3
domain error
1 ? 1 2 3
  ^
>  

which is in complete agreement with kona.

tavmem commented 4 years ago

I would fix the documentation, but I can't seem to find the spot you refer to. Can you please identify the spot that needs to be fixed. Thanks !!

loganmhb commented 4 years ago

Sure. In the verb help (\+), there is a line reading:

? dyadic sample. n?y yields n random elements from list y (-n for no replacement)

That was what I was going off of -- not sure if it's referenced elsewhere.