Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -1621,7 +1621,8 @@
"recursion",
"strings",
"errors",
"locals"
"locals",
"generics"
],
"difficulty": 6
},
Expand Down
11 changes: 11 additions & 0 deletions exercises/concept/bering-bearings/.docs/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,17 @@ against its class: a mismatch like `"x" triple` is rejected
(*expected input value of type integer but got string*) rather
than silently flowing through.

The output can be annotated the same way. `yes?` types both its
input and its result:

```factor
TYPED:: yes? ( word: string -- answer: boolean )
word "yes" = ;

"yes" yes? . ! => t
"no" yes? . ! => f
```

## Math functions and constants

This exercise also leans on a few words from `math.constants`
Expand Down
4 changes: 2 additions & 2 deletions exercises/concept/bering-bearings/.meta/exemplar.factor
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
USING: accessors combinators kernel locals math math.constants
math.functions namespaces ;
math.functions namespaces typed ;
IN: bering-bearings

SYMBOLS: north east south west
Expand Down Expand Up @@ -61,7 +61,7 @@ M: relative flip
{ port [ starboard ] }
} case ] change-bearing ;

:: add-bearings ( a b -- x y )
TYPED:: add-bearings ( a b -- x: number y: number )
a >cartesian :> ay :> ax
b >cartesian :> by :> bx
ax bx +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ IN: bering-bearings
! Define `flip` as a generic word with one method per
! direction class.

! Define `add-bearings` here.
! Define `add-bearings` here, using TYPED:: to type its
! cartesian outputs: ( a b -- x: number y: number ).
2 changes: 1 addition & 1 deletion exercises/practice/bank-account/.meta/example.factor
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ IN: bank-account

TUPLE: bank-account open? balance lock ;

: <bank-account> ( -- account )
: <bank-account> ( -- account: bank-account )
bank-account new
f >>open?
0 >>balance
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
USING: kernel math typed ;
USING: kernel typed ;
IN: bank-account

TUPLE: bank-account ;

: <bank-account> ( -- account )
: <bank-account> ( -- account: bank-account )
"unimplemented" throw ;

TYPED:: open-account ( account: bank-account -- )
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/nth-prime/nth-prime/nth-prime.factor
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
USING: kernel math typed ;
USING: kernel typed ;
IN: nth-prime

TYPED:: nth-prime ( n: integer -- prime: integer )
Expand Down
8 changes: 4 additions & 4 deletions exercises/practice/say/.meta/example.factor
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
USING: kernel locals math math.order sequences strings ;
USING: kernel locals math math.order sequences strings typed ;
IN: say

CONSTANT: ones { "zero" "one" "two" "three" "four" "five" "six" "seven" "eight" "nine"
Expand Down Expand Up @@ -31,6 +31,6 @@ CONSTANT: tens { f f "twenty" "thirty" "forty" "fifty" "sixty" "seventy" "eighty
dup 1000 >= [ 1000 "thousand" say-chunk ] when
dup 0 > [ say-below-1000 swap dup empty? [ drop ] [ swap " " glue ] if ] [ drop ] if ;

: say ( n -- str )
dup 0 999999999999 between? [ "input out of range" throw ] unless
dup 0 = [ drop "zero" ] [ say-positive ] if ;
TYPED:: say ( n: integer -- str: string )
n 0 999999999999 between? [ "input out of range" throw ] unless
n 0 = [ "zero" ] [ n say-positive ] if ;
4 changes: 2 additions & 2 deletions exercises/practice/say/say/say.factor
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
USING: kernel ;
USING: kernel typed ;
IN: say

: say ( n -- str )
TYPED:: say ( n: integer -- str: string )
"unimplemented" throw ;