| 1 | #include "hybrid_main.h" |
| 2 | #include "ui_hybrid_main.h" |
| 3 | #include <sstream> |
| 4 | #include <QMessageBox> |
| 5 | #include "cl_bridge_utils.hpp" |
| 6 | using ss=std::stringstream; |
| 7 | using std::cout; |
| 8 | using std::endl; |
| 9 | hybrid_main::hybrid_main(QWidget *parent) : |
| 10 | QMainWindow(parent), |
| 11 | ui(new Ui::hybrid_main) |
| 12 | { |
| 13 | ui->setupUi(this); |
| 14 | } |
| 15 | |
| 16 | |
| 17 | hybrid_main::~hybrid_main() |
| 18 | { |
| 19 | delete ui; |
| 20 | } |
| 21 | |
| 22 | /* int -> string */ |
| 23 | auto itos=[](auto in){ |
| 24 | ss s;s<<in;string res;s>>res; |
| 25 | return res; |
| 26 | }; |
| 27 | |
| 28 | /* when called, an alert dialog shows up */ |
| 29 | auto jump_out_alert_window=[](std::string str){ |
| 30 | QMessageBox::critical(0 , |
| 31 | "critical message" , QString::fromStdString(str), |
| 32 | QMessageBox::Ok | QMessageBox::Default , |
| 33 | QMessageBox::Cancel | QMessageBox::Escape , 0 ); |
| 34 | |
| 35 | }; |
| 36 | |
| 37 | /* concurrent fibonacci */ |
| 38 | void hybrid_main::on_pushButton_clicked() |
| 39 | { |
| 40 | auto str=ui->edit->text().toStdString(); |
| 41 | if(str==""){ |
| 42 | jump_out_alert_window("You haven't input anything!"); |
| 43 | } else { |
| 44 | cl_obj rtv=cl_eval("pfib", str); |
| 45 | string strt=itos(rtv.to_int()); |
| 46 | ui->ans->setText(QString::fromStdString(strt)); |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | /* quick sort. */ |
| 51 | void hybrid_main::on_pushButton_2_clicked() |
| 52 | { |
| 53 | auto str=ui->input->text().toStdString(); |
| 54 | if(str=="") |
| 55 | { |
| 56 | jump_out_alert_window("You haven't input anything!"); |
| 57 | } else { |
| 58 | cout<<par_list(str)<<endl; |
| 59 | cl_obj rtvl=cl_eval("qsort", par_list(str), "#'<"); |
| 60 | cout<<rtvl.car().to_int(); |
| 61 | string lab=""; |
| 62 | auto read_list_to_string=[&](auto elem){lab=lab+" "+itos(ecl_to_int(elem));}; |
| 63 | rtvl.list_traverse(read_list_to_string); |
| 64 | ui->output->setText(QString::fromStdString(lab)); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | /* hello lisp */ |
| 72 | void hybrid_main::on_pushButton_3_clicked() |
| 73 | { |
| 74 | string s=cl_obj(cl_eval("say-hello")).to_std_string(); |
| 75 | jump_out_alert_window(s); |
| 76 | } |