Created
February 17, 2010 05:03
-
-
Save JonathanSmith/306323 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defmodule imp (export (bar 0))) | |
(eval-when-compile | |
(defun import-function-1 (module function) | |
;(: io format '"~p~p~n" (list module function)) | |
(let ((mod-fun (list_to_atom | |
(: lists concat (list module '":" function))))) | |
; (: io format '"~p~n" (list mod-fun)) | |
(let ((bar `(defmacro ,mod-fun | |
(() | |
`(: ,',module ,',function)) | |
((arg) | |
`(: ,',module ,',function ,arg)) | |
((arg . args) | |
`(: ,',module ,',function ,arg ,@args))))) | |
;(: io format '"~p~n" (list bar)) | |
bar)))) | |
(defmacro import-function (module function) | |
(import-function-1 module function)) | |
(defmacro import-module (module) | |
;(: io format '"~p~n" (list module)) | |
(let ((mod-symbols (call module 'module_info 'exports))) | |
; (: io format '"~p~n" (list mod-symbols)) | |
(let ((bar `(progn | |
,@(: lists | |
usort | |
(: lists map | |
(lambda (X) | |
(case X | |
((tuple fn-symbol _arity) | |
(import-function-1 module fn-symbol)))) | |
mod-symbols))))) | |
; (: io format '"~p~n" (list bar)) | |
bar))) | |
(import-module io) | |
(import-module math) | |
(defun bar () (io:format '"bar~p~n" (list (math:sin (math:pi))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment