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 promising (and it's incredibly short). However,
 when I try it, I'm still getting that macro error.


 In your main you missed the [ ] around prop-even. This line:

 https://github.com/mcandre/factcheck/blob/master/example.factor#L12

 should read:

 [ prop-even ] [ gen-even ] for-all? .

 -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


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 via 
inputsequence:

:: for-all ( generator: ( -- ..a ) predicate: ( ..a -- ? ) -- ? )
1000 iota [ drop 
generator { } outputsequence : generated
generated predicate inputsequence : ok?
ok? [ generated . ] unless
ok? not
] find drop not ; inline

-Joe

smime.p7s
Description: S/MIME cryptographic signature
--
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


Re: [Factor-talk] sequences and the stack

2011-08-24 Thread Andrew Pennebaker
Is there a word more general than firstn? I'd like to push all the elements
of a sequence onto the stack.

Cheers,

Andrew Pennebaker
www.yellosoft.us

On Sun, Aug 21, 2011 at 2:26 PM, Alexander J. Vondrak 
ajvond...@csupomona.edu wrote:

 first2: http://docs.factorcode.org/content/word-first2,sequences.html

 In general, firstn:
 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 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 nth, how can I do this? Is there a word that pops the
 elements of a sequence onto the stack?

 Cheers,

 Andrew Pennebaker
 www.yellosoft.ushttp://www.yellosoft.us


 --
 Get a FREE DOWNLOAD! and learn more about uberSVN rich system,
 user administration capabilities and model configuration. Take
 the hassle out of deploying and managing Subversion and the
 tools developers use with it. http://p.sf.net/sfu/wandisco-d2d-2
 ___
 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


Re: [Factor-talk] sequences and the stack

2011-08-24 Thread John Benediktsson
Typically there are better ways to operate on sequences than to put all the
elements on the stack, but you could:

( scratchpad ) { 0 1 2 3 } dup length firstn

Better might be to use some combinators to act on the sequence each grabbing
the element that they need (bi, tri, or the more general cleave):

( scratchpad ) { 0 1 2 3 } {
  [ first ]
  [ second ]
  [ third ]
   } cleave




On Wed, Aug 24, 2011 at 6:50 PM, Andrew Pennebaker 
andrew.penneba...@gmail.com wrote:

 Is there a word more general than firstn? I'd like to push all the elements
 of a sequence onto the stack.


 Cheers,

 Andrew Pennebaker
 www.yellosoft.us

 On Sun, Aug 21, 2011 at 2:26 PM, Alexander J. Vondrak 
 ajvond...@csupomona.edu wrote:

 first2: http://docs.factorcode.org/content/word-first2,sequences.html

 In general, firstn:
 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 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 nth, how can I do this? Is there a word that pops the
 elements of a sequence onto the stack?

 Cheers,

 Andrew Pennebaker
 www.yellosoft.ushttp://www.yellosoft.us


 --
 Get a FREE DOWNLOAD! and learn more about uberSVN rich system,
 user administration capabilities and model configuration. Take
 the hassle out of deploying and managing Subversion and the
 tools developers use with it. http://p.sf.net/sfu/wandisco-d2d-2
 ___
 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


--
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


Re: [Factor-talk] sequences and the stack

2011-08-24 Thread Andrew Pennebaker
I've got a function that I want to call over a sequence of values (both are
determined at run time).

Is there something like call that accepts a sequence of arguments?

Something like this:

f args call-seq

Cheers,

Andrew Pennebaker
www.yellosoft.us

