[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] A few questions
From: |
Kon Lovett |
Subject: |
Re: [Chicken-users] A few questions |
Date: |
Tue, 29 Jan 2008 10:25:33 -0800 |
On Jan 29, 2008, at 9:47 AM, Hans Nowak wrote:
Hi,
I am studying Chicken this year (and blogging about it, as some
people here
already discovered :-). So far I have been able to figure out most
things by
myself (my experience with Scheme is limited, but I'm not a *complete*
beginner), but I still have a few unanswered questions. Maybe
somebody here
can help me. Here goes...
1. Does Chicken (or Scheme in general) support docstrings?
Chicken doesn't; this is an on-going issue/discussion. Scheme, in the
sense of RnRS, doesn't. Some Scheme implementations might.
Common LISP does but that isn't a Scheme.
2. Python has a way to make the same file usable as both a module
and a
script. For example:
# foo.py
def bar(x): ...
if __name__ == "__main__":
bar(42)
When run as a script, all the code is executed; when imported, you
get the
definitions, but the code inside the 'if' is omitted.
Is there a way to do something similar in Chicken? Or, in other
words, is
there a way for Chicken code to tell if it's being run a script, or
being
loaded as auxiliary code?
For interpreted code, see
http://galinha.ucpel.tche.br/A%20script%20to%20browse%20the%20HTML%
20manual
For compiled code, not without some work. An extension can be created
(a dynld binary). Then create a program (a binary) that uses the
extension & parses the command line and calls the extension's
procedures. See http://galinha.ucpel.tche.br/chicken-setup
3. This is more of a technical question about something that I
haven't grasped
yet. When I define a function, I can "see" it at the toplevel, and
refer to
it by name:
#;8> (define (f x) x)
#;9> f
#<procedure (f x)>
But I cannot do the same thing with macros:
#;6> (define-macro (m x) `,x)
#;7> (m 3)
3
#;8> m
Error: unbound variable: m
Why is that? There is probably a good reason why I cannot type 'm'
and get
back something like '#<macro (m x)>', but what is that reason?
Different "namespace". However the macro "namespace" & the toplevel
"namespace" shadow each other:
#;1> (define foo 1)
#;2> foo
1
#;3> (define-macro (foo) 1)
#;4> (foo)
1
#;5> (define foo 1)
#;6> foo
1
#;7> (foo)
Error: call of non-procedure: 1
Call history:
<syntax> (foo)
<eval> (foo) <--
Also, is there
a way to get a list of defined macros?
In the utils unit the apropos functions can list macros. However,
these take a pattern and are not exclusive to macros - procedures are
included.
An undocumented function can be used to just list the macros -
(##sys#apropos-macros "" #f).
I don't think hygienic macros will be listed.
Thanks,
--Hans
`
_______________________________________________
Chicken-users mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/chicken-users
Best Wishes,
Kon
- Re: [Chicken-users] Re: A few questions, (continued)
- Re: [Chicken-users] Re: A few questions, Graham Fawcett, 2008/01/31
- Re: [Chicken-users] Re: A few questions, John Cowan, 2008/01/31
- Re: [Chicken-users] Re: A few questions, John Cowan, 2008/01/31
- Re: [Chicken-users] Re: A few questions, Zbigniew, 2008/01/31
- Re: [Chicken-users] Re: A few questions, Elf, 2008/01/31
- Re: [Chicken-users] Re: A few questions, John Cowan, 2008/01/31
- Re: [Chicken-users] Re: A few questions, Elf, 2008/01/31
- Re: [Chicken-users] Re: A few questions, John Cowan, 2008/01/31
- Re: [Chicken-users] Re: A few questions, Kon Lovett, 2008/01/31
- Re: [Chicken-users] Re: A few questions, Elf, 2008/01/31
Re: [Chicken-users] A few questions,
Kon Lovett <=
Re: [Chicken-users] A few questions, John Cowan, 2008/01/29