Hi -- A few weeks back I posted a playful
message complaining to Chris Double for having steered me to a book on the
Clean functional programming language that he used as a basis for one of the
blogs he did on creating Factor parser words.
I was drawn into reading it although I had no time or earthly business
for doing so and was complaining to Chris for having been so helpful in his
answer.
Having now plowed through much of
the first book, I wanted to take a more serious note and highly recommend it
for anyone like myself who is new to functional programming and wants a
readable introduction to combinators with a language that is different from,
but in many respects also similar to Factor.
(The URL is below in Chris's original response.) Perhaps any functional
language shares these qualities and I’m just too
green to be aware of it. But Clean,
although strongly typed in a way that Factor certainly is not, does what it
does largely on the basis of function composition. And the listings of
functions and space-delimited
function parameters that proliferate throughout the book’s explanations and
code examples often end up looking a lot like Factor code, albeit in reverse
order.
Of course it depends on what kind
of coding style is used and the parallels only go so far, but throughout my
read of the book I found myself imagining reading Factor (doing the mental
reversing thing as I went, of course) and imagining someone having coded Factor
words to support some of the more important Clean constructs. This
enabled me to follow many of the examples with an idea of how they might be
implemented in Factor code and allowed me to gain the insights offered up by
the book’s rich discussion of combinators.
Much of this mental shifting was
made possible by Clean’s core reliance on function concatenation and by the
Factor-like absence of extra call-site syntax for demarcating functions and the
parameters that are passed to them.
This in turn allows for easy partial function parameterization, thereby
blurring the distinction between functions and parameters altogether. So
taking an example immediately at hand
from the train I’m currently riding on, the function sequence Emergency Exit
Window can fluidly be seen as an Emergency Exit that takes the form of a Window
or of an Exit Window that is to be used in case of Emergency. To achieve the
first you would look at
Emergency as a function that expects two parameters, and then Emergency Exit as
a partial parameterization of this that expects one parameter; to achieve the
second you would look at Emergency and Exit each as functions that take one
parameter and Emergency Exit as a composition of these.
Both Clean and Factor care about
all of this, of course – Clean, because it is strongly typed, and Factor,
because
it is, well, weakly typed (stack effect specs and all that). But in terms of
expressing what you want in
the end, it doesn’t really matter too much and the ability to treat Emergency
Exit as a concept (whether achieved by partial parameterization or function
composition) is a powerful thing. Now I
would never probably find myself coding in Clean, because the hoops that it
goes through to make itself strongly typed just require too much effort to read
and understand. And the flexibility that
it gives to define local variables -- together with the flexibility described
above -- makes it difficult sometimes to understand exactly what’s happening and
what is being defined where. But it
certainly is powerful.
The book itself, on the other hand,
has what I found to be some nice discussions.
Much of it is not that immediately relevant to the Factor user, as it
discusses Clean’s type system and things you have to do to keep it happy. But
I’m actually continuing to slog through
the fifth chapter, not because I ever expect to use the Clean I/O library that
it discusses in details, but because it is good practice in parsing and reading
Clean code and thus preparation for the exercise that I propose below. And I’m
guessing that it might also include
illustrations of techniques that are either useful in their own right or needed
for understanding what is written in later chapters. I do expect the following
chapter that
discusses some performance considerations of using Clean and of doing
Lisp-style list processing to be of interest and possibly of relevance to
programming in Factor.
So all the way through this I was
thinking, “Gee, it would certainly be nice to have something that introduces
some of these concepts in a Factor context that is as accessible to the
novitiate as the Clean code book is”. There
are, of course, the FAQs and the blogs (which I’m also systematically
slogging through as part of my own project to understand the bootstrapper,
compiler and underlying execution engine of Factor). But I have found these
on more than one
occasion not so accessible to the rank beginner. So in the spirit that this
community likes to
foster, I am contemplating (not promising, mind you, but definitely seriously
considering) putting together a series of introductory discussions for the
Factor user to some of the more powerful concepts I encountered in the Clean
book. I would probably do this
by a series of concept tutorials that work through a handful of the half dozen
or so serious examples that are in part 2 of the Clean book and demonstrate how
you would code them in Factor (much along the lines of Chris’s blog that got me
started on all of this).
Of course my underlying agenda is
to answer some of this for myself and to learn Factor well enough to be able to
pull such an exercise off. So I would
expect anything coming from me to get better as it goes along. Now I could try
to do all this myself, but
given what a busy guy I am, chances are that if I did, this would remain
largely the stuff
of pipe dreams. So anyone else wishing
to engage in such an effort would be most appreciated and welcomed and would
help make this idea actually come to fruition.
Also, I’m sure there’s stuff out there that I don’t know about that is
more geared to the newcomer than some of the things I’ve been looking at, so no
need to reinvent the wheel .
Given these caveats, here’s an
introductory list of topics (in no particular order) I would propose to cover.
Any feedback on suitability and valuable
additions/deletions would be greatly appreciated:
Defining by combination in Factor and
effective use of Higher Order FunctionsPartial parameterization and
Currying
Effective use of Pattern matching
Effective alternation (if/else,
switch, etc.)
Iteration in Factor
Induction and Recursion
Lists, Tuples, Records and Arrays
in Factor
Effective use of named stack
parameters and local variables
Overloading – effective use of
Factor’s Generics
List and array comprehensions and
lazy sequences in Factor
Creating and using effective algebraic
data structures
This is more or less the set of
concepts needed to slog your way through some of the more extended Clean
examples, so I’m assuming they are available in one form or another in Factor
as well. Even if there is a good
treatment of all these concepts available already in one place or another, it
still
might be valuable to have them all pulled together and applied in an integrated
way to a series of coherent examples. And I've found in the past that it can
be valuable having the efforts of a group coordinated by a single editor, who
helps achieve consistency and coherence. Of
course if any of this does materialize, we’ll have to find a place to put it (I
don’t
think you want me posting tutorials here).
But I’ll cross that bridge when it actually becomes an issue. Talk is cheap
after all.
Sorry about the long post. It seemed potentially worthwhile, however.
From: mclag...@hotmail.com
To: factor-talk@lists.sourceforge.net
Date: Tue, 4 Sep 2012 21:43:27 +0000
Subject: Re: [Factor-talk] Quick Question For Chris Double
Damn you, Chris Double! Now you have me reading the Functional Programming in
Clean book. Please, don't ever answer any of my questions so helpfully again.
> From: chris.dou...@double.co.nz
> Date: Sat, 25 Aug 2012 01:39:41 +1200
> To: factor-talk@lists.sourceforge.net
> Subject: Re: [Factor-talk] Quick Question For Chris Double
>
> On Fri, Aug 24, 2012 at 11:29 PM, Michael Clagett <mclag...@hotmail.com>
> wrote:
> > Back in December of 2006 in one of your articles on Parser Combinators you
> > reference
> > a Chapter 5 on Parser Combinators from some larger work. This is a nice
> > article and it leads to wonder what the source is that it is taken from and
> > whether the surrounding chapters are any good and worth reading as well.
>
> I that that was this chapter:
>
> <http://www.bluishcoder.co.nz/II.05.ParserCombinators.pdf>
>
> It was from Part II of a book on the Clean programming language.
> Unfortunately it seems to no longer be available according to:
>
> <http://wiki.clean.cs.ru.nl/Functional_Programming_in_Clean>
>
> Luckily it's rare for things to disappear completely from the net:
>
> <http://www.mmnt.net/db/0/0/ftp.cs.kun.nl/pub/CSI/SoftwEng.FunctLang/papers/cleanbook>
>
> The case studies are a good read.
>
> Chris.
> --
> http://www.bluishcoder.co.nz
>
> ------------------------------------------------------------------------------
> 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
------------------------------------------------------------------------------
How fast is your code?
3 out of 4 devs don\\\'t know how their code performs in production.
Find out how slow your code is with AppDynamics Lite.
http://ad.doubleclick.net/clk;262219672;13503038;z?
http://info.appdynamics.com/FreeJavaPerformanceDownload.html
_______________________________________________
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk