Sha256: 96797d89a7a9997c56fe8d6e2afe20080585f4151e6dc86b538311027de9f9b3

Contents?: true

Size: 779 Bytes

Versions: 10

Compression:

Stored size: 779 Bytes

Contents


(defmodule arith
  (export all))

(defun demo-arith ()
  (case (: io fread '"Please enter two integers: " '"~d~d")
    ((tuple 'ok (a b))
      (: io format '"~p + ~p = ~p~n" (list a b (+ a b)))
      (: io format '"~p - ~p = ~p~n" (list a b (- a b)))
      (: io format '"~p * ~p = ~p~n" (list a b (* a b)))
      (: io format '"~p^~p = ~p~n" (list a b (: math pow a b)))
      ; div truncates towards zero
      (: io format '"~p div ~p = ~p~n" (list a b (div a b)))
      ; rem's result takes the same sign as the first operand
      (: io format '"~p rem ~p = ~p~n" (list a b (rem a b))))))


Usage from the LFE REPL:

> (slurp '"arith.lfe")
#(ok arith)
> (demo-arith)
Please enter two integers: 2 8
2 + 8 = 10
2 - 8 = -6
2 * 8 = 16
2^8 = 256.0
2 div 8 = 0
2 rem 8 = 2
ok

Version data entries

10 entries across 7 versions & 1 rubygems

Version Path
zettacode-0.1.7 files.zettacode/arithmetic.integer/lfe.txt
zettacode-0.1.6 files.zettacode/arithmetic.integer/lfe.txt
zettacode-0.1.6 files.zettacode2/arithmetic.integer/lfe.txt
zettacode-0.1.5 files.zettacode/arithmetic.integer/lfe.txt
zettacode-0.1.5 files.zettacode2/arithmetic.integer/lfe.txt
zettacode-0.1.4 files.zettacode/arithmetic.integer/lfe.txt
zettacode-0.1.4 files.zettacode2/arithmetic.integer/lfe.txt
zettacode-0.1.3 files.zettacode/arithmetic.integer/lfe.txt
zettacode-0.1.2 files.zettacode/arithmetic.integer/lfe.txt
zettacode-0.1.1 zettacode.files/arithmetic.integer/lfe.txt