I have realised that whilst working on https://deavmi.assigned.network/git/tlang/tlang/issues/113#issuecomment-1342 that universal cerocion should be something I implement first. I have an algo for it - it isn't really that big, it just provides a new function that calls already-existing functions to coerce into a certain type provided. So it shouldn't be too hard.

I will keep you all posted.

I have started work on documenting a function that will do this, I'm calling it `typeEnforce` and its signature is `bool typeEnforce(Value v1, Value v2, bool attemptCoercion = false)`, what it WILL do (when I implement it) is the following:

```

/**

* For: 🧠️ Feature: Universal coercion

*

* Given two `Value`-based instructions this method will extract

* the types of both and return true if their types are the same,

* however in the case their types are not the same then if coercion

* is allowed then an attempt at coercion will take place - if it

* succeeds then the type of `v2` is updated (it is coerced to the

* type of `v1`) and true is returned, else false is returned.

*

* In the case that coercion is disabled then mismatched types results

* in false being returned.

*

* Params:

* v1 = Value-instruction 1 (will coerce towards if requested)

* v2 = Value-instruction 2

* attemptCoercion = whether or not at attempt coercion on initial type mismatch (default: `false`)

*

* Returns: true if the types match (or were coerced successfully if requested), false otherwise

*/

```

Reply to this note

Please Login to reply.

Discussion

I have started work on this now and have a skeleton going of what I want to do, I think the best thing I can do is:

1. Finish implementing `typeEnforce(Value, Value, bool)`

2. Write unit tests which setup scenarios where it should pass, pass with coercion and fail so that I can be insured it works

3. Start moving code over to using it