Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Qualified imports don't work well with uniform call syntax. How would you write "foo-bar".split("-") with full qualification? "foo-bar".(strutils.split)("-") ?


You could have something like

    import strutils{split, trim}
similar to how rust does things.

What would be the problem with that?


Nim does have that:

    from strutils import split, trim
Most people don't use it because it's annoying to constantly add and remove imports when changing your code, but it's definitely an option.


In some languages there is a pipe operator that does the job well. Elixir example:

    "foo-bar" |> String.split("-")
IMO method chaining is a lot better this way, much less desire for monkey patching, etc.


There's no need for monkey patching in Nim. x.f(y) is fully equivalent to f(x,y).

The functional approach requires currying and data-last parameter order, which are both unidiomatic in Nim.


Thanks, TIL! Obviously I have no experience in Nim. This convention reminds me of Perl, which works much the same way.

How is it possible, then, to call a function that lives in a different namespace as part of a dot-chain of methods?

The Elixir approach does not rely on currying; like much of the language's fancy parts, it's a macro.


Nim generally doesn't use namespaces, so… that's how.

I didn't even know Elixir had macros…


Elixir is a homoiconic language with hygienic macros. Macros are a great tool when you need them!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: