Expressed in Factor:

: depth ( -- n ) datastack length ;

: package-stack ( -- seq )
    datastack [ depth narray ] with-datastack ;

...but just the datastack word itself will result in the same sequence ;-)

On Tue, Jun 19, 2012 at 8:52 PM, Graham Telfer <gakouse...@hotmail.com> wrote:
> Doug Coleman <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, at
>> which point you return the array?
>>
>> That's kind of what it sounds like you're suggesting, which would be
>> kind of fun but totally impractical. In C, you'd collect them
>> immediately after you calculate them, too, just like you should in
>> Factor.
>>
>> The data stack is not for storing all your data, just for threading
>> arguments and return values between word calls in a predictable way
>> (known stack height.)
>>
>> Is that helpful? :)
>>
>> Doug
>
> I know nothing about C. In Prolog an accumulator is exactly what I'd use.
>
> Forth has a "Depth" word which is partly why I expected one in Factor. When 
> the
> job has finished the stack depth is known and
>
> As an alternative data structure to I tried constructing a list and adding 
> each
> new result to it; but the list data structure in Factor is so messy and 
> unwieldy
> I quickly decided not to use it. The Lisp words "cons" "cadr" are dreadful.
> Prolog and Haskell are much more elegant in their use of lists.
>
>
>
>
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond. Discussions
> will include endpoint security, mobile security and the latest in malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to