[Chicken-users] Egg example

2009-07-21 Thread bill

Hi all,

I've decided to try my hand a writing an egg.  I'm one of those people 
who learn best by example.   But when I try to  download the mpeg3 
example fromk SVN I'm told the URL does not exist.   Am I doing 
something wrong or is the tutorial wrong?I have not yet started 
writing an egg - I just want to see an example of how it's done.


Bill


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


Re: [Chicken-users] Egg example

2009-07-21 Thread Christian Kellermann
* bill ramsa...@comcast.net [090721 13:43]:
 Hi all,

 I've decided to try my hand a writing an egg.  I'm one of those people  
 who learn best by example.   But when I try to  download the mpeg3  
 example fromk SVN I'm told the URL does not exist.   Am I doing  
 something wrong or is the tutorial wrong?I have not yet started  
 writing an egg - I just want to see an example of how it's done.


Maybe you are using an URL from outdated documentation?
The url that works for me is:
 https://galinha.ucpel.tche.br/svn/chicken-eggs/release/3/mpeg3

Replace 3 by 4 if you want the eggs for chicken4.

The username is anonymous, the password is empty.

Cheers,

Christian


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


Re: [Chicken-users] Egg example

2009-07-21 Thread bill

Christian,

I tried release 4 and it did not work.   I then tried 3 and it did.   
I'm fine now, but there may be a problem with release 4.


Thanks for the help.

Bill

Christian Kellermann wrote:

* bill ramsa...@comcast.net [090721 13:43]:
  

Hi all,

I've decided to try my hand a writing an egg.  I'm one of those people  
who learn best by example.   But when I try to  download the mpeg3  
example fromk SVN I'm told the URL does not exist.   Am I doing  
something wrong or is the tutorial wrong?I have not yet started  
writing an egg - I just want to see an example of how it's done.





Maybe you are using an URL from outdated documentation?
The url that works for me is:
 https://galinha.ucpel.tche.br/svn/chicken-eggs/release/3/mpeg3

Replace 3 by 4 if you want the eggs for chicken4.

The username is anonymous, the password is empty.

Cheers,

Christian

  




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


[Chicken-users] FFI and stack use

2009-07-21 Thread Thomas Bushnell BSG
I have an FFI function, and it will be allocating some significant stack
space.  (It calls the Linux syscall epoll_wait, with a significant
stack-allocated array, and then wants to cons the results into a list.)

So this raises a question.  Scheme functions get compiled into code that
carefully checks stack bounds before allocating, and bangs off to the
garbage collector if necessary.

The FFI doesn't do this.  So I'm assuming that in fact, I have the full
C stack available, and can just go ahead and use it.  When I invoke the
return continuation, it will go just fine, and presumably if I've
exceeded the Chicken stack size, it will just trigger a gc and proceed
happily as before.

Am I right?

Thomas




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


Re: [Chicken-users] FFI and stack use

2009-07-21 Thread John Cowan
Thomas Bushnell BSG scripsit:

 So this raises a question.  Scheme functions get compiled into code that
 carefully checks stack bounds before allocating, and bangs off to the
 garbage collector if necessary.
 
 The FFI doesn't do this.  So I'm assuming that in fact, I have the full
 C stack available, and can just go ahead and use it.  When I invoke the
 return continuation, it will go just fine, and presumably if I've
 exceeded the Chicken stack size, it will just trigger a gc and proceed
 happily as before.

In fact, it's unpredictable how much C stack you have, because each compiled
Scheme function invokes its successor, leaving garbage return addresses,
saved registers, etc. on the C stack.  So just before calling a function
that allocates lots of C stack, call (gc #f) to force a minor GC.  
Alternatively,
use the -nursery switch at compile time or the -:s switch at run time to
force a large stack.

-- 
John Cowanco...@ccil.orghttp://ccil.org/~cowan
Heckler: Go on, Al, tell 'em all you know.  It won't take long.
Al Smith: I'll tell 'em all we *both* know.  It won't take any longer.


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


Re: [Chicken-users] FFI and stack use

2009-07-21 Thread Francisco Rafael Leon
Thomas Bushnell BSG t...@becket.net writes:

 I have an FFI function, and it will be allocating some significant stack
 space.  (It calls the Linux syscall epoll_wait, with a significant
 stack-allocated array, and then wants to cons the results into a list.)

 So this raises a question.  Scheme functions get compiled into code that
 carefully checks stack bounds before allocating, and bangs off to the
 garbage collector if necessary.

 The FFI doesn't do this.  So I'm assuming that in fact, I have the full
 C stack available, and can just go ahead and use it.  When I invoke the
 return continuation, it will go just fine, and presumably if I've
 exceeded the Chicken stack size, it will just trigger a gc and proceed
 happily as before.

 Am I right?

 Thomas

In C, when you make a mess, you must clean it up yourself.

For this reason, I treat all my FFI calls like toxic waste, and wrap
them in (let ... ) containers which allocate everything I need for the 
FFI call. I get pointers using (location ...) and call the C function.
After the FFI call returns, the closing ) of the let 
establishes scope and the GC can do whatever it wants after that.  It
has never eaten my stuff before the ), so this seems to work. The last
line before the ) is a call to cons or append or list with
whatever I need from my let. This is how I write wrappers. It Works
For Me (TM). 

For event-driven programs with external C contexts and data structures,
you need an event loop which calls (collect-c-garbage context) which checks your
program state and calls free() when needed.  You need to write
(collect-c-garbage) yourself, and fill it with conditionals and calls to
free(). For programs with I/O structures or AI genetic algorithms or
whatever, you can probably come up with reasonable conditionals for when
you need or don't need something anymore.  Read through the lolevel unit
docs in the manual about tools you can use for this.  With persistent
data out in C-land, an event loop with a custom GC is excellent form I
think.  Within the loop, you pass pointers around and use them and then
do a check at the end of each iteration.

Those are two easy ways of making C behave. They add overhead. They are
simple and difficult to screw up. 

Then, there is the incredibly scary alternative which involves
sprinkling your functions with FFI calls to alloc() and free() and then
trying to map out the state space and all possible transitions and
drawing epic flow diagrams to try and match up calls to alloc() and
free(). This is not a good idea because life is short, and even if you
spend 100 hours doing this, you will still screw it up. I promise.  

Lastly, there is the overwhelmingly popular option of doing the above,
but not worrying about matching up calls to alloc() and free(). If you
want an example of this ... well I'll stop before I become really 
offensive. Let me just state that *some* languages lack GC, and that
*some* software in those languages use lots of memory. I am not
kidding. In 2009, this is still true. 

I haven't looked at the chicken source code, but I don't really want to,
because then I will think I am smart and will use GC tricks that are not
portable to other implementations.  Or worse, I might learn that my
let statements are not safe from the GC and that I should use
object-evict to be totally safe.  So far, the GC has not harmed me and
has respected the closing ) of the let before moving anything.

-Rafael


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