XojoScript Compilation Error

I’m sure I’m missing something obvious here but why won’t this XojoScript compile?

Class Fib
	Public Shared Function Compute(n As Integer) As integer
		If (n < 2) Then Return n
		Return Compute(n - 1) + Compute(n - 2)
	End Function
End Class

Var Start As Double = System.Microseconds
For i As Integer = 1 To 5
	Print(Fib.Compute(28))
Next i

Var elapsed As Integer = (System.Microseconds - start) / 1000
Print("elapsed: " + elapsed.ToString)

Using @Kem_Tekinay XsEdit to try to help me debug puts the error here:

Print(Fib.Compute(28))

Saying:

Parameter “Parameter2” expects type String but this is type Integer

As far as I can tell, there is no Parameter2 for the Compute function.

What gives?

Maybe this is what you need?

1 Like

Yes, why not return a string from Compute() ?

I’m testing Xojoscript’s performance. If you look at the body of Compute() you’ll see it’s recursive hence why it’s returning an integer.

@Donald_Lunder Doh! Yes you’re right. Thanks.

This works for me in Xojo (not in XsEdit, unfortunately).

Class Fib
  Public Shared Function Compute(n As Integer) As integer
  If (n < 2) Then Return n
  Return Compute(n - 1) + Compute(n - 2)
  End Function
End Class

Var Start As Double = System.Microseconds
For i As Integer = 1 To 5
  Print(Fib.Compute(28).ToString)
Next i

Var elapsed As Integer = (System.Microseconds - start) / 1000
Print("elapsed: " + elapsed.ToString)
1 Like

Thanks Kem. Looks like Donald beat you to it with Str (I edited my reply a few moments ago).

XsEdit is really helpful for debugging XojoScript btw.

Your code (with ToString()) is working for me in XsEdit. FYI, there are several compilation errors with XsEdit in Xojo 2021r3.1 (mostly to do with deprecated macOS file handles and the use of var as a variable name.