Hacker News new | past | comments | ask | show | jobs | submit login
Show HN: Scheme with first-class call/cc in 700 lines of Go code (github.com/nukata)
1 point by suzuki on March 17, 2019 | hide | past | favorite | 1 comment



This is a small interpreter of a subset of Scheme. It implements the same language as https://github.com/nukata/little-scheme-in-python (and also its meta-circular interpreter, https://github.com/nukata/little-scheme). As a Scheme implementation, it also handles first-class continuations and runs the yin-yang puzzle correctly.

  $ cat yin-yang-puzzle.scm
  ;; The yin-yang puzzle 
  ;; cf. https://en.wikipedia.org/wiki/Call-with-current-continuation
  
  ((lambda (yin)
     ((lambda (yang)
        (yin yang))
      ((lambda (cc)
         (display '*)
         cc)
       (call/cc (lambda (c) c)))))
   ((lambda (cc)
      (newline)
      cc)
    (call/cc (lambda (c) c))))
  
  ;; => \n*\n**\n***\n****\n*****\n******\n...
  $ little-scheme-in-go yin-yang-puzzle.scm | head
  
  *
  **
  ***
  ****
  *****
  ******
  *******
  ********
  *********
  $




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: