Discussion:
my first Goo program
Paul Dufresne
2005-10-14 20:13:01 UTC
Permalink
#/
Fortune library, show one line of a file at random
Copyright (C) 2005 Paul Dufresne

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
USA

I can be contacted at ***@fastmail.fm or
14 rue St-Joseph Est
Québec, QC G1K 3A5
Canada
/#

(use goo/random)

(dv filename "/home/paul/mygoo/fortune.txt")

(dm read-file (filename|<str> => <col>)
(def output-col (vec))
(def myport (open <file-in-port> filename))
(until (eof-object? (peek myport))
(def ligne (gets myport))
(add! output-col ligne))
(close myport)
output-col)

(dm show-fortune (col|<col>)
(msg out (elt col (random (len col)))))

(dm main ()
(def mycol (read-file filename))
(show-fortune mycol))

(main)
#/ End of program /#

I know, it was not big enough to release under LGPL. :-)
First, I wanted to use with-port rather than until(eof-object?... but I
was unable.
Second, how would I generate a C program from it?
I used emacs Goo mode (was installed from the Ubuntu package, nice!) to
evaluate and
test program as I was writing it, and I suppose I am using the virtual
machine under
the hood, that is I guess I am using g2m under the hood.
--
http://www.fastmail.fm - One of many happy users:
http://www.fastmail.fm/docs/quotes.html
Loading...