Skip Menu |

This queue is for tickets about the Language-Expr CPAN distribution.

Report information
The Basics
Id: 64505
Status: resolved
Priority: 0/
Queue: Language-Expr

People
Owner: Nobody in particular
Requestors: user42 [...] zip.com.au
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: synopsis sample code error
Date: Thu, 06 Jan 2011 07:50:29 +1100
To: bug-Language-Expr [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
In Language::Expr 0.13 and recent debian i386 perl 5.10.1 I tried to run the synopsis sample code of the Language::Expr pod, in foo.pl below, and got an error Undefined subroutine &Language::Expr::Compiler::Perl::sqr called at (eval 267) line 1. Does the func() user function thingie only work for interpreted=>1, or has to be a named perl function or something for it to work "compiled"? (In case it helps, Test::Synopsis is a way to exercise synopsis code, perhaps just as an "author" test.)
use 5.010; use strict; use warnings; use Language::Expr; my $le = new Language::Expr; $le->var('a' => 1, 'b' => 2); $le->func(sqr => sub { $_[0] ** 2 }, rand => sub {rand()}); # evaluate expression say $le->eval('$a + sqr($b)'); # 5
Hi Kevin, Thanks for the report. I've now corrected and expanded the synopsis (have not started using Test::Synopsis yet, it's a good idea though). As for your question, yep. The $le->var(...) and $le->func(...) are for use by the interpreter. By default, the Perl compiler compiles 'foo()' as-is into 'foo()' Perl code, and run it in Language::Expr::Compiler::Perl namespace. So you need to provide a foo () subroutine there. Same with variables. You can instruct the compiler to translate 'foo()' into 'Your::Package::foo()' or even '$le->interpreter->funcs->{foo}->()' to make the compiled code works with the interpreter supplied data. All of this is now explained in the new (0.14 release) synopsis. Btw, I'm curious as to what do you use Language::Expr for. Regards, Steven On Wed Jan 05 15:50:30 2011, user42@zip.com.au wrote: Show quoted text
> In Language::Expr 0.13 and recent debian i386 perl 5.10.1 I tried to > run > the synopsis sample code of the Language::Expr pod, in foo.pl below, > and > got an error > > Undefined subroutine &Language::Expr::Compiler::Perl::sqr called > at (eval 267) line 1. > > Does the func() user function thingie only work for interpreted=>1, or > has to be a named perl function or something for it to work > "compiled"? > > > (In case it helps, Test::Synopsis is a way to exercise synopsis code, > perhaps just as an "author" test.) > >
Subject: Re: [rt.cpan.org #64505] synopsis sample code error
Date: Sat, 08 Jan 2011 06:53:56 +1100
To: bug-Language-Expr [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
"steven haryanto via RT" <bug-Language-Expr@rt.cpan.org> writes: Show quoted text
> > I'm curious as to what do you use Language::Expr for.
I had an expression parser in my math-image program (on cpan :-) using Math::Symbolic and was looking at what other modules can do a similar thing. So far I chucked in Math::Expression::Evaluator. It's only meant for a numeric like 2*x^2+1 for what values to plot. A choice of syntax, maybe a straight perl eval too, is just for some flexibility or for what modules are or aren't installed, etc.
On Fri Jan 07 14:53:59 2011, user42@zip.com.au wrote: Show quoted text
> "steven haryanto via RT" <bug-Language-Expr@rt.cpan.org> writes:
> > > > I'm curious as to what do you use Language::Expr for.
> > I had an expression parser in my math-image program (on cpan :-) using > Math::Symbolic and was looking at what other modules can do a similar > thing. So far I chucked in Math::Expression::Evaluator. It's only > meant for a numeric like 2*x^2+1 for what values to plot. A choice of > syntax, maybe a straight perl eval too, is just for some flexibility
or Show quoted text
> for what modules are or aren't installed, etc.
I see. Math::Expression::Evaluator is a good choice. Language::Expr is pretty straightforward to use in interpreted mode, the problem might be the longer list of dependencies (Mouse, Regexp::Grammars, etc), but it can be handy if you someday decide to do browser stuffs (convert expression to JS). Regards, steven
Subject: Re: [rt.cpan.org #64505] synopsis sample code error
Date: Tue, 11 Jan 2011 09:24:49 +1100
To: bug-Language-Expr [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
"steven haryanto via RT" <bug-Language-Expr@rt.cpan.org> writes: Show quoted text
> > Math::Expression::Evaluator is a good choice.
Math::Expression can probably work too if I'm keen, though I'd only need the numbers, not strings and arrays and stuff. Show quoted text
> Language::Expr is pretty straightforward to use in interpreted mode,
I'm expecting to evaluate at as much as maybe 100,000 points for a screen full of image, so I've had a go at the perl code output and eval that to a subr. It's a bit like hard work so far, but it goes (enough for the next release :-). It took me a while to realize interpreted means calculate during parsing, and compile means make a string of perl (or whatever) code. You could think about a couple of words in the docs to summarize what happens, and maybe guidance on repeated evaluation of the same string (with input variables changing a bit). Show quoted text
> longer list of dependencies (Mouse, Regexp::Grammars, etc),
If it's only optional that that's ok. Moose is certainly more than I think I'm keen on, but may yet end up going to it for my other values calculating modules so as to have a way to "introspect" available parameters to show as widgets in the GUI.
On Mon Jan 10 17:24:49 2011, user42@zip.com.au wrote: Show quoted text
> It took me a while to realize interpreted means calculate during > parsing, and compile means make a string of perl (or whatever) code. > You could think about a couple of words in the docs to summarize what > happens, and maybe guidance on repeated evaluation of the same string > (with input variables changing a bit).
Good point, committed. Regards, steven
Closing this ticket, no more issues left. -- sh