Implementing Input Expression and Outputting Calculation Results

Hello Everyone,

I hope you all are doing well. I am trying to implement a toy program that takes an input expression and outputs the calculated result. The desired functionality is similar to print input() in Python.

Luckily, I have found the Easy Expression Eval lib more capable than expected.

Thank you in advance for your support.

1 Like

Hi Sunrise,

if you are talking about GitHub - eltony81/easy_expression_eval,
I can say it is intended to evaluate just math expression. Let me know if you are suggestions or if there are issues. Thanks in advance

Well, I am just asking for a way to implement print input() with the Crystal language standard library.

For reading a line from stdin and printing it to stdout you can use this:

puts gets

Enm, it’s executing a statement in fact.
The same as puts eval(input_expression) in Ruby.
Is there similar any similar method in Crystal?

Ah okay. I was looking at Built-in Functions — Python 3.11.4 documentation which seems to be the equivalent of gets in Crystal.

Evaluation of code at runtime is not possible in Crystal because it’s a compiled language and the compiler builds the entire program ahead of time and is no longer available to evaluate an expression at runtime.

What kind of expressions do you want to evaluate?