This is the mail archive of the guile@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]

Generalized set!


F.Y.I.: The development snapshot now contains a generalized set!.

The generalized set! macro is the default.  When we have modularized
Guile, it will be easy to create a module containing the R5RS one.

I think it is important that the generalized set! is the default one
since we want to regard it as a standard part of the Guile language.

Also, when we load the object system (which depends on the generalized
set!), we don't want the behaviour of set! to change.

(For those who are worried what impact this may have on the
implementation can look below.)


Note that I finally followed Maciej and others'  advice regarding the
order of arguments.  It is most intuitive to have the expansion:

  (set! (PWS A1 ...) V) --> ((SETTER PWS) A1 ... V)

and it has the advantage of working with all setters except the
current array-set! which I think should be modified.

>From eval.c:

SCM
scm_m_set_x (xorig, env)
     SCM xorig;
     SCM env;
{
  SCM x = SCM_CDR (xorig);
  SCM_ASSYNT (2 == scm_ilength (x), xorig, scm_s_expression, scm_s_set_x);
  SCM_ASSYNT (SCM_NIMP (SCM_CAR (x)) && SCM_SYMBOLP (SCM_CAR (x)),
        xorig, scm_s_variable, scm_s_set_x);
  return scm_cons (SCM_IM_SET_X, x);
}

>From evalext.c:

SCM
scm_m_generalized_set_x (SCM xorig, SCM env)
{
  SCM x = SCM_CDR (xorig);
  SCM_ASSYNT (2 == scm_ilength (x), xorig, scm_s_expression, scm_s_set_x);
  if (SCM_NIMP (SCM_CAR (x)) && SCM_SYMBOLP (SCM_CAR (x)))
    return scm_cons (SCM_IM_SET_X, x);
  else if (SCM_NIMP (SCM_CAR (x)) && SCM_CONSP (SCM_CAR (x)))
    return scm_cons (SCM_LIST2 (scm_sym_setter, SCM_CAAR (x)),
	        scm_append (SCM_LIST2 (SCM_CDAR (x), SCM_CDR (x))));
  return scm_wta (xorig, scm_s_variable, scm_s_set_x);
}