Message Boards Message Boards

Wolfram Language vs. Python - which one calls itself better? Part 1

Posted 20 days ago

Attachments:
POSTED BY: Thomas Adler
4 Replies
Posted 5 days ago

Hi Darren,

Thanks for pointing that out, that is a mistake from my part. I've rectified it my original post.

POSTED BY: Thomas Adler

Hello, here's my experience with Python versus Mathematica. As opposed to Mathematica which I use since 20 years, I hardly know Python. Part of the reason is this: Learning Mathematica on your own (with its lush explanations of in-built functions, including toy examples) is certainly easier than learning Python. Furthermore various versions of Pythons are incompatible. Unfortunately Mathematica does not offer Binary Decision Diagrams (BDD) to work with (why??). For the latter I had to turn to expr2bdd from Python, and to the help of Python pro's.

POSTED BY: Marcel Wild

Hi Thomas, This is not correct:

In Mathematica, on the other hand, arguments are passed as values, meaning that the arguments are copied into the function’s local environment. This means that any modifications made to the arguments inside the function do not affect the original variables.

...associations are immutable data types, so we cannot modify them in-place anyways..

ClearAll[fChangeAssoc];
SetAttributes[fChangeAssoc, HoldFirst];
fChangeAssoc[assoc_, key_, newVal_] := AppendTo[assoc, key -> newVal];

assoc = <| "this" -> 1, "that" -> 2 |>

fChangeAssoc[assoc, "this", 3]

assoc

<| "that" -> 2, "this" -> 3 |>

Note that the first argument is NOT restricted as _Association when using the HoldFirst:

ClearAll[fChangeAssocWRONG];
SetAttributes[fChangeAssocWRONG, HoldFirst];
fChangeAssocWRONG[assoc_Association, key_, newVal_] := AppendTo[assoc, key -> newVal];

The following is not matched:

fChangeAssocWRONG[assoc]

fChangeAssocWRONG[assoc]
POSTED BY: Darren Kelly

enter image description here -- you have earned Featured Contributor Badge enter image description here Your exceptional post has been selected for our editorial column Staff Picks http://wolfr.am/StaffPicks and Your Profile is now distinguished by a Featured Contributor Badge and is displayed on the Featured Contributor Board. Thank you!

POSTED BY: EDITORIAL BOARD
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract