def repl(): """Start the interactive Read-Eval-Print-Loop""" print() print(" " + faded(" \`. T ")) print(" Welcome to " + faded(" .--------------.___________) \ | T ")) print(" the DIY-lisp " + faded(" |//////////////|___________[ ] ! T | ")) print(" REPL " + faded(" `--------------' ) ( | ! ")) print(" " + faded(" '-' ! ")) print(faded(" use ^D to exit")) print() env = Environment() interpret_file(join(dirname(relpath(__file__)), '..', 'stdlib.diy'), env) while True: try: source = read_expression() print(interpret(source, env)) except LispError as e: print(colored("!", "red")) print(faded(str(e.__class__.__name__) + ":")) print(str(e)) except KeyboardInterrupt: msg = "Interupted. " + faded("(Use ^D to exit)") print("\n" + colored("! ", "red") + msg) except EOFError: print(faded("\nBye! o/")) sys.exit(0) except Exception as e: print(colored("! ", "red") + faded("The Python is showing through…")) print(faded(" " + str(e.__class__.__name__) + ":")) print(str(e))
def repl(): """Start the interactive Read-Eval-Print-Loop""" print() print(" " + faded(" \`. T ")) print(" Welcome to " + faded(" .--------------.___________) \ | T ")) print(" the DIY-lisp " + faded(" |//////////////|___________[ ] ! T | ")) print(" REPL " + faded(" `--------------' ) ( | ! ")) print(" " + faded(" '-' ! ")) print(faded(" use ^D to exit")) print() env = Environment() interpret_file(join(dirname(relpath(__file__)), '..', 'stdlib.diy'), env) while True: try: source = read_expression() print(interpret(source, env)) except LispError as e: print(colored("!", "red")) print(faded(str(e.__class__.__name__) + ":")) print(str(e)) except KeyboardInterrupt: msg = "Interupted. " + faded("(Use ^D to exit)") print("\n" + colored("! ", "red") + msg) except EOFError: print(faded("\nBye! o/")) sys.exit(0) except Exception as e: print( colored("! ", "red") + faded("The Python is showing through…")) print(faded(" " + str(e.__class__.__name__) + ":")) print(str(e))
# -*- coding: utf-8 -*- from nose.tools import assert_equals from os.path import dirname, relpath, join from diylisp.interpreter import interpret, interpret_file from diylisp.types import Environment env = Environment() path = join(dirname(relpath(__file__)), '..', 'stdlib.diy') interpret_file(path, env) """ Consider these tests as suggestions for what a standard library for your language could contain. Each test function tests the implementation of one stdlib function. Put the implementation in the file `stdlib.diy` at the root directory of the repository. The first function, `not` is already defined for you. It's your job to create the rest, or perhaps something completely different? Anything you put in `stdlib.diy` is also available from the REPL, so feel free to test things out there. $ ./repl → (not #t) #f PS: Note that in these tests, `interpret` is used. In addition to parsing and evaluating, it "unparses" the result, hence strings such as "#t" as the expected result instead of `True`.
# -*- coding: utf-8 -*- from nose.tools import assert_equals from os.path import dirname, relpath, join from diylisp.interpreter import interpret, interpret_file from diylisp.types import Environment env = Environment() path = join(dirname(relpath(__file__)), '..', 'stdlib.diy') interpret_file(path, env) """ Consider these tests as suggestions for what a standard library for your language could contain. Each test function tests the implementation of one stdlib function. Put the implementation in the file `stdlib.diy` at the root directory of the repository. The first function, `not` is already defined for you. It's your job to create the rest, or perhaps somthing completely different? Anything you put in `stdlib.diy` is also available from the REPL, so feel free to test things out there. $ ./repl → (not #t) #f PS: Note that in these tests, `interpret` is used. In addition to parsing and evaluating, it "unparses" the result, hence strings such as "#t" as the expected result instead of `True`. """
def prepare_env(): global env env = Environment() path = join(dirname(relpath(__file__)), '..', 'stdlib.diy') interpret_file(path, env)