RFC: Almost a Book
billh
created: 2006-04-15 13:46:01
Hi,

I'm new here, but some of the London PerlMongers know me.

To cut to the point, I started writing a book about implementing other languages in Perl. Then the publisher went quiet. So I continued anyway. Then I got despondant, and what I have so far is here.

It's really Section 1 of 3, "Interpreters", the other two sections would be "Parsing" and "Compilation". It's unfinished, insofar as the OO extension code is done but I'm not happy with it yet, and the continuation passing interpreter is conceptual only (trampoline implementation probably).

I'm not sure if I'll finish it, but it seems such a waste to throw it all away so feel free to read, comment etc.

Re: RFC: Almost a Book
created: 2006-04-15 15:30:56

Scheme? Now that's a name I haven't heard in awhile. Got a PDF? I am not a great fan of major reading on screen.

Re^2: RFC: Almost a Book
created: 2006-04-15 16:40:15
sorry, you caught me on the hop a little there. I'm writing it in xml, with transforms to html and LaTeX, but the LaTeX transform had fallen a bit behind so I had to patch it up to make a current pdf.

Anyway, here you go.

Re: RFC: Almost a Book
created: 2006-04-15 15:42:39
BillH:

Update: I ran out of votes already. I'll remember to come back tomorrow morning and give you the first one, then!</Update>

Cool--I just read the first four sections, and I must say that I like it so far. You get my last ++ of the day! I think your pedagogy is spot on.

Now I'll have to slot out some time tomorrow to finish it off

--roboticus

Re^2: RFC: Almost a Book
created: 2006-04-15 17:27:10
Thanks!

Like I said, I'm new here so I'm not really familiar with your protocols, but votes sounds good :-)

Re^3: RFC: Almost a Book
created: 2006-04-15 21:01:24
BillH:

Update: I've just been informed that linking by [id:######] is better than by title, so I made the appropriate adjustment...</Update>

I'm relatively new here, myself, having just joined about 6 weeks ago. And I have learned that votes are good. In fact, a few of us were just chatting about PerlMonk's experience point system in the thread A Cautionary tale for Newbies “Monks don’t bite”. (I haven't done a Super Search on it, but I suspect that there are just short of a few billion threads about the XP system. One day, when I get bored, I may look 'em up!)

I don't know how long I've been on Slashdot, but I've only done 5 posts in the last 5 years. Here, the voting/XP system makes interaction a lot more fun, and eminently worthwhile. With contributions like the PScheme stuff, you'll do quite well!

--roboticus

Re: RFC: Almost a Book
created: 2006-04-16 14:02:34
I haven't done a Super Search on it, but I suspect that there are just short of a few billion threads about the XP system. One day, when I get bored, I may look 'em up!

Do yourself a favor: don't.

Most of them consist of newish users arguing, often quite strenuously, that their (sometimes rather harebrained) ideas for how to improve the XP system should be implemented, and the people who have been around for a while explaining why it either isn't practical or wouldn't be that much of an improvement. (Occasionally a good idea is suggested, in which case sometimes it is implemented (usually by tye), and sometimes not.)

Most of the rest of the XP threads consist of people (presumably people whose nodes got downvoted) complaining that everyone should not downvote them, but reply or /msg them instead. If I never see that particular complaint again, I shall consider the PM reputation system to be a success.


Sanity? Oh, yeah, I've got all kinds of sanity. In fact, I've developed whole new kinds of sanity. Why, I've got so much sanity it's driving me crazy.
Re^2: RFC: Almost a Book
created: 2006-04-16 20:47:33

There's also the occasional interesting analysis of the psychology of the voting system itself, which usually gets mistaken for a complaint about downvotes and, as a result, gets downvoted mercilessly. Those are pretty rare, though.

print substr("Just another Perl hacker", 0, -2);
- apotheon
CopyWrite Chad Perrin

Re: RFC: Almost a Book
created: 2006-04-15 17:07:30
It's very interesting indeed. I hope you'll be able to finish and publish it anyway !
Re: RFC: Almost a Book
created: 2006-04-16 14:06:46
Like others, I don't post very often so perhaps that fact will add weight to what I say (or not!) To paraphrase; Finish it and they will come... publishers that is. And for that matter make sure that you keep us all updated as I don't particularly like to wait...

--hsm

"Never try to teach a pig to sing...it wastes your time and it annoys the pig."
Re^2: RFC: Almost a Book
created: 2006-04-16 16:27:08
My personal Field of Dreams would cost me a lot of time and effort, of course that's the whole point isn't it, I guess I realised that I had committed to something when I first posted.

I will endeavour to finish it, in fact the luxury of writing without a publisher has a lot of benefits, However I'm much happier with the code (which only took me a weekend to write) than with the prose (which I've laboured over for months) and i'm desparate for some constructive criticism to help me improve it. That's the main reason for my aforementioned despondancy: I felt like I was writing in a vacuum - do all writers feel like that?

Re^3: RFC: Almost a Book
created: 2006-04-16 20:52:32

"do all writers feel like that?"
Yes, I think we do.

Lately, I've been doing a lot of short article writing for publication, and I have a personal editor past whom I run everything before submitting it for publication, so I'm not suffering under that particular burden at the moment, but I have four novels in various states of completion that are languishing on back burners in part because of that "writing in a vacuum" feeling.

print substr("Just another Perl hacker", 0, -2);
- apotheon
CopyWrite Chad Perrin

Re^3: RFC: Almost a Book
created: 2006-04-17 12:09:19
If pressed, I will admit to having been an editor. Further if it means earlly access I'd be happy to volunteer my services such as they are.

--hsm

"Never try to teach a pig to sing...it wastes your time and it annoys the pig."
Re^4: RFC: Almost a Book
created: 2006-04-17 15:22:25
early access! - I'm flattered, honestly.

I somehow thought my enthusiasms for esoterics like language implementation were shared by very few people :-)

Give me a few days to collect my thoughts and I'll get back to you on that.

Re: RFC: Almost a Book
created: 2006-04-18 01:32:35

I know some people aren't into self-publishing - you lose the benefit of an editor, etc, but I'm a big fan of it in principle - I've just never had cause to practise it. To my mind, self publishing gives power to the indiviudal in the same way that blogging does.

If you haven't looked at it already, may I suggest you have a gander at Lulu. It allows you to print on demand (POD) - so everytime someone purchases a book it gets printed and sent to them. I think this is a bit more expensive per item than traditional printing, but you don't have to worry about the cost of an initial print run. There are other POD providers, but I don't whther they are beter or worse than Lulu.

And as for editorial input, I'm sure that members here at Perlmonks would only be too happy to provide helpful feedback - especially since your book would intrigue a good number of them

Re^2: RFC: Almost a Book
created: 2006-04-18 03:25:04
One idea I'm toying with is to turn it into a collaborative effort, or at least make the online book a CGI a la the MySQL documentation, where readers can post inline comments and questions. Then I could incorporate all that iteratively.
Re: RFC: Almost a Book
created: 2006-04-19 00:36:11

I say, go for it. It's not a waste, even if you don't fint a publisher. For one thing, the mere act of writing forces you to organize your thinking, which helps you to clarify what you're doing. For another, you've got a very interesting idea going. I'd love to see how it turns out. I'm sure many others agree. I think what would be a waste is to give up after already investing so much effort into this.

If you get that book published, I'll buy a copy. So that's one sale already...

Re: RFC: Almost a Book
created: 2006-04-19 02:21:18
Looks very nice. Something that caugh my eye: did you create the UML diagrams automatically, and if so, with what tools?

I have a basic Perl5 structural grapher, implemented with the help of PPI and some not-so-evil introspection, but I haven't been able to find a good automatic layouter for class structures (although Graph::Easy does okay at times).

Re^2: RFC: Almost a Book
created: 2006-04-19 03:29:51
No, the diagrams are manually drawn (OmniGraffle on a mac)

There is a lot of support code for the listings however. I use PPI to transform the perl source into XML, with line number and "changed since last version" (delta="Y/N") attributes, then use XML::LibXML to search the listings with XPath. I pre-cache references to subroutines like this:


Then displaying a sub is just:


Also when I want to refer to a line I say:

ReadEvalPrint() on

is the central control routine of the
whole interpreter. It takes an input file handle and an output file
handle as arguments.
Starting on

it defaults the output file handle to STDOUT, ...

