chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] A few questions


From: John Cowan
Subject: Re: [Chicken-users] A few questions
Date: Tue, 29 Jan 2008 13:31:49 -0500
User-agent: Mutt/1.5.13 (2006-08-11)

Hans Nowak scripsit:

> 1. Does Chicken (or Scheme in general) support docstrings?

No.

> 2. Python has a way to make the same file usable as both a module and a
> script. For example:

[snip]

> 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?

Not that I know of.

> 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)>

That works because the procedure is the ordinary value of the ordinary
variable f.  You can use f in any context, either as the procedure to be
called, as an argument to a call, or a as a simple reference to its value.

> 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

Correct.  Syntactic keywords, whether built-in like if, or defined by
define-macro or define-syntax, belong to a separate namespace which
overrides ordinary variables -- but only when used as the first position
of a Scheme form.  Thus you could have a variable m and do (m m); if
m's value happened to be a procedure, you could not invoke it as (m 3)
but could do so using (apply m (list 3)).

This is part of the definition of the Scheme language.

> Also, is there a way to get a list of defined macros?

No.

-- 
                Si hoc legere scis, nimium eruditionis habes.




reply via email to

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