oozby icon indicating copy to clipboard operation
oozby copied to clipboard

'>' before calling a def only applies to last part of the def content ?

Open DeuxVis opened this issue 12 years ago • 2 comments

Or maybe I should always use an union as the root in my def ?

Sample code :

def sumfin 
  cube( [10, 10, 10] )
  cube( [10, 10, 10], center: true )
end


rotate( z: -45 ) > sumfin

#doesn't rotate the 1st cube while


translate( z: 20 ) do 
  rotate( z: -45 ) do
    sumfin 
  end
end

#does

DeuxVis avatar Oct 03 '13 22:10 DeuxVis

Yeah I think always using a union is a good idiom for oozby, for now at least. I've been thinking about hooking the environment so when you call a def method which you defined in that 'global' scope (actually oozby files are instance-exec'd on the Oozby::Environment) any methods you define could automatically be patched to include an implied union operation, by overloading Oozby::Environment#send, or Oozby::Environment.method_added to do it at runtime or compile time.

I'm not sure if it's a great idea because of the ruby principal of least surprise. What happens when the method is being used for some calculation, and you don't want the return value to be a union Oozby::Element? Do methods only return a Union Element if there were oozby calls inside the method? do they only return them if the return value of the method is an oozby element?

Maybe a better solution is to have the oozby command line app warn users that it's detected they emitted multiple things from their method, and let them know that it isn't automatically unioning them, with a link to a webpage explaining that in detail, but having a bunch of warnings shoot out every time you compile a legit app seems kinda crummy.

Bluebie avatar Oct 03 '13 22:10 Bluebie

Go for the simple, not magically doing anything in the background solution IMO.

Just add a line mentioning that in the documentation near the definition of that '>' operator should be enough.

DeuxVis avatar Oct 10 '13 20:10 DeuxVis