Skip to content

Instantly share code, notes, and snippets.

@sinelaw
Last active August 29, 2015 14:23
Show Gist options
  • Save sinelaw/161cd4c94987a1b82802 to your computer and use it in GitHub Desktop.
Save sinelaw/161cd4c94987a1b82802 to your computer and use it in GitHub Desktop.
Next-generation IDE for functional programming
# Next-generation IDE for functional programming
# Run it, and press any key to start writing code.
# It will automatically exit when you're done writing your function.
# Work in progress, currently supports factorial
import sys
factorial = 'fac n = if n > 1 then n * (fac (n - 1)) else 1'.split()
# Copied from rosettacode.org: http://rosettacode.org/wiki/Keyboard_input/Keypress_check#Python
try:
from msvcrt import getch # try to import Windows version
except ImportError:
def getch(): # define non-Windows version
import sys, tty, termios
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(sys.stdin.fileno())
ch = sys.stdin.read(1)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
return ch
for code in factorial:
getch()
print code,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment