Skip to content

Instantly share code, notes, and snippets.

@dyoo
Created April 18, 2013 18:28
Show Gist options
  • Save dyoo/5415070 to your computer and use it in GitHub Desktop.
Save dyoo/5415070 to your computer and use it in GitHub Desktop.
Gauss sum, using a very perverse loop. Really a test of continuation prompts.
#lang racket
(define (f i acc)
(cond [(> i 0)
(abort-current-continuation (default-continuation-prompt-tag)
(lambda ()
(f (sub1 i) (+ i acc))))
(printf "You should not see this\n")
(/ 1 0)]
[else
acc]))
(define (gauss i)
(call-with-continuation-prompt (lambda ()
(f i 0))))
(gauss 100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment