[plt-scheme] MzScheme as embedded engine for LilyPond ?

From: Han-Wen Nienhuys (hanwen at xs4all.nl)
Date: Thu Feb 3 18:37:32 EST 2005

eli at barzilay.org writes:
> I cannot reply to everything but I'll do some.  Specifically, I don't
> have experience with using mzscheme as an embedded application -- just
> with extending mzscheme itself, but it should be similar.  (Someone
> please correct me if this is wrong.)

Thanks for you consideration. 

> On Feb  3, Han-Wen Nienhuys wrote:
> > * How well is embedding MzScheme supported? I've read "Inside PLT
> >   MzScheme". Am I correct that there is no way to add "coded" types
> >   to MzScheme?
> 
> There is -- you need to define some struct that has `Scheme_Object' as
> its first field (I'm talking about v299), something like this 
> 
>   static Scheme_Type foo_tag;
>   typedef struct foo_struct {
>     Scheme_Object so;
>     int x;
>     void* p;
>   } foo_struct;
> 
> and you need to initialize foo_tag like this:
> 
>   foo_tag = scheme_make_type("<foo>");

Does MzScheme know to mark SO because it's the first object, or
because it's aligned? Oh wait, MzScheme uses Boehm GC, and Boehm GC is
fully conservative, so I shouldn't worry about marking. 

OTOH, I've understood that the internal types of MzScheme apply FIXUP
macros to their Scheme_Object, for moving about data in copying
collectors.

Is there a reason for maintaining that difference? iow: why can't I
define my own mark function so my types work exactly like the internal
ones?

> > * Is there a possibility to read a single expression precisely off
> >   an input stream?
> 
> You mean using `read'?  Of course.

OK. So I need to setup a port for every # expression I get.

> >   In LilyPond input files, you can escape to Scheme, using # , for
> >   example:
> > 
> >     \score { #(make-music 'NoteEvent) }
> > 
> >   here, the lexer gives control to the Scheme interpreter when it
> >   reaches # . The Scheme interpreter reads up to the ) and evals the
> >   result. The lexer then continues at the )
> > 
> >   Is this somehow possible with MzScheme? 
> 
> Yes -- there is a library (parser-tools) that provides you with
> lex/yacc-like tools.  If you want something that makes heavy use of

No, that's not what I need. We already have a fully fleshed Yacc/Lex
system. We just need a Scheme system that jibes with it.

> > * Is there support for read extensions?  We have a special feature,
> >   that allows us to parse LilyPond code inside one of these embedded
> >   Scheme fragments, for example
> 
> There is no real reader extension support, 

is it planned? 

> but using the preprocessor
> it is easy to modify things when you load modules (mztext which is one
> component has a similar approach, where some command character is used
> to dispatch to different handlers).  But if you only need to escape
> from LilyPond to Scheme and back, then you don't need to change the
> syntax dynamically...

Correct. So, I have to look at mztext.

> 
> 
> > * Is there support for stack-traces/source annotation?  If I make an
> >   error in GUILE in debug mode, I get 
> > 
> > 	byrd:~/usr/src/lilypond$ guile --debug b.scm
> > 	Backtrace:
> > 	In unknown file:
> > 	   ?: 0* [primitive-load "b.scm"]
> > 	In b.scm:
> > 	   9: 1* [Y]
> > 	   7: 2  [x 0]
> > 	   3: 3  [0]
> > 
> > 	b.scm:3:3: In expression (a):
> > 	b.scm:3:3: Wrong type to apply: 0
> > 
> >   a nice stack trace, with line/column numbers of the calling points.
> > 
> >   How do I get that in MzScheme?  I've understood that this is only
> >   supported in DrScheme, but I need to switch between both modes on
> >   the fly. In other words,
> > 
> >     lilypond --debug foo.ly
> > 
> >   would use the MzScheme with locations, and 
> > 
> >     lilypond foo.ly
> >  
> >   would use the non-debugging version.  Is this possible at all?
> 
> mzscheme -M errortrace

This produces line/column numbers, but no stacktrace, for the above
example, I now get 

	byrd:~/usr/src/lilypond$ mzscheme -M errortrace -f b.scm
	Welcome to MzScheme version 209, Copyright (c) 2004 PLT Scheme, Inc.
	procedure application: expected procedure, given: 0 (no arguments)
	/home/hanwen/usr/src/savannah/lily/lilypond/b.scm:3:2: (a)

> > * Is there support for doc strings and self-documentation?  In
> >   LilyPond, almost all coded subroutines come with docstrings, and
> >   would show up if you did
> > 
> >     (apropos "ly:music?")
> 
> There is no standard facility for docstrings.  Cooking one up is
> really simple, but the common approach is to provide documentation
> that is used with Help-Desk.

OK.

-- 

 Han-Wen Nienhuys   |   hanwen at xs4all.nl   |   http://www.xs4all.nl/~hanwen 



Posted on the users mailing list.