Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Simple CLI calculator based on Perl's eval()

by bliako (Monsignor)
on Mar 04, 2021 at 14:18 UTC ( [id://11129120]=note: print w/replies, xml ) Need Help??


in reply to Simple CLI calculator based on Perl's eval()

reisinge respect for daring one more step into Lazyness. And sharing your code.

Here's my Lazyness with a big help from Math::Symbolic and friends:

perl -MMath::Symbolic=parse_from_string -MMath::Symbolic::Compiler=com +pile_to_sub -e ' die "no!" unless @ARGV==1 and defined($e=$ARGV[0]) and not $e=~/^\s*$/ and defined($t=Math::Symbolic::parse_from_string($e)) and ($s) = Math::Symbolic::Compiler->compile_to_sub($t) and $s and ref($s)eq"CODE" and defined($r=$s->()) ; print "$r\n"; ' 'sin(log(2,2))'

P.S. I still don't know how to use constants (like PI) into symbolic expressions. Anyone?

bw, bliako

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11129120]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-04-19 10:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found