Also the delta attributes allow the text that changed from the previous version to be hilighted.

The upshot of all of this is that the book is pulling the code listings directly out of a working application under CVS, I don't have to cut'n'paste anything, and changes to the codebase are immediately reflected in the book. I was quite pleased about that.

Re^3: RFC: Almost a Book
created: 2006-04-19 07:39:19
Thank you for the information. I wish I had a Mac. :)
Re: RFC: Almost a Book
created: 2006-04-19 11:34:41
This is definitely an interesting project, as writing an interpreter teaches you a lot about how languages work. However, it seems almost like it's going in the wrong direction. Scheme is a pile of planks and nails, and to get any use of it you have to pound them into a language. Perl, on the other hand, is all sorts of nifty wooden doohickeys designed for common tasks. So your book is doing something like showing how to make boards out of furniture.

It would probably be more useful to write an interpreter or translator that started with all of the built-ins that Perl already has, and added something more. Two examples that come to mind are MJD's Linogram for line drawings, and PDL's PDL::PP, for fast matrix operations. Learning how to extend Perl into other domains and integrate these extensions into the language would both supply interpreter-fu and be extremely useful.

But anyways, I'm just sittin' in the peanut gallery, so who am I to say?

Re^2: RFC: Almost a Book
created: 2006-04-19 12:36:10
I think you're misunderstanding the primary motivation, which is not to produce something which is useful but something which is comprehensible, in as small a piece of code as possible. I'm perfectly happy with your assertion that scheme is not the most practical of languages for doing real work, but the real attraction of Scheme is that it is internally a thing of great beauty, like a piece of clockwork, and something that with a little effort can be grasped in its entirity.

A second reason for chosing Scheme was that the proposed "Part II" of the book, on parsing, would make a very clear distinction between the various external syntaxes of languages and a far more conservative core of internal forms, and would point out that in the case of scheme there is little or no difference between the external and the internal form (which is why it's so easy to parse).

Choosing Perl as the Implementation language was a no-brainer for me because I use it all day every day in any case; and the "Part III" on compilation could justifiably target Parrot, which would be an additional selling point.

Re^3: RFC: Almost a Book
created: 2006-04-19 12:46:48
Oh, and another reason for choosing perl, of course, Is precisely because it has all of those wonderful dohickeys that let me get on with the job in hand and don't get in the way of the explaination.
Re^3: RFC: Almost a Book
created: 2006-04-19 13:55:12
Okay, but my take is that there are already a number of well-done "write your own mini-Scheme" books out there (e.g. SICP, Lisp in Small Pieces), and countless homebrew minischeme projects on SourceForge, etc. With a built-in "read" and list-manipulating functions, it's at least as easy to parse and interpret Scheme in Scheme itself as to do it in Perl. Why recapitulate these books in Perl?

If part 2 supplied an interesting non-scheme-like language with a translation down to part 1's scheme-like one, the book might stand out more. I dunno. I'm not really the target audience for this, so maybe I don't have a good feel for what would be interesting.

Re^4: RFC: Almost a Book
created: 2006-04-19 15:27:22
> there are already a number of well-done "write your own mini-Scheme" books out there

Point taken, but a Perl implementation has an advantage over C for understanding an implementation because it's much higher level, and over Scheme because there's no incestuous metacircular evaluation to confuse things.

Secondly, yes, you hit the nail on the head about syntax because the Parsing section would use the existing evaluator as a target with new, alternative and interesting syntax, certainly better than those "Pratt parsers" that I've seen. Syntax aesthetics is often ignored in hard CS texts.

Finally the third section on compilation would generate Parrot, making the use of Perl in the other sections doubly relevant, but I said that already.

Re^5: RFC: Almost a Book
created: 2006-05-05 18:54:03
Finally the third section on compilation would generate Parrot...

There are a couple of attempts in progress to port Scheme (or something Scheme-like) to Parrot. Pheme, for example, is far enough along to have exposed a few bugs in Parrot.

perlmonks.org content © perlmonks.org and apotheon, astroboy, billh, chromatic, educated_foo, hsmyers, jonadab, Marza, roboticus, spiritway, wazoox, wolv

prlmnks.org © 2006 edmund von der burg (eccles & toad)

v 0.03