Plan 9 from Bell Labs’s /usr/web/sources/contrib/fernan/nhc98/src/libraries/Cabal/tests/wash2hs/test/ManuelsTable.wash

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


module Main where

import Prelude hiding (map, span, head, div)
import CGI

{-- 
    ms> -----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----
    ms> (define (fact n)
    ms>    (if (= n 0)
    ms>        1
    ms>        (* n (fact (- n 1)))))

    ms> (define (make-fact-row n)
    ms>    (tr (td :align 'center (bold n))
    ms>        (td :align 'right (it (fact n)))))

    ms> (define (make-fact-table n)
    ms>    (apply table :border 1
    ms> 	  (tr (th "n=") (th "fact"))
    ms> 	  (map make-fact-row (upto 3 n))))

    ms> (font :size -1 (make-fact-table 11))
    ms> -----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----
-}

fact n =
  if n == 0
     then 1
     else n * fact (n - 1)

makeFactRow n =
  <tr>
    <td align="center"><b> <%= show n %> </b></td>
    <td align="right"><i> <%= show (fact n) %> </i></td>
  </tr>

makeFactTable n =
  <table border="1">
    <tr><th>n=</th> <th>fact</th></tr>
    <% mapM makeFactRow [3..n] %>
  </table>

main = 
  run $ standardQuery "FactTable" $
  <font size="-1"><% makeFactTable 11 %></font>

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.