Re: [Factor-talk] sequences and the stack

2011-08-25 Thread Andrew Pennebaker
Aha! How could I rewrite for-all? so that it prints the first stack that fails the predicate? Cheers, Andrew Pennebaker www.yellosoft.us On Thu, Aug 25, 2011 at 1:11 AM, Joe Groff arc...@gmail.com wrote: On Aug 24, 2011, at 10:05 PM, Andrew Pennebaker wrote: Joe, your for-all? looks

Re: [Factor-talk] sequences and the stack

2011-08-25 Thread Joe Groff
On Aug 25, 2011, at 12:34 AM, Andrew Pennebaker wrote: Aha! How could I rewrite for-all? so that it prints the first stack that fails the predicate? The most straightforward thing I can think of is to package up the generated values with outputsequence, then feed the array to the predicate

Re: [Factor-talk] sequences and the stack

2011-08-24 Thread Andrew Pennebaker
: [Factor-talk] sequences and the stack The stack contains a sequence of number pairs: { { x1 y1 } { x2 y2 } { x3 y3 } ... } I want to map over the pairs, accessing xi and yi. [ ! stack = { xi yi } ! ... ! stack = xi yi ] map What's the code that goes in !... ? Other than using

Re: [Factor-talk] sequences and the stack

2011-08-24 Thread John Benediktsson
: http://docs.factorcode.org/content/word-firstn,sequences.generalizations.html Regards, --Alex Vondrak From: Andrew Pennebaker [andrew.penneba...@gmail.com] Sent: Sunday, August 21, 2011 11:20 AM To: Factor Subject: [Factor-talk] sequences

Re: [Factor-talk] sequences and the stack

2011-08-24 Thread Andrew Pennebaker
Subject: [Factor-talk] sequences and the stack The stack contains a sequence of number pairs: { { x1 y1 } { x2 y2 } { x3 y3 } ... } I want to map over the pairs, accessing xi and yi. [ ! stack = { xi yi } ! ... ! stack = xi yi ] map What's the code that goes in !... ? Other

Re: [Factor-talk] sequences and the stack

2011-08-24 Thread John Benediktsson
From: Andrew Pennebaker [andrew.penneba...@gmail.com] Sent: Sunday, August 21, 2011 11:20 AM To: Factor Subject: [Factor-talk] sequences and the stack The stack contains a sequence of number pairs: { { x1 y1 } { x2 y2 } { x3 y3 } ... } I want to map over

Re: [Factor-talk] sequences and the stack

2011-08-24 Thread Joe Groff
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,...)

Re: [Factor-talk] sequences and the stack

2011-08-24 Thread Andrew Pennebaker
Pennebaker [andrew.penneba...@gmail.com] Sent: Sunday, August 21, 2011 11:20 AM To: Factor Subject: [Factor-talk] sequences and the stack The stack contains a sequence of number pairs: { { x1 y1 } { x2 y2 } { x3 y3 } ... } I want to map over the pairs, accessing xi and yi. [ ! stack = { xi yi

Re: [Factor-talk] sequences and the stack

2011-08-24 Thread Andrew Pennebaker
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

Re: [Factor-talk] sequences and the stack

2011-08-24 Thread Joe Groff
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 “inputsequence” to an input parameter of a non-inline word macro inputsequence inputsequence is also a

Re: [Factor-talk] sequences and the stack

2011-08-24 Thread Joe Groff
On Aug 24, 2011, at 8:44 PM, Andrew Pennebaker wrote: 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.

Re: [Factor-talk] sequences and the stack

2011-08-24 Thread Andrew Pennebaker
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

Re: [Factor-talk] sequences and the stack

2011-08-24 Thread Joe Groff
On Aug 24, 2011, at 9:30 PM, Andrew Pennebaker wrote: predicate { gen-type1 gen-type2 gen-type3 ... } for-all The generators needn't be in an array; they could be a simple quotation. Simply calling each generator function in turn will line up their outputs on the stack in the proper order.

Re: [Factor-talk] sequences and the stack

2011-08-24 Thread Andrew Pennebaker
The exemplar idea is attractive, especially since it's idiomatic in Factor. However, an exemplar of 1 may not be precise enough for certain predicates. How can we define sufficiently specific exemplars for predicates like non-negative? positive? divides-by-three? byte? char? lowercase char?

Re: [Factor-talk] sequences and the stack

2011-08-24 Thread Joe Groff
On Aug 24, 2011, at 9:50 PM, Andrew Pennebaker wrote: The exemplar idea is attractive, especially since it's idiomatic in Factor. However, an exemplar of 1 may not be precise enough for certain predicates. True. Unfortunately Factor doesn't support CLOS-style eq generics, otherwise you

Re: [Factor-talk] sequences and the stack

2011-08-24 Thread Andrew Pennebaker
Joe, your for-all? looks promising (and it's incredibly short). However, when I try it, I'm still getting that macro error. Latest code incorporating your for-all?: https://github.com/mcandre/factcheck Macro Error: $ ./example.factor Loading /Users/andrew/.factor-rc The word main cannot be

[Factor-talk] sequences and the stack

2011-08-21 Thread Andrew Pennebaker
The stack contains a sequence of number pairs: { { x1 y1 } { x2 y2 } { x3 y3 } ... } I want to map over the pairs, accessing xi and yi. [ ! stack = { xi yi } ! ... ! stack = xi yi ] map What's the code that goes in !... ? Other than using nth, how can I do this? Is there a word

Re: [Factor-talk] sequences and the stack

2011-08-21 Thread Alexander J. Vondrak
: Sunday, August 21, 2011 11:20 AM To: Factor Subject: [Factor-talk] sequences and the stack The stack contains a sequence of number pairs: { { x1 y1 } { x2 y2 } { x3 y3 } ... } I want to map over the pairs, accessing xi and yi. [ ! stack = { xi yi } ! ... ! stack = xi yi ] map What's

Re: [Factor-talk] sequences and the stack

2011-08-21 Thread John Benediktsson
, --Alex Vondrak From: Andrew Pennebaker [andrew.penneba...@gmail.com] Sent: Sunday, August 21, 2011 11:20 AM To: Factor Subject: [Factor-talk] sequences and the stack The stack contains a sequence of number pairs: { { x1 y1 } { x2 y2 } { x3 y3