Created
November 29, 2009 21:16
-
-
Save JonathanSmith/245073 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 resource4 | |
(author '[email protected]) | |
(export (out 1))) | |
(include-file "/home/jon/clyawjure/yaws-1.85/include/yaws_api.lfe") | |
(defun out (arg) | |
(let* ((url (: yaws_api request_url arg)) | |
(method (http_request-method (arg-req arg))) | |
(path (: string tokens (url-path url) '"/"))) | |
(out arg method path))) | |
;(defmacro gen-out | |
; ([resource node] | |
; ([arg method [_ ',(atom_to_list resource)]] | |
; (let* ((to (tuple ',resource ',node)) | |
; (ref (make_ref))) | |
; (: erlang send to | |
; (tuple (self) ref method [])) | |
; (receive ((tuple ref msg) (tuple 'html msg)) | |
; (after 500 (tuple 'html '"404"))))))) | |
(defmacro gen_out [node resources] | |
(let ((resource_bodies (: lists map | |
(match-lambda | |
([[resource args]] | |
`([arg method [_ ',(atom_to_list resource) ,@args]] | |
(let* ((to (tuple ',resource ',node)) | |
(ref (make_ref))) | |
(: erlang send to | |
(tuple (self) ref method (list ,@args))) | |
(receive ((tuple ref msg) (tuple 'html msg)) | |
(after 500 (tuple 'html '"404"))))))) | |
resources))) | |
`(defun out ,@resource_bodies | |
([arg method [_ Foo . Rest]] | |
(tuple 'html | |
(: io_lib format '"Unknown Resource: ~p ~p ~n" | |
(list Foo Rest))))))) | |
;(defmacro gen_outs [specs] | |
; (let ((foo `(defun out | |
; ,@(: lists map (lambda (a) `(gen_out ~@a)) specs)))) | |
;(: io format '"~p~n" (list foo)) | |
; foo)) | |
(gen_out clojure@Jon-Laptop ([echo ['"bar" '"foo" Bar]] | |
[echo ['"foo" '"bar" Baz]] | |
[echo [Bar]] | |
[add [M N]] | |
[sub [M N]] | |
[mul [M N]] | |
[div [M N]] | |
)) | |
; (gen_outs [(echo clojure@Jon-Laptop [(quote "bar") (quote "foo") Bar]) | |
; (echo clojure@Jon-Laptop [(quote "bar") (quote "foo") Bar]) | |
; (echo clojure@Jon-Laptop [(quote "bar") (quote "foo") Bar])]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment