Group Abstract Group Abstract

Message Boards Message Boards

0
|
8.7K Views
|
4 Replies
|
0 Total Likes
View groups...
Share
Share this post:

User Defined Heads

Posted 10 years ago

Is it possible to define one's own Head or type in Mathematica? If so then how does one do it? Thank you.

POSTED BY: Roger Backhus
4 Replies

There are no types! Integer and Complex are just heads that people use in a way that's like a type.

What is your background in programming and software engineering? If you have a lot of background in programming languages, like a grad student in comp sci, I recommend the free book I linked to. However, if you are like most people who program with Mathematica, you don't need to know anything about this stuff and it won't help you. It will instead just be needlessly confusing and frustrating. To learn the basics of programming in Mathematica, read through the Mathemativa virtual book: https://www.youtube.com/watch?v=2wlk9qqPxp4

To answer your question:

Once you've created a head, you use Upvalues and Downvalues to create operations with that Head.

If you're interested in this, you may be interested in reading about how people implement algebras such as Quarternions or Dual Numbers in Mathematica.

POSTED BY: Sean Clarke
Posted 10 years ago

Yes, you are correct and function names are heads. I forgot about that. But, I was thinking about my own type like an Interger or Complex. Then I'd create the infrastructure around my type to handle sums, products, ...

POSTED BY: Roger Backhus
POSTED BY: Ulrich Mutze

Yes you can make your own Head.

Bit I'm afraid I don't actually understanding your question as it is written. Are you asking how to make a fuction?

If you have a background with programming already, I would recommend this introduction. http://www.mathprogramming-intro.org/

Here is how you make your own head in Mathematica:

hereIsMyHead[]

You just write it. That's it. There's no grand declaration of its existence or anything. If you want it to do something ... you can program that head to do something. For example, we can program the head to do something to an argument, which basically makes it a function:

hereIsMyHead[a_] := "The Head Called hereisMyHead was given " <> ToString[a] <> " as an argument

The Wolfram Language isn't really typed. As you have noted, heads take the place of types in many respects.

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