1
$\begingroup$

I was trying to implement some Graph related functions in Functional form and came accross this result which I found surprising.

I want a function that does various operations on a graph.

The simplest operation is Identity which could simply count the number of nodes in the graph.

Somehow this function does exactly that.

Fold[1 + #&][1,{a,b,c,d}]

giving:

5

And the corollary result which shows how it works:

FoldList[1 + #&][1,{a,b,c,d}]

giving:

{1, 2, 3, 4, 5}

The two questions that arise are:

  1. Can this result be explained in an intuitive fashion ?
  2. Can this idea be used to perform more complex operations on the graph ?
$\endgroup$

closed as off-topic by Αλέξανδρος Ζεγγ, m_goldberg, bbgodfrey, Henrik Schumacher, mikado Dec 29 '18 at 10:42

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Αλέξανδρος Ζεγγ, m_goldberg, bbgodfrey, Henrik Schumacher, mikado
If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ Did you forget a }? Or did you have a { too much? $\endgroup$ – C. E. Dec 22 '18 at 21:25
  • 1
    $\begingroup$ FoldList >> Properties and Relations : Functions that ignore their second argument give the same result as in NestList. Similarly for Fold. $\endgroup$ – kglr Dec 22 '18 at 21:40
  • $\begingroup$ @C.E. Thanks for pointing this out. I removed the superfluous {. $\endgroup$ – v1j4y Dec 23 '18 at 0:33
  • $\begingroup$ @kglr Ah yes, reading the docs. Thanks a lot. I learned my first lesson the hard way ! Althouth this is such an obfuscated way to count the length of a list :-P $\endgroup$ – v1j4y Dec 23 '18 at 0:36