Skip to content

Commit f1d4830

Browse files
committed
improve type casting builting
use namba() to convert to integer and tungo() to convert to string
1 parent f520183 commit f1d4830

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

evaluator/builtins.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,24 @@ var builtins = map[string]*object.Builtin{
177177
}
178178
},
179179
},
180+
"namba": {
181+
Fn: func(args ...object.Object) object.Object {
182+
if len(args) != 1 {
183+
return newError("Samahani, namba inahitaji hoja 1, wewe umeweka %d", len(args))
184+
}
185+
value := args[0]
186+
return convertToInteger(value)
187+
},
188+
},
189+
"tungo": {
190+
Fn: func(args ...object.Object) object.Object {
191+
if len(args) != 1 {
192+
return newError("Samahani, tungo inahitaji hoja 1, wewe umeweka %d", len(args))
193+
}
194+
value := args[0]
195+
return convertToString(value)
196+
},
197+
},
180198

181199
// "jumla": {
182200
// Fn: func(args ...object.Object) object.Object {

0 commit comments

Comments
 (0)