shorter lines in example/is-palindrome.forth
FossilOrigin-Name: c165ad47ac1755bbb5b0b2f7de41286d47de5aac2e7da4af1d4d0640bbc16790
This commit is contained in:
parent
ab1a93a1a8
commit
fa7aa5da72
1 changed files with 6 additions and 3 deletions
|
@ -2,14 +2,17 @@
|
|||
|
||||
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.
|
||||
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.
|
||||
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?
|
||||
````
|
||||
````
|
||||
|
|
Loading…
Reference in a new issue