#898 closed doubt (fixed)
Can I define a function whose existence is unkown to me
Reported by: | imendez | Owned by: | Víctor de Buen Remiro |
---|---|---|---|
Priority: | low | Milestone: | |
Component: | Kernel | Version: | 1.1.7 |
Severity: | minor | Keywords: | |
Cc: |
Description
Hi, I have a doubt about the functions definition.
When I can't know if a certain global variable (A) exists, I can define it using ObjectExist code:
Real If(ObjectExist("Real", "A"), ?, Real A = 4);
This works right.
However, in the case of a function, I'm not sure about how must I define it:
Real If(ObjectExist("Code", "MultiplicaPorDos"), ?, Real MultiplicaPorDos(Real n) { 2*n }); Real m = MultiplicaPorDos(3);
The code above seems to work right, because variable "m" is created, but an error message is shown:
ERROR: [1] No ha sido posible convertir de Code hacia Real para el objeto 'MultiplicaPorDos'
Is this an error of mine in programming or is it an error of TOL?
Change History (2)
comment:1 Changed 15 years ago by
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:2 Changed 15 years ago by
Note that if you want to know if there is a function returning just a given type as Real
or a grammar inside a set of options you also can use
Real FunctionExist({Text|Set} gramatica, Text reference)
The evaluator is complaining about the object returned by the If expression because it is evaluated in the context of the Real grammar. If you rewrite the code as follow you will not get any error message.
of course you can keep the Real in front of the If expression but in that case you should ensure that every branch of the If return a Real object.