From: "Victor \"Zverok\" Shepelev" Date: 2006-12-06T10:07:01+09:00 Subject: Re: Lisp comprehensions => SQL From: khaines@enigo.com [mailto:khaines@enigo.com] Sent: Wednesday, December 06, 2006 2:46 AM >On Wed, 6 Dec 2006, Victor "Zverok" Shepelev wrote: > >A lot of these things are either supported in Kansas, or are in the >drawing board for when I can get back to Kansas development. > >> employees = Table.new(:id, :name, :sec_name, :salary, :age) >> >> employees.select{|e| e.name == 'John' && e.salary > 50}.sort_by{|e| >> e.age}[2,10] > >Current Kansas: > >dbh.select(:Employees) do |e| > sort_by(e.age) > limit(2,10) > (e.name == 'John') & (e.salary > 50) >end > >Future Kansas: > >employees = Kansas::DBNAME::Employees >employees.select do |e| > sort_by(e.age) > limit(2,10) > (e.name == 'John') & (e.salary > 50) >end > >> employees.select{|e| e.salary < 150}.count > >Current: > >dbh.count(:Employees) {|e| e.salary < 150} > >Future: > >employees.count {|e| e.salary < 150} > >> employees = Table.new(:id, :name, :sec_name, :salary, :age) >> positions = Table.new(:id, :employee_id, :position_name) >> >> (employees + positions).select{|e, p| e.id == p.employee_id} > >Current: > >dbh.select(:Employees, :Positions) {|e,p| e.id == p.employee_id} > > >I have not worked on Kansas much in the last year because it is stable for >me, but there are a number of things that I have planned when I can set >aside some time to get back around to it. > Interesting. But I still don't understand, why to use custom DSL instead of familiar Ruby (ok, with changin && => &) #having employees.select do |e| sort_by(e.age) limit(2,10) (e.name == 'John') & (e.salary > 50) end #proposal: employees.select{|e| (e.name == 'John') & (e.salary > 50)}.sort_by{|e| e.age}[2..10] The latter is "just Ruby". V.