withPort :: Handle
         -> (ScmValue -> ([ScmValue] -> IO (ErrOr ScmValue)))
         -> Int
         -> String
         -> (Handle -> [ScmValue] -> IO (ErrOr ScmValue))
         -> [ScmValue] -> IO (ErrOr ScmValue)

withPort defaultHdl apply idx s f args =
   let (xs, p) = splitAt idx args
    in case p of
            [x] -> apply x xs
            []  -> f defaultHdl xs
            _   -> return$ tooManyArgs s
withPort :: Handle
         -> (ScmValue -> ([ScmValue] -> IO (ErrOr ScmValue)))
         -> Int
         -> String
         -> (Handle -> [ScmValue] -> IO (ErrOr ScmValue))
         -> [ScmValue] -> IO (ErrOr ScmValue)
withPort defaultHdl apply idx s f args =
   let (xs, p) = splitAt idx args
    in case p of
            [x] -> apply x xs
            []  -> f defaultHdl xs
            _   -> return$ tooManyArgs s
withPort defaultHdl apply idx s f args =
   let (xs, p) = splitAt idx args
    in case p of
            [x] -> apply x xs
            []  -> f defaultHdl xs
            _   -> return$ tooManyArgs s