Posted to tcl by mjanssen at Fri Jul 23 09:35:24 GMT 2021view raw

  1. set grades {Peter B
  2. Celine A-
  3. Zsófia B+
  4. João F
  5. Maryam B+
  6. Àñ B-
  7. Finn D+
  8. Aarav A
  9. Emma F
  10. Omar B}
  11.  
  12. package require sqlite3
  13.  
  14. sqlite3 db :memory:
  15. db eval {CREATE TABLE grades(name TEXT PRIMARY KEY, grade TEXT, naked_grade TEXT)}
  16.  
  17. foreach {name grade} $grades {
  18. if {![regexp {[A-F][+-]?} $grade]} {
  19. puts "Can't parse pair '$name $grade'"
  20. exit 1
  21. }
  22. db eval {INSERT INTO grades VALUES ($name, $grade, trim($grade, '+-') )}
  23. }
  24.  
  25. puts "Zsófia's grade: [db eval {SELECT grade FROM grades WHERE name='Zsófia'}]"
  26.  
  27. puts "List of students with a failing grade:"
  28. puts " [join [
  29. db eval {SELECT name FROM grades WHERE grade >= 'E' ORDER BY grade}
  30. ] {, }]"
  31.  
  32.  
  33. db eval {select naked_grade, count(*) from grades group by naked_grade}