A simple command line calculator
Examples
C:>calc 5+5*5 30.000000 c:>calc 0x30 48.000000 c:>calc (123456 % 51)/12 3.000000
Thank you again, Steve Hanov!
"Apparently you've forgotten to remove debug output:
C:>calc 10*4
parse_expr()
parse_term()
parse_factor()
parse_num_op()
parse_rest_term()
parse_factor()
parse_num_op()
parse_rest_term()
parse_rest_expr()
40.000000
"
C:>calc 10*4
parse_expr()
parse_term()
parse_factor()
parse_num_op()
parse_rest_term()
parse_factor()
parse_num_op()
parse_rest_term()
parse_rest_expr()
40.000000
calc() {
python -c "from math import *; print $*"
}
Example:
$ calc pi - 3
0.14159265359
This, or one of the ipython shells I have lying around.
it seems that the replacement i did have effect on A ^ 9 expression...
the replacement should be :
resolve_variable(val);
if ( match_char( '^' ) ){
val_t val2;
parse_num_op( &val2 );
val->d.fval = pow( val->d.fval, val2.d.fval );
parse_rest_num_op( val );
}
parse_rest_expr( val );
myVariable + 1
This is due to a bug in the void parse_rest_var function !
The following code solve this problem and seems to not have boundary effect !
void parse_rest_var( val_t* val )
{
if ( match_char( '=' ) ) {
val_t vexp;
parse_expr( &vexp );
if ( vexp.type != TYPE_FLOAT ) {
printf("Error: Tried to assign non-number to %s.\n", val->d.variable );
longjmp( env, 1 );
}
printf("Assigned to %s: ", val->d.variable );
map_add( val->d.variable, vexp.d.fval );
*val = vexp;
} else {
// -----------------------replace
// parse_rest_num_op( val );
// -- by
resolve_variable(val);
parse_rest_expr( val );
// ------------------End of modif !
}
Zero load time file formats
When your app needs to be fast, you can't afford to load things fro disk. In this toy example, an on-disk data structure helps you instantly look up lists of related words.Game Theory, Salary Negotiation, and Programmers
When you get a new job, you can breathe a sigh of relief, but not for long. You have an offer letter in your hand, and it is easy to miss one of the most important opportunities of your life: the starting salary. Here's what to do to increase your chances.Asana's shocking pricing practices, and how you can get away with it too
If one apple costs $1, how much would five apples cost? How about 500? If everyday life, when you buy more of something, you get more bananas for your buck. But software companies are bucking the trend.
Throw away the keys: Easy, Minimal Perfect Hashing
Perfect hashing is a technique for building a hash table with no collisions in the minimum possible space. They are a easy to build with this simple python function.
Installing the Latest Debian on an Ancient Laptop
The challenge: Install Linux on a really old laptop. The catch: It has only 32 MB of RAM, no network ports, no CD-ROM, and the floppy drive makes creaking noises. Is it possible? Yes. Is it easy? No. Is is useful? Maybe...
My thoughts on various programming languages
Some ill-informed remarks on various programming languages.
