Re: [stack] Point free (pointless) programming in ruby? (fwd)
John Nowak <[email protected]>
| Newsgroups | gmane.comp.lang.concatenative |
|---|---|
| Message-ID | <[email protected]> |
On Jan 13, 2009, at 6:15 PM, John Carter wrote:
> 1) Is there a neater way of expressing a sequence of function
> compositions in Ruby?
Evaluation of a concatenative language is just a fold of 'apply' over
your list of functions with the empty list as the initial element. For
example, in Scheme:
(define (ceval fs) (fold apply '() fs))
Your Ruby version is essentially the same thing.
> 2) Which Ruby Pointfree sequences are actually useful?
All you can really do is implement a concatenative language inside
Ruby complete with its own standard library. This is probably not so
useful.
Languages like ML and Haskell work better because they have curried
functions. There even exists a tool for automatically translating
pointful Haskell functions to point-free Haskell functions, although
the results are often less than clear:
\x y z -> y * z - x == flip (flip . ((-) .) . (*))
You may want to look at the following:
http://www.haskell.org/haskellwiki/Pointfree
Keep in mind that all existing concatenative languages make heavy use
of stacks. Related languages like FP and FL make heavy use of lists.
Trying to do pointfree programming in languages that don't do such
things (Ruby, Python, Haskell, Scheme, etc) is going to be quite
painful. For example, here's the Haskell example above in Joy:
* swap -
And in a concatenative FP-style language:
- [hd, * tl]
- John