Top 1K Features Creators Events Podcasts Books Extensions Interviews Blog Explorer CSV

Dc

< >

Dc, aka desk calculator, is a programming language created in 1978.

#912on PLDB 46Years Old
REPL · Try It Online · Wikipedia

dc (desk calculator) is a cross-platform reverse-polish calculator which supports arbitrary-precision arithmetic. It is one of the oldest Unix utilities, predating even the invention of the C programming language. Like other utilities of that vintage, it has a powerful set of features but terse syntax. Read more on Wikipedia...


Example from Riju:
[Hello, world!] p
Example from hello-world:
[Hello World ]n
Example from Wikipedia:
#!/usr/bin/perl my ($g,$e,$m) = map { "\U$_" } @ARGV; die "$0 gen exp mod\n" unless $m; print `echo $g $e $m | dc -e ' # Hex input and output 16dio # Read m, e and g from stdin on one line ?SmSeSg # Function z: return g * top of stack [lg*]sz # Function Q: remove the top of the stack and return 1 [sb1q]sQ # Function X(e): recursively compute g^e % m # It is the same as Sm^Lm%, but handles arbitrarily large exponents. # Stack at entry: e # Stack at exit: g^e % m # Since e may be very large, this uses the property that g^e % m == # if( e == 0 ) # return 1 # x = (g^(e/2)) ^ 2 # if( e % 2 == 1 ) # x *= g # return x % [ d 0=Q # return 1 if e==0 (otherwise, stack: e) d 2% Sa # Store e%2 in a (stack: e) 2/ # compute e/2 lXx # call X(e/2) d* # compute X(e/2)^2 La1=z # multiply by g if e%2==1 lm % # compute (g^e) % m ] SX le # Load e from the register lXx # compute g^e % m p # Print the result '`;

Language features

Feature Supported Example Token
Comments ✓ # A comment
Line Comments ✓ # A comment #
Semantic Indentation X

- Build the next great programming language · Add · Issues · About · Search · Keywords · Livestreams · Labs · Resources · Acknowledgements

Built with Scroll v155.3.0