-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiple heads and nested lists and functions? #22
Comments
I don't quite understand. What does the Mathematica code do? |
What does it mean to match a function? In your JS example, what do the tildes mean? |
@littledan Matching a functions is more unique to Lisp and Mathematica. I have used
http://reference.wolfram.com/language/tutorial/Introduction-Patterns.html.en |
How can a function be matched if not by identity? Its name and length are all you can reliably know about it. |
@ljharb do you mean how can they be matched internally or what would the syntax be? |
Internally. There's no other meaningful information available (anything that's newly matchable constitutes new exposure of information about a function, and that could violate security concerns) |
@ljharb if you do function.toString() you often get the entire functions body depending on the implementation. |
Correct, but that's not something that we should be matching on. |
@ljharb Pattern matching truly becomes useful when the language is more like LISP which I guess is my opinion. |
I don't see how we can support pattern matching on functions. We'd need a proposal for multi-methods or similar which is out of scope for this proposal (but should be considered). I still don't understand what "heads" means above? |
@bterlson If we are ignoring matching pattern matching functions then Heads can bascically be regarded as the variables instanceof value(with caveats). In haskell it is the first value of a list but that isn't particularly useful and would be covered easily by the implementation above like so |
May I ask why this was reopened after 3 years? Honestly, I reread OP several times and I don't understand the issue. Are you essentially asking for active patterns? If so, active patterns don't make sense without tagged union types. If you are asking about pattern matching, there is already this issue. |
Is there a way to match multiple 1,1+ or 0+ heads(also known as variable type/instance of depending on the implementation or first value in a list)? For example let's say I have the following array of JavaScript instances where Number and String could be any type. There is the left and right side of the
..
operator. The left side defines the name of the the pattern and the right is the instanceof object(with _caveats).In addition what about nested patterns of functions? Doing so would make JavaScript much more like a LISP.
I'm thinking something like the following in Mathematica which would return
True
. Remember functions in Mathematica start with are written like the followingf[agrs]
instead off(args)
and arrays are written like{1,2}
.If you are familiar with LISP the following is a basic example.
In Mathematica the function name you are trying to match exists before the
_
while the variable name exists after the underscore.Adopting how Mathematica does it it except using the
..
.Basically in LISP you can match both functions and lists which are nested. Adapting more examples give me a minute.
values that can get reevaluated can get tricky.
The text was updated successfully, but these errors were encountered: