@@ -33,7 +33,7 @@ type Builtin = WhnfEvaluator -> [CoreExpr] -> Interpreter CoreExpr
33
33
--
34
34
euPanic :: WhnfEvaluator -> [CoreExpr ] -> Interpreter CoreExpr
35
35
euPanic _ [e@ (CorePrim (CoreString s))] = throwEvalError $ Panic s e
36
- euPanic _ args = throwEvalError $ Bug " Bad arguments for panic" (CoreList args )
36
+ euPanic _ as = throwEvalError $ Bug " Bad arguments for panic" (CoreList as )
37
37
38
38
-- | __NULL builtin - evaluates to null primitive. Arity 0.
39
39
--
@@ -71,7 +71,7 @@ euEq whnfM [l, r] = do
71
71
l' <- forceDataStructures whnfM l
72
72
r' <- forceDataStructures whnfM r
73
73
return $ (CorePrim . CoreBoolean ) (l' == r')
74
- euEq _ args = throwEvalError $ Bug " __EQ called with bad args " (CoreList args )
74
+ euEq _ as = throwEvalError $ Bug " __EQ called with bad as " (CoreList as )
75
75
76
76
-- | Evaluate an expression and ensure it's a boolean value.
77
77
evalBoolean :: WhnfEvaluator -> CoreExpr -> Interpreter Bool
@@ -90,14 +90,14 @@ euIf whnfM [c, t, f] = do
90
90
if cbool
91
91
then t
92
92
else f
93
- euIf _ args = throwEvalError $ Bug " __IF called with bad args " (CoreList args )
93
+ euIf _ as = throwEvalError $ Bug " __IF called with bad as " (CoreList as )
94
94
95
95
-- | __NOT(b) - 'b' must be boolean. Arity 1. Strict in 'b'. Runtime
96
96
-- error if 'b' is not a boolean.
97
97
--
98
98
euNot :: WhnfEvaluator -> [CoreExpr ] -> Interpreter CoreExpr
99
99
euNot whnfM [e] = CorePrim . CoreBoolean . not <$> evalBoolean whnfM e
100
- euNot _ args = throwEvalError $ Bug " __NOT called with bad args " (CoreList args )
100
+ euNot _ as = throwEvalError $ Bug " __NOT called with bad as " (CoreList as )
101
101
102
102
-- | __AND(l,r) - 'l' and 'r' must be boolean. Arity 2. Strict in 'l'
103
103
-- and 'r'.
@@ -107,7 +107,7 @@ euAnd whnfM [l, r] = do
107
107
lbool <- evalBoolean whnfM l
108
108
rbool <- evalBoolean whnfM r
109
109
return $ CorePrim (CoreBoolean (lbool && rbool))
110
- euAnd _ args = throwEvalError $ Bug " __AND called with bad args " (CoreList args )
110
+ euAnd _ as = throwEvalError $ Bug " __AND called with bad as " (CoreList as )
111
111
112
112
-- | __OR(l,r) - 'l' and 'r' must be boolean. Arity 2. Strict in 'l'
113
113
-- and 'r'.
@@ -117,7 +117,7 @@ euOr whnfM [l, r] = do
117
117
lbool <- evalBoolean whnfM l
118
118
rbool <- evalBoolean whnfM r
119
119
return $ CorePrim (CoreBoolean (lbool || rbool))
120
- euOr _ args = throwEvalError $ Bug " __OR called with bad args " (CoreList args )
120
+ euOr _ as = throwEvalError $ Bug " __OR called with bad as " (CoreList as )
121
121
122
122
-- | General binary arithmetic implementation, takes care of
123
123
-- destructuring and type casting
@@ -135,7 +135,7 @@ arith whnfM op [l, r] = do
135
135
(CorePrim (CoreFloat i), CorePrim (CoreInt j)) ->
136
136
return $ CorePrim (CoreFloat $ i `op` fromInteger j)
137
137
(i, j) -> throwEvalError $ NotNumber (CoreList [i, j])
138
- arith _ _ args = throwEvalError $ Bug " Arith op called with bad args " (CoreList args )
138
+ arith _ _ as = throwEvalError $ Bug " Arith op called with bad as " (CoreList as )
139
139
140
140
141
141
-- | __ADD(l, r) - 'l' and 'r' must be numbers. Arity 2. String in both.
@@ -169,7 +169,7 @@ euDiv whnfM [l, r] = do
169
169
then throwEvalError $ DivideByZero r
170
170
else return $ CorePrim (CoreFloat val)
171
171
172
- euDiv _ args = throwEvalError $ Bug " Division with bad args " (CoreList args )
172
+ euDiv _ as = throwEvalError $ Bug " Division with bad as " (CoreList as )
173
173
174
174
-- | General binary arithmetic comparison implementation, takes care
175
175
-- of destructuring and type casting
@@ -187,7 +187,7 @@ arithComp whnfM op [l, r] = do
187
187
(CorePrim (CoreFloat i), CorePrim (CoreInt j)) ->
188
188
return $ CorePrim (CoreBoolean $ i `op` fromInteger j)
189
189
(i, j) -> throwEvalError $ NotNumber (CoreList [i, j])
190
- arithComp _ _ args = throwEvalError $ Bug " Comparison op called with bad args " (CoreList args )
190
+ arithComp _ _ as = throwEvalError $ Bug " Comparison op called with bad as " (CoreList as )
191
191
192
192
-- | __LT(l, r) - 'l' and 'r' must be numbers. Arity 2. String in both.
193
193
euLt :: WhnfEvaluator -> [CoreExpr ] -> Interpreter CoreExpr
@@ -213,7 +213,7 @@ euHead whnfM [l] =
213
213
(CoreList (h: _)) -> return h
214
214
(CoreList [] ) -> throwEvalError $ EmptyList (CoreList [] )
215
215
e -> throwEvalError $ NotList e
216
- euHead _ args = throwEvalError $ Bug " __HEAD called with bad args " (CoreList args )
216
+ euHead _ as = throwEvalError $ Bug " __HEAD called with bad as " (CoreList as )
217
217
218
218
-- | __TAIL(l) - 'l' must be list. Arity 1. Strict in 'l'.
219
219
--
@@ -223,7 +223,7 @@ euTail whnfM [l] =
223
223
(CoreList (_: t)) -> return (CoreList t)
224
224
(CoreList [] ) -> throwEvalError $ EmptyList (CoreList [] )
225
225
e -> throwEvalError $ NotList e
226
- euTail _ args = throwEvalError $ Bug " __TAIL called with bad args " (CoreList args )
226
+ euTail _ as = throwEvalError $ Bug " __TAIL called with bad as " (CoreList as )
227
227
228
228
-- | __CONS(h, t) - 't' must be list. Arity 2.
229
229
--
@@ -235,7 +235,7 @@ euCons whnfM [h, t] =
235
235
whnfM t >>= \ case
236
236
(CoreList t') -> return (CoreList (h : t'))
237
237
e -> throwEvalError $ NotList e
238
- euCons _ args = throwEvalError $ Bug " __TAIL called with bad args " (CoreList args )
238
+ euCons _ as = throwEvalError $ Bug " __TAIL called with bad as " (CoreList as )
239
239
240
240
241
241
-- | Concatenate two lists or blocks into a list. The default action
@@ -262,14 +262,14 @@ euSym :: WhnfEvaluator -> [CoreExpr] -> Interpreter CoreExpr
262
262
euSym whnfM [s] = whnfM s >>= \ case
263
263
(CorePrim (CoreString v)) -> return (CorePrim (CoreSymbol v))
264
264
e -> throwEvalError $ SymbolNamesMustBeStrings e
265
- euSym _ args = throwEvalError $ Bug " __SYM called with bad args " (CoreList args )
265
+ euSym _ as = throwEvalError $ Bug " __SYM called with bad as " (CoreList as )
266
266
267
267
268
268
-- | __BLOCK(l) builtin. Arity 1. Non-strict. Wrap up a list of elements as a block.
269
269
--
270
270
euBlock :: WhnfEvaluator -> [CoreExpr ] -> Interpreter CoreExpr
271
271
euBlock _ [l] = return $ CoreBlock l
272
- euBlock _ args = throwEvalError $ Bug " __BLOCK called with bad args " (CoreList args )
272
+ euBlock _ as = throwEvalError $ Bug " __BLOCK called with bad as " (CoreList as )
273
273
274
274
275
275
@@ -280,7 +280,7 @@ euElements whnfM [e] =
280
280
whnfM e >>= \ case
281
281
CoreBlock l -> return l
282
282
_ -> throwEvalError $ ElementsArgumentNotBlock e
283
- euElements _ args = throwEvalError $ Bug " __ELEMENTS called with bad args " (CoreList args )
283
+ euElements _ as = throwEvalError $ Bug " __ELEMENTS called with bad as " (CoreList as )
284
284
285
285
286
286
@@ -315,7 +315,7 @@ euMerge whnfM [l, r] = do
315
315
(CoreList ll, CoreList rr) -> CoreBlock . CoreList <$> mergeElements whnfM ll rr
316
316
_ -> throwEvalError $ BadBlockMerge (CoreList [l, r])
317
317
_ -> throwEvalError $ BadBlockMerge (CoreList [l, r])
318
- euMerge _ args = throwEvalError $ BadBlockMerge (CoreList args )
318
+ euMerge _ as = throwEvalError $ BadBlockMerge (CoreList as )
319
319
320
320
321
321
@@ -383,7 +383,7 @@ euLookupOr whnfM [n, d, b] = do
383
383
(CorePrim (CoreSymbol s)) -> lookupOr whnfM (return d) b' s
384
384
(CorePrim (CoreString s)) -> lookupOr whnfM (return d) b' s
385
385
_ -> throwEvalError $ LookupKeyNotStringLike n'
386
- euLookupOr _ args = throwEvalError $ Bug " __LOOKUP called with bad arguments" (CoreList args )
386
+ euLookupOr _ as = throwEvalError $ Bug " __LOOKUP called with bad arguments" (CoreList as )
387
387
388
388
-- | __LOOKUP(n, d, b) - look up name `n` (string or symbol) in
389
389
-- block `b`, returning `d` if it isn't there. Strict in `b` and `r`.
@@ -397,7 +397,7 @@ euLookup whnfM [n, b] = do
397
397
(CorePrim (CoreSymbol s)) -> lookupName whnfM b' s
398
398
(CorePrim (CoreString s)) -> lookupName whnfM b' s
399
399
_ -> throwEvalError $ LookupKeyNotStringLike n'
400
- euLookup _ args = throwEvalError $ Bug " __LOOKUP called with bad arguments" (CoreList args )
400
+ euLookup _ as = throwEvalError $ Bug " __LOOKUP called with bad arguments" (CoreList as )
401
401
402
402
-- | Remove item from block with the specified key
403
403
removeItem :: WhnfEvaluator -> CoreExpr -> CoreRelativeName -> Interpreter CoreExpr
@@ -425,7 +425,7 @@ euRemove whnfM [n, b] = do
425
425
(CorePrim (CoreSymbol s)) -> removeItem whnfM b' s
426
426
(CorePrim (CoreString s)) -> removeItem whnfM b' s
427
427
_ -> throwEvalError $ LookupKeyNotStringLike n'
428
- euRemove _ args = throwEvalError $ Bug " __LOOKUP called with bad arguments" (CoreList args )
428
+ euRemove _ as = throwEvalError $ Bug " __LOOKUP called with bad arguments" (CoreList as )
429
429
430
430
-- | Lookup in a block, throwing if key absent.
431
431
--
@@ -453,7 +453,7 @@ euSplit whnfM [s, re] = do
453
453
(CorePrim (CoreString target), CorePrim (CoreString regex)) ->
454
454
return $ CoreList $ map (CorePrim . CoreString ) $ splitRegex target regex
455
455
_ -> throwEvalError $ BadSplitArgs s re
456
- euSplit _ args = throwEvalError $ Bug " __SPLIT called with bad arguments" (CoreList args )
456
+ euSplit _ as = throwEvalError $ Bug " __SPLIT called with bad arguments" (CoreList as )
457
457
458
458
-- | __JOIN(l, sep) - join (string) items of l with sep.
459
459
--
@@ -469,7 +469,7 @@ euJoin whnfM [l, sep] = do
469
469
stringItem x = whnfM x >>= extractString
470
470
extractString (CorePrim (CoreString x)) = return x
471
471
extractString x = throwEvalError $ NotString x
472
- euJoin _ args = throwEvalError $ Bug " __JOIN called with bad arguments" (CoreList args )
472
+ euJoin _ as = throwEvalError $ Bug " __JOIN called with bad arguments" (CoreList as )
473
473
474
474
-- | __MATCH(s, re) - match s with re, returning list of full match t
475
475
-- index 0 then groups.
@@ -483,7 +483,7 @@ euMatch whnfM [s, re] = do
483
483
return . CoreList . map (CorePrim . CoreString ) $
484
484
getAllTextSubmatches (target =~ regex :: AllTextSubmatches [] String )
485
485
_ -> throwEvalError $ BadMatchArgs s re
486
- euMatch _ args = throwEvalError $ Bug " __MATCH called with bad arguments" (CoreList args )
486
+ euMatch _ as = throwEvalError $ Bug " __MATCH called with bad arguments" (CoreList as )
487
487
488
488
-- | __MATCHES(s, re) - find all matches of @re@ in @s@, returning list of
489
489
-- string matches.
@@ -497,15 +497,15 @@ euMatches whnfM [s, re] = do
497
497
return . CoreList . map (CorePrim . CoreString ) $
498
498
getAllTextMatches (target =~ regex :: AllTextMatches [] String )
499
499
_ -> throwEvalError $ BadMatchArgs s re
500
- euMatches _ args = throwEvalError $ Bug " __MATCHES called with bad arguments" (CoreList args )
500
+ euMatches _ as = throwEvalError $ Bug " __MATCHES called with bad arguments" (CoreList as )
501
501
502
502
-- | __WITHMETA(m, e) - tag metadata `m` onto expression `e`.
503
- -- Lazy in both args .
503
+ -- Lazy in both as .
504
504
--
505
505
euWithMeta :: WhnfEvaluator -> [CoreExpr ] -> Interpreter CoreExpr
506
506
euWithMeta _ [m, e] = return $ CoreMeta m e
507
- euWithMeta _ args =
508
- throwEvalError $ Bug " __WITHMETA called with bad arguments" (CoreList args )
507
+ euWithMeta _ as =
508
+ throwEvalError $ Bug " __WITHMETA called with bad arguments" (CoreList as )
509
509
510
510
-- | __META(e) - retrieve metadata from value - which must be a
511
511
-- metadata annotated value (not the value contained
@@ -516,8 +516,8 @@ euMeta whnfM [e] = do
516
516
case e' of
517
517
(CoreMeta m _) -> return m
518
518
_ -> return $ block []
519
- euMeta _ args =
520
- throwEvalError $ Bug " __WITHMETA called with bad arguments" (CoreList args )
519
+ euMeta _ as =
520
+ throwEvalError $ Bug " __WITHMETA called with bad arguments" (CoreList as )
521
521
522
522
523
523
-- | __STR(e) - convert to string.
@@ -529,8 +529,8 @@ euStr whnfM [e] = whnfM e >>= skipMeta whnfM >>= \case
529
529
(CorePrim (CoreSymbol s)) -> (return . CorePrim . CoreString ) s
530
530
(CorePrim (CoreBoolean b)) -> (return . CorePrim . CoreString . show ) b
531
531
x -> (return . CorePrim . CoreString . show ) x
532
- euStr _ args =
533
- throwEvalError $ Bug " __STR called with bad arguments" (CoreList args )
532
+ euStr _ as =
533
+ throwEvalError $ Bug " __STR called with bad arguments" (CoreList as )
534
534
535
535
536
536
-- | The builtins exposed to the language.
0 commit comments