On Wed, Aug 24, 2011 at 10:04 PM, John Benediktsson mrj...@gmail.comwrote:

 Typically there are better ways to operate on sequences than to put all the
 elements on the stack, but you could:

 ( scratchpad ) { 0 1 2 3 } dup length firstn

 Better might be to use some combinators to act on the sequence each
 grabbing the element that they need (bi, tri, or the more general cleave):

 ( scratchpad ) { 0 1 2 3 } {
   [ first ]
   [ second ]
   [ third ]
} cleave




 On Wed, Aug 24, 2011 at 6:50 PM, Andrew Pennebaker 
 andrew.penneba...@gmail.com wrote:

 Is there a word more general than firstn? I'd like to push all the
 elements of a sequence onto the stack.


 Cheers,

 Andrew Pennebaker
 www.yellosoft.us

 On Sun, Aug 21, 2011 at 2:26 PM, Alexander J. Vondrak 
 ajvond...@csupomona.edu wrote:

 first2: http://docs.factorcode.org/content/word-first2,sequences.html

 In general, firstn:
 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 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 nth, how can I do this? Is there a word that pops the
 elements of a sequence onto the stack?

 Cheers,

 Andrew Pennebaker
 www.yellosoft.ushttp://www.yellosoft.us


 --
 Get a FREE DOWNLOAD! and learn more about uberSVN rich system,
 user administration capabilities and model configuration. Take
 the hassle out of deploying and managing Subversion and the
 tools developers use with it. http://p.sf.net/sfu/wandisco-d2d-2
 ___
 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




 --
 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


Re: [Factor-talk] sequences and the stack

2011-08-24 Thread John Benediktsson
Look at inputsequence from combinators.smart.

On Wed, Aug 24, 2011 at 7:19 PM, Andrew Pennebaker 
andrew.penneba...@gmail.com wrote:

 I've got a function that I want to call over a sequence of values (both are
 determined at run time).

 Is there something like call that accepts a sequence of arguments?

 Something like this:

 f args call-seq

 Cheers,

 Andrew Pennebaker
 www.yellosoft.us

 On Wed, Aug 24, 2011 at 10:04 PM, John Benediktsson mrj...@gmail.comwrote:

 Typically there are better ways to operate on sequences than to put all
 the elements on the stack, but you could:

 ( scratchpad ) { 0 1 2 3 } dup length firstn

 Better might be to use some combinators to act on the sequence each
 grabbing the element that they need (bi, tri, or the more general cleave):

 ( scratchpad ) { 0 1 2 3 } {
   [ first ]
   [ second ]
   [ third ]
} cleave




 On Wed, Aug 24, 2011 at 6:50 PM, Andrew Pennebaker 
 andrew.penneba...@gmail.com wrote:

 Is there a word more general than firstn? I'd like to push all the
 elements of a sequence onto the stack.


 Cheers,

 Andrew Pennebaker
 www.yellosoft.us

 On Sun, Aug 21, 2011 at 2:26 PM, Alexander J. Vondrak 
 ajvond...@csupomona.edu wrote:

 first2: http://docs.factorcode.org/content/word-first2,sequences.html

 In general, firstn:
 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 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 nth, how can I do this? Is there a word that pops the
 elements of a sequence onto the stack?

 Cheers,

 Andrew Pennebaker
 www.yellosoft.ushttp://www.yellosoft.us


 --
 Get a FREE DOWNLOAD! and learn more about uberSVN rich system,
 user administration capabilities and model configuration. Take
 the hassle out of deploying and managing Subversion and the
 tools developers use with it. http://p.sf.net/sfu/wandisco-d2d-2
 ___
 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




 --
 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


--
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


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,...) 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

smime.p7s
Description: S/MIME cryptographic signature
--
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


Re: [Factor-talk] sequences and the stack

2011-08-24 Thread Andrew Pennebaker
Thanks, inputsequence seems to be what I'm looking for.

I must be incorrectly declaring and passing the quotations, because I get a
compilation error.

Code at GitHub https://github.com/mcandre/factcheck.

$ ./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

Cheers,

Andrew Pennebaker
www.yellosoft.us

