Note that there are some explanatory texts on larger screens.

plurals
  1. PODoes this language feature already exist?
    primarykey
    data
    text
    <p>I'm currently developing a new language for programming in a continuous environment (compare it to electrical engineering), and I've got some ideas on a certain language construction.</p> <p>Let me explain the feature by explanation and then by definition:</p> <pre><code>x = a U b; </code></pre> <p>Where <code>x</code> is a variable and <code>a</code> and <code>b</code> are other variables (or static values). This works like a union between <code>a</code> and <code>b</code>; no duplicates and no specific order.</p> <pre><code>with(x) { // regular 'with' usage; using the global interpretation of "x" x = 5; // effectively will do: // x = a U b U 5; // a = 5; // b = 5; // Thus, when "a" or "b" changes, "x" is still equal to "5". } with(x = a) { // this code block is executed when the "x" variable // has the "a" variable assigned. All references in // this code-block to "x" are references to "a". So saying: x = 5; // would only change the variable "a". If the variable "a" // later on changes, x still equals to 5, in this fashion: // 'x = a U b U 5;' // '[currentscope] = 5;' // thus, 'a = 5;' } with(x = b) { // same but with "b" } with(x != a) { // here the "x" variable refers to any variable // but "a"; thus saying x = 5; // is equal to the rewriting of // 'x = a U b U 5;' // 'b = 5;' (since it was the scope of this block) } with(x = (a U b)) { // guaranteed that "x" is 'a U b'; interacting with "x" // will interact with both "a" and "b". x = 5; // makes both "a" and "b" equal to 5; also the "x" variable // is updated to contain: // 'x = a U b U 5;' // '[currentscope] = 5;' // 'a U b = 5;' // and thus: 'a = 5; b = 5;'. } // etc. </code></pre> <p>In the above, all code-blocks are executed, but the "scope" changes in each block how <code>x</code> is interpreted. In the first block, <code>x</code> is guaranteed to be <code>a</code>: thus interacting with <code>x</code> inside that block will interact on <code>a</code>. The second and the third code-block are only equal in this situation (because <code>not a</code>: then there only remains <code>b</code>). The last block guarantees that <code>x</code> is at least <code>a</code> or <code>b</code>.</p> <p>Further more; <code>U</code> is not the "bitwise or operator", but I've called it the "and/or"-operator. Its definition is:</p> <pre><code>"U" = "and" U "or" </code></pre> <p>(On my blog, <a href="http://cplang.wordpress.com/2009/12/19/binop-and-or/" rel="noreferrer">http://cplang.wordpress.com/2009/12/19/binop-and-or/</a>, there is more (mathematical) background information on this operator. It's loosely based on sets. Using different syntax, changed it in this question.)</p> <p><strong>Update: more examples.</strong></p> <pre><code>print = "Hello world!" U "How are you?"; // this will print // both values, but the // order doesn't matter. // 'userkey' is a variable containing a key. with(userkey = "a") { print = userkey; // will only print "a". } with(userkey = ("shift" U "a")) { // pressed both "shift" and the "a" key. print = userkey; // will "print" shift and "a", even // if the user also pressed "ctrl": // the interpretation of "userkey" is changed, // such that it only contains the matched cases. } with((userkey = "shift") U (userkey = "a")) { // same as if-statement above this one, showing the distributivity. } x = 5 U 6 U 7; y = x + x; // will be: // y = (5 U 6 U 7) + (5 U 6 U 7) // = 10 U 11 U 12 U 13 U 14 somewantedkey = "ctrl" U "alt" U "space" with(userkey = somewantedkey) { // must match all elements of "somewantedkey" // (distributed the Boolean equals operated) // thus only executed when all the defined keys are pressed } with(somewantedkey = userkey) { // matches only one of the provided "somewantedkey" // thus when only "space" is pressed, this block is executed. } </code></pre> <p><strong>Update2: more examples and some more context.</strong></p> <pre><code>with(x = (a U b)) { // this } // can be written as with((x = a) U (x = b)) { // this: changing the variable like x = 5; // will be rewritten as: // a = 5 and b = 5 } </code></pre> <p><strong>Some background information:</strong> I'm building a language which is "time-independent", like Java is "platform-independant". Everything stated in the language is "as is", and is continuously actively executed. This means; the programmer does not know in which order (unless explicitly stated using constructions) elements are, nor when statements are executed. The language is completely separated from the "time"-concept, i.e. it's continuously executed:</p> <pre><code>with(true) { a = 0; // only runs once (lazy execution) } with(a &lt; 5) { a++; } // this is a loop-structure; // how and when it's executed isn't known however. with(a) { // everytime the "a" variable changes, this code-block is executed. with(true) { b = 3; // only 5 times (again lazy execution, but it's a sub-with) } with(b &lt; 2) { // dependent on "b" // runs only 3 times * 5 times = 15 times. } with(b &gt; 1) { // dependent on "b" b = b - 1; // runs 4 times * 5 times = 20 times. } } </code></pre> <p><strong>Update 3:</strong></p> <p>After pondering on the type of this language feature; it closely resemblances Netbeans Platform's Lookup, where each "with"-statement a synchronized agent is, working on it's specific "filter" of objects. Instead of type-based, this is variable-based (fundamentally quite the same; just a different way of identifiying objects).</p> <p>I greatly thank all of you for providing me with very insightful information and links/hints to great topics I can research. Thanks.</p> <p>I do not know if this construction already exists, so that's my question: <strong>does this language feature already exist?</strong></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload