Slava Pestov | 23 Apr 01:55

Interesting use of 'fry'

Hi all,

I'm working on the web framework and came up with this:

: render-plain-list ( seq component quot -- )
     '[ , component>> renderer>> @ ] each ; inline

: render-ordered-list ( seq quot component -- )
     <ol> '[ <li> @ </li> ] render-plain-list </ol> ; inline

: render-unordered-list ( seq quot component -- )
     <ul> '[ <li> @ </li> ] render-plain-list </ul> ; inline

: render-list ( value renderer quot -- )
     over type>> {
         { +plain+     [ render-plain-list ] }
         { +ordered+   [ render-ordered-list ] }
         { +unordered+ [ render-unordered-list ] }
     } case ; inline

M: list-renderer render-view*
     [ render-view* ] render-list ;

M: list-renderer render-summary*
     [ render-summary* ] render-list ;

I think this is a pretty nice use-case for 'fry' and its hard to  
imagine how this code could be improved further.

Slava
(Continue reading)

Daniel Ehrenberg | 23 Apr 02:08

Re: Interesting use of 'fry'

<unimportant>
Well, you could do this minor factoring, if you find it hard to
imagine how to improve your code further...

: render-plain-list ( seq component quot -- )
    '[ , component>> renderer>> @ ] each ; inline

: render-li-list ( seq quot component -- )
    '[ <li> @ </li> ] render-plain-list ; inline

: render-ordered-list ( seq quot component -- )
    <ol> render-li-list </ol> ; inline

: render-unordered-list ( seq quot component -- )
    <ul> render-li-list </ul> ; inline

(OK, I guess I'm out of excuses to procrastinate on homework now. Bye)

Dan
</unimportant>

On Tue, Apr 22, 2008 at 6:59 PM, Slava Pestov <slava@...> wrote:
> Hi all,
>
>  I'm working on the web framework and came up with this:
>
>  : render-plain-list ( seq component quot -- )
>      '[ , component>> renderer>> @ ] each ; inline
>
>  : render-ordered-list ( seq quot component -- )
(Continue reading)

Chris Double | 23 Apr 02:18

Re: Interesting use of 'fry'

On Wed, Apr 23, 2008 at 11:59 AM, Slava Pestov <slava@...> wrote:
>  I think this is a pretty nice use-case for 'fry' and its hard to
>  imagine how this code could be improved further.

Maybe use multimethods to get rid of the case and the
render-plain-list, render-ordered-list, etc? Or does this interfere
with the need to inline the code since it uses quotations? The fry
stuff does make it look nice.

Chris.

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
Slava Pestov | 23 Apr 02:25

Re: Interesting use of 'fry'

Hi Chris,

Good point. Having thought about it a little, I think with  
multimethods I'd use the following design:

- render-view*, render-summary* and render-edit* replaced by render*  
taking a singleton symbol (view, summary, edit)
- render-list takes this symbol instead of a quotation

In this case, I could certainly use multi-methods for render-list.

I'm looking forward to having multi-methods in the core :-)

Slava

On Apr 22, 2008, at 7:18 PM, Chris Double wrote:

> Maybe use multimethods to get rid of the case and the
> render-plain-list, render-ordered-list, etc? Or does this interfere
> with the need to inline the code since it uses quotations? The fry
> stuff does make it look nice.
>
> Chris.
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
> Don't miss this year's exciting event. There's still time to save  
> $100.
> Use priority code J8TL2D2.
> http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
(Continue reading)


Gmane