This is the mail archive of the guile@sourceware.cygnus.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: Translators/source language detection


Jim Blandy <jimb@red-bean.com> writes:

> So I think Guile should have a function (generic-load "FOO"),
> that tries different extensions and chooses a translator
> appropriately.  Then we can use that for loading .guile files,
> ~/.someapp/prefs, and so on.

This would easily solve about all problems so far.  It's not
really necessary to read/eval foreign code seperately (though it
could come in handy sometimes), other languages rarely make it
possible to do so.

The original design was to be able to read any language, and have
scheme come out.  This seems to be too difficult most of the
time.

Actually, it would be nice to have a

(eval-port language #&optional port)

That would allow us to write a module which provides:

- (register-language langname eval-proc)

  langname (symbol)
	the name of the language
  eval-proc (proc port environment)
	a proc which evaluates the language code read from port
	in environment until it reads an eof-object?

- (register-extension langname extension)

  langname (symbol)
	the name of the language
  ext (string)
	the extension for which to use the language named above

- (generic-load filename #&optional environment)

  filename
	the filename. the proc can deduce the language to use
	according to the registered languages (see above)
  environment
	in which environment to evaluate the code

and last but not least:

(define (eval-string language string . environment)
  (call-with-input-string
   string
   (lambda (port)
     ((language->eval language) 
      port
      (if (null? environment)
	  (the-environment)
	  (car environment))))))


with such a module in place, new languages can be added easily,
and smoothly.  (this breaks a useful idea i had for mod_guile,
but oh well, i can change that, it's not the best solution,
anyways)

And btw, it would make sense to overload (load) -- just not in
the R5RS core, but in some module.

hth,
	-- forcer

-- 
((email . "forcer@mindless.com")       (www . "http://forcix.cx/")
 (irc   . "forcer@#StarWars (IRCnet)") (gpg . "/other/forcer.gpg"))

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