Paste: why 3 semantics errors ?

Author: Ludovic Kuty
Mode: factor
Date: Fri, 20 Feb 2009 07:44:34
Plain Text |
USING: kernel accessors prettyprint namespaces math math.constants syntax ;
IN: scratchpad

TUPLE: rectangle { width float }  { height float } ;
: <rectangle> ( -- rectangle )
   rectangle new ;

TUPLE: circle { radius float } ;
: <circle> ( -- circle )
   circle new ;

GENERIC: area

M: rectangle area ( rectangle -- x )
   dup width>> swap height>> * ;

M: circle area ( circle -- x )
   radius>> dup * pi * ;

<rectangle>
   100 >>width
   50 >>height
area .

<circle>
   10 >>radius
area .

Annotation: semantic errors

Author: Ludovic Kuty
Mode: factor
Date: Fri, 20 Feb 2009 07:49:51
Plain Text |
( scratchpad ) :errors

While compiling area: 

In word: area
The word rectangle=>area must declare a stack effect

While compiling circle=>area: 

In word: circle=>area
The word circle=>area must declare a stack effect

While compiling rectangle=>area: 

In word: area
The word rectangle=>area must declare a stack effect

Annotation: using bi instead of swap and dup

Author: Ludovic Kuty
Mode: factor
Date: Fri, 20 Feb 2009 09:20:47
Plain Text |
Also

dup width>> swap height>> *

should be written

[ width>> ] [ height>> ] bi *

New Annotation

Summary:
Author:
Mode:
Body: