[Ometa] ometa first project?: plain text math parser which feeds a grapher

Alessandro Warth alexwarth at gmail.com
Fri Dec 4 10:49:36 PST 2009


Hi Stephen,

Sounds like fun!

You could do the graphing on a canvas element, which you can add dynamically
to the OMeta/JS Workspace Wiki page. (I did that in the Logo
project<http://tinlizzie.org/ometa-js/#Logo> --
take look at the first two lines.)

It should be straightforward to write the parser, and if it returns a string
like you were saying, e.g., "Math.sin(x) * Math.cos(x)", it would be easy to
wrap that inside a string that looks like a JavaScript function that takes x
as an argument. Then you could eval that string in order to get a real
function that you can call repeatedly in order to draw the graph. Here's
what I mean:

var e =3D THE_RESULT_OF_PARSING; // which is a string
var s =3D "function(x) { return " + p + "; }";
var f =3D eval(s);


Let us know if you run into any problems...

Cheers,
Alex

On Thu, Dec 3, 2009 at 7:29 PM, Stephen Bannasch <
stephen.bannasch at deanbrook.org> wrote:

> Here's an idea for a relatively simple project to learn more about ometa.
>
> I'd like to have users enter different forms of math functions, parse the
> text input and end up with a JavaScript function I can graph.
>
> For example see this page which is shows an example of entering a
> JavaScript equation and graphing it with JSXGraph:
>
>  http://jsxgraph.uni-bayreuth.de/wiki/index.php/Change_Equation_of_a_Graph
>
> I'm thinking that a relatively simple project to learn more about ometa-js
> would be enable a user to enter either:
>
>  1. sinx(x)*cos(x)
>
> or
>
>  2. sinx cosx
>
> The parser would in the end return:
>
>  Math.sin(x)*Math.cos(x)
>
> Which would then be graphed.
>
> Does this seem like something I could use ometa-js for?
>
>
> _______________________________________________
> OMeta mailing list
> OMeta at vpri.org
> http://vpri.org/mailman/listinfo/ometa
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://vpri.org/pipermail/ometa/attachments/20091204/ae71d4d1/attachme=
nt-0001.htm


More information about the OMeta mailing list