[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Newbie seeks guiding hands.

From: Gary Benson
Subject: Re: Newbie seeks guiding hands.
Date: Thu, 15 Mar 2001 10:35:09 +0000

On Thu, 15 Mar 2001, Martin Grabmueller wrote:

> > From: Gary Benson <address@hidden>
> > Date: Wed, 14 Mar 2001 17:20:12 +0000
> >
> > I'm almost completely new to both Guile and Scheme but I think they
> > could be incredibly useful for a project I am involved in. I've got a
> > couple of questions, one quick and one not so quick.
> >
> > The quick one: what is the difference between Scheme and Lisp?
> Well, short question -- long answer...  if you have questions left,
> feel free to ask more detailed questions.

Someone pointed me in the direction of R5RS (which is challenging my
perception of programming in general) and `Teach yourself Scheme in
fixnum days'. I may well have more detailed questions in a couple of
days ;-)

> [I didn't look at rcalc yet, but will try to give a few hints though]
> > Secondly (and will probably resolve itself as I get more into Scheme), I
> > don't know where to make the split between the C and Guile parts. Do I
> > code each function as a separate scm file and do all the other stuff in
> > C or do I rewrite the calculation engine in Scheme?
> It depends (of course): If you just want to add the ability to call
> user-defined functions, you wouldn't have to write any Scheme code
> yourself.  You could (for example) read a user's initialization file,
> which defines functions. Then you would have to modify rcalc's
> evaluator to call these functions when they appear in the input.
> I image a scenario like this:
> 1. The user defines a function in her .rcalcrc 
>    (define (myfunc x)
>      (* 2 x))
> 2. The user types in an expression, e.g
>    1 + myfunc(2.4)
> 3. Your evaluator sees the call to `myfunc', and calls Guile to
>    evaluate the call `(myfunc 2.4)'.   
> 4. Guile returns the value `4.8'.
> 5. You evaluator calculates the rest of the expression and outputs
>    `5.8'.

This was my original plan, but see below...

> Another possibility would be to translate the input the user types
> into Scheme expressions and then use Guile for evaluating them. That
> would give you access to all the math functions already contained in 
> Guile. That would mean
> 3. The expression  is translated to
>    `(+ 1 (myfunc 2.4))'
> 4. Guile is used to calculate the value `5.8'.
> 5. Your application outputs the result.

rcalc translates from `1 + myfunc(2.4)' to `(+ 1 (myfunc 2.4))' anyway!
>From reading R5RS I get the impression that I can create a string
(external representation) that says "(+ 1 (myfunc 2.4))" and execute it.
However the process to convert from infix notation (ie "1 +
myfunc(2.4)") to postfix (ie "(+ 1 (myfunc 2.4))") would probably be a
lot nicer written in Scheme than in C: there's lots of recursive stack
bashing going on. So I might regress your points 3, 4 and 5 to:

3. Guile translates the expression "1 + myfunc(2.4)" (or at least a
tokenised version of it) into postfix and evaluates it.

4. rcalc outputs the result.

The only problem I can see with this method -- effectively translating
rcalc's minilanguage into Scheme and evaluating it - is the error
reporting. Rcalc is supposed to be a nice, user friendly program, and
one facet of that is that it makes nice, descriptive error
messages.Whether this is possible depends really on how much
information you can get out of the Guile engine.

One further question I thought of: how does Guile handle
internationalisation? Specifically of messages displayed by the Scheme
part of rcalc. This may be a question that could be handled by poking
aroung in Gnucash (since rcalc is a GNOME program as well), but if
anyone has any `high-level' knowledge then that would be welcome.

> >                                                      Applications that
> > get to the point of embedding Guile tend to be massive already, which
> > means that there is a hell of a lot of code to hunt through to find the
> > relevant bits. It would probably take me a week, working solidly, to
> > understand how something like Gnucash does its stuff.
> Note that Gnucash does more than using Guile just for simple
> user-extension.  A lot of Gnucash is written in Scheme, so it maybe is
> more like Emacs in that respect [Gnucash experts: Please correct me if
> I'm wrong].

This is the direction I am leaning in myself. I don't know much about
Gnucash, but I do know that most of the reason Emacs is so flexible is
that it isn't so much `extended by' as `written in' Emacs-lisp.

That's all for now,

[ address@hidden ][ PGP 85A8F78B ][ ]

reply via email to

[Prev in Thread] Current Thread [Next in Thread]