Changeset 14953 for src/Pugs/Prim.hs
- Timestamp:
- 12/30/06 14:29:18 (23 months ago)
- Files:
-
- 1 modified
-
src/Pugs/Prim.hs (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Pugs/Prim.hs
r14933 r14953 181 181 op1 "sort" = \v -> do 182 182 args <- fromVal v 183 (valList, sortBy ) <- case args of183 (valList, sortByGiven) <- case args of 184 184 (v:vs) -> do 185 185 ifValTypeIsa v "Code" … … 189 189 (return (args, Nothing))) 190 190 _ -> return (args, Nothing) 191 case sortBy of 192 Nothing -> do 193 strs <- mapM fromVal valList 194 retSeq . map snd . sort $ (strs :: [VStr]) `zip` valList 195 Just subVal -> do 196 sub <- fromVal subVal 197 sorted <- (`sortByM` valList) $ \v1 v2 -> do 198 rv <- enterEvalContext (cxtItem "Int") $ App (Val sub) Nothing [Val v1, Val v2] 199 int <- fromVal rv 200 return (int <= (0 :: Int)) 201 retSeq sorted 191 sortBy <- case sortByGiven of 192 Nothing -> readVar (cast "&infix:cmp") 193 Just subVal -> return subVal 194 sub <- fromVal sortBy 195 sorted <- (`sortByM` valList) $ \v1 v2 -> do 196 rv <- enterEvalContext (cxtItem "Int") $ App (Val sub) Nothing [Val v1, Val v2] 197 int <- fromVal rv 198 return (int <= (0 :: Int)) 199 retSeq sorted 202 200 op1 "Scalar::reverse" = \v -> do 203 201 str <- fromVal v … … 952 950 op2 "=>" = \x y -> return $ castV (x, y) 953 951 op2 "=" = \x y -> evalExp (Syn "=" [Val x, Val y]) 954 op2 "cmp"= op2Ord vCastStr952 op2 "cmp"= op2OrdNumStr 955 953 op2 "leg"= op2Ord vCastStr 956 954 op2 "<=>"= op2Ord vCastRat … … 1515 1513 EQ -> 0 1516 1514 GT -> 1 1515 1516 isNumeric :: Val -> Bool 1517 isNumeric (VNum {}) = True 1518 isNumeric (VRat {}) = True 1519 isNumeric (VInt {}) = True 1520 isNumeric _ = False 1521 1522 op2OrdNumStr :: Val -> Val -> Eval Val 1523 op2OrdNumStr x y 1524 | isNumeric x && isNumeric y = op2Ord vCastRat x y 1525 | otherwise = op2Ord vCastStr x y 1517 1526 1518 1527 op3Caller :: Type -> Int -> Val -> Eval Val … … 2069 2078 \\n Bool left ?& safe (Bool, Bool)\ 2070 2079 \\n Pair right => safe (Any, Any)\ 2071 \\n Int non cmp safe ( Str, Str)\2080 \\n Int non cmp safe (Any, Any)\ 2072 2081 \\n Int non leg safe (Str, Str)\ 2073 2082 \\n Int non <=> safe (Num, Num)\
