This is the mail archive of the guile@sources.redhat.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: How should I write a program?


>>>>> "Juli-Manel" == Juli-Manel Merino Vidal <jmmv84@yahoo.com> writes:

    Juli-Manel> First of all, hi everybody cos I'm new to this list
    Juli-Manel> and guile world!!

Hello, and welcome!

    Juli-Manel> Well, my question is about how should I write a
    Juli-Manel> program that I'm developing.  Some time ago I wrote a
    Juli-Manel> simple library to use databases. Now, I want to write
    Juli-Manel> a front-end to that library, with a command
    Juli-Manel> interpreter and the ability to run scripts.

    Juli-Manel> I don't want that the user have to type scheme
    Juli-Manel> sentences in the command line, cos they are a bit
    Juli-Manel> large and are not easier as simple commands. For
    Juli-Manel> example, in the command line: (gdc) open test.gdc And
    Juli-Manel> if I'm in a script: (gdc-open "test.gdc")

I've been doing exactly this with an old graphics program that I
wanted to convert to Guile, and I've been trying to do it generically
so that most of it could be reused by applications such as yours.

So please feel free to look at and use:

http://www.ossau.uklinux.net/interactive.scm
http://www.ossau.uklinux.net/command-loop.scm
http://www.ossau.uklinux.net/filesys.scm
http://www.ossau.uklinux.net/affiche 
http://www.ossau.uklinux.net/affiche.scm

These files are roughly as follows:

interactive.scm supports the interactive reading of command arguments
in a way similar to Emacs.  It basically means that, as well as being
able to type

(gdc) open test.gdc

you'd equally be able to have the exchange

(gdc) open
Filename: test.gdc

where the "Filename: " is a prompt generated by the system.

command-loop.scm implements a command loop by reading a command symbol
(such as "open" in the example above), evaluating it in an
application-provided environment, to give a procedure, and then
calling that procedure using the call-interactively! procedure that is
provided by interactive.scm.

So the idea is that the set of valid application commands is just the
set of top level symbols in an environment that the application
provides.

interactive.scm and command-loop.scm aren't 100% complete;
e.g. command-loop.scm doesn't handle erroneous input very well yet,
and command line completion isn't implemented.  But the framework is
all there already.

filesys.scm is just some utility functions to do with the file system.

The application-specific parts are affiche, the top level executable
script, and affiche.scm, which defines the application commands for my
application (and is currently incomplete).  These are relatively small
and will hopefully indicate quite clearly how to use the command-loop
and interactive stuff - the most important point is the
run-error-catching-command-loop call in the affiche procedure.

Best wishes, and I'd love to hear if this is any use to you!

        Neil

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]