* [guile/scwm] 2nd argument problem to scm_definedp()
@ 2002-09-16 18:49 P Pareit
2002-09-16 19:42 ` Marius Vollmer
2002-09-16 19:49 ` Rob Browning
0 siblings, 2 replies; 15+ messages in thread
From: P Pareit @ 2002-09-16 18:49 UTC (permalink / raw)
Hey,
Scwm is running but modules do not get loaded. I get an error like:
Error loading module: no code for module.
It looks like %load-path is messed up, %load-path gives me:
("/usr/local/scwm/modules/" %load-path . 0)
The c-code that modifies %load-path looks like creating %load-path in stead of
adding strings to %load-path. 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 (SCM_NFALSEP(scm_definedp(load_path_symbol,
scm_interaction_environment()))) { /* print */ }
or
if (SCM_NFALSEP(scm_definedp(load_path_symbol, scm_current_module()))) { /*
print */ }
give me both:
ERROR: In procedure defined?:
ERROR: Wrong type argument in position 2: #<directory (guile-user) 8084560>
So what argument should I use?
pieter;
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [guile/scwm] 2nd argument problem to scm_definedp()
2002-09-16 18:49 [guile/scwm] 2nd argument problem to scm_definedp() P Pareit
@ 2002-09-16 19:42 ` Marius Vollmer
2002-09-16 19:55 ` Rob Browning
2002-09-17 9:25 ` P Pareit
2002-09-16 19:49 ` Rob Browning
1 sibling, 2 replies; 15+ messages in thread
From: Marius Vollmer @ 2002-09-16 19:42 UTC (permalink / raw)
Cc: guile-user
P Pareit <pieter.pareit@planetinternet.be> 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?
> 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.
--
GPG: D5D4E405 - 2F9B BCCC 8527 692A 04E3 331E FAF8 226A D5D4 E405
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [guile/scwm] 2nd argument problem to scm_definedp()
2002-09-16 18:49 [guile/scwm] 2nd argument problem to scm_definedp() P Pareit
2002-09-16 19:42 ` Marius Vollmer
@ 2002-09-16 19:49 ` Rob Browning
2002-09-16 19:53 ` Rob Browning
1 sibling, 1 reply; 15+ messages in thread
From: Rob Browning @ 2002-09-16 19:49 UTC (permalink / raw)
Cc: guile-user
P Pareit <pieter.pareit@planetinternet.be> writes:
> I would first like to know if %load-path is already defined
It should be.
In generally you usually just augment %load-path
(set! %load-path (cons "foo" %load-path))
or
(set! %load-path (append %load-path '("foo")))
You might also want to filter it or something. I'd suspect the cases
where it would make sense to set it from scratch are extremely rare.
> (SCM_NFALSEP(scm_definedp(load_path_symbol,
> scm_interaction_environment()))) { /* print */ } or if
> (SCM_NFALSEP(scm_definedp(load_path_symbol, scm_current_module())))
> { /* print */ } give me both: ERROR: In procedure defined?: ERROR:
> Wrong type argument in position 2: #<directory (guile-user) 8084560>
> So what argument should I use?
I believe scm_definedp takes an environment as the second argument
rather than a module. I'm not sure offhand how to get the environment
from a module, but I suspect this is it:
scm_definedp (load_path_sym,
scm_module_lookup_closure (scm_current_module));
I suspect Marius can correct me if I'm wrong.
--
Rob Browning
rlb @defaultvalue.org, @linuxdevel.com, and @debian.org
Previously @cs.utexas.edu
GPG=1C58 8B2C FB5E 3F64 EA5C 64AE 78FE E5FE F0CB A0AD
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [guile/scwm] 2nd argument problem to scm_definedp()
2002-09-16 19:49 ` Rob Browning
@ 2002-09-16 19:53 ` Rob Browning
2002-09-16 20:22 ` Marius Vollmer
0 siblings, 1 reply; 15+ messages in thread
From: Rob Browning @ 2002-09-16 19:53 UTC (permalink / raw)
Cc: guile-user
Rob Browning <rlb@defaultvalue.org> writes:
>
> scm_definedp (load_path_sym,
> scm_module_lookup_closure (scm_current_module));
Oops, that should have been
scm_definedp (load_path_sym,
scm_module_lookup_closure (scm_current_module ()));
but judging from Marius' other comment, this may be wrong altogether.
--
Rob Browning
rlb @defaultvalue.org, @linuxdevel.com, and @debian.org
Previously @cs.utexas.edu
GPG=1C58 8B2C FB5E 3F64 EA5C 64AE 78FE E5FE F0CB A0AD
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [guile/scwm] 2nd argument problem to scm_definedp()
2002-09-16 19:42 ` Marius Vollmer
@ 2002-09-16 19:55 ` Rob Browning
2002-09-16 20:24 ` Marius Vollmer
2002-09-17 9:25 ` rm
2002-09-17 9:25 ` P Pareit
1 sibling, 2 replies; 15+ messages in thread
From: Rob Browning @ 2002-09-16 19:55 UTC (permalink / raw)
Cc: P Pareit, guile-user
Marius Vollmer <mvo@zagadka.ping.de> writes:
> 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.
Do we have anything like
scm_defined_in_modulep (sym, module)
If not, should we? (ISTR some discussion about this a while back...)
--
Rob Browning
rlb @defaultvalue.org, @linuxdevel.com, and @debian.org
Previously @cs.utexas.edu
GPG=1C58 8B2C FB5E 3F64 EA5C 64AE 78FE E5FE F0CB A0AD
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [guile/scwm] 2nd argument problem to scm_definedp()
2002-09-16 19:53 ` Rob Browning
@ 2002-09-16 20:22 ` Marius Vollmer
2002-09-16 20:25 ` Rob Browning
2002-09-17 16:00 ` Rob Browning
0 siblings, 2 replies; 15+ messages in thread
From: Marius Vollmer @ 2002-09-16 20:22 UTC (permalink / raw)
Cc: P Pareit, guile-user
Rob Browning <rlb@defaultvalue.org> writes:
> scm_definedp (load_path_sym,
> scm_module_lookup_closure (scm_current_module ()));
>
> but judging from Marius' other comment, this may be wrong altogether.
Close! :-)
scm_definedp (load_path_sym,
scm_top_level_env (
scm_module_lookup_closure (scm_current_module ())));
But I would not recommend using this. Better lobby us to include a
real scm_c_module_defined_p function.
--
GPG: D5D4E405 - 2F9B BCCC 8527 692A 04E3 331E FAF8 226A D5D4 E405
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [guile/scwm] 2nd argument problem to scm_definedp()
2002-09-16 19:55 ` Rob Browning
@ 2002-09-16 20:24 ` Marius Vollmer
2002-09-17 9:25 ` rm
1 sibling, 0 replies; 15+ messages in thread
From: Marius Vollmer @ 2002-09-16 20:24 UTC (permalink / raw)
Cc: P Pareit, guile-user
Rob Browning <rlb@defaultvalue.org> writes:
> Do we have anything like
>
> scm_defined_in_modulep (sym, module)
>
> If not, should we? (ISTR some discussion about this a while back...)
I think we should have it.
--
GPG: D5D4E405 - 2F9B BCCC 8527 692A 04E3 331E FAF8 226A D5D4 E405
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [guile/scwm] 2nd argument problem to scm_definedp()
2002-09-16 20:22 ` Marius Vollmer
@ 2002-09-16 20:25 ` Rob Browning
2002-09-17 16:00 ` Rob Browning
1 sibling, 0 replies; 15+ messages in thread
From: Rob Browning @ 2002-09-16 20:25 UTC (permalink / raw)
Cc: P Pareit, guile-user
Marius Vollmer <mvo@zagadka.ping.de> writes:
> scm_definedp (load_path_sym,
> scm_top_level_env (
> scm_module_lookup_closure (scm_current_module ())));
>
> But I would not recommend using this. Better lobby us to include a
> real scm_c_module_defined_p function.
Yeah. This seems a bit too dependent on implementation details for
the long term.
--
Rob Browning
rlb @defaultvalue.org, @linuxdevel.com, and @debian.org
Previously @cs.utexas.edu
GPG=1C58 8B2C FB5E 3F64 EA5C 64AE 78FE E5FE F0CB A0AD
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [guile/scwm] 2nd argument problem to scm_definedp()
2002-09-16 19:55 ` Rob Browning
2002-09-16 20:24 ` Marius Vollmer
@ 2002-09-17 9:25 ` rm
2002-09-17 21:51 ` Marius Vollmer
1 sibling, 1 reply; 15+ messages in thread
From: rm @ 2002-09-17 9:25 UTC (permalink / raw)
Cc: Marius Vollmer, P Pareit, guile-user
On Mon, Sep 16, 2002 at 02:55:03PM -0500, Rob Browning wrote:
> [...]
>
> Do we have anything like
>
> scm_defined_in_modulep (sym, module)
Oh yes, please! <jumping-in-exitement/>
Ralf Mattes
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [guile/scwm] 2nd argument problem to scm_definedp()
2002-09-16 19:42 ` Marius Vollmer
2002-09-16 19:55 ` Rob Browning
@ 2002-09-17 9:25 ` P Pareit
2002-09-17 13:53 ` P Pareit
1 sibling, 1 reply; 15+ messages in thread
From: P Pareit @ 2002-09-17 9:25 UTC (permalink / raw)
On Monday 16 September 2002 09:42 pm, Marius Vollmer wrote:
> P Pareit <pieter.pareit@planetinternet.be> 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:
[ppareit@localhost 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 .)>)
[ppareit@localhost 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;
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [guile/scwm] 2nd argument problem to scm_definedp()
2002-09-17 9:25 ` P Pareit
@ 2002-09-17 13:53 ` P Pareit
2002-09-17 21:38 ` Marius Vollmer
0 siblings, 1 reply; 15+ messages in thread
From: P Pareit @ 2002-09-17 13:53 UTC (permalink / raw)
On Tuesday 17 September 2002 11:25 am, P Pareit wrote:
<snip>
> #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);
> }
Thanks to the help of dsmith, this is already fixed:
void init_load_path(void)
{
SCM path = scm_c_lookup("%load-path");
SCM_VARIABLE_SET(path,
scm_cons(scm_makfrom0str("/usr/local/share/scwm/modules"),
SCM_VARIABLE_REF(path)));
}
Maybe someone can document SCM_VARIABLE_SET and SCM_VARIABLE_REF?
pieter;
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [guile/scwm] 2nd argument problem to scm_definedp()
2002-09-16 20:22 ` Marius Vollmer
2002-09-16 20:25 ` Rob Browning
@ 2002-09-17 16:00 ` Rob Browning
2002-09-17 21:50 ` Marius Vollmer
1 sibling, 1 reply; 15+ messages in thread
From: Rob Browning @ 2002-09-17 16:00 UTC (permalink / raw)
Cc: P Pareit, guile-user
Marius Vollmer <mvo@zagadka.ping.de> writes:
> scm_definedp (load_path_sym,
> scm_top_level_env (
> scm_module_lookup_closure (scm_current_module ())));
>
> But I would not recommend using this. Better lobby us to include a
> real scm_c_module_defined_p function.
Why did we decide not to just have scm_module_lookup return SCM_BOOL_F
if the variable wasn't defined? That seems more flexible. I think
there was some reason, but I can't reecall it at the moment. i.e.
SCM
scm_module_lookup (SCM module, SCM sym)
#define FUNC_NAME "module-lookup"
{
SCM var;
SCM_VALIDATE_MODULE (1, module);
var = scm_sym2var (sym, scm_module_lookup_closure (module), SCM_BOOL_F);
return var;
}
#undef FUNC_NAME
alternately, if that's not OK, how about:
SCM
scm_module_symbol_defined_p (SCM module, SCM sym)
#define FUNC_NAME "module-symbol-defined?"
{
SCM var;
SCM_VALIDATE_MODULE (1, module);
var = scm_sym2var (sym, scm_module_lookup_closure (module), SCM_BOOL_F);
if (SCM_FALSEP (var))
return SCM_BOOL_F;
else
return SCM_BOOL_T;
}
#undef FUNC_NAME
Though this is wasteful in cases where you want to know if the value
is defined *and* use it if it is.
--
Rob Browning
rlb @defaultvalue.org, @linuxdevel.com, and @debian.org
Previously @cs.utexas.edu
GPG=1C58 8B2C FB5E 3F64 EA5C 64AE 78FE E5FE F0CB A0AD
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [guile/scwm] 2nd argument problem to scm_definedp()
2002-09-17 13:53 ` P Pareit
@ 2002-09-17 21:38 ` Marius Vollmer
0 siblings, 0 replies; 15+ messages in thread
From: Marius Vollmer @ 2002-09-17 21:38 UTC (permalink / raw)
Cc: guile-user
P Pareit <pieter.pareit@planetinternet.be> writes:
> Maybe someone can document SCM_VARIABLE_SET and SCM_VARIABLE_REF?
Hmm, scm_variable_ref and scm_variable_set are documented so you might
want to use those. SCM_VARIABLE_SET and SCM_VARIABLE_REF are
performance hacks that are not really useful when used only one time.
We will document these performance hacks, but that should probably
best happen together with other performance hacks (if there are any
that are undocumented...)
--
GPG: D5D4E405 - 2F9B BCCC 8527 692A 04E3 331E FAF8 226A D5D4 E405
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [guile/scwm] 2nd argument problem to scm_definedp()
2002-09-17 16:00 ` Rob Browning
@ 2002-09-17 21:50 ` Marius Vollmer
0 siblings, 0 replies; 15+ messages in thread
From: Marius Vollmer @ 2002-09-17 21:50 UTC (permalink / raw)
Cc: P Pareit, guile-user
Rob Browning <rlb@defaultvalue.org> writes:
> Why did we decide not to just have scm_module_lookup return SCM_BOOL_F
> if the variable wasn't defined? That seems more flexible. I think
> there was some reason, but I can't reecall it at the moment. i.e.
The reasoning was, if I remember correctly, that making
scm_module_lookup issue the error message will make that error message
more uniform and it will also make it easier for people to use
scm_module_lookup correctly in the 'usual' situation.
We can have a second function thta behaves differently. That function
should also be able to return non-variables (like the mythical macro
transformers).
--
GPG: D5D4E405 - 2F9B BCCC 8527 692A 04E3 331E FAF8 226A D5D4 E405
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [guile/scwm] 2nd argument problem to scm_definedp()
2002-09-17 9:25 ` rm
@ 2002-09-17 21:51 ` Marius Vollmer
0 siblings, 0 replies; 15+ messages in thread
From: Marius Vollmer @ 2002-09-17 21:51 UTC (permalink / raw)
Cc: Rob Browning, P Pareit, guile-user
rm@fabula.de writes:
> On Mon, Sep 16, 2002 at 02:55:03PM -0500, Rob Browning wrote:
> > [...]
> >
> > Do we have anything like
> >
> > scm_defined_in_modulep (sym, module)
>
> Oh yes, please! <jumping-in-exitement/>
So send the patch already! :-)
--
GPG: D5D4E405 - 2F9B BCCC 8527 692A 04E3 331E FAF8 226A D5D4 E405
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2002-09-17 21:51 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-09-16 18:49 [guile/scwm] 2nd argument problem to scm_definedp() P Pareit
2002-09-16 19:42 ` Marius Vollmer
2002-09-16 19:55 ` Rob Browning
2002-09-16 20:24 ` Marius Vollmer
2002-09-17 9:25 ` rm
2002-09-17 21:51 ` Marius Vollmer
2002-09-17 9:25 ` P Pareit
2002-09-17 13:53 ` P Pareit
2002-09-17 21:38 ` Marius Vollmer
2002-09-16 19:49 ` Rob Browning
2002-09-16 19:53 ` Rob Browning
2002-09-16 20:22 ` Marius Vollmer
2002-09-16 20:25 ` Rob Browning
2002-09-17 16:00 ` Rob Browning
2002-09-17 21:50 ` Marius Vollmer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).