how to wrap functions from a context without prefixing?
Posted: Thu Jun 20, 2013 12:50 am
This is a mock-up to simplify my question.
I got these scheme:
File wrappers.lsp contains functions to wrap snippets of reusable code like: header, navbar, sidebar, you-get-the-idea.
File main.lsp calls functions from wrappers.lsp.
Now, the context switch shown in function wrap-one wont produce the desired result. I think it's because the double pass newlisp parser does. So on the first pass (hin-show) gets transformed into (MAIN:hin-show).
The idea of hin.lsp is to be able to wrote code like this:
If I have to prefix every call with "hin:" or even with an alias like "h:" hin's while purpose is defeated, which is to be as close to HTML syntax as possible.
My question is: what's the best way to wrap functions calls from hin inside a function defined in another context without prefixing hin calls?
I'm trying to build a macro to parse those calls by my own and prefix when appropriate, it will be used like this:
But I'm having problems recurring inside the macro. And now I'm thinking all this extra parsing could make the whole idea to work too slow. Anyway, I'm digressing. Back to the point: any ideas about how to avoid prepending all calls with context name?
I got these scheme:
- hin.lsp
Code: Select all
(context 'hin) (define (hin-show) (println "from hin.lsp"))
- wrappers.lsp
Code: Select all
(load "hin.lsp") (define (wrap-one) (context hin) (hin-show) ; this wont work (context MAIN))
- main.lsp
Code: Select all
(load "wrappers.lsp") (wrap-one)
File wrappers.lsp contains functions to wrap snippets of reusable code like: header, navbar, sidebar, you-get-the-idea.
File main.lsp calls functions from wrappers.lsp.
Now, the context switch shown in function wrap-one wont produce the desired result. I think it's because the double pass newlisp parser does. So on the first pass (hin-show) gets transformed into (MAIN:hin-show).
The idea of hin.lsp is to be able to wrote code like this:
Code: Select all
(html lang= "en"
(head
(title "Some title"))
(body
(p class= "shiny" "Lore ipsum...")))
My question is: what's the best way to wrap functions calls from hin inside a function defined in another context without prefixing hin calls?
I'm trying to build a macro to parse those calls by my own and prefix when appropriate, it will be used like this:
Code: Select all
(define (wrap-one)
(wrap-in-context
(...))) ; calls to hin functions