Macaulay2 / Macaulay2/M2

Catching uncaught type errors

Open
#3,354 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Interpreter
Dominant language
Macaulay2
Stars
435
Forks
297
Avg merge
4d 20h
Merged PRs (30d)
11

Description

In the documentation node [Tutorial: Divisors](https://www.macaulay2.com/doc/Macaulay2/share/doc/Macaulay2/Macaulay2Doc/html/___Tutorial_co_sp__Divisors.html), there's this code:
```m2
i54 : effective = (D) -> (
LB := globalSections D;
L := LB#0; -- the matrix of numerators
if numgens source L == 0
then error(toString D + " is not effective")
else divisor sectionIdeal(L_(0,0), LB#1, D));
i55 : effective(2 R - P)

o55 = Divisor{ideal (z, x), ideal 1}

o55 : Divisor
```
which seems fine on the surface, until you realize that `toString D + " is not effective"` is an error, since `String + String` is not defined! Perhaps this used to be defined, but was removed at some point and because that branch in the code was never tested in the documentation, nobody realized that this is an error now.

I'm curious whether other languages have mechanisms to detect type errors like this. @DanGrayson was there ever a plan for the interpreter to catch errors like this using the `typicalValues` hash table or `pseudocode` or `disassemble`?

I understand that a user may define a function like this and define the missing methods _later_, but is there a way to check if every method call in a function is well-defined at a given point in time? e.g. `isWellDefined effective`?

For instance, `disassemble effective` yields a lisp like string and I think this section contains the error:
```
(adjacent (global-fetch 410) (2-OP + (adjacent (global-fetch 1067) (fetch 0 0)) " is not effective"))
```
I can guess what `adjacent` and `2-OP` mean and I presume `global-fetch 410` is `error` and `global-fetch 1067` is `toString`. Is there anyway to get the function corresponding to these numbers in the top level? If so, then from `typicalValues#toString` it would be apparent that the binary operator `+` is not defined for two strings.

This would be a very useful check for packages, and to make sure changes in the engine don't break untested code.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Tutorial: Divisors documentation node and the effective function, especially the failing String + String expression. Then inspect the interpreter facilities named in the issue—typicalValues, pseudocode, disassemble, and the proposed isWellDefined entry point. Done would require a decided and implemented way to detect or report such undefined method calls, with the documentation example covered.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.