Comment

Comment by masswerk

  ; Palindrome test by simple reduction
  ; "(0)" is a catch-all pattern
  ; "NONE" matches, where no keyword matches
  ; - ideal for help phrases
  
  (PALIN
      ((PALIN 0) (PRE (2) (=REDUCE)))
  )
  
  (REDUCE
      ((A)     (=TERM_TRUE))
      ((B)     (=TERM_TRUE))
      ((A A)   (=TERM_TRUE))
      ((B B)   (=TERM_TRUE))
      ((A 0 A) (PRE (2) (=REDUCE)))
      ((B 0 B) (PRE (2) (=REDUCE)))
      ((0)     (=TERM_FALSE))
  )
  
  (TERM_TRUE
      ((0) (WELL, THIS IS A PALINDROME))
  )
  
  (TERM_FALSE
      ((0) (NOT A PALINDROME AT ALL))
  )
  
  (NONE
      ((0) (TRY: PALIN A B A))
  )
parent masswerk 4 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton