examples/FactorialI.tea
author Jan Vrany <jan.vrany@fit.cvut.cz>
Sun, 27 Sep 2015 07:07:46 +0100
changeset 19 7597503194b8
permissions -rw-r--r--
First shot of libt and some examples libt serves (well, might serve at some point) as a basic library for Tea language. Added directory with examples demostration Tea (and libt) Both includes makefiles to compile libt and examples to compile them down to machine code. This also demonstrates how to use `teak`, a standalone Tea compiler.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
19
7597503194b8 First shot of libt and some examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     1
nil subclass: #FactorialI
7597503194b8 First shot of libt and some examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     2
    category: 't-Examples'
7597503194b8 First shot of libt and some examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     3
!
7597503194b8 First shot of libt and some examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     4
7597503194b8 First shot of libt and some examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     5
!FactorialI class methodsFor:'examples'!
7597503194b8 First shot of libt and some examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     6
factorialI:v <tSIntegerW> <^ tSIntegerW>
7597503194b8 First shot of libt and some examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     7
    | result <tSIntegerW> 
7597503194b8 First shot of libt and some examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     8
      i <tSIntegerW> |
7597503194b8 First shot of libt and some examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     9
7597503194b8 First shot of libt and some examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    10
    result := 0.
7597503194b8 First shot of libt and some examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    11
    i := v.
7597503194b8 First shot of libt and some examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    12
7597503194b8 First shot of libt and some examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    13
    [ i > 1 ] whileTrue:[ 
7597503194b8 First shot of libt and some examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    14
        result := result * i.
7597503194b8 First shot of libt and some examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    15
        i := i - 1
7597503194b8 First shot of libt and some examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    16
    ].
7597503194b8 First shot of libt and some examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    17
    ^ result
7597503194b8 First shot of libt and some examples
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    18
! !