News for hackers. Stuff that matters.
Re:Decision Tables by jmmcd on Thursday October 18, 2018 @04:58PM (#18252051)
Yes, but it would be nicer if the table was stored as a table -- as data -- not as code.
Re:Decision Tables by derefr on Thursday October 18, 2018 @05:12PM (#18252174)
Why? It'd be a mapping from "patterns" (a concept that exists only within the language's compiler/interpreter) to executable closures. How is that any different from the AST of the match-expression in the GP's comment? And what would you do with that mapping, besides using it as an AST to generate code, perhaps after adding/removing some match clauses?

In this case, the most optimal representation of the data is the code.

Re:Decision Tables by zokier on Thursday October 18, 2018 @05:49PM (#18252456)
I would go with a "compromise"; while decision tables should be "code", I think it could be nice if there was some syntatic sugar for making these tables actually tabular. Of course semantically it would be very much the same as a pattern match.
Re:Decision Tables by jmmcd on Thursday October 18, 2018 @06:03PM (#18252551)
> what would you do with that mapping

Well, I could write another tool to analyse it, eg extract some statistics; I could write another tool to generate it, eg based on data.

Re:Decision Tables by derefr on Thursday October 18, 2018 @06:12PM (#18252609)
Why can't you do either of those things with the AST of the match-expression? And what stops you from leaving the code as code, and extracting that AST by calling into the compiler?

(Maybe I'm being unfair here. I write mostly Elixir, and it's really easy in Elixir—one or two lines—to extract the AST of the body of a function defined in a given file and then work with it. It's just as easy to hold data canonically in its AST representation, and then both analyze it, and generate code from it, at runtime.)