<div dir="ltr">Every function is jitted the first time it is called if you're running on a platform that the JIT supports (currently x86 and ARM).<div><br></div><div style>Robby</div></div><div class="gmail_extra"><br>
<br><div class="gmail_quote">On Thu, May 23, 2013 at 1:25 PM, Greg Hendershott <span dir="ltr"><<a href="mailto:greghendershott@gmail.com" target="_blank">greghendershott@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
p.s.<br>
<div class="im"><br>
> Also: Am I correct that the user-supplied function gets JIT-ed, and<br>
> there's no big performance hit from this? (I think the answer is no,<br>
<br>
</div>That question had mixed polarities. :) I should have written, I think<br>
the answer is No there's no big performance hit, and Yes it gets<br>
JIT-ed.<br>
<div class="HOEnZb"><div class="h5"><br>
On Thu, May 23, 2013 at 2:22 PM, Greg Hendershott<br>
<<a href="mailto:greghendershott@gmail.com">greghendershott@gmail.com</a>> wrote:<br>
> I've never had a reason to use `dynamic-require`, but now I think I do.<br>
><br>
> For my Frog static blog generator, I'd like to provide a light<br>
> "template" feature, where the user can override the default layout of<br>
> the main container <div> in the page.<br>
><br>
> I have an existing function that returns an xexpr for this. So my idea<br>
> is to let the user optionally supply a `template.rkt` file that<br>
> `provide`s a function named (say) `container` that returns (listof<br>
> xexpr?).<br>
><br>
> So I think what I want to do is something like this:<br>
><br>
> (define (container-proc)<br>
> (define p (build-path (src-path) "template.rkt"))<br>
> (cond [(file-exists? p)<br>
> (dynamic-require p<br>
> 'container<br>
> (thunk default-container))]<br>
> [else default-container]))<br>
><br>
> The built-in `default-container` looks something like this:<br>
><br>
> (define (default-container bootstrap-row-class ;"row" or "row-fluid"<br>
> bodies ;listof xexpr?: main content<br>
> tocs ;listof xexpr?: TOC<br>
> tags/feeds ;listof xexpr?: tag/feed links<br>
> follow) ;listof xexpr?: Twitter, etc.<br>
> `((div ([class ,bootstrap-row-class])<br>
> ;; Left column<br>
> (div ([id "left-sidebar"]<br>
> [class "span2 bs-docs-sidebar"])<br>
> ,@tocs<br>
> (p nbsp))<br>
> ;; Main column<br>
> (div ([id "content"]<br>
> [class "span8"])<br>
> ,@bodies)<br>
> ;; Right column<br>
> (div ([id "right-sidebar"]<br>
> [class "span2"])<br>
> ,@(tags/feeds)<br>
> ,@(follow)))))<br>
><br>
> The user-supplied template.rkt would provide some variation on it. For<br>
> example they don't want any left column with a TOC, so they supply<br>
> this:<br>
><br>
> ;; template.rkt<br>
> #lang racket<br>
> (provide container)<br>
> (define (container bootstrap-row-class ;"row" or "row-fluid"<br>
> bodies ;listof xexpr?: main content<br>
> tocs ;listof xexpr?: TOC<br>
> tags/feeds ;listof xexpr?: tag/feed links<br>
> follow) ;listof xexpr?: Twitter, etc.<br>
> `((div ([class ,bootstrap-row-class])<br>
> ;; Don't want any left column; ignore `tocs`<br>
> ;; Main column<br>
> (div ([id "content"]<br>
> [class "span9"]) ;wider<br>
> ,@bodies)<br>
> ;; Right column: Tags/feeds/follow<br>
> (div ([id "right-sidebar"]<br>
> [class "span3"]) ;wider<br>
> ,@(tags/feeds)<br>
> ,@(follow)))))<br>
><br>
> In a quick experiment this seems to work fine. I could also go further<br>
> and make this a tiny s-exp #lang, to make the end user experience even<br>
> simpler. But meanwhile, and before that, I just want to make sure that<br>
> `dynamic-require` is a reasonable way to do this? Does anyone<br>
> disagree?<br>
><br>
> Also: Am I correct that the user-supplied function gets JIT-ed, and<br>
> there's no big performance hit from this? (I think the answer is no,<br>
> because from reviewing Racket's own source, I got the impression that<br>
> all modules are built on dynamic-require, but I might have<br>
> understood.)<br>
><br>
> Thank you in advance for any advice or suggestions!<br>
____________________<br>
Racket Users list:<br>
<a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
</div></div></blockquote></div><br></div>