Git Product home page Git Product logo

Comments (2)

leyarotheconquerer avatar leyarotheconquerer commented on July 20, 2024 1

TLDR: lci doesn't seem to handle Bukkit inheritance quite right. There's a possible workaround (see below).

Explanation

Interesting behavior indeed. I've dug into this a bit and here's what I've found.

I believe lci was patterned after the Lolcode 1.3 proposal for Bukkits, so a rough explanation for how this should work can be found in the archived proposal.

Inheritance / Prototyping

To create an object based upon an existing object:

I HAS A <object> ITZ LIEK A <parent>

Behavior of this sort of inheritance is described further below.

To define inheritance using alternate syntax, do the following.

O HAI IM <object> [IM LIEK <parent>]
  <code block>
KTHX

Inheritance implies a few things, one of which is inheritance of slots (described below). Another thing inheritance does is automatically > create a “parent” slot on the new object. The “parent” slot refers to the object that this object was inherited from, or its prototype. > The parent slot is treated specially by the Bukkit.

...

Assigning a variable within the object first searches for it within the current object. If it has been declared within the current object, then it is set. If that fails, it attempts to access it within the parent object. Search continues in up the chain of parents. If the variable name is found up the inheritance chain, then that variable is declared and created within the current object (where the search started), and the value is set. If the variable search fails and the variable was never previously assigned, then it's a declaration error.

Looking at your example program, it seems that lci is not completely following that last paragraph. It says that "If the variable name is found up the inheritance chain, then that variable is declared and created within the current object". Currently, if the variable name is found up the inheritance chain, then the variable is changed within the parent object.

The code responsible for the assignment is in the updateScopeValue() function. The interpreter shares the same logic for updating nested scopes and Bukkits. Currently, the logic is correctly written for scopes but not for Bukkits. We may need to add Bukkit-specific logic to the function to handle updating inherited fields.

Workaround

In the meantime, the tests in 1.3-Tests/12-Arrays/13-Inheritance/2-Assignment demonstrate a method that might be able to help with your use case. If you want to override the value of a parent's field, you can use the following syntax to set it on the child:

I HAS A parent ITZ A BUKKIT
parent HAS A foo ITZ "bar"

I HAS A child ITZ LIEK A parent
child HAS A foo ITZ "baz"

I HAS A otherChild ITZ LIEK A parent

VISIBLE SMOOSH "Parent:: " AN parent'Z foo MKAY
VISIBLE SMOOSH "Child:: " AN child'Z foo MKAY
VISIBLE SMOOSH "Other child:: " AN otherChild'Z foo MKAY

from lci.

lucidBrot avatar lucidBrot commented on July 20, 2024

Thank you for the explanation! That makes sense to me :)

My usecase was to read input into an object with different fields, and then making a copy of that object so that I could have an unmodified copy and a working copy.

Anyway, I have managed to copy without LIEK and finished the adventofcode task I was working on, so I don't need further assistance.

Enjoy the rest of your weekend!

from lci.

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.