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

I do not understand at all author's statement that OCaml datastructures are big win over Python's

  let {cache; config} = b in
  print_endline (String.concat "," cache);
  print_endline (String.concat "," config)
  ;;
vs, actually I'm not even sure what the ocaml is attempting, some variation of

  print '%s,' % b.cache
  print '%s,' % b.config
Which, in Python, if your printing more than a few should be

  print ',\n'.join((b.config, b.cache, b.data))
Or if want all fields and they are in correct order

  print ',\n'.join(b)
>> The syntax [of NamedTuples] isn’t great, though, and you can’t do pattern matching on the names, only by remembering the order:

Other than misuse of term "pattern matching", that statement is true and is trivially overcome with two line function, one line lambda, or once and for all by subclassing NamedTuple. Here's the function variant:

  def GimmieThing(keyword args in any order)
     return ThingNamedTuple(args in correct order)


How is it a misuse of the term "pattern matching" ?


Generically http://en.wikipedia.org/wiki/Pattern_matching

And as for a language / call semantic look at Erlang for what actual pattern matching looks like.


That doesn't contradict the use of pattern matching in OCaml.


Both the OA and myself are talking about Python.




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

Search: