* make-module question.
@ 2010-08-10 19:25 Ian Hulin
2010-08-18 14:03 ` Ludovic Courtès
0 siblings, 1 reply; 6+ messages in thread
From: Ian Hulin @ 2010-08-10 19:25 UTC (permalink / raw)
To: guile-user
Hi all,
(make-module) doesn't seem to appear in the documentation, Is it
supported, discouraged or deprecated?
We use it in the Lilypond/Guile interface code but we use it by doing a
lookup and effectively scm_eval the result. I notice it appears in the
shim code Andy supplied to support module-export-all! for V1.8.7.
Is there a supported scm_make_module we can use in the Guile API, and
if not, is it safe to use
SCM scm_make_module_x = SCM_EOL;
scm_permanent_object (scm_c_lookup ("make-module"));
and then do
scm_call_0( SCM_VARIABLE_REF (scm_make_module_x)):
?
Also what are the args the REPL says you can supply to (make-module) ?.
Cheers,
Ian Hulin
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: make-module question.
2010-08-10 19:25 make-module question Ian Hulin
@ 2010-08-18 14:03 ` Ludovic Courtès
2010-08-18 21:35 ` Ian Hulin
0 siblings, 1 reply; 6+ messages in thread
From: Ludovic Courtès @ 2010-08-18 14:03 UTC (permalink / raw)
To: guile-user
Hi!
Ian Hulin <ian@hulin.org.uk> writes:
> (make-module) doesn't seem to appear in the documentation, Is it
> supported, discouraged or deprecated?
It is undocumented but safe to use.
> Is there a supported scm_make_module we can use in the Guile API, and
> if not, is it safe to use
>
> SCM scm_make_module_x = SCM_EOL;
> scm_permanent_object (scm_c_lookup ("make-module"));
> and then do
> scm_call_0( SCM_VARIABLE_REF (scm_make_module_x)):
> ?
Yes, you can do this. You could also write Scheme code instead. ;-)
> Also what are the args the REPL says you can supply to (make-module) ?.
‘make-module’ takes one optional argument, which is the expected number
of bindings in the module (it’s a hint so that the underlying hash table
has the right size from the start.)
Thanks,
Ludo’.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: make-module question.
2010-08-18 14:03 ` Ludovic Courtès
@ 2010-08-18 21:35 ` Ian Hulin
2010-08-29 19:05 ` Andy Wingo
0 siblings, 1 reply; 6+ messages in thread
From: Ian Hulin @ 2010-08-18 21:35 UTC (permalink / raw)
To: Ludovic Courtès; +Cc: guile-user
Hi Ludo,
On 18/08/10 15:03, Ludovic � wrote:
> Hi!
>
> Ian Hulin <ian@hulin.org.uk> writes:
>
>> (make-module) doesn't seem to appear in the documentation, Is it
>> supported, discouraged or deprecated?
>
> It is undocumented but safe to use.
>
>> Is there a supported scm_make_module we can use in the Guile API, and
>> if not, is it safe to use
>>
>> SCM scm_make_module_x = SCM_EOL;
>> scm_permanent_object (scm_c_lookup ("make-module"));
>> and then do
>> scm_call_0( SCM_VARIABLE_REF (scm_make_module_x)):
>> ?
>
> Yes, you can do this. You could also write Scheme code instead. ;-)
>
It's already in C++.
>> Also what are the args the REPL says you can supply to (make-module) ?.
>
> ‘make-module’ takes one optional argument, which is the expected number
> of bindings in the module (it’s a hint so that the underlying hash table
> has the right size from the start.)
>
Since posting this I managed to track down the V1.8.7 ice-9/boot-9.scm,
where this is declared.
It looks like there are three optional parameters, and the code is
trying to do a home-grown version of (ice-9 optargs) to default the
first parameter of missing to be 31, and then process two others, an
optional list of modules to be added to the new module's uses list and
an optional initialization thunk to be called.
It's as it it's trying to do
(define*-public (make-module (#:optional (size=31)
#:optional (uses-list='()) #:optional (init-thunk='()))
...)
As the lilypond C++ routine immediately adds stuff to the uses list it
could be useful to call make-module with this parameter.
However, how do you call the thing while getting it to accept that you
don't want to pass it the first parameter and want to let it default the
value, but the first positional one you are passing is actually the
second actual one, as you don't have any list separators in Scheme like
in C++, or Pascal or whatever. So Scheme cannot distinguish between
(make-module ( my-obarray-size)) and (make-module ( my-uses-list))
whereas a language with list-element separators could make this clear
make-module ( my_obbaray_size, , );
and make-module ( , my_uses_list , );
I suppose I could try a bit more noodling around in the REPL.
Cheers,
Ian
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: make-module question.
2010-08-18 21:35 ` Ian Hulin
@ 2010-08-29 19:05 ` Andy Wingo
2010-09-04 21:10 ` Ian Hulin
0 siblings, 1 reply; 6+ messages in thread
From: Andy Wingo @ 2010-08-29 19:05 UTC (permalink / raw)
To: Ian Hulin; +Cc: Ludovic Courtès, guile-user
Greets,
On Wed 18 Aug 2010 14:35, Ian Hulin <ian@hulin.org.uk> writes:
> On 18/08/10 15:03, Ludovic Courtès wrote:
>> Ian Hulin <ian@hulin.org.uk> writes:
>>> Also what are the args the REPL says you can supply to (make-module) ?.
> It looks like there are three optional parameters, and the code is
> trying to do a home-grown version of (ice-9 optargs) [...]
In git, the definition begins:
(define* (make-module #:optional (size 31) (uses '()) (binder #f))
...)
> As the lilypond C++ routine immediately adds stuff to the uses list it
> could be useful to call make-module with this parameter.
> However, how do you call the thing while getting it to accept that you
> don't want to pass it the first parameter and want to let it default the
> value, but the first positional one you are passing is actually the
> second actual one, as you don't have any list separators in Scheme like
> in C++, or Pascal or whatever. So Scheme cannot distinguish between
> (make-module ( my-obarray-size)) and (make-module ( my-uses-list))
> whereas a language with list-element separators could make this clear
> make-module ( my_obbaray_size, , );
> and make-module ( , my_uses_list , );
You use #:key instead of #:optional arguments. make-module needs to be
declared to have #:key arguments, though, which is not currently the
case.
Andy
--
http://wingolog.org/
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: make-module question.
2010-08-29 19:05 ` Andy Wingo
@ 2010-09-04 21:10 ` Ian Hulin
2010-09-06 11:25 ` Andy Wingo
0 siblings, 1 reply; 6+ messages in thread
From: Ian Hulin @ 2010-09-04 21:10 UTC (permalink / raw)
To: Andy Wingo; +Cc: Ludovic Courtès, guile-user
Hi Andy,
On 29/08/10 20:05, Andy Wingo wrote:
> Greets,
>
> On Wed 18 Aug 2010 14:35, Ian Hulin <ian@hulin.org.uk> writes:
>
>> On 18/08/10 15:03, Ludovic Courtès wrote:
>>> Ian Hulin <ian@hulin.org.uk> writes:
>>>> Also what are the args the REPL says you can supply to (make-module) ?.
>
>> It looks like there are three optional parameters, and the code is
>> trying to do a home-grown version of (ice-9 optargs) [...]
>
> In git, the definition begins:
>
> (define* (make-module #:optional (size 31) (uses '()) (binder #f))
> ...)
>
>> As the lilypond C++ routine immediately adds stuff to the uses list it
>> could be useful to call make-module with this parameter.
>> However, how do you call the thing while getting it to accept that you
>> don't want to pass it the first parameter and want to let it default the
>> value, but the first positional one you are passing is actually the
>> second actual one, as you don't have any list separators in Scheme like
>> in C++, or Pascal or whatever. So Scheme cannot distinguish between
>> (make-module ( my-obarray-size)) and (make-module ( my-uses-list))
>> whereas a language with list-element separators could make this clear
>> make-module ( my_obbaray_size, , );
>> and make-module ( , my_uses_list , );
>
> You use #:key instead of #:optional arguments. make-module needs to be
> declared to have #:key arguments, though, which is not currently the
> case.
>
Then I have two questions;
If #:key is a superset of #:optional, and allows you to specify
parameters positionally without the keywords if you're omitting
parameters from the right-hand end
(make-module my_obarray-size my_uses_list)
or
(make-module my_obarray-size)
but if you omit the size or uses parameter you have to use keywords
(make-module #:uses '((ice-9 syncase) (ice-9 debug))).
If this is the case, could I request an enhancement for this the base
code to declared using
(define* (make-module #:key (size 31) (uses '()) (binder #f))
...)
If make-module is declared using #;key, how would this affect calling it
from code with scm_call_1, scm_call_2, scm_call_3 or scm_call_n? Would
we need to pass the keywords as separate parameters like this,
SCM scm_make_module_x = SCM_EOL;
SCM keyname = scm_str2symbol ("#;uses");
SCM modlist = scm_list_2 (scm_str2sym("ice-9 syncase"),
scm_str2sym("ice-9 debug"))
scm_permanent_object (scm_c_lookup ("make-module"));
scm_call_2( SCM_VARIABLE_REF (scm_make_module_x), keyname, modlist):
or like this, with a place-holder blank parameter for the size parameter
with SCM_EOL or SCM_BOOL_F?
scm_call_2 (SCM_VARIABLE_REF (scm_make_module_x), SCM_BOOL_F, modlist);
Cheers,
Ian Hulin
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: make-module question.
2010-09-04 21:10 ` Ian Hulin
@ 2010-09-06 11:25 ` Andy Wingo
0 siblings, 0 replies; 6+ messages in thread
From: Andy Wingo @ 2010-09-06 11:25 UTC (permalink / raw)
To: Ian Hulin; +Cc: Ludovic Courtès, guile-user
Hello,
On Sat 04 Sep 2010 23:10, Ian Hulin <ian@hulin.org.uk> writes:
> If #:key is a superset of #:optional
#:key is not a superset of optional. Keyword parameters are bound by
name; optional parameters are bound by position. Keyword parameters are
not bound by position.
((lambda* (#:optional foo) foo) 10) => 10
((lambda* (#:key foo) foo) 10) => Error.
> If this is the case, could I request an enhancement for this the base
> code to declared using
> (define* (make-module #:key (size 31) (uses '()) (binder #f))
> ...)
Unfortunately we cannot, as this would be an incompatible change.
> If make-module is declared using #;key, how would this affect calling it
> from code with scm_call_1, scm_call_2, scm_call_3 or scm_call_n?
> SCM keyname = scm_str2symbol ("#;uses");
In modern Guile (>= 1.8), one makes a symbol from a string via
scm_from_locale_symbol. However in this case you want to make a keyword,
so use scm_from_locale_keyword ("uses").
(Actually, we should be using scm_from_latin1_keyword here, but that
doesn't exist yet.)
> SCM modlist = scm_list_2 (scm_str2sym("ice-9 syncase"),
> scm_str2sym("ice-9 debug"))
Neither of these modules are needed in current Guile. scm_str2sym is not
a part of Guile either; assuming it is one of your functions, you should
use your own namespace (ly_ for example), not Guile's (scm_).
> scm_call_2( SCM_VARIABLE_REF (scm_make_module_x), keyname, modlist):
Yes, you would call it like this.
Regards,
Andy
--
http://wingolog.org/
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2010-09-06 11:25 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-08-10 19:25 make-module question Ian Hulin
2010-08-18 14:03 ` Ludovic Courtès
2010-08-18 21:35 ` Ian Hulin
2010-08-29 19:05 ` Andy Wingo
2010-09-04 21:10 ` Ian Hulin
2010-09-06 11:25 ` Andy Wingo
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).