guile-user
[Top][All Lists]
Advanced

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

Re: [guile/scwm] 2nd argument problem to scm_definedp()


From: P Pareit
Subject: Re: [guile/scwm] 2nd argument problem to scm_definedp()
Date: Tue, 17 Sep 2002 11:25:17 +0200
User-agent: KMail/1.4.2

On Monday 16 September 2002 09:42 pm, Marius Vollmer wrote:
> P Pareit <address@hidden> writes:
> > The c-code that modifies %load-path looks like creating %load-path
> > in stead of adding strings to %load-path.
>
> Can you show that code?
>

/* in a header */
#define SCWM_VAR(cvar, name) \
  do { pscm_ ## cvar = SCM_CDRLOC( \
      scm_sysintern0(name) ); } while (0)

/* in a source file */
void init_scwm_load_path()
{
  SCM *pscm_pct_load_path;
  SCM path;

  SCWM_VAR(pct_load_path,"%load-path");
  /** The internal compiled-in loading path for scwm. */

  path = *pscm_pct_load_path;
  path = gh_cons(gh_str02scm(SCWM_LOAD_PATH),path);
  path = gh_cons(gh_str02scm(SCWM_BIN_LOAD_PATH),path);
  path = scm_internal_parse_path(getenv("SCWM_LOAD_PATH"), path);
  *pscm_pct_load_path = path;
}

SCWM_LOAD_PATH and SCWM_LOAD_PATH get set by cpp to things like 
"/usr/local/share/scwm/modules".

> > I would first like to know if %load-path is
> > already defined, in scheme code this would be: (and (defined? %load-path)
> > (display "%load-path is defined") (newline)), it seems I cannot get the
> > argument for _current_lexical_environment_ right:
>
> If you want to default an optional argument from C, use SCM_UNDEFINED:
>
>   if (SCM_NFALSEP (scm_definedp (load_path_symbol, SCM_UNDEFINED)))
>     ...
>
> I guess you want the default.  If not, things get messy.  The lexical
> environment that definedp expects is the data structure that gets
> passed as the second argument to macro transformers.

Yes, I want the default. I was trying to do do something like this:
(set! %load-path (cons "/usr/.../modules" %load-path)) in c-code to replace 
the code given. But I run into the same problems with my code:

address@hidden mkhk]$ ./test -c "(display %load-path) (newline)"
(/usr/local/share/scwm/modules . #<variable 806b120 binding: 
(/usr/share/guile/site /usr/share/guile/1.6.0 /usr/share/guile .)>)
address@hidden mkhk]$ cat main.c

#include <stdio.h>
#include <libguile.h>

void init_load_path(void)
{
  SCM path;

  path = scm_c_lookup("%load-path");
  path = scm_cons(scm_makfrom0str("/usr/local/share/scwm/modules"),
                  path);
  scm_c_define("%load-path", path);
}

void inner_main(void* closure, int argc, char** argv)
{
  init_load_path();
  scm_shell(argc, argv);
}

int main(int argc, char* argv[])
{
  scm_boot_guile(argc, argv, inner_main, NULL);
}

I must also note that I did not find documentation on scm_makfrom0str(), 
except on what I found in the header files. The reason that I'm using scm_*() 
instead of the original gh_*() functions is because they are no longer 
supported so whenever I have to change something I use the scm_* interface.
It seems I have a problem to get the value of an scheme variable in c-code 
right now.

pieter;




reply via email to

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