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

IMO better would be a database interface that acts as a normal programming language, treating tables as arrays of records. Compare:

  how many teachers older than 30
  teachers.filter(*.age > 30).len
Same length, but the second one has a degree of precision that the first lacks. (Though they might diverge somewhat as the complexity of queries grows, I suspect programming languages would do better as they have better facilities for symbolic manipulation.) Note also that the second example (and your SQL example) had to specify the table's name, while the natural language one did not—another mark against the natural language solution.


What you described sounds a lot like .NET's LINQ, which translates to SQL queries as well:

    teachers.Where(t => t.Age > 30).Count();


Linq is cool; I haven't really had opportunity to play with it as I'm not in the .net ecosystem. Another integrated language/database is kdb, although it borrows somewhat from sql's syntax.


I would suggest something more like:

    teachers[age > 30].count
(Because I'm working on something exactly like this right now)


In apl (incl. apl-alikes—kdb, etc.), you can essentially say this directly. 'age > 30' produces an array with the same shape as 'age' with a 1 for instances that are >30 and 0 else. So for instance:

        27 42 44 > 30
   0 1 1
If all you want is a count of teachers older than 30, you can simply sum up the resulting array, so:

         +/0 1 1  ⍝note: '/' is reduction, so +/ is sum reduction
   2

If you want the indices, you can use 'where', which will produce an array of indices corresponding to 1s in its argument, so

         ⍸0 1 1
   1 2
Indicates that '0 1 1' has 1s at indices 1 and 2. (We could also take the length of this array to get the count of teachers older than 30, although that would be a bit silly compared to just summing the original array.)

We can then use these indices to index a different array:

         ages←27 42 44
         names←'anthony' 'barbara' 'bert'
         names[1 2]
    barbara  bert
         names[⍸ ages>30]
    barbara  bert
However, we don't even need to use 'where' in this case; the reduction operator (/) has a second use which lets us say:

         0 1 1 / names
    barbara  bert
         (ages > 30) / names
    barbara  bert
Good luck with your database, and hope this helps!


It's possible to use Clojure/ClojureScript functions inside datalog queries

http://www.learndatalogtoday.org/


Your example reminds me of RethinkDB, which I haven't used in years but as I recall it was quite nice!




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

Search: