How can I parse coordinates in CL?

I’ve got an expression where students are to enter some coordinates like (4, 5) and I want to extract the x and y components.

How can I do this in CL?

There’s a function “parseOrderedPair”, which converts latex input to an object with an “x” and a “y” member, which are the string values of what a student typed. As one example:

myPair = parseOrderedPair("(4,5)")
content: "That pair means X = ${myPair.x} and Y = ${myPair.y}"

You can see a working version here: Note • Activity Builder by Desmos

The x and y members will be latex strings, so you can use simpleFunction() to parse them if you want to plug in variable values, like we do in Blue Point Rule • Activity Builder by Desmos, or you can use numericValue() if you just want to interpret them as numbers.


Thanks! I see that it is included in the docs as the example for numericValue, but will it also get its own status as a function in that list?

Yes. We’re still expanding documentation for functions and some of the more complex data types (layers, sketches, pairs, lines)

1 Like