logo       
Google Custom Search
    AddThis Social Bookmark Button

Obj.magic-less of_enum: msg#00032

Subject: Obj.magic-less of_enum
In my ongoing quest to remove all but one Obj.magic calls from ExtList, I 
propose the following implementation for ExtList.of_enum:

let of_enum e =
    try
        let h = [ Enum.next e ] in
        let _ = Enum.fold (fun x acc ->
            let r = [ x ] in
            _setcdr acc r;
            r) h e in
        h
    with Enum.No_more_elements -> []

(I have tabstop set to 4 currently.  That's a different argument.)

This depends upon the exported Enum.next patch.  Basically, if the enum is 
empty creating the head element throws a caught exception and returns [], 
otherwise we go on to the classic fold implementation.

Brian




-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf



Try Searching:
servers, voip, java, networking, microsoft ...
<Prev in Thread] Current Thread [Next in Thread>