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: thanks


dirk@ida.ing.tu-bs.de writes:
> > providing an interface that doesn't dump core when you pass it the
> > wrong type of argument?
> 
> The problem with this is, that if you have to use a different interface,
> you will have to change your code after debugging in order to get the best
> possible performance.  On the other hand, providing extensive type
> checking as a default within libguile (independent of whether this is done 
> in the gh_ or the scm_ part of the library) will also not be desired by
> many users.

Some more thinking about this leads me to the following question:
isn't there a generic way of attaching type signatures to  Scheme
functions? How do Scheme compilers cope with this?

The reason why I ask this, is that doing typechecking in a less
kludged way than this

	> One possible solution might be something like:
	> fscm_car(...)  /* fscm = fast scm */
	> {
	>     don't do any type checking at all
	> }
	> 
	> sscm_car(...)  /* sscm = secure scm */
	> {
	>     perform extensive type checking on the parameters and then call
	>     fscm_car(...);
	> }

needs a generic way of identifying types.  The generic approach is
that every (C-) function definition is accompanied by a type signature
(or, at least a predicate that returns false if the type is
wrong). Every time a C-primitive procedure is called, the associated
type predicate is also checked.  If you want speed, you can turn off
this typechecking.

In other words, I propose


      typedef struct {

	      ...

	     SCM (*func)(..);
	     SCM (*type_p)(SCM args);
	     char const *name;
      } scm_subr_entry;

      SCM
      call_c_procedure (scm_subr_entry * desc, SCM args)
      {
	if (debug_types)
	   {
		SCM check = (*desc->type_p )(args);
		if(check != SCM_BOOL_T)
			 {
			 printf ("error in arg to function %s: ",
			       desc->name);
			 printf ("%s", gh_scm2newstr0 (check))
			 }
	   }

	return (*desc->func)(args);
      }

Would this be worth the effort?  It could possibly clean up some of
the code, moving lots of SCM_ASSERT calls out of function bodies. It
allows both speed and debuggability.  The big contra, is that
including checks is extra expensive, since there is a lot of code
looking like

	SCM_ASSERT(SCM_INUMP(k), k, SCM_ARG2, s_list_ref);
	i = SCM_INUM(k);
	SCM_ASSERT(i >= 0, k, SCM_ARG2, s_list_ref);
	
(where the 2nd check uses an intermediate result I of the body).


Anyways, now that I am thinking longer about the subject, I realise
that type checking/inferencing is a hairy subject (decidability comes
around the corner, iirc), so anything more fancy than this probably
isn't worth the effort.

I'll stop now, the Haskell addicts live two floors lower in the CS
building.




-- 

Han-Wen Nienhuys, hanwen@cs.uu.nl ** GNU LilyPond - The Music Typesetter 
      http://www.cs.uu.nl/people/hanwen/lilypond/index.html 


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