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

Support for objects #533

Merged
merged 40 commits into from Feb 27, 2016

Conversation

Projects
None yet
2 participants
@josdejong
Owner

josdejong commented Jan 5, 2016

I've implemented support for objects:

  • In the expression parser you can now do:

    math.eval('{a: 2, b: 3}')
    math.eval('obj.prop')
    math.eval('obj["prop"]')
    math.eval('obj.prop = 4')
  • The functions math.subset and math.format are extended with object/property support.

To be discussed:

I think we have to make one breaking change.

Right now, assignments in the expression parser are implemented such that they return the updated object or matrix rather than the assigned value. For matrices this made sense as you want to see the whole updated matrix as output in a maths application. But I think we have to distinguish the operation of the assignment, and the processing of output. All languages I know of return the assigned value, which also makes sense as you can chain multiple assignments. Example:

A = eye(3)
A[1,1] = 2        # math.js currently returns the the updated matrix A instead of 2 

obj = {}
obj.prop = 42     # math.js currently returns obj instead of 42 

What do you think?

@josdejong

This comment has been minimized.

Owner

josdejong commented on lib/expression/node/ObjectNode.js in 8d3d58e Jan 3, 2016

@FSMaxB I'm working on implementing support for objects in the expression parser (branch feature/objectsupport). I've introduced a new Node for this: ObjectNode.

I'm not sure how we should format an (JSON like) object in LaTeX, do you have an idea?

This comment has been minimized.

Collaborator

FSMaxB replied Jan 4, 2016

Hm, that's quite a hard problem.

Some kind of tree would be nice, but that's probably not possible with MathJAX.

Maybe something like this:

\left\{\begin{matrix}
  \mathbf{key:} &  \mathbf{value}\\
  \mathbf{some\_object:} & \left\{\begin{matrix}
    \mathbf{key1:} & \mathbf{value1}\\
    \mathbf{key2:} & \mathbf{value2}\\
  \end{matrix}\right.\\ 
\end{matrix}\right.

object-latex

Or maybe just print regular JSON?

This comment has been minimized.

Owner

josdejong replied Jan 4, 2016

Thanks for the feedback. I think we should be careful not to over-engineer this (after all, people can always override the default formatting if they want something special :) ). At least we should not rely on specific non-standard packages for indentation and stuff.

How about something that looks more traditional, with newlines and indentation blocks? I'm only not sure how to do that with LaTeX, at least the following doesn't work:

\{\newline
\indent key: value\newline
\}\newline

This comment has been minimized.

Collaborator

FSMaxB replied Jan 4, 2016

Even if it did work, this would be problematic when nesting objects because this would have to keep track of the current indentation level to work properly.

I am by no means a LaTeX expert, but I'll think about how this can be done. Maybe use the matrices from my former example code to achieve something similar to your indentation blocks.

This comment has been minimized.

Owner

josdejong replied Jan 4, 2016

Ok thanks for looking into it. If it becomes to too complicated or fragile I think we should just keep it simple though.

FSMaxB and others added some commits Jan 4, 2016

Merge pull request #531 from FSMaxB/object-latex
ObjectNode: prettier LaTeX output
Assignments in the expression parser now return the assigned value ra…
…ther than the created or updated object (see #533)
@josdejong

This comment has been minimized.

Owner

josdejong commented Jan 8, 2016

I've now changed this behavior: assignments in the expression parser now return the assigned value rather than the created or updated object.

@josdejong josdejong referenced this pull request Feb 15, 2016

Closed

Breaking changes for v3 #572

@josdejong josdejong merged commit a60a70e into develop Feb 27, 2016

0 of 2 checks passed

continuous-integration/travis-ci/pr The Travis CI build is in progress
Details
continuous-integration/travis-ci/push The Travis CI build is in progress
Details

@josdejong josdejong deleted the feature/objectsupport branch Feb 27, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment