Re: [Factor-talk] Stack Depth

2012-06-19 Thread Graham Telfer
Doug Coleman writes: > > How would you do this in C? Would you take the return address off the > stack frame, then start calculating the division-by-2s and pushing > them to the local stack frame in a loop, and then walk back up > accumulating them in an array until you hit the return address, a

Re: [Factor-talk] Stack Depth

2012-06-19 Thread Doug Coleman
Actually, here's how you can do this in Factor using the with-datastack word: USING: kernel math prettyprint sequences ; { 1337 } [ [ dup 1 > ] [ 2/ dup ] while ] with-datastack It's clean looking, but it's pretty slow. Doug On Tue, Jun 19, 2012 at 8:33 PM, Doug Coleman wrote: > How would you

Re: [Factor-talk] Stack Depth

2012-06-19 Thread Doug Coleman
How would you do this in C? Would you take the return address off the stack frame, then start calculating the division-by-2s and pushing them to the local stack frame in a loop, and then walk back up accumulating them in an array until you hit the return address, at which point you return the array

Re: [Factor-talk] Stack Depth

2012-06-19 Thread Graham Telfer
John Benediktsson writes: > > > I want to divide an integer by 2 until it gets to 1. > I have this snippet of code that goes into a loop. > dup 1 > [ dup 2 /i ] [  ] if > When it gets to 1 I want to push the elements into a sequence. > > > Take a look at the "produce" word: > > : divide-unti

Re: [Factor-talk] Stack Depth

2012-06-19 Thread Graham Telfer
Marshall Lochbaum writes: > > > I figured there would be a word designed for that already... Here's my take on this anyway. > I would append the items to a sequence as the algorithm goes along: > { } swap [ dup 1 > ] [ dup 2 /i [ suffix ] dip ] while suffixaccomplishes the task. > > Marshall

Re: [Factor-talk] Stack Depth

2012-06-19 Thread John Benediktsson
If you are concerned about performance ("suffix" makes a new array each time), then you can use vectors and "push" onto them, or use the "make" vocabulary which provides some convenience mechanisms for that. Or look into "collector-for" which the produce word uses... On Tue, Jun 19, 2012 at 8:09

Re: [Factor-talk] Stack Depth

2012-06-19 Thread Doug Coleman
The example for the produce word is basically your solution already. \ produce help click the example It should look like this: USING: kernel math prettyprint sequences ; 1337 [ dup 0 > ] [ 2/ dup ] produce nip . { 668 334 167 83 41 20 10 5 2 1 0 } This is basically John's solution, too. Chee

Re: [Factor-talk] Stack Depth

2012-06-19 Thread Marshall Lochbaum
I figured there would be a word designed for that already... Here's my take on this anyway. I would append the items to a sequence as the algorithm goes along: { } swap [ dup 1 > ] [ dup 2 /i [ suffix ] dip ] while suffix accomplishes the task. Marshall On Tue, Jun 19, 2012 at 10:50 PM, Graham

Re: [Factor-talk] Stack Depth

2012-06-19 Thread John Benediktsson
> > I want to divide an integer by 2 until it gets to 1. > > I have this snippet of code that goes into a loop. > > dup 1 > [ dup 2 /i ] [ ] if > > When it gets to 1 I want to push the elements into a sequence. > Take a look at the "produce" word: : divide-until-2 ( n -- seq ) [ dup 1 > ] [

Re: [Factor-talk] Stack Depth

2012-06-19 Thread Graham Telfer
Doug Coleman writes: > > In general, you shouldn't want to do this, as all Factor words > (besides the one I'm about to show you) need a fixed number of > parameters at compile-time. Macros expand at compile-time, so that's > one way to get around the restriction. > > The other way it to use a

Re: [Factor-talk] Stack Depth

2012-06-19 Thread Doug Coleman
In general, you shouldn't want to do this, as all Factor words (besides the one I'm about to show you) need a fixed number of parameters at compile-time. Macros expand at compile-time, so that's one way to get around the restriction. The other way it to use a slow word called with-datastack: { 1

[Factor-talk] Stack Depth

2012-06-19 Thread graham telfer
The word narray constructs a sequence but needs an integer to tell it how many elements to push. If you want to push all the stack elements how do you find the stack's depth? --

Re: [Factor-talk] sqlite on linux

2012-06-19 Thread Grisha Freilikhman
I've managed by installing sqlite from the software center. thanks. On Tue, Jun 19, 2012 at 2:05 PM, Grisha Freilikhman wrote: > I am using ubuntu x86.I've compilted sqlite3 and checked it, it works. > > Now, in foctor I'm running: > "my.db" db-open > > db-open fails with: > The image refers to

Re: [Factor-talk] sqlite on linux

2012-06-19 Thread Grisha Freilikhman
I am using ubuntu x86.I've compilted sqlite3 and checked it, it works. Now, in foctor I'm running: "my.db" db-open db-open fails with: The image refers to a libray or symbol that was not found at load time. Any suggestions? On Tue, Jun 19, 2012 at 12:34 AM, Jon Harper wrote: > On debian-ish d