├── .gitignore ├── README.md ├── hype └── ann.hy └── setup.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | 5 | # C extensions 6 | *.so 7 | 8 | # Distribution / packaging 9 | .Python 10 | env/ 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | lib/ 17 | lib64/ 18 | parts/ 19 | sdist/ 20 | var/ 21 | *.egg-info/ 22 | .installed.cfg 23 | *.egg 24 | 25 | # PyInstaller 26 | # Usually these files are written by a python script from a template 27 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 28 | *.manifest 29 | *.spec 30 | 31 | # Installer logs 32 | pip-log.txt 33 | pip-delete-this-directory.txt 34 | 35 | # Unit test / coverage reports 36 | htmlcov/ 37 | .tox/ 38 | .coverage 39 | .cache 40 | nosetests.xml 41 | coverage.xml 42 | 43 | # Translations 44 | *.mo 45 | *.pot 46 | 47 | # Django stuff: 48 | *.log 49 | 50 | # Sphinx documentation 51 | docs/_build/ 52 | 53 | # PyBuilder 54 | target/ 55 | 56 | .ropeproject/ 57 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Hype 2 | ==== 3 | The Hype is Real! 4 | 5 | With the help of the [typeannotations]( https://github.com/ceronman/typeannotations ) you can have types, AND type checking with Hy! 6 | 7 | Work in progress! 8 | 9 | ```hy 10 | => (require hype.ann) 11 | => (ann foo [int :-> str]) 12 | => (defn foo [a] (str a)) 13 | => (foo 1) 14 | '1' 15 | => (foo "1") 16 | Traceback (most recent call last): 17 | ... 18 | TypeError: Incorrect type for "a" 19 | ``` 20 | -------------------------------------------------------------------------------- /hype/ann.hy: -------------------------------------------------------------------------------- 1 | (import [annotation.typed [typechecked]]) 2 | (import [annotation.typed [*]]) 3 | 4 | 5 | (defn AddAnnotations [ann] 6 | (defn _ [fn] 7 | (def fn-args fn.--code--.co-varnames) 8 | (def ret-ann (if (in :-> ann) (first (slice ann (+ 1 (.index ann :->)))))) 9 | (def ann-args (dict (zip fn-args (slice ann 0 (len fn-args))))) 10 | (if ret-ann (assoc ann-args "return" ret-ann)) 11 | (setv fn.--annotations-- ann-args) 12 | (typechecked fn)) 13 | _) 14 | 15 | 16 | (defmacro ann [sym args] 17 | "Define function annotations over a function" 18 | `(defmacro defn [name lambda-list &rest body] 19 | (import hy.models.list) 20 | (def a (hy.models.list.HyList '~args)) 21 | (if (= '~sym name) 22 | `(do (import [hype.ann [AddAnnotations]]) 23 | (with-decorator (AddAnnotations ~a) (setv ~name (fn ~lambda-list ~@body)))) 24 | `(setv ~name (fn ~lambda-list ~@body)))) 25 | ) 26 | 27 | 28 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | ## adderall - miniKanren in Hy 3 | ## Copyright (C) 2014 Gergely Nagy 4 | ## 5 | ## This library is free software: you can redistribute it and/or 6 | ## modify it under the terms of the GNU Lesser General Public License 7 | ## as published by the Free Software Foundation, either version 3 of 8 | ## the License, or (at your option) any later version. 9 | ## 10 | ## This library is distributed in the hope that it will be useful, but 11 | ## WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | ## Lesser General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU Lesser General Public 16 | ## License along with this program. If not, see . 17 | 18 | from setuptools import find_packages, setup 19 | 20 | setup( 21 | name="hype", 22 | version="0.1.0", 23 | install_requires = ['hy>=0.10','typeannotations>=1.0.0'], 24 | dependency_links = [ 25 | 'http://github.com/ceronman/typeannotations/tarball/master#egg=typeannotations-1.0.0', 26 | ], 27 | packages=find_packages(exclude=['tests']), 28 | package_data={ 29 | 'hype': ['*.hy'], 30 | }, 31 | author="Morten Linderud", 32 | author_email="Morten@Linderud.pw", 33 | long_description="Function Annotations library for Hylang.", 34 | license="", 35 | url="https://github.com/Foxboron/hype", 36 | platforms=['any'], 37 | classifiers=[ 38 | "Development Status :: 3 - Alpha", 39 | "Intended Audience :: Developers", 40 | "Operating System :: OS Independent", 41 | "Programming Language :: Lisp", 42 | "Topic :: Software Development :: Libraries", 43 | ] 44 | ) 45 | --------------------------------------------------------------------------------