Re: [stack] adding construction to Joy-like languages
Stevan Apter <[email protected]>
| Newsgroups | gmane.comp.lang.concatenative |
|---|---|
| Message-ID | <[email protected]> |
----- Original Message ----- From: "John Nowak" <[email protected]> [:] > > 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. why limit yourself to a single element, or to indexing only at the top level of a list? i'll use "S" and "D" to denote the surface and depth indexing functions, and i'll write them infix. the left argument is the list to index, the right argument is the index: 10 20 30 S 2 30 10 20 30 D 2 30 10 20 30 S 2 0 30 10 (10 20 30)(40 50) S 0 10 20 30 (10 20 30)(40 50) D 0(2 1) 30 20 i.e. the right argument of D describes a path through the list. () = X D () () = X S () it's useful to have a null of some kind to represent all the elements. i'll use "N": (10 20 30)(40 50) D N 1 20 50 detaching the index from the function allows you to compute the elements to index, e.g. 10 20 30 40 50 60 S where 10 20 30 40 50 60 > 30 40 50 60 (this is very APLish: 10 20 30 40 50 60 > 30 -> 0 0 0 1 1 1, and where 0 0 0 1 1 1 -> 3 4 5.) > > 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. k has a pair of functions which might be useful to consider. i'll use "T" and "C" to denote 'take' and 'cut'. with list on the left, control argument on the right: 1 2 3 4 5 6 T 2 1 2 1 2 3 4 5 6 T -2 5 6 1 2 3 4 5 6 T 2 3 (1 2 3)(4 5 6) 1 2 3 4 5 6 T 3 2 (1 2)(3 4)(5 6) 1 2 3 4 5 6 C 2 3 4 5 6 1 2 3 4 5 6 C -2 1 2 3 4 1 2 3 4 5 6 C 0 2 (1 2)(3 4 5 6) 1 2 3 4 5 6 C 0 1 3 1 2(3 4 5 6) again, detaching the control argument from the function name allows you to compute the take/cut. > > The solution I propose has four parts: [:] i'm not sure what the problem is, so my suggestions might be off- target. my sense is that you may be starved for examples. what i mean is this: your data universe is the set of nested vectors. that's your machinery for representing the world. so you want a small set of primitives which give you maximum expressivity and also combine in powerful ways. that pretty much describes the history of innovation in the array programming world over the last 50 years.