feat: add string? and number? (#1130)

This commit is contained in:
Veit Heller 2021-01-17 14:39:11 +01:00 committed by GitHub
parent 5d225905ea
commit dd81164f93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 0 deletions

View File

@ -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))

View File

@ -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)",