Aye, it's a bit awkward, but I know that Haskell can do it because that's
how Haskell's QuickCheck library works. It even goes one step further and
creates the appropriate list of value generators according to the
predicate's type.
Cheers,
Andrew Pennebaker
www.yellosoft.us
On Wed, Aug 24, 2011 at 10:32 PM, Joe Groff <arc...@gmail.com> wrote:
>
> On Aug 24, 2011, at 6:50 PM, Andrew Pennebaker wrote:
>
> > Is there a word more general than firstn? I'd like to push all the
> elements of a sequence onto the stack.
>
> Asking for a function that pushes all the elements of an arbitrary sequence
> onto the stack is like asking for an [a] -> (a,a,a,...) function in Haskell.
> The stack in Factor is an abstract notational convenience akin to function
> composition (or more generally, arrows), not a real place. firstn is a
> macro; the expression "5 firstn" is evaluated at compile time and replaced
> in-line by a ( seq -- x x x x x ) function; this still only works when the
> value 5 is known at compile time.
>
> Guessing from your previous post, you're probably trying to turn this:
>
> [ even? ] { gen-integer } check
>
> into something like:
>
> { t } [ 1,000 [ gen-integer ] replicate [ even? not ] find drop not
> ] unit-test
>
> You'd do this as a macro. Macros are functions from their compile-time
> arguments to a quotation. Something like this (not tested):
>
> MACRO: check ( predicates generators -- quot )
> [ swap '[ { t } [ 1,000 [ _ execute( -- x ) ] replicate [ @ not ]
> find drop not ] unit-test ] ] with map concat ;
>
> -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