retroforth/example/is-palindrome.forth
crc 9b5212cb45 updates to some examples
FossilOrigin-Name: 6efdcd9c4a9455a2f908fa727dae442aee8f7c3e5a5d6c4d09f1ad53960d9d89
2018-06-20 13:03:22 +00:00

19 lines
502 B
Forth

# rosetta|is-palindrome
A palindrome is a phrase which reads the same backward and forward.
Write a function or program that checks whether a given sequence of
characters (or, if you prefer, bytes) is a palindrome.
In Retro this is fairly easy. We can use `s:hash` to identify a unique
string. So make a copy, take he hash, reverse the copy, get its hash,
and compare them.
~~~
:s:palindrome? (s-f)
[ s:hash ]
[ s:reverse s:hash ] bi eq? ;
'ingirumimusnocteetconsumimurigni s:palindrome?
~~~