recursion

execute promises recursively nodejs

Deadly 提交于 2020-01-03 21:10:45
问题 the following function creates new folder on my server via xmlrpc var createFolder = function(folder_name) { var defer = Q.defer(); client.methodCall('create_folder', [sessionID, folder_name], function(err, resp) { if (err) { if (err.responseString && err.responseString.match('already exist')) { //call the same function recursively with folder_name+Math.round(Math.random()*100) } else { defer.reject(err); } } else { defer.resolve(folder_name); } }); return defer.promise; } The functions

execute promises recursively nodejs

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-03 21:09:33
问题 the following function creates new folder on my server via xmlrpc var createFolder = function(folder_name) { var defer = Q.defer(); client.methodCall('create_folder', [sessionID, folder_name], function(err, resp) { if (err) { if (err.responseString && err.responseString.match('already exist')) { //call the same function recursively with folder_name+Math.round(Math.random()*100) } else { defer.reject(err); } } else { defer.resolve(folder_name); } }); return defer.promise; } The functions

make a variable last for a call stack

筅森魡賤 提交于 2020-01-03 20:02:04
问题 I have a class that contains some fields. I need to compare instances of this class by value, so I defined GetHashCode and Equals accordingly. Because the class allows circular references, I need a mechanism to avoid infinite recursion (for a more detailed explanation see Value-equals and circular references: how to resolve infinite recursion?). I solved this problem by modifying my Equals method so that it keeps track of the comparisons done before: class Foo { public string Name { get; set;

make a variable last for a call stack

霸气de小男生 提交于 2020-01-03 20:01:03
问题 I have a class that contains some fields. I need to compare instances of this class by value, so I defined GetHashCode and Equals accordingly. Because the class allows circular references, I need a mechanism to avoid infinite recursion (for a more detailed explanation see Value-equals and circular references: how to resolve infinite recursion?). I solved this problem by modifying my Equals method so that it keeps track of the comparisons done before: class Foo { public string Name { get; set;

xslt recursive template on parent-child data

倾然丶 夕夏残阳落幕 提交于 2020-01-03 17:44:28
问题 I'm trying to wrap my mind around xslt. A number of questions here on stackoverflow help ( XSLT templates and recursion and XSLT for-each loop, filter based on variable ) but I'm still kinda puzzled. I guess I'm "thinking of template as functions" ( https://stackoverflow.com/questions/506348/how-do-i-know-my-xsl-is-efficient-and-beautiful ) Anyway...my data is <Entities> <Entity ID="8" SortValue="0" Name="test" ParentID="0" /> <Entity ID="14" SortValue="2" Name="test2" ParentID="8" /> <Entity

How to find partitions of a list in Scheme

痞子三分冷 提交于 2020-01-03 17:19:08
问题 Say there is any given list in Scheme. This list is ‘(2 3 4) I want to find all possible partitions of this list. This means a partition where a list is separated into two subsets such that every element of the list must be in one or the other subsets but not both, and no element can be left out of a split. So, given the list ‘(2 3 4) , I want to find all such possible partitions. These partitions would be the following: {2, 3} and {4}, {2, 4} and {3}, and the final possible partition being

PHP recursively traverse object tree [closed]

青春壹個敷衍的年華 提交于 2020-01-03 17:04:10
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . I have got a $branch object that can contain other $branch objects: $branch->children(); Each of them can have $apples as children.

Program to find every list of X in Prolog

青春壹個敷衍的年華 提交于 2020-01-03 16:01:30
问题 I am starting on learning Prolog. This program tries to get all occurrences of a given element: occurences(_, [], Res):- Res is []. occurences(X, [X|T], Res):- occurences(X,T,TMP), Res is [X,TMP]. occurences(X, [_|T], Res):- occurences(X,T,Res). But here is the error: ?- occurences(a,[a,b,c,a],Res). ERROR: is/2: Arithmetic: `[]/0' is not a function ^ Exception: (11) _G525 is [] ? creep Exception: (10) occurences(a, [], _G524) ? creep Exception: (9) occurences(a, [a], _G524) ? creep Exception:

The mechanism of anonymous function to call itself in Scheme?

不羁的心 提交于 2020-01-03 14:07:26
问题 I'm reading The Little Schemer and feel confused about the following code: ((lambda (len) (lambda (l) (cond ((null? l) 0) (else (+ 1 (len (cdr l))))))) eternity) (define eternity (lambda (x) (eternity x))) The code is to determine the empty list, otherwise it never stops. Why is the " len " not recursion? 回答1: Although it can be dangerous to apply textual substitution to Lisp forms (since there are dangers of multiple evaluation, etc.), in this case it may help to look at this form and see

The mechanism of anonymous function to call itself in Scheme?

南楼画角 提交于 2020-01-03 14:07:09
问题 I'm reading The Little Schemer and feel confused about the following code: ((lambda (len) (lambda (l) (cond ((null? l) 0) (else (+ 1 (len (cdr l))))))) eternity) (define eternity (lambda (x) (eternity x))) The code is to determine the empty list, otherwise it never stops. Why is the " len " not recursion? 回答1: Although it can be dangerous to apply textual substitution to Lisp forms (since there are dangers of multiple evaluation, etc.), in this case it may help to look at this form and see