[racket] What is the equivalent of ToExpression in Mathematica?

From: Jens Axel Søgaard (jensaxel at soegaard.net)
Date: Wed Feb 29 18:40:30 EST 2012

2012/2/29 ashok bakthavathsalam <lifebalance at gmail.com>

> I am looking for something similar to ToExpression<http://reference.wolfram.com/mathematica/ref/ToExpression.html> that
> is available in Mathematica. I just want to convert a string to an
> expression, and evaluate the expression. As a first pass, my strings will
> include only numbers and arithmetic operators, and not even parentheses.
> If I need to write it, please point me in the direction of the appropriate
> pre-defined modules/definitions which I should use.

Maybe you can use this parser for infix expressions.

Here is a small example (it takes a while for the library to install - it
seems it old Schematics test suite takes forever to install these days - I
need to switch to a builtin one).

#lang at-exp racket
(require (planet soegaard/infix)
         (planet soegaard/infix/parser))
(display (format "1+2*3 is ~a\n" @${1+2*3} ))

(parse-expression #'here (open-input-string "1+2*3"))

The output will be:
    1+2*3 is 7
    .#<syntax:6:21 (#%infix (+ 1 (* 2 3)))>

The function parse-expression parses the expression in the string and
returns a syntax-object that resembles the output of ToExpression.

Jens Axel Søgaard
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20120301/bd3f1cd0/attachment-0001.html>

Posted on the users mailing list.