chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] Re: A few questions


From: Kon Lovett
Subject: Re: [Chicken-users] Re: A few questions
Date: Tue, 29 Jan 2008 11:29:17 -0800


On Jan 29, 2008, at 11:08 AM, Hans Nowak wrote:


First of all, thanks to everybody who replied.

Re docstrings: My next question would be, is it possible to add them (e.g. as a library)? And would it be desirable to do so? Apparently it is already possible to write code like:

(define (foo x)
  "docstring for foo"
  ...body...)

It just has no effect, currently (or so I assume). Would it be possible to write a function/macro/etc like this:

> (get-docstring foo)
"docstring for foo"

Yes, but not with a documented interface. The procedure '(##sys#decorate-lambda proc pred decorator)' can create arbitrary "decorations" for a procedure. Then, '(##sys#lambda-decoration proc pred)' can retrieve it.

Let me look into this.


...?

The reason I am asking is that someone suggested I should write doctest for Scheme. For those not familiar with it, this is a Python module that allows you to add tests to docstrings. It does so by emulating the interactive interpreter; e.g. you could write:

(define (plus a b)
  "Add two numbers.

   >>> (plus 2 2)
   4
   >>> (plus 1 2 3)
   Error: bad argument count
  "
  ...implementation...)

More here:

http://docs.python.org/lib/module-doctest.html

Does Chicken have something similar? It doesn't have docstrings, but it would still be possible to write unit tests like you're typing them in the REPL. I did not find an egg that does this kind of testing, though. Does such a library exist? Would it be useful to have?

No. But see above. (I wouldn't put the tests in a docstring but in a test decoration.)

There are plenty of testing eggs. Both testeez & testbase provide a REPL style test interface. But I don't use the REPL style for unit tests.



Re using files as modules and scripts: I just found csi's -ss option, which pretty much does what I want, although in a different way.

Anyway, I have another question: when you define a function, how much "introspection" is possible? E.g. from another thread ("Runtime arity") I learned that it's possible to get the function's signature. Is there also a way to get e.g. the function's body? (My guess is, probably not, but I thought I'd ask.)

No. Why do you want it?


Thanks,

--Hans



_______________________________________________
Chicken-users mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/chicken-users

Best Wishes,
Kon






reply via email to

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