Sow the phase and Reap the sin -- why?

  • Context: Mathematica 
  • Thread starter Thread starter Swamp Thing
  • Start date Start date
  • Tags Tags
    Phases Sine
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
2 replies · 3K views
Swamp Thing
Insights Author
Messages
1,062
Reaction score
819
Mathematica code :

Code:
Reap[     (
              sin = (
                           (
                             phase = 2 Pi #/32; Sow[phase]; Sin[phase]
                           ) & /@ Range[32]
                    )
           )
     ]

The output looks like this:
1739760534140.png



But I would have expected only the phases, i.e. the second sublist only. Why do the sine values get reaped along with the phases that are actually sown?
 
Physics news on Phys.org
Reap returns a list with two elements. The first is the value of the expression evaluated. The second is the list of sown elements.
 
Reply
  • Informative
Likes   Reactions: Swamp Thing
Ok... a semicolon after the "sin = (...)" changes the sin arrray into a Null. In the past I have sometimes wondered about the Null... I suppose I used to put the semicolon in without realizing its role, and forgot to do so this time. Also this time, the reaping of the sin values is actually better than assigning them inside the loop. So I will remove the semicolon and the assignments and then unpack the big list that gets reaped, containing the phases as well as the sin terms.

Thank you.