2

I am writing an algorithm in latex and don't know how to distinguish between assignment and collection operations.

Assignments be written as: A <- B + C

But in case of add to collection, I usually do

A <- {}
loop condition:
  A <- A + X

Is there anything else that I can use instead of \leftarrow and not have to write A + X on the right always.

Thanks in advance

3
  • If the collection is based on sets, then use \cup (set union).
    – Werner
    Aug 7 '13 at 20:37
  • @Werner: Thanks. Actually I thought about it but sometimes I have Map data where I am currently using :: A <- A + T[key -> value] Which looks dirty I think :/
    – Shauvik
    Aug 8 '13 at 6:07
  • Welcome to TeX.sx! Your post was migrated here from Stack Overflow. Please register on this site, too, and make sure that both accounts are associated with each other (by using the same OpenID), otherwise you won't be able to comment on or accept answers or edit your question.
    – Werner
    Aug 12 '13 at 19:38
2

I don't think there is a standard for pseudocode. You could write it in a somewhat object-oriented way like this:

  A.insert(X)

In pseudocode I would also avoid + to merge sets, and would rather use the set union symbol, ∪.

3
  • Yes, i thought about this but adding words makes it more non-standard. Don't you think? I mean there can be insert, append, add, put etc all for the same fundamental operation. What about adding a plus over the arrow? A <-+- X .. this can be done using \overset{+}{\leftarrow} Example: latex.codecogs.com/…
    – Shauvik
    Aug 8 '13 at 6:13
  • Sure, there can be multiple words, so pick one and stick with it. I think that's better than inventing your own symbols. When in doubt, just show it to some colleagues and see if they understand your notation right away.
    – Thomas
    Aug 8 '13 at 9:21
  • Thanks :) Since my work might be read by an international audience, I thought StackOverflow was a better platform than my labmates who are somewhat biased.
    – Shauvik
    Aug 8 '13 at 18:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.