nim-lang / fusion

Fusion is for now an idea about how to grow Nim's ecosystem without the pain points of more traditional approaches.
MIT License
128 stars 16 forks source link

`min` example for fusion/astdsl.nim is wrong #43

Closed slonik-az closed 3 years ago

slonik-az commented 3 years ago

The fusion/astdsl has a usage example in https://nim-lang.github.io/fusion/src/fusion/astdsl.html for the min macro that is wrong.

How to reproduce

replace the assertion in the example with

assert min("d", "c", "b", "a") == "a"

Output

Error: unhandled exception: XXXX/min.nim(25, 8) `min("d", "c", "b", "a") == "a"`  [AssertionDefect]

The reason being that min("d", "c", "b", "a") returns "c" actually.

The min algorithm as implemented is wrong. It should not be a sequence of elif branches that stops the first time a smaller element is found. A loop over all the elements is needed to find the minimum.

planetis-m commented 3 years ago

Omg you are totally right! I should have tested it better.

planetis-m commented 3 years ago

The easiest way to implement min with a macro is using nestList So maybe I should look for a better example.

slonik-az commented 3 years ago

Just sumbitted a PR #48 that fixes the min macro example code.

narimiran commented 3 years ago

Fixed in #48.