Skip to content
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

Detect and complain if the same symbol is used for two or more concepts within the same document #1916

Closed
smiths opened this issue Sep 20, 2019 · 7 comments · Fixed by #2167

Comments

@smiths
Copy link
Collaborator

smiths commented Sep 20, 2019

This issue came up during the discussion in #1901.

Symbols are routinely used for different meanings in science and engineering. However, if the same symbol has more than one meaning in the same document, this is a problem. Drasil should prevent the user from making this mistake by automatically detecting if a symbol is use for more than one purpose within the same document.

@muhammadaliog3
Copy link
Collaborator

@smiths
do you know how to convert a sentence to a string. I need it because the error function in Haskell must have an argument of type string.

@smiths
Copy link
Collaborator Author

smiths commented Jun 3, 2020

I'm sorry @muhammadaliog3, but I do not know the answer to your question. Maybe you can find it by looking at the code documentation:

https://jacquescarette.github.io/Drasil/docs/index.html

Alternatively, this is likely a question that @JacquesCarette or @bmaclach could answer.

@JacquesCarette
Copy link
Owner

First, you should really investigate if that Sentence is crucial, i.e. if it is inevitable that the only information you have, when you're ready to throw that error, is a Sentence. Often, it is not, and then printing is simplified.

If it is, then there are various 'rendering' functions in drasil-printer. You'll need to use the plain printer.

If you tell us the context more precisely, we can direct you to the proper functions. Often, wishing to print a Sentence is actually a sign that you're not quite doing the right thing. [And sometimes, it's a design bug in Drasil.]

@muhammadaliog3
Copy link
Collaborator

muhammadaliog3 commented Jun 3, 2020

@JacquesCarette
I guess this is a good time to present my solution.
Say we have the the following rows in a symbols table
[(sigma, description_1),(sigma, description_2),(E, discription_3),(E, description_4)]
Here two variables have the conflicting symbol of sigma and 2 have conflicting symbol of E.

I do not believe that in the error we should simply print "Duplicate symbols found", rather we should at the very least say "Duplicate symbols found. See the following descriptions: (description_1,description_2,description_3,description_4)".

These descriptions are stored as a list of sentences. I can fold the sentences into one sentence, but to print the error I still need to convert that one sentence to a string. This is the code by the way, the line with ----HERE------------ is where I print the error.

table :: (Quantity s, MayHaveUnit s) => Stage -> [s] -> (s -> Sentence) -> LabelledContent
table st ls f
    |noDuplicate = llcc symbTableRef $
      Table [atStart symbol_, atStart description, atStart' unit_]
      (mkTable [P . (`symbol` st), f, toSentence]
      $ filteredChunks)
      (titleize tOfSymb) True
    |otherwise = error $ "Duplicate Symbols" ++ foldlSentCol descDuplicates ---HERE----------------
    where 
        filteredChunks = filter (`hasStageSymbol`st) ls
        symbolsCol = map (P . (`symbol` st)) $ filteredChunks
        descCol    = map (f)                 $ filteredChunks
        symDescPair = zip symbolsCol descCol
        symDuplicates = symbolsCol \\ (nub symbolsCol) --if you did not know (\\) is the difference between lists
        noDuplicate = symDuplicates == []
        descDuplicates = [snd x | x <- symDescPair, fst x `elem` symDuplicates]

@JacquesCarette
Copy link
Owner

That's a nice piece of Haskell. I would prefer if the error was even more verbose & precise: it should give an error for each UID/symbol/description tuple that is duplicate. So an error for (sigma, description_1),(sigma, description_2) and another for (E, discription_3),(E, description_4).

@muhammadaliog3
Copy link
Collaborator

muhammadaliog3 commented Jun 4, 2020

But to print the errors you mentioned I would need to convert a sentence to a string. I still do not know how to do that.

@JacquesCarette
Copy link
Owner

Oh, because of the descriptions? Ok, skip those. Just do the UIDs and symbols then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants