+
Skip to content

Conversation

Bruno-366
Copy link

@Bruno-366 Bruno-366 commented Aug 12, 2021

description:
Executes a quote with inputs, preserving inputs and outputs
Takes a quote and a seq containing inputs for the quote
Returns a seq containing the inputs as well as any produced output
Useful for checking the behaviour of words under different inputs

example:

    USING: test-word math prettyprint ;
    { { 1 2 } { 3 4 } { 2 3 } { 1 4 } } [ + ] test-word .

output:

    {
        { { 1 2 } { 3 } }
        { { 3 4 } { 7 } }
        { { 2 3 } { 5 } }
        { { 1 4 } { 5 } }
    }

@Bruno-366
Copy link
Author

was unsure as to where to put it, so I put it in extra. Also the word could be renamed to something better...

@Bruno-366 Bruno-366 marked this pull request as ready for review August 12, 2021 14:19
@timor
Copy link
Contributor

timor commented Aug 12, 2021

Just out of curiosity, what is your use case for this? It looks similar to the interface for writing unit tests in a way.

@Bruno-366
Copy link
Author

Bruno-366 commented Aug 12, 2021 via email

@timor
Copy link
Contributor

timor commented Aug 12, 2021

Maybe this should be added to the test vocab then?

@Bruno-366
Copy link
Author

Bruno-366 commented Aug 12, 2021 via email

@mrjbq7
Copy link
Member

mrjbq7 commented Aug 12, 2021 via email

@Bruno-366
Copy link
Author

Bruno-366 commented Aug 12, 2021 via email

@timor
Copy link
Contributor

timor commented Aug 12, 2021

Ah sorry. I was under the impression that you use it for unit testing in the end.

@Bruno-366
Copy link
Author

I'm going to add one more word that I wrote some time ago, its a bit similar.
Given an array of words (for example: produced by \ palindrome? definition)
it will execute those words and show any intermediary values, as a form of super simple printf debugging.

@jonenst
Copy link
Contributor

jonenst commented Aug 13, 2021

The help still has "before-word" but the actual word is "before-after".
What about "visualize-results" or "gather-results" instead of "test-word" ?
And "gather-intermediates" for "before-after" ?

To me, this is a good tool for visualizing results when you don't really know what you want and are exploring (otherwise, unit tests are superior because they are silent when they work and check results)

@Bruno-366
Copy link
Author

Bruno-366 commented Aug 13, 2021 via email

@Bruno-366
Copy link
Author

Hmm, the property-based testing seems to be harder than I expected.

[ xor ] infer in>> length

I can use the above to figure out if a word is unary, binary or ternary (ie how many inputs it takes).

{ 1 2 3 4 5 } 1 all-selections . ! for unary number words
{ 1 2 3 4 5 } 2 all-selections . ! for binary number words

There's three obstacles I don't know how to solve:

  1. In the above example, for words with 2 inputs, we expect the word to have 2 inputs of the same class
    If we instead have for example remove-nth ( n seq -- seq' ) which expects 2 inputs with different classes,
    then the following would not work, because sometimes we would get n seq and sometimes seq n (also n n and seq seq)
{ 0 "a"  } 2 all-selections

So the above problem was how to generate possible inputs, while taking into account situations where stack order matters
The second problem is:

  1. I don't know if its possible to figure out from infer's output the appropriate class for the inputs of a word.
[ xor ] infer in>> ! outputs an array containing the strings "x" "x"

"x" could be anything, not necessarily a number, and I think this has to do with the fact that factor is dynamically typed.

  1. There's a random numbers generator, but in true property testing you would have a random array generator, random string generator, etc.

Summary: my guess is that from the stack effect of a word, there isn't an easy way to generate possible inputs for that word,
this is something that has to be done by hand, although I'll mention in the docs a few examples as how to do this :)

@timor
Copy link
Contributor

timor commented Aug 13, 2021

Could you replace "quote" with "quotation" in the documentation?

@razetime
Copy link
Member

these seem to be extension of with-datastack, so with that in mind i have these ideas:

  • change vocab to continuations.extras
  • rename gather-results to with-datastacks
  • rename gather-intermediates to datastack-states, or something similar.

@mrjbq7
Copy link
Member

mrjbq7 commented Jan 11, 2023

@razetime sounds good to me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载