mirror of
https://github.com/carp-lang/Carp.git
synced 2024-09-17 16:38:14 +03:00
feat: add string? and number? (#1130)
This commit is contained in:
parent
5d225905ea
commit
dd81164f93
@ -432,6 +432,18 @@ commandIsSymbol ctx x =
|
||||
XObj (Sym _ _) _ _ -> (ctx, Right trueXObj)
|
||||
_ -> (ctx, Right falseXObj)
|
||||
|
||||
commandIsNumber :: UnaryCommandCallback
|
||||
commandIsNumber ctx x =
|
||||
pure $ case x of
|
||||
XObj (Num _ _) _ _ -> (ctx, Right trueXObj)
|
||||
_ -> (ctx, Right falseXObj)
|
||||
|
||||
commandIsString :: UnaryCommandCallback
|
||||
commandIsString ctx x =
|
||||
pure $ case x of
|
||||
XObj (Str _) _ _ -> (ctx, Right trueXObj)
|
||||
_ -> (ctx, Right falseXObj)
|
||||
|
||||
commandArray :: VariadicCommandCallback
|
||||
commandArray ctx args =
|
||||
pure (ctx, Right (XObj (Arr args) (Just dummyInfo) Nothing))
|
||||
|
@ -247,6 +247,8 @@ dynamicModule =
|
||||
f "list?" commandIsList "checks whether the argument is a list." "(list? '()) ; => true",
|
||||
f "array?" commandIsArray "checks whether the arguments is an array." "(array? []) ; => true",
|
||||
f "symbol?" commandIsSymbol "checks whether the argument is a symbol." "(symbol? 'x) ; => true",
|
||||
f "number?" commandIsNumber "checks whether the argument is a number." "(number? 1) ; => true",
|
||||
f "string?" commandIsString "checks whether the argument is a string." "(string? \"hi\") ; => true",
|
||||
f "length" commandLength "returns the length of the argument (must be an array, string or list)." "(length '(1 2 3)) ; => 3",
|
||||
f "car" commandCar "gets the head of a list or array." "(car '(1 2 3)) ; => 1",
|
||||
f "cdr" commandCdr "gets the tail of a list or array." "(cdr '(1 2 3)) ; => '(2 3)",
|
||||
|
Loading…
Reference in New Issue
Block a user