Skip to content
Open
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
44 changes: 44 additions & 0 deletions solutions/8th/bob/1/bob.8th
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
: is-question \ s -- b
1 s:rsub "?" =
;

: is-capitalized \ s -- b
s:uc s:cmp 0 =
;

: is-letter \ n -- b
dup 65 90 n:between
swap 97 122 n:between or
;

: contains-letter \ s -- b
false swap
( nip is-letter if
drop true break
then
) s:each
;

: is-capitalized-word \ s -- b
contains-letter swap dup is-capitalized and
;

: bob \ s -- s
dup s:trim s:len 0 = if
2drop "Fine. Be that way!" cr
else
dup is-question if
dup is-capitalized-word if
drop "Calm down, I know what I'm doing!" cr
else
drop "Sure." cr
then
else
dup is-capitalized-word if
drop "Whoa, chill out!" cr
else
drop "Whatever." cr
then
then
then
;