On Wed, Aug 24, 2011 at 10:25 PM, John Benediktsson mrj...@gmail.comwrote:

 Look at inputsequence from combinators.smart.


 On Wed, Aug 24, 2011 at 7:19 PM, Andrew Pennebaker 
 andrew.penneba...@gmail.com wrote:

 I've got a function that I want to call over a sequence of values (both
 are determined at run time).

 Is there something like call that accepts a sequence of arguments?

 Something like this:

 f args call-seq

 Cheers,

 Andrew Pennebaker
 www.yellosoft.us

 On Wed, Aug 24, 2011 at 10:04 PM, John Benediktsson mrj...@gmail.comwrote:

 Typically there are better ways to operate on sequences than to put all
 the elements on the stack, but you could:

 ( scratchpad ) { 0 1 2 3 } dup length firstn

 Better might be to use some combinators to act on the sequence each
 grabbing the element that they need (bi, tri, or the more general cleave):

 ( scratchpad ) { 0 1 2 3 } {
   [ first ]
   [ second ]
   [ third ]
} cleave




 On Wed, Aug 24, 2011 at 6:50 PM, Andrew Pennebaker 
 andrew.penneba...@gmail.com wrote:

 Is there a word more general than firstn? I'd like to push all the
 elements of a sequence onto the stack.


 Cheers,

 Andrew Pennebaker
 www.yellosoft.us

 On Sun, Aug 21, 2011 at 2:26 PM, Alexander J. Vondrak 
 ajvond...@csupomona.edu wrote:

 first2: http://docs.factorcode.org/content/word-first2,sequences.html

 In general, firstn:
 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 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 nth, how can I do this? Is there a word that pops the
 elements of a sequence onto the stack?

 Cheers,

 Andrew Pennebaker
 www.yellosoft.ushttp://www.yellosoft.us


 --
 Get a FREE DOWNLOAD! and learn more about uberSVN rich system,
 user administration capabilities and model configuration. Take
 the hassle out of deploying and managing Subversion and the
 tools developers use with it. http://p.sf.net/sfu/wandisco-d2d-2
 ___
 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




 --
 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




 --
 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
 

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 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


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 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 ) inputsequence ; 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

smime.p7s
Description: S/MIME cryptographic signature
--
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


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.

Perhaps you could do something similar in Factor. Instead of using generator 
functions, you could make a single generic function that lets types describe 
how to generate arbitrary members of themselves:

GENERIC: something-like ( exemplar -- arbitrary )

ERROR: don't-know-how-to-make-something-like exemplar ;

M: object something-like
don't-know-how-to-make-something-like ;

M: integer something-like
2 64 ^ random ;

M: float something-like
-1.0 1.0 uniform-random-float ;

Then pass an exemplar of the type to something-like:

( scratchpad ) 1 something-like .
16789018172707

( scratchpad ) 1.0 something-like .
-0.13980920020477

Union types and tuple types could then naturally implement something-like in 
terms of their constituent types.

-Joe

smime.p7s
Description: S/MIME cryptographic signature
--
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


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
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 “inputsequence” to an input parameter of a non-inline word
 macro inputsequence


 inputsequence 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 ) inputsequence ; 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


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. Assuming the net output effect of the generators is 
supposed to match the input effect of the predicate, the generators and 
predicate together would have a constant effect ( -- ? ). The following works, 
and should be general enough for everything you describe:

CONSTANT: number-of-tries 1,000

: for-all? ( generator: ( -- ..a ) predicate: ( ..a -- ? ) -- ? )
[ number-of-tries iota ] 2dip '[ drop @ @ not ] find drop not ; inline

( scratchpad ) [ 2 64 ^ random ] [ even? ] for-all? .
f
( scratchpad ) [ 2 64 ^ random 2 * ] [ even? ] for-all? .
t

: random-string ( -- x ) 32 random [ HEX: 10 random ]  replicate-as ;

( scratchpad ) [ random-string random-string ] [ [ [ length ] bi@ + ] [ append 
length ] 2bi = ] for-all?
t

-Joe

smime.p7s
Description: S/MIME cryptographic signature
--
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


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? vowel?

I imagine classes could reduce the ambiguity of exemplars. How much
boilerplate would be required to make classes for the above? non-negative,
positive, divides-by-three, byte?

It's starting to look circular: How can we define legal inputs for a
predicate in order to test whether the predicate is succeeds for all legal
inputs?

A conceptually easy solution is to make quotations that generate the desired
input, slap 'em in an array, and call predicate { generators ... }
forall100 times. I'm just not sure how to do call(function, arguments)
in factor.

Cheers,

Andrew Pennebaker
www.yellosoft.us

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


 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.


 Perhaps you could do something similar in Factor. Instead of using
 generator functions, you could make a single generic function that lets
 types describe how to generate arbitrary members of themselves:

 GENERIC: something-like ( exemplar -- arbitrary )

 ERROR: don't-know-how-to-make-something-like exemplar ;

 M: object something-like
 don't-know-how-to-make-something-like ;

 M: integer something-like
 2 64 ^ random ;

 M: float something-like
 -1.0 1.0 uniform-random-float ;

 Then pass an exemplar of the type to something-like:

 ( scratchpad ) 1 something-like .
 16789018172707

 ( scratchpad ) 1.0 something-like .
 -0.13980920020477

 Union types and tuple types could then naturally implement something-like
 in terms of their constituent types.

 -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


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 could dispatch on the class names themselves, and use Factor's predicate 
classes and class algebra to naturally describe more specific constraints:

