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

GP talks about getting encoding and decoding together by implementing the spec once. In Erlang/Elixir you can only get one at a time because you can't do the equivalent of this:

  some_predicate(<concrete values>, Decoded). % decoder
  some_predicate(Encoded, <concrete values>). % encoder
  some_predicate(<concrete values>, <concrete values>). % validator
But in Prolog, that's what many predicates permit as a baseline. In Erlang, yes, a validator is, or can be, a parser/decoder. But it's not an encoder which still needs to be a separate function (or set of functions) to describe movement in the other direction.


This is fantastic bite-sized example of exactly what makes Prolog and other logic languages so different to program in and will probably become my go-to example for introducing what's so special about Prolog to programmers with backgrounds in other programming languages who are looking for examples that involve "real-world" programming tasks.




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

Search: