My goal is to test a user-supplied predicate, e.g. even? with a function
for-all that checks even? for all values (actually just 100 random values),
in other words, that arbitrary-integer even? is always true. Obviously this
is not true, but we need a predicate that fails in order to test the test
framework itself.

If the predicate is the odd? property of integers, then we have:

[ even? ] { gen-integer } for-all

Which should fail on odd numbers.

If we make a generator for just even numbers (gen-even), we have:

[ even? ] { gen-even } for-all

Which should always succeed.

It's difficult to dynamically determine test values for a given predicate.
Therefore, the user must supply an array of quotations which generate input
for the predicate. Some predicates take a single integer (even?), others
take a sequence (length), still others take multiple inputs, each of
different types. So the user calls for-all as follows:

*predicate* { *gen-type1* *gen-type2* *gen-type3* ... } for-all

If this test framework only handled unary predicates, then we could simply:

*predicate* *gen-type* for-all

I want to construct a for-all that tests predicates of arbitrary complexity.
For instance, there is already a generator for arbitrary arrays, which we
use to construct a generator of arbitrary strings.

! A quotation generating a random sequence.
: gen-seq ( quot: ( -- obj ) -- quot: ( -- seq ) ) [ gen-integer call 100
mod swap replicate ] ; inline

! A quotation generating a random string.
: gen-string ( -- str ) [ gen-char gen-seq call >string ] ; inline

That's why I want to emulate Smalltalk's valueWithArguments, a way to call a
quotation on an array of arguments rather than the stack. Imagine a
call-with that accepts a quotation and an array of values to operate on.

Cheers,

Andrew Pennebaker
www.yellosoft.us

On Thu, Aug 25, 2011 at 12:05 AM, Joe Groff <arc...@gmail.com> wrote:

> On Aug 24, 2011, at 8:38 PM, Andrew Pennebaker wrote:
>
> $ ./example.factor
> Loading /Users/andrew/.factor-rc
> The word for-all cannot be executed because it failed to compile
>
> Cannot apply “input<sequence” to an input parameter of a non-inline word
> macro input<sequence
>
>
> input<sequence is also a macro; it's essentially "firstn" with the "n"
> determined by stack effect inference on the input quotation. Since it's a
> macro, that input quotation needs to be statically determinable by the
> compiler. The compiler isn't smart enough to reach up to the caller's frame
> without the "inline" annotation on the callee:
>
> : foo ( quot -- x ) input<sequence ; inline ! *must* be inline
> : bar ( -- six ) { 1 2 3 } [ + + ] foo ;
>
> The stack is ultimately not a dynamic thing in Factor, and while there are
> hacks to pretend it is, you'll be happier if you find a more
> data-structure-oriented approach. You said you had an array of quotations; a
> better approach would be to iterate over the array, call each quotation with
> call( -- ) and process the outputs in a single pass, something akin like
> this:
>
> : generate-and-print ( generators -- )
> [ call( -- x ) . ] each ;
>
> -Joe
>
>
> ------------------------------------------------------------------------------
> EMC VNX: the world's simplest storage, starting under $10K
> The only unified storage solution that offers unified management
> Up to 160% more powerful than alternatives and 25% more efficient.
> Guaranteed. http://p.sf.net/sfu/emc-vnx-dev2dev
> _______________________________________________
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>
>
------------------------------------------------------------------------------
EMC VNX: the world's simplest storage, starting under $10K
The only unified storage solution that offers unified management 
Up to 160% more powerful than alternatives and 25% more efficient. 
Guaranteed. http://p.sf.net/sfu/emc-vnx-dev2dev
_______________________________________________
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to