Comments (2)
See, this is a tricky one. While I get why I wanted this, I either need to make Variables
smarter (i.e. make them try to evaluate themselves) or I have to make Operations
smarter, and try to evaluate Variables
.
I think I like the first one better; part of being a 'variable' could simply be, "we must resolve ourself to the correct basic type on evaluation'.
from rpgdice.
Second tricky part: How to prevent recursion? Do we not pass in the scope, do we unset our key from the scope, or do we attempt to detect recursion, and throw an error?
Here's how I break those down:
- Don't pass in outer
scope
- Pro: Simplest option; we only ever evaluate one level of nesting.
- Con: Doesn't allow for
Weapon.Damage
to equal1d6 + 'Abilities.StrMod'
, an easy to imagine use case.
- Unset our key from the scope
- Pro: It immediately breaks any recursion, while still allowing for nesting.
- Pro: Covers all reasonable use cases, while disallowing clearly abusive ones.
- Con: It is both difficult and slow to emulate
_.unset
. - Con: Requires cloning the scope; the deeper nested, the more clones of the scope are made. (If scope is a large object, this could run us out of memory.)
- Detect recursion, and throw an error
- Detect by name reference
- Pro: Detects blatantly abusive case, without modifying anything
- Con: Easily defeated, since it doesn't detect cycles.
- Con: Difficult to implement.
- Store current depth in scope, limit to a maximum value
- Pro: Usage agnostic, simply limits maximum parsing depth.
- Pro: Trivial Implementation.
- Con: Modifies scope; we shouldn't touch a user's object.
- Con: 'leaks' maximum depth.
- Con: Does not directly address recursion, so it might not be obvious what's wrong.
- Store current depth in
Expression
, limit to a maximum value- Pro: Usage agnostic, simply limits maximum parsing depth.
- Pro: Trivial Implementation.
- Con: Does not directly address recursion, so it might not be obvious what's wrong.
- Detect by name reference
At this point, after working all of that out, I'm opting for 3.3
, since it seems the easiest to implement, and seems a reasonable guard.
from rpgdice.
Related Issues (6)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rpgdice.