Trancor Posted April 23, 2015 Share Posted April 23, 2015 (edited) Hey guys, I've been trying to find a way of making a recursive function in VEX.I'm trying to aggregate infromation from points and build an return array, but can't get any recursive funtions to work.For example, when ever I try running something like- void printer(int count){ count+=1; printf("\n %c", count); if(count < 10){ printer(count); } } printer(1); It throws the error-"Call to undifiend function 'printer'"I know I can go the messy route with while loops and maintaining variables by adding and subtracting elements and having a result variable... but this is needlessly insane to try to do a basic recursive function.I've tried giving pointer variables, and it seems like vex doesn't want to accept standard C pointer code. Or at least doesn't like * in the input variables of a void definition.Has anyone had success with this and might be able to point me in a useful direction for vex code?(No, this can't be done with nodes or a python node for the real node I'm working on)Thanks in advance!-Kevin Edited April 23, 2015 by Trancor Quote Link to comment Share on other sites More sharing options...
Guest mantragora Posted April 23, 2015 Share Posted April 23, 2015 You wound need to define it in Outer code to make it work. Don't ask me how to do it in any inline/snippet/etc. node, I failed to make it work, some syntax problems. But if you create new node definition, you have Inner and Outer tabs and Inner is where you execute code, Outher is where you define helper functions before the main body of the VEX code. Quote Link to comment Share on other sites More sharing options...
Guest mantragora Posted April 23, 2015 Share Posted April 23, 2015 ... But if you create new node definition... VOP node definition The Outer is also place where you Include files. You cannot do this in Inner part. Quote Link to comment Share on other sites More sharing options...
Trancor Posted April 23, 2015 Author Share Posted April 23, 2015 Interesting, I never knew what this Outer Code option was meant for. But I'm unsure how to use this vex code without it being on snippet. Which its throwing an error, probably the same one you are talking about.Unexpected "[" on line 22.Course, I'm just putting "printer" into the Outer Code parm.I tried putting it into a header file and loading the header file from the file, but it also throws that same error.So I'm probably trying to use this Outer Code option wrong.Can you help any further?Are you using this Outer Code method on a VEX node itself? Writing out a VCC compiler command?Because when ever I try to load up VEX that have nested headers, it can't find the header. Which is also what was happening when I tried using the Outer Code option on the snippet with any additional headers I'm trying to include.Sorry for my ignorance on this topic. Quote Link to comment Share on other sites More sharing options...
Guest mantragora Posted April 23, 2015 Share Posted April 23, 2015 (edited) You won't like it, but actually recursion is not possible in VEX, sorry. I write to much HDK You would need to put it in something like SolverSOP to make it work. Otherwise you can't accumulate it.But you can go Python way and use InlineCPP if you need more speed. In Python you can do recursion. Edited April 23, 2015 by mantragora 1 Quote Link to comment Share on other sites More sharing options...
Guest mantragora Posted April 23, 2015 Share Posted April 23, 2015 Well, we got shader calls in VEX which allows to do recursion => http://www.sidefx.com/docs/houdini14.0/vex/shadercalls, but I'm not sure will it help you. Quote Link to comment Share on other sites More sharing options...
kleer001 Posted April 23, 2015 Share Posted April 23, 2015 CS tangent... Does that mean that VEX is not Turing Complete? I think that's what it means. Quote Link to comment Share on other sites More sharing options...
Guest mantragora Posted April 23, 2015 Share Posted April 23, 2015 (No, this can't be done with nodes or a python node for the real node I'm working on) Why? Quote Link to comment Share on other sites More sharing options...
Trancor Posted April 23, 2015 Author Share Posted April 23, 2015 I'll look into shader calls some, but yeah, dunno if this will help much.VEX might or might not be Turing Complete, but who knows, might need some special syntax, ha.I've written up my script through VEX since it runs VEX commands native to houdini. To jump between python nodes and back would be cumber some and slow things down. I'd need a ton more nodes to pass the data around or use python nodes just to generate attributes and process data to pass back to vex. Not exactly what I'm looking for when it would take a simple 5-6 line void to do the process.I've gone a different route now anyway, whiles loops and maintaining variables. I'm not a fan, but it works.Thanks for the info Mantragora, I'll have to look into Outer Code more in the future. Quote Link to comment Share on other sites More sharing options...
edward Posted May 8, 2015 Share Posted May 8, 2015 One can always simulate function recursion using an array-based stack 1 Quote Link to comment Share on other sites More sharing options...
magneto Posted August 24, 2015 Share Posted August 24, 2015 One can always simulate function recursion using an array-based stack Can you please show a simple example on how to do this Edward? Is it gonna involve a for loop where you are iterating through the stack and accumulate the result in a variable stored outside? Quote Link to comment Share on other sites More sharing options...
edward Posted September 4, 2015 Share Posted September 4, 2015 http://stackoverflow.com/questions/159590/way-to-go-from-recursion-to-iteration 2 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.