retroforth/example/is-palindrome.forth
crc 3f1775f73a drop RoseetaCode| prefix
FossilOrigin-Name: 553edaf3baa258b7cf87caf6e76dcc4dcfece3065f5994080cac2760d41fd473
2017-10-19 12:01:53 +00:00

15 lines
No EOL
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)
dup s:hash [ s:reverse s:hash ] dip eq? ;
'ingirumimusnocteetconsumimurigni s:palindrome?
````