Re: [stack] adding construction to Joy-like languages
"Daniel Ehrenberg" <[email protected]>
| Newsgroups | gmane.comp.lang.concatenative |
|---|---|
| Message-ID | <[email protected]> |
Factor can, in fact, do all of these things within the typical stack model, though I've never needed any of them in practical programming problems. Going through your list, On Mon, Dec 29, 2008 at 10:05 PM, John Nowak <[email protected]> wrote: > 1. The single form of construction handles any number of inputs and > outputs properly. In contrast, a family of cleave combinators is > needed. Factor has "smart combinators" that rely on the types of the > functions involved to get around this, but they're quite awkward in > comparison to FP's approach. Could you elaborate on why this is insufficient? Maybe it can be remedied, if there's a specific use case you can show. > > 2. FP has functions which, given a list, return a single element from > that list. Factor has no way (that I know of) to index into a stack > returning only the element selected. There's npick, which copies the nth item from the top of the stack on to the top, given an integer parameter (IIRC). If you follow that by [ clear ] dip, then that'll be all that's on the stack. This seems no less awkward than your solution (you can of course make a word : th npick [ clear ] dip ; to make this easier) but I don't see the motivation. > > 3. FP uses lists to group more than one element. As such, you can do > something like '[sq, dup]:5' to get '<25, <5, 5>>'. Emulating this > behavior is nearly impossible in Factor because all values are carried > inside a stack. As such, you must either return a flat stack like '25 > 5 5' (which is what '[sq] [dup] bi' would do) or return all stacks > independently like '{25} {5 5}' which makes getting at the values > painful. I've mentioned this problem earlier but I'm not sure if I'm > explaining it adequately. A better solution is to use an explicit array for problems like this. If you want it to be like a stack, you can use the with-datastack combinator (this is infra). I have not seen a situation where this would be needed, though. The general stack philosophy, as I understand it, is that not all parameters need to be seen by every function. To me, the stack is a nice representation of this; it is very simple and easy to use. I don't understand how the dataflow of a complicated function could be represented with the vector system. I don't remember large functions in the FP paper, just things like matrix multiplication. It'd be interesting to see some existing Factor or Joy code translated into this. Dan