Coder Social home page Coder Social logo

Comments (5)

zaskar9 avatar zaskar9 commented on July 24, 2024

Line 38: "2" is treated a STRING literal in this case. Line 39: casting CHAR to ARRAY OF CHAR cannot happen implicitly. Everything is as it should be.

Edit: If you wrote "2" as 32X, it will not work either. A CHAR is not an ARRAY OF CHAR, but "2" can be both a CHAR and a STRING, due to the ambiguity introduced by using " to enclose both CHAR and STRING literals.

from oberon-lang.

tenko avatar tenko commented on July 24, 2024

Very good.
I see XDS has this implicit cast from CHAR to ARRAY OF CHAR.

from oberon-lang.

zaskar9 avatar zaskar9 commented on July 24, 2024

I thought about implementing such an implicit cast. However, if we started going down that road and tried to be general, every value could stand for the value itself and a one-element array containing that value. To me, that would be at odds with having a strongly typed language.

The fact that "2" can be both a CHAR and a STRING (which is assignable to ARRAY OF CHAR) is a weakness, not a feature. Ambiguity and implicit conversions are rarely a good thing. Therefore, I decided to limit that flexibility to the plane of literals (using the internal type STRING that is not even available to the programmer).

from oberon-lang.

tenko avatar tenko commented on July 24, 2024

Yes. There are corner cases as any language report is not 100% water tight.

I tested with oberonjs which returns:

line 38: type mismatch for argument 2: 'CHAR' cannot be converted to 'ARRAY OF CHAR'

The literal is OK, so this is most likely in line with other implementations.

OBNC returned error:

test.obn:39: error: array incompatible types in substitution of parameter 2 in Append: CHAR -> open array type

Otherwise it compiles.
It also failed at runtime due to array out of bounds. I believe it is expecting ARRAY OF CHAR to always be
NULL terminated and therefore fails when assigning a CHAR to a array with length 1.

Edit : OBNC tested. Turns out it can be downloaded for Windows.

from oberon-lang.

zaskar9 avatar zaskar9 commented on July 24, 2024

Otherwise it compiles. It also failed at runtime due to array out of bounds. I believe it is expecting ARRAY OF CHAR to always be NULL terminated and therefore fails when assigning a CHAR to an array with length 1.

That's precisely why I do not think that having this implicit conversion is a good idea and why the type system of oberon-lang distinguishes between STRING and ARRAY OF CHAR.

from oberon-lang.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.