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

You can't do this in regular Python:

Numpy array * 10

Pandas column A + column B

Pandas Dataframe[ column C < 10 ]

Numpy array 1 / array 2 where the second array has 0s and NaNs in it. Numpy has overridden division to allow division by 0 and NaN (Numpy added data type) in addition to vectorization.

Moreover, you're encouraged to not iterate (generally a lot slower) if you can help it when using these libraries.



I believe the dot product for an array is a.dot(b) ?

Would a.mult(b) be terrible for the first example?

I assume the third example is R-style:

  df[df['foo'] < 10 ] ?
I don't believe I can ovveride 'is', or 'instanceof', plus df has to pre-exist:

  foo = make_df()[foo['col'] > 10]
why does it have to be R-style? is that necessarily more powerful than something more pythonic?

  df.filt(lambda x: x > 10, ['foo'])
or even

  df.filt(lambda x, y: (x > 10) and (y > 10), ['foo', 'bar'])

  new_tbl = make_df().filt(lambda x, y: (x > 10) and (y > 10), ['foo', 'bar'])
vs

  df[(df['foo'] < 10) & (df['bar'] < 10)]
also, I believe James Powell does a talk wrt the inconsistencies of pandas/numpy interface.


Subclass array.array and specialize the operators as you desire. All in pure, albeit slower, Python. Numpy is just a library.


Embedded DSL's are just libraries, what makes something an embedded DSL is that it attempts to be a literate fluent configuration language in the host languages native syntax. If it doesn't use the host langauge's syntax, it's not an embedded DSL, it's an external one.


Numpy doesn't introduce new syntax. Novel operator behavior does not a DSL make.


You don't have to intrude new syntax to create an embedded DSL, that's the whole point of an embedded DSL, it uses the languages existing syntax. Smalltalk and Lisp are full of DSL's, as is Ruby, of the three only Lisp has the ability for syntactic abstraction, every Smalltalk DSL uses native syntax. See Seaside's DSL for html generation or Glorp's for database mappings.


I don't think you can introduce new syntax in Python and have it run as part of the language, so magic methods, decorators and metaclasses are as good as it gets. You'd have to write a parser to handle new syntax, and that makes it external, right?


You can also use MacroPy[1] and create embedded DSL with a macro system inspired by Scheme and Elixir.

You don't need to write a parser, btw, because the stdlib provides one for you (in `ast` module).

[1] https://github.com/lihaoyi/macropy




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

Search: