Giter Club home page Giter Club logo

Comments (7)

electronicwhisper avatar electronicwhisper commented on May 29, 2024

Yeah, it crashes when you drag a function in to itself (or create any kind of circular dependency).

For my own reference, or if anyone wants to tackle it, here is a sketch for a fix:

Write a test that checks when you drag function A into function B that A does not contain B anywhere down the tree and B does not contain A anywhere down the tree.

Patch Actions.addChildFn to make sure that the above is not the case. If it is, don't add the function (and maybe display some sort of warning?).

from shadershop.

mgold avatar mgold commented on May 29, 2024

Thanks for the sketch. This seems to work doesn't account for the case of the added tree containing a compound function, I guess I'll get to that tomorrow:

containsCircularDep = (fn_to_add, existing) ->                                      
  if fn_to_add instanceof C.BuiltInFn                                               
      return false                                                                  
  fn_to_add = fn_to_add.childFns[0].fn                                              
  recurse = (fn) ->                                                                 
    if fn.__id == fn_to_add.__id                                                    
        return true                                                                 
    if fn instanceof C.CompoundFn                                                   
        fn.childFns.some recurse                                                    
    else                                                                            
        false                                                                       
  recurse(existing) 

Then in Actions.addChildFn, right before creating the new childFn,

  if containsCircularDep fn, parent                                              
      console.log "CIRCULAR DEP"                                                 
      return 

What to do once the circular dependency is detected is up to you.

from shadershop.

mgold avatar mgold commented on May 29, 2024

Okay, I've got this version. Let me know if you can break it.

containsCircularDep = (fn_to_add, existing) ->                                      
  if fn_to_add instanceof C.BuiltInFn                                               
      return false                                                                  
  recurse = (fn) ->                                                                 
    if fn instanceof C.DefinedFn or fn instanceof C.CompoundFn                      
        fn == existing or fn.childFns.some recurse                                  
    else if fn instanceof C.ChildFn                                                 
        recurse fn.fn                                                               
    else # C.BuiltInFn                                                              
        false                                                                       
  recurse(fn_to_add) 

The exact semantics are simple once stated: the function being add must not contain its soon-to-be parent anywhere in its tree.

from shadershop.

electronicwhisper avatar electronicwhisper commented on May 29, 2024

I like your wording. I pushed some code based on your snippet.

from shadershop.

mgold avatar mgold commented on May 29, 2024

I could have sworn there was a case that required handling C.DefinedFn but I can't break your version. Thanks for merging.

from shadershop.

electronicwhisper avatar electronicwhisper commented on May 29, 2024

DefinedFn extends CompoundFn so that case handles it.

from shadershop.

mgold avatar mgold commented on May 29, 2024

Nice!

from shadershop.

Related Issues (14)

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.