Group Abstract Group Abstract

Message Boards Message Boards

1
|
16.9K Views
|
15 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Can a function know its own name?

Say I have a function:

test[x_] := Block[{x}, ToExpression["test" <> "State"]; testState = 67]

testState is a global that test can refer to to see its last state:

In[133]:= testState

Out[133]= 67

Test needs to be used repeatedly by renaming it test1, test2, etc.

So, can test1 know its own name?

POSTED BY: Eric Johnstone
15 Replies

Hi Neil,

Using SystemModeler would defeat the purposes of this exercise which are to learn more about Mathematica and also to play around with Boolean algebra. I'd like to use the original algebra that Boole develops in An Investigation of the Laws of Thought. In it, he uses subtraction and division and elimination of variables from a system of equations. Of course, it has nothing to do with circuits--it's all about thought!

But the big problem is: Why doesn't Mathematica support static variables?

Hi Michael,

When I tried your original code, nothing happened. Just tried it again, still nothing. But it obviously works. (Sorry for misspelling your name.)

I suggested using a name in the fifth post down. This is the way to go--you're right, test1[] produces testState, not test1State.

Eric

POSTED BY: Eric Johnstone

Not sure exactly what you're after, but this sets name to the held head of the function call:

call : test[x_] := Block[{x},
  Print[name = Hold@call /. Hold[f_[___]] :> Hold[f]];
  ToExpression["test" <> "State"];
  testState = 67]

test[a]
(*
  Hold[test]
  67
*)

name
(*  Hold[test]  *)

Not sure what the Block[{x}..] is for nor the ToExpression. They seem extraneous or confusing.

POSTED BY: Michael Rogers
Posted 8 years ago

Eric,

I hadn't seen your other thread. I just glanced at it. I can give a few comments on Mathematica's notation vs engineering notation. I think it is fine that you are creating a way to convert between the two. However, I don't have a problem with using or interpreting Mathematica's notation. It is standard, accepted math notation, after all. I say that as a former EE who was taught engineering notation. The downside of the conversion is that it adds another layer of notation. It may also lead to undesirable side effects. For those reasons, I doubt that I would find it useful.

I wasn't currently working on any Boolean related functionality. I happened to see this thread about function names and thought it might be interesting to see the reason for the question and the replies. After understanding what you were actually trying to implement, I thought it would be useful to see if I could implement a JK FF in MMA. I read Neil's suggestion to use SystemModeler, but a full license for that is unreasonably expensive for an individual (my opinion). I have the Home licensed version of SystemModeler, but it is not being kept updated as far as I know. You also mentioned that you would like to implement the MMA version as a learning experience. So, I came up with something very rudimentary in MMA. I used very limited error checking. I haven't thought much about how I would model connecting these FF's in a circuit and sequence them with a clock. Obviously, it would be a significant abstraction from real world hardware. I'm sure what I implemented could be improved, but I'm happy with my first attempt. Good luck with you investigations.

POSTED BY: David G

Hi David,

I've been poring over the MMA Boolean functions. As usual in MMA, there is more than you could have imagined available. Here is my Boolean thread that I will be augmenting soon:

http://community.wolfram.com/groups/-/m/t/1257404

The current state of the Boole functions is attached below. As you can see, I'm not a sophisticated user, but I'm learning a lot about MMA. I'll study your post and try manipulating things. Are you working with Boolean functions? You're the only responder so far who has mentioned the Boolean functions.

Eric

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard
Be respectful. Review our Community Guidelines to understand your role and responsibilities. Community Terms of Use