Git Product home page Git Product logo

Comments (1)

jhoehle avatar jhoehle commented on September 1, 2024

The compiler already refuses to initialize or assign variables later used in loop, reporting that they are read-only. So I was wrong when I said "x is mine".

var int x = 7; // invalid assignment : read-only variable "x"
loop x in [2->8] do ... end

Hence what's left of this issue is:

  1. Bug: The compiler should detect and prevent the nested loop example.
  2. Enhancement: Make the loop variable unreadable after loop exit, to avoid undefined behaviour and thus non-determinism. (Alternatively try really hard to precisely define the value. Not trivial with C as a backend, where lots of simple operations cause undefined behaviour, e.g. signed addition overflow.)
  3. Enhancement: Syntax loop var int x in ... which would avoid all these pitfalls.

Meanwhile, one can take advantage of the current behaviour to provide immutable variables to Céu:

#define constvar(typ,name,value) \
  var typ name; \
  loop/1 name in [ (value) -> _] do break; end
constvar(uint, x, 1+2*3);
_printf("%u\n",x);
//x = 7; // invalid assignment : read-only variable "x"

Alas, vec[x] is still not the same as vec[7] (dynamic vs. static allocation). That would require real support for constants in Céu.

from ceu.

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.