Skip to content

Commit

Permalink
add badilisha built in function
Browse files Browse the repository at this point in the history
  • Loading branch information
AvicennaJr committed Oct 29, 2024
1 parent 9abd50f commit 480eb06
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions evaluator/builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,36 @@ var builtins = map[string]*object.Builtin{
},
},

"badilisha": {
Fn: func(args ...object.Object) object.Object {
if len(args) != 2 {
return newError("Samahani, badili inahitaji hoja 2, wewe umeweka %d", len(args))
}

value := args[0]
targetType := args[1]

if targetType.Type() != object.STRING_OBJ {
return newError("Aina ya lengo lazima iwe neno")
}

targetTypeStr := targetType.(*object.String).Value

switch targetTypeStr {
case "NAMBA":
return convertToInteger(value)
case "DESIMALI":
return convertToFloat(value)
case "NENO":
return convertToString(value)
case "BOOLEAN":
return convertToBoolean(value)
default:
return newError("Aina isiyojulikana: %s", targetTypeStr)
}
},
},

// "jumla": {
// Fn: func(args ...object.Object) object.Object {
// if len(args) != 1 {
Expand Down

0 comments on commit 480eb06

Please sign in to comment.