On Mon, Oct 13, 2008 at 22:09, Per Cederberg <[EMAIL PROTECTED]> wrote:
> I fooled around a bit with the visual effects instead...
> http://www.percederberg.net/mochikit/pack.html

Ah, nice, very nice.

As for the other thing (generating the pack) - I don't think there is
a good, clean way to do it on the client side and probably something
server side (it can be dead-simple) is the way to go.

Although, there is one outrageous possibility: We could pregenerate
all possible combinations of modules. Now, before you call me crazy,
note that even if 14 modules could potentially mean 2^14~=16k
different combinations, the dependency graph puts severe restrictions
on that. So for fun, I decided to see how many there really are. Given
the dependency specs Per used in the above html file, there are
exactly 1952 possible combinations such that all dependencies are
included :D

Now, generating these 1952 files every time there is a commit might
seem stupid, but it is actually doable :)

Ok, now feel free to call me crazy.

Below this message is a Haskell program to find all legal combinations.

cheers,
Arnar


module Main where

import Control.Concurrent (forkIO)
import Control.Concurrent.MVar
import Data.Maybe (fromJust)
import Data.List (nub)

-- Modules in topological order, i.e.
-- a module must appear after all of its
-- dependencies
dependencies = [
 ("Base",[]),
 ("DateTime",["Base"]),
 ("Format",["Base"]),
 ("Iter",["Base"]),
 ("Async",["Base"]),
 ("DOM",["Base"]),
 ("Style",["Base"]),
 ("Color",["DOM", "Style"]),
 ("Logging",["Base"]),
 ("LoggingPane",["Logging"]),
 ("Selector",["DOM", "Style"]),
 ("Signal",["DOM", "Style"]),
 ("Visual",["Color"]),
 ("DragAndDrop",["Iter","Signal","Visual"]),
 ("Sortable",["DragAndDrop"])
 ]

modules = map fst dependencies


antichains :: MVar (Maybe [String]) -> IO ()
antichains channel = antichains' [] modules >> putMVar channel Nothing
    where
      antichains' :: [String] -> [String] -> IO ()
      antichains' ac [] = putMVar channel (Just ac) >> return ()
      antichains' ac (candidate:rest) =
          do if ac `accepts` candidate
                then antichains' (candidate:ac) rest
                else return ()
             antichains' ac rest
      chain `accepts` candidate =
          all (\c -> not . elem c
                     $ fromJust
                     $ lookup candidate dependencies) chain

closure :: [String] -> [String]
closure ms =
    let missing = nub $ filter (not . flip elem ms)
                  $ concatMap (fromJust . flip lookup dependencies) ms
    in
      if null missing
         then ms
         else closure (ms ++ missing)

printer :: MVar () -> MVar (Maybe [String]) -> IO ()
printer stop in_ =
    do v <- takeMVar in_
       case v of
         Just xs -> putStrLn $ show $ closure xs
         Nothing -> putMVar stop ()
       printer stop in_

main :: IO ()
main = do chan <- newEmptyMVar
          stop <- newEmptyMVar
          forkIO $ printer stop chan
          forkIO $ antichains chan
          takeMVar stop
          return ()

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"MochiKit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/mochikit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to