EQ-GENERIC: arbitrary ( class -- value ) ! not in factor, unfortunately

M: integer arbitrary 2 64 ^ random ;

PREDICATE: even-integer  integer
even? ;

M: even-integer arbitrary 2 63 ^ random 2 * ;

\ integer arbitrary . ! would print e.g. 12345
\ even-integer arbitrary . ! would print e.g. 12346

INTERSECTION: even-fixnum
fixnum even-integer ;

M: even-fixnum arbitrary most-positive-fixnum 2 / random 2 * ;

\ even-fixnum arbitrary .

-Joe

smime.p7s
Description: S/MIME cryptographic signature
--
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


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 executed because it failed to compile

Cannot apply “call” to a run-time computed value
macro call

Cheers,

Andrew Pennebaker
www.yellosoft.us

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


 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. Assuming the net output effect of the
 generators is supposed to match the input effect of the predicate, the
 generators and predicate together would have a constant effect ( -- ? ). The
 following works, and should be general enough for everything you describe:

 CONSTANT: number-of-tries 1,000

 : for-all? ( generator: ( -- ..a ) predicate: ( ..a -- ? ) -- ? )
 [ number-of-tries iota ] 2dip '[ drop @ @ not ] find drop not ; inline

 ( scratchpad ) [ 2 64 ^ random ] [ even? ] for-all? .
 f
 ( scratchpad ) [ 2 64 ^ random 2 * ] [ even? ] for-all? .
 t

 : random-string ( -- x ) 32 random [ HEX: 10 random ]  replicate-as ;

 ( scratchpad ) [ random-string random-string ] [ [ [ length ] bi@ + ] [
 append length ] 2bi = ] for-all?
 t

 -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


Re: [Factor-talk] sequences and the stack

2011-08-21 Thread Alexander J. Vondrak
first2: http://docs.factorcode.org/content/word-first2,sequences.html

In general, firstn: 
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 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 nth, how can I do this? Is there a word that pops the elements 
of a sequence onto the stack?

Cheers,

Andrew Pennebaker
www.yellosoft.ushttp://www.yellosoft.us

--
Get a FREE DOWNLOAD! and learn more about uberSVN rich system, 
user administration capabilities and model configuration. Take 
the hassle out of deploying and managing Subversion and the 
tools developers use with it. http://p.sf.net/sfu/wandisco-d2d-2
___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] sequences and the stack

2011-08-21 Thread John Benediktsson
Also, for your case a sequence of two elements can be treated a bit like a map 
of key/value pairs.  You can use the assocs vocabulary to manipulate your 
sequence (called an association list or 'alist' in the documentation).

Try:

( scratchpad ) USE: assocs
( scratchpad ) \ assoc-map help
( scratchpad ) \ assoc-each help




On Aug 21, 2011, at 11:26 AM, Alexander J. Vondrak ajvond...@csupomona.edu 
wrote:

 first2: http://docs.factorcode.org/content/word-first2,sequences.html
 
 In general, firstn: 
 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 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 nth, how can I do this? Is there a word that pops the 
 elements of a sequence onto the stack?
 
 Cheers,
 
 Andrew Pennebaker
 www.yellosoft.ushttp://www.yellosoft.us
 
 --
 Get a FREE DOWNLOAD! and learn more about uberSVN rich system, 
 user administration capabilities and model configuration. Take 
 the hassle out of deploying and managing Subversion and the 
 tools developers use with it. http://p.sf.net/sfu/wandisco-d2d-2
 ___
 Factor-talk mailing list
 Factor-talk@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/factor-talk

--
Get a FREE DOWNLOAD! and learn more about uberSVN rich system, 
user administration capabilities and model configuration. Take 
the hassle out of deploying and managing Subversion and the 
tools developers use with it. http://p.sf.net/sfu/wandisco-d2d-2
___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk