Giter Site home page Giter Site logo

Comments (8)

stevedekorte avatar stevedekorte commented on June 14, 2024

This is because the script is parsed before it is executed (so it doesn't see the new operator entry while parsing).

from io.

coiscir avatar coiscir commented on June 14, 2024

So, this is by design and I'm SOL?

from io.

stevedekorte avatar stevedekorte commented on June 14, 2024

How could it be designed any differently? Would you parse and eval each line separately? What if an line eval attempted to look at the message tree - it would not be able to see the rest of it and this would also lead to a SOL situation.

from io.

stevedekorte avatar stevedekorte commented on June 14, 2024

You can avoid the problem by simply putting the:

OperatorTable addAssignOperator("=>", "setKey")

bit in a separate script file.

from io.

coiscir avatar coiscir commented on June 14, 2024

To clarify, my comment of "by design" was in regard to IO having inconsistent behavior depending on the environment and/or mode of execution.

I didn't actually intend on questioning "parse before execute" -- language design and implementation isn't my realm to question. But, outside this realm, your original response was rather useless. It gave me some additional understanding of the VM, that I appreciate, but it didn't resolve the issue.

From an admittedly naive understanding, it is at least odd that a new assignment operator isn't actually known until execution when the parser is what seems to need it. So, perhaps addAssignOperator could be rethought to be a parsable message rather than an executable message? I don't know...

Nevertheless, thank you for the suggestion. However, placing it in a separate file doesn't seem to make any difference. I've tried placing it in an addon script and importing, as well as just trying to execute it with doFile. Am I missing a 3rd option?

from io.

stevedekorte avatar stevedekorte commented on June 14, 2024

If you send me your email address, I can send you a zip that shows it working.

from io.

stevedekorte avatar stevedekorte commented on June 14, 2024

Also, here's the code if you don't mind creating the files yourself:

FILE: map.io
map(foo => 2, bar => 3)

FILE: op.io
OperatorTable addAssignOperator("=>", "setKey")

map := method(
call message arguments foreach(arg, writeln(arg))
)

FILE: runme.io
doFile("op.io")
doFile("map.io")

from io.

coiscir avatar coiscir commented on June 14, 2024

Ah. Didn't think to run everything through doFile.

Though, that did lead me to find Message fromString, which works just as well with a little less overhead in the setup: ;)

OperatorTable addAssignOperator("=>", "setKey")

map := method(
  call message arguments foreach(arg,
    writeln(Message fromString(arg asString))
  )
)

map(foo => 2, bar => 3)

from io.

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.