CljPerl
view release on metacpan or search on metacpan
lib/CljPerl.pm view on Meta::CPAN
CljPerl is a lisp implemented by Perl. It borrows the idea from Clojure,
which makes a seamless connection with Java packages.
Like Java, Perl has huge number of CPAN packages.
They are amazing resources. We should make use of them as possible.
However, programming in lisp is more insteresting.
CljPerl is a bridge between lisp and perl. We can program in lisp and
make use of the great resource from CPAN.
=head2 EXPORT
=head3 Lisp <-> Perl
CljPerl is hosted on Perl. Any object of CljPerl can be passed into Perl and vice versa including code.
An example of using Perl's IO functions.
=head4 Perl functions in CljPerl.pm
package CljPerl;
sub open {
my $file = shift;
my $cb = shift;
my $fh;
open $fh, $file;
&{$cb}($fh);
close $fh;
}
sub puts {
my $fh = shift;
my $str = shift;
print $fh $str;
}
sub readline {
my $fh = shift;
return <$fh>;
}
=head4 CljPerl functions in core.clp
(ns file
(defn open [file cb]
(. open file cb))
(defn >> [fh str]
(. puts fh str))
(defn << [fh]
(. readline fh)))
=head4 Test
(file#open ">t.txt" (fn [f]
(file#>> f "aaa")))
(file#open "<t.txt" (fn [f]
(println (perl->clj (file#<< f)))))
An advanced example which creates a timer with AnyEvent.
(. require AnyEvent)
(def cv (->AnyEvent condvar))
(def count 0)
(def t (->AnyEvent timer
{:after 1
:interval 1
:cb (fn [ & args]
(println count)
(set! count (+ count 1))
(if (>= count 10)
(set! t nil)))}))
(.AnyEvent::CondVar::Base recv cv)
=head3 Documents
=head4 Reader
* Reader forms
* Symbols :
foo, foo#bar
* Literals
* Strings :
"foo", "\"foo\tbar\n\""
* Numbers :
1, -2, 2.5
* Booleans :
true, false
* Keywords :
:foo
* Lists :
(foo bar)
* Vectors :
[foo bar]
* Maps :
{:key1 value1 :key2 value2 "key3" value3}
=head4 Macro charaters
* Quote (') :
'(foo bar)
* Comment (;) :
; comment
( run in 0.892 second using v1.01-cache-2.11-cpan-39bf76dae61 )