id
int64
0
45.1k
file_name
stringlengths
4
68
file_path
stringlengths
14
193
content
stringlengths
32
9.62M
size
int64
32
9.62M
language
stringclasses
1 value
extension
stringclasses
6 values
total_lines
int64
1
136k
avg_line_length
float64
3
903k
max_line_length
int64
3
4.51M
alphanum_fraction
float64
0
1
repo_name
stringclasses
779 values
repo_stars
int64
0
882
repo_forks
int64
0
108
repo_open_issues
int64
0
90
repo_license
stringclasses
8 values
repo_extraction_date
stringclasses
146 values
sha
stringlengths
64
64
__index_level_0__
int64
0
45.1k
exdup_ids_cmlisp_stkv2
sequencelengths
1
47
14,331
90-globals.tcl
asmaloney_ACT-R/environment/GUI/init/90-globals.tcl
set current_open_model_name "No Model Open" set current_open_model "" set ignore_returns "" set current_file_window "" set during_reload 0
144
Common Lisp
.cl
5
26.8
43
0.783582
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
cd899e4ab67de86fe44ac72aae638e0d113aee24086af7535230d7e95dccaa32
14,331
[ -1 ]
14,332
00-net-config.tcl
asmaloney_ACT-R/environment/GUI/init/00-net-config.tcl
# This is the default ip address and port that will be used for communication with ACT-R. set actr_port 2650 set actr_address "localhost"
140
Common Lisp
.cl
3
45
89
0.8
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
bad937f4436b49d31f393a4a945f67da7d57873100dedd4f199a0eb70c59966d
14,332
[ -1 ]
14,333
99-userconfig.tcl
asmaloney_ACT-R/environment/GUI/init/99-userconfig.tcl
# this file generated from saving the options set options_array(update_when_stepped) 1 set options_array(use_env_window) true set options_array(show_copyrights) 1 set options_array(use_localhost) 0 set options_array(kill_model_windows) 1 set options_array(use_smart_load) false set options_array(save_before_reload) 1 set options_array(save_backups) 1 set options_array(sort_lists) 1 set options_array(edit_warn) 1
426
Common Lisp
.cl
11
36.727273
46
0.79759
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
ce9c631acf9456af837021f1c123fc1be8ea453cceac70193bd07b5177515f1e
14,333
[ -1 ]
14,334
40-parameter-viewer.tcl
asmaloney_ACT-R/environment/GUI/dialogs/40-parameter-viewer.tcl
proc make_parameter_viewer {} { set model [currently_selected_model] if {$model == "nil"} { tk_messageBox -icon info -type ok -title "Parameter Viewer" -message "The parameter viewer requires a current model." } else { set win [toplevel [new_variable_name .param_viewer]] wm withdraw $win record_new_window $win $win $model wm geometry $win [get_configuration .param_viewer $win] # frame and list box for modules set list_frame_1 [frame $win.list_frame_1 -borderwidth 2] set list_box_1 [listbox $list_frame_1.list_box -listvar \ $list_frame_1.list_box.var \ -yscrollcommand "$list_frame_1.list_scrl set" \ -selectmode single \ -exportselection 0 -font list_font -bd 0] set list_scroll_bar_1 [scrollbar $list_frame_1.list_scrl -command "$list_box_1 yview"] global $list_box_1.var set $list_box_1.var [lindex [call_act_r_command "modules-with-parameters" $model] 0] # Frame and list box for parameters set list_frame_2 [frame $win.list_frame -borderwidth 2] set list_box_2 [listbox $list_frame_2.list_box -listvar \ $list_frame_2.list_box.var \ -yscrollcommand "$list_frame_2.list_scrl set" \ -selectmode single \ -exportselection 0 -font list_font -bd 0] set list_scroll_bar_2 [scrollbar $list_frame_2.list_scrl -command "$list_box_2 yview"] # The lables for the sections set l1 [label $win.l1 -text "Modules" -justify left -font label_font] set l2 [label $win.l2 -text "Parameters" -justify left -font label_font] # frame for the parameter display set text_frame_1 [frame $win.text_frame_1 -borderwidth 0] set text_box_1 [text $text_frame_1.text -xscrollcommand \ "$text_frame_1.text_scrl set" \ -font text_font -width 200 -wrap none] set text_scroll_bar_1 [scrollbar $text_frame_1.text_scrl -command "$text_box_1 xview" -orient horizontal] # make selection lists call the appropriate updater bind $list_box_1 <<ListboxSelect>> "select_param_module $list_box_1 $list_box_2 $text_box_1 $model" bind $list_box_2 <<ListboxSelect>> "select_param_value $list_box_2 $text_box_1 $model" pack $list_scroll_bar_1 -side right -fill y pack $list_box_1 -side left -expand 1 -fill both pack $text_scroll_bar_1 -side bottom -fill x pack $text_box_1 -side left -expand 1 -fill both pack $list_scroll_bar_2 -side right -fill y pack $list_box_2 -side left -expand 1 -fill both place $l1 -relx 0.0 -y 0 -height 25 -relwidth .5 place $list_frame_1 -relx 0.0 -y 25 -relheight 1.0 -height -75 -relwidth .5 place $l2 -relx .5 -y 0 -height 25 -relwidth .5 place $list_frame_2 -relx .5 -y 25 -relheight 1.0 -height -75 -relwidth .5 place $text_frame_1 -relx 0.0 -rely 1.0 -y -45 -height 45 -relwidth 1.0 set_update_script $win "select_param_value $list_box_2 $text_box_1 $model" wm deiconify $win focus $win } } proc select_param_module {modulewin paramswin text model} { set selection [$modulewin curselection] global $paramswin.var $paramswin selection clear 0 end update_text_pane $text "" if {$selection != ""} { set $paramswin.var [lindex [call_act_r_command "modules-parameters" $model [list [$modulewin get $selection]]] 0] } else { set $paramswin.var "" } } proc select_param_value {paramswin target_win model} { set selection [$paramswin curselection] if {$selection != ""} { update_text_pane $target_win [lindex [call_act_r_command "printed-parameter-details" $model [list [$paramswin get $selection]]] 0] } else { update_text_pane $target_win "" } } button [control_panel_name].param_viewer -command {make_parameter_viewer} -text "Parameters" -font button_font pack [control_panel_name].param_viewer
4,031
Common Lisp
.cl
76
44.907895
134
0.651193
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
894325f61f62c8bcddbf74d373b39956c63e22817a4ba95b4b2f38602d0a664d
14,334
[ -1 ]
14,335
91-dispatcher-status.tcl
asmaloney_ACT-R/environment/GUI/dialogs/91-dispatcher-status.tcl
proc make_dispatcher_status_viewer {} { if {[winfo exists .dispatcher] == 1} { wm deiconify .dispatcher raise .dispatcher } else { toplevel .dispatcher wm withdraw .dispatcher wm title .dispatcher "Connections Status" wm geometry .dispatcher [get_configuration .dispatcher] # frame and list box for names set list_frame_1 [frame .dispatcher.list_frame_1 -borderwidth 0] set list_box_1 [listbox $list_frame_1.list_box -listvar \ $list_frame_1.list_box.var \ -yscrollcommand "$list_frame_1.list_scrl set" \ -selectmode single \ -exportselection 0 -font list_font -bd 0] set list_scroll_bar_1 [scrollbar $list_frame_1.list_scrl -command "$list_box_1 yview"] # Frame and list box for commands set list_frame_2 [frame .dispatcher.list_frame -borderwidth 0] set list_box_2 [listbox $list_frame_2.list_box -listvar \ $list_frame_2.list_box.var \ -yscrollcommand "$list_frame_2.list_scrl set" \ -selectmode single \ -exportselection 0 -font list_font -bd 0] set list_scroll_bar_2 [scrollbar $list_frame_2.list_scrl -command "$list_box_2 yview"] # The lables for the sections set l1 [label .dispatcher.l1 -text "Address" -justify center -font label_font] set l2 [label .dispatcher.l2 -text "Pending" -justify center -font label_font] set l3 [label .dispatcher.l3 -text "Sent" -justify center -font label_font] set l4 [label .dispatcher.l4 -text "Received" -justify center -font label_font] set l5 [label .dispatcher.l5 -text "Commands" -justify center -font label_font] # the labels for the info set li0 [label .dispatcher.li0 -text "" -font label_font -justify center -textvariable .dispatcher.li0.value] set li1 [label .dispatcher.li1 -text "" -font label_font -justify center -textvariable .dispatcher.li1.value] set li2 [label .dispatcher.li2 -text "" -font label_font -justify center -textvariable .dispatcher.li2.value] # Label and text box to hold the doc strings when a command is clicked set d1 [label .dispatcher.d1 -text "Documentation:" -justify left -font label_font] set d2 [label .dispatcher.d2 -font text_font -text "" -textvar .dispatcher.d2.value -justify left -anchor nw] global .dispatcher.d2.value set .dispatcher.d2.value "" # make name selection update the other displays and create a global to # hold the data when the button is pressed global dispatcher_data set dispatcher_data "" global .dispatcher.li0.value global .dispatcher.li1.value global .dispatcher.li2.value .dispatcher.list_frame_1.list_box delete 0 end .dispatcher.list_frame.list_box delete 0 end set .dispatcher.li0.value "" set .dispatcher.li1.value "" set .dispatcher.li2.value "" set .dispatcher.d2.value "" bind $list_box_1 <<ListboxSelect>> "select_dispatcher_name" bind $list_box_2 <<ListboxSelect>> "select_command_name" bind $d2 <Configure> "resize_documentation %w" button .dispatcher.get -text "Get Status" -font button_font -command "get_dispatcher_status" bind $list_box_1 <Destroy> "global dispatcher_data unset dispatcher_data" pack $list_scroll_bar_1 -side right -fill y pack $list_box_1 -side left -expand 1 -fill both pack $list_scroll_bar_2 -side right -fill y pack $list_box_2 -side left -expand 1 -fill both place .dispatcher.get -relx 0 -y 0 -height 25 -relwidth .3 place $list_frame_1 -relx 0 -y 25 -relheight 1.0 -height -85 -relwidth .3 place $d1 -relx 0 -rely 1.0 -y -43 -height 25 -relwidth .3 place $l1 -relx .3 -y 0 -height 25 -relwidth .7 place $li0 -relx .3 -y 25 -height 25 -relwidth .7 place $l2 -relx .3 -y 50 -height 25 -relwidth .7 place $l4 -relx .3 -y 75 -height 25 -relwidth .35 place $l3 -relx .65 -y 75 -height 25 -relwidth .35 place $li1 -relx .3 -y 100 -height 25 -relwidth .35 place $li2 -relx .65 -y 100 -height 25 -relwidth .35 place $l5 -relx .3 -y 125 -height 25 -relwidth .7 place $list_frame_2 -relx .3 -y 150 -relheight 1.0 -height -210 -relwidth .7 place $d2 -relx .3 -rely 1.0 -y -60 -height 60 -relwidth .7 # now show the window wm deiconify .dispatcher focus .dispatcher return .dispatcher } } proc get_dispatcher_status {} { global dispatcher_data global .dispatcher.li0.value global .dispatcher.li1.value global .dispatcher.li2.value global .dispatcher.d2.value .dispatcher.list_frame_1.list_box delete 0 end .dispatcher.list_frame.list_box delete 0 end set .dispatcher.li0.value "" set .dispatcher.li1.value "" set .dispatcher.li2.value "" set .dispatcher.d2.value "" set dispatcher_data [lindex [send_cmd {list-connections} ""] 0] foreach i $dispatcher_data { .dispatcher.list_frame_1.list_box insert end [lindex $i 0] } } proc select_command_name {} { global .dispatcher.d2.value set .dispatcher.d2.value "" set selections [.dispatcher.list_frame.list_box curselection] if {[llength $selections] != 0} { set cmd [.dispatcher.list_frame.list_box get [lindex $selections 0]] set result [send_cmd "check" [list $cmd]] set w [expr "floor(.7 * [winfo width .dispatcher])"] .dispatcher.d2 configure -wraplength $w set .dispatcher.d2.value [lindex $result 2] } } proc resize_documentation {w} { .dispatcher.d2 configure -wraplength $w } proc select_dispatcher_name {} { global dispatcher_data global .dispatcher.li0.value global .dispatcher.li1.value global .dispatcher.li2.value global .dispatcher.d2.value .dispatcher.list_frame.list_box delete 0 end set .dispatcher.li0.value "" set .dispatcher.li1.value "" set .dispatcher.li2.value "" set .dispatcher.d2.value "" set selections [.dispatcher.list_frame_1.list_box curselection] if {[llength $selections] != 0} { set data [lindex $dispatcher_data [lindex $selections 0]] set .dispatcher.li0.value [lindex $data 1] set .dispatcher.li1.value [lindex $data 2] set .dispatcher.li2.value [lindex $data 3] foreach i [lindex $data 4] { .dispatcher.list_frame.list_box insert end $i } } } if {$tcl_platform(os) == "Darwin"} { button [control_panel_name].dispatcher_status -command make_dispatcher_status_viewer -text "Connections & Commands" -font button_font -justify center } else { button [control_panel_name].dispatcher_status -command make_dispatcher_status_viewer -text "Connections &\nCommands" -font button_font -justify center } pack [control_panel_name].dispatcher_status
6,837
Common Lisp
.cl
142
41.676056
152
0.684634
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
c8b78387c5af4b70741ed49afeef181e30721cd01b31088c4ba3ca641b12646c
14,335
[ -1 ]
14,336
67a-ptrace-button.tcl
asmaloney_ACT-R/environment/GUI/dialogs/67a-ptrace-button.tcl
proc select_ptrace {} { set model [currently_selected_model] if {$model == "nil"} { tk_messageBox -icon info -type ok -title "Production History" -message "Production history viewer requires a current model." } else { set win [toplevel [new_variable_name .ptrace]] global $win.scale global $win.grid_state global $win.c_height global $win.c_width global $win.label_offset global $win.data wm withdraw $win wm geometry $win [get_configuration .ptrace $win] record_new_window $win $win $model frame $win.frame -borderwidth 0 canvas $win.frame.canvas \ -xscrollcommand "$win.frame.scrlx set" \ -yscrollcommand "$win.frame.scrly set" \ -width 900 -height 300 -scrollregion {0 0 900 300} -bg white canvas $win.frame.canvas1 \ -yscrollcommand "$win.frame.scrly set" \ -width 150 -height 300 -scrollregion {0 0 150 300} -bg white scrollbar $win.frame.scrlx \ -command "$win.frame.canvas xview" -orient horizontal scrollbar $win.frame.scrly \ -command "scroll_ptraces_canvas $win" -orient vertical set $win.scale 1.0 label $win.notes -font text_font -textvariable $win.notesvar -anchor nw set $win.notesvar "" label $win.details -font text_font -textvariable $win.details -anchor nw set $win.details "" button $win.grid -command "p_trace_grid $win" -text "Grid" -font button_font button $win.zoom_in -command "p_trace_zoom_in $win" -text "+" -font button_font button $win.zoom_out -command "p_trace_zoom_out $win" -text "-" -font button_font button $win.save1 -command "save_phistory_trace $win" -text "Save .eps" -font button_font button $win.save2 -command "save_phistory_trace_multi $win" -text "Save .ps" -font button_font # Add a checkbox to allow removing the empty columns to the tool checkbutton $win.check \ -text "Hide empty columns" \ -font checkbox_font \ -variable $win.check_val \ -command "draw_p_trace $win $model {} 1" \ -onvalue 1 -offvalue 0 button $win.get -text "Get History" -font button_font -command "draw_p_trace $win $model" button $win.save -text "Save History" -font button_font -command "save_p_history_data $model" button $win.load -text "Load History" -font button_font -command "load_p_history_data $win $model" canvas $win.key -width 300 -height 30 global gui_options $win.key create text 50 15 -anchor center -font label_font -text "Selected" -fill #FFF -tag label $win.key create text 150 15 -anchor center -font label_font -text "Matched" -fill #FFF -tag label $win.key create text 250 15 -anchor center -font label_font -text "Mismatched" -fill #FFF -tag label $win.key create rectangle 0 0 99 30 -fill $gui_options(p_selected) -width 0 -tag p_selected $win.key create rectangle 100 0 199 30 -fill $gui_options(p_matched) -width 0 -tag p_matched $win.key create rectangle 200 0 299 30 -fill $gui_options(p_mismatched) -width 0 -tag p_mismatched $win.key bind all <ButtonPress> "change_p_history_color %x $win.key $win.frame.canvas" $win.key raise label call_act_r_command record-history $model [list "production-history"] global $win.value set $win.value "" bind $win.frame.canvas <Destroy> "call_act_r_command stop-recording-history $model [list {production-history}] global $win.value unset $win.value" set $win.grid_state 1 pack $win.frame.scrlx -side bottom -fill x pack $win.frame.scrly -side right -fill y pack $win.frame.canvas1 -side left -fill y pack $win.frame.canvas -side left -fill both place $win.frame -x 0 -y 0 -relwidth 1.0 -relheight 1.0 -height -105 place $win.key -x 0 -rely 1.0 -y -105 -height 30 -width 300 place $win.details -x 300 -rely 1.0 -y -105 -height 30 -relwidth 1.0 -width -300 place $win.notes -x 0 -rely 1.0 -y -75 -relwidth 1.0 -height 25 place $win.grid -x 0 -rely 1.0 -y -50 -width 60 -height 24 place $win.zoom_in -x 61 -rely 1.0 -y -50 -width 35 -height 24 place $win.zoom_out -x 97 -rely 1.0 -y -50 -width 35 -height 24 place $win.save1 -x 140 -rely 1.0 -y -50 -width 85 -height 24 place $win.save2 -x 226 -rely 1.0 -y -50 -width 85 -height 24 place $win.check -x 312 -rely 1.0 -y -50 -width 150 -height 24 place $win.get -relx .05 -rely 1.0 -y -25 -height 25 -relwidth .3 place $win.save -relx .35 -rely 1.0 -y -25 -height 25 -relwidth .3 place $win.load -relx .65 -rely 1.0 -y -25 -height 25 -relwidth .3 wm deiconify $win return $win } } proc change_p_history_color {x key display} { global gui_options if {$x < 100} { set index p_selected set label "Selected Production Color" } elseif {$x < 200} { set index p_matched set label "Matched Production Color" } else { set index p_mismatched set label "Mismatched Production Color" } set new [tk_chooseColor -title $label -initialcolor $gui_options($index)] if {$new != ""} { set gui_options($index) $new $key itemconfigure $index -fill $new $display itemconfigure $index -fill $new } } proc scroll_ptraces_canvas {win args} { set ignore "" eval [append ignore $win.frame.canvas " " yview " " $args] set ignore "" eval [append ignore $win.frame.canvas1 " " yview " " $args] } set p_history_warnings "" proc p_record_warnings {model s} { global p_history_warnings set p_history_warnings "$p_history_warnings$s" return "" } proc p_button_toggle {win state} { $win.grid configure -state $state $win.zoom_in configure -state $state $win.zoom_out configure -state $state $win.save1 configure -state $state $win.save2 configure -state $state $win.check configure -state $state } proc draw_p_trace {win model {file ""} {reuse 0}} { $win.frame.canvas delete all $win.frame.canvas1 delete all global $win.check_val global $win.details upvar #0 $win.check_val hide_empty upvar $win.notesvar display upvar #0 $win.value old_data global $win.scale global $win.grid_state global $win.c_height global $win.c_width global $win.label_offset upvar $win.scale scale upvar $win.grid_state grid upvar $win.c_height g_c_height upvar $win.c_width g_c_width upvar $win.label_offset label_offset set c_height 0 set c_width 0 set t_height 0 set t_width 0 set n_width 0 set x_display 0 p_button_toggle $win disabled if {$file == ""} { if {$reuse == 1} { set result $old_data } else { set any [call_act_r_command "history-data-available" $model [list "production-history"]] if {$any == ""} { set $win.details "No Data available" p_button_toggle $win normal return "" } else { set $win.details "Collecting Data ..." set id [call_act_r_command "start-incremental-history-data" $model [list "production-grid" 16000]] if {$id == ""} { set $win.details "No Data available" p_button_toggle $win normal return "" } else { set result [get_incremental_history $id] set $win.details "Data for model $model" } } } } else { global p_history_warnings set p_history_warnings "" set warning_monitor [add_new_cmd warning_monitor "p_record_warnings" "Environment command for capturing warnings during Load Production Grid."] send_cmd "monitor" [list "warning-trace" $warning_monitor] set $win.details "Loading Data from file $file" set id [call_act_r_command "start-incremental-history-data" $model [list "production-grid" 16000 $file]] send_cmd "remove-monitor" [list "warning-trace" $warning_monitor] remove_cmd $warning_monitor if {$id == "" || $id == "null"} { tk_messageBox -icon warning -type ok -title "Load Retrieval History problem" \ -message "Get-history-data returned failure result.\n$p_history_warnings." set $win.details "" p_button_toggle $win normal return "" } else { set comment [call_act_r_command "get-incremental-history-data" nil [list $id]] set result [get_incremental_history $id] set $win.details [json::json2dict [lindex $comment 0]] } } set old_data $result foreach x $result { switch [lindex $x 1] { info { set reasons [lindex $x 2] set c_height [expr [font metrics text_font -displayof $win.frame.canvas -linespace] + 3] set p_count [llength [lindex $x 3]] set c_count 0 foreach i $result { if {[lindex $i 1] == "conflict-resolution"} { if {$hide_empty == 0 || [lindex $i 2] == true} { incr c_count } } } set c_width 100 set t_height [expr $c_height * (1 + $p_count)] set t_width [expr $c_count * $c_width] set n_width 0 set names [list] foreach i [lindex $x 3] { set w [font measure text_font [lindex $i 0]] if {$w > $n_width} { set n_width $w } lappend names [lindex $i 0] } set n_width [expr $n_width + 10] set label_offset [expr -$n_width] $win.frame.canvas configure -width $t_width -height $t_height $win.frame.canvas1 configure -width $n_width -height $t_height $win.frame.canvas1 configure -scrollregion "0 0 $n_width $t_height" $win.frame.canvas configure -scrollregion "0 0 $t_width $t_height" set y $c_height foreach i [lindex $x 3] { set box_name [new_variable_name box] $win.frame.canvas create text [expr $label_offset + 5] $y -anchor nw -font text_font -text [lindex $i 0] $win.frame.canvas1 create text 5 $y -anchor nw -font text_font -text [lindex $i 0] -tag $box_name $win.frame.canvas1 create line 0 $y $n_width $y -width 1 -f gray $win.frame.canvas1 bind $box_name <ButtonPress> "p_history_p_view $win [lindex $i 0] {[lindex $i 1]}" incr y $c_height } } conflict-resolution { if {$hide_empty == 0 || [lindex $x 2] == true} { $win.frame.canvas create text [expr $x_display + ($c_width / 2)] 0 -anchor n -font graphic_trace_font -text [expr [lindex $x 0] / 1000.0 ] -tag zoom set y $c_height global gui_options set index 0 foreach i [lindex $x 3] { set box_name [new_variable_name box] switch [lindex $i 0] { 0 { $win.frame.canvas create rectangle $x_display $y [expr $x_display + $c_width] [expr $y + $c_height] -width 0 -fill $gui_options(p_selected) -tag [list $box_name zoom p_selected] $win.frame.canvas bind $box_name <Enter> "set $win.notesvar \"Utility: [lindex $i 1] U(n): [lindex $i 2]\"" $win.frame.canvas bind $box_name <ButtonPress> "p_history_whynot_view $win 0 [lindex $i 1] [lindex $i 2] [lindex $names $index] [lindex $x 0]" } 1 { $win.frame.canvas create rectangle $x_display $y [expr $x_display + $c_width] [expr $y + $c_height] -width 0 -fill $gui_options(p_matched) -tag [list $box_name zoom p_matched] $win.frame.canvas bind $box_name <Enter> "set $win.notesvar \"Utility: [lindex $i 1] U(n): [lindex $i 2]\"" $win.frame.canvas bind $box_name <ButtonPress> "p_history_whynot_view $win 1 [lindex $i 1] [lindex $i 2] [lindex $names $index] [lindex $x 0]" } 2 { $win.frame.canvas create rectangle $x_display $y [expr $x_display + $c_width] [expr $y + $c_height] -width 0 -fill $gui_options(p_mismatched) -tag [list $box_name zoom p_mismatched] $win.frame.canvas bind $box_name <Enter> "set $win.notesvar {Whynot: [lindex $reasons [lindex $i 1]]}" $win.frame.canvas bind $box_name <ButtonPress> "p_history_whynot_view $win 2 {[lindex $reasons [lindex $i 1]]} {} [lindex $names $index] [lindex $x 0]" } } $win.frame.canvas bind $box_name <Leave> "set $win.notesvar \"\"" incr y $c_height incr index } incr x_display $c_width } } } } for {set x 0} {$x < $t_width} {incr x $c_width} { $win.frame.canvas create line $x 0 $x $t_height -width 1 -f black -tag [list grid grid_vert zoom] } for {set y $c_height} {$y < $t_height} {incr y $c_height} { $win.frame.canvas create line 0 $y $t_width $y -width 1 -f black -tag [list grid zoom] } set scale 1.0 set grid black set g_c_height $c_height set g_c_width $c_width p_button_toggle $win normal } proc load_p_history_data {win model} { global top_dir set fname [tk_getOpenFile -title "Load Production History" -initialdir $top_dir] if {$fname != ""} { draw_p_trace $win $model $fname } } proc p_trace_zoom_out {win} { global $win.scale upvar $win.scale scale set scale [expr .5 * $scale] $win.frame.canvas scale zoom 0 0 0.5 1.0 $win.frame.canvas configure -width [expr .5 * [$win.frame.canvas cget -width]] $win.frame.canvas configure -scrollregion "0 0 [$win.frame.canvas cget -width] [$win.frame.canvas cget -height]" } proc p_trace_zoom_in {win} { global $win.scale upvar $win.scale scale if {$scale < 16} { set scale [expr 2 * $scale] $win.frame.canvas scale zoom 0 0 2.0 1.0 $win.frame.canvas configure -width [expr 2.0 * [$win.frame.canvas cget -width]] $win.frame.canvas configure -scrollregion "0 0 [$win.frame.canvas cget -width] [$win.frame.canvas cget -height]" } } proc p_trace_grid {win} { global $win.grid_state upvar $win.grid_state grid if {$grid == ""} { $win.frame.canvas itemconfigure grid -f black set grid black } elseif {$grid == "vert"} { $win.frame.canvas itemconfigure grid -f "" set grid "" } else { $win.frame.canvas itemconfigure grid_vert -f "" set grid vert } } proc p_history_p_view {win name text} { # make a new window set top [toplevel [new_variable_name ".p_history_p_view"]] wm geometry $top [get_configuration .p_history_p_view $top] wm title $top "[wm title $win] Production: $name" frame $top.frame -borderwidth 0 set text_box [text $top.frame.text -font text_font \ -yscrollcommand "$top.frame.scrl set" ] $text_box insert 0.0 $text $text_box configure -state disabled set scrl_bar [scrollbar $top.frame.scrl -command "$top.frame.text yview"] place $top.frame -x 0 -y 0 -relwidth 1.0 -relheight 1.0 pack $scrl_bar -side right -fill y pack $text_box -side left -expand 1 -fill both } proc p_history_whynot_view {win which t1 t2 name time} { # make a new window set top [toplevel [new_variable_name ".p_history_whynot_view"]] wm geometry $top [get_configuration .p_history_whynot_view $top] wm title $top "[wm title $win] Whynot Production: $name at time $time" frame $top.frame -borderwidth 0 set text_box [text $top.frame.text -font text_font \ -yscrollcommand "$top.frame.scrl set" ] switch $which { 0 { $text_box insert 0.0 "Production $name Was selected at time $time\nUtility: $t1 U(n): $t2" } 1 { $text_box insert 0.0 "Production $name matched but was not selected at time $time\nUtility: $t1 U(n): $t2" } 2 { $text_box insert 0.0 "Production $name did not match at time $time\nWhynot: $t1" } } $text_box configure -state disabled set scrl_bar [scrollbar $top.frame.scrl -command "$top.frame.text yview"] place $top.frame -x 0 -y 0 -relwidth 1.0 -relheight 1.0 pack $scrl_bar -side right -fill y pack $text_box -side left -expand 1 -fill both } proc save_p_history_data {model} { global top_dir set fname [tk_getSaveFile -title "Save Production History" -initialdir $top_dir] if {$fname != ""} { set any [call_act_r_command "history-data-available" $model [list "production-history"]] if {$any == "nil" || $any == ""} { tk_messageBox -icon warning -type ok -title "Save Production History warning" \ -message "No data available to save with current settings." } else { global p_history_warnings set p_history_warnings "" set warning_monitor [add_new_cmd warning_monitor "p_record_warnings" "Environment command for capturing warnings during Save Production History."] send_cmd "monitor" [list "warning-trace" $warning_monitor] set result [call_act_r_command_with_error_messages "save-history-data" $model [list "production-history" $fname "Data saved from Production History window for model $model"]] send_cmd "remove-monitor" [list "warning-trace" $warning_monitor] remove_cmd $warning_monitor if {[lindex $result 0] == 0} { tk_messageBox -icon warning -type ok -title "Save Production History error" \ -message "Get-history-data resulted in error.\n[lindex $result 1]." } elseif {[lindex $result 1] == "null"} { tk_messageBox -icon warning -type ok -title "Save Production History problem" \ -message "Get-history-data returned failure result.\n$p_history_warnings." } } } } proc save_phistory_trace {win} { set fname [tk_getSaveFile -title "Save production history as" -filetypes {{"Encapsulated PostScript" "*.eps"}}] global $win.label_offset upvar $win.label_offset label_offset if {$fname != ""} { $win.frame.canvas postscript -file $fname -width [expr -$label_offset + [$win.frame.canvas cget -width]] -height [$win.frame.canvas cget -height] -x $label_offset -y 0 -pageanchor nw -pagex 0.0 -pagey [$win.frame.canvas cget -height] -pagewidth [expr -$label_offset + [$win.frame.canvas cget -width]] } } proc save_phistory_trace_multi {win} { global $win.label_offset upvar $win.label_offset label_offset save_multi_page_image $win "Save production history as" $label_offset } proc save_multi_page_image {win prompt {x_offset 0}} { set fname [tk_getSaveFile -title $prompt -filetypes {{"PostScript" "*.ps"}}] if {$fname != ""} { set width 1400.0 set height 400 set xMax [expr -$x_offset + [$win.frame.canvas cget -width]] set NOP [expr ceil ($xMax / $width)] # The following code was modified from code written by Robert Heller # in a file called bridge.tcl which was posted to comp.lang.tcl as # an example of producing multi-page ps files. set prFile [open $fname w] puts $prFile "%!PS-Adobe-2.0" puts $prFile "%%Creator: ACT-R Environment Copyright 2011 Dan Bothell" puts $prFile "%%Title: Production History Chart" puts -nonewline $prFile "%%CreationDate: " global tcl_version if {$tcl_version >= 7.6} { puts $prFile "[clock format [clock seconds]]" } else { puts $prFile "[exec date]" } puts $prFile "%%Pages: $NOP $xMax $width [expr ceil($xMax / $width)]" puts $prFile "%%EndComments" puts $prFile "/EncapDict 200 dict def EncapDict begin" puts $prFile "/showpage {} def /erasepage {} def /copypage {} def end" puts $prFile "/BeginInclude {0 setgray 0 setlinecap 1 setlinewidth" puts $prFile "0 setlinejoin 10 setmiterlimit \[\] 0 setdash" puts $prFile "/languagelevel where {" puts $prFile " pop" puts $prFile " languagelevel 2 ge {" puts $prFile " false setoverprint" puts $prFile " false setstrokeadjust" puts $prFile " } if" puts $prFile "} if" puts $prFile "newpath" puts $prFile "save EncapDict begin} def" puts $prFile "/EndInclude {restore end} def" puts $prFile "%%EndProlog" set pageNo 1 for {set xoff 0} {$xoff < $xMax} {set xoff [expr $xoff + $width]} { puts $prFile "%%Page: $pageNo $pageNo" puts $prFile "BeginInclude" # this one works set eps "[$win.frame.canvas postscript -height $height -width $width -x [expr $xoff - 150] -y 0 -pageanchor nw -pagex 0.25i -pagey 7.5i -pagewidth 8.0i]" set eps "[$win.frame.canvas postscript -height $height -width $width -x [expr $xoff + $x_offset] -y 0 -pageanchor nw -pagex 2.0i -pagey 0.5i -pagewidth 10.0i -rotate 1]" set EOC [string first "%%BeginProlog\n" "$eps"] set EOF [expr [string first "%%EOF\n" "$eps"] - 1] puts $prFile "[StripPSComments [string range $eps $EOC $EOF]]" puts $prFile "EndInclude showpage" incr pageNo } puts $prFile "%%EOF" close $prFile } } proc StripPSComments {PSString} { set result {} foreach l [split "$PSString" "\n"] { set i [string first "%" "$l$"] if {$i == 0} { set result "$result\n" } elseif {$i > 0 && [regexp {(^.*[^\\])(%.*$)} "$l" whole prefix comment]} { set result "$result$prefix\n" } else { set result "$result$l\n" } } return "$result" } add_p_history_type "grid" select_ptrace
21,336
Common Lisp
.cl
468
38.613248
305
0.640943
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
ea25f9d441117dabe00ce3a1a3693cff465aed9f89743a943a917a648c5bd32d
14,336
[ -1 ]
14,337
67-p-history-button.tcl
asmaloney_ACT-R/environment/GUI/dialogs/67-p-history-button.tcl
set p_history_table [dict create] frame [control_panel_name].p_history_display -borderwidth 0 button [control_panel_name].p_history_display.show_trace -command p_history_trace -text "Production" -font button_font tk_optionMenu [control_panel_name].p_history_display.which_trace current_p_history_trace "" [control_panel_name].p_history_display.which_trace configure -font checkbox_font [[control_panel_name].p_history_display.which_trace cget -menu] configure -font checkbox_font pack [control_panel_name].p_history_display.which_trace -side right pack [control_panel_name].p_history_display.show_trace -side left pack [control_panel_name].p_history_display proc p_history_trace {} { global current_p_history_trace global p_history_table if [dict exists $p_history_table $current_p_history_trace] { set cmd [dict get $p_history_table $current_p_history_trace] $cmd } else { tk_messageBox -title "No production history" -message "No production history type selected." -icon warning -type ok } } proc add_p_history_type {title cmd} { global current_p_history_trace global p_history_table set menu [[control_panel_name].p_history_display.which_trace cget -menu] set top [$menu entrycget 0 -value] $menu add radiobutton -label $title -variable current_p_history_trace if {$top == ""} { $menu delete "" set current_p_history_trace $title } dict set p_history_table $title $cmd }
1,445
Common Lisp
.cl
31
43.322581
119
0.757554
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
dccac1095050da7606ca655a67dfb09564106894c6f6d3106aeb127e49e23ec8
14,337
[ -1 ]
14,338
63a-blending-history.tcl
asmaloney_ACT-R/environment/GUI/dialogs/63a-blending-history.tcl
proc make_blending_history_viewer {} { set model [currently_selected_model] if {$model == "nil"} { tk_messageBox -icon info -type ok -title "Blending History" -message "Blending history viewer requires a current model." } else { set win [toplevel [new_variable_name .blending_history]] wm withdraw $win record_new_window $win $win $model wm geometry $win [get_configuration .blending_history $win] # frame and list box for times set list_frame_1 [frame $win.list_frame_1 -borderwidth 0] set list_box_1 [listbox $list_frame_1.list_box -listvar \ $list_frame_1.list_box.var \ -yscrollcommand "$list_frame_1.list_scrl set" \ -selectmode single \ -exportselection 0 -font list_font -bd 0] set list_scroll_bar_1 [scrollbar $list_frame_1.list_scrl -command "$list_box_1 yview"] # Frame and list box for chunks set list_frame_2 [frame $win.list_frame -borderwidth 0] set list_box_2 [listbox $list_frame_2.list_box -listvar \ $list_frame_2.list_box.var \ -yscrollcommand "$list_frame_2.list_scrl set" \ -selectmode single \ -exportselection 0 -font list_font -bd 0] set list_scroll_bar_2 [scrollbar $list_frame_2.list_scrl -command "$list_box_2 yview"] # The lables for the sections set l1 [label $win.l1 -text "Times" -justify left -font label_font] set l2 [label $win.l2 -text "Blended Chunks" -justify left -font label_font] set l3 [label $win.l3 -text "Chunk" -justify left -font label_font] set l4 [label $win.l4 -text "Request" -justify left -font label_font] set l5 [label $win.l5 -text "Trace" -justify left -font label_font] set l6 [label $win.l6 -text "Result" -justify left -font label_font] set l0 [label $win.l0 -text "" -font label_font -textvariable $win.l0.value] # frame for the chunk display set text_frame_1 [frame $win.text_frame_1 -borderwidth 0] set text_box_1 [text $text_frame_1.text -yscrollcommand \ "$text_frame_1.text_scrl set" \ -xscrollcommand "$text_frame_1.text_scrl_x set" \ -font text_font -wrap none] # create the scroll bar for the text box set text_scroll_bar_1 [scrollbar $text_frame_1.text_scrl -command "$text_box_1 yview"] set text_scroll_bar_1a [scrollbar $text_frame_1.text_scrl_x -command "$text_box_1 xview" -orient horizontal] # frame for the request display set text_frame_2 [frame $win.text_frame_2 -borderwidth 0] set text_box_2 [text $text_frame_2.text -yscrollcommand \ "$text_frame_2.text_scrl set" \ -xscrollcommand "$text_frame_2.text_scrl_x set" \ -font text_font] # create the scroll bar for the text box set text_scroll_bar_2 [scrollbar $text_frame_2.text_scrl -command "$text_box_2 yview"] set text_scroll_bar_2a [scrollbar $text_frame_2.text_scrl_x -command "$text_box_2 xview" -orient horizontal] # frame for the activation display set text_frame_3 [frame $win.text_frame_3 -borderwidth 0] set text_box_3 [text $text_frame_3.text -yscrollcommand \ "$text_frame_3.text_scrl set" \ -xscrollcommand "$text_frame_3.text_scrl_x set" \ -font text_font -wrap none] # create the scroll bar for the text box set text_scroll_bar_3 [scrollbar $text_frame_3.text_scrl -command "$text_box_3 yview"] set text_scroll_bar_3a [scrollbar $text_frame_3.text_scrl_x -command "$text_box_3 xview" -orient horizontal] # frame for the result display set text_frame_4 [frame $win.text_frame_4 -borderwidth 0] set text_box_4 [text $text_frame_4.text -yscrollcommand \ "$text_frame_4.text_scrl set" \ -xscrollcommand "$text_frame_4.text_scrl_x set" \ -font text_font -wrap none] # create the scroll bar for the text box set text_scroll_bar_4 [scrollbar $text_frame_4.text_scrl -command "$text_box_4 yview"] set text_scroll_bar_4a [scrollbar $text_frame_4.text_scrl_x -command "$text_box_4 xview" -orient horizontal] # make chunk selection update the other displays global $win.value set $win.value "" global $win.value2 set $win.value2 "" bind $list_box_1 <<ListboxSelect>> "select_blend_history_time $list_box_1 $list_box_2 $text_box_1 $text_box_2 $text_box_3 $text_box_4 $win.value $win.value2" bind $list_box_2 <<ListboxSelect>> "select_blend_history_chunk $list_box_2 $text_box_1 $win.value2" button $win.get -text "Get History" -font button_font -command "get_blend_history $list_box_1 $list_box_2 $text_box_1 $text_box_2 $text_box_3 $text_box_4 $win.l0.value $model $win.value" button $win.save -text "Save History" -font button_font -command "save_blend_history_data $model" button $win.load -text "Load History" -font button_font -command "load_blend_history_data $list_box_1 $list_box_2 $text_box_1 $text_box_2 $text_box_3 $text_box_4 $win.l0.value $model $win.value" call_act_r_command record-history $model [list "blending-trace"] bind $text_box_1 <Destroy> "call_act_r_command stop-recording-history $model [list blending-trace] global $win.value unset $win.value global $win.value2 unset $win.value2" pack $list_scroll_bar_1 -side right -fill y pack $list_box_1 -side left -expand 1 -fill both pack $list_scroll_bar_2 -side right -fill y pack $list_box_2 -side left -expand 1 -fill both pack $text_scroll_bar_1 -side right -fill y pack $text_scroll_bar_1a -side bottom -fill x pack $text_box_1 -side left -expand 1 -fill both pack $text_scroll_bar_2 -side right -fill y pack $text_scroll_bar_2a -side bottom -fill x pack $text_box_2 -side left -expand 1 -fill both pack $text_scroll_bar_3 -side right -fill y pack $text_scroll_bar_3a -side bottom -fill x pack $text_box_3 -side left -expand 1 -fill both pack $text_scroll_bar_4 -side right -fill y pack $text_scroll_bar_4a -side bottom -fill x pack $text_box_4 -side left -expand 1 -fill both place $l0 -relx 0 -y 0 -height 25 -relwidth 1.0 place $l1 -relx 0.0 -y 25 -height 25 -relwidth .15 place $list_frame_1 -relx 0.0 -y 50 -relheight .6 -height -50 -relwidth .15 place $l4 -relx .15 -y 25 -height 25 -relwidth .3 place $text_frame_2 -relx .15 -y 50 -relheight .3 -height -50 -relwidth .3 place $l6 -relx .15 -rely .3 -height 25 -relwidth .3 place $text_frame_4 -relx .15 -rely .3 -y 25 -relheight .3 -height -25 -relwidth .30 place $l2 -relx .45 -y 25 -height 25 -relwidth .20 place $list_frame_2 -relx .45 -y 50 -relheight .6 -height -50 -relwidth .20 place $l3 -relx .65 -y 25 -height 25 -relwidth .35 place $text_frame_1 -relx .65 -y 50 -relheight .6 -height -50 -relwidth .35 place $l5 -relx .0 -rely .6 -height 25 -relwidth 1.0 place $text_frame_3 -relx .0 -rely .6 -y 25 -relheight .4 -height -50 -relwidth 1.0 place $win.get -relx .05 -rely 1.0 -y -25 -height 25 -relwidth .3 place $win.save -relx .35 -rely 1.0 -y -25 -height 25 -relwidth .3 place $win.load -relx .65 -rely 1.0 -y -25 -height 25 -relwidth .3 # now show the window wm deiconify $win focus $win return $win } } proc get_blend_history {lb1 lb2 tb1 tb2 tb3 tb4 label model data_var} { global $label $lb1 delete 0 end $lb2 delete 0 end $tb1 delete 1.0 end $tb2 delete 1.0 end $tb3 delete 1.0 end $tb4 delete 1.0 end set any [call_act_r_command "history-data-available" $model [list "blending-trace"]] if {$any == ""} { set $label "No Data available" } else { set $label "Collecting Data ..." set id [call_act_r_command "start-incremental-history-data" $model [list "blending-environment-history" 16000 false]] if {$id != ""} { set result [get_incremental_history $id] } else { tk_messageBox -icon warning -type ok -title "Get Blending History warning" \ -message "Unknown problem occurred trying to get data." set $label "Data Error occurred" return "" } global $data_var unset $data_var upvar $data_var data foreach i $result { set time [expr [lindex $i 0] / 1000.0 ] $lb1 insert end $time set data($time) [lrange $i 1 end] } set $label "Blending History Data for model $model" } } proc blend_record_warnings {model s} { global blend_history_warnings set blend_history_warnings "$blend_history_warnings$s" return "" } proc load_blend_history_data {lb1 lb2 tb1 tb2 tb3 tb4 label model data_var} { global top_dir global $label set fname [tk_getOpenFile -title "Load Blending History" -initialdir $top_dir] if {$fname != ""} { set $label "" $lb1 delete 0 end $lb2 delete 0 end $tb1 delete 1.0 end $tb2 delete 1.0 end $tb3 delete 1.0 end $tb4 delete 1.0 end global blend_history_warnings set blend_history_warnings "" set warning_monitor [add_new_cmd warning_monitor "blend_record_warnings" "Environment command for capturing warnings during Load Blending History."] send_cmd "monitor" [list "warning-trace" $warning_monitor] set id [call_act_r_command "start-incremental-history-data" $model [list "blending-environment-history" 16000 $fname]] send_cmd "remove-monitor" [list "warning-trace" $warning_monitor] remove_cmd $warning_monitor if {$id == "" || $id == "null"} { tk_messageBox -icon warning -type ok -title "Load Blending History problem" \ -message "Get-history-data returned failure result.\n$blend_history_warnings." set $label "Failure to load data" } else { set comment [call_act_r_command "get-incremental-history-data" nil [list $id]] set result [get_incremental_history $id] global $data_var unset $data_var upvar $data_var data foreach i $result { set time [expr [lindex $i 0] / 1000.0 ] $lb1 insert end $time set data($time) [lrange $i 1 end] } set $label [json::json2dict [lindex $comment 0]] } } } proc save_blend_history_data {model} { global top_dir set fname [tk_getSaveFile -title "Save Blending History" -initialdir $top_dir] if {$fname != ""} { set any [call_act_r_command "history-data-available" $model [list "blending-trace"]] if {$any == "nil" || $any == ""} { tk_messageBox -icon warning -type ok -title "Save Blending History warning" \ -message "No data available to save with current settings." } else { global blend_history_warnings set blend_history_warnings "" set warning_monitor [add_new_cmd warning_monitor "blend_record_warnings" "Environment command for capturing warnings during Save Blending History."] send_cmd "monitor" [list "warning-trace" $warning_monitor] set result [call_act_r_command_with_error_messages "save-history-data" $model [list "blending-environment-history" $fname "Data saved from Blending History window for model $model"]] send_cmd "remove-monitor" [list "warning-trace" $warning_monitor] remove_cmd $warning_monitor if {[lindex $result 0] == 0} { tk_messageBox -icon warning -type ok -title "Save Blending History error" \ -message "Save-history-data resulted in error.\n[lindex $result 1]." } elseif {[lindex $result 1] == "null"} { tk_messageBox -icon warning -type ok -title "Save Blending History problem" \ -message "Save-history-data returned failure result.\n$blend_history_warnings." } } } } proc select_blend_history_time {lb1 lb2 tb1 tb2 tb3 tb4 data_var data_var2} { $lb2 delete 0 end $tb1 delete 1.0 end $tb2 delete 1.0 end $tb3 delete 1.0 end $tb4 delete 1.0 end set selections [$lb1 curselection] if {[llength $selections] != 0} { set time [$lb1 get [lindex $selections 0]] upvar $data_var data set vals $data($time) $tb2 insert end "+blending>\n[lindex $vals 0]" $tb4 insert end [lindex $vals 1] $tb3 insert end [lindex $vals 3] global $data_var2 unset $data_var2 upvar $data_var2 data2 foreach i [lindex $vals 2] { set name [lindex $i 0] $lb2 insert end $name set data2($name) [lrange $i 1 end] } } } proc select_blend_history_chunk {lb2 tb1 data_var2} { $tb1 delete 1.0 end set selections [$lb2 curselection] if {[llength $selections] != 0} { set name [$lb2 get [lindex $selections 0]] upvar $data_var2 data set vals $data($name) $tb1 insert end "Activation: [lindex $vals 0]\n\n" $tb1 insert end [lindex $vals 1] } } set check_blending [lindex [call_act_r_command "sorted-module-names" "nil"] 0] if {[lsearch -regexp $check_blending (?i)^blending$] != -1} { button [control_panel_name].blending_history -command make_blending_history_viewer -text "Blending History" -font button_font pack [control_panel_name].blending_history }
13,605
Common Lisp
.cl
265
43.075472
198
0.646681
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
5665e03bb76f300e06beae39615d2d314d20d06253337a2f98481e33cae79e44
14,338
[ -1 ]
14,339
999-image-item.tcl
asmaloney_ACT-R/environment/GUI/dialogs/999-image-item.tcl
# This file is an extension for the ACT-R Environment to actually # display .gif files as images in the visible-virtual-windows # using the image-vdi objects created in the tools/image-feature.lisp # file. # # All of the .gif files to display must be available in the # gui/AGI-images directory. # # Mouse clicks on the item will be handled in the virtual # view on the Lisp side just like they would if the window # were not shown even if a person clicks on it (the window # sends all clicks back to Lisp where they get processed). # The code below adds agi handlers that perform the necessary # changes to cleanly provide the image items using the new # visible-virtual extension mechanism with add_agi_handler. # # When the window closes delete the images to save mem. proc agi_image_close_handler {cmd win coords params} { foreach i [$win.can find withtag image] { $win.can dtag $i image set name [lindex [$win.can gettags $i] 0] image delete $name } } add_agi_handler close agi_image_close_handler # When the window is cleared remove the image items proc agi_image_clear_handler {cmd win coords params} { $win.can delete image } add_agi_handler clear agi_image_clear_handler # When an item is removed delete it to save mem. proc agi_image_remove_handler {cmd win coords params} { set tags [$win.can gettags [lindex $params 0]] set tindex [lsearch -exact $tags image] if {$tindex != -1} { image delete [lindex $params 0] } } add_agi_handler remove agi_image_remove_handler # When an image cmd is sent read the file from the images # directory in gui and add it to the window's canvas. # The params sent are: item_name x y file_name width height proc agi_image_creation_handler {cmd win coords params} { global tcl_env_dir # Assume that it exists to keep the example simple. image create photo [lindex $params 0] -file [file join $tcl_env_dir "AGI-images" [lindex $params 3]] -width [lindex $params 4] -height [lindex $params 5] # Place that image into the display. Again, this is kept simple for an example, but it # should probably actually first create a 'dummy' image and subsample or zoom to fit # the width and height specified instead of just clipping the image. $win.can create image [lindex $params 1] [lindex $params 2] -anchor nw -image [lindex $params 0] -tags [list [lindex $params 0] image] } add_agi_handler image agi_image_creation_handler
2,541
Common Lisp
.cl
52
44.403846
155
0.752857
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
b0d89456583988dc2f6f418ff55795ead8f03d37d87ecc214d286020ef46f35a
14,339
[ -1 ]
14,340
72a-ctrl-panel-gt-horizontal.tcl
asmaloney_ACT-R/environment/GUI/dialogs/72a-ctrl-panel-gt-horizontal.tcl
proc select_graphic_trace {} { set model [currently_selected_model] if {$model == "nil"} { tk_messageBox -icon info -type ok -title "Graphic Trace" -message "Graphic trace viewer requires a current model." } else { set win [toplevel [new_variable_name .graphic_trace]] global $win.scale wm withdraw $win wm geometry $win [get_configuration .graphic_trace $win] record_new_window $win $win $model call_act_r_command "record-history" $model [list "buffer-trace"] frame $win.frame -borderwidth 0 canvas $win.frame.canvas \ -xscrollcommand "$win.frame.scrl set" \ -width 2000 -height 400 -scrollregion {-4 0 2000 400} -bg white scrollbar $win.frame.scrl \ -command "$win.frame.canvas xview" -orient horizontal set $win.scale 1.0 bind $win.frame.canvas <Destroy> " call_act_r_command stop-recording-history $model [list buffer-trace] global $win.scale unset $win.scale " canvas $win.canvas1 -width 150 -height 400 -bg white label $win.details -font label_font label $win.time_label -font label_font -text "Time:" label $win.time -font text_font label $win.duration_label -font label_font -text "Duration:" label $win.duration -font text_font label $win.notes_label -font label_font -text "Notes:" label $win.notes -font text_font -anchor nw label $win.request_label -font label_font -text "Request:" label $win.request -font text_font -anchor nw label $win.chunk_label -font label_font -text "Chunk:" label $win.chunk -font text_font -anchor nw frame $win.buttons -borderwidth 0 button $win.buttons.zoom_in -command "horiz_zoom_in $win" -text "+" -font button_font button $win.buttons.zoom_out -command "horiz_zoom_out $win" -text "-" -font button_font checkbutton $win.buttons.ht \ -text "Hide text" \ -font checkbox_font \ -variable $win.ht \ -command "configure_h_trace_text $win" \ -onvalue 1 -offvalue 0 checkbutton $win.buttons.hg \ -text "Hide grid" \ -font checkbox_font \ -variable $win.hg \ -command "draw_h_grid $win" \ -onvalue 1 -offvalue 0 button $win.buttons.save1 -command "save_horiz_graphic_trace $win" -text "Save .eps" -font button_font button $win.buttons.save2 -command "save_horiz_graphic_trace_multi $win" -text "Save .ps" -font button_font button $win.get -text "Get History" -font button_font -command "get_h_graph_data $win $model" button $win.save -text "Save History" -font button_font -command "save_h_graph_history_data $model" button $win.load -text "Load History" -font button_font -command "load_h_graph_history_data $win $model" pack $win.frame.scrl -side bottom -fill x pack $win.frame.canvas -side top -fill both place $win.canvas1 -x 0 -y 0 -width 150 -relheight 1.0 -height -175 place $win.frame -x 150 -y 0 -relwidth 1.0 -width -150 -relheight 1.0 -height -175 place $win.details -x 0 -rely 1.0 -y -175 -height 24 -relwidth 1.0 place $win.request_label -x 0 -rely 1.0 -y -150 -width 70 -height 24 place $win.request -x 71 -rely 1.0 -y -150 -relwidth 1.0 -width -70 -height 24 place $win.chunk_label -x 0 -rely 1.0 -y -125 -width 70 -height 24 place $win.chunk -x 71 -rely 1.0 -y -125 -relwidth 1.0 -width -70 -height 24 place $win.notes_label -x 0 -rely 1.0 -y -100 -width 70 -height 24 place $win.notes -x 71 -rely 1.0 -y -100 -relwidth 1.0 -width -70 -height 24 place $win.time_label -x 0 -rely 1.0 -y -75 -width 70 -height 24 place $win.time -x 71 -rely 1.0 -y -75 -relwidth 0.5 -width -70 -height 24 place $win.duration_label -relx 0.5 -rely 1.0 -y -75 -width 70 -height 24 place $win.duration -relx 0.5 -x 71 -rely 1.0 -y -75 -relwidth 0.5 -width -70 -height 24 place $win.buttons.zoom_in -x 0 -y 0 -width 59 -height 24 place $win.buttons.zoom_out -x 60 -y 0 -width 59 -height 24 place $win.buttons.ht -x 320 -y 0 -width 99 -height 24 place $win.buttons.hg -x 420 -y 0 -width 99 -height 24 place $win.buttons.save1 -x 140 -y 0 -width 79 -height 24 place $win.buttons.save2 -x 220 -y 0 -width 79 -height 24 place $win.buttons -x 0 -rely 1.0 -y -50 -width 525 -height 25 place $win.get -relx .05 -rely 1.0 -y -25 -height 25 -relwidth .3 place $win.save -relx .35 -rely 1.0 -y -25 -height 25 -relwidth .3 place $win.load -relx .65 -rely 1.0 -y -25 -height 25 -relwidth .3 # now show the window $win.frame.canvas xview moveto 0 wm deiconify $win pick_buffers return $win } } proc horiz_zoom_out {win} { upvar #0 $win.scale scale set scale [expr .5 * $scale] $win.frame.canvas scale trace_items 0 0 0.5 1.0 $win.frame.canvas configure -scrollregion "-4 0 [expr .5 * [lindex [$win.frame.canvas cget -scrollregion] 2]] 400" $win.frame.canvas configure -width [expr .5 * [$win.frame.canvas cget -width]] foreach x [$win.frame.canvas find withtag trace_text] { $win.frame.canvas itemconfigure $x -width [expr .5 * [$win.frame.canvas itemcget $x -width]] } } proc horiz_zoom_in {win} { upvar #0 $win.scale scale if {$scale < 16} { set scale [expr 2 * $scale] $win.frame.canvas scale trace_items 0 0 2.0 1.0 $win.frame.canvas configure -scrollregion "-4 0 [expr 2 * [lindex [$win.frame.canvas cget -scrollregion] 2]] 400" $win.frame.canvas configure -width [expr 2 * [$win.frame.canvas cget -width]] foreach x [$win.frame.canvas find withtag trace_text] { $win.frame.canvas itemconfigure $x -width [expr 2 * [$win.frame.canvas itemcget $x -width]] } } } proc get_h_graph_data {win model} { draw_horiz_items $win $model "" } proc load_h_graph_history_data {win model} { global top_dir set fname [tk_getOpenFile -title "Load Production History" -initialdir $top_dir] if {$fname != ""} { draw_horiz_items $win $model $fname } } set h_graph_history_warnings "" proc h_graph_record_warnings {model s} { global h_graph_history_warnings set h_graph_history_warnings "$h_graph_history_warnings$s" return "" } proc save_h_graph_history_data {model} { global top_dir set fname [tk_getSaveFile -title "Save Graphic Trace Data" -initialdir $top_dir] if {$fname != ""} { set any [call_act_r_command "history-data-available" $model [list "buffer-trace"]] if {$any == "nil" || $any == ""} { tk_messageBox -icon warning -type ok -title "Save Graphic Trace warning" \ -message "No data available to save with current settings." } else { global h_graph_history_warnings set h_graph_history_warnings "" set warning_monitor [add_new_cmd warning_monitor "h_graph_record_warnings" "Environment command for capturing warnings during Save Horizontal Graphic trace."] send_cmd "monitor" [list "warning-trace" $warning_monitor] set result [call_act_r_command_with_error_messages "save-history-data" $model [list "buffer-trace" $fname "Data saved from Graphic Trace window for model $model"]] send_cmd "remove-monitor" [list "warning-trace" $warning_monitor] remove_cmd $warning_monitor if {[lindex $result 0] == 0} { tk_messageBox -icon warning -type ok -title "Save Graphic Trace error" \ -message "Save-history-data resulted in error.\n[lindex $result 1]." } elseif {[lindex $result 1] == "null"} { tk_messageBox -icon warning -type ok -title "Save Graphic Trace problem" \ -message "Save-history-data returned failure result.\n$h_graph_history_warnings." } } } } proc draw_h_grid {win} { upvar #0 $win.hg hide upvar #0 $win.scale scale if {$hide == 0} { set max [$win.frame.canvas cget -width] set x 0 while {$x <= $max} { set x_pos [expr $x * $scale] $win.frame.canvas create line $x_pos 0 $x_pos 400 -width 1 -f gray -tag [list grid trace_items] $win.frame.canvas create text $x_pos 400 -text [format "%.3f" [expr 0.001 * $x]] -anchor sw -font graphic_trace_font -tag [list grid trace_items] incr x 50 } $win.frame.canvas lower grid } else { $win.frame.canvas delete grid } } proc configure_h_trace_text {win} { upvar #0 $win.ht hide if {[$win.frame.canvas find withtag trace_text] != ""} { if {$hide == 0} { $win.frame.canvas itemconfigure trace_text -fill black $win.frame.canvas raise trace_text boxes } else { $win.frame.canvas itemconfigure trace_text -fill white $win.frame.canvas lower trace_text all } } } set h_graphic_trace_color_list [list #ff0000 #8080ff #008000 #ff8000 #7f7f7f #ff00ff #ffff00 #c08000 #f0f0f0 #c000c0 #00c050 #f0c0ff #c05850 #50ff25] proc draw_horiz_items {win model fname} { $win.buttons.zoom_in configure -state disabled $win.buttons.zoom_out configure -state disabled $win.buttons.ht configure -state disabled $win.buttons.hg configure -state disabled $win.buttons.save1 configure -state disabled $win.buttons.save2 configure -state disabled $win.get configure -state disabled $win.save configure -state disabled $win.load configure -state disabled $win.frame.canvas delete all $win.canvas1 delete all $win.details configure -text "" $win.request configure -text "" $win.chunk configure -text "" $win.notes configure -text "" $win.time configure -text "" $win.duration configure -text "" if {$fname == ""} { set any [call_act_r_command "history-data-available" $model [list "buffer-trace"]] if {$any == "nil" || $any == ""} { $win.details configure -text "No Data available" set data [list "nothing"] } else { $win.details configure -text "Collecting Data ..." set id [call_act_r_command "start-incremental-history-data" $model [list "horizontal-graphic-trace" 16000]] if {$id != ""} { set data [get_incremental_history $id] } else { tk_messageBox -icon warning -type ok -title "Get Graphic trace History warning" \ -message "Unknown problem occurred trying to get data." $win.details configure -text "Data Error occurred" $win.buttons.zoom_in configure -state normal $win.buttons.zoom_out configure -state normal $win.buttons.ht configure -state normal $win.buttons.hg configure -state normal $win.buttons.save1 configure -state normal $win.buttons.save2 configure -state normal $win.get configure -state normal $win.save configure -state normal $win.load configure -state normal return "" } $win.details configure -text "Graphic Trace data for model $model" } } else { global h_graph_history_warnings set h_graph_history_warnings "" set warning_monitor [add_new_cmd warning_monitor "h_graph_record_warnings" "Environment command for capturing warnings during Load Horizontal Graphic Trace."] send_cmd "monitor" [list "warning-trace" $warning_monitor] $win.details configure -text "Loading Data from file $fname" set id [call_act_r_command "start-incremental-history-data" $model [list "horizontal-graphic-trace" 16000 $fname]] send_cmd "remove-monitor" [list "warning-trace" $warning_monitor] remove_cmd $warning_monitor if {$id == "" || $id == "null"} { tk_messageBox -icon warning -type ok -title "Load Graph Trace problem" \ -message "Get-history-data returned failure result.\n$h_graph_history_warnings." $win.details configure -text "Failure to load data" $win.buttons.zoom_in configure -state normal $win.buttons.zoom_out configure -state normal $win.buttons.ht configure -state normal $win.buttons.hg configure -state normal $win.buttons.save1 configure -state normal $win.buttons.save2 configure -state normal $win.get configure -state normal $win.save configure -state normal $win.load configure -state normal return "" } else { set comment [call_act_r_command "get-incremental-history-data" nil [list $id]] set comment "[json::json2dict [lindex $comment 0]] loaded from file $fname" set data [get_incremental_history $id] } } set size [lindex $data 0] upvar #0 $win.scale scale set scale 1.0 if {[lindex $size 0] == "size"} { set max [lindex $size 1] $win.frame.canvas configure -width [expr $max + 5] $win.frame.canvas configure -scrollregion "-4 0 [expr 1 + $max] 400" draw_h_grid $win } else { # should have more error checking... } global h_graphic_trace_color_list foreach x [lrange $data 1 end] { switch [lindex $x 0] { label { $win.frame.canvas create text -145 [lindex $x 2] -anchor w -font text_font -justify right -text [lindex $x 1] -width 140 -fill [lindex $h_graphic_trace_color_list [lindex $x 3]] $win.canvas1 create text 5 [lindex $x 2] -anchor w -font text_font -justify right -text [lindex $x 1] -width 140 -tag label_tag -fill [lindex $h_graphic_trace_color_list [lindex $x 3]] } rectangle { set box_name [new_variable_name box] $win.frame.canvas create rectangle [lindex $x 1] [lindex $x 2] [lindex $x 3] [lindex $x 4] -width 1 -fill [lindex $h_graphic_trace_color_list [lindex $x 5]] -outline black -tag [list boxes trace_items $box_name] set duration [format "%.3f" [expr 0.001 * ([lindex $x 3] - [lindex $x 1])]] set time [format "%.3f - %.3f" [expr 0.001 * [lindex $x 1]] [expr 0.001 * [lindex $x 3]]] $win.frame.canvas bind $box_name <Enter> "$win.request configure -text {[lindex $x 6]} $win.chunk configure -text {[lindex $x 7]} $win.notes configure -text {[lindex $x 8]} $win.time configure -text {$time} $win.duration configure -text $duration " $win.frame.canvas bind $box_name <Leave> "$win.request configure -text \"\" $win.chunk configure -text \"\" $win.notes configure -text \"\" $win.time configure -text \"\" $win.duration configure -text \"\" " # For now don't allow clicking to open other dialogs because of potential problems $win.frame.canvas bind $box_name <ButtonPress> [list history_custom_buffer_view $win $key $current [lindex $x 10] [lindex $x 1] [lindex $x 3]] if {[lindex $x 9] != ""} { $win.frame.canvas create text [expr 2 + [lindex $x 1]] [lindex $x 2] -text [lindex $x 9] -anchor nw -font graphic_trace_font -fill black -tag [list trace_items trace_text $box_name] -width [expr [lindex $x 3] - [lindex $x 1]] } } } } configure_h_trace_text $win $win.buttons.zoom_in configure -state normal $win.buttons.zoom_out configure -state normal $win.buttons.ht configure -state normal $win.buttons.hg configure -state normal $win.buttons.save1 configure -state normal $win.buttons.save2 configure -state normal $win.get configure -state normal $win.save configure -state normal $win.load configure -state normal # looks better at 2 pixels per ms, but easier to draw at 1 horiz_zoom_in $win if {$fname == "" && $data != "nothing"} { $win.details configure -text "Graphic Trace data for model $model" } elseif {$fname != ""} { $win.details configure -text $comment } } proc save_horiz_graphic_trace {win} { set fname [tk_getSaveFile -title "Save graphic trace as"\ -filetypes {{"Encapsulated PostScript" "*.eps"}}] if {$fname != ""} { $win.frame.canvas postscript -file $fname -width [expr 150 + [$win.frame.canvas cget -width]] -height [$win.frame.canvas cget -height] -x -150 -y 0 -pageanchor nw -pagex 0.0 -pagey [$win.frame.canvas cget -height] -pagewidth [expr 150 + [$win.frame.canvas cget -width]] } } proc save_horiz_graphic_trace_multi {win} { set fname [tk_getSaveFile -title "Save graphic trace as" -filetypes {{"PostScript" "*.ps"}}] if {$fname != ""} { set width 1400.0 set height 400 set xMax [expr 150.0 + [$win.frame.canvas cget -width]] set NOP [expr ceil ($xMax / $width)] # The following code was modified from code written by Robert Heller # in a file called bridge.tcl which was posted to comp.lang.tcl as # an example of producing multi-page ps files. set prFile [open $fname w] puts $prFile "%!PS-Adobe-2.0" puts $prFile "%%Creator: ACT-R Environment Copyright 2007 Dan Bothell" puts $prFile "%%Title: Horizontal Graphic Trace" puts -nonewline $prFile "%%CreationDate: " global tcl_version if {$tcl_version >= 7.6} { puts $prFile "[clock format [clock seconds]]" } else { puts $prFile "[exec date]" } puts $prFile "%%Pages: $NOP $xMax $width [expr ceil($xMax / $width)]" puts $prFile "%%EndComments" puts $prFile "/EncapDict 200 dict def EncapDict begin" puts $prFile "/showpage {} def /erasepage {} def /copypage {} def end" puts $prFile "/BeginInclude {0 setgray 0 setlinecap 1 setlinewidth" puts $prFile "0 setlinejoin 10 setmiterlimit \[\] 0 setdash" puts $prFile "/languagelevel where {" puts $prFile " pop" puts $prFile " languagelevel 2 ge {" puts $prFile " false setoverprint" puts $prFile " false setstrokeadjust" puts $prFile " } if" puts $prFile "} if" puts $prFile "newpath" puts $prFile "save EncapDict begin} def" puts $prFile "/EndInclude {restore end} def" puts $prFile "%%EndProlog" set pageNo 1 for {set xoff 0} {$xoff < $xMax} {set xoff [expr $xoff + $width]} { puts $prFile "%%Page: $pageNo $pageNo" puts $prFile "BeginInclude" # this one works set eps "[$win.frame.canvas postscript -height $height -width $width -x [expr $xoff - 150] -y 0 -pageanchor nw -pagex 0.25i -pagey 7.5i -pagewidth 8.0i]" set eps "[$win.frame.canvas postscript -height $height -width $width -x [expr $xoff - 150] -y 0 -pageanchor nw -pagex 2.0i -pagey 0.5i -pagewidth 10.0i -rotate 1]" set EOC [string first "%%BeginProlog\n" "$eps"] set EOF [expr [string first "%%EOF\n" "$eps"] - 1] puts $prFile "[horiz_StripPSComments [string range $eps $EOC $EOF]]" puts $prFile "EndInclude showpage" incr pageNo } puts $prFile "%%EOF" close $prFile } } proc horiz_StripPSComments {PSString} { set result {} foreach l [split "$PSString" "\n"] { set i [string first "%" "$l$"] if {$i == 0} { set result "$result\n" } elseif {$i > 0 && [regexp {(^.*[^\\])(%.*$)} "$l" whole prefix comment]} { set result "$result$prefix\n" } else { set result "$result$l\n" } } return "$result" } add_graphic_trace_type horizontal select_graphic_trace
19,371
Common Lisp
.cl
391
42.350384
274
0.645859
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
4206324fcecf7249aec5c45f5767dadc607acf08302e38c2f9ded368681b13f0
14,340
[ -1 ]
14,341
60-ctrl-panel-recorded-label.tcl
asmaloney_ACT-R/environment/GUI/dialogs/60-ctrl-panel-recorded-label.tcl
label [control_panel_name].gen_recorded_label -text "General\nRecordable Data" -font label_font pack [control_panel_name].gen_recorded_label proc get_incremental_history {id} { set start [call_act_r_command "get-incremental-history-data" nil [list $id]] set result "" while {$start != ""} { set result "$result [json::json2dict [lindex $start 0]]" set start [call_act_r_command "get-incremental-history-data" nil [list $id]] } return $result }
478
Common Lisp
.cl
11
39.363636
95
0.712088
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
f1cdabd2bb7c11a50035ceadc9ee6ccc9f57f30161608711f1f33a1412e460bf
14,341
[ -1 ]
14,342
11-ctrl-panel-load-python-button.tcl
asmaloney_ACT-R/environment/GUI/dialogs/11-ctrl-panel-load-python-button.tcl
# Assumes the normal load button has been loaded first. # Works like the load ACT-R code button except that it # passes the pathname off to the Python-import-from-file # command if it exists which can import a python module # set load_result "" proc record_load_traces {model s} { global load_result set load_result "$load_result$s" return "" } proc load_python_file {fname {wait ""}} { global load_result global options_array set load_result "" set load_monitor [add_new_cmd load_monitor "record_load_traces" "Environment command for capturing output during Import Python module."] send_cmd "monitor" [list "model-trace" $load_monitor] send_cmd "monitor" [list "command-trace" $load_monitor] send_cmd "monitor" [list "warning-trace" $load_monitor] send_cmd "monitor" [list "general-trace" $load_monitor] set result [call_act_r_command_with_error_messages "Python-import-from-file" nil [list {$fname}]] send_cmd "remove-monitor" [list "model-trace" $load_monitor] send_cmd "remove-monitor" [list "command-trace" $load_monitor] send_cmd "remove-monitor" [list "warning-trace" $load_monitor] send_cmd "remove-monitor" [list "general-trace" $load_monitor] remove_cmd $load_monitor set win [toplevel [new_variable_name .import_response]] # hide the window for speed and aesthetic reasons wm withdraw $win wm geometry $win [get_configuration .import_response $win] set text_frame [frame $win.text_frame -borderwidth 0] set text_box [text $text_frame.text -yscrollcommand \ "$text_frame.text_scrl set" -state normal \ -font text_font] set text_scroll_bar [scrollbar $text_frame.text_scrl \ -command "$text_box yview"] set the_button [button $win.but -text "Ok" -font button_font -command "destroy $win"] place $text_frame -x 0 -y 0 -relheight 1.0 -height -30 -relwidth 1.0 place $the_button -relx .5 -x -30 -width 60 -rely 1.0 -y -30 -height 30 pack $text_scroll_bar -side right -fill y pack $text_box -side left -expand 1 -fill both if {[lindex $result 1] != "true" } { wm title $win "ERROR importing" $text_box insert 1.0 "Failed to import $fname\n[lindex $result 1]" } else { wm title $win "SUCCESSFUL import" $text_box insert 1.0 $load_result } wm deiconify $win focus $win if {$wait != ""} {tkwait window $win} } button [control_panel_name].load_py -text "Import Python module" -font button_font -command { global local_connection global top_dir global current_file_window global currently_open_files set fname "" if {$local_connection == 0} { tk_messageBox -icon warning -type ok -title "Load warning" \ -message "You cannot use the Load Python module button if the\ environment is not running on the same machine\ as ACT-R." } elseif {[send_cmd "check" "Python-import-from-file"] == "null"} { tk_messageBox -icon warning -type ok -title "No Python connection found" \ -message "Did not find a Python with the actr.py module imported that would accept the import request." } else { if {$current_file_window == ""} { set fname [tk_getOpenFile -title "File to load" -initialdir $top_dir] } else { set fname [tk_getOpenFile -title "File to load" -initialdir [file dirname $currently_open_files($current_file_window)] -initialfile [file tail $currently_open_files($current_file_window)]] } if {$fname != ""} { load_python_file $fname } } } pack [control_panel_name].load_py
3,643
Common Lisp
.cl
78
40.923077
194
0.682336
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
e2440eef8b1a4a9a339c931e48c7444192a9c298124f06c23213da8416285d31
14,342
[ -1 ]
14,343
36-procedural.tcl
asmaloney_ACT-R/environment/GUI/dialogs/36-procedural.tcl
proc make_procedural_viewer {} { set model [currently_selected_model] if {$model == "nil"} { tk_messageBox -icon info -type ok -title "Procedural" -message "Procedural viewer requires a current model." } else { set win [toplevel [new_variable_name .procedural]] wm withdraw $win record_new_window $win $win $model wm geometry $win [get_configuration .procedural $win] set list_frame [frame $win.list_frame -borderwidth 2] set list_box [listbox $list_frame.list_box \ -listvar $list_frame.list_box.var \ -yscrollcommand "$list_frame.list_scrl set" \ -selectmode single -font list_font\ -exportselection 0 -bd 0] set list_scroll_bar [scrollbar $list_frame.list_scrl \ -command "$list_box yview"] set text_frame [frame $win.text_frame -borderwidth 0] set text_box [text $text_frame.text -yscrollcommand \ "$text_frame.text_scrl set" -state disabled \ -font text_font] set text_scroll_bar [scrollbar $text_frame.text_scrl -command "$text_box yview"] bind $list_box <<ListboxSelect>> "select_production $list_box $text_box $model" set why_not [button $win.whynot_button -text "Why not?" -font button_font \ -command "show_why_not $list_box $model"] place $why_not -x 2 -y 5 -width 75 -height 24 place $list_frame -relx 0.0 -y 30 -relheight 1.0 -height -30 -relwidth .4 place $text_frame -relx .4 -y 30 -relheight 1.0 -height -30 -relwidth .6 pack $list_scroll_bar -side right -fill y pack $list_box -side left -expand 1 -fill both pack $text_scroll_bar -side right -fill y pack $text_box -side left -expand 1 -fill both set_update_script $win "update_production_list $list_box $text_box $model" wm deiconify $win focus $win } } proc update_production_list {list text_box model} { set productions [lindex [call_act_r_command "all-productions" $model] 0] global options_array if {$options_array(sort_lists) == 1} { set productions [lsort -dictionary $productions] } global $list.var set selection [$list curselection] if {$selection != ""} { set name [$list get $selection] } set $list.var $productions if {$selection != ""} { $list selection clear 0 end set newpos [lsearch -exact $productions $name] if {$newpos != -1} { $list selection set $newpos } } select_production $list $text_box $model } proc select_production {list_box text_box model} { if {[$list_box curselection] != ""} { update_text_pane $text_box [lindex [call_act_r_command "production-details" $model [list [$list_box get [$list_box curselection]]]] 0] } else { update_text_pane $text_box "" } } proc show_why_not {prods model} { # get the current selection - knowing it's a single selection list box set selection [$prods curselection] if {$selection != "" } { set prod [$prods get $selection] # make a new window set top [toplevel [new_variable_name ".whynot"]] wm geometry $top [get_configuration .whynot $top] record_new_window $top "Whynot $prod" $model # create a text_box to hold the output and put it in the window # also need a frame to hold it and the scroll bar frame $top.frame -borderwidth 0 set text_box [text $top.frame.text -font text_font -state disabled \ -yscrollcommand "$top.frame.scrl set" ] set scrl_bar [scrollbar $top.frame.scrl -command "$top.frame.text yview"] place $top.frame -x 0 -y 0 -relwidth 1.0 -relheight 1.0 pack $scrl_bar -side right -fill y pack $text_box -side left -expand 1 -fill both update_text_pane $text_box [lindex [call_act_r_command "whynot-text" $model [list $prod]] 0] } } # Make a button for the control panel that will open a new procedural viewer button [control_panel_name].procedural -command {make_procedural_viewer} -text "Procedural" -font button_font # put that button on the control panel pack [control_panel_name].procedural
4,239
Common Lisp
.cl
90
39.533333
138
0.654492
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
1c15691a0a9bf2ba64b6460d659b44b3e8e3be7737190d1960741df442d1c220
14,343
[ -1 ]
14,344
61-trace-history.tcl
asmaloney_ACT-R/environment/GUI/dialogs/61-trace-history.tcl
proc make_text_trace_history_viewer {} { set win [toplevel [new_variable_name .text_trace_history]] wm withdraw $win wm geometry $win [get_configuration .text_trace_history $win] # frame and radio buttons for level set level_frame_1 [frame $win.level_frame_1 -borderwidth 0] set rb1 [radiobutton $level_frame_1.rb1 -text "low" -variable $level_frame_1.level -value "low" -anchor w] set rb2 [radiobutton $level_frame_1.rb2 -text "medium" -variable $level_frame_1.level -value "medium" -anchor w] set rb3 [radiobutton $level_frame_1.rb3 -text "high" -variable $level_frame_1.level -value "high" -anchor w] set rb4 [radiobutton $level_frame_1.rb4 -text "ALL" -variable $level_frame_1.level -value "t" -anchor w] $rb1 invoke # set the range for the trace label $win.start -font text_font -text "start" label $win.end -font text_font -text "end" entry $win.min -text "" -font text_font entry $win.max -text "" -font text_font # The lables for the sections set l1 [label $win.l1 -text "Level" -justify left -font label_font] set l3 [label $win.l3 -text "" -justify left -font label_font -textvariable $win.l3.value] # frame for the trace display set text_frame_1 [frame $win.text_frame_1 -borderwidth 0] set text_box_1 [text $text_frame_1.text -yscrollcommand "$text_frame_1.text_scrl set" \ -xscrollcommand "$text_frame_1.hscrl set" \ -wrap none -font text_font -state disabled] # create the scroll bars for the text box set text_scroll_bar_1 [scrollbar $text_frame_1.text_scrl -command "$text_box_1 yview"] set h_scrl_bar [scrollbar $text_frame_1.hscrl -command "$text_box_1 xview" -orient horizontal] call_act_r_command "record-history" nil [list "trace-history"] bind $text_box_1 <Destroy> { call_act_r_command "stop-recording-history" nil [list "trace-history"] } button $win.get -text "Get History" -font button_font -command [list get_trace_history_data $text_box_1 $level_frame_1.level $win.min $win.max $win.l3.value] button $win.save -text "Save History" -font button_font -command [list save_trace_history_data $level_frame_1.level $win.min $win.max] button $win.load -text "Load History" -font button_font -command [list load_trace_history_data $text_box_1 $win.l3.value] pack $rb1 -side top -expand 1 -fill x pack $rb2 -side top -expand 1 -fill x pack $rb3 -side top -expand 1 -fill x pack $rb4 -side top -expand 1 -fill x pack $text_scroll_bar_1 -side right -fill y pack $h_scrl_bar -side bottom -fill x pack $text_box_1 -side left -expand 1 -fill both place $l3 -relx 0.0 -y 0.0 -height 25 -relwidth 1.0 place $text_frame_1 -relx .15 -y 25 -relheight 1.0 -height -25 -relwidth .85 place $l1 -relx 0.0 -y 25 -height 25 -relwidth .15 place $level_frame_1 -relx 0.0 -y 50 -height 100 -relwidth .15 place $win.start -relx 0.0 -y 150 -height 25 -relwidth .06 place $win.min -relx .06 -y 150 -height 25 -relwidth .09 place $win.end -relx 0.0 -y 175 -height 25 -relwidth .06 place $win.max -relx .06 -y 175 -height 25 -relwidth .09 place $win.get -relx 0 -y 200 -height 25 -relwidth .15 place $win.save -relx 0 -y 225 -height 25 -relwidth .15 place $win.load -relx 0 -y 250 -height 25 -relwidth .15 # now show the window wm deiconify $win focus $win return $win } proc get_trace_history_data {trace_window level_var min_entry max_entry top_label} { global $level_var global $top_label set min "nil" set max "nil" scan [$min_entry get] "%f" min scan [$max_entry get] "%f" max upvar $level_var level $trace_window configure -state normal $trace_window delete 1.0 end set any [call_act_r_command "history-data-available" nil [list "trace-history" $min $max $level]] if {$any == "nil" || $any == ""} { set $top_label "No Data available" } else { set $top_label "Collecting Data ..." set id [call_act_r_command "start-incremental-history-data" nil [list "trace-history" 16000 false $min $max $level]] if {$id != ""} { set result [get_incremental_history $id] foreach i $result { $trace_window insert end [lindex $i 3] $trace_window insert end "\n" } if {$level == "t"} { set detail "ALL" } else { set detail $level } set $top_label "Trace detail: $detail start: $min end: $max" } else { tk_messageBox -icon warning -type ok -title "Get Text History warning" \ -message "Unknown problem occurred trying to get data." set $top_label "Data Error occurred" } } } set trace_history_warnings "" proc th_record_warnings {model s} { global trace_history_warnings set trace_history_warnings "$trace_history_warnings$s" return "" } proc save_trace_history_data {level_var min_entry max_entry} { global top_dir global trace_history_warnings set fname [tk_getSaveFile -title "Save Text History" -initialdir $top_dir] if {$fname != ""} { global $level_var set min "nil" set max "nil" scan [$min_entry get] "%f" min scan [$max_entry get] "%f" max upvar $level_var level if {$level == "t"} { set detail "ALL" } else { set detail $level } set any [call_act_r_command "history-data-available" nil [list "trace-history" $min $max $level]] if {$any == "nil" || $any == ""} { tk_messageBox -icon warning -type ok -title "Save Text History warning" \ -message "No data available to save with current settings." } else { set trace_history_warnings "" set warning_monitor [add_new_cmd warning_monitor "th_record_warnings" "Environment command for capturing warnings during Save Text History."] send_cmd "monitor" [list "warning-trace" $warning_monitor] set result [call_act_r_command_with_error_messages "save-history-data" nil [list "trace-history" $fname "Data saved from Text Trace window. Trace detail: $detail start: $min end: $max" $min $max $level]] send_cmd "remove-monitor" [list "warning-trace" $warning_monitor] remove_cmd $warning_monitor if {[lindex $result 0] == 0} { tk_messageBox -icon warning -type ok -title "Save Text Trace error" \ -message "Save-history-data resulted in error.\n[lindex $result 1]." } elseif {[lindex $result 1] == "null"} { tk_messageBox -icon warning -type ok -title "Save Text Trace problem" \ -message "Save-history-data returned failure result.\n$trace_history_warnings." } } } } proc load_trace_history_data {trace_window top_label} { global top_dir global $top_label set fname [tk_getOpenFile -title "Load Text History" -initialdir $top_dir] if {$fname != ""} { $trace_window configure -state normal $trace_window delete 1.0 end global trace_history_warnings set trace_history_warnings "" set warning_monitor [add_new_cmd warning_monitor "th_record_warnings" "Environment command for capturing warnings during Load Text History."] send_cmd "monitor" [list "warning-trace" $warning_monitor] set id [call_act_r_command "start-incremental-history-data" nil [list "trace-history" 16000 $fname]] send_cmd "remove-monitor" [list "warning-trace" $warning_monitor] remove_cmd $warning_monitor if {$id == "" || $id == "null"} { tk_messageBox -icon warning -type ok -title "Load Text Trace problem" \ -message "Get-history-data returned failure result.\n$trace_history_warnings." set $top_label "Failure to load data" } else { set comment [call_act_r_command "get-incremental-history-data" nil [list $id]] set result [get_incremental_history $id] foreach i $result { $trace_window insert end [lindex $i 3] $trace_window insert end "\n" } set $top_label [json::json2dict [lindex $comment 0]] } } } # add_history_button make_text_trace_history_viewer "Text Trace" :save-trace "Text trace" left get-saved-text-trace default-save-history-info button [control_panel_name].text_trace -command {make_text_trace_history_viewer} \ -text "Text Trace" -font button_font # put that button on the control panel pack [control_panel_name].text_trace
8,446
Common Lisp
.cl
169
43.64497
209
0.673091
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
8371bc97fef394b293714634dea55413c2310615cee7a5cf57c42be8cadcfefa
14,344
[ -1 ]
14,345
21-stepper.tcl
asmaloney_ACT-R/environment/GUI/dialogs/21-stepper.tcl
global stop_type global stepper_tutor global tutor_ans global tutor_bindings global tutor_answers global step_now global stepper_tutorable global stepper_tutored global current_stepper_id global tutor_selections frame [control_panel_name].step_frame -borderwidth 0 checkbutton [control_panel_name].step_frame.step_all_events -text "Step All" -font checkbox_font \ -variable step_for_all -command {change_step_all} set current_stepper_id -1 set step_for_all 0 set revert_step_all 0 proc stepper_pause {} { global step_for_all global revert_step_all global current_stepper_id if {$step_for_all == 0} { set step_for_all 1 call_act_r_command "set-stepper-step-all" nil [list $current_stepper_id true] set revert_step_all 1 } select_stepper } proc change_step_all {} { global step_for_all global current_stepper_id if {$current_stepper_id != -1} { if {$step_for_all == 0} { set step false } else { set step true } call_act_r_command "set-stepper-step-all" nil [list $current_stepper_id $step] } } proc stepper_button_state_control {state} { .stepper.step configure -state $state .stepper.stop configure -state $state .stepper.run_until configure -state $state } proc select_stepper {} { global current_stepper_id global step_for_all global stepper_wait global stepper_stepped global close_stepper global reset_stepper if {[winfo exists .stepper] == 1} { wm deiconify .stepper raise .stepper } else { if {$step_for_all == 0} { set s null } else { set s true } set start [call_act_r_command "start-stepper" nil [list $s false $stepper_wait $stepper_stepped]] if {[lindex $start 0] != "true" } { tk_messageBox -icon info -type ok -title "Stepper" \ -message [lindex $start 1] return 0 } set current_stepper_id [lindex $start 1] toplevel .stepper wm withdraw .stepper wm title .stepper "Stepper" wm geometry .stepper [get_configuration .stepper] tk_optionMenu .stepper.run_until_type stop_type Time Production Module .stepper.run_until_type configure -font button_font [.stepper.run_until_type cget -menu] configure -font menu_font button .stepper.run_until -text "Run Until:" -font button_font -command {stepper_run_until} entry .stepper.run_until_time -width 6 -font text_font -textvariable run_until_time label .stepper.current -text "Last Stepped:" -justify left -font label_font label .stepper.next -text "Next Step:" -justify left -font label_font button .stepper.step -text "Step" -font button_font -command {stepper_step_button} button .stepper.stop -text "Stop" -font button_font -command {stepper_stop_button} label .stepper.current_text -font text_font \ -textvar .stepper.current_text.var -justify left -anchor nw label .stepper.next_text -font text_font \ -textvar .stepper.next_text.var -justify left -anchor nw frame .stepper.prod_frame -borderwidth 0 frame .stepper.prod_frame.f4 -borderwidth 0 label .stepper.prod_frame.f4.list_title -textvar .stepper.prod_frame.f4.list_title.var \ -anchor nw -justify left -font label_font set .stepper.prod_frame.f4.list_title.var "" frame .stepper.prod_frame.f4.f -borderwidth 0 listbox .stepper.prod_frame.f4.f.list -listvar .stepper.prod_frame.f4.f.list.var \ -yscrollcommand ".stepper.prod_frame.f4.f.scrl set" \ -selectmode single -exportselection 0 -font list_font -bd 0 bind .stepper.prod_frame.f4.f.list <<ListboxSelect>> { update_instantiation_viewers %W } scrollbar .stepper.prod_frame.f4.f.scrl -command ".stepper.prod_frame.f4.f.list yview" frame .stepper.prod_frame.f3 -borderwidth 0 frame .stepper.prod_frame.f3.f -borderwidth 0 label .stepper.prod_frame.f3.production \ -textvariable .stepper.prod_frame.f3.production.var \ -justify left -font label_font text .stepper.prod_frame.f3.f.text -font text_font \ -yscrollcommand ".stepper.prod_frame.f3.f.scrl set" \ -state disabled scrollbar .stepper.prod_frame.f3.f.scrl -command ".stepper.prod_frame.f3.f.text yview" frame .stepper.prod_frame.f2 -borderwidth 0 frame .stepper.prod_frame.f2.f -borderwidth 0 label .stepper.prod_frame.f2.bindings \ -textvariable .stepper.prod_frame.f2.bindings.var \ -justify left -font label_font text .stepper.prod_frame.f2.f.text -font text_font \ -yscrollcommand ".stepper.prod_frame.f2.f.scrl set" \ -state disabled scrollbar .stepper.prod_frame.f2.f.scrl -command ".stepper.prod_frame.f2.f.text yview" checkbutton .stepper.stepper_tutor -text "Tutor Mode" -font checkbox_font \ -variable stepper_tutor -command {select_tutor_mode} .stepper.stepper_tutor deselect frame .stepper.prod_frame.f5 -borderwidth 0 frame .stepper.prod_frame.f5.f -borderwidth 0 label .stepper.prod_frame.f5.production \ -textvariable .stepper.prod_frame.f5.production.var \ -justify left -font label_font text .stepper.prod_frame.f5.f.text -font text_font \ -yscrollcommand ".stepper.prod_frame.f5.f.scrl set" \ -state disabled scrollbar .stepper.prod_frame.f5.f.scrl -command ".stepper.prod_frame.f5.f.text yview" place .stepper.step -x 2 -y 2 -width 50 -height 25 place .stepper.stop -x 55 -y 2 -width 50 -height 25 place .stepper.run_until -x 108 -y 2 -width 80 -height 25 place .stepper.run_until_type -x 190 -y 2 -width 100 -height 25 place .stepper.run_until_time -x 292 -y 2 -width -394 -relwidth 1.0 -height 25 place .stepper.stepper_tutor -x -100 -relx 1.0 -y 5 -height 25 -width 100 place .stepper.next -x 0 -y 30 -height 25 -width 90 place .stepper.next_text -x 102 -y 32 -relwidth 1.0 -width -92 -height 23 place .stepper.current -x 0 -y 60 -height 25 -width 90 place .stepper.current_text -x 102 -y 62 -relwidth 1.0 -width -92 -height 23 place .stepper.prod_frame -x 0 -y 90 -relwidth 1.0 -relheight 1.0 -height -90 place .stepper.prod_frame.f5 -relx 0.0 -rely .5 -relwidth .4 -relheight .5 pack .stepper.prod_frame.f5.production -side top pack .stepper.prod_frame.f5.f.scrl -side right -fill y pack .stepper.prod_frame.f5.f.text -side left -expand 1 -fill both pack .stepper.prod_frame.f5.f -side top -expand 1 -fill both place .stepper.prod_frame.f4 -relx 0.0 -rely 0.0 -relwidth .4 -relheight .5 pack .stepper.prod_frame.f4.list_title -side top pack .stepper.prod_frame.f4.f.scrl -side right -fill y pack .stepper.prod_frame.f4.f.list -side left -expand 1 -fill both pack .stepper.prod_frame.f4.f -side top -expand 1 -fill both place .stepper.prod_frame.f3 -relx 0.4 -rely 0.4 -relwidth .6 -relheight .6 pack .stepper.prod_frame.f3.production -side top pack .stepper.prod_frame.f3.f.scrl -side right -fill y pack .stepper.prod_frame.f3.f.text -side left -expand 1 -fill both pack .stepper.prod_frame.f3.f -side top -expand 1 -fill both place .stepper.prod_frame.f2 -relx 0.4 -rely 0.0 -relwidth .6 -relheight .4 pack .stepper.prod_frame.f2.bindings -side top pack .stepper.prod_frame.f2.f.scrl -side right -fill y pack .stepper.prod_frame.f2.f.text -side left -expand 1 -fill both pack .stepper.prod_frame.f2.f -side top -expand 1 -fill both send_cmd "monitor" [list "clear-all-start" $close_stepper] send_cmd "monitor" [list "reset-step1" $reset_stepper] bind .stepper.step <Destroy> { send_cmd "remove-monitor" [list "clear-all-start" $close_stepper] send_cmd "remove-monitor" [list "reset-step1" $reset_stepper] call_act_r_command "stop-stepper" nil [list $current_stepper_id] global step_for_all global revert_step_all if {$revert_step_all == 1} { set step_for_all 0 set revert_step_all 0 } set current_stepper_id -1 } reset_stepper_tool "" wm deiconify .stepper call_act_r_command "set-stepper-ready" nil [list $current_stepper_id] } } proc close_stepper_tool {model} { destroy .stepper } proc reset_stepper_tool {model} { global .stepper.current_text.var global .stepper.prod_frame.f4.list_title.var global .stepper.prod_frame.f3.production.var global .stepper.prod_frame.f2.bindings.var global .stepper.prod_frame.f5.production.var global .stepper.next_text.var global .stepper.prod_frame.f4.f.list.var global stepper_tutor global stepper_tutored global stepper_tutorable global current_stepper_id if {[winfo exists .tutor_response] == 1} { global tutor_ans set tutor_ans "" destroy .tutor_response } set .stepper.next_text.var "" set .stepper.current_text.var "" set .stepper.prod_frame.f4.list_title.var "" set .stepper.prod_frame.f5.production.var "" set .stepper.prod_frame.f2.bindings.var "" set .stepper.prod_frame.f3.production.var "" update_text_pane .stepper.prod_frame.f5.f.text "" update_text_pane .stepper.prod_frame.f2.f.text "" update_text_pane .stepper.prod_frame.f3.f.text "" set .stepper.prod_frame.f4.f.list.var "" set stepper_tutor 0 set stepper_tutored 0 set stepper_tutorable 0 stepper_button_state_control disabled call_act_r_command "set-stepper-tutoring" nil [list $current_stepper_id false] } proc select_tutor_mode {} { global tutor_bindings global tutor_answers global stepper_tutored global stepper_tutor global stepper_tutorable global current_stepper_id if {[winfo exists .tutor_response] == 1} { global tutor_ans set tutor_ans "" destroy .tutor_response } if {[winfo exists .tutor_cr] == 1} { destroy .tutor_cr } if {[winfo exists .tutor_r] == 1} { destroy .tutor_r } if [array exists tutor_bindings] { array unset tutor_bindings } if [array exists tutor_answers] { array unset tutor_answers } if {$stepper_tutored && !$stepper_tutor} { set stepper_tutored 0 } elseif {$stepper_tutorable && $stepper_tutor} { set stepper_tutored 1 } if {$stepper_tutor} { call_act_r_command "set-stepper-tutoring" nil [list $current_stepper_id true] } else { call_act_r_command "set-stepper-tutoring" nil [list $current_stepper_id false] } update_instantiation_viewers .stepper.prod_frame.f4.f.list } proc wait_for_stepper {model event} { global .stepper.next_text.var set .stepper.next_text.var $event stepper_button_state_control normal } proc display_stepper_stepped {model text items tutorable p1 p2 p3 p4} { global .stepper.current_text.var global .stepper.prod_frame.f4.list_title.var global .stepper.prod_frame.f3.production.var global .stepper.prod_frame.f2.bindings.var global .stepper.prod_frame.f5.production.var global stepper_tutored global stepper_tutor global .stepper.next_text.var global stepper_tutorable global options_array global tutor_bindings set .stepper.next_text.var "" set .stepper.current_text.var $text set .stepper.prod_frame.f4.list_title.var $p1 set .stepper.prod_frame.f5.production.var $p2 set .stepper.prod_frame.f2.bindings.var $p3 set .stepper.prod_frame.f3.production.var $p4 update_text_pane .stepper.prod_frame.f5.f.text "" update_text_pane .stepper.prod_frame.f2.f.text "" update_text_pane .stepper.prod_frame.f3.f.text "" # quick hack to fix an issue with my JSON parser not converting null to "" if {$items == "null"} {set items ""} if {$tutorable =="null"} { set stepper_tutorable 0 } else { set stepper_tutorable 1 } if {$tutorable != "null" && $stepper_tutor} { if {[string compare -nocase $tutorable "conflict-resolution"] == 0} { set stepper_tutored 2 } elseif {[string compare -nocase $tutorable "start-retrieval"] == 0} { set stepper_tutored 3 } else { set stepper_tutored 1 } if {[llength $items] > 1} { set items [list [lindex $items 0]] } } else { set stepper_tutored 0 } update_list_box .stepper.prod_frame.f4.f.list $items 1 1 if {$stepper_tutored == 2 } { set data [call_act_r_command "update-stepper" nil false] set tutor_bindings(productions) [lindex $data 0] display_conflict_resolution } if {$stepper_tutored == 3 } { set data [call_act_r_command "update-stepper" nil false] set tutor_bindings(retrieval) [lindex $data 0] display_retrieval_choice } if $options_array(update_when_stepped) { update_registered_windows } } proc stepper_step_button {} { global stepper_tutor global tutor_bindings global current_stepper_id global stepper_tutored if {!$stepper_tutor || [array names tutor_bindings] == ""} { stepper_button_state_control disabled set result [call_act_r_command "step-stepper" nil [list $current_stepper_id]] if {[lindex $result 0] == "null"} { tk_messageBox -icon info -type ok -title "Step error" \ -message [lindex $result 1] stepper_button_state_control normal } } else { if {$stepper_tutored == 1} { tk_messageBox -icon info -type ok -title "Tutoring" \ -message "You must complete the production instantiation before continuing in tutor mode." } elseif {$stepper_tutored == 2} { tk_messageBox -icon info -type ok -title "Tutoring" \ -message "You must complete the conflict-resolution selection before continuing in tutor mode." } elseif {$stepper_tutored == 3} { tk_messageBox -icon info -type ok -title "Tutoring" \ -message "You must complete the retrieved chunk selection before continuing in tutor mode." } } } proc stepper_stop_button {} { # always let the user stop even in tutor mode now global current_stepper_id stepper_button_state_control disabled set result [call_act_r_command "step-stepper" nil [list $current_stepper_id true]] if {[lindex $result 0] == "null"} { tk_messageBox -icon info -type ok -title "Stop error" \ -message [lindex $result 1] stepper_button_state_control normal } } proc stepper_run_until {} { global stepper_tutor global stop_type global run_until_time global step_now global current_stepper_id if $stepper_tutor { tk_messageBox -icon info -type ok -title "Tutoring" \ -message "Run Until not allowed when in tutor mode." } else { stepper_button_state_control disabled set result [call_act_r_command "step-stepper" nil [list $current_stepper_id false $stop_type $run_until_time]] if {[lindex $result 0] == "null"} { tk_messageBox -icon info -type ok -title "Run Until error" \ -message [lindex $result 1] stepper_button_state_control normal } } } proc update_instantiation_viewers {list} { global stepper_tutor global tutor_bindings global stepper_tutored global tutor_answers if {[$list curselection] != ""} { set data [call_act_r_command "update-stepper" nil [list [$list get [$list curselection]]]] set params [lindex $data 0] set bindings [lindex $data 1] set display [lindex $data 2] set tutored_display [lindex $data 3] update_text_pane .stepper.prod_frame.f5.f.text $params update_text_pane .stepper.prod_frame.f3.f.text $display if {$stepper_tutored == 1} { set b "" set line 1 foreach i $tutored_display { set var_name [lindex $i 0] set strt 1.0 set side lhs set buf "no" set match "$var_name" # " $var_name" set is_buffer 0 if {$i != "null"} { append b [format "%s: \n" [lindex $i 0]] } if [regexp {^\'(.*)\'$} [lindex $i 1] all sub] { set val [format "\"%s\"" $sub] } else { set val [lindex $i 1] } set tutor_answers([lindex $i 0]) [list $val 0 $line] incr line if {[string tolower [lindex $i 2]] == "true"} { set is_buffer 1 } while {[set indx [.stepper.prod_frame.f3.f.text search $match $strt end]] != ""} { set v_start $indx # [.stepper.prod_frame.f3.f.text index "$indx + 1 chars"] set word_end [.stepper.prod_frame.f3.f.text index "$v_start + [string length $var_name] chars"] if {[.stepper.prod_frame.f3.f.text search -backwards -exact "==>" $v_start 1.0] != ""} { set side "rhs" } elseif {$buf == "no"} { set previous_buf [.stepper.prod_frame.f3.f.text search -backwards -regexp " =.*>" $v_start 1.0] if {$previous_buf != ""} { set b_start [.stepper.prod_frame.f3.f.text index "$previous_buf + 1 chars"] set b_end [.stepper.prod_frame.f3.f.text search ">" $b_start end] set buf [.stepper.prod_frame.f3.f.text get $b_start $b_end] } } if { $side == "rhs" && $is_buffer == 1 && [.stepper.prod_frame.f3.f.text search -exact ">" $word_end "$word_end +1 chars"] != ""} { #do nothing for the RHS buffer modification actions } else { set t_name [new_variable_name tag] .stepper.prod_frame.f3.f.text tag add $t_name $v_start $word_end .stepper.prod_frame.f3.f.text tag configure $t_name -background black -foreground white set tutor_bindings($t_name) [list $v_start $word_end $var_name $side $is_buffer $buf] .stepper.prod_frame.f3.f.text tag bind $t_name <1> { global tutor_bindings global tutor_ans set t_name [%W tag names @%x,%y] if {[llength $t_name] == 1} { set strt [lindex $tutor_bindings($t_name) 0] set w_end [lindex $tutor_bindings($t_name) 1] set var [lindex $tutor_bindings($t_name) 2] set side [lindex $tutor_bindings($t_name) 3] set is_buf [lindex $tutor_bindings($t_name) 4] set buf [lindex $tutor_bindings($t_name) 5] if {[get_tutor_response $var $side $buf $is_buf $strt $w_end $t_name]} { tkwait variable tutor_ans if {$tutor_ans != "NoAnswer"} { array unset tutor_bindings [lindex $tutor_ans 3] .stepper.prod_frame.f3.f.text configure -state normal .stepper.prod_frame.f3.f.text delete [lindex $tutor_ans 1] [lindex $tutor_ans 2] .stepper.prod_frame.f3.f.text tag delete [lindex $tutor_ans 3] .stepper.prod_frame.f3.f.text insert [lindex $tutor_ans 1] [lindex $tutor_ans 0] .stepper.prod_frame.f3.f.text configure -state disabled } } } else { tk_messageBox -icon warning -title "Invalid Selection" \ -message "There was additional text selected when clicking on a variable. Please try again." -type ok } } } set strt $word_end } } update_text_pane .stepper.prod_frame.f2.f.text $b } else { update_text_pane .stepper.prod_frame.f2.f.text $bindings } } } proc get_tutor_response {word side buf is_buf start end name} { if {[winfo exists .tutor_response] == 1} { tk_messageBox -icon info -type ok -title "Tutoring" \ -message "You haven't completed the previous binding yet." wm deiconify .tutor_response raise .tutor_response return 0 } else { global tutor_help global tutor_entry global tutor_ans toplevel .tutor_response wm withdraw .tutor_response wm title .tutor_response "Tutor Response" wm geometry .tutor_response [get_configuration .tutor_response] label .tutor_response.label \ -text "What is the binding for $word?" \ -justify left -font label_font entry .tutor_response.entry \ -width 50 -textvariable tutor_entry -font text_font set tutor_entry "" set tutor_ans "" bind .tutor_response.entry <Key-Return> "accept_tutor_response $word $start $end $name" label .tutor_response.help \ -textvariable tutor_help \ -justify left -font label_font \ -height 2 set tutor_help "" button .tutor_response.help_button -text "Help" -font button_font -command "tutor_help $word" button .tutor_response.hint_button -text "Hint" -font button_font -command "tutor_hint $word $side $buf $is_buf" bind .tutor_response.entry <Destroy> { if {$tutor_ans == ""} { set tutor_ans "NoAnswer" } } pack .tutor_response.label -anchor w pack .tutor_response.entry -anchor w pack .tutor_response.help -anchor w pack .tutor_response.hint_button -side left pack .tutor_response.help_button -side left wm deiconify .tutor_response after idle {focus .tutor_response.entry} return 1 } } proc accept_tutor_response {word start end name} { global tutor_entry global tutor_help global tutor_ans global tutor_answers if {$tutor_entry != ""} { set correct [lindex $tutor_answers($word) 0] if {[string compare -nocase $correct [string trim $tutor_entry]] == 0} { set tutor_ans [list $correct $start $end $name] destroy .tutor_response if {[lindex $tutor_answers($word) 1] == 0} { set i [string length "$word : "] set l [lindex $tutor_answers($word) 2] .stepper.prod_frame.f2.f.text insert "$l.$i" $correct set tutor_answers($word) [list $correct 1] } } else { set tutor_help "Incorrect.\n$tutor_entry is not the binding for $word in this instantiation." set tutor_entry "" } } } proc tutor_hint {word side buf is_buf} { global tutor_help global tutor_answers if {[lindex $tutor_answers($word) 1] == 1} { set tutor_help "Look in the bindings section of the stepper window\nto see the current binding for $word." } elseif {$side == "rhs"} { set tutor_help "You should find the binding for $word on\nthe left hand side of the production first." } elseif $is_buf { set tutor_help "Use the buffers tool to determine the chunk in the [string range $word 1 end] buffer." } elseif {$side == "lhs" && $buf != ""} { set tutor_help "$word is in a slot of the [string range $buf 1 end] buffer.\nYou can find its value using the buffers tool." } else { set tutor_help "No hint is available for this variable. If it is in a !bind! or !mv-bind! you will need to use the help button to get the answer." } } proc tutor_help {word} { global tutor_help global tutor_answers set tutor_help "The binding of $word is [lindex $tutor_answers($word) 0]" } proc check_conflict_resolution {} { global tutor_bindings global tutor_selections global tutor_cr_none set data $tutor_bindings(productions) set picked 0 for {set count 0} {$count < [llength $data]} {incr count} { if $tutor_selections($count) { incr picked } } if {$tutor_cr_none == 0 && $picked == 0} { tk_messageBox -icon info -type ok -title "Tutoring" \ -message "You must select at least one production or the None match option." } else { set count 0 set correct 0 foreach i $data { .tutor_cr.frame.c.contents.$count.but.b configure -state disabled set value [lindex $i 1] pack forget .tutor_cr.frame.c.contents.$count incr count } set count 0 foreach i $data { set value [lindex $i 1] if $tutor_selections($count) { if {$value == ""} { incr correct } else { .tutor_cr.frame.c.contents.$count.label configure -width [winfo width .tutor_cr.frame.c.contents.$count.but.text] .tutor_cr.frame.c.contents.$count.label configure -text "Does not match.\n[lindex $i 1]" pack .tutor_cr.frame.c.contents.$count update_text_pane .tutor_cr.frame.c.contents.$count.but.text [.tutor_cr.frame.c.contents.$count.but.text get 1.0 end] } } else { if {$value != ""} { incr correct } else { .tutor_cr.frame.c.contents.$count.label configure -width [winfo width .tutor_cr.frame.c.contents.$count.but.text] .tutor_cr.frame.c.contents.$count.label configure -text "Does match the current state." pack .tutor_cr.frame.c.contents.$count update_text_pane .tutor_cr.frame.c.contents.$count.but.text [.tutor_cr.frame.c.contents.$count.but.text get 1.0 end] } } incr count } if {$correct == [llength $data]} { destroy .tutor_cr } else { destroy .tutor_cr.none .tutor_cr.message configure -text "These selections were incorrect. Press Ok after reviewing the reasons." .tutor_cr.button configure -command "destroy .tutor_cr" -text "Ok" } } } proc unselect_all_productions {} { global tutor_bindings global tutor_cr_none if {$tutor_cr_none == 1} { for {set c 0} {$c < [llength $tutor_bindings(productions)]} {incr c} { .tutor_cr.frame.c.contents.$c.but.b deselect } } } proc display_conflict_resolution {} { global tutor_bindings global tutor_selections if [array exists tutor_selections] { array unset tutor_selections } set data $tutor_bindings(productions) if {[winfo exists .tutor_cr] == 1} { wm deiconify .tutor_cr raise .tutor_cr } else { toplevel .tutor_cr wm withdraw .tutor_cr wm title .tutor_cr "Conflict Resolution" wm geometry .tutor_cr [get_configuration .tutor_cr] message .tutor_cr.message \ -text "Using the information in the buffers, click the box next to each of the productions which have conditions that match the current state, or check the box labeled 'None match' if none of them match. Then Press the Check button when done." \ -font label_font place .tutor_cr.message -x 2 -y 5 -width -4 -relwidth 1.0 -height 100 button .tutor_cr.button -text "Check" -font button_font -command check_conflict_resolution place .tutor_cr.button -x -40 -relx .5 -width 80 -height 25 -y 110 checkbutton .tutor_cr.none -text "None match" -command unselect_all_productions -variable tutor_cr_none .tutor_cr.none deselect place .tutor_cr.none -x 2 -y 140 -height 20 bind .tutor_cr <Destroy> { global tutor_bindings global tutor_selections array unset tutor_bindings array unset tutor_selections } # Use a simple scrollable frame which is based on code # found at http://www.tek-tips.com/viewthread.cfm?qid=372792 by # Ken Jones of Avia Training and Consulting, www.avia-training.com # Create a "hull" frame to contain all other widgets # composing the scrollable frame. frame .tutor_cr.frame canvas .tutor_cr.frame.c -height [winfo height .tutor_cr] -width [winfo width .tutor_cr] -yscrollcommand ".tutor_cr.frame.ybar set" scrollbar .tutor_cr.frame.ybar -orient vertical -command ".tutor_cr.frame.c yview" # Create the frame that will actually # hold all children of the scrollable # frame. All children should be packed # or gridded into this frame, *not* the # hull frame or the canvas! frame .tutor_cr.frame.c.contents -borderwidth 0 # Tell the canvas to display the frame, # anchoring the upper-left hand corner # of the frame in the upper-left hand # corner of the canvas .tutor_cr.frame.c create window 0 0 -anchor nw -window .tutor_cr.frame.c.contents -tag win # Use grid to display the canvas and its # scrollbars. Handle resizing properly. grid .tutor_cr.frame.c -row 0 -column 0 -sticky nsew -pady 4 -padx 2 grid .tutor_cr.frame.ybar -row 0 -column 1 -sticky ns -pady 4 -padx 2 grid columnconfigure .tutor_cr.frame 0 -weight 1 grid rowconfigure .tutor_cr.frame 0 -weight 1 # Detect <Configure> events on the frame # to detect when it is first displayed # and any time is is resized. In either # case, recompute the visible bounds of # the canvas and update its -scrollregion # attribute. bind .tutor_cr.frame <Configure> { .tutor_cr.message configure -width [winfo width .tutor_cr.frame.c] .tutor_cr.frame.c configure -scrollregion [.tutor_cr.frame.c bbox all] .tutor_cr.frame.c itemconfigure win -width [winfo width .tutor_cr.frame.c] .tutor_cr.frame.c itemconfigure win -height [winfo height .tutor_cr.frame.c] } bind .tutor_cr.frame.c.contents <Configure> { .tutor_cr.message configure -width [winfo width .tutor_cr.frame.c] .tutor_cr.frame.c configure -scrollregion [.tutor_cr.frame.c bbox all] .tutor_cr.frame.c itemconfigure win -width [winfo width .tutor_cr.frame.c] .tutor_cr.frame.c itemconfigure win -height [winfo height .tutor_cr.frame.c] } place .tutor_cr.frame -x 0 -y 160 -relwidth 1.0 -relheight 1.0 -height -160 set count 0 foreach i $data { frame .tutor_cr.frame.c.contents.$count -borderwidth 0 frame .tutor_cr.frame.c.contents.$count.but -borderwidth 0 checkbutton .tutor_cr.frame.c.contents.$count.but.b -variable tutor_selections($count) -command ".tutor_cr.none deselect" .tutor_cr.frame.c.contents.$count.but.b deselect text .tutor_cr.frame.c.contents.$count.but.text -state disabled -font text_font -width 45 -height [expr 1 + [llength [split [lindex $i 0] "\n"]]] update_text_pane .tutor_cr.frame.c.contents.$count.but.text "(p production[expr 1 + $count]\n[lindex $i 0]==>" message .tutor_cr.frame.c.contents.$count.label -text "" -font label_font -justify left # grid config .tutor_cr.frame.c.contents.$count.text -column 1 -row 0 -sticky nsew # grid config .tutor_cr.frame.c.contents.$count.label -column 1 -row 1 -sticky w # grid .tutor_cr.frame.c.contents.$count.b -column 0 -row 0 -sticky nsew pack .tutor_cr.frame.c.contents.$count.but.b -side left pack .tutor_cr.frame.c.contents.$count.but.text -side right pack .tutor_cr.frame.c.contents.$count.but pack .tutor_cr.frame.c.contents.$count.label pack .tutor_cr.frame.c.contents.$count -anchor nw incr count } wm deiconify .tutor_cr } } proc check_start_retrieval {} { global tutor_bindings global tutor_selections global tutor_r_none set data $tutor_bindings(retrieval) set picked 0 for {set count 0} {$count < [llength [lindex $data 1]]} {incr count} { if $tutor_selections($count) { incr picked } } if {$tutor_r_none == 0 && $picked == 0} { tk_messageBox -icon info -type ok -title "Tutoring" \ -message "You must select at least one chunk or the None match option." } else { set count 0 set correct 0 foreach i [lindex $data 1] { .tutor_r.frame.c.contents.$count.but.b configure -state disabled set value [lindex $i 1] pack forget .tutor_r.frame.c.contents.$count incr count } set count 0 foreach i [lindex $data 1] { set value [lindex $i 1] if $tutor_selections($count) { if {$value == true} { incr correct } else { .tutor_r.frame.c.contents.$count.label configure -width [winfo width .tutor_r.frame.c.contents.$count.but.text] .tutor_r.frame.c.contents.$count.label configure -text "Does not match the retrieval request." pack .tutor_r.frame.c.contents.$count update_text_pane .tutor_r.frame.c.contents.$count.but.text [.tutor_r.frame.c.contents.$count.but.text get 1.0 end] } } else { if {$value == "null"} { incr correct } else { .tutor_r.frame.c.contents.$count.label configure -width [winfo width .tutor_r.frame.c.contents.$count.but.text] .tutor_r.frame.c.contents.$count.label configure -text "Does match the retrieval request." pack .tutor_r.frame.c.contents.$count update_text_pane .tutor_r.frame.c.contents.$count.but.text [.tutor_r.frame.c.contents.$count.but.text get 1.0 end] } } incr count } if {$correct == [llength [lindex $data 1]]} { destroy .tutor_r } else { destroy .tutor_r.none .tutor_r.message configure -text "These selections were incorrect. Press Ok after reviewing the results.\n\n[lindex $data 0]" .tutor_r.button configure -command "destroy .tutor_r" -text "Ok" } } } proc unselect_all_retrievals {} { global tutor_bindings global tutor_r_none if {$tutor_r_none == 1} { for {set c 0} {$c < [llength [lindex $tutor_bindings(retrieval) 1]]} {incr c} { .tutor_r.frame.c.contents.$c.but.b deselect } } } proc display_retrieval_choice {} { global tutor_bindings global tutor_selections if [array exists tutor_selections] { array unset tutor_selections } set data $tutor_bindings(retrieval) if {[winfo exists .tutor_r] == 1} { wm deiconify .tutor_r raise .tutor_r } else { toplevel .tutor_r wm withdraw .tutor_r wm title .tutor_r "Start Retrieval" wm geometry .tutor_r [get_configuration .tutor_r] message .tutor_r.message \ -text "Click the box next to each chunk from the model's declarative memory which matches the retrieval request from the production that fired (shown below) or check the 'None match' box if none of them match. Then press the Check button when done.\n\n[lindex $data 0]" \ -font label_font place .tutor_r.message -x 2 -y 5 -width -4 -relwidth 1.0 -height 150 button .tutor_r.button -text "Check" -font button_font -command check_start_retrieval place .tutor_r.button -x -40 -relx .5 -width 80 -height 25 -y 160 checkbutton .tutor_r.none -text "None match" -command unselect_all_retrievals -variable tutor_r_none .tutor_r.none deselect place .tutor_r.none -x 2 -y 190 -height 20 bind .tutor_r <Destroy> { global tutor_bindings global tutor_selections array unset tutor_bindings array unset tutor_selections } # Use a simple scrollable frame which is based on code # found at http://www.tek-tips.com/viewthread.cfm?qid=372792 by # Ken Jones of Avia Training and Consulting, www.avia-training.com # Create a "hull" frame to contain all other widgets # composing the scrollable frame. frame .tutor_r.frame canvas .tutor_r.frame.c -height [winfo height .tutor_r] -width [winfo width .tutor_r] -yscrollcommand ".tutor_r.frame.ybar set" scrollbar .tutor_r.frame.ybar -orient vertical -command ".tutor_r.frame.c yview" # Create the frame that will actually # hold all children of the scrollable # frame. All children should be packed # or gridded into this frame, *not* the # hull frame or the canvas! frame .tutor_r.frame.c.contents -borderwidth 0 # Tell the canvas to display the frame, # anchoring the upper-left hand corner # of the frame in the upper-left hand # corner of the canvas .tutor_r.frame.c create window 0 0 -anchor nw -window .tutor_r.frame.c.contents -tag win # Use grid to display the canvas and its # scrollbars. Handle resizing properly. grid .tutor_r.frame.c -row 0 -column 0 -sticky nsew -pady 4 -padx 2 grid .tutor_r.frame.ybar -row 0 -column 1 -sticky ns -pady 4 -padx 2 grid columnconfigure .tutor_r.frame 0 -weight 1 grid rowconfigure .tutor_r.frame 0 -weight 1 # Detect <Configure> events on the frame # to detect when it is first displayed # and any time is is resized. In either # case, recompute the visible bounds of # the canvas and update its -scrollregion # attribute. bind .tutor_r.frame <Configure> { .tutor_r.message configure -width [winfo width .tutor_r.frame.c] .tutor_r.frame.c configure -scrollregion [.tutor_r.frame.c bbox all] .tutor_r.frame.c itemconfigure win -width [winfo width .tutor_r.frame.c] .tutor_r.frame.c itemconfigure win -height [winfo height .tutor_r.frame.c] } bind .tutor_r.frame.c.contents <Configure> { .tutor_r.message configure -width [winfo width .tutor_r.frame.c] .tutor_r.frame.c configure -scrollregion [.tutor_r.frame.c bbox all] .tutor_r.frame.c itemconfigure win -width [winfo width .tutor_r.frame.c] .tutor_r.frame.c itemconfigure win -height [winfo height .tutor_r.frame.c] } place .tutor_r.frame -x 0 -y 210 -relwidth 1.0 -relheight 1.0 -height -210 set count 0 foreach i [lindex $data 1] { frame .tutor_r.frame.c.contents.$count -borderwidth 0 frame .tutor_r.frame.c.contents.$count.but -borderwidth 0 checkbutton .tutor_r.frame.c.contents.$count.but.b -variable tutor_selections($count) -command ".tutor_r.none deselect" .tutor_r.frame.c.contents.$count.but.b deselect text .tutor_r.frame.c.contents.$count.but.text -state disabled -font text_font -width 45 -height [llength [split [lindex $i 0] "\n"]] update_text_pane .tutor_r.frame.c.contents.$count.but.text [lindex $i 0] message .tutor_r.frame.c.contents.$count.label -text "" -font label_font -justify left # grid config .tutor_r.frame.c.contents.$count.text -column 1 -row 0 -sticky nsew # grid config .tutor_r.frame.c.contents.$count.label -column 1 -row 1 -sticky w # grid .tutor_r.frame.c.contents.$count.b -column 0 -row 0 -sticky nsew pack .tutor_r.frame.c.contents.$count.but.b -side left pack .tutor_r.frame.c.contents.$count.but.text -side right pack .tutor_r.frame.c.contents.$count.but pack .tutor_r.frame.c.contents.$count.label pack .tutor_r.frame.c.contents.$count -anchor nw incr count } wm deiconify .tutor_r } } set stepper_wait [add_new_cmd "wait_for_stepper" "wait_for_stepper" "Internal command for stepper tool wait during pre-event hook. Do not call."] set stepper_stepped [add_new_cmd "display_stepper_stepped" "display_stepper_stepped" "Internal command for stepper tool update. Do not call."] set close_stepper [add_new_cmd "close-stepper-tool" "close_stepper_tool" "Internal command for closing the stepper when a clear-all occurs. Do not call."] set reset_stepper [add_new_cmd "reset-stepper-tool" "reset_stepper_tool" "Internal command for monitoring resets in stepper. Do not call."] button [control_panel_name].step_frame.step_button -command {select_stepper} -text "Stepper" -font button_font pack [control_panel_name].step_frame.step_button -side left pack [control_panel_name].step_frame.step_all_events -side right pack [control_panel_name].step_frame button [control_panel_name].pause_button -command {stepper_pause} -text "Pause" -font button_font pack [control_panel_name].pause_button
39,244
Common Lisp
.cl
880
38.085227
281
0.671979
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
8dac9c043cca4e66875dc493dc5cbc2095772965b6097988920d3cbfb79a57c3
14,345
[ -1 ]
14,346
00-copyrights.tcl
asmaloney_ACT-R/environment/GUI/dialogs/00-copyrights.tcl
# This file was mostly generated by vtcl-1.5.2 # I did the layout there, then hacked it up mostly # because I'm not sure how to get vtcl to do what # I want so it's easier to fix it by hand. In the process # I removed the font 'support' stuff that was added automatically # (things like get_font etc) because I've got my own font # mechanism - there's a global set of font names for the # environment that are set in the fonts.tcl init file. global copyrightlab30var proc select_copyrights {} { global got_actr_connection global environment_socket global options_array global screen_center_x global screen_center_y if {[winfo exists .copyright] == 1} { wm deiconify .copyright focus -force .copyright } else { # here the window gets created and set up toplevel .copyright wm withdraw .copyright wm geometry .copyright \ "400x290+[expr $screen_center_x - 200]+[expr $screen_center_y - 145]" global tcl_platform if {$tcl_platform(os) != "Darwin"} { wm overrideredirect .copyright 1 } label .copyright.lab22 -font intro_l_font -height 1 -text {ACT-R Environment} -anchor center label .copyright.lab30 -font intro_l_font -height 2 -textvariable copyrightlab30var -anchor center label .copyright.lab24 -font intro_s_font -height 1 -text "\u00a9 2002-2019" -anchor center label .copyright.lab33 -font intro_s_font -height 1 -anchor center -text {Dan Bothell} label .copyright.lab43 -font intro_s_font -height 1 -anchor center -text {John R. Anderson} label .copyright.lab35 -font intro_s_font -height 1 -anchor center -text {Department of Psychology, Carnegie Mellon University} global tcl_env_dir image create photo small_onr_logo -file [file join $tcl_env_dir dialogs smalllogo.gif] label .copyright.image -width 400 -height 142 -anchor center -image small_onr_logo ################### # SETTING GEOMETRY ################### pack .copyright.lab22 pack .copyright.lab30 pack .copyright.lab24 pack .copyright.lab33 pack .copyright.lab43 pack .copyright.lab35 pack .copyright.image # get the version strings, but being careful because an # overzelous clicker could clear the dialog before the # register messages arrive, so make sure the update messages # arrive (they're sent after the registers) before showing # the window global copyrightlab30var set copyrightlab30var [call_act_r_command "act-r-version"] # show the window if the user wants it # sort of cheats because it still gets "built" if {$options_array(show_copyrights) == 1} { wm deiconify .copyright } } } select_copyrights # then if it's supposed to be shown if {$options_array(show_copyrights) == 1} { # create a variable that will trigger the destruction of the window # after 5 seconds or when the window is clicked set clear_copyright 0 # set the variable that triggers destruction after 3 seconds # or as soon as a button is pressed on the window after 5000 {set clear_copyright 1} bind .copyright <ButtonPress> {set clear_copyright 1} # wait for one of the triggering events to happen tkwait variable clear_copyright } # close the window destroy .copyright
3,385
Common Lisp
.cl
76
38.763158
134
0.708771
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
fe0f679ba804b06fb84185d370fbce3a8ee5784f7a53ccb4f011ff7a36abd3f4
14,346
[ -1 ]
14,347
73-ctrl-panel-gt-vertical.tcl
asmaloney_ACT-R/environment/GUI/dialogs/73-ctrl-panel-gt-vertical.tcl
proc select_vert_graphic_trace {} { set model [currently_selected_model] if {$model == "nil"} { tk_messageBox -icon info -type ok -title "Graphic Trace" -message "Graphic trace viewer requires a current model." } else { set win [toplevel [new_variable_name .graphic_trace]] global $win.scale wm withdraw $win wm geometry $win [get_configuration .vert_graphic_trace $win] record_new_window $win $win $model call_act_r_command "record-history" $model [list "buffer-trace"] frame $win.frame -borderwidth 0 canvas $win.frame.canvas \ -yscrollcommand "$win.frame.scrl set" \ -xscrollcommand "$win.frame.scrlx set" \ -width 1000 -height 2000 -scrollregion {0 -4 1000 2000} -bg white scrollbar $win.frame.scrl \ -command "$win.frame.canvas yview" -orient vertical scrollbar $win.frame.scrlx \ -command "scroll_vtrace_canvas $win" -orient horizontal set $win.scale 1.0 bind $win.frame.canvas <Destroy> " call_act_r_command stop-recording-history $model [list buffer-trace] global $win.scale unset $win.scale " bind $win <MouseWheel> " \ if { %D < 0 } { \ $win.frame.canvas yview scroll 1 units \ } else { \ $win.frame.canvas yview scroll -1 units \ } " canvas $win.canvas1 -width 1000 -height 30 -bg white \ -xscrollcommand "$win.frame.scrlx set" \ -scrollregion {0 0 1000 30} -bg white label $win.details -font label_font label $win.time_label -font label_font -text "Time:" label $win.time -font text_font label $win.duration_label -font label_font -text "Duration:" label $win.duration -font text_font label $win.notes_label -font label_font -text "Notes:" label $win.notes -font text_font -anchor nw label $win.request_label -font label_font -text "Request:" label $win.request -font text_font -anchor nw label $win.chunk_label -font label_font -text "Chunk:" label $win.chunk -font text_font -anchor nw frame $win.buttons -borderwidth 0 button $win.buttons.zoom_in -command "vert_zoom_in $win" -text "+" -font button_font button $win.buttons.zoom_out -command "vert_zoom_out $win" -text "-" -font button_font checkbutton $win.buttons.ht \ -text "Hide text" \ -font checkbox_font \ -variable $win.ht \ -command "configure_v_trace_text $win" \ -onvalue 1 -offvalue 0 checkbutton $win.buttons.hg \ -text "Hide grid" \ -font checkbox_font \ -variable $win.hg \ -command "draw_v_grid $win" \ -onvalue 1 -offvalue 0 button $win.buttons.save1 -command "save_vert_graphic_trace $win" -text "Save .eps" -font button_font button $win.buttons.save2 -command "save_vert_graphic_trace_multi $win" -text "Save .ps" -font button_font button $win.get -text "Get History" -font button_font -command "get_v_graph_data $win $model" button $win.save -text "Save History" -font button_font -command "save_v_graph_history_data $model" button $win.load -text "Load History" -font button_font -command "load_v_graph_history_data $win $model" pack $win.frame.scrl -side right -fill y pack $win.frame.scrlx -side bottom -fill x pack $win.frame.canvas -side top -fill both place $win.canvas1 -x 0 -y 0 -relwidth 1.0 -height 30 place $win.frame -x 0 -y 30 -relwidth 1.0 -height -205 -relheight 1.0 place $win.details -x 0 -rely 1.0 -y -175 -height 24 -relwidth 1.0 place $win.request_label -x 0 -rely 1.0 -y -150 -width 70 -height 24 place $win.request -x 71 -rely 1.0 -y -150 -relwidth 1.0 -width -70 -height 24 place $win.chunk_label -x 0 -rely 1.0 -y -125 -width 70 -height 24 place $win.chunk -x 71 -rely 1.0 -y -125 -relwidth 1.0 -width -70 -height 24 place $win.notes_label -x 0 -rely 1.0 -y -100 -width 70 -height 24 place $win.notes -x 71 -rely 1.0 -y -100 -relwidth 1.0 -width -70 -height 24 place $win.time_label -x 0 -rely 1.0 -y -75 -width 70 -height 24 place $win.time -x 71 -rely 1.0 -y -75 -relwidth 0.5 -width -70 -height 24 place $win.duration_label -relx 0.5 -rely 1.0 -y -75 -width 70 -height 24 place $win.duration -relx 0.5 -x 71 -rely 1.0 -y -75 -relwidth 0.5 -width -70 -height 24 place $win.buttons.zoom_in -x 0 -y 0 -width 59 -height 24 place $win.buttons.zoom_out -x 60 -y 0 -width 59 -height 24 place $win.buttons.ht -x 320 -y 0 -width 99 -height 24 place $win.buttons.hg -x 420 -y 0 -width 99 -height 24 place $win.buttons.save1 -x 140 -y 0 -width 79 -height 24 place $win.buttons.save2 -x 220 -y 0 -width 79 -height 24 place $win.buttons -x 0 -rely 1.0 -y -50 -width 525 -height 25 place $win.get -relx .05 -rely 1.0 -y -25 -height 25 -relwidth .3 place $win.save -relx .35 -rely 1.0 -y -25 -height 25 -relwidth .3 place $win.load -relx .65 -rely 1.0 -y -25 -height 25 -relwidth .3 # now show the window $win.frame.canvas yview moveto 0 $win.frame.canvas xview moveto 0 wm deiconify $win pick_buffers return $win } } proc scroll_vtrace_canvas {win args} { set ignore "" eval [append ignore $win.frame.canvas " " xview " " $args] set ignore "" eval [append ignore $win.canvas1 " " xview " " $args] } proc vert_zoom_in {win} { upvar #0 $win.scale scale set w [$win.frame.canvas cget -width] if {$scale < 16} { set scale [expr 2 * $scale] $win.frame.canvas scale scale_items 0 0 1.0 2.0 $win.frame.canvas configure -scrollregion "0 -4 $w [expr 2 * [lindex [$win.frame.canvas cget -scrollregion] 3]]" $win.frame.canvas configure -height [expr 2 * [$win.frame.canvas cget -height]] } } proc vert_zoom_out {win} { upvar #0 $win.scale scale set w [$win.frame.canvas cget -width] set scale [expr .5 * $scale] $win.frame.canvas scale scale_items 0 0 1.0 0.5 $win.frame.canvas configure -scrollregion "0 -4 $w [expr .5 * [lindex [$win.frame.canvas cget -scrollregion] 3]]" $win.frame.canvas configure -height [expr .5 * [$win.frame.canvas cget -height]] } proc get_v_graph_data {win model} { draw_vert_items $win $model "" } proc load_v_graph_history_data {win model} { global top_dir set fname [tk_getOpenFile -title "Load Graphic Trace history" -initialdir $top_dir] if {$fname != ""} { draw_vert_items $win $model $fname } } set v_graph_history_warnings "" proc v_graph_record_warnings {model s} { global v_graph_history_warnings set v_graph_history_warnings "$v_graph_history_warnings$s" return "" } proc save_v_graph_history_data {model} { global top_dir set fname [tk_getSaveFile -title "Save Graphic Trace Data" -initialdir $top_dir] if {$fname != ""} { set any [call_act_r_command "history-data-available" $model [list "buffer-trace"]] if {$any == "nil" || $any == ""} { tk_messageBox -icon warning -type ok -title "Save Graphic Trace warning" \ -message "No data available to save with current settings." } else { global v_graph_history_warnings set v_graph_history_warnings "" set warning_monitor [add_new_cmd warning_monitor "v_graph_record_warnings" "Environment command for capturing warnings during Save Vertical Graphic trace."] send_cmd "monitor" [list "warning-trace" $warning_monitor] set result [call_act_r_command_with_error_messages "save-history-data" $model [list "buffer-trace" $fname "Data saved from Graphic Trace window for model $model"]] send_cmd "remove-monitor" [list "warning-trace" $warning_monitor] remove_cmd $warning_monitor if {[lindex $result 0] == 0} { tk_messageBox -icon warning -type ok -title "Save Graphic Trace error" \ -message "Save-history-data resulted in error.\n[lindex $result 1]." } elseif {[lindex $result 1] == "null"} { tk_messageBox -icon warning -type ok -title "Save Graphic Trace problem" \ -message "Save-history-data returned failure result.\n$v_graph_history_warnings." } } } } proc draw_v_grid {win} { upvar #0 $win.hg hide upvar #0 $win.scale scale if {$hide == 0} { set size [$win.frame.canvas cget -height] set y 0 set x [$win.frame.canvas cget -width] while {$y <= $size} { set y_pos [expr $y * $scale] $win.frame.canvas create line 40 $y_pos $x $y_pos -width 1 -f gray -tag [list trace_items scale_items time_line grid] $win.frame.canvas create text 0 $y_pos -text [format "%.3f" [expr 0.001 * $y]] -anchor w -font graphic_trace_font -tag [list trace_items scale_items grid] incr y 50 } $win.frame.canvas lower time_line } else { $win.frame.canvas delete grid } } proc configure_v_trace_text {win} { upvar #0 $win.ht hide if {[$win.frame.canvas find withtag trace_text] != ""} { if {$hide == 0} { $win.frame.canvas itemconfigure trace_text -fill black $win.frame.canvas raise trace_text display_boxes } else { $win.frame.canvas itemconfigure trace_text -fill white $win.frame.canvas lower trace_text all } } } set v_graphic_trace_color_list [list #ff0000 #8080ff #008000 #ff8000 #7f7f7f #ff00ff #ffff00 #c08000 #f0f0f0 #c000c0 #00c050 #f0c0ff #c05850 #50ff25] proc draw_vert_items {win model fname} { $win.buttons.zoom_in configure -state disabled $win.buttons.zoom_out configure -state disabled $win.buttons.ht configure -state disabled $win.buttons.hg configure -state disabled $win.buttons.save1 configure -state disabled $win.buttons.save2 configure -state disabled $win.get configure -state disabled $win.save configure -state disabled $win.load configure -state disabled $win.frame.canvas delete all $win.canvas1 delete all $win.details configure -text "" $win.request configure -text "" $win.chunk configure -text "" $win.notes configure -text "" $win.time configure -text "" $win.duration configure -text "" if {$fname == ""} { set any [call_act_r_command "history-data-available" $model [list "buffer-trace"]] if {$any == "nil" || $any == ""} { set data [list "nothing"] $win.details configure -text "No Data available" } else { $win.details configure -text "Collecting Data ..." set id [call_act_r_command "start-incremental-history-data" $model [list "vertical-graphic-trace" 16000]] if {$id != ""} { set data [get_incremental_history $id] } else { tk_messageBox -icon warning -type ok -title "Get Graphic trace History warning" \ -message "Unknown problem occurred trying to get data." $win.details configure -text "Data Error occurred" $win.buttons.zoom_in configure -state normal $win.buttons.zoom_out configure -state normal $win.buttons.ht configure -state normal $win.buttons.hg configure -state normal $win.buttons.save1 configure -state normal $win.buttons.save2 configure -state normal $win.get configure -state normal $win.save configure -state normal $win.load configure -state normal return "" } $win.details configure -text "Graphic Trace data for model $model" } } else { global v_graph_history_warnings set v_graph_history_warnings "" set warning_monitor [add_new_cmd warning_monitor "v_graph_record_warnings" "Environment command for capturing warnings during Load Vertical Graphic Trace."] send_cmd "monitor" [list "warning-trace" $warning_monitor] $win.details configure -text "Loading Data from file $fname" set id [call_act_r_command "start-incremental-history-data" $model [list "vertical-graphic-trace" 16000 $fname]] send_cmd "remove-monitor" [list "warning-trace" $warning_monitor] remove_cmd $warning_monitor if {$id == "" || $id == "null"} { tk_messageBox -icon warning -type ok -title "Load Graph Trace problem" \ -message "Get-history-data returned failure result.\n$v_graph_history_warnings." $win.details configure -text "Failure to load data" $win.buttons.zoom_in configure -state normal $win.buttons.zoom_out configure -state normal $win.buttons.ht configure -state normal $win.buttons.hg configure -state normal $win.buttons.save1 configure -state normal $win.buttons.save2 configure -state normal $win.get configure -state normal $win.save configure -state normal $win.load configure -state normal return "" } else { set comment [call_act_r_command "get-incremental-history-data" nil [list $id]] set comment "[json::json2dict [lindex $comment 0]] loaded from file $fname" set data [get_incremental_history $id] } } set size [lindex $data 0] upvar #0 $win.scale scale set scale 1.0 if {[lindex $size 0] == "size"} { set max [lindex $size 1] set w [$win.frame.canvas cget -width] $win.frame.canvas configure -height [expr $max + 15] $win.frame.canvas configure -scrollregion "0 -4 $w [expr 11 + $max]" draw_v_grid $win } else { # should have more error checking... } global v_graphic_trace_color_list foreach x [lrange $data 1 end] { switch [lindex $x 0] { label { if {[expr 40 + [lindex $x 2] + ([lindex $x 4] / 2)] > [$win.frame.canvas cget -width]} { $win.frame.canvas configure -width [expr 40 + [lindex $x 2] + round([lindex $x 4] / 2)] set h [$win.frame.canvas cget -height] set w [$win.frame.canvas cget -width] $win.frame.canvas configure -scrollregion "0 -4 $w [expr 11 + $h]" $win.canvas1 configure -width $w $win.canvas1 configure -scrollregion "0 0 $w 30" } $win.frame.canvas create text [expr 40 + [lindex $x 2]] -60 -anchor n -font text_font -text [lindex $x 1] -width [lindex $x 4] -fill [lindex $v_graphic_trace_color_list [lindex $x 3]] -tag trace_items $win.canvas1 create text [expr 40 + [lindex $x 2]] 5 -anchor n -font text_font -text [lindex $x 1] -width [lindex $x 4] -tag label_tag -fill [lindex $v_graphic_trace_color_list [lindex $x 3]] } rectangle { set box_name [new_variable_name box] $win.frame.canvas create rectangle [expr 40 + [lindex $x 1]] [lindex $x 2] [expr 40 + [lindex $x 3]] [lindex $x 4] -width 1 -fill [lindex $v_graphic_trace_color_list [lindex $x 5]] -outline black -tag [list scale_items display_boxes trace_items $box_name] set duration [format "%.3f" [expr 0.001 * ([lindex $x 4] - [lindex $x 2])]] set time [format "%.3f - %.3f" [expr 0.001 * [lindex $x 2]] [expr 0.001 * [lindex $x 4]]] $win.frame.canvas bind $box_name <Enter> "$win.request configure -text {[lindex $x 6]} $win.chunk configure -text {[lindex $x 7]} $win.notes configure -text {[lindex $x 8]} $win.time configure -text {$time} $win.duration configure -text $duration " $win.frame.canvas bind $box_name <Leave> "$win.request configure -text \"\" $win.chunk configure -text \"\" $win.notes configure -text \"\" $win.time configure -text \"\" $win.duration configure -text \"\" " # For now don't allow clicking to open other dialogs because of potential problems $win.frame.canvas bind $box_name <ButtonPress> [list history_custom_buffer_view $win $key $current [lindex $x 10] [lindex $x 1] [lindex $x 3]] if {[lindex $x 9] != ""} { $win.frame.canvas create text [expr 42 + [lindex $x 1]] [lindex $x 2] -text [lindex $x 9] -anchor nw -font graphic_trace_font -fill black -tag [list trace_items trace_text $box_name scale_items] -width [expr [lindex $x 3] - [lindex $x 1]] } } } } configure_v_trace_text $win $win.buttons.zoom_in configure -state normal $win.buttons.zoom_out configure -state normal $win.buttons.ht configure -state normal $win.buttons.hg configure -state normal $win.buttons.save1 configure -state normal $win.buttons.save2 configure -state normal $win.get configure -state normal $win.save configure -state normal $win.load configure -state normal if {$fname == "" && $data != "nothing"} { $win.details configure -text "Graphic Trace data for model $model" } elseif {$fname != ""} { $win.details configure -text $comment } } proc save_vert_graphic_trace {win} { set fname [tk_getSaveFile -title "Save graphic trace as" -filetypes {{"Encapsulated PostScript" "*.eps"}}] if {$fname != ""} { $win.frame.canvas postscript -file $fname -width [$win.frame.canvas cget -width] -height [expr 60 + [$win.frame.canvas cget -height]] -x 0 -y -60 -pageanchor nw -pagex 0.0 -pagey [expr 60 + [$win.frame.canvas cget -height]] -pagewidth [$win.frame.canvas cget -width] } } proc save_vert_graphic_trace_multi {win} { set fname [tk_getSaveFile -title "Save graphic trace as" -filetypes {{"PostScript" "*.ps"}}] if {$fname != ""} { # $win.frame.canvas postscript -file $fname -width [$win.frame.canvas cget -width] -height [expr 60 + [$win.frame.canvas cget -height]] -x 0 -y -60 -pageanchor nw -pagex 0.0 -pagey [expr 60 + [$win.frame.canvas cget -height]] -pageheight [expr 60 + [$win.frame.canvas cget -height]] set scale [expr ceil([$win.frame.canvas cget -width] / 8)] set width [expr ceil($scale * 8)] set height [expr $scale * 10] set yMax [expr 60 + [$win.frame.canvas cget -height]] set NOP [expr ceil ([expr (60.0 + [$win.frame.canvas cget -height]) / $height])] # The following code was modified from code written by Robert Heller # in a file called bridge.tcl which was posted to comp.lang.tcl as # an example of producing multi-page ps files. set prFile [open $fname w] puts $prFile "%!PS-Adobe-2.0" puts $prFile "%%Creator: ACT-R Environment Copyright 2007 Dan Bothell" puts $prFile "%%Title: Vertical Graphic Trace" puts -nonewline $prFile "%%CreationDate: " global tcl_version if {$tcl_version >= 7.6} { puts $prFile "[clock format [clock seconds]]" } else { puts $prFile "[exec date]" } puts $prFile "%%Pages: $NOP" puts $prFile "%%EndComments" puts $prFile "/EncapDict 200 dict def EncapDict begin" puts $prFile "/showpage {} def /erasepage {} def /copypage {} def end" puts $prFile "/BeginInclude {0 setgray 0 setlinecap 1 setlinewidth" puts $prFile "0 setlinejoin 10 setmiterlimit \[\] 0 setdash" puts $prFile "/languagelevel where {" puts $prFile " pop" puts $prFile " languagelevel 2 ge {" puts $prFile " false setoverprint" puts $prFile " false setstrokeadjust" puts $prFile " } if" puts $prFile "} if" puts $prFile "newpath" puts $prFile "save EncapDict begin} def" puts $prFile "/EndInclude {restore end} def" puts $prFile "%%EndProlog" set pageNo 1 for {set yoff 0} {$yoff < $yMax} {set yoff [expr $yoff + $height]} { puts $prFile "%%Page: $pageNo $pageNo" puts $prFile "BeginInclude" set eps "[$win.frame.canvas postscript -height $height -width $width -x 0 -y [expr $yoff - 60] -pageanchor nw -pagex 0.25i -pagey 10.5i -pagewidth 8.0i]" set EOC [string first "%%BeginProlog\n" "$eps"] set EOF [expr [string first "%%EOF\n" "$eps"] - 1] puts $prFile "[vert_StripPSComments [string range $eps $EOC $EOF]]" puts $prFile "EndInclude showpage" incr pageNo } puts $prFile "%%EOF" close $prFile } } proc vert_StripPSComments {PSString} { set result {} foreach l [split "$PSString" "\n"] { set i [string first "%" "$l$"] if {$i == 0} { set result "$result\n" } elseif {$i > 0 && [regexp {(^.*[^\\])(%.*$)} "$l" whole prefix comment]} { set result "$result$prefix\n" } else { set result "$result$l\n" } } return "$result" } add_graphic_trace_type vertical select_vert_graphic_trace
20,561
Common Lisp
.cl
414
42.557971
287
0.644022
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
ecf3dc18d9f9cf8e3ef741ba04e501ccb636ba641ffb13b4e9fd49b48c6d425b
14,347
[ -1 ]
14,348
06-ctrl-panel-show-loaded.tcl
asmaloney_ACT-R/environment/GUI/dialogs/06-ctrl-panel-show-loaded.tcl
label [control_panel_name].current_load -text "Current Model" -font label_font tk_optionMenu [control_panel_name].current_model_name global_current_model_name "No Current Model" [control_panel_name].current_model_name configure -font label_font [[control_panel_name].current_model_name cget -menu] configure -font button_font pack [control_panel_name].current_load pack [control_panel_name].current_model_name proc create_current_model {ignore_model name} { global global_current_model_name set menu [[control_panel_name].current_model_name cget -menu] set top [$menu entrycget 0 -value] if {$top == "No Current Model"} { $menu delete "No Current Model" } $menu add radiobutton -label $name -variable global_current_model_name set global_current_model_name $name } proc delete_current_model {ignore_model name} { global global_current_model_name global during_reload global options_array set menu [[control_panel_name].current_model_name cget -menu] set top [$menu entrycget 0 -value] $menu delete $name if {[$menu entrycget 0 -value] == ""} { $menu add radiobutton -label "No Current Model" -variable global_current_model_name } if {$global_current_model_name == $name} { set global_current_model_name [$menu entrycget 0 -value] } if {$during_reload == 0} { if {$options_array(kill_model_windows) == 1} { kill_all_model_windows $name } } } set env_current_add_monitor [add_new_cmd env_current_add_monitor "create_current_model" "Environment command for setting the current model menu when models created."] set env_current_delete_monitor [add_new_cmd env_current_delete_monitor "delete_current_model" "Environment command for setting the current model menu when models deleted."] proc check_current_models {} { global global_current_model_name set menu [[control_panel_name].current_model_name cget -menu] set top [$menu entrycget 0 -value] set models [lindex [call_act_r_command "mp-models"] 0] if {$top == "No Current Model" && [llength $models] != 0} { $menu delete "No Current Model" } foreach model $models { $menu add radiobutton -label $model -variable global_current_model_name set global_current_model_name $model } } check_current_models send_cmd "monitor" [list "creating-model" $env_current_add_monitor] send_cmd "monitor" [list "deleting-model" $env_current_delete_monitor] # Can be lazy about this because the dispatcher will clean up automatically # when the connection drops. #bind [control_panel_name].current_load <Destroy> { # global env_current_add_monitor # global env_current_delete_monitor # send_cmd "remove-monitor" [list $env_current_add_monitor "creating-model"] # send_cmd "remove-monitor" [list $env_current_delete_monitor "deleting-model"] # send_cmd "remove" $env_current_add_monitor # send_cmd "remove" $env_current_delete_monitor #} proc currently_selected_model {} { global global_current_model_name if {$global_current_model_name == "No Current Model" } { return "nil" } else { return $global_current_model_name } } proc model_in_current_list {model} { set menu [[control_panel_name].current_model_name cget -menu] set last [$menu index last] for {set i 0} {$i <= $last} {incr i} { if {$model == [$menu entrycget $i -value]} { return 1 } } return 0 } proc set_currently_selected_model {model} { global global_current_model_name if [model_in_current_list $model] { set global_current_model_name $model return 1 } else { return 0 } } global window_to_model global model_to_windows proc kill_all_model_windows {name} { global model_to_windows if {[array names model_to_windows -exact $name] != ""} { set windows $model_to_windows($name) foreach x $windows { catch { destroy $x } } array unset model_to_windows $name } } proc remove_model_window {win} { global window_to_model global model_to_windows if {[array names window_to_model -exact $win] != ""} { set model $window_to_model($win) array unset window_to_model $win set old $model_to_windows($model) set index [lsearch -exact $old $model] if {$index != -1} { set model_to_windows($model) [lreplace $old $index $index] } } } proc record_new_window {win_name title {model ""}} { if {$model == ""} { record_window_with_model $win_name [currently_selected_model] $title } else { record_window_with_model $win_name $model $title } } proc record_window_with_model {win_name model {title ""}} { global window_to_model global model_to_windows set window_to_model($win_name) $model if {$title == ""} { wm title $win_name "$win_name ($model)" } else { wm title $win_name "$title ($model)" } if {[array names model_to_windows -exact $model] == ""} { set model_to_windows($model) [list $win_name] } else { set model_to_windows($model) [concat $model_to_windows($model) $win_name] } bind $win_name <Destroy> {remove_model_window %W} } proc model_for_window {win} { global window_to_model if {[array names window_to_model -exact $win] != ""} { return $window_to_model($win) } else { return "nil" } } proc update_registered_windows {} { global window_to_model set names [array names window_to_model] foreach n $names { set tag [lindex [bindtags $n] 0] if [regexp {^focus_tag[0-9]+$} $tag] { eval [bind $tag <FocusIn>] } } }
5,550
Common Lisp
.cl
158
31.297468
172
0.699849
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
ad08916c8f94bf4f74ab1df65afa3e1a27903070eb778332d73c648211d3adee
14,348
[ -1 ]
14,349
999-touch-fingers.tcl
asmaloney_ACT-R/environment/GUI/dialogs/999-touch-fingers.tcl
# This file is an extension for the ACT-R Environment to show # the location of the fingers from the touch device from ACT-Touch # (included in the extras) in the visible virtual windows using the # agi handlers mechanism. proc touch_agi_change {cmd win coords params} { if {$win != "" && [$win.can gettags all] != ""} { $win.can raise finger_spot all $win.can raise finger_label all } } add_agi_handler agi_change touch_agi_change proc touch_finger_spots {cmd win coords params} { $win.can delete "[lindex $params 1]_[lindex $params 2]" set x [lindex $params 3] set y [lindex $params 4] set z [lindex $params 5] set name [string toupper "[string index [lindex $params 1] 0][string index [lindex $params 2] 0]"] if { $x >= [lindex $coords 0] && $x <= [expr [lindex $coords 0] + [lindex $coords 2]] && $y >= [lindex $coords 1] && $y <= [expr [lindex $coords 1] + [lindex $coords 3]]} { if {$z == 1} { # up $win.can create oval [expr $x - 10 - [lindex $coords 0]] [expr $y - 10 - [lindex $coords 1]] [expr $x + 10 - [lindex $coords 0]] [expr $y + 10 - [lindex $coords 1]] -outline brown -width 2 -fill white -tags [list "[lindex $params 1]_[lindex $params 2]" finger_spot] $win.can create text [expr $x - [lindex $coords 0]] [expr $y - [lindex $coords 1]] -text $name -anchor center -fill brown -font menu_font -tags [list "[lindex $params 1]_[lindex $params 2]" finger_label] } else { $win.can create oval [expr $x - 10 - [lindex $coords 0]] [expr $y - 10 - [lindex $coords 1]] [expr $x + 10 - [lindex $coords 0]] [expr $y + 10 - [lindex $coords 1]] -outline brown -fill brown -tags [list "[lindex $params 1]_[lindex $params 2]" finger_spot] $win.can create text [expr $x - [lindex $coords 0]] [expr $y - [lindex $coords 1]] -text $name -anchor center -fill white -font menu_font -tags [list "[lindex $params 1]_[lindex $params 2]" finger_label] } } } add_agi_handler showfinger touch_finger_spots proc touch_removefinger {cmd win coords params} { $win.can delete "[lindex $params 0]_[lindex $params 1]" } add_agi_handler removefinger touch_removefinger
2,182
Common Lisp
.cl
32
63.25
272
0.649222
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
ee994d5ea6401268cb94c20c59bc1db4a5d215aea1453f33ac994ab4eb61f61e
14,349
[ -1 ]
14,350
81a-bold-browser.tcl
asmaloney_ACT-R/environment/GUI/dialogs/81a-bold-browser.tcl
set bold_color_list [list #ff0000 #8080ff #008000 #ff8000 #7f7f7f #ff00ff #ffff00 #c08000 #f0f0f0 #c000c0 #00c050 #f0c0ff #c05850 #50ff25] proc make_bold_multi_graphs {} { set model [currently_selected_model] if {$model == "nil"} { tk_messageBox -icon info -type ok -title "BOLD graph" -message "BOLD graph viewer requires a current model." } else { set win [toplevel [new_variable_name .bold_graphs]] wm withdraw $win record_new_window $win $win $model wm geometry $win [get_configuration .bold_graphs $win] set list_frame [frame $win.list_frame -borderwidth 0] set list_box [listbox $list_frame.list_box -listvar \ $list_frame.list_box.var \ -yscrollcommand "$list_frame.list_scrl set" \ -selectmode multiple \ -exportselection 0 -font list_font -bd 0] set list_scroll_bar [scrollbar $list_frame.list_scrl -command "$list_box yview"] set frame [frame $win.frame -borderwidth 0] canvas $win.frame.canvas \ -xscrollcommand "$win.frame.scrlx set" \ -yscrollcommand "$win.frame.scrly set" \ -bg white scrollbar $win.frame.scrlx -command "$win.frame.canvas xview" -orient horizontal scrollbar $win.frame.scrly -command "$win.frame.canvas yview" -orient vertical bind $list_box <<ListboxSelect>> "select_multi_buffer_graph $list_box $win.frame.canvas $win" label $win.details -font label_font set button_frame [frame $win.buttons -borderwidth 0] radiobutton $win.buttons.grid0 -text "Raw values" -font button_font -value "raw" -variable $win.buttons.value radiobutton $win.buttons.grid1 -command "select_multi_buffer_graph $list_box $win.frame.canvas $win" -text "Scale each" -font button_font -value "each" -variable $win.buttons.value radiobutton $win.buttons.grid2 -command "select_multi_buffer_graph $list_box $win.frame.canvas $win" -text "Scale all" -font button_font -value "all" -variable $win.buttons.value $win.buttons.grid0 invoke $win.buttons.grid0 configure -command "select_multi_buffer_graph $list_box $win.frame.canvas $win" button $win.buttons.zoom_in -command "bold_multi_zoom_in $win" -text "+" -font button_font button $win.buttons.zoom_out -command "bold_multi_zoom_out $win" -text "-" -font button_font button $win.get -text "Get History" -font button_font -command "get_bold_graph_history_data $win $model $list_box $win.frame.canvas" button $win.save -text "Save History" -font button_font -command "save_bold_graph_history_data $model" button $win.load -text "Load History" -font button_font -command "load_bold_graph_history_data $win $model $list_box $win.frame.canvas" call_act_r_command record-history $model [list "bold-prediction-with-time"] global $win.scale set $win.scale 1.0 global $win.data set $win.data "" bind $win.frame.canvas <Destroy> " call_act_r_command stop-recording-history $model [list "bold-prediction-with-time"] global $win.scale unset $win.scale global $win.data unset $win.data " pack $win.frame.scrlx -side bottom -fill x pack $win.frame.scrly -side right -fill y pack $win.frame.canvas -side left -fill both pack $list_scroll_bar -side right -fill y pack $list_box -side left -expand 1 -fill both place $win.buttons.grid0 -x 0 -y 0 -width 95 -height 24 place $win.buttons.grid1 -x 100 -y 0 -width 95 -height 24 place $win.buttons.grid2 -x 200 -y 0 -width 95 -height 24 place $win.buttons.zoom_in -relx 1.0 -x -100 -y 0 -width 45 -height 24 place $win.buttons.zoom_out -relx 1.0 -x -50 -y 0 -width 45 -height 24 place $win.buttons -x 0 -y 0 -height 25 -relwidth 1.0 place $win.details -x 0 -y 25 -relwidth 1.0 -height 25 place $list_frame -relx 0.0 -y 50 -relheight 1.0 -height -75 -relwidth .2 place $win.frame -relx .25 -y 50 -relheight 1.0 -height -75 -relwidth .75 place $win.get -relx .05 -rely 1.0 -y -25 -height 25 -relwidth .3 place $win.save -relx .35 -rely 1.0 -y -25 -height 25 -relwidth .3 place $win.load -relx .65 -rely 1.0 -y -25 -height 25 -relwidth .3 wm deiconify $win pick_buffers } } proc bold_multi_zoom_out {win} { upvar #0 $win.scale scale if {[$win.frame.canvas cget -scrollregion] != ""} { set scale [expr .5 * $scale] resize_window $win .5 } } proc resize_window {win scale} { $win.frame.canvas scale all 0 0 $scale 1.0 $win.frame.canvas configure -scrollregion "0 0 [expr $scale * [lindex [$win.frame.canvas cget -scrollregion] 2]] [$win.frame.canvas cget -height]" $win.frame.canvas configure -width [expr $scale * [$win.frame.canvas cget -width]] } proc bold_multi_zoom_in {win} { upvar #0 $win.scale scale if {[$win.frame.canvas cget -scrollregion] != ""} { set scale [expr 2 * $scale] resize_window $win 2 } } set bold_pps 100 set bold_v_scale 300 proc select_multi_buffer_graph {listwin target_win win} { global bold_pps global bold_v_scale $target_win delete all set selections [$listwin curselection] if {[llength $selections] != 0} { upvar #0 $win.scale scale upvar #0 $win.data data upvar #0 $win.buttons.value value set scale 1.0 set times $data(times) if {[llength $times] > 1} { set w [expr round(40 + ($bold_pps * ([lindex $times 0] + [lindex $times end])))] set h [expr round(20 + (13 * $bold_v_scale / 10))] $target_win configure -height $h -width $w -scrollregion "0 0 $w $h" $target_win create line 40 0 40 [expr $h - 20] -fill black -width 1 for {set y 0} {$y <= [expr $h - 20]} {incr y [expr round($bold_v_scale / 10)]} { $target_win create line 36 $y 44 $y -fill black -width 1 } set zero [expr round(11 * $bold_v_scale / 10)] $target_win create line 40 $zero $w $zero -fill black -width 1 $target_win create text 5 $zero -text "0.0" -fill black -anchor w $target_win create text 5 [expr round($bold_v_scale / 10)] -text "1.0" -fill black -anchor w foreach t $times { $target_win create line [expr round(40 + ($bold_pps * $t))] [expr $zero - 3] [expr round(40 + ($bold_pps * $t))] [expr $zero + 3] -fill black -width 1 $target_win create text [expr round(40 + ($bold_pps * $t))] [expr $h - 20] -font env_window_font -fill black -text [format "%.3f" $t] -anchor n } foreach index $selections { set buf [$listwin get $index] set d $data($buf) set c $data($buf.color) switch $value { raw {set s 1.0} all {set s $data(max)} each {set s $data($buf.max)} } set prev [lindex $d 0] set i 0 foreach y [lrange $d 1 end] { $target_win create line [expr round(40 + ($bold_pps * [lindex $times $i]))] [expr round($zero - ($bold_v_scale * $prev / $s))] \ [expr round(40 + ($bold_pps * [lindex $times [expr $i + 1]]))] [expr round($zero - ($bold_v_scale * $y / $s))] \ -fill $c -width 2 set prev $y incr i } } } } } set bold_graph_history_warnings "" proc bold_graph_record_warnings {model s} { global bold_graph_history_warnings set bold_graph_history_warnings "$bold_graph_history_warnings$s" return "" } proc save_bold_graph_history_data {model} { global top_dir set fname [tk_getSaveFile -title "Save BOLD Data" -initialdir $top_dir] if {$fname != ""} { set any [call_act_r_command "history-data-available" $model [list "bold-prediction-with-time"]] if {$any == "nil" || $any == ""} { tk_messageBox -icon warning -type ok -title "Save BOLD warning" \ -message "No data available to save with current settings." } else { global bold_graph_history_warnings set bold_graph_history_warnings "" set warning_monitor [add_new_cmd warning_monitor "bold_graph_record_warnings" "Environment command for capturing warnings during Save BOLD graph trace."] send_cmd "monitor" [list "warning-trace" $warning_monitor] set result [call_act_r_command_with_error_messages "save-history-data" $model [list "bold-prediction-with-time" $fname "Data saved from BOLD graph window for model $model"]] send_cmd "remove-monitor" [list "warning-trace" $warning_monitor] remove_cmd $warning_monitor if {[lindex $result 0] == 0} { tk_messageBox -icon warning -type ok -title "Save BOLD graph error" \ -message "Save-history-data resulted in error.\n[lindex $result 1]." } elseif {[lindex $result 1] == "null"} { tk_messageBox -icon warning -type ok -title "Save BOLD graph problem" \ -message "Save-history-data returned failure result.\n$bold_graph_history_warnings." } } } } proc load_bold_graph_history_data {win model list_box canvas} { global top_dir set fname [tk_getOpenFile -title "Load BOLD History" -initialdir $top_dir] if {$fname != ""} { get_bold_graph_history_data $win $model $list_box $canvas $fname } } proc get_bold_graph_history_data {win model list_box canvas {fname ""}} { $win.buttons.zoom_in configure -state disabled $win.buttons.zoom_out configure -state disabled $win.buttons.grid0 configure -state disabled $win.buttons.grid1 configure -state disabled $win.buttons.grid2 configure -state disabled $win.get configure -state disabled $win.save configure -state disabled $win.load configure -state disabled $canvas delete all $list_box delete 0 end $win.details configure -text "" if {$fname == ""} { set any [call_act_r_command "history-data-available" $model [list "bold-prediction-with-time"]] if {$any == "nil" || $any == ""} { $win.details configure -text "No Data available" set data [list "nothing"] } else { $win.details configure -text "Collecting Data ..." set id [call_act_r_command "start-incremental-history-data" $model [list "bold-prediction-with-time" 16000]] if {$id != ""} { set data [get_incremental_history $id] } else { tk_messageBox -icon warning -type ok -title "Get BOLD History warning" \ -message "Unknown problem occurred trying to get data." $win.details configure -text "Data Error occurred" $win.buttons.zoom_in configure -state normal $win.buttons.zoom_out configure -state normal $win.buttons.grid0 configure -state normal $win.buttons.grid1 configure -state normal $win.buttons.grid2 configure -state normal $win.get configure -state normal $win.save configure -state normal $win.load configure -state normal return "" } $win.details configure -text "BOLD data for model $model" } } else { global bold_graph_history_warnings set bold_graph_history_warnings "" set warning_monitor [add_new_cmd warning_monitor "bold_graph_record_warnings" "Environment command for capturing warnings during Load BOLD data."] send_cmd "monitor" [list "warning-trace" $warning_monitor] $win.details configure -text "Loading Data from file $fname" set id [call_act_r_command "start-incremental-history-data" $model [list "bold-prediction-with-time" 16000 $fname]] send_cmd "remove-monitor" [list "warning-trace" $warning_monitor] remove_cmd $warning_monitor if {$id == "" || $id == "null"} { tk_messageBox -icon warning -type ok -title "Load BOLD problem" \ -message "Get-history-data returned failure result.\n$bold_graph_history_warnings." $win.details configure -text "Failure to load data" $win.buttons.zoom_in configure -state normal $win.buttons.zoom_out configure -state normal $win.buttons.grid0 configure -state normal $win.buttons.grid1 configure -state normal $win.buttons.grid2 configure -state normal $win.get configure -state normal $win.save configure -state normal $win.load configure -state normal return "" } else { set comment [call_act_r_command "get-incremental-history-data" nil [list $id]] set comment "[json::json2dict [lindex $comment 0]] loaded from file $fname" set data [get_incremental_history $id] } } if {$data != "nothing"} { upvar #0 $win.data d unset d global bold_color_list set d(times) [lrange [lindex $data 0] 1 end] set i 0 set max 0 foreach b [lrange $data 1 end] { set buf [lindex $b 0] $list_box insert end $buf $list_box itemconfigure $i -selectbackground [lindex $bold_color_list $i] set d($buf) [lrange $b 1 end] set d($buf.color) [lindex $bold_color_list $i] set m 0 foreach z [lrange $b 1 end] { if {$z > $m} {set m $z} } if {$m == 0} { set d($buf.max) 1 } else { set d($buf.max) $m } if {$m > $max} {set max $m} incr i } if {$max == 0} { set d(max) 1 } else { set d(max) $max } } else { # should have more error checking... } $win.buttons.zoom_in configure -state normal $win.buttons.zoom_out configure -state normal $win.buttons.grid0 configure -state normal $win.buttons.grid1 configure -state normal $win.buttons.grid2 configure -state normal $win.get configure -state normal $win.save configure -state normal $win.load configure -state normal if {$fname == "" && $data != "nothing"} { $win.details configure -text "BOLD data for model $model" } elseif {$fname != ""} { $win.details configure -text $comment } } add_bold_trace_type "graph" make_bold_multi_graphs
13,963
Common Lisp
.cl
293
40.672355
185
0.651336
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
6faa6270ecbde5d28c58f80e654e9a2a3ba625d2bec9b0a43a94ba27e51fe8b4
14,350
[ -1 ]
14,351
63-retrieval-history.tcl
asmaloney_ACT-R/environment/GUI/dialogs/63-retrieval-history.tcl
proc make_declarative_history_viewer {} { set model [currently_selected_model] if {$model == "nil"} { tk_messageBox -icon info -type ok -title "Retrieval History" -message "Retrieval history viewer requires a current model." } else { set win [toplevel [new_variable_name .retrieval_history]] wm withdraw $win record_new_window $win $win $model wm geometry $win [get_configuration .retrieval_history $win] # frame and list box for times set list_frame_1 [frame $win.list_frame_1 -borderwidth 0] set list_box_1 [listbox $list_frame_1.list_box -listvar \ $list_frame_1.list_box.var \ -yscrollcommand "$list_frame_1.list_scrl set" \ -selectmode single \ -exportselection 0 -font list_font -bd 0] set list_scroll_bar_1 [scrollbar $list_frame_1.list_scrl -command "$list_box_1 yview"] # Frame and list box for chunks set list_frame_2 [frame $win.list_frame -borderwidth 0] set list_box_2 [listbox $list_frame_2.list_box -listvar \ $list_frame_2.list_box.var \ -yscrollcommand "$list_frame_2.list_scrl set" \ -selectmode single \ -exportselection 0 -font list_font -bd 0] set list_scroll_bar_2 [scrollbar $list_frame_2.list_scrl -command "$list_box_2 yview"] # The lables for the sections set l1 [label $win.l1 -text "Times" -justify left -font label_font] set l2 [label $win.l2 -text "Matching Chunks" -justify left -font label_font] set l3 [label $win.l3 -text "Details" -justify left -font label_font] set l4 [label $win.l4 -text "Request" -justify left -font label_font] set l5 [label $win.l5 -text "Activation" -justify left -font label_font] set l0 [label $win.l0 -text "" -font label_font -textvariable $win.l0.value] # frame for the chunk display set text_frame_1 [frame $win.text_frame_1 -borderwidth 0] set text_box_1 [text $text_frame_1.text -yscrollcommand \ "$text_frame_1.text_scrl set" \ -xscrollcommand "$text_frame_1.text_scrl_x set" \ -font text_font -wrap none] # create the scroll bar for the text box set text_scroll_bar_1 [scrollbar $text_frame_1.text_scrl -command "$text_box_1 yview"] set text_scroll_bar_1a [scrollbar $text_frame_1.text_scrl_x -command "$text_box_1 xview" -orient horizontal] # frame for the request display set text_frame_2 [frame $win.text_frame_2 -borderwidth 0] set text_box_2 [text $text_frame_2.text -yscrollcommand \ "$text_frame_2.text_scrl set" \ -font text_font] # create the scroll bar for the text box set text_scroll_bar_2 [scrollbar $text_frame_2.text_scrl -command "$text_box_2 yview"] # bind the selection of a time to the updating of the chunks list and # the request box # frame for the activation display set text_frame_3 [frame $win.text_frame_3 -borderwidth 0] set text_box_3 [text $text_frame_3.text -yscrollcommand \ "$text_frame_3.text_scrl set" \ -xscrollcommand "$text_frame_3.text_scrl_x set" \ -font text_font -wrap none] # create the scroll bar for the text box set text_scroll_bar_3 [scrollbar $text_frame_3.text_scrl -command "$text_box_3 yview"] set text_scroll_bar_3a [scrollbar $text_frame_3.text_scrl_x -command "$text_box_3 xview" -orient horizontal] # make chunk selection update the other displays global $win.value set $win.value "" global $win.value2 set $win.value2 "" bind $list_box_1 <<ListboxSelect>> "select_dm_history_time $list_box_1 $list_box_2 $text_box_1 $text_box_2 $text_box_3 $win.value $win.value2" bind $list_box_2 <<ListboxSelect>> "select_dm_history_chunk $list_box_2 $text_box_1 $text_box_3 $win.value2" button $win.get -text "Get History" -font button_font -command "get_dm_history $list_box_1 $list_box_2 $text_box_1 $text_box_2 $text_box_3 $win.l0.value $model $win.value" button $win.save -text "Save History" -font button_font -command "save_dm_history_data $model" button $win.load -text "Load History" -font button_font -command "load_dm_history_data $list_box_1 $list_box_2 $text_box_1 $text_box_2 $text_box_3 $win.l0.value $model $win.value" call_act_r_command record-history $model [list "retrieval-history"] bind $text_box_1 <Destroy> "call_act_r_command stop-recording-history $model [list retrieval-history] global $win.value unset $win.value global $win.value2 unset $win.value2" pack $list_scroll_bar_1 -side right -fill y pack $list_box_1 -side left -expand 1 -fill both pack $text_scroll_bar_1 -side right -fill y pack $text_scroll_bar_1a -side bottom -fill x pack $text_box_1 -side left -expand 1 -fill both pack $list_scroll_bar_2 -side right -fill y pack $list_box_2 -side left -expand 1 -fill both pack $text_scroll_bar_2 -side right -fill y pack $text_box_2 -side left -expand 1 -fill both pack $text_scroll_bar_3 -side right -fill y pack $text_scroll_bar_3a -side bottom -fill x pack $text_box_3 -side left -expand 1 -fill both place $l0 -relx 0 -y 0 -height 25 -relwidth 1.0 place $l1 -relx 0.0 -y 25 -height 25 -relwidth .12 place $list_frame_1 -relx 0.0 -y 50 -relheight .6 -height -50 -relwidth .12 place $l2 -relx .12 -y 25 -height 25 -relwidth .28 place $list_frame_2 -relx .12 -y 50 -relheight .6 -height -50 -relwidth .28 place $l3 -relx .4 -y 25 -height 25 -relwidth .60 place $text_frame_1 -relx .4 -y 50 -relheight .45 -height -50 -relwidth .60 place $l4 -relx .4 -rely .45 -height 25 -relwidth .60 place $text_frame_2 -relx .4 -rely .45 -y 25 -relheight .15 -height -25 -relwidth .60 place $l5 -relx .0 -rely .6 -height 25 -relwidth 1.0 place $text_frame_3 -relx .0 -rely .6 -y 25 -relheight .4 -height -50 -relwidth 1.0 place $win.get -relx .05 -rely 1.0 -y -25 -height 25 -relwidth .3 place $win.save -relx .35 -rely 1.0 -y -25 -height 25 -relwidth .3 place $win.load -relx .65 -rely 1.0 -y -25 -height 25 -relwidth .3 # now show the window wm deiconify $win focus $win return $win } } proc get_dm_history {lb1 lb2 tb1 tb2 tb3 label model data_var} { global $label $lb1 delete 0 end $lb2 delete 0 end $tb1 delete 1.0 end $tb2 delete 1.0 end $tb3 delete 1.0 end set any [call_act_r_command "history-data-available" $model [list "retrieval-history"]] if {$any == ""} { set $label "No Data available" } else { set $label "Collecting Data ..." set id [call_act_r_command "start-incremental-history-data" $model [list "retrieval-history" 16000 false]] if {$id != ""} { set result [get_incremental_history $id] } else { tk_messageBox -icon warning -type ok -title "Get Retrieval History warning" \ -message "Unknown problem occurred trying to get data." set $label "Data Error occurred" return "" } global $data_var unset $data_var upvar $data_var data foreach i $result { set time [expr [lindex $i 0] / 1000.0 ] $lb1 insert end $time set data($time) [lrange $i 1 end] } set $label "Retrieval History Data for model $model" } } proc dm_record_warnings {model s} { global dm_history_warnings set dm_history_warnings "$dm_history_warnings$s" return "" } proc load_dm_history_data {lb1 lb2 tb1 tb2 tb3 label model data_var} { global top_dir global $label set fname [tk_getOpenFile -title "Load Retrieval History" -initialdir $top_dir] if {$fname != ""} { set $label "" $lb1 delete 0 end $lb2 delete 0 end $tb1 delete 1.0 end $tb2 delete 1.0 end $tb3 delete 1.0 end global dm_history_warnings set dm_history_warnings "" set warning_monitor [add_new_cmd warning_monitor "dm_record_warnings" "Environment command for capturing warnings during Load Retrieval History."] send_cmd "monitor" [list "warning-trace" $warning_monitor] set id [call_act_r_command "start-incremental-history-data" $model [list "retrieval-history" 16000 $fname]] send_cmd "remove-monitor" [list "warning-trace" $warning_monitor] remove_cmd $warning_monitor if {$id == "" || $id == "null"} { tk_messageBox -icon warning -type ok -title "Load Retrieval History problem" \ -message "Get-history-data returned failure result.\n$dm_history_warnings." set $label "Failure to load data" } else { set comment [call_act_r_command "get-incremental-history-data" nil [list $id]] set result [get_incremental_history $id] global $data_var unset $data_var upvar $data_var data foreach i $result { set time [expr [lindex $i 0] / 1000.0 ] $lb1 insert end $time set data($time) [lrange $i 1 end] } set $label [json::json2dict [lindex $comment 0]] } } } proc save_dm_history_data {model} { global top_dir set fname [tk_getSaveFile -title "Save Retrieval History" -initialdir $top_dir] if {$fname != ""} { set any [call_act_r_command "history-data-available" $model [list "retrieval-history"]] if {$any == "nil" || $any == ""} { tk_messageBox -icon warning -type ok -title "Save Retrieval History warning" \ -message "No data available to save with current settings." } else { global dm_history_warnings set dm_history_warnings "" set warning_monitor [add_new_cmd warning_monitor "dm_record_warnings" "Environment command for capturing warnings during Save Retrieval History."] send_cmd "monitor" [list "warning-trace" $warning_monitor] set result [call_act_r_command_with_error_messages "save-history-data" $model [list "retrieval-history" $fname "Data saved from Retrieval History window for model $model"]] send_cmd "remove-monitor" [list "warning-trace" $warning_monitor] remove_cmd $warning_monitor if {[lindex $result 0] == 0} { tk_messageBox -icon warning -type ok -title "Save Retrieval History error" \ -message "Save-history-data resulted in error.\n[lindex $result 1]." } elseif {[lindex $result 1] == "null"} { tk_messageBox -icon warning -type ok -title "Save Retrieval History problem" \ -message "Save-history-data returned failure result.\n$dm_history_warnings." } } } } proc select_dm_history_time {lb1 lb2 tb1 tb2 tb3 data_var data_var2} { $lb2 delete 0 end $tb1 delete 1.0 end $tb2 delete 1.0 end $tb3 delete 1.0 end set selections [$lb1 curselection] if {[llength $selections] != 0} { set time [$lb1 get [lindex $selections 0]] upvar $data_var data set vals $data($time) $tb2 insert end "+retrieval>\n[lindex $vals 0]" global $data_var2 unset $data_var2 upvar $data_var2 data2 foreach i [lindex $vals 1] { set name [lindex $i 0] $lb2 insert end $name set data2($name) [lrange $i 1 end] } } } proc select_dm_history_chunk {lb2 tb1 tb3 data_var2} { $tb1 delete 1.0 end $tb3 delete 1.0 end set selections [$lb2 curselection] if {[llength $selections] != 0} { set name [$lb2 get [lindex $selections 0]] upvar $data_var2 data set vals $data($name) $tb1 insert end [lindex $vals 0] $tb1 insert end [lindex $vals 1] $tb3 insert end [lindex $vals 2] } } button [control_panel_name].retrieval_history -command make_declarative_history_viewer -text "Retrieval History" -font button_font pack [control_panel_name].retrieval_history
12,151
Common Lisp
.cl
243
41.864198
183
0.646494
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
6f45531a63a90f2d3d39bb06811a86b0144da9543e927cfe17f5cd32a65998e2
14,351
[ -1 ]
14,352
64-buffer-history.tcl
asmaloney_ACT-R/environment/GUI/dialogs/64-buffer-history.tcl
proc make_buffer_history_viewer {} { set model [currently_selected_model] if {$model == "nil"} { tk_messageBox -icon info -type ok -title "Buffer History" -message "Buffer history viewer requires a current model." } else { set win [toplevel [new_variable_name .buffer_history]] wm withdraw $win record_new_window $win $win $model wm geometry $win [get_configuration .buffer_history $win] set list_frame_1 [frame $win.list_frame_1 -borderwidth 0] set list_box_1 [listbox $list_frame_1.list_box -listvar \ $list_frame_1.list_box.var \ -yscrollcommand "$list_frame_1.list_scrl set" \ -selectmode single \ -exportselection 0 -font list_font -bd 0] set list_scroll_bar_1 [scrollbar $list_frame_1.list_scrl -command "$list_box_1 yview"] # Frame and list box for chunks set list_frame_2 [frame $win.list_frame -borderwidth 0] set list_box_2 [listbox $list_frame_2.list_box -listvar \ $list_frame_2.list_box.var \ -yscrollcommand "$list_frame_2.list_scrl set" \ -selectmode single \ -exportselection 0 -font list_font -bd 0] set list_scroll_bar_2 [scrollbar $list_frame_2.list_scrl -command "$list_box_2 yview"] # The lables for the sections set l1 [label $win.l1 -text "Times" -justify left -font label_font] set l2 [label $win.l2 -text "Buffer actions" -justify left -font label_font] set l3 [label $win.l3 -text "After Action" -justify left -font label_font] set l4 [label $win.l4 -text "Starting" -justify left -font label_font] set l5 [label $win.l5 -text "Ending" -justify left -font label_font] set l0 [label $win.l0 -text "" -font label_font -textvariable $win.l0.value] # frame for the display set text_frame_1 [frame $win.text_frame_1 -borderwidth 0] set text_box_1 [text $text_frame_1.text -yscrollcommand \ "$text_frame_1.text_scrl set" \ -xscrollcommand "$text_frame_1.text_scrl_x set" \ -font text_font -wrap none] set text_scroll_bar_1 [scrollbar $text_frame_1.text_scrl -command "$text_box_1 yview"] set text_scroll_bar_1a [scrollbar $text_frame_1.text_scrl_x -command "$text_box_1 xview" -orient horizontal] set text_frame_2 [frame $win.text_frame_2 -borderwidth 0] set text_box_2 [text $text_frame_2.text -yscrollcommand \ "$text_frame_2.text_scrl set" \ -xscrollcommand "$text_frame_2.text_scrl_x set" \ -font text_font] set text_scroll_bar_2 [scrollbar $text_frame_2.text_scrl -command "$text_box_2 yview"] set text_scroll_bar_2a [scrollbar $text_frame_2.text_scrl_x -command "$text_box_2 xview" -orient horizontal] set text_frame_3 [frame $win.text_frame_3 -borderwidth 0] set text_box_3 [text $text_frame_3.text -yscrollcommand \ "$text_frame_3.text_scrl set" \ -xscrollcommand "$text_frame_3.text_scrl_x set" \ -font text_font -wrap none] # create the scroll bar for the text box set text_scroll_bar_3 [scrollbar $text_frame_3.text_scrl -command "$text_box_3 yview"] set text_scroll_bar_3a [scrollbar $text_frame_3.text_scrl_x -command "$text_box_3 xview" -orient horizontal] global $win.value set $win.value "" global $win.value2 set $win.value2 "" bind $list_box_1 <<ListboxSelect>> "select_buffer_history_time $list_box_1 $list_box_2 $text_box_1 $text_box_2 $text_box_3 $win.value $win.value2" bind $list_box_2 <<ListboxSelect>> "select_buffer_history_action $list_box_2 $text_box_1 $text_box_2 $text_box_3 $win.value2" button $win.get -text "Get History" -font button_font -command "get_buffer_history $list_box_1 $list_box_2 $text_box_1 $text_box_2 $text_box_3 $win.l0.value $model $win.value" button $win.save -text "Save History" -font button_font -command "save_buffer_history_data $model" button $win.load -text "Load History" -font button_font -command "load_buffer_history_data $list_box_1 $list_box_2 $text_box_1 $text_box_2 $text_box_3 $win.l0.value $model $win.value" call_act_r_command record-history $model [list "buffer-history"] bind $text_box_1 <Destroy> "call_act_r_command stop-recording-history $model [list buffer-history] global $win.value unset $win.value global $win.value2 unset $win.value2" pack $list_scroll_bar_1 -side right -fill y pack $list_box_1 -side left -expand 1 -fill both pack $list_scroll_bar_2 -side right -fill y pack $list_box_2 -side left -expand 1 -fill both pack $text_scroll_bar_1 -side right -fill y pack $text_scroll_bar_1a -side bottom -fill x pack $text_box_1 -side left -expand 1 -fill both pack $text_scroll_bar_2 -side right -fill y pack $text_scroll_bar_2a -side bottom -fill x pack $text_box_2 -side left -expand 1 -fill both pack $text_scroll_bar_3 -side right -fill y pack $text_scroll_bar_3a -side bottom -fill x pack $text_box_3 -side left -expand 1 -fill both place $l0 -relx 0 -y 0 -height 25 -relwidth 1.0 place $l1 -relx 0.0 -y 25 -height 25 -relwidth .3 place $list_frame_1 -relx 0.0 -y 50 -relheight .4 -height -50 -relwidth .3 place $l2 -relx .3 -y 25 -height 25 -relwidth .7 place $list_frame_2 -relx .3 -y 50 -relheight .4 -height -50 -relwidth .7 place $l3 -relx 0.0 -rely .4 -height 25 -relwidth .34 place $text_frame_1 -relx 0.0 -rely .4 -y 25 -relheight .6 -height -50 -relwidth .34 place $l4 -relx 0.34 -rely .4 -height 25 -relwidth .33 place $text_frame_2 -relx 0.34 -rely .4 -y 25 -relheight .6 -height -50 -relwidth .33 place $l5 -relx 0.67 -rely .4 -height 25 -relwidth .33 place $text_frame_3 -relx 0.67 -rely .4 -y 25 -relheight .6 -height -50 -relwidth .33 place $win.get -relx .05 -rely 1.0 -y -25 -height 25 -relwidth .3 place $win.save -relx .35 -rely 1.0 -y -25 -height 25 -relwidth .3 place $win.load -relx .65 -rely 1.0 -y -25 -height 25 -relwidth .3 # now show the window wm deiconify $win return $win } } proc get_buffer_history {lb1 lb2 tb1 tb2 tb3 label model data_var} { global $label $lb1 delete 0 end $lb2 delete 0 end $tb1 delete 1.0 end $tb2 delete 1.0 end $tb3 delete 1.0 end set any [call_act_r_command "history-data-available" $model [list "buffer-history"]] if {$any == ""} { set $label "No Data available" } else { set $label "Collecting Data ..." set id [call_act_r_command "start-incremental-history-data" $model [list "buffer-history" 16000 false]] if {$id != ""} { set result [get_incremental_history $id] } else { tk_messageBox -icon warning -type ok -title "Get Buffer History warning" \ -message "Unknown problem occurred trying to get data." set $label "Data Error occurred" return "" } global $data_var unset $data_var upvar $data_var data foreach i $result { set time [expr [lindex $i 0] / 1000.0 ] $lb1 insert end $time set data($time) [lindex $i 1] } set $label "Buffer History Data for model $model" } } proc buffer_record_warnings {model s} { global buffer_history_warnings set buffer_history_warnings "$buffer_history_warnings$s" return "" } proc load_buffer_history_data {lb1 lb2 tb1 tb2 tb3 label model data_var} { global top_dir global $label set fname [tk_getOpenFile -title "Load Buffer History" -initialdir $top_dir] if {$fname != ""} { set $label "" $lb1 delete 0 end $lb2 delete 0 end $tb1 delete 1.0 end $tb2 delete 1.0 end $tb3 delete 1.0 end global buffer_history_warnings set buffer_history_warnings "" set warning_monitor [add_new_cmd warning_monitor "buffer_record_warnings" "Environment command for capturing warnings during Load Buffer History."] send_cmd "monitor" [list "warning-trace" $warning_monitor] set id [call_act_r_command "start-incremental-history-data" $model [list "buffer-history" 16000 $fname]] send_cmd "remove-monitor" [list "warning-trace" $warning_monitor] remove_cmd $warning_monitor if {$id == "" || $id == "null"} { tk_messageBox -icon warning -type ok -title "Load Buffer History problem" \ -message "Get-history-data returned failure result.\n$buffer_history_warnings." set $label "Failure to load data" } else { set comment [call_act_r_command "get-incremental-history-data" nil [list $id]] set result [get_incremental_history $id] global $data_var unset $data_var upvar $data_var data foreach i $result { set time [expr [lindex $i 0] / 1000.0 ] $lb1 insert end $time set data($time) [lindex $i 1] } set $label [json::json2dict [lindex $comment 0]] } } } proc save_buffer_history_data {model} { global top_dir set fname [tk_getSaveFile -title "Save Buffer History" -initialdir $top_dir] if {$fname != ""} { set any [call_act_r_command "history-data-available" $model [list "buffer-history"]] if {$any == "nil" || $any == ""} { tk_messageBox -icon warning -type ok -title "Save Buffer History warning" \ -message "No data available to save with current settings." } else { global buffer_history_warnings set buffer_history_warnings "" set warning_monitor [add_new_cmd warning_monitor "buffer_record_warnings" "Environment command for capturing warnings during Save Buffer History."] send_cmd "monitor" [list "warning-trace" $warning_monitor] set result [call_act_r_command_with_error_messages "save-history-data" $model [list "buffer-history" $fname "Data saved from Buffer History window for model $model"]] send_cmd "remove-monitor" [list "warning-trace" $warning_monitor] remove_cmd $warning_monitor if {[lindex $result 0] == 0} { tk_messageBox -icon warning -type ok -title "Save Buffer History error" \ -message "Get-history-data resulted in error.\n[lindex $result 1]." } elseif {[lindex $result 1] == "null"} { tk_messageBox -icon warning -type ok -title "Save Buffer History problem" \ -message "Get-history-data returned failure result.\n$buffer_history_warnings." } } } } proc select_buffer_history_time {lb1 lb2 tb1 tb2 tb3 data_var data_var2} { $lb2 delete 0 end $tb1 delete 1.0 end $tb2 delete 1.0 end $tb3 delete 1.0 end set selections [$lb1 curselection] if {[llength $selections] != 0} { set time [$lb1 get [lindex $selections 0]] upvar $data_var data set vals $data($time) global $data_var2 unset $data_var2 upvar $data_var2 data2 set index 0 foreach i $vals { set name [lindex $i 0] set action [lindex $i 1] $lb2 insert end "$name $action" set data2($index) [lrange $i 1 end] incr index } } } proc select_buffer_history_action {lb2 tb1 tb2 tb3 data_var2} { $tb1 delete 1.0 end $tb2 delete 1.0 end $tb3 delete 1.0 end set selections [$lb2 curselection] if {[llength $selections] != 0} { set index [lindex $selections 0] upvar $data_var2 data set vals $data($index) $tb1 insert end [lindex $vals 0] $tb1 insert end "\n " $tb1 insert end [lindex $vals 1] $tb1 insert end "\n" $tb1 insert end [lindex $vals 2] $tb2 insert end [lindex $vals 3] $tb2 insert end "\n" $tb2 insert end [lindex $vals 4] $tb3 insert end [lindex $vals 5] $tb3 insert end "\n" $tb3 insert end [lindex $vals 6] } } button [control_panel_name].buffer_history -command make_buffer_history_viewer -text "Buffer History" -font button_font pack [control_panel_name].buffer_history
12,292
Common Lisp
.cl
248
41.5
187
0.643244
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
ab0e4ba88ff56132cff6c69347f442c67dd80144ebef3dee68727a889774c75b
14,352
[ -1 ]
14,353
999-emma-eye-spot.tcl
asmaloney_ACT-R/environment/GUI/dialogs/999-emma-eye-spot.tcl
# This file is an extension for the ACT-R Environment to show # the location of the eye spot from the EMMA module in extras # in the visible virtual windows using the agi handlers # mechanism. proc emma_agi_change {cmd win coords params} { if {$win != "" && [$win.can gettags all] != ""} { $win.can raise eyeloc all } } add_agi_handler agi_change emma_agi_change proc emma_eyeloc {cmd win coords params} { $win.can delete "[lindex $params 0]-eyeloc" set x [lindex $params 1] set y [lindex $params 2] if { $x >= [lindex $coords 0] && $x <= [expr [lindex $coords 0] + [lindex $coords 2]] && $y >= [lindex $coords 1] && $y <= [expr [lindex $coords 1] + [lindex $coords 3]]} { $win.can create oval [expr $x - 5 - [lindex $coords 0]] [expr $y - 5 - [lindex $coords 1]] [expr $x + 5 - [lindex $coords 0]] [expr $y + 5 - [lindex $coords 1]] -outline [translate_color [lindex $params 4]] -width 3 -tags [list "[lindex $params 0]-eyeloc" eyeloc] } } add_agi_handler eyeloc emma_eyeloc proc emma_cleareyeloc {cmd win coords params} { $win.can delete "[lindex $params 0]-eyeloc" } add_agi_handler cleareyeloc emma_cleareyeloc
1,195
Common Lisp
.cl
23
47.521739
268
0.658195
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
68b0fded65425577b52b0746f6df69f958c6751092d3ed7ce29e75a86205374a
14,353
[ -1 ]
14,354
21a-event-queue.tcl
asmaloney_ACT-R/environment/GUI/dialogs/21a-event-queue.tcl
proc select_event_queue {} { if {[winfo exists .event_queue] == 1} { wm deiconify .event_queue raise .event_queue } else { # make it now toplevel .event_queue wm withdraw .event_queue wm geometry .event_queue [get_configuration .event_queue] set f [frame .event_queue.frame -borderwidth 0] set t [text $f.text -font text_font -yscrollcommand "$f.scrl set" -state disabled] set s [scrollbar $f.scrl -command "$t yview"] # set new_tags [concat [list [new_variable_name "focus_tag"]] [bindtags .event_queue]] # bindtags .event_queue $new_tags # bind [lindex $new_tags 0] <FocusIn> { # catch {update_text_pane .event_queue.frame.text [lindex [call_act_r_command "mp-queue-text" nil 1] 0]} # } set_update_script .event_queue {update_text_pane .event_queue.frame.text [lindex [call_act_r_command "mp-queue-text" nil 1] 0]} pack $s -side right -fill y pack $t -side left -expand 1 -fill both place $f -x 0 -y 0 -relwidth 1.0 -relheight 1.0 # now show the window wm deiconify .event_queue focus .event_queue } } button [control_panel_name].event_queue_button \ -command {select_event_queue} -text "Event Queue" -font button_font pack [control_panel_name].event_queue_button
1,303
Common Lisp
.cl
29
39.793103
131
0.677419
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
4a25853d61e25cc5cd856562d56b0285202dec3cc0651ea4acc59c937242ef7a
14,354
[ -1 ]
14,355
22-ctrl-panel-reset-buttons.tcl
asmaloney_ACT-R/environment/GUI/dialogs/22-ctrl-panel-reset-buttons.tcl
global reload_return global during_reload set during_reload 0 frame [control_panel_name].r_frame -borderwidth 0 set reset_warnings "" proc record_reset_warnings {model s} { global reset_warnings set reset_warnings "$reset_warnings$s" return "" } button [control_panel_name].r_frame.reset -text "Reset" -font button_font -command { global reset_warnings [control_panel_name].r_frame.reset configure -state disabled set reset_warnings "" set reset_monitor [add_new_cmd reset_monitor "record_reset_warnings" "Environment command for capturing warnings during a call to reset."] send_cmd "monitor" [list "warning-trace" $reset_monitor] set result [call_act_r_command_with_error_messages "reset"] send_cmd "remove-monitor" [list "warning-trace" $reset_monitor] remove_cmd $reset_monitor if {[lindex $result 0] == 0} { tk_messageBox -icon warning -type ok -title "Reset Error" \ -message [lindex $result 1] } elseif {[lindex $result 1] == "null"} { tk_messageBox -icon warning -type ok -title "Reset Error" \ -message $reset_warnings } else { call_act_r_command "act-r-output" "nil" [list [format "#|## ACT-R has been Reset ##|#"]] } set reset_warnings "" [control_panel_name].r_frame.reset configure -state normal } button [control_panel_name].r_frame.reload -text "Reload" -font button_font -command { global options_array global during_reload global reset_warnings set during_reload 1 [control_panel_name].r_frame.reload configure -state disabled set reset_warnings "" global currently_open_files if {$options_array(save_before_reload) == 1 && [array exists currently_open_files]} { foreach win [array names currently_open_files] { save_model $win } } set reload_monitor [add_new_cmd reload_monitor "record_reset_warnings" "Environment command for capturing output during a call to reload."] send_cmd "monitor" [list "model-trace" $reload_monitor] send_cmd "monitor" [list "command-trace" $reload_monitor] send_cmd "monitor" [list "warning-trace" $reload_monitor] send_cmd "monitor" [list "general-trace" $reload_monitor] if {$options_array(use_smart_load) == "t"} { set result [call_act_r_command_with_error_messages "reload" nil [list $options_array(use_smart_load)]] } else { set result [call_act_r_command_with_error_messages "reload"] } send_cmd "remove-monitor" [list "model-trace" $reload_monitor] send_cmd "remove-monitor" [list "command-trace" $reload_monitor] send_cmd "remove-monitor" [list "warning-trace" $reload_monitor] send_cmd "remove-monitor" [list "general-trace" $reload_monitor] remove_cmd $reload_monitor set win [toplevel [new_variable_name .reload_response]] # hide the window for speed and aesthetic reasons wm withdraw $win wm geometry $win [get_configuration .reload_response $win] set text_frame [frame $win.text_frame -borderwidth 0] set text_box [text $text_frame.text -yscrollcommand \ "$text_frame.text_scrl set" -state normal \ -font text_font] set text_scroll_bar [scrollbar $text_frame.text_scrl \ -command "$text_box yview"] set the_button [button $win.but -text "Ok" -command "destroy $win" -font button_font] place $text_frame -x 0 -y 0 -relheight 1.0 -height -30 -relwidth 1.0 place $the_button -relx .5 -x -30 -width 60 -rely 1.0 -y -30 -height 30 pack $text_scroll_bar -side right -fill y pack $text_box -side left -expand 1 -fill both if {[lindex $result 0] == 0} { wm title $win "ERROR Reloading" $text_box insert 1.0 "$reset_warnings\n[lindex $result 1]" } elseif {[lindex $result 1] == "null"} { wm title $win "ERROR Reloading" $text_box insert 1.0 "$reset_warnings" } else { wm title $win "SUCCESSFUL Reload" $text_box insert 1.0 "$reset_warnings" call_act_r_command "act-r-output" "nil" [list [format "#|## Reload Complete ##|#"]] } set during_reload 0 [control_panel_name].r_frame.reload configure -state normal wm deiconify $win focus $win } pack [control_panel_name].r_frame.reset -side left pack [control_panel_name].r_frame.reload -side right pack [control_panel_name].r_frame
4,301
Common Lisp
.cl
93
41.215054
141
0.700606
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
28cd1ad04d0f9da7e12ca0426e82ada5c94f1f1e7530702c8cb8745975d1a710
14,355
[ -1 ]
14,356
70-ctrl-panel-recorded-label.tcl
asmaloney_ACT-R/environment/GUI/dialogs/70-ctrl-panel-recorded-label.tcl
label [control_panel_name].recorded_label -text "Buffer Based\nRecordable Data" -font label_font pack [control_panel_name].recorded_label
139
Common Lisp
.cl
2
68
96
0.808824
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
ed30ca21ec537ddd1d7c8f46cf7ea621c834a8f1e8008d79b7a9de98b682cab0
14,356
[ -1 ]
14,357
38-visicon.tcl
asmaloney_ACT-R/environment/GUI/dialogs/38-visicon.tcl
proc select_visicon {} { set model [currently_selected_model] if {$model == "nil"} { tk_messageBox -icon info -type ok -title "Visicon" -message "Inspector tools require a current model." } else { set win ".visicon_$model" if {[winfo exists $win] == 1} { wm deiconify $win raise $win } else { toplevel $win wm withdraw $win record_new_window $win "Visicon" $model wm geometry $win [get_configuration .visicon $win] set f [frame $win.frame -borderwidth 0] set t [text $f.text -font text_font -yscrollcommand "$f.scrl set" -state disabled] set s [scrollbar $f.scrl -command "$t yview"] pack $s -side right -fill y pack $t -side left -expand 1 -fill both place $f -x 0 -y 0 -relwidth 1.0 -relheight 1.0 set_update_script $win "update_visicon_view $t $model" wm deiconify $win focus $win } } } proc update_visicon_view {text model} { update_text_pane $text [lindex [call_act_r_command "printed-visicon" $model] 0] } button [control_panel_name].visicon_button \ -command {select_visicon} -text "Visicon" -font button_font pack [control_panel_name].visicon_button
1,225
Common Lisp
.cl
32
32.0625
106
0.654278
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
78addeb6b38b337b062d1bb968b0a427a00360fc03c68e8551e70ebd1a7fb1ca
14,357
[ -1 ]
14,358
39-audicon.tcl
asmaloney_ACT-R/environment/GUI/dialogs/39-audicon.tcl
proc select_audicon {} { set model [currently_selected_model] if {$model == "nil"} { tk_messageBox -icon info -type ok -title "Audicon" -message "Inspector tools require a current model." } else { set win ".audicon_$model" if {[winfo exists $win] == 1} { wm deiconify $win raise $win } else { toplevel $win wm withdraw $win record_new_window $win "Audicon" $model wm geometry $win [get_configuration .audicon $win] set f [frame $win.frame -borderwidth 0] set t [text $f.text -font text_font -yscrollcommand "$f.scrl set" -state disabled] set s [scrollbar $f.scrl -command "$t yview"] pack $s -side right -fill y pack $t -side left -expand 1 -fill both place $f -x 0 -y 0 -relwidth 1.0 -relheight 1.0 set_update_script $win "update_audicon_view $t $model" wm deiconify $win focus $win } } } proc update_audicon_view {text model} { update_text_pane $text [lindex [call_act_r_command "printed-audicon" $model] 0] } button [control_panel_name].audicon_button \ -command {select_audicon} -text "Audicon" -font button_font pack [control_panel_name].audicon_button
1,226
Common Lisp
.cl
32
32.0625
106
0.654278
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
3d9b174dde3d1428679bb74f3a63c8c97fd6b30cefa9ccdfafd0cf396eed5d8b
14,358
[ -1 ]
14,359
37-buffer-viewer.tcl
asmaloney_ACT-R/environment/GUI/dialogs/37-buffer-viewer.tcl
proc make_buffer_viewer {} { set model [currently_selected_model] if {$model == "nil"} { tk_messageBox -icon info -type ok -title "Buffer Viewer" -message "Inspector tools require a current model." } else { set win [toplevel [new_variable_name .buffers]] wm withdraw $win record_new_window $win $win $model wm geometry $win [get_configuration .buffers $win] set list_frame [frame $win.list_frame -borderwidth 2] set list_box [listbox $list_frame.list_box \ -listvar $list_frame.list_box.var \ -yscrollcommand "$list_frame.list_scrl set" \ -selectmode single \ -exportselection 0 -font list_font -bd 0] set list_scroll_bar [scrollbar $list_frame.list_scrl -command "$list_box yview"] set other_frame [frame $win.other_frame -borderwidth 0] set text_frame [frame $other_frame.text_frame -borderwidth 0] set b1 [button $other_frame.contents -text "Contents" -font button_font -foreground black -relief raised] set b2 [button $other_frame.status -text "Status" -font button_font -foreground gray -relief sunken] set var [new_variable_name buffer_state] upvar #0 $var s set s "contents" set text_box [text $text_frame.text -yscrollcommand \ "$text_frame.text_scrl set" -state disabled \ -font text_font] $b1 configure -command "switch_buffer_view $b1 $b2 $var contents $list_box $text_box $model" $b2 configure -command "switch_buffer_view $b2 $b1 $var status $list_box $text_box $model" global tcl_platform if {$tcl_platform(os) == "Darwin"} { $b1 configure -state active } bind $list_box <<ListboxSelect>> "select_buffer_viewer $list_box $text_box $model $var" set text_scroll_bar [scrollbar $text_frame.text_scrl -command "$text_box yview"] place $list_frame -relx 0.0 -rely 0.0 -relheight 1.0 -relwidth .4 place $other_frame -relx .4 -rely 0.0 -relheight 1.0 -relwidth .6 pack $list_scroll_bar -side right -fill y pack $list_box -side left -expand 1 -fill both place $b1 -x 0 -y 0 -height 25 -relwidth .5 place $b2 -relx .5 -y 0 -height 25 -relwidth .5 place $text_frame -x 0 -y 25 -relheight 1.0 -height -25 -relwidth 1.0 pack $text_scroll_bar -side right -fill y pack $text_box -side left -expand 1 -fill both set_update_script $win "update_buffers_list $list_box $text_box $model $var" wm deiconify $win focus $win } } proc switch_buffer_view {b1 b2 var state lb tb m} { global tcl_platform if {$tcl_platform(os) == "Darwin"} { $b1 configure -state active $b2 configure -state normal } else { $b1 configure -relief raised -foreground black $b2 configure -relief sunken -foreground gray } upvar #0 $var x set x $state select_buffer_viewer $lb $tb $m $var } proc update_buffers_list {list text_box model var} { set buffers [lindex [call_act_r_command "model-buffers" $model [list 1]] 0] global options_array if {$options_array(sort_lists) == 1} { set buffers [lsort -dictionary $buffers] } global $list.var set selection [$list curselection] if {$selection != ""} { set name [$list get $selection] } set $list.var $buffers if {$selection != ""} { # check if the selection is still available $list selection clear 0 end set newpos [lsearch -exact $buffers $name] if {$newpos != -1} { $list selection set $newpos } } select_buffer_viewer $list $text_box $model $var } proc select_buffer_viewer {list_box text_box model var} { upvar #0 $var mode if {[$list_box curselection] != ""} { if {$mode == "contents"} { if {[lindex [call_act_r_command "buffer-read" $model [list [$list_box get [$list_box curselection]]]] 0] == ""} { if {[lindex [call_act_r_command "multi-buffer-p" $model [list [$list_box get [$list_box curselection]]]] 0] == ""} { update_text_pane $text_box "Buffer is empty" } else { set text "Empty multi-buffer\nPossible chunks are:\n" foreach c [call_act_r_command "get-m-buffer-chunks" $model [list [$list_box get [$list_box curselection]]]] { set text "$text[lindex [call_act_r_command "printed-chunk" $model [list $c]] 0]\n" } update_text_pane $text_box $text } } else { update_text_pane $text_box [lindex [call_act_r_command "printed-buffer-chunk" $model [list [$list_box get [$list_box curselection]]]] 0] } } else { update_text_pane $text_box [lindex [call_act_r_command "printed-buffer-status" $model [list [$list_box get [$list_box curselection]]]] 0] } } else { update_text_pane $text_box "" } } # Make a button for the control panel that will open a new buffer viewer button [control_panel_name].buffers -command {make_buffer_viewer} -text "Buffers" -font button_font # put that button on the control panel pack [control_panel_name].buffers
5,067
Common Lisp
.cl
111
39.207207
144
0.652289
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
bbe1630cb75278bfb9da5d62c7657786a747a8e03fc949aa7a615ee03e2d33f2
14,359
[ -1 ]
14,360
81-bold-button.tcl
asmaloney_ACT-R/environment/GUI/dialogs/81-bold-button.tcl
set bold_view_table [dict create] frame [control_panel_name].bold_display -borderwidth 0 button [control_panel_name].bold_display.show_trace -command display_bold_trace -text "BOLD" -font button_font tk_optionMenu [control_panel_name].bold_display.which_trace current_bold_trace "" [control_panel_name].bold_display.which_trace configure -font checkbox_font [[control_panel_name].bold_display.which_trace cget -menu] configure -font checkbox_font pack [control_panel_name].bold_display.which_trace -side right pack [control_panel_name].bold_display.show_trace -side left pack [control_panel_name].bold_display proc display_bold_trace {} { global current_bold_trace global bold_view_table if [dict exists $bold_view_table $current_bold_trace] { set cmd [dict get $bold_view_table $current_bold_trace] $cmd } else { tk_messageBox -title "No BOLD trace" -message "No BOLD trace type selected." -icon warning -type ok } } proc add_bold_trace_type {title cmd} { global current_bold_trace global bold_view_table set menu [[control_panel_name].bold_display.which_trace cget -menu] set top [$menu entrycget 0 -value] $menu add radiobutton -label $title -variable current_bold_trace if {$top == ""} { $menu delete "" set current_bold_trace $title } dict set bold_view_table $title $cmd }
1,351
Common Lisp
.cl
31
40.258065
110
0.752124
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
0ae959abdd24846292fa844d0369c3cd953d7fa24a44fa15f16af310b103b5f0
14,360
[ -1 ]
14,361
23a-ctrl-panel-running-indicator.tcl
asmaloney_ACT-R/environment/GUI/dialogs/23a-ctrl-panel-running-indicator.tcl
frame [control_panel_name].run_display -borderwidth 0 label [control_panel_name].run_display.running_indicator -text "-------" -font label_font -foreground black -width 7 checkbutton [control_panel_name].run_display.enable_running -text "Show Run State" -font checkbox_font \ -variable check_running -command {change_running_indicator} pack [control_panel_name].run_display.running_indicator -side left pack [control_panel_name].run_display.enable_running -side right pack [control_panel_name].run_display set check_running 0 set run_indicator "[control_panel_name].run_display.running_indicator" proc indicate_running {model time} { global run_indicator $run_indicator configure -text "Running" -foreground darkgreen } proc indicate_not_running {model time} { global run_indicator $run_indicator configure -text "Stopped" -foreground red } set x [add_new_cmd running_indicator "indicate_running" "Environment command for detecting that ACT-R is running to display on control panel."] set runnig_indicator_start_fct $x set x [add_new_cmd run_stop_indicator "indicate_not_running" "Environment command for detecting that ACT-R has stopped running to display on control panel."] set runnig_indicator_stop_fct $x proc enable_running_indicator {} { global runnig_indicator_stop_fct global runnig_indicator_start_fct send_cmd "monitor" [list "run-stop" $runnig_indicator_stop_fct] send_cmd "monitor" [list "run-start" $runnig_indicator_start_fct] } proc disable_running_indicator {} { global runnig_indicator_stop_fct global runnig_indicator_start_fct global run_indicator $run_indicator configure -text "-------" -foreground black send_cmd "remove-monitor" [list "run-stop" $runnig_indicator_stop_fct] send_cmd "remove-monitor" [list "run-start" $runnig_indicator_start_fct] } proc change_running_indicator {} { global check_running if $check_running { enable_running_indicator } else { disable_running_indicator } }
2,078
Common Lisp
.cl
43
43.488372
158
0.752911
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
60cdc76c6e4da394f9eb253613bcda599cf7063282531d22bdf1295317eca6e3
14,361
[ -1 ]
14,362
66-perceptual-history.tcl
asmaloney_ACT-R/environment/GUI/dialogs/66-perceptual-history.tcl
proc make_percept_history_viewer {name window cmd} { set model [currently_selected_model] if {$model == "nil"} { tk_messageBox -icon info -type ok -title "$name History" -message "$name history viewer requires a current model." } else { set win [toplevel [new_variable_name $window]] wm withdraw $win record_new_window $win $win $model wm geometry $win [get_configuration $window $win] # frame and list box for times set list_frame_1 [frame $win.list_frame_1 -borderwidth 0] set list_box_1 [listbox $list_frame_1.list_box -listvar \ $list_frame_1.list_box.var \ -yscrollcommand "$list_frame_1.list_scrl set" \ -selectmode single \ -exportselection 0 -font list_font -bd 0] set list_scroll_bar_1 [scrollbar $list_frame_1.list_scrl -command "$list_box_1 yview"] # The lables for the sections set l1 [label $win.l1 -text "Times" -justify left -font label_font] set l3 [label $win.l3 -text "" -justify left -font label_font -textvariable $win.l3.value] # frame for the display set text_frame_1 [frame $win.text_frame_1 -borderwidth 0] set text_box_1 [text $text_frame_1.text -yscrollcommand "$text_frame_1.text_scrl set" \ -xscrollcommand "$text_frame_1.hscrl set" \ -wrap none -font text_font] # create the scroll bars for the text box set text_scroll_bar_1 [scrollbar $text_frame_1.text_scrl -command "$text_box_1 yview"] set h_scrl_bar [scrollbar $text_frame_1.hscrl -command "$text_box_1 xview" -orient horizontal] # hold the history info when it's gotten global $win.data set $win.data "" # make the selection list call the display updater for the audicon bind $list_box_1 <<ListboxSelect>> "select_percept_history $list_box_1 $text_box_1 $win.data" button $win.get -text "Get History" -font button_font -command "get_percept_history_data $cmd $name $list_box_1 $text_box_1 $win.l3.value $model $win.data" button $win.save -text "Save History" -font button_font -command "save_percept_history_data $cmd $name $model" button $win.load -text "Load History" -font button_font -command "load_percept_history_data $cmd $name $list_box_1 $text_box_1 $win.l3.value $model $win.data" pack $list_scroll_bar_1 -side right -fill y pack $list_box_1 -side left -expand 1 -fill both pack $text_scroll_bar_1 -side right -fill y pack $h_scrl_bar -side bottom -fill x pack $text_box_1 -side left -expand 1 -fill both place $l1 -relx 0.0 -y 0 -height 25 -relwidth .10 place $list_frame_1 -relx 0.0 -y 25 -relheight 1.0 -height -50 -relwidth .10 place $l3 -relx .1 -y 0 -height 25 -relwidth .9 place $text_frame_1 -relx .1 -y 25 -relheight 1.0 -height -50 -relwidth .9 place $win.get -relx .05 -rely 1.0 -y -25 -height 25 -relwidth .3 place $win.save -relx .35 -rely 1.0 -y -25 -height 25 -relwidth .3 place $win.load -relx .65 -rely 1.0 -y -25 -height 25 -relwidth .3 # record the appropriate history info call_act_r_command record-history $model [list $cmd] bind $text_box_1 <Destroy> "call_act_r_command stop-recording-history $model [list $cmd] global $win.data unset $win.data" # now show the window wm deiconify $win focus $win return $win } } proc get_percept_history_data {cmd name timelst txt label model data_var} { global $label $timelst delete 0 end $txt delete 1.0 end set any [call_act_r_command "history-data-available" $model [list $cmd]] if {$any == ""} { set $label "No Data available" } else { set $label "Collecting Data ..." set id [call_act_r_command "start-incremental-history-data" $model [list $cmd 16000 false]] if {$id != ""} { set result [get_incremental_history $id] } else { tk_messageBox -icon warning -type ok -title "Get $name History warning" \ -message "Unknown problem occurred trying to get data." set $label "Data Error occurred" return "" } global $data_var unset $data_var upvar $data_var data foreach i $result { set time [expr [lindex $i 0] / 1000.0 ] $timelst insert end $time set txt "" foreach j [lrange $i 1 end] { append txt $j } set data($time) $txt } set $label $name } } proc percept_record_warnings {model s} { global percept_history_warnings set percept_history_warnings "$percept_history_warnings$s" return "" } proc load_percept_history_data {cmd name timelst txt label model data_var} { global top_dir global $label set fname [tk_getOpenFile -title "Load $name History" -initialdir $top_dir] if {$fname != ""} { set $label "" $timelst delete 0 end $txt delete 1.0 end global percept_history_warnings set percept_history_warnings "" set warning_monitor [add_new_cmd warning_monitor "percept_record_warnings" "Environment command for capturing warnings during Load $name History."] send_cmd "monitor" [list "warning-trace" $warning_monitor] set id [call_act_r_command "start-incremental-history-data" $model [list $cmd 16000 $fname]] send_cmd "remove-monitor" [list "warning-trace" $warning_monitor] remove_cmd $warning_monitor if {$id == "" || $id == "null"} { tk_messageBox -icon warning -type ok -title "Load $name History problem" \ -message "Get-history-data returned failure result.\n$percept_history_warnings." } else { set comment [call_act_r_command "get-incremental-history-data" nil [list $id]] set result [get_incremental_history $id] global $data_var unset $data_var upvar $data_var data foreach i $result { set time [expr [lindex $i 0] / 1000.0 ] $timelst insert end $time set txt "" foreach j [lrange $i 1 end] { append txt $j } set data($time) $txt } set $label [json::json2dict [lindex $comment 0]] } } } proc save_percept_history_data {cmd name model} { global top_dir global percept_history_warnings set fname [tk_getSaveFile -title "Save $name History" -initialdir $top_dir] if {$fname != ""} { set any [call_act_r_command "history-data-available" $model [list $cmd]] if {$any == "nil" || $any == ""} { tk_messageBox -icon warning -type ok -title "Save $name History warning" \ -message "No data available to save with current settings." } else { set percept_history_warnings "" set warning_monitor [add_new_cmd warning_monitor "percept_record_warnings" "Environment command for capturing warnings during Save $name History."] send_cmd "monitor" [list "warning-trace" $warning_monitor] set result [call_act_r_command_with_error_messages "save-history-data" $model [list $cmd $fname "Data saved from $name History window for model $model."]] send_cmd "remove-monitor" [list "warning-trace" $warning_monitor] remove_cmd $warning_monitor if {[lindex $result 0] == 0} { tk_messageBox -icon warning -type ok -title "Save $name History error" \ -message "Save-history-data resulted in error.\n[lindex $result 1]." } elseif {[lindex $result 1] == "null"} { tk_messageBox -icon warning -type ok -title "Save $name History problem" \ -message "Save-history-data returned failure result.\n$percept_history_warnings." } } } } proc select_percept_history {timelst text data_var} { $text delete 1.0 end upvar $data_var data set selections [$timelst curselection] if {[llength $selections] != 0} { set time [$timelst get [lindex $selections 0]] $text insert 1.0 $data($time) } } button [control_panel_name].audicon_history -command {make_percept_history_viewer "Audicon" ".audicon_history" "audicon-history"} -text "Audicon History" -font button_font button [control_panel_name].visicon_history -command {make_percept_history_viewer "Visicon" ".visicon_history" "visicon-history"} -text "Visicon History" -font button_font # put that button on the control panel pack [control_panel_name].audicon_history pack [control_panel_name].visicon_history
8,583
Common Lisp
.cl
174
41.465517
171
0.653963
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
2bb5e5f18e2fdfc3c77117da410899c346978bdb808e03739c74e88b203d23b6
14,362
[ -1 ]
14,363
83-bold-brain-3d.tcl
asmaloney_ACT-R/environment/GUI/dialogs/83-bold-brain-3d.tcl
# The 3d code in this file was found on the Tcl/Tk Wiki (wiki.tcl.tk). # It's been stripped down and modified specifically for # use with the brain viewer, but the original file name # and author are: # # 3dviewer.tcl # # Author : Mark B. Stucky set voxel_colors [list "#f00" "#090" "#00f" "#aa0" "#0aa" "#a0a" "#0e0" "#36a"] proc main_bold_brains {} { set model [currently_selected_model] if {$model == "nil"} { tk_messageBox -icon info -type ok -title "BOLD brain" -message "BOLD brain viewer requires a current model." } else { global voxel_colors global gvar set win [toplevel [new_variable_name .bold_brain_3d]] wm withdraw $win record_new_window $win $win $model wm geometry $win [get_configuration .bold_brain_3d $win] set gvar($win,Xscreen) 750 set gvar($win,Yscreen) 500 set gvar($win,rho) 5. set gvar($win,theta) 0.0 set gvar($win,phi) 0.0 set gvar($win,dist) 1200.0 set gvar($win,x,translate) 0.0 set gvar($win,y,translate) 0.0 set gvar($win,look_at) [list 0.0 0.0 0.0] set pi [expr {4.0 * atan(1.0)}] set mpi [expr {-1.0 * $pi}] set gvar($win,pi) $pi set gvar($win,mpi) $mpi set gvar($win,twopi) [expr {2.0 * $pi}] set gvar($win,theta_light) 0.0 set gvar($win,phi_light) 0.0 set gvar($win,colors) [list none none none none none none none none] canvas $win.c -width 650 -height 500 -bg black -bd 0 set gvar($win,canv) $win.c bind $win.c <ButtonPress-1> "canvas_rotate_start $win %W %x %y" bind $win.c <B1-Motion> "canvas_rotate_drag $win %W %x %y" bind $win.c <ButtonRelease-1> "canvas_rotate_end $win %W %x %y" bind $win.c <ButtonPress-2> "canvas_pan_start $win %W %x %y" bind $win.c <B2-Motion> "canvas_pan_drag $win %W %x %y" bind $win.c <ButtonRelease-2> "canvas_pan_end $win %W %x %y" bind $win.c <ButtonPress-3> "canvas_zoom_start $win %W %x %y" bind $win.c <B3-Motion> "canvas_zoom_drag $win %W %x %y" bind $win.c <ButtonRelease-3> "canvas_zoom_end $win %W %x %y" global $win.data set $win.data "" call_act_r_command record-history $model [list "bold-prediction-with-time-scaled"] bind $win.c <Destroy> " call_act_r_command stop-recording-history $model [list "bold-prediction-with-time-scaled"] global $win.data unset $win.data " scale $win.s -orient horizontal -from 0 -to 0 -label "Scan #" -tickinterval 0 -font checkbox_font label $win.details -font label_font button $win.get -text "Get History" -font button_font -command "get_3dbrain_history_data $win $model $win.s" button $win.save -text "Save History" -font button_font -command "save_3dbrain_history_data $model" button $win.load -text "Load History" -font button_font -command "load_3dbrain_history_data $win $model $win.s" place $win.c -x 0 -y 0 place $win.s -relwidth 1.0 -rely 1.0 -y -125 place $win.details -x 0 -rely 1.0 -y -50 -height 25 -relwidth 1.0 place $win.get -relx .05 -rely 1.0 -y -25 -height 25 -relwidth .3 place $win.save -relx .35 -rely 1.0 -y -25 -height 25 -relwidth .3 place $win.load -relx .65 -rely 1.0 -y -25 -height 25 -relwidth .3 $win.c create text 10 200 -text "manual" -fill [lindex $voxel_colors 0] -anchor w -font checkbox_font $win.c create text 10 240 -text "goal" -fill [lindex $voxel_colors 1] -anchor w -font checkbox_font $win.c create text 10 280 -text "vocal" -fill [lindex $voxel_colors 2] -anchor w -font checkbox_font $win.c create text 10 320 -text "imaginal" -fill [lindex $voxel_colors 3] -anchor w -font checkbox_font $win.c create text 10 360 -text "retrieval" -fill [lindex $voxel_colors 4] -anchor w -font checkbox_font $win.c create text 10 400 -text "procedural" -fill [lindex $voxel_colors 5] -anchor w -font checkbox_font $win.c create text 10 440 -text "aural" -fill [lindex $voxel_colors 6] -anchor w -font checkbox_font $win.c create text 10 480 -text "visual" -fill [lindex $voxel_colors 7] -anchor w -font checkbox_font $win.c create text 10 10 -text "0.0" -fill #ddd -anchor w -font checkbox_font $win.c create text 10 170 -text "1.0" -fill #ddd -anchor w -font checkbox_font for {set c 0} {$c < 256} {incr c 3} { $win.c create rectangle 30 [expr round ($c / 3 * 2)] 40 [expr round ($c / 3 * 2) + 2] -outline "" -fill [format "#%.2x%.2x%.2x" $c $c $c] } bb_ReadData $win Set_Viewing_Transform $win $gvar($win,rho) $gvar($win,theta) $gvar($win,phi) $gvar($win,dist) bb_Draw_Objects $win $win.s configure -command "redraw_brain $win" wm deiconify $win pick_buffers } } proc redraw_brain {win time} { global gvar upvar #0 $win.data data if {$data != ""} { set gvar($win,colors) [lindex $data $time] } bb_redraw $win } proc bb_min { val1 val2 } { if { $val1 <= $val2 } { return $val1 } else { return $val2 } } proc bb_max { val1 val2 } { if { $val1 >= $val2 } { return $val1 } else { return $val2 } } #******************************* MatrixVectorProduct ***************** proc MatrixVectorProduct {M V} { set x [lindex $V 0] set y [lindex $V 1] set z [lindex $V 2] set w [lindex $V 3] return [list \ [expr {[lindex [lindex $M 0] 0]*$x+[lindex [lindex $M 1] 0]*$y+[lindex [lindex $M 2] 0]*$z+[lindex [lindex $M 3] 0]*$w}] \ [expr {[lindex [lindex $M 0] 1]*$x+[lindex [lindex $M 1] 1]*$y+[lindex [lindex $M 2] 1]*$z+[lindex [lindex $M 3] 1]*$w}] \ [expr {[lindex [lindex $M 0] 2]*$x+[lindex [lindex $M 1] 2]*$y+[lindex [lindex $M 2] 2]*$z+[lindex [lindex $M 3] 2]*$w}] \ [expr {[lindex [lindex $M 0] 3]*$x+[lindex [lindex $M 1] 3]*$y+[lindex [lindex $M 2] 3]*$z+[lindex [lindex $M 3] 3]*$w}] ] } #******************************* bb_d_move ******************************** proc bb_d_move {win x y z w } { global gvar set tmp [MatrixVectorProduct $gvar($win,Curnt_Trans) [list $x $y $z $w]] foreach {xt yt zt wt} $tmp {break} if {$zt == 0.0} { set zt 0.000001 } set x1 [expr {($gvar($win,Xscreen)/2.) + round($gvar($win,dist)*($xt/$zt)) }] set y1 [expr {($gvar($win,Yscreen)/2.) - round($gvar($win,dist)*($yt/$zt)) }] set x1 [expr {$x1 + $gvar($win,x,translate) }] set y1 [expr {$y1 - $gvar($win,y,translate) }] set gvar($win,Curnt_X_position) $x1 set gvar($win,Curnt_Y_position) $y1 return [list $x1 $y1] } #******************************* bb_d_draw ******************************** proc bb_d_draw {win x y z w {color white} {arrow none} } { global gvar set tmp [MatrixVectorProduct $gvar($win,Curnt_Trans) [list $x $y $z $w]] foreach {xt yt zt} $tmp {break} if {$zt == 0.0} { set zt 0.000001 } set x2 [expr {($gvar($win,Xscreen)/2.) + round($gvar($win,dist)*($xt/$zt)) }] set y2 [expr {($gvar($win,Yscreen)/2.) - round($gvar($win,dist)*($yt/$zt)) }] set x2 [expr {$x2 + $gvar($win,x,translate) }] set y2 [expr {$y2 - $gvar($win,y,translate) }] $gvar($win,canv) create line [list $gvar($win,Curnt_X_position) $gvar($win,Curnt_Y_position) $x2 $y2] \ -fill $color -arrow $arrow -tag brain set gvar($win,Curnt_X_position) $x2 set gvar($win,Curnt_Y_position) $y2 return [list $x2 $y2] } #******************************* bb_draw_shaded ******************************** proc bb_draw_shaded {win clist {fillcolor blue} {edgecolor white} } { global gvar set poly {} foreach {x y z} $clist { set w 1.0 set tmp [MatrixVectorProduct $gvar($win,Curnt_Trans) [list $x $y $z $w]] foreach {xt yt zt} $tmp {break} if {$zt == 0.0} { puts "zt = 0.0" set zt 0.001 } set x2 [expr {($gvar($win,Xscreen)/2.) + round($gvar($win,dist)*($xt/$zt)) }] set y2 [expr {($gvar($win,Yscreen)/2.) - round($gvar($win,dist)*($yt/$zt)) }] set x2 [expr {$x2 + $gvar($win,x,translate) }] set y2 [expr {$y2 - $gvar($win,y,translate) }] lappend poly $x2 $y2 } if {$edgecolor == "none"} { $gvar($win,canv) create polygon $poly -fill $fillcolor -tag brain } else { $gvar($win,canv) create polygon $poly -fill $fillcolor -outline $edgecolor -tag brain -width 3 } } #*********************** Set_Viewing_Transform ******************************** # proc Set_Viewing_Transform {win rho theta phi dist } { global gvar set sinth [expr {sin($theta)}] set costh [expr {cos($theta)}] set sinph [expr {sin($phi)}] set cosph [expr {cos($phi)}] set l1 [list [expr {-$sinth}] [expr {-$costh * $cosph}] [expr {-$costh * $sinph}] 0.0] set l2 [list [expr {$costh}] [expr {-$sinth * $cosph}] [expr {-$sinth * $sinph}] 0.0] set l3 [list 0.0 $sinph [expr {-$cosph}] 0.0] set l4 [list 0.0 0.0 $rho 1.0] set Ct [list $l1 $l2 $l3 $l4] set gvar($win,Curnt_Trans) $Ct set eye_x [expr {$rho * $sinph * $costh}] set eye_y [expr {$rho * $sinph * $sinth}] set eye_z [expr {$rho * $cosph}] set gvar($win,eye_point) [list $eye_x $eye_y $eye_z] } proc Conc_Trans { a b c } { for {set i 0} {$i < 4} {incr i} { set xa [lindex $a $i 0] set ya [lindex $a $i 1] set za [lindex $a $i 2] set wa [lindex $a $i 3] for {set j 0} {$j < 4} {incr j} { set xb [lindex $b 0 $j] set yb [lindex $b 1 $j] set zb [lindex $b 2 $j] set wb [lindex $b 3 $j] lset c $i $j [expr {$xa*$xb + $ya*$yb + $za*$zb + $wa*$wb}] } } return $c } #********************************* Get_Vector ********************** proc Get_Vector { v1 v2 } { set x1 [lindex $v1 0] set y1 [lindex $v1 1] set z1 [lindex $v1 2] set x2 [lindex $v2 0] set y2 [lindex $v2 1] set z2 [lindex $v2 2] set ux [expr {$x2 - $x1 }] set uy [expr {$y2 - $y1 }] set uz [expr {$z2 - $z1 }] return [list $ux $uy $uz] } #********************************* CrossProduct **************** proc Vector_CrossProduct {v1 v2} { set x1 [lindex $v1 0] set y1 [lindex $v1 1] set z1 [lindex $v1 2] set x2 [lindex $v2 0] set y2 [lindex $v2 1] set z2 [lindex $v2 2] set normal [list [expr {$y1*$z2 - $y2*$z1}] \ [expr {$z1*$x2 - $z2*$x1}] \ [expr {$x1*$y2 - $x2*$y1}]] return $normal } #********************************* CrossProduct **************** proc CrossProduct {x1 y1 z1 x2 y2 z2} { set normal [list [expr {$y1*$z2 - $y2*$z1}] \ [expr {$z1*$x2 - $z2*$x1}] \ [expr {$x1*$y2 - $x2*$y1}]] return $normal } #********************************* DotProduct **************** proc Vector_DotProduct {v1 v2} { set x1 [lindex $v1 0] set y1 [lindex $v1 1] set z1 [lindex $v1 2] set x2 [lindex $v2 0] set y2 [lindex $v2 1] set z2 [lindex $v2 2] set mag [expr {$x1*$x2 + $y1*$y2 + $z1*$z2}] return $mag } proc DotProduct {x1 y1 z1 x2 y2 z2} { set mag [expr {$x1*$x2 + $y1*$y2 + $z1*$z2}] return $mag } proc Normal_Vector { v1 v2 } { set n [Vector_CrossProduct $v1 $v2] set mag [Vector_DotProduct $n $n] set mag [expr {sqrt($mag)}] foreach {x y z} $n {break} set xn [expr {$x / $mag }] set yn [expr {$y / $mag }] set zn [expr {$z / $mag }] set norm [list $xn $yn $zn] return $norm } #***************************** R E A D D A T A ****************************** proc bb_ReadData {win} { global gvar set lvtx {{ 0 0 0.5120} { 0.2969 0.0000 0.4800} { 0.3047 0.2187 0.4800} { 0.1562 0.4844 0.4800} { -.1484 0.4609 0.4800} { -.2578 0.1875 0.4800} { -.2500 0.0000 0.4800} { -.1797 -.1250 0.4800} { -.0703 -.2187 0.4800} { 0.0703 -.2266 0.4800} { 0.2109 -.1484 0.4800} { 0.3203 0.0000 0.4480} { 0.3281 0.2422 0.4480} { 0.1797 0.5547 0.4480} { -.1797 0.5547 0.4480} { -.3281 0.2422 0.4480} { -.3203 0.0000 0.4480} { -.2266 -.1641 0.4480} { -.0859 -.2578 0.4480} { 0.0859 -.2578 0.4480} { 0.2266 -.1641 0.4480} { 0.3750 0.0000 0.4160} { 0.3906 0.2812 0.4160} { 0.1953 0.6016 0.4160} { -.1875 0.5859 0.4160} { -.3594 0.2656 0.4160} { -.3437 0.0000 0.4160} { -.2734 -.1953 0.4160} { -.1250 -.3906 0.4160} { 0.1328 -.3984 0.4160} { 0.2891 -.2109 0.4160} { 0.4453 0.0000 0.3840} { 0.4453 0.3203 0.3840} { 0.2031 0.6250 0.3840} { -.1953 0.6016 0.3840} { -.4141 0.2969 0.3840} { -.4062 0.0000 0.3840} { -.3125 -.2266 0.3840} { -.1484 -.4453 0.3840} { 0.1562 -.4766 0.3840} { 0.3437 -.2500 0.3840} { 0.4844 0.0000 0.3520} { 0.4922 0.3594 0.3520} { 0.2109 0.6406 0.3520} { -.2031 0.6328 0.3520} { -.4531 0.3281 0.3520} { -.4375 0.0000 0.3520} { -.3594 -.2656 0.3520} { -.1641 -.5000 0.3520} { 0.1719 -.5234 0.3520} { 0.3906 -.2812 0.3520} { 0.5312 0.0000 0.3200} { 0.5391 0.3906 0.3200} { 0.2187 0.6641 0.3200} { -.2109 0.6562 0.3200} { -.5078 0.3672 0.3200} { -.4844 0.0000 0.3200} { -.3984 -.2891 0.3200} { -.1797 -.5469 0.3200} { 0.1875 -.5781 0.3200} { 0.4297 -.3125 0.3200} { 0.5625 0.0000 0.2880} { 0.5547 0.4062 0.2880} { 0.2266 0.6875 0.2880} { -.2187 0.6641 0.2880} { -.5156 0.3750 0.2880} { -.5156 0.0000 0.2880} { -.4297 -.3125 0.2880} { -.1953 -.5937 0.2880} { 0.2031 -.6172 0.2880} { 0.4609 -.3359 0.2880} { 0.5781 0.0000 0.2560} { 0.5859 0.4297 0.2560} { 0.2266 0.7031 0.2560} { -.2266 0.6953 0.2560} { -.5625 0.4062 0.2560} { -.5469 0.0000 0.2560} { -.4453 -.3281 0.2560} { -.2031 -.6172 0.2560} { 0.2031 -.6250 0.2560} { 0.4687 -.3359 0.2560} { 0.6094 0.0000 0.2240} { 0.5859 0.4297 0.2240} { 0.2344 0.7109 0.2240} { -.2266 0.6875 0.2240} { -.5547 0.4062 0.2240} { -.5703 0.0000 0.2240} { -.4531 -.3281 0.2240} { -.2187 -.6719 0.2240} { 0.2266 -.6875 0.2240} { 0.4766 -.3437 0.2240} { 0.6172 0.0000 0.1920} { 0.5781 0.4219 0.1920} { 0.2500 0.7578 0.1920} { -.2422 0.7500 0.1920} { -.5625 0.4062 0.1920} { -.5937 0.0000 0.1920} { -.4922 -.3594 0.1920} { -.2266 -.6875 0.1920} { 0.2266 -.7031 0.1920} { 0.5156 -.3750 0.1920} { 0.6406 0.0000 0.1600} { 0.5937 0.4297 0.1600} { 0.2500 0.7734 0.1600} { -.2500 0.7656 0.1600} { -.5781 0.4219 0.1600} { -.6172 0.0000 0.1600} { -.5078 -.3672 0.1600} { -.2422 -.7344 0.1600} { 0.2422 -.7500 0.1600} { 0.5234 -.3828 0.1600} { 0.6562 0.0000 0.1280} { 0.6094 0.4453 0.1280} { 0.2578 0.7891 0.1280} { -.2500 0.7734 0.1280} { -.5937 0.4297 0.1280} { -.6328 0.0000 0.1280} { -.5312 -.3828 0.1280} { -.2500 -.7656 0.1280} { 0.2500 -.7812 0.1280} { 0.5469 -.3984 0.1280} { 0.6875 0.0000 0.0960} { 0.6406 0.4609 0.0960} { 0.2578 0.8047 0.0960} { -.2578 0.7891 0.0960} { -.6016 0.4375 0.0960} { -.6406 0.0000 0.0960} { -.5469 -.3984 0.0960} { -.2500 -.7812 0.0960} { 0.2578 -.8047 0.0960} { 0.5781 -.4219 0.0960} { 0.6953 0.0000 0.0640} { 0.6484 0.4687 0.0640} { 0.2656 0.8203 0.0640} { -.2578 0.7969 0.0640} { -.6094 0.4375 0.0640} { -.6484 0.0000 0.0640} { -.5469 -.3984 0.0640} { -.2578 -.7891 0.0640} { 0.2656 -.8203 0.0640} { 0.5859 -.4297 0.0640} { 0.6953 0.0000 0.0320} { 0.6484 0.4687 0.0320} { 0.2656 0.8203 0.0320} { -.2578 0.7969 0.0320} { -.6172 0.4531 0.0320} { -.6562 0.0000 0.0320} { -.5469 -.3984 0.0320} { -.2656 -.8125 0.0320} { 0.2656 -.8281 0.0320} { 0.5781 -.4141 0.0320} { 0.6875 0.0000 0.0000} { 0.6406 0.4609 0.0000} { 0.2812 0.8516 0.0000} { -.2734 0.8359 0.0000} { -.6172 0.4531 0.0000} { -.6562 0.0000 0.0000} { -.5625 -.4062 0.0000} { -.2656 -.8203 0.0000} { 0.2734 -.8359 0.0000} { 0.5859 -.4297 0.0000} { 0.6875 0.0000 -.0320} { 0.6484 0.4687 -.0320} { 0.2812 0.8516 -.0320} { -.2734 0.8359 -.0320} { -.6172 0.4531 -.0320} { -.6484 0.0000 -.0320} { -.5547 -.4062 -.0320} { -.2656 -.8125 -.0320} { 0.2734 -.8359 -.0320} { 0.5859 -.4297 -.0320} { 0.6797 0.0000 -.0640} { 0.6562 0.4766 -.0640} { 0.2812 0.8672 -.0640} { -.2812 0.8516 -.0640} { -.6250 0.4531 -.0640} { -.6328 0.0000 -.0640} { -.5469 -.3984 -.0640} { -.2656 -.8125 -.0640} { 0.2734 -.8359 -.0640} { 0.5859 -.4297 -.0640} { 0.6953 0.0000 -.0960} { 0.6484 0.4687 -.0960} { 0.2812 0.8750 -.0960} { -.2812 0.8594 -.0960} { -.6172 0.4531 -.0960} { -.6641 0.0000 -.0960} { -.5703 -.4141 -.0960} { -.2734 -.8359 -.0960} { 0.2734 -.8437 -.0960} { 0.5937 -.4297 -.0960} { 0.6719 0.0000 -.1280} { 0.6328 0.4609 -.1280} { 0.2812 0.8594 -.1280} { -.2812 0.8516 -.1280} { -.6250 0.4531 -.1280} { -.6562 0.0000 -.1280} { -.5625 -.4062 -.1280} { -.2734 -.8359 -.1280} { 0.2734 -.8359 -.1280} { 0.5781 -.4141 -.1280} { 0.6562 0.0000 -.1600} { 0.6406 0.4609 -.1600} { 0.2812 0.8750 -.1600} { -.2812 0.8672 -.1600} { -.6328 0.4609 -.1600} { -.6484 0.0000 -.1600} { -.5625 -.4062 -.1600} { -.2656 -.8125 -.1600} { 0.2656 -.8125 -.1600} { 0.5703 -.4141 -.1600} { 0.6719 0.0000 -.1920} { 0.6484 0.4687 -.1920} { 0.2891 0.8906 -.1920} { -.2812 0.8750 -.1920} { -.6250 0.4531 -.1920} { -.6484 0.0000 -.1920} { -.5469 -.3984 -.1920} { -.2578 -.8047 -.1920} { 0.2656 -.8125 -.1920} { 0.5703 -.4141 -.1920} { 0.6641 0.0000 -.2240} { 0.6328 0.4609 -.2240} { 0.2812 0.8750 -.2240} { -.2812 0.8672 -.2240} { -.6250 0.4531 -.2240} { -.6484 0.0000 -.2240} { -.5234 -.3828 -.2240} { -.2578 -.7969 -.2240} { 0.2578 -.8047 -.2240} { 0.5391 -.3906 -.2240} { 0.6797 0.0000 -.2560} { 0.6406 0.4609 -.2560} { 0.2891 0.8828 -.2560} { -.2812 0.8750 -.2560} { -.6250 0.4531 -.2560} { -.6562 0.0000 -.2560} { -.5156 -.3750 -.2560} { -.2578 -.7891 -.2560} { 0.2578 -.7969 -.2560} { 0.5312 -.3828 -.2560} { 0.6562 0.0000 -.2880} { 0.6250 0.4531 -.2880} { 0.2812 0.8594 -.2880} { -.2812 0.8516 -.2880} { -.6172 0.4531 -.2880} { -.6484 0.0000 -.2880} { -.5078 -.3672 -.2880} { -.2422 -.7500 -.2880} { 0.2500 -.7578 -.2880} { 0.5156 -.3750 -.2880} { 0.6797 0.0000 -.3200} { 0.6406 0.4609 -.3200} { 0.2891 0.8984 -.3200} { -.2891 0.8828 -.3200} { -.6172 0.4531 -.3200} { -.6562 0.0000 -.3200} { -.5078 -.3672 -.3200} { -.2422 -.7422 -.3200} { 0.2266 -.6953 -.3200} { 0.5234 -.3828 -.3200} { 0.6641 0.0000 -.3520} { 0.6250 0.4531 -.3520} { 0.2891 0.8828 -.3520} { -.2812 0.8516 -.3520} { -.5859 0.4297 -.3520} { -.6094 0.0000 -.3520} { -.4766 -.3437 -.3520} { -.2266 -.7031 -.3520} { 0.2187 -.6641 -.3520} { 0.5156 -.3750 -.3520} { 0.6641 0.0000 -.3840} { 0.6328 0.4609 -.3840} { 0.2891 0.8828 -.3840} { -.2734 0.8437 -.3840} { -.5703 0.4141 -.3840} { -.5859 0.0000 -.3840} { -.4609 -.3359 -.3840} { -.1875 -.5859 -.3840} { 0.1953 -.5937 -.3840} { 0.5156 -.3750 -.3840} { 0.6641 0.0000 -.4160} { 0.6094 0.4375 -.4160} { 0.2891 0.8828 -.4160} { -.2812 0.8516 -.4160} { -.5703 0.4141 -.4160} { -.6016 0.0000 -.4160} { -.4766 -.3437 -.4160} { -.1797 -.5391 -.4160} { 0.1797 -.5391 -.4160} { 0.5156 -.3750 -.4160} { 0.6719 0.0000 -.4480} { 0.6016 0.4375 -.4480} { 0.2812 0.8672 -.4480} { -.2812 0.8516 -.4480} { -.5859 0.4297 -.4480} { -.6484 0.0000 -.4480} { -.4922 -.3594 -.4480} { -.0937 -.2891 -.4480} { 0.0937 -.2891 -.4480} { 0.5156 -.3750 -.4480} { 0.6562 0.0000 -.4800} { 0.6016 0.4375 -.4800} { 0.2656 0.8281 -.4800} { -.2656 0.8125 -.4800} { -.5859 0.4297 -.4800} { -.6328 0.0000 -.4800} { -.4687 -.3359 -.4800} { -.0937 -.2969 -.4800} { 0.0937 -.2969 -.4800} { 0.4766 -.3516 -.4800} { 0.6328 0.0000 -.5120} { 0.5859 0.4297 -.5120} { 0.2500 0.7656 -.5120} { -.2500 0.7578 -.5120} { -.5547 0.4062 -.5120} { -.6094 0.0000 -.5120} { -.4766 -.3437 -.5120} { -.0937 -.2891 -.5120} { 0.0937 -.2891 -.5120} { 0.4766 -.3437 -.5120} { 0.6094 0.0000 -.5440} { 0.5703 0.4141 -.5440} { 0.2422 0.7344 -.5440} { -.2422 0.7422 -.5440} { -.5391 0.3906 -.5440} { -.5859 0.0000 -.5440} { -.4609 -.3359 -.5440} { -.0391 -.1250 -.5440} { 0.0391 -.1250 -.5440} { 0.4766 -.3437 -.5440} { 0.1719 0.0000 -.5760} { 0.5703 0.4141 -.5760} { 0.2422 0.7344 -.5760} { -.2422 0.7422 -.5760} { -.5625 0.4062 -.5760} { -.1484 0.0000 -.5760} { -.4219 -.3047 -.5760} { -.0391 -.1172 -.5760} { 0.0391 -.1172 -.5760} { 0.4297 -.3125 -.5760} { 0.1719 0.0000 -.5760} { 0.5703 0.4141 -.5760} { 0.2422 0.7344 -.5760} { -.2422 0.7422 -.5760} { -.5625 0.4062 -.5760} { -.1484 0.0000 -.5760} { -.4219 -.3047 -.5760} { -.0391 -.1172 -.5760} { 0.0391 -.1172 -.5760} { 0.4297 -.3125 -.5760} { -.4609 0.0703 0.2880} { -.3281 0.0703 0.2880} { -.4609 0.2031 0.2880} { -.3281 0.2031 0.2880} { -.4609 0.0703 0.1920} { -.3281 0.0703 0.1920} { -.4609 0.2031 0.1920} { -.3281 0.2031 0.1920} { 0.3750 0.0703 0.2880} { 0.5078 0.0703 0.2880} { 0.3750 0.2031 0.2880} { 0.5078 0.2031 0.2880} { 0.3750 0.0703 0.1920} { 0.5078 0.0703 0.1920} { 0.3750 0.2031 0.1920} { 0.5078 0.2031 0.1920} { -.0859 -.2734 0.2240} { -.0156 -.2734 0.2240} { -.0859 -.1406 0.2240} { -.0156 -.1406 0.2240} { -.0859 -.2734 0.1280} { -.0156 -.2734 0.1280} { -.0859 -.1406 0.1280} { -.0156 -.1406 0.1280} { 0.0547 -.2734 0.2240} { 0.1250 -.2734 0.2240} { 0.0547 -.1406 0.2240} { 0.1250 -.1406 0.2240} { 0.0547 -.2734 0.1280} { 0.1250 -.2734 0.1280} { 0.0547 -.1406 0.1280} { 0.1250 -.1406 0.1280} { -.4922 -.0234 0.1280} { -.3594 -.0234 0.1280} { -.4922 0.1094 0.1280} { -.3594 0.1094 0.1280} { -.4922 -.0234 0.0320} { -.3594 -.0234 0.0320} { -.4922 0.1094 0.0320} { -.3594 0.1094 0.0320} { 0.3828 -.0234 0.1280} { 0.5156 -.0234 0.1280} { 0.3828 0.1094 0.1280} { 0.5156 0.1094 0.1280} { 0.3828 -.0234 0.0320} { 0.5156 -.0234 0.0320} { 0.3828 0.1094 0.0320} { 0.5156 0.1094 0.0320} { -.2734 0.5078 0.1280} { -.1406 0.5078 0.1280} { -.2734 0.6406 0.1280} { -.1406 0.6406 0.1280} { -.2734 0.5078 0.0320} { -.1406 0.5078 0.0320} { -.2734 0.6406 0.0320} { -.1406 0.6406 0.0320} { 0.1641 0.5078 0.1280} { 0.2969 0.5078 0.1280} { 0.1641 0.6406 0.1280} { 0.2969 0.6406 0.1280} { 0.1641 0.5078 0.0320} { 0.2969 0.5078 0.0320} { 0.1641 0.6406 0.0320} { 0.2969 0.6406 0.0320} { -.4922 -.4297 0.0960} { -.3594 -.4297 0.0960} { -.4922 -.2969 0.0960} { -.3594 -.2969 0.0960} { -.4922 -.4297 0.0000} { -.3594 -.4297 0.0000} { -.4922 -.2969 0.0000} { -.3594 -.2969 0.0000} { 0.4062 -.4297 0.0960} { 0.5391 -.4297 0.0960} { 0.4062 -.2969 0.0960} { 0.5391 -.2969 0.0960} { 0.4062 -.4297 0.0000} { 0.5391 -.4297 0.0000} { 0.4062 -.2969 0.0000} { 0.5391 -.2969 0.0000} { -.1797 -.3047 -.0960} { -.0781 -.3047 -.0960} { -.1797 -.2031 -.0960} { -.0781 -.2031 -.0960} { -.1797 -.3047 -.1920} { -.0781 -.3047 -.1920} { -.1797 -.2031 -.1920} { -.0781 -.2031 -.1920} { 0.1094 -.3047 -.0960} { 0.2109 -.3047 -.0960} { 0.1094 -.2031 -.0960} { 0.2109 -.2031 -.0960} { 0.1094 -.3047 -.1920} { 0.2109 -.3047 -.1920} { 0.1094 -.2031 -.1920} { 0.2109 -.2031 -.1920} { -.5234 0.0391 -.1280} { -.3906 0.0391 -.1280} { -.5234 0.1719 -.1280} { -.3906 0.1719 -.1280} { -.5234 0.0391 -.2240} { -.3906 0.0391 -.2240} { -.5234 0.1719 -.2240} { -.3906 0.1719 -.2240} { 0.4062 0.0391 -.1280} { 0.5391 0.0391 -.1280} { 0.4062 0.1719 -.1280} { 0.5391 0.1719 -.1280} { 0.4062 0.0391 -.2240} { 0.5391 0.0391 -.2240} { 0.4062 0.1719 -.2240} { 0.5391 0.1719 -.2240} { -.4375 0.4141 -.3840} { -.3047 0.4141 -.3840} { -.4375 0.5469 -.3840} { -.3047 0.5469 -.3840} { -.4375 0.4141 -.4480} { -.3047 0.4141 -.4480} { -.4375 0.5469 -.4480} { -.3047 0.5469 -.4480} { 0.3828 0.4141 -.3840} { 0.5156 0.4141 -.3840} { 0.3828 0.5469 -.3840} { 0.5156 0.5469 -.3840} { 0.3828 0.4141 -.4480} { 0.5156 0.4141 -.4480} { 0.3828 0.5469 -.4480} { 0.5156 0.5469 -.4480} } set lcnx {{ 0 10 1 none} { 0 11 12 none} { 0 2 3 none} { 0 13 14 none} { 0 4 5 none} { 0 15 16 none} { 0 6 7 none} { 0 17 18 none} { 0 8 9 none} { 0 19 20 none} { 10 30 21 1 none} { 2 22 23 3 none} { 4 24 25 5 none} { 6 26 27 7 none} { 8 28 29 9 none} { 11 31 32 12 none} { 13 33 34 14 none} { 15 35 36 16 none} { 17 37 38 18 none} { 19 39 40 20 none} { 30 50 41 21 none} { 22 42 43 23 none} { 24 44 45 25 none} { 26 46 47 27 none} { 28 48 49 29 none} { 31 51 52 32 none} { 33 53 54 34 none} { 35 55 56 36 none} { 37 57 58 38 none} { 39 59 60 40 none} { 50 70 61 41 none} { 42 62 63 43 none} { 44 64 65 45 none} { 46 66 67 47 none} { 48 68 69 49 none} { 51 71 72 52 none} { 53 73 74 54 none} { 55 75 76 56 none} { 57 77 78 58 none} { 59 79 80 60 none} { 70 90 81 61 none} { 62 82 83 63 none} { 64 84 85 65 none} { 66 86 87 67 none} { 68 88 89 69 none} { 71 91 92 72 none} { 73 93 94 74 none} { 75 95 96 76 none} { 77 97 98 78 none} { 79 99 100 80 none} { 90 110 101 81 none} { 82 102 103 83 none} { 84 104 105 85 none} { 86 106 107 87 none} { 88 108 109 89 none} { 91 111 112 92 none} { 93 113 114 94 none} { 95 115 116 96 none} { 97 117 118 98 none} { 99 119 120 100 none} { 110 130 121 101 none} { 102 122 123 103 none} { 104 124 125 105 none} { 106 126 127 107 none} { 108 128 129 109 none} { 111 131 132 112 none} { 113 133 134 114 none} { 115 135 136 116 none} { 117 137 138 118 none} { 119 139 140 120 none} { 130 150 141 121 none} { 122 142 143 123 none} { 124 144 145 125 none} { 126 146 147 127 none} { 128 148 149 129 none} { 131 151 152 132 none} { 133 153 154 134 none} { 135 155 156 136 none} { 137 157 158 138 none} { 139 159 160 140 none} { 150 170 161 141 none} { 142 162 163 143 none} { 144 164 165 145 none} { 146 166 167 147 none} { 148 168 169 149 none} { 151 171 172 152 none} { 153 173 174 154 none} { 155 175 176 156 none} { 157 177 178 158 none} { 159 179 180 160 none} { 170 190 181 161 none} { 162 182 183 163 none} { 164 184 185 165 none} { 166 186 187 167 none} { 168 188 189 169 none} { 171 191 192 172 none} { 173 193 194 174 none} { 175 195 196 176 none} { 177 197 198 178 none} { 179 199 200 180 none} { 190 210 201 181 none} { 182 202 203 183 none} { 184 204 205 185 none} { 186 206 207 187 none} { 188 208 209 189 none} { 191 211 212 192 none} { 193 213 214 194 none} { 195 215 216 196 none} { 197 217 218 198 none} { 199 219 220 200 none} { 210 230 221 201 none} { 202 222 223 203 none} { 204 224 225 205 none} { 206 226 227 207 none} { 208 228 229 209 none} { 211 231 232 212 none} { 213 233 234 214 none} { 215 235 236 216 none} { 217 237 238 218 none} { 219 239 240 220 none} { 230 250 241 221 none} { 222 242 243 223 none} { 224 244 245 225 none} { 226 246 247 227 none} { 228 248 249 229 none} { 231 251 252 232 none} { 233 253 254 234 none} { 235 255 256 236 none} { 237 257 258 238 none} { 239 259 260 240 none} { 250 270 261 241 none} { 242 262 263 243 none} { 244 264 265 245 none} { 246 266 267 247 none} { 248 268 269 249 none} { 251 271 272 252 none} { 253 273 274 254 none} { 255 275 276 256 none} { 257 277 278 258 none} { 259 279 280 260 none} { 270 290 281 261 none} { 262 282 283 263 none} { 264 284 285 265 none} { 266 286 287 267 none} { 268 288 289 269 none} { 271 291 292 272 none} { 273 293 294 274 none} { 275 295 296 276 none} { 277 297 298 278 none} { 279 299 300 280 none} { 290 310 301 281 none} { 282 302 303 283 none} { 284 304 305 285 none} { 286 306 307 287 none} { 288 308 309 289 none} { 291 311 312 292 none} { 293 313 314 294 none} { 295 315 316 296 none} { 297 317 318 298 none} { 299 319 320 300 none} { 310 330 321 301 none} { 302 322 323 303 none} { 304 324 325 305 none} { 306 326 327 307 none} { 308 328 329 309 none} { 311 331 332 312 none} { 313 333 334 314 none} { 315 335 336 316 none} { 317 337 338 318 none} { 319 339 340 320 none} { 330 350 341 321 none} { 322 342 343 323 none} { 324 344 345 325 none} { 326 346 347 327 none} { 328 348 349 329 none} { 351 355 356 352 0} { 351 353 357 355 0} { 351 352 354 353 0} { 358 354 352 356 0} { 358 357 353 354 0} { 358 356 355 357 0} { 359 363 364 360 0} { 359 361 365 363 0} { 359 360 362 361 0} { 366 362 360 364 0} { 366 365 361 362 0} { 366 364 363 365 0} { 367 371 372 368 1} { 367 369 373 371 1} { 367 368 370 369 1} { 374 370 368 372 1} { 374 373 369 370 1} { 374 372 371 373 1} { 375 379 380 376 1} { 375 377 381 379 1} { 375 376 378 377 1} { 382 378 376 380 1} { 382 381 377 378 1} { 382 380 379 381 1} { 383 387 388 384 2} { 383 385 389 387 2} { 383 384 386 385 2} { 390 386 384 388 2} { 390 389 385 386 2} { 390 388 387 389 2} { 391 395 396 392 2} { 391 393 397 395 2} { 391 392 394 393 2} { 398 394 392 396 2} { 398 397 393 394 2} { 398 396 395 397 2} { 399 403 404 400 3} { 399 401 405 403 3} { 399 400 402 401 3} { 406 402 400 404 3} { 406 405 401 402 3} { 406 404 403 405 3} { 407 411 412 408 3} { 407 409 413 411 3} { 407 408 410 409 3} { 414 410 408 412 3} { 414 413 409 410 3} { 414 412 411 413 3} { 415 419 420 416 4} { 415 417 421 419 4} { 415 416 418 417 4} { 422 418 416 420 4} { 422 421 417 418 4} { 422 420 419 421 4} { 423 427 428 424 4} { 423 425 429 427 4} { 423 424 426 425 4} { 430 426 424 428 4} { 430 429 425 426 4} { 430 428 427 429 4} { 431 435 436 432 5} { 431 433 437 435 5} { 431 432 434 433 5} { 438 434 432 436 5} { 438 437 433 434 5} { 438 436 435 437 5} { 439 443 444 440 5} { 439 441 445 443 5} { 439 440 442 441 5} { 446 442 440 444 5} { 446 445 441 442 5} { 446 444 443 445 5} { 447 451 452 448 6} { 447 449 453 451 6} { 447 448 450 449 6} { 454 450 448 452 6} { 454 453 449 450 6} { 454 452 451 453 6} { 455 459 460 456 6} { 455 457 461 459 6} { 455 456 458 457 6} { 462 458 456 460 6} { 462 461 457 458 6} { 462 460 459 461 6} { 463 467 468 464 7} { 463 465 469 467 7} { 463 464 466 465 7} { 470 466 464 468 7} { 470 469 465 466 7} { 470 468 467 469 7} { 471 475 476 472 7} { 471 473 477 475 7} { 471 472 474 473 7} { 478 474 472 476 7} { 478 477 473 474 7} { 478 476 475 477 7} } set obj [list $lvtx $lcnx] set gvar($win,display) [list $obj] #################################################################### # Calculate the bounds (xmin,xmax,ymin,ymax,zmin,zmax) # set xmin 9.9999e10 set xmax -9.9999e10 set ymin $xmin set ymax $xmax set zmin $xmin set zmax $xmax foreach obj $gvar($win,display) { set verts [lindex $obj 0] foreach v $verts { foreach {x y z} $v { set xmin [bb_min $x $xmin] set ymin [bb_min $y $ymin] set zmin [bb_min $z $zmin] set xmax [bb_max $x $xmax] set ymax [bb_max $y $ymax] set zmax [bb_max $z $zmax] } } } set gvar($win,display,bounds) [list $xmin $xmax $ymin $ymax $zmin $zmax] #################################################################### # Calculate Normal for each face # set newdisp {} foreach obj $gvar($win,display) { set verts [lindex $obj 0] set conn [lindex $obj 1] set faceNorm {} set newconn {} foreach edge $conn { set i1 [lindex $edge 0] set i2 [lindex $edge 1] set i3 [lindex $edge 2] set v1 [lindex $verts $i1] set v2 [lindex $verts $i2] set v3 [lindex $verts $i3] set u_vector [Get_Vector $v1 $v2] set v_vector [Get_Vector $v1 $v3] set normal [Normal_Vector $u_vector $v_vector] lappend newconn [lrange $edge 0 [expr [llength $edge] - 2]] $normal [lindex $edge end] } lappend newdisp [list $verts $newconn] } set gvar($win,display) $newdisp } #********************************* Draw_Face ************************ proc Draw_Face {win verts edge fNorm {color white} } { global gvar if { [llength $edge] < 3} { return } set nedges [expr {[llength $edge] - 1}] set ilast [lindex $edge $nedges] set vtx [lindex $verts $ilast] foreach {x y z} $vtx {break} bb_d_move $win $x $y $z 1 for {set n 0} {$n < [llength $edge]} {incr n} { set i [lindex $edge $n] set vtx [lindex $verts $i] foreach {x y z} $vtx {break} bb_d_draw $win $x $y $z 1 $color } } #********************************* Shade_Face ************************ proc Shade_Face {win verts edge fNorm {fillcolor blue} {edgecolor white} } { global gvar if { [llength $edge] < 3} { return } set nedges [expr {[llength $edge] - 1}] set ilast [lindex $edge $nedges] set vtx [lindex $verts $ilast] foreach {x y z} $vtx {break} set coordlst [list $x $y $z] for {set n 0} {$n < [llength $edge]} {incr n} { set i [lindex $edge $n] set vtx [lindex $verts $i] foreach {x y z} $vtx {break} lappend coordlst $x $y $z } bb_draw_shaded $win $coordlst $fillcolor $edgecolor } proc cull_backfaces {win verts face } { global gvar set retval {} foreach {edge faceNorm draw} $face { set i1 [lindex $edge 0] set i2 [lindex $edge 1] set i3 [lindex $edge 2] set v1 [lindex $verts $i1] set v2 [lindex $verts $i2] set v3 [lindex $verts $i3] set u_vector [Get_Vector $v1 $v2] set v_vector [Get_Vector $v1 $v3] set line_of_sight [Get_Vector $v1 $gvar($win,eye_point)] set normal [Vector_CrossProduct $u_vector $v_vector] set mag [Vector_DotProduct $faceNorm $line_of_sight] if {$mag < 0.0 && $draw == "none"} { set visible 0 } else { set visible 1 lappend retval $edge $faceNorm $draw } } return $retval } # sort each face based on it's distance from the "eye_point" # This is to implement the "Painter's Algorithm" hidden surface # removal # proc sortconn {win verts face } { global gvar set sconn {} foreach {xe ye ze} $gvar($win,eye_point) {break} foreach {edge faceNorm draw} $face { set d 0.0 set nedge [llength $edge] for {set n 0} {$n < $nedge} {incr n} { set i [lindex $edge $n] set vtx [lindex $verts $i] foreach {x y z} $vtx {break} set dx [expr {$x - $xe}] set dy [expr {$y - $ye}] set dz [expr {$z - $ze}] set vdist [expr {sqrt($dx*$dx + $dy*$dy + $dz*$dz)}] set d [expr {$d + $vdist}] } set d [expr {$d / $nedge}] lappend sconn [list $d $edge $faceNorm $draw] } set sconn [lsort -decreasing -index 0 $sconn] set newface {} foreach s $sconn { lappend newface [lindex $s 1] [lindex $s 2] [lindex $s 3] } return $newface } proc canvas_rotate_start {win w x y} { global gvar set gvar($win,canvas,rotate,coords) [list $x $y] } proc canvas_rotate_drag {win w x y} { global gvar foreach {newtheta newphi} [canvas_rotate_calc $win $x $y] {break} set gvar($win,theta) $newtheta set gvar($win,phi) $newphi set gvar($win,canvas,rotate,coords) [list $x $y] bb_redraw $win } proc canvas_rotate_end {win w x y} { global gvar foreach {newtheta newphi} [canvas_rotate_calc $win $x $y] {break} set gvar($win,theta) $newtheta set gvar($win,phi) $newphi set gvar($win,canvas,rotate,coords) [list $x $y] bb_redraw $win } proc canvas_rotate_calc {win x y} { global gvar foreach {xold yold} $gvar($win,canvas,rotate,coords) {break} set dx [expr { ($x - $xold) * 0.01}] set dy [expr {-($y - $yold) * 0.01}] set newtheta [expr {$gvar($win,theta) - $dx}] set newphi [expr {$gvar($win,phi) + $dy}] if {$newtheta > $gvar($win,pi)} { set newtheta [expr {$newtheta - $gvar($win,twopi)}] } if {$newtheta < $gvar($win,mpi)} { set newtheta [expr {$newtheta + $gvar($win,twopi)}] } if {$newphi > $gvar($win,pi)} { set newphi [expr {$newphi - $gvar($win,twopi)}] } if {$newphi < $gvar($win,mpi)} { set newphi [expr {$newphi + $gvar($win,twopi)}] } set retval [list $newtheta $newphi] return $retval } proc canvas_pan_start {win w x y} { global gvar set gvar($win,canvas,pan,coords) [list $x $y] } proc canvas_pan_drag {win w x y} { global gvar foreach {xold yold} $gvar($win,canvas,pan,coords) {break} set dx [expr { ($x - $xold) * 1.0}] set dy [expr {-($y - $yold) * 1.0}] set gvar($win,x,translate) [expr {$gvar($win,x,translate) + $dx}] set gvar($win,y,translate) [expr {$gvar($win,y,translate) + $dy}] set gvar($win,canvas,pan,coords) [list $x $y] bb_redraw $win } proc canvas_pan_end {win w x y} { global gvar foreach {xold yold} $gvar($win,canvas,pan,coords) {break} set dx [expr { ($x - $xold) * 0.1}] set dy [expr {-($y - $yold) * 0.1}] set gvar($win,x,translate) [expr {$gvar($win,x,translate) + $dx}] set gvar($win,y,translate) [expr {$gvar($win,y,translate) + $dy}] set gvar($win,canvas,pan,coords) [list $x $y] bb_redraw $win } proc canvas_zoom_start {win w x y} { global gvar set gvar($win,canvas,zoom,coords) [list $x $y] } proc canvas_zoom_drag {win w x y} { global gvar foreach {xold yold} $gvar($win,canvas,zoom,coords) {break} set dy [expr {-($y - $yold)}] if {$dy != 0} { set gvar($win,dist) [expr {$gvar($win,dist) + $dy * 2}] } set gvar($win,canvas,zoom,coords) [list $x $y] bb_redraw $win } proc canvas_zoom_end {win w x y} { global gvar foreach {xold yold} $gvar($win,canvas,zoom,coords) {break} set dy [expr {-($y - $yold)}] if {$dy != 0} { set gvar($win,dist) [expr {$gvar($win,dist) + $dy * 2}] } set gvar($win,canvas,zoom,coords) [list $x $y] bb_redraw $win } #************************** bb_Draw_Objects ************************* proc bb_Draw_Objects {win} { global gvar global voxel_colors global voxel_shade_colors foreach obj $gvar($win,display) { set verts [lindex $obj 0] set face [lindex $obj 1] set face [cull_backfaces $win $verts $face] set face [sortconn $win $verts $face] foreach {edge fNorm draw} $face { if {$draw == "none"} { set colr "none" } else { set colr [lindex $voxel_colors $draw] set shade [lindex $gvar($win,colors) $draw] if {$shade == "none"} { set fill_color "#000" } else { set c [expr round(255 * $shade)] set fill_color [format "#%.2x%.2x%.2x" $c $c $c] } } if {$colr != "none"} { Shade_Face $win $verts $edge $fNorm $fill_color $colr } else { Draw_Face $win $verts $edge $fNorm "#8f8f8f" } } } $gvar($win,canv) delete values set y 200 foreach {color} $gvar($win,colors) { if {$color == "none"} { $gvar($win,canv) create text 70 $y -text "---" -fill "#ccc" -anchor w -tag values -font checkbox_font } else { $gvar($win,canv) create text 70 $y -text [format "%1.3f" $color] -fill "#ccc" -anchor w -tag values -font checkbox_font } incr y 40 } } # Update the display # proc bb_redraw {win} { global gvar $gvar($win,canv) delete brain Set_Viewing_Transform $win $gvar($win,rho) $gvar($win,theta) $gvar($win,phi) $gvar($win,dist) bb_Draw_Objects $win } set brain_3d_history_warnings "" proc brain_3d_record_warnings {model s} { global brain_3d_history_warnings set brain_3d_history_warnings "$brain_3d_history_warnings$s" return "" } proc save_3dbrain_history_data {model} { global top_dir set fname [tk_getSaveFile -title "Save BOLD Data" -initialdir $top_dir] if {$fname != ""} { set any [call_act_r_command "history-data-available" $model [list "bold-prediction-with-time-scaled"]] if {$any == "nil" || $any == ""} { tk_messageBox -icon warning -type ok -title "Save BOLD warning" \ -message "No data available to save with current settings." } else { global brain_3d_history_warnings set brain_3d_history_warnings "" set warning_monitor [add_new_cmd warning_monitor "brain_3d_record_warnings" "Environment command for capturing warnings during Save BOLD 3D brain trace."] send_cmd "monitor" [list "warning-trace" $warning_monitor] set result [call_act_r_command_with_error_messages "save-history-data" $model [list "bold-prediction-with-time-scaled" $fname "Data saved from BOLD 3D brain window for model $model"]] send_cmd "remove-monitor" [list "warning-trace" $warning_monitor] remove_cmd $warning_monitor if {[lindex $result 0] == 0} { tk_messageBox -icon warning -type ok -title "Save BOLD brain error" \ -message "Save-history-data resulted in error.\n[lindex $result 1]." } elseif {[lindex $result 1] == "null"} { tk_messageBox -icon warning -type ok -title "Save BOLD brain problem" \ -message "Save-history-data returned failure result.\n$brain_3d_history_warnings." } } } } proc load_3dbrain_history_data {win model scale} { global top_dir set fname [tk_getOpenFile -title "Load BOLD History" -initialdir $top_dir] if {$fname != ""} { get_3dbrain_history_data $win $model $scale $fname } } proc get_3dbrain_history_data {win model scale {fname ""}} { $win.get configure -state disabled $win.save configure -state disabled $win.load configure -state disabled $win.details configure -text "" if {$fname == ""} { set any [call_act_r_command "history-data-available" $model [list "bold-prediction-with-time-scaled"]] if {$any == "nil" || $any == ""} { $win.details configure -text "No Data available" set data [list "nothing"] } else { $win.details configure -text "Collecting Data ..." set id [call_act_r_command "start-incremental-history-data" $model [list "bold-prediction-with-time-scaled" 16000]] if {$id != ""} { set data [get_incremental_history $id] } else { tk_messageBox -icon warning -type ok -title "GetBOLD History warning" \ -message "Unknown problem occurred trying to get data." $win.details configure -text "Data Error occurred" $win.get configure -state normal $win.save configure -state normal $win.load configure -state normal return "" } $win.details configure -text "BOLD data for model $model" } } else { global brain_3d_history_warnings set brain_3d_history_warnings "" set warning_monitor [add_new_cmd warning_monitor "brain_3d_record_warnings" "Environment command for capturing warnings during Load BOLD 3D brain data."] send_cmd "monitor" [list "warning-trace" $warning_monitor] $win.details configure -text "Loading Data from file $fname" set id [call_act_r_command "start-incremental-history-data" $model [list "bold-prediction-with-time-scaled" 16000 $fname]] send_cmd "remove-monitor" [list "warning-trace" $warning_monitor] remove_cmd $warning_monitor if {$id == "" || $id == "null"} { tk_messageBox -icon warning -type ok -title "Load BOLD problem" \ -message "Get-history-data returned failure result.\n$brain_3d_history_warnings." $win.details configure -text "Failure to load data" $win.get configure -state normal $win.save configure -state normal $win.load configure -state normal return "" } else { set comment [call_act_r_command "get-incremental-history-data" nil [list $id]] set comment "[json::json2dict [lindex $comment 0]] loaded from file $fname" set data [get_incremental_history $id] } } if {$data != "nothing"} { $scale configure -to [expr [llength [lindex $data 0]] - 1 ] -tickinterval [expr [llength [lindex $data 0]] - 1 ] upvar #0 $win.data d set d "" for {set j 0} {$j < [llength [lindex $data 0]]} {incr j} { set sub "" for {set i 0} {$i < 8} {incr i} { lappend sub none } lappend d $sub } foreach x [lrange $data 1 end] { set index -1 switch [string tolower [lindex $x 0]] { manual {set index 0} goal {set index 1} vocal {set index 2} imaginal {set index 3} retrieval {set index 4} production {set index 5} aural {set index 6} visual {set index 7} } if {$index != -1} { set i 1 foreach y [lrange $x 1 end] { set d [lreplace $d $i $i [lreplace [lindex $d $i] $index $index $y]] incr i } } } redraw_brain $win 0 $scale set 0 } else { # should have more error checking... } $win.get configure -state normal $win.save configure -state normal $win.load configure -state normal if {$fname == "" && $data != "nothing"} { $win.details configure -text "BOLD data for model $model" } elseif {$fname != ""} { $win.details configure -text $comment } } add_bold_trace_type "3D brain" main_bold_brains
47,498
Common Lisp
.cl
846
47.375887
396
0.547479
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
17c42cc453a270237654ac2015f118cdbb9b1a566c2bc03e92c697c0486dc85a
14,363
[ -1 ]
14,364
72-ctrl-panel-gt-button.tcl
asmaloney_ACT-R/environment/GUI/dialogs/72-ctrl-panel-gt-button.tcl
set graphic_trace_table [dict create] frame [control_panel_name].gt_display -borderwidth 0 button [control_panel_name].gt_display.graphic_trace -command select_current_graphic_trace -text "Graphic Trace" -font button_font tk_optionMenu [control_panel_name].gt_display.which_trace current_graphic_trace "" [control_panel_name].gt_display.which_trace configure -font checkbox_font [[control_panel_name].gt_display.which_trace cget -menu] configure -font checkbox_font pack [control_panel_name].gt_display.which_trace -side right pack [control_panel_name].gt_display.graphic_trace -side left pack [control_panel_name].gt_display proc select_current_graphic_trace {} { global current_graphic_trace global graphic_trace_table if [dict exists $graphic_trace_table $current_graphic_trace] { set cmd [dict get $graphic_trace_table $current_graphic_trace] $cmd } else { tk_messageBox -title "No graphic trace" -message "No graphic trace type selected." -icon warning -type ok } } proc add_graphic_trace_type {title cmd} { global current_graphic_trace global graphic_trace_table set menu [[control_panel_name].gt_display.which_trace cget -menu] set top [$menu entrycget 0 -value] $menu add radiobutton -label $title -variable current_graphic_trace if {$top == ""} { $menu delete "" set current_graphic_trace $title } dict set graphic_trace_table $title $cmd }
1,422
Common Lisp
.cl
31
42.548387
130
0.762811
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
4e2aade63e4bd72374d7f04755a751b30cb9e7c0dcab243cf94be35bd9352553
14,364
[ -1 ]
14,365
23-ctrl-panel-run-button.tcl
asmaloney_ACT-R/environment/GUI/dialogs/23-ctrl-panel-run-button.tcl
frame [control_panel_name].run_frame -borderwidth 0 -width 130 entry [control_panel_name].run_frame.run_time -width 6 -font text_font \ -textvariable run_button_time -justify right [control_panel_name].run_frame.run_time insert 0 "10.0" set run_warnings "" proc record_run_warnings {model s} { global run_warnings set run_warnings "$run_warnings$s" return "" } button [control_panel_name].run_frame.run -text "Run" -font button_font -command { global run_warnings [control_panel_name].run_frame.run configure -state disabled set run_warnings "" set run_monitor [add_new_cmd run_monitor "record_run_warnings" "Environment command for capturing warnings during a call to run."] send_cmd "monitor" [list "warning-trace" $run_monitor] set result [call_act_r_command_with_error_messages "run" "nil" [list $run_button_time]] send_cmd "remove-monitor" [list "warning-trace" $run_monitor] remove_cmd $run_monitor if {[lindex $result 0] == 0} { tk_messageBox -icon warning -type ok -title "Run Error" \ -message [lindex $result 1] } elseif {[lindex $result 1] == "null"} { tk_messageBox -icon warning -type ok -title "Run Error" \ -message $run_warnings } set $run_warnings "" [control_panel_name].run_frame.run configure -state normal } pack [control_panel_name].run_frame.run -side left pack [control_panel_name].run_frame.run_time -side right pack [control_panel_name].run_frame
1,501
Common Lisp
.cl
32
41.90625
132
0.704782
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
f37d78ac6b2e55005567179cadfa2f150e9b75085c2d9ab57bc4a912fc3a601d
14,365
[ -1 ]
14,366
11-ctrl-panel-load-button.tcl
asmaloney_ACT-R/environment/GUI/dialogs/11-ctrl-panel-load-button.tcl
# The use_smart_load is going to be on the options panel, and it # determines whether or not the file is just reloaded with the reload # command (when it's nil) or whether the smart-loader function # is used. For now the default is t - use smart-loader set load_result "" proc record_load_traces {model s} { global load_result set load_result "$load_result$s" return "" } proc load_model_file {fname {wait ""}} { global load_result global options_array set load_result "" set load_monitor [add_new_cmd load_monitor "record_load_traces" "Environment command for capturing output during Load ACT-R code."] send_cmd "monitor" [list "model-trace" $load_monitor] send_cmd "monitor" [list "command-trace" $load_monitor] send_cmd "monitor" [list "warning-trace" $load_monitor] send_cmd "monitor" [list "general-trace" $load_monitor] set result [call_act_r_command_with_error_messages "load-act-r-code" nil [list {$fname} $options_array(use_smart_load)]] send_cmd "remove-monitor" [list "model-trace" $load_monitor] send_cmd "remove-monitor" [list "command-trace" $load_monitor] send_cmd "remove-monitor" [list "warning-trace" $load_monitor] send_cmd "remove-monitor" [list "general-trace" $load_monitor] remove_cmd $load_monitor set win [toplevel [new_variable_name .reload_response]] # hide the window for speed and aesthetic reasons wm withdraw $win wm geometry $win [get_configuration .reload_response $win] set text_frame [frame $win.text_frame -borderwidth 0] set text_box [text $text_frame.text -yscrollcommand \ "$text_frame.text_scrl set" -state normal \ -font text_font] set text_scroll_bar [scrollbar $text_frame.text_scrl \ -command "$text_box yview"] set the_button [button $win.but -text "Ok" -font button_font -command "destroy $win"] place $text_frame -x 0 -y 0 -relheight 1.0 -height -30 -relwidth 1.0 place $the_button -relx .5 -x -30 -width 60 -rely 1.0 -y -30 -height 30 pack $text_scroll_bar -side right -fill y pack $text_box -side left -expand 1 -fill both if {[lindex $result 0] == 0} { wm title $win "ERROR Loading" $text_box insert 1.0 "$load_result\n[lindex $result 1]" } else { wm title $win "SUCCESSFUL Load" $text_box insert 1.0 $load_result } wm deiconify $win focus $win if {$wait != ""} {tkwait window $win} } button [control_panel_name].load -text "Load ACT-R code" -font button_font -command { global local_connection global top_dir global current_file_window global currently_open_files set fname "" if {$local_connection == 0} { tk_messageBox -icon warning -type ok -title "Load warning" \ -message "You cannot use the Load ACT-R code button if the\ environment is not running on the same machine\ as ACT-R." } else { if {$current_file_window == ""} { set fname [tk_getOpenFile -title "File to load" -initialdir $top_dir] } else { set fname [tk_getOpenFile -title "File to load" -initialdir [file dirname $currently_open_files($current_file_window)] -initialfile [file tail $currently_open_files($current_file_window)]] } if {$fname != ""} { load_model_file $fname } } } pack [control_panel_name].load
3,379
Common Lisp
.cl
74
39.972973
194
0.679594
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
5d5352ac7ad4c9c28bc8a6cf2c30ede09546d96242689c9c49490d701b92b549
14,366
[ -1 ]
14,367
99-exp-window.tcl
asmaloney_ACT-R/environment/GUI/dialogs/99-exp-window.tcl
# This file creates windows on the Environment side for showing # Experiments generated with the AGI. # There can be any number of experiment windows on the environment side, # but there's only one "main" handler which isn't visible but is used # to catch the environment closing to remove the vv-handler. toplevel .env_window wm withdraw .env_window global name_to_window_array global name_to_params_array proc name_to_window {name} { global name_to_window_array if {[array names name_to_window_array -exact $name] != ""} { return $name_to_window_array($name) } else { return "" } } proc name_to_params {name} { global name_to_params_array if {[array names name_to_params_array -exact $name] != ""} { return $name_to_params_array($name) } else { return "" } } proc add_name_to_window {name window params} { global name_to_window_array set name_to_window_array($name) $window global name_to_params_array set name_to_params_array($name) $params } proc remove_name_to_window {name} { global name_to_window_array array unset name_to_window_array $name global name_to_params_array array unset name_to_params_array $name } global agi_extensions_array proc agi_handlers {cmd} { global agi_extensions_array if {[array names agi_extensions_array -exact $cmd] != ""} { return $agi_extensions_array($cmd) } else { return "" } } proc call_agi_handlers {cmd win coords params} { foreach i [agi_handlers $cmd] { $i $cmd $win $coords $params } } proc add_agi_handler {cmd fn} { global agi_extensions_array if {[array names agi_extensions_array -exact $cmd] != ""} { set agi_extensions_array($cmd) [lappend $agi_extensions_array($cmd) $fn] } else { set agi_extensions_array($cmd) [list $fn] } } set env_handler [add_new_cmd "env_vv_handler" "process_env_window" "Environment command for handling the visible virtual windows. Do not call."] call_act_r_command "add-virtual-window-handler" nil [list $env_handler] bind .env_window <Destroy> { global $env_handler call_act_r_command "remove-virtual-window-handler" nil [list $env_handler] } proc create_env_window {title x y width height} { set win [toplevel [new_variable_name ".visible_virtual"]] wm withdraw $win wm title $win $title wm geometry $win [format "%dx%d+%d+%d" $width $height $x $y] canvas $win.can place $win.can -x 0 -y 0 -relwidth 1.0 -relheight 1.0 add_name_to_window $title $win [list $x $y $width $height] # don't really close it when the close button pressed wm protocol $win WM_DELETE_WINDOW "wm withdraw $win" # send all the keypresses and mouse button 1 clicks to ACT-R bind $win <KeyPress> "call_act_r_command_string_only output-key nil [list [list false [translate_key %K]]]" bind $win <Button-1> "call_act_r_command visible-virtual-window-mouse-click nil [list [list $title %x %y]]" wm deiconify $win focus -force $win } proc lighten_color {w c degree} { set max [lindex [winfo rgb $w white] 0] set offset [expr ($max + 1) / $degree] set size [string length [format "%x" $max]] set clist [winfo rgb $w $c] set c1 [lindex $clist 0] set c2 [lindex $clist 1] set c3 [lindex $clist 2] return [format "\#%0*X%0*X%0*X" \ $size [expr ($c1 + $offset) < $max ? $c1 + $offset : $max] \ $size [expr ($c2 + $offset) < $max ? $c2 + $offset : $max] \ $size [expr ($c3 + $offset) < $max ? $c3 + $offset : $max]] } proc flip_button_view {win box_down box_up down up} { # assume that if one of the tagged items still exists # that they all do since it's single threaded set check [$win.can find withtag $box_up] if {$check != ""} { $win.can raise "$box_up" "$box_down" $win.can raise "$up" "$box_up" $win.can lower "$down" "$box_up" } } proc process_env_window {model cmd} { global options_array set win [name_to_window [lindex $cmd 1]] set coords [name_to_params [lindex $cmd 1]] call_agi_handlers [lindex $cmd 0] $win $coords [lrange $cmd 2 end] switch [lindex $cmd 0] { check { return $options_array(use_env_window) } select { wm deiconify $win raise $win focus -force $win } close { $win.can delete all remove_name_to_window [lindex $cmd 1] destroy $win set win "" } open { if {$win != ""} { wm deiconify $win raise $win focus -force $win } else { create_env_window [lindex $cmd 1] [lindex $cmd 2] [lindex $cmd 3] [lindex $cmd 4] [lindex $cmd 5] } } remove { $win.can delete [lindex $cmd 2] } attention { $win.can delete "[lindex $cmd 2]-attention" set x [lindex $cmd 3] set y [lindex $cmd 4] if { $x >= [lindex $coords 0] && $x <= [expr [lindex $coords 0] + [lindex $coords 2]] && $y >= [lindex $coords 1] && $y <= [expr [lindex $coords 1] + [lindex $coords 3]]} { $win.can create oval [expr $x - 10 - [lindex $coords 0]] [expr $y - 10 - [lindex $coords 1]] [expr $x + 10 - [lindex $coords 0]] [expr $y + 10 - [lindex $coords 1]] -outline [translate_color [lindex $cmd 5]] -width 4 -tags [list "[lindex $cmd 2]-attention" attention] } } clearattention { $win.can delete "[lindex $cmd 2]-attention" } clearcursor { set tag "cursor-[lindex $cmd 2]" $win.can delete $tag } cursor { set tag "cursor-[lindex $cmd 2]" $win.can delete $tag set x [lindex $cmd 3] set y [lindex $cmd 4] $win.can create polygon $x $y $x [expr $y + 15] [expr $x + 4] [expr $y + 13] [expr $x + 7] [expr $y + 19] \ [expr $x + 9] [expr $y + 19] [expr $x + 7] [expr $y + 12] [expr $x + 12] [expr $y + 12] \ -fill white -outline [lindex $cmd 5] -tags [list $tag cursor] } line { $win.can create line [lindex $cmd 3] [lindex $cmd 4] \ [lindex $cmd 5] [lindex $cmd 6] \ -fill [translate_color [lindex $cmd 7]] -width 2 -tags [list [lindex $cmd 2] line] } text { $win.can create text [lindex $cmd 3] [lindex $cmd 4] \ -font [list courier [expr int(round([lindex $cmd 7] / [tk scaling]))] roman] -fill [translate_color [lindex $cmd 6]] \ -text [lindex $cmd 5] -anchor nw -tags [list [lindex $cmd 2] text] } button { # fake buttons so that we can draw the attention and cursor over them set x1 [lindex $cmd 3] set y1 [lindex $cmd 4] set x2 [expr $x1 + [lindex $cmd 5]] set y2 [expr $y1 + [lindex $cmd 6]] set base_color [translate_color [lindex $cmd 8]] set name [lindex $cmd 2] $win.can create rectangle $x1 $y1 $x2 $y2 \ -fill $base_color -outline white -width 1 -tags [list $name button "$name-box-up"] $win.can create rectangle $x1 $y1 $x2 $y2 \ -fill [lighten_color $win.can $base_color 2] -outline black -width 1 -tags [list $name button "$name-box-down"] $win.can create text [expr $x1 + round([lindex $cmd 5] / 2)] [expr $y1 + round([lindex $cmd 6] / 2)] \ -font button_font -fill black -text [lindex $cmd 7] -anchor center -tags [list $name button "$name-up"] $win.can create text [expr $x1 + round([lindex $cmd 5] / 2) + 1] [expr $y1 + round([lindex $cmd 6] / 2) + 1] \ -font button_font -fill black -text [lindex $cmd 7] -anchor center -tags [list $name button "$name-down"] $win.can create line $x2 $y1 $x2 $y2 -width 1 -fill black -tags [list $name button "$name-up"] $win.can create line $x2 $y2 $x1 $y2 -width 1 -fill black -tags [list $name button "$name-up"] $win.can create line $x2 $y1 $x2 $y2 -width 1 -fill white -tags [list $name button "$name-down"] $win.can create line $x2 $y2 $x1 $y2 -width 1 -fill white -tags [list $name button "$name-down"] $win.can create line [expr $x1 + 1] [expr $y1 + 1] [expr $x1 + 1] [expr $y2 - 1] -width 1 -fill darkgray -tags [list $name button "$name-down"] $win.can create line [expr $x1 + 1] [expr $y1 + 1] [expr $x2 - 1] [expr $y1 + 1] -width 1 -fill darkgray -tags [list $name button "$name-down"] $win.can create line [expr $x2 - 1] [expr $y1 + 1] [expr $x2 - 1] [expr $y2 - 1] -width 1 -fill darkgray -tags [list $name button "$name-up"] $win.can create line [expr $x2 - 1] [expr $y2 - 1] [expr $x1 + 1] [expr $y2 - 1] -width 1 -fill darkgray -tags [list $name button "$name-up"] # set things in the "up" position $win.can raise "$name-box-up" "$name-box-down" $win.can raise "$name-up" "$name-box-up" $win.can lower "$name-down" "$name-box-up" } click { set name [lindex $cmd 2] # set things in the down position $win.can raise "$name-box-down" "$name-box-up" $win.can raise "$name-down" "$name-box-down" $win.can lower "$name-up" "$name-box-down" after 100 "flip_button_view $win \"$name-box-down\" \"$name-box-up\" \"$name-down\" \"$name-up\"" } } call_agi_handlers agi_change $win $coords [lrange $cmd 2 end] if {$win != "" && [$win.can gettags all] != ""} { # make sure these show over everything after any update $win.can raise cursor all $win.can raise attention all } } proc translate_key {key} { switch $key { Escape {return "esc"} quoteleft {return "`"} minus {return "-"} equal {return "="} backslash {return "\\"} BackSpace {return "delete"} bracketleft {return "\["} bracketright {return "\]"} Caps_Lock {return "caps-lock"} semicolon {return ";"} Prior {return "pageup"} Delete {return "forward-delete"} Next {return "pagedown"} Shift_L {return "shift"} comma {return ","} period {return "."} slash {return "/"} Shift_R {return "right-shift"} Up {return "up-arrow"} Left {return "left-arrow"} Down {return "down-arrow"} Right {return "right-arrow"} Control_L {return "control"} Win_L {return "option"} Alt_L {return "command"} Alt_R {return "right-command"} Win_R {return "right-option"} Control_R {return "right-control"} asterisk {return "keypad-*"} plus {return "keypad-+"} 0 {return "0"} 1 {return "1"} 2 {return "2"} 3 {return "3"} 4 {return "4"} 5 {return "5"} 6 {return "6"} 7 {return "7"} 8 {return "8"} 9 {return "9"} default {return $key} } } proc translate_color {color} { switch $color { black {return "black"} blue {return "blue"} brown {return "brown"} cyan {return "cyan"} dark-blue {return "blue4"} dark-cyan {return "cyan4"} dark-gray {return "gray40"} dark-green {return "green4"} dark-magenta {return "magenta4"} dark-red {return "red4"} dark-yellow {return "yellow4"} gray {return "gray"} green {return "green"} light-blue {return "LightBlue"} light-gray {return "gray90"} magenta {return "magenta"} pink {return "pink"} purple {return "purple"} red {return "red"} white {return "white"} yellow {return "yellow"} default {return "black"} } }
11,451
Common Lisp
.cl
286
33.793706
275
0.604108
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
ba847c4ae04257a1fbb45a741b62fe8a433cd77d52458c82468dff4eeb173d1d
14,367
[ -1 ]
14,368
35-declarative.tcl
asmaloney_ACT-R/environment/GUI/dialogs/35-declarative.tcl
proc make_declarative_viewer {} { set model [currently_selected_model] if {$model == "nil"} { tk_messageBox -icon info -type ok -title "Declarative" -message "Declarative memory viewer requires a current model." } else { set win [toplevel [new_variable_name .declarative]] wm withdraw $win record_new_window $win $win $model wm geometry $win [get_configuration .declarative $win] set filter_label [label $win.filter_label -text "Filter:" -justify left -font label_font] set list_frame [frame $win.list_frame -borderwidth 2] set list_box [listbox $list_frame.list_box -listvar \ $list_frame.list_box.var \ -yscrollcommand "$list_frame.list_scrl set" \ -selectmode single \ -exportselection 0 -font list_font -bd 0] set list_scroll_bar [scrollbar $list_frame.list_scrl -command "$list_box yview"] # here's the frame for the chunk display set text_frame [frame $win.text_frame -borderwidth 0] set text_box [text $text_frame.text -yscrollcommand \ "$text_frame.text_scrl set" -state disabled \ -font text_font] set text_scroll_bar [scrollbar $text_frame.text_scrl -command "$text_box yview"] bind $list_box <<ListboxSelect>> "select_chunk $list_box $text_box $model" set why_not [button $win.whynot_button -text "Why not?" -font button_font \ -command "show_why_not_dm $list_box $model"] # Here is where I create my own drop-down (combobox, whatever you want to # call it) widget for the filter. This one is actually going to be a button # that when pressed displays the list of items to choose from. I guess # that's slightly outside of the style guidelines, but it doesn't seem too # bad to me but if people don't like it maybe I'll fix it then. set filter_button [button $win.filter_button -text "_none_" -borderwidth 2 \ -relief sunken -font button_font\ -command "declarative_drop_list \ $win \ $win.filter_button \ $list_box \ $text_box \ $model"] # here the items are placed into the window using the relative # options for those items that need to resize if the window gets resized # could get this from the Visual Tcl/tk GUI builder, or just work it out # sizes are based on the default fonts, so if you change that it could # look a little "off" place $filter_label -x 80 -y 5 -width 40 -height 20 place $filter_button -x 124 -y 5 -relwidth 1.0 -width -130 -height 24 place $why_not -x 2 -y 5 -width 75 -height 24 place $list_frame -relx 0.0 -y 35 -relheight 1.0 -height -35 -relwidth .4 place $text_frame -relx .4 -y 35 -relheight 1.0 -height -35 -relwidth .6 pack $list_scroll_bar -side right -fill y pack $list_box -side left -expand 1 -fill both pack $text_scroll_bar -side right -fill y pack $text_box -side left -expand 1 -fill both set_update_script $win "update_dm_chunk_list $list_box $text_box $model $filter_button" # now show the window wm deiconify $win focus $win } } proc update_dm_chunk_list {list text_box model filter_button} { # get the new list, and if something is selected output that in the window set filter [$filter_button cget -text] set chunks [lindex [call_act_r_command "filter-dm-chunks" $model [list $filter]] 0] global options_array if {$options_array(sort_lists) == 1} { set chunks [lsort -dictionary $chunks] } global $list.var set selection [$list curselection] if {$selection != ""} { set name [$list get $selection] } set $list.var $chunks if {$selection != ""} { # check if the selection is still available $list selection clear 0 end set newpos [lsearch -exact $chunks $name] if {$newpos != -1} { $list selection set $newpos } } select_chunk $list $text_box $model } proc select_chunk {list_box text_box model} { if {[$list_box curselection] != ""} { update_text_pane $text_box [lindex [call_act_r_command "dm-chunk-details" $model [list [$list_box get [$list_box curselection]]]] 0] } else { update_text_pane $text_box "" } } # declarative_drop_list # This is the procedure that implements the interaction of a drop-down # widget triggered by pressing a button. Its parameters are that button (but) # the window (top) that holds a frame (drop_frame) which contains # the listbox (drop_box) and the scrollbar (drop_scroll_bar), and the chunk # list widget (list_box). # It displays the selection listbox below the button and waits for either a # selection or the dismissal of the selection box. If there is a selection # different from the current one it updates the button to reflect the new # choice and issues an update request for the chunk list for chunks with the # specified slots. proc pick_drop_selection {var box} { global $var if {[$box curselection] != ""} { set $var [$box get [$box curselection]] } else { set $var -1 } } proc quit_drop_selection {var} { global $var set $var -1 } proc declarative_drop_list {win but list_box text_box model} { # first create a toplevel window that will hold the selection list # it's got to be a separate window so that things like leaving it's focus # can easily be trapped if [winfo exists $win.top] { destroy $win.top } set top [toplevel $win.top] wm overrideredirect $top 1 wm withdraw $top # now create a listbox to hold the list that drops down set drop_frame [frame $top.frame -borderwidth 0] set drop_box [listbox $drop_frame.drop_box \ -listvar $drop_frame.drop_box.var \ -yscrollcommand "$drop_frame.drop_scrl set" \ -exportselection 0 -font list_font -bd 0] set drop_scroll_bar [scrollbar $drop_frame.drop_scrl -command "$drop_box yview"] # create a variable for recording the response global $but.choice set $but.choice "" # Only take the selection when the button is released or return pressed bind $drop_box <ButtonRelease-1> "pick_drop_selection $but.choice $drop_box" bind $drop_box <Key-Return> "pick_drop_selection $but.choice $drop_box" # have the esc key close down the interaction without a choise and moving outside the window bind $drop_box <Key-Escape> "quit_drop_selection $but.choice" # if the user moves the focus outside of this window then destroy it bind $top <FocusOut> "quit_drop_selection $but.choice" # record the current filter set current_filter [$but cget -text] # get the new one global $drop_frame.drop_box.var set $drop_frame.drop_box.var [lindex [call_act_r_command "dm-slot-filters" $model] 0] # get a pointer to the list of chunk_types upvar $drop_frame.drop_box.var cur_list # figure out where the current selection is in the list # so that it can be made visible set choice [lsearch -exact $cur_list $current_filter] # make the selection window as wide as the button and 5 lines high set f_height [font metrics list_font -linespace] $top configure -width [winfo width $but] -height [expr 5*$f_height] # put the selection components into the top level window place $drop_frame -relx 0.0 -rely 0.0 -relheight 1.0 -relwidth 1.0 pack $drop_scroll_bar -side right -fill y pack $drop_box -side left -expand 1 -fill both # move the top level window so that it's directly below the button set x [winfo rootx $but] set y [winfo rooty $but] set y [expr $y + [winfo height $but]] wm geometry $top "+$x+$y" # make it visible and ensure it's on top wm deiconify $top raise $top # set the selected item in the list to the current filter choice and # make sure it's visible in the list $drop_box activate $choice $drop_box see $choice # make the selection box the current focus focus $drop_box # wait for the user to pick something or dismiss the window tkwait variable $but.choice upvar $but.choice new_choice destroy $top # if the user picked something that was different from # what was chosen before then change the button's text if {$new_choice != -1 && $new_choice != $current_filter} { $but configure -text $new_choice } # make sure to focus on the main window again to # have the update occur automatically because # if it gets called directly it could happen twice focus -force $win } proc show_why_not_dm {chunks model} { # get the current selection - knowing it's a single selection list box set selection [$chunks curselection] if {$selection != "" } { # get the chunk name set chunk [$chunks get $selection] # make a new window set top [toplevel [new_variable_name ".whynotdm"]] wm geometry $top [get_configuration .whynotdm $top] record_new_window $top "Whynot-dm $chunk" $model # create a text_box to hold the output and put it in the window # also need a frame to hold it and the scroll bar frame $top.frame -borderwidth 0 set text_box [text $top.frame.text -font text_font -state disabled \ -yscrollcommand "$top.frame.scrl set" ] set scrl_bar [scrollbar $top.frame.scrl -command "$top.frame.text yview"] place $top.frame -x 0 -y 0 -relwidth 1.0 -relheight 1.0 pack $scrl_bar -side right -fill y pack $text_box -side left -expand 1 -fill both # get the text for the window update_text_pane $text_box [lindex [call_act_r_command "dm-whynot-text" $model [list $chunk]] 0] } } # Make a button for the control panel that will open a new declarative viewer button [control_panel_name].declarative -command {make_declarative_viewer} \ -text "Declarative" -font button_font # put that button on the control panel pack [control_panel_name].declarative
10,296
Common Lisp
.cl
213
41.206573
136
0.67034
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
80a4713cf52eabcdb3aa1207da6a4ba980bcfb08eceb69d26b7f0ac9e6619b9c
14,368
[ -1 ]
14,369
12-ctrl-panel-open-button.tcl
asmaloney_ACT-R/environment/GUI/dialogs/12-ctrl-panel-open-button.tcl
# Combine the Open and save buttons into one file (close no longer useful since multiple files may be opened) # Open frame [control_panel_name].o_frame button [control_panel_name].o_frame.open -text "Open File" \ -font button_font \ -command { global local_connection global currently_open_files global model_type global top_dir global options_array if {$local_connection == 0} { tk_messageBox -icon warning -type ok -title "Open warning" \ -message "You cannot use the Open File button if the\ environment is not running on the same machine\ as ACT-R." } else { if {$options_array(edit_warn) == 1} { tk_messageBox -icon warning -type ok -title "Open file" \ -message "ACT-R model and experiment files are regular text files.\ They can be opened and modified with any text editor.\ This tool is not meant as the primary means of working with\ ACT-R files. It is a very limited text editor meant mostly\ as a way to view or make simple changes to the files.\ This warning can be disabled in the Options." } set fname [tk_getOpenFile -title "File to open" -initialdir $top_dir] if {$fname != ""} { edit_model_file $fname } } } button [control_panel_name].o_frame.create -text "New File" \ -font button_font \ -command { global local_connection global currently_open_files global model_type global top_dir global options_array if {$local_connection == 0} { tk_messageBox -icon warning -type ok -title "Open warning" \ -message "You cannot use the Open File button if the\ environment is not running on the same machine\ as ACT-R." } else { if {$options_array(edit_warn) == 1} { tk_messageBox -icon warning -type ok -title "New file" \ -message "ACT-R model and experiment files are regular text files.\ They can be created and modified with any text editor.\ This tool is not meant as the primary means of working with\ ACT-R files, and it is a very limited text editor.\ This warning can be disabled in the Options." } set fname [tk_getSaveFile -title "Save new file as" -initialdir $top_dir] if {$fname != ""} { write_data "" $fname edit_model_file $fname } } } pack [control_panel_name].o_frame.open -side left pack [control_panel_name].o_frame.create -side left pack [control_panel_name].o_frame set pmatch_id "" proc edit_model_file {file_name} { global current_file_window global file_changed global currently_open_files set win_name [toplevel [new_variable_name .edit_window]] wm withdraw $win_name wm geometry $win_name [get_configuration .model $win_name] wm title $win_name [file tail $file_name] # create a text_box to hold the output and put it in the window # also need a frame to hold it and the scroll bar frame $win_name.frame -borderwidth 0 set text_box [text $win_name.frame.text -yscrollcommand "$win_name.frame.vscrl set" \ -xscrollcommand "$win_name.frame.hscrl set" -font text_font -wrap none] set v_scrl_bar [scrollbar $win_name.frame.vscrl -command "$win_name.frame.text yview"] set h_scrl_bar [scrollbar $win_name.frame.hscrl -command "$win_name.frame.text xview" -orient horizontal] place $win_name.frame -x 0 -y 0 -relwidth 1.0 -relheight 1.0 pack $v_scrl_bar -side right -fill y pack $h_scrl_bar -side bottom -fill x pack $text_box -side left -expand 1 -fill both set data [read_file $file_name] if {$data != ""} { $text_box delete 1.0 end $text_box insert end $data } set currently_open_files($win_name) $file_name set file_changed($win_name) 0 set current_file_window $win_name bind $text_box <KeyPress-parenright> "edit_right_paren $win_name %W" bind $text_box <KeyPress-parenleft> "edit_left_paren $win_name %W" bind $text_box <KeyPress> " global file_changed set file_changed($win_name) 1 " set_update_script $win_name " global current_file_window set current_file_window $win_name " wm protocol $win_name WM_DELETE_WINDOW "prompt_close_text $win_name" wm deiconify $win_name raise $win_name focus $win_name } proc edit_left_paren {win text} { global file_changed set file_changed($win) 1 set start [$text index insert] set paren_count 1 set index_count -1 set hit_end 0 while { $paren_count != 0 && $hit_end == 0} { incr index_count 1 set cur_char [$text get "$start + $index_count chars"] if {[$text index "$start + $index_count chars"] == [$text index end]} { set hit_end 1 } if { $cur_char == "(" } { incr paren_count 1 } elseif {$cur_char == ")" } { incr paren_count -1 } } global pmatch_id if {$paren_count == 0} { if {[lsearch -exact [$text tag names] pmatch] != -1} { after cancel $pmatch_id $text tag delete pmatch } $text tag add pmatch "$start + $index_count chars" $text tag configure pmatch -underline 1 set pmatch_id [after 300 "$text tag delete pmatch"] } } proc edit_right_paren {win text} { global file_changed set file_changed($win) 1 set start [$text index insert] set paren_count 1 set index_count 0 set hit_start 0 while {$paren_count != 0 && $hit_start == 0} { incr index_count 1 set cur_char [$text get "$start - $index_count chars"] if {[$text index "$start - $index_count chars"] == [$text index 1.0]} { set hit_start 1 } if { $cur_char == ")" } { incr paren_count 1 } elseif {$cur_char == "(" } { incr paren_count -1 } } global pmatch_id if {$paren_count == 0} { if {[lsearch -exact [$text tag names] pmatch] != -1} { after cancel $pmatch_id $text tag delete pmatch } $text tag add pmatch "$start - $index_count chars" $text tag configure pmatch -underline 1 set pmatch_id [after 300 "$text tag delete pmatch"] } } proc prompt_close_text {win} { global currently_open_files global file_changed global current_file_window set remaining 0 if {$file_changed($win) == 1} { set answer [tk_messageBox -icon warning -title "Closing $currently_open_files($win)]" \ -message "Save changes before closing?" -type yesnocancel] switch -- $answer { yes { save_model $win destroy $win } no { destroy $win } cancel { set remaining 1 } } } else { destroy $win } if {$remaining == 0} { set current_file_window "" array unset currently_open_files $win array unset file_changed $win } } # Save button [control_panel_name].save \ -command { global current_file_window [control_panel_name].save configure -state disabled save_model $current_file_window [control_panel_name].save configure -state normal } \ -text "Save File" -font button_font pack [control_panel_name].save proc save_model {win} { global file_changed global currently_open_files if {$win == ""} { tk_messageBox -icon warning -type ok -title "Saving file" \ -message "You must select an open file window before pressing Save File." } else { save_backup $currently_open_files($win) save_text $win.frame.text $currently_open_files($win) set file_changed($win) 0 } } proc save_backup {fname} { global options_array if $options_array(save_backups) { set save_index 0 while {[file exists "$fname-$save_index"] == 1} { incr save_index } write_data [read_file $fname] "$fname-$save_index" } }
8,618
Common Lisp
.cl
229
28.641921
109
0.601404
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
6edfc9307d0378ebeb1536bfb8dfc4188959cc2d3a2e6975ce7e18932d30fc36
14,369
[ -1 ]
14,370
82-bold-brain.tcl
asmaloney_ACT-R/environment/GUI/dialogs/82-bold-brain.tcl
image create photo brain -file [file join $tcl_env_dir dialogs ref-brain.gif] proc make_bold_brains {} { set model [currently_selected_model] if {$model == "nil"} { tk_messageBox -icon info -type ok -title "BOLD 2D brain" -message "BOLD viewer requires a current model." } else { set win [toplevel [new_variable_name .bold_brain]] wm withdraw $win record_new_window $win $win $model wm geometry $win [get_configuration .bold_slices $win] set frame [frame $win.frame -borderwidth 0] canvas $win.frame.canvas -bg gray\ -xscrollcommand "$win.frame.scrlx set" \ -yscrollcommand "$win.frame.scrly set" \ -width 740 -height 640 -scrollregion {0 0 740 640} scrollbar $win.frame.scrlx -command "$win.frame.canvas xview" -orient horizontal scrollbar $win.frame.scrly -command "$win.frame.canvas yview" -orient vertical $win.frame.canvas create image 100 0 -image brain -anchor nw initialize_brain_scans $win global $win.data set $win.data "" call_act_r_command record-history $model [list "bold-prediction-with-time-scaled"] bind $win.frame.canvas <Destroy> " call_act_r_command stop-recording-history $model [list "bold-prediction-with-time-scaled"] global $win.data unset $win.data " scale $win.s -orient horizontal -command "report_scale_brain $win" -from 0 -to 0 -label "Scan #" -font checkbox_font -tickinterval 0 button $win.get -text "Get History" -font button_font -command "get_brain_history_data $win $model $win.frame.canvas $win.s" button $win.save -text "Save History" -font button_font -command "save_brain_history_data $model" button $win.load -text "Load History" -font button_font -command "load_brain_history_data $win $model $win.frame.canvas $win.s" label $win.details -font label_font pack $win.frame.scrlx -side bottom -fill x pack $win.frame.scrly -side right -fill y place $win.frame.canvas -relx 0 -rely 0 -relwidth 1.0 -relheight 1.0 place $win.frame -x 0 -y 0 -height -125 -relheight 1.0 -relwidth 1.0 place $win.s -relwidth 1.0 -rely 1.0 -y -125 -height 75 place $win.details -x 0 -rely 1.0 -y -50 -height 25 -relwidth 1.0 place $win.get -relx .05 -rely 1.0 -y -25 -height 25 -relwidth .3 place $win.save -relx .35 -rely 1.0 -y -25 -height 25 -relwidth .3 place $win.load -relx .65 -rely 1.0 -y -25 -height 25 -relwidth .3 wm deiconify $win pick_buffers } } proc initialize_brain_scans {win} { $win.frame.canvas delete box $win.frame.canvas delete text $win.frame.canvas create rectangle 262 68 272 78 -width 0 -fill "" -outline "" -tag {box manual} $win.frame.canvas create rectangle 390 68 400 78 -width 0 -fill "" -outline "" -tag {box manual} $win.frame.canvas create rectangle 518 68 528 78 -width 0 -fill "" -outline "" -tag {box manual} $win.frame.canvas create rectangle 646 68 656 78 -width 0 -fill "" -outline "" -tag {box manual} $win.frame.canvas create rectangle 316 68 326 78 -width 0 -fill "" -outline "" -tag {box manual} $win.frame.canvas create rectangle 444 68 454 78 -width 0 -fill "" -outline "" -tag {box manual} $win.frame.canvas create rectangle 572 68 582 78 -width 0 -fill "" -outline "" -tag {box manual} $win.frame.canvas create rectangle 700 68 710 78 -width 0 -fill "" -outline "" -tag {box manual} $win.frame.canvas create rectangle 390 602 400 612 -width 0 -fill "" -outline "" -tag {box visual} $win.frame.canvas create rectangle 518 602 528 612 -width 0 -fill "" -outline "" -tag {box visual} $win.frame.canvas create rectangle 646 602 656 612 -width 0 -fill "" -outline "" -tag {box visual} $win.frame.canvas create rectangle 444 602 454 612 -width 0 -fill "" -outline "" -tag {box visual} $win.frame.canvas create rectangle 572 602 582 612 -width 0 -fill "" -outline "" -tag {box visual} $win.frame.canvas create rectangle 700 602 710 612 -width 0 -fill "" -outline "" -tag {box visual} $win.frame.canvas create rectangle 542 46 548 56 -width 0 -fill "" -outline "" -tag {box goal} $win.frame.canvas create rectangle 670 46 676 56 -width 0 -fill "" -outline "" -tag {box goal} $win.frame.canvas create rectangle 158 174 164 184 -width 0 -fill "" -outline "" -tag {box goal} $win.frame.canvas create rectangle 286 174 292 184 -width 0 -fill "" -outline "" -tag {box goal} $win.frame.canvas create rectangle 550 46 556 56 -width 0 -fill "" -outline "" -tag {box goal} $win.frame.canvas create rectangle 678 46 684 56 -width 0 -fill "" -outline "" -tag {box goal} $win.frame.canvas create rectangle 166 174 172 184 -width 0 -fill "" -outline "" -tag {box goal} $win.frame.canvas create rectangle 294 174 300 184 -width 0 -fill "" -outline "" -tag {box goal} $win.frame.canvas create rectangle 260 190 270 200 -width 0 -fill "" -outline "" -tag {box vocal} $win.frame.canvas create rectangle 388 190 398 200 -width 0 -fill "" -outline "" -tag {box vocal} $win.frame.canvas create rectangle 516 190 526 200 -width 0 -fill "" -outline "" -tag {box vocal} $win.frame.canvas create rectangle 644 190 654 200 -width 0 -fill "" -outline "" -tag {box vocal} $win.frame.canvas create rectangle 316 190 326 200 -width 0 -fill "" -outline "" -tag {box vocal} $win.frame.canvas create rectangle 444 190 454 200 -width 0 -fill "" -outline "" -tag {box vocal} $win.frame.canvas create rectangle 572 190 582 200 -width 0 -fill "" -outline "" -tag {box vocal} $win.frame.canvas create rectangle 700 190 710 200 -width 0 -fill "" -outline "" -tag {box vocal} $win.frame.canvas create rectangle 274 224 284 234 -width 0 -fill "" -outline "" -tag {box imaginal} $win.frame.canvas create rectangle 402 224 412 234 -width 0 -fill "" -outline "" -tag {box imaginal} $win.frame.canvas create rectangle 530 224 540 234 -width 0 -fill "" -outline "" -tag {box imaginal} $win.frame.canvas create rectangle 658 224 668 234 -width 0 -fill "" -outline "" -tag {box imaginal} $win.frame.canvas create rectangle 304 224 314 234 -width 0 -fill "" -outline "" -tag {box imaginal} $win.frame.canvas create rectangle 432 224 442 234 -width 0 -fill "" -outline "" -tag {box imaginal} $win.frame.canvas create rectangle 560 224 570 234 -width 0 -fill "" -outline "" -tag {box imaginal} $win.frame.canvas create rectangle 688 224 698 234 -width 0 -fill "" -outline "" -tag {box imaginal} $win.frame.canvas create rectangle 388 164 398 174 -width 0 -fill "" -outline "" -tag {box retrieval} $win.frame.canvas create rectangle 516 164 526 174 -width 0 -fill "" -outline "" -tag {box retrieval} $win.frame.canvas create rectangle 644 164 654 174 -width 0 -fill "" -outline "" -tag {box retrieval} $win.frame.canvas create rectangle 132 292 142 302 -width 0 -fill "" -outline "" -tag {box retrieval} $win.frame.canvas create rectangle 444 164 454 174 -width 0 -fill "" -outline "" -tag {box retrieval} $win.frame.canvas create rectangle 572 164 582 174 -width 0 -fill "" -outline "" -tag {box retrieval} $win.frame.canvas create rectangle 700 164 710 174 -width 0 -fill "" -outline "" -tag {box retrieval} $win.frame.canvas create rectangle 188 292 198 302 -width 0 -fill "" -outline "" -tag {box retrieval} $win.frame.canvas create rectangle 536 300 544 308 -width 0 -fill "" -outline "" -tag {box procedural} $win.frame.canvas create rectangle 664 300 672 308 -width 0 -fill "" -outline "" -tag {box procedural} $win.frame.canvas create rectangle 152 428 160 436 -width 0 -fill "" -outline "" -tag {box procedural} $win.frame.canvas create rectangle 280 428 288 436 -width 0 -fill "" -outline "" -tag {box procedural} $win.frame.canvas create rectangle 554 300 562 308 -width 0 -fill "" -outline "" -tag {box procedural} $win.frame.canvas create rectangle 682 300 690 308 -width 0 -fill "" -outline "" -tag {box procedural} $win.frame.canvas create rectangle 170 428 178 436 -width 0 -fill "" -outline "" -tag {box procedural} $win.frame.canvas create rectangle 298 428 306 436 -width 0 -fill "" -outline "" -tag {box procedural} $win.frame.canvas create rectangle 642 322 652 332 -width 0 -fill "" -outline "" -tag {box aural} $win.frame.canvas create rectangle 130 450 140 460 -width 0 -fill "" -outline "" -tag {box aural} $win.frame.canvas create rectangle 258 450 268 460 -width 0 -fill "" -outline "" -tag {box aural} $win.frame.canvas create rectangle 386 450 396 460 -width 0 -fill "" -outline "" -tag {box aural} $win.frame.canvas create rectangle 702 322 712 332 -width 0 -fill "" -outline "" -tag {box aural} $win.frame.canvas create rectangle 190 450 200 460 -width 0 -fill "" -outline "" -tag {box aural} $win.frame.canvas create rectangle 318 450 328 460 -width 0 -fill "" -outline "" -tag {box aural} $win.frame.canvas create rectangle 446 450 456 460 -width 0 -fill "" -outline "" -tag {box aural} $win.frame.canvas create text 10 120 -text "manual" -fill gray -anchor w -font checkbox_font -tag {text manual.text} $win.frame.canvas create text 10 140 -text "goal" -fill gray -anchor w -font checkbox_font -tag {text goal.text} $win.frame.canvas create text 10 160 -text "vocal" -fill gray -anchor w -font checkbox_font -tag {text vocal.text} $win.frame.canvas create text 10 180 -text "imaginal" -fill gray -anchor w -font checkbox_font -tag {text imaginal.text} $win.frame.canvas create text 10 200 -text "retrieval" -fill gray -anchor w -font checkbox_font -tag {text retrieval.text} $win.frame.canvas create text 10 400 -text "procedural" -fill gray -anchor w -font checkbox_font -tag {text procedural.text} $win.frame.canvas create text 10 420 -text "aural" -fill gray -anchor w -font checkbox_font -tag {text aural.text} $win.frame.canvas create text 10 440 -text "visual" -fill gray -anchor w -font checkbox_font -tag {text visual.text} } proc make_brain_color {name level} { set rs 0 set gs 0 set bs 0 switch $name { manual { set rs 1 } goal { set gs 1 } vocal { set bs 1 } imaginal { set rs 1 set gs 1 } retrieval { set rs 1 set bs 1 } production { set rs 1 set bs 1 } aural { set gs 1 } visual { set bs 1 } } return [format "#%.2x%.2x%.2x" [expr round($rs * $level * 255)] [expr round($gs * $level * 255)] [expr round($bs * $level * 255)] ] } proc report_scale_brain {win s} { upvar #0 $win.data data if {$s == 0} { $win.frame.canvas itemconfigure box -fill "" foreach x $data { $win.frame.canvas itemconfigure [lindex $x 0] -width 1 -outline [make_brain_color [lindex $x 0] .75] $win.frame.canvas itemconfigure [lindex $x 0].text -fill [make_brain_color [lindex $x 0] .75] } } elseif {$s > 0} { foreach x $data { $win.frame.canvas itemconfigure [lindex $x 0] -fill [make_brain_color [lindex $x 0] [lindex $x $s]] } } } set brain_graph_history_warnings "" proc brain_graph_record_warnings {model s} { global brain_graph_history_warnings set brain_graph_history_warnings "$brain_graph_history_warnings$s" return "" } proc save_brain_history_data {model} { global top_dir set fname [tk_getSaveFile -title "Save BOLD Data" -initialdir $top_dir] if {$fname != ""} { set any [call_act_r_command "history-data-available" $model [list "bold-prediction-with-time-scaled"]] if {$any == "nil" || $any == ""} { tk_messageBox -icon warning -type ok -title "Save BOLD warning" \ -message "No data available to save with current settings." } else { global brain_graph_history_warnings set brain_graph_history_warnings "" set warning_monitor [add_new_cmd warning_monitor "brain_graph_record_warnings" "Environment command for capturing warnings during Save BOLD brain trace."] send_cmd "monitor" [list "warning-trace" $warning_monitor] set result [call_act_r_command_with_error_messages "save-history-data" $model [list "bold-prediction-with-time-scaled" $fname "Data saved from BOLD 2D brain window for model $model"]] send_cmd "remove-monitor" [list "warning-trace" $warning_monitor] remove_cmd $warning_monitor if {[lindex $result 0] == 0} { tk_messageBox -icon warning -type ok -title "Save BOLD brain error" \ -message "Save-history-data resulted in error.\n[lindex $result 1]." } elseif {[lindex $result 1] == "null"} { tk_messageBox -icon warning -type ok -title "Save BOLD brain problem" \ -message "Save-history-data returned failure result.\n$brain_graph_history_warnings." } } } } proc load_brain_history_data {win model canvas scale} { global top_dir set fname [tk_getOpenFile -title "Load BOLD History" -initialdir $top_dir] if {$fname != ""} { get_brain_history_data $win $model $canvas $scale $fname } } proc get_brain_history_data {win model canvas scale {fname ""}} { $win.get configure -state disabled $win.save configure -state disabled $win.load configure -state disabled initialize_brain_scans $win $win.details configure -text "" if {$fname == ""} { set any [call_act_r_command "history-data-available" $model [list "bold-prediction-with-time-scaled"]] if {$any == "nil" || $any == ""} { $win.details configure -text "No Data available" set data [list "nothing"] } else { $win.details configure -text "Collecting Data ..." set id [call_act_r_command "start-incremental-history-data" $model [list "bold-prediction-with-time-scaled" 16000]] if {$id != ""} { set data [get_incremental_history $id] } else { tk_messageBox -icon warning -type ok -title "Get BOLD History warning" \ -message "Unknown problem occurred trying to get data." $win.details configure -text "Data Error occurred" $win.get configure -state normal $win.save configure -state normal $win.load configure -state normal return "" } $win.details configure -text "BOLD data for model $model" } } else { global brain_graph_history_warnings set brain_graph_history_warnings "" set warning_monitor [add_new_cmd warning_monitor "brain_graph_record_warnings" "Environment command for capturing warnings during Load BOLD brain data."] send_cmd "monitor" [list "warning-trace" $warning_monitor] $win.details configure -text "Loading Data from file $fname" set id [call_act_r_command "start-incremental-history-data" $model [list "bold-prediction-with-time-scaled" 16000 $fname]] send_cmd "remove-monitor" [list "warning-trace" $warning_monitor] remove_cmd $warning_monitor if {$id == "" || $id == "null"} { tk_messageBox -icon warning -type ok -title "Load BOLD problem" \ -message "Get-history-data returned failure result.\n$brain_graph_history_warnings." $win.details configure -text "Failure to load data" $win.get configure -state normal $win.save configure -state normal $win.load configure -state normal return "" } else { set comment [call_act_r_command "get-incremental-history-data" nil [list $id]] set comment "[json::json2dict [lindex $comment 0]] loaded from file $fname" set data [get_incremental_history $id] } } if {$data != "nothing"} { $scale configure -to [expr [llength [lindex $data 0]] - 1 ] -tickinterval [expr [llength [lindex $data 0]] - 1 ] upvar #0 $win.data d set d "" foreach x [lrange $data 1 end] { lappend d [lreplace $x 0 0 [string tolower [lindex $x 0]]] } report_scale_brain $win 0 $scale set 0 } else { # should have more error checking... } $win.get configure -state normal $win.save configure -state normal $win.load configure -state normal if {$fname == "" && $data != "nothing"} { $win.details configure -text "BOLD data for model $model" } elseif {$fname != ""} { $win.details configure -text $comment } } add_bold_trace_type "2D brain" make_bold_brains
16,451
Common Lisp
.cl
279
53.075269
189
0.67152
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
d31fad9199f8ae367658daf0d95b8ac4602817f6e81328c339184d418316283f
14,370
[ -1 ]
14,371
95-ctrl-panel-opt-button.tcl
asmaloney_ACT-R/environment/GUI/dialogs/95-ctrl-panel-opt-button.tcl
global current_options proc select_options {} { global options_array global current_options array set current_options [array get options_array] if {[winfo exists .options] == 1} { wm deiconify .options raise .options } else { toplevel .options wm withdraw .options wm title .options "Options" wm geometry .options [get_configuration .options] frame .options.but_frame button .options.but_frame.save -text "Save" -font button_font -command { save_options destroy .options } button .options.but_frame.apply -text "Apply" -font button_font -command { apply_options } button .options.but_frame.cancel -text "Cancel" -font button_font -command { destroy .options } button .options.but_frame.revert -text "Revert" -font button_font -command { array set current_options [array get options_array] } pack .options.but_frame.save -side left pack .options.but_frame.apply -side left pack .options.but_frame.cancel -side left pack .options.but_frame.revert -side left checkbutton .options.use_env_window \ -text "Use an Environment window for visible experiment windows" \ -font checkbox_font -variable current_options(use_env_window) \ -onvalue true -offvalue false checkbutton .options.use_smart_load \ -text "Compile an ACT-R file when loaded or reloaded" \ -font checkbox_font -variable current_options(use_smart_load) \ -onvalue true -offvalue false checkbutton .options.save_before_reload \ -text "Automatically save all open files when reload pressed" \ -font checkbox_font \ -variable current_options(save_before_reload) \ -onvalue 1 -offvalue 0 checkbutton .options.show_copyrights \ -text "Show the ACT-R copyrights screen" \ -font checkbox_font \ -variable current_options(show_copyrights) \ -onvalue 1 -offvalue 0 checkbutton .options.save_backups \ -text "Automatically save a backup file when saving opened files" \ -font checkbox_font \ -variable current_options(save_backups) \ -onvalue 1 -offvalue 0 checkbutton .options.multiple_models_close \ -text "Close inspector windows for deleted models" \ -font checkbox_font \ -variable current_options(kill_model_windows) \ -onvalue 1 -offvalue 0 checkbutton .options.update_when_stepped \ -text "Update inspector windows automatically when stepping" \ -font checkbox_font \ -variable current_options(update_when_stepped) \ -onvalue 1 -offvalue 0 checkbutton .options.use_localhost \ -text "Use localhost instead of 127.0.0.1" \ -font checkbox_font \ -variable current_options(use_localhost) \ -onvalue 1 -offvalue 0 checkbutton .options.sort \ -text "Sort declarative, procedural, and buffers viewers' item lists" \ -font checkbox_font \ -variable current_options(sort_lists) \ -onvalue 1 -offvalue 0 checkbutton .options.edit_warn \ -text "Show message about editor when using Open File and New File" \ -font checkbox_font \ -variable current_options(edit_warn) \ -onvalue 1 -offvalue 0 pack .options.use_env_window -anchor w -expand 1 -fill x pack .options.use_smart_load -anchor w -expand 1 -fill x pack .options.save_before_reload -anchor w -expand 1 -fill x pack .options.show_copyrights -anchor w -expand 1 -fill x pack .options.save_backups -anchor w -expand 1 -fill x pack .options.multiple_models_close -anchor w -expand 1 -fill x pack .options.update_when_stepped -anchor w -expand 1 -fill x pack .options.use_localhost -anchor w -expand 1 -fill x pack .options.sort -anchor w -expand 1 -fill x pack .options.edit_warn -anchor w -expand 1 -fill x pack .options.but_frame wm deiconify .options } } proc apply_options {} { global options_array global current_options array set options_array [array get current_options] # take care of any special updating necessary # catch { # send_environment_cmd \ # "update [get_handler_name .env_window] \ # (lambda (x) \ # (declare (ignore x)) \ # (setf (environment-control-use-env-windows *environment-control*) $options_array(use_env_window) ) \ # (list 'ignore))" # } } proc save_options {} { global options_array global tcl_env_dir apply_options set file [file join $tcl_env_dir init "99-userconfig.tcl"] write_data "# this file generated from saving the options\n" $file foreach name [array names options_array] { append_data "set options_array($name) $options_array($name)\n" $file } } button [control_panel_name].options -text "Options" -font button_font -command {select_options} pack [control_panel_name].options
5,250
Common Lisp
.cl
119
35.722689
113
0.644218
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
9f171507bc652742c4a61f26ba7905413d0a89409aea06b3f6c23a0b8eff6db4
14,371
[ -1 ]
14,372
68-pgraph-button.tcl
asmaloney_ACT-R/environment/GUI/dialogs/68-pgraph-button.tcl
proc select_pgraph {} { set model [currently_selected_model] if {$model == "nil"} { tk_messageBox -icon info -type ok -title "Production Graph" -message "Production Graph viewer requires a current model." } else { set win [toplevel [new_variable_name .pgraph]] wm withdraw $win record_new_window $win $win $model wm geometry $win [get_configuration .pgraph $win] frame $win.frame -borderwidth 0 frame $win.frame.f -borderwidth 0 canvas $win.frame.f.canvas \ -xscrollcommand "$win.frame.f.scrlx set" \ -yscrollcommand "$win.frame.f.scrly set" \ -width 900 -height 300 -scrollregion {0 0 900 300} -bg white scrollbar $win.frame.f.scrlx \ -command "$win.frame.f.canvas xview" -orient horizontal scrollbar $win.frame.f.scrly \ -command "$win.frame.f.canvas yview" -orient vertical global $win.count global $win.max global $win.data global $win.labels global $win.boxes global $win.links global $win.graph_name set $win.count "" set $win.max "" set $win.data "" set $win.labels "" set $win.boxes "" set $win.links "" set $win.graph_name "" global $win.fname set $win.fname "" call_act_r_command "record-history" $model [list "production-history"] bind $win.frame.f.canvas <Destroy> " call_act_r_command stop-recording-history $model [list production-history] global $win.count unset $win.count global $win.max unset $win.max global $win.data unset $win.data global $win.labels unset $win.labels global $win.boxes unset $win.boxes global $win.links unset $win.links global $win.graph_name unset $win.graph_name " label $win.text -font text_font -anchor nw label $win.notes -font text_font -anchor nw frame $win.buttons -borderwidth 0 radiobutton $win.buttons.grid0 -text "All Transitions" -font button_font -value "production-graph-all" -variable $win.buttons.value radiobutton $win.buttons.grid1 -command "change_p_graph_data $win $model" -text "Frequencies" -font button_font -value "production-graph-freq" -variable $win.buttons.value radiobutton $win.buttons.grid2 -command "change_p_graph_data $win $model" -text "Cycles" -font button_font -value "production-graph-cycles" -variable $win.buttons.value radiobutton $win.buttons.grid3 -command "change_p_graph_data $win $model" -text "Unique Cycles" -font button_font -value "production-graph-u-cycles" -variable $win.buttons.value radiobutton $win.buttons.grid4 -command "change_p_graph_data $win $model" -text "Runs" -font button_font -value "production-graph-runs" -variable $win.buttons.value radiobutton $win.buttons.grid5 -command "change_p_graph_data $win $model" -text "Unique Runs" -font button_font -value "production-graph-u-runs" -variable $win.buttons.value radiobutton $win.buttons.grid6 -command "change_p_graph_data $win $model" -text "Utilities" -font button_font -value "production-graph-utility" -variable $win.buttons.value checkbutton $win.buttons.check \ -text "Hide unused productions" \ -font checkbox_font \ -variable $win.check_val \ -command "toggle_graph_unused $win $model" \ -onvalue 1 -offvalue 0 label $win.frame.cur_d -font text_font -anchor center label $win.frame.of -font text_font -text "of" -anchor center label $win.frame.max_d -font text_font -anchor center button $win.frame.next -command [list pgraph_flip_button_action increment_p_graph_count $win $model] -text "->" -font graphic_trace_font -state disable button $win.frame.previous -command [list pgraph_flip_button_action decrement_p_graph_count $win $model] -text "<-" -font graphic_trace_font -state disable button $win.save1 -command "save_phistory_graph $win" -text "Save as .eps" -font button_font button $win.save2 -command "save_phistory_graph_dot $win" -text "Save as .dot" -font button_font button $win.get -text "Get History" -font button_font -command "get_p_graph_data $win $model" button $win.save -text "Save History" -font button_font -command "save_p_graph_history_data $model" button $win.load -text "Load History" -font button_font -command "load_p_graph_history_data $win $model" global $win.labels global $win.boxes global $win.links global $win.graph_name place $win.buttons.grid0 -x 0 -y 0 -height 24 place $win.buttons.grid1 -x 0 -y 25 -height 24 place $win.buttons.grid2 -x 0 -y 50 -height 24 place $win.buttons.grid3 -x 0 -y 75 -height 24 place $win.buttons.grid4 -x 0 -y 100 -height 24 place $win.buttons.grid5 -x 0 -y 125 -height 24 place $win.buttons.grid6 -x 0 -y 150 -height 24 place $win.buttons.check -x 0 -rely 1.0 -y -25 -height 24 pack $win.frame.f.scrlx -side bottom -fill x pack $win.frame.f.scrly -side right -fill y pack $win.frame.f.canvas -side left -fill both place $win.frame.f -x 0 -y 0 -relwidth 1.0 -relheight 1.0 -height -25 place $win.frame.of -relx .5 -x -15 -width 30 -rely 1.0 -y -25 -height 24 place $win.frame.cur_d -relx .5 -x -77 -width 60 -rely 1.0 -y -25 -height 24 place $win.frame.previous -relx .5 -x -109 -width 30 -rely 1.0 -y -25 -height 24 place $win.frame.max_d -relx .5 -x 17 -width 60 -rely 1.0 -y -25 -height 24 place $win.frame.next -relx .5 -x 79 -width 30 -rely 1.0 -y -25 -height 24 place $win.buttons -x 0 -y 0 -width 150 -relheight 1.0 -height -100 place $win.frame -x 150 -y 0 -relwidth 1.0 -relheight 1.0 -height -75 -width -150 place $win.save1 -x 0 -rely 1.0 -y -75 -width 100 -height 24 place $win.save2 -x 0 -rely 1.0 -y -50 -width 100 -height 24 place $win.text -x 100 -rely 1.0 -y -75 -relwidth 1.0 -width -100 -height 24 place $win.notes -x 100 -rely 1.0 -y -50 -relwidth 1.0 -width -100 -height 24 place $win.get -relx .05 -rely 1.0 -y -25 -height 25 -relwidth .3 place $win.save -relx .35 -rely 1.0 -y -25 -height 25 -relwidth .3 place $win.load -relx .65 -rely 1.0 -y -25 -height 25 -relwidth .3 $win.buttons.grid0 invoke $win.buttons.grid0 configure -command "change_p_graph_data $win $model" wm deiconify $win } } proc pgraph_flip_button_action {action win model} { $action $win draw_p_graph $win $model 0 } proc increment_p_graph_count {win} { upvar #0 $win.count count upvar #0 $win.max max if {$count != $max} { incr count 1 } } proc decrement_p_graph_count {win} { upvar #0 $win.count count if {$count != 0} { incr count -1 } } proc load_p_graph_history_data {win model} { global top_dir set fname [tk_getOpenFile -title "Load Production History" -initialdir $top_dir] if {$fname != ""} { draw_p_graph $win $model 1 $fname } } proc toggle_graph_unused {win model} { draw_p_graph $win $model 0 } set pg_history_warnings "" proc pg_record_warnings {model s} { global pg_history_warnings set pg_history_warnings "$pg_history_warnings$s" return "" } proc get_p_graph_data {win model} { global $win.fname set $win.fname "" draw_p_graph $win $model 1 } proc change_p_graph_data {win model} { upvar #0 $win.fname saved_fname draw_p_graph $win $model 1 $saved_fname } proc draw_p_graph {win model clear_all {fname ""}} { $win.buttons.grid0 configure -state disabled $win.buttons.grid1 configure -state disabled $win.buttons.grid2 configure -state disabled $win.buttons.grid3 configure -state disabled $win.buttons.grid4 configure -state disabled $win.buttons.grid5 configure -state disabled $win.buttons.grid6 configure -state disabled $win.frame.next configure -state disabled $win.frame.previous configure -state disabled $win.save1 configure -state disabled $win.save2 configure -state disabled $win.get configure -state disabled $win.save configure -state disabled $win.load configure -state disabled upvar #0 $win.data data upvar #0 $win.count count upvar #0 $win.max max upvar #0 $win.buttons.value value upvar #0 $win.check_val hide_unused upvar #0 $win.labels labels upvar #0 $win.boxes boxes upvar #0 $win.links links upvar #0 $win.graph_name name upvar #0 $win.fname saved_fname $win.frame.f.canvas delete all if {$clear_all == 1} { $win.notes configure -text "" $win.frame.cur_d configure -text "" $win.frame.max_d configure -text "" if {$fname == ""} { set any [call_act_r_command "history-data-available" $model [list "production-history"]] if {$any == "nil" || $any == ""} { $win.text configure -text "No Data available" } else { $win.text configure -text "Collecting Data ..." set id [call_act_r_command "start-incremental-history-data" $model [list $value 16000]] if {$id != ""} { set data [get_incremental_history $id] } else { tk_messageBox -icon warning -type ok -title "Get Text History warning" \ -message "Unknown problem occurred trying to get data." $win.buttons.grid0 configure -state normal $win.buttons.grid1 configure -state normal $win.buttons.grid2 configure -state normal $win.buttons.grid3 configure -state normal $win.buttons.grid4 configure -state normal $win.buttons.grid5 configure -state normal $win.buttons.grid6 configure -state normal $win.save1 configure -state normal $win.save2 configure -state normal $win.get configure -state normal $win.save configure -state normal $win.load configure -state normal set name "Data Error occurred" return "" } $win.text configure -text "Production Graph data for model $model" set name "Production Graph data for model $model" set count 1 set max [expr [llength $data] - 1] } } else { global pg_history_warnings set pg_history_warnings "" set warning_monitor [add_new_cmd warning_monitor "pg_record_warnings" "Environment command for capturing warnings during Load Production Graph."] send_cmd "monitor" [list "warning-trace" $warning_monitor] $win.text configure -text "Loading Data from file $fname" set id [call_act_r_command "start-incremental-history-data" $model [list $value 16000 $fname]] send_cmd "remove-monitor" [list "warning-trace" $warning_monitor] remove_cmd $warning_monitor if {$id == "" || $id == "null"} { tk_messageBox -icon warning -type ok -title "Load Production Graph History problem" \ -message "Get-history-data returned failure result.\n$pg_history_warnings." set name "" $win.text configure -text "" $win.buttons.grid0 configure -state normal $win.buttons.grid1 configure -state normal $win.buttons.grid2 configure -state normal $win.buttons.grid3 configure -state normal $win.buttons.grid4 configure -state normal $win.buttons.grid5 configure -state normal $win.buttons.grid6 configure -state normal $win.save1 configure -state normal $win.save2 configure -state normal $win.get configure -state normal $win.save configure -state normal $win.load configure -state normal return "" } else { set comment [call_act_r_command "get-incremental-history-data" nil [list $id]] set data [get_incremental_history $id] set name [json::json2dict [lindex $comment 0]] $win.text configure -text "Loaded Data from file $fname" set saved_fname $fname set count 1 set max [expr [llength $data] - 1] } } } set labels [list] set boxes [list] set links [list] set min_time "" set max_time "" set size [lindex $data 0] if {[lindex $size 0] == "size"} { $win.frame.f.canvas configure -width [lindex $size 1] -height [lindex $size 2] -scrollregion "0 0 [lindex $size 1] [lindex $size 2]" } else { # should have more error checking... } foreach x [lindex $data $count] { switch [lindex $x 0] { label { set p [lindex $x 1] if {[lindex $x 8] == "gray"} { lappend labels "\"$p\" \[ color = gray \]" } else { lappend labels "\"$p\"" } if {$hide_unused == 0 || [lindex $x 8] == "black"} { $win.frame.f.canvas create text [lindex $x 2] [lindex $x 3] -anchor center -font text_font -text $p -tag $p $win.frame.f.canvas bind $p <ButtonPress> "p_graph_p_view $win $p {[lindex $x 9]}" $win.frame.f.canvas create rectangle [lindex $x 4] [lindex $x 5] [lindex $x 6] [lindex $x 7] -outline [lindex $x 8] -width 2 -tag $p } } box { lappend boxes "\"[lindex $x 1]\" \[ color = [lindex $x 6] \]" if {$hide_unused == 0 || [lindex $x 7] == 1} { $win.frame.f.canvas create rectangle [lindex $x 2] [lindex $x 3] [lindex $x 4] [lindex $x 5] -outline [lindex $x 6] -width 2 } } link { if {[lindex $x 3] == "gray"} { lappend links "\"[lindex $x 1]\" -> \"[lindex $x 2]\" \[ style=dashed color=gray \]" if {$hide_unused == 0 || [lindex $x 5] == 1} { $win.frame.f.canvas create line [lindex $x 6] -fill [lindex $x 3] -arrow last -smooth 1 -width [lindex $x 4] -dash ".-" } } else { lappend links "\"[lindex $x 1]\" -> \"[lindex $x 2]\"" if {$hide_unused == 0 || [lindex $x 5] == 1} { $win.frame.f.canvas create line [lindex $x 6] -fill [lindex $x 3] -arrow last -smooth 1 -width [lindex $x 4] -tag transient } } } min_time { set min_time [lindex $x 1] } max_time { set max_time [lindex $x 1] } } } $win.buttons.grid0 configure -state normal $win.buttons.grid1 configure -state normal $win.buttons.grid2 configure -state normal $win.buttons.grid3 configure -state normal $win.buttons.grid4 configure -state normal $win.buttons.grid5 configure -state normal $win.buttons.grid6 configure -state normal $win.save1 configure -state normal $win.save2 configure -state normal $win.get configure -state normal $win.save configure -state normal $win.load configure -state normal if {$max > 1} { if {$count < $max} { $win.frame.next configure -state normal } if {$count > 1} { $win.frame.previous configure -state normal } } if {$min_time != "" && $max_time != ""} { $win.notes configure -text "Time [expr $min_time / 1000.0] - [expr $max_time / 1000.0]" } else { $win.notes configure -text "" } $win.frame.cur_d configure -text $count $win.frame.max_d configure -text $max } proc save_p_graph_history_data {model} { global top_dir set fname [tk_getSaveFile -title "Save Production History" -initialdir $top_dir] if {$fname != ""} { set any [call_act_r_command "history-data-available" $model [list "production-history"]] if {$any == "nil" || $any == ""} { tk_messageBox -icon warning -type ok -title "Save Production History warning" \ -message "No data available to save with current settings." } else { global pg_history_warnings set pg_history_warnings "" set warning_monitor [add_new_cmd warning_monitor "pg_record_warnings" "Environment command for capturing warnings during Save Production History."] send_cmd "monitor" [list "warning-trace" $warning_monitor] set result [call_act_r_command_with_error_messages "save-history-data" $model [list "production-history" $fname "Data saved from Production History window for model $model"]] send_cmd "remove-monitor" [list "warning-trace" $warning_monitor] remove_cmd $warning_monitor if {[lindex $result 0] == 0} { tk_messageBox -icon warning -type ok -title "Save Production History error" \ -message "Get-history-data resulted in error.\n[lindex $result 1]." } elseif {[lindex $result 1] == "null"} { tk_messageBox -icon warning -type ok -title "Save Production History problem" \ -message "Get-history-data returned failure result.\n$pg_history_warnings." } } } } proc p_graph_p_view {win name text} { # make a new window set top [toplevel [new_variable_name ".p_graph_p_view"]] wm geometry $top [get_configuration .p_graph_p_view $top] wm title $top "[wm title $win] Production: $name" frame $top.frame -borderwidth 0 set text_box [text $top.frame.text -font text_font \ -yscrollcommand "$top.frame.scrl set" ] $text_box insert 0.0 $text set scrl_bar [scrollbar $top.frame.scrl -command "$top.frame.text yview"] place $top.frame -x 0 -y 0 -relwidth 1.0 -relheight 1.0 pack $scrl_bar -side right -fill y pack $text_box -side left -expand 1 -fill both } proc save_phistory_graph {win} { set fname [tk_getSaveFile -title "Save production graph as"\ -filetypes {{"Encapsulated PostScript" "*.eps"}}] if {$fname != ""} { $win.frame.f.canvas postscript -file $fname -width [$win.frame.f.canvas cget -width] -height [$win.frame.f.canvas cget -height] -x 0 -y 0 -pageanchor nw -pagex 0.0 -pagey [$win.frame.f.canvas cget -height] -pagewidth [$win.frame.f.canvas cget -width] } } proc save_phistory_graph_dot {win} { set fname [tk_getSaveFile -title "Save production graph as"\ -filetypes {{"DOT file" "*.dot"}}] if {$fname != ""} { upvar #0 $win.labels labels upvar #0 $win.boxes boxes upvar #0 $win.links links upvar #0 $win.graph_name name write_data "digraph $name \{\n" $fname foreach label $labels { append_data " $label ;\n" $fname } foreach box $boxes { append_data " $box ;\n" $fname } foreach link $links { append_data " $link ;\n" $fname } append_data "\}" $fname } } add_p_history_type "graph" select_pgraph
18,455
Common Lisp
.cl
406
38.53202
255
0.648312
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
3f424db977c91e71d4ad0dfc7d9398e17be53c326c0af92750f48d46c3c6731f
14,372
[ -1 ]
14,373
71-pick-buffers.tcl
asmaloney_ACT-R/environment/GUI/dialogs/71-pick-buffers.tcl
proc pick_buffers {} { set model [currently_selected_model] if {$model == "nil"} { tk_messageBox -icon info -type ok -title "Select Buffers" -message "Selecting Buffers to record requires a current model." } else { set win .pick_buffers_$model if {[winfo exists $win] == 1} { wm deiconify $win raise $win } else { toplevel $win wm withdraw $win wm geometry $win [get_configuration .pick_buffers $win] record_new_window $win $win $model set buffers [lindex [call_act_r_command "model-buffers" $model ""] 0] set y 0 foreach b [lsort $buffers] { set name [string tolower $b] checkbutton $win.$name -text $b \ -font checkbox_font \ -command "toggle_buffer $win $name $model" \ -onvalue 1 -offvalue 0 \ -variable $win.$name \ -height 24 -anchor nw bind $win.$name <Destroy> "global $win.$name unset $win.$name " place $win.$name -x 10 -y $y -height 25 -relwidth 1.0 -width -10 incr y 25 } set used [lindex [call_act_r_command "used-production-buffers" $model ""] 0] foreach b $used { set name [string tolower $b] upvar #0 $win.$name v if {$v == 0} { $win.$name invoke } } # don't destroy it when the close button pressed # but do stop recording because that is just # enabled to avoid the warnings wm protocol $win WM_DELETE_WINDOW "wm withdraw $win" wm deiconify $win } } } proc toggle_buffer {win name model} { upvar #0 $win.$name v if {$v == 1} { call_act_r_command "record-history" $model [list $name] } else { call_act_r_command "stop-recording-history" $model [list $name] } } button [control_panel_name].pick_buffers -command pick_buffers -text "Select Buffers" -font button_font # put that button on the control panel # Don't put the button there -- let the other tools open it so that buffer-history is recorded first # pack [control_panel_name].pick_buffers
2,302
Common Lisp
.cl
58
29.396552
127
0.575646
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
43bc67193cc5bb98c6105debae4122183aa569311fa00836ffda300ba46928d7
14,373
[ -1 ]
14,374
simple_declarative.py
asmaloney_ACT-R/examples/creating-modules/external/simple_declarative.py
# Implement a replacement declartive memory module which provides # a very small subset of the standard version that is sufficient # to run the unit 1 models as an example. # Also uses some ACT-R tools (matching chunks and a merge function # for the parameters) to make the implementation simpler. # Depends on the actr interface from the tutorial. import actr import threading # Remove the default module and the commands it creates which # are being redefined. actr.undefine_module('declarative') actr.remove_command('add-dm') actr.remove_command('dm') actr.remove_command('sdp') # To support multiple models keep a dictionary of model name to module instances declarative_modules = {} def current_module(name): return declarative_modules[name.lower()] # A simple class to hold the module info class declarative_module(): def __init__(self): self.lock = threading.Lock() # To avoid potential issues always lock access when changing things self.chunks = [] # a simple list of all the chunks self.pending = False # any event for an ongoing retrieval/failure self.error = False # did the last request fail self.lf = 1 # value of :lf parameter self.esc = False # is the :esc parameter set def reset(self): self.lock.acquire() self.chunks = [] self.pending = False self.error = False self.lock.release() # Functions and ACT-R commands for the scheduled events to handle retrievals def retrieved_chunk(name,chunk): module = current_module(name) module.lock.acquire() module.pending = False actr.schedule_set_buffer_chunk("retrieval",chunk,0,"declarative",":max") module.lock.release() actr.add_command('retrieved-chunk',retrieved_chunk,'Python declarative module successful retrieval event.') def retrieval_failure(name): module = current_module(name) module.lock.acquire() module.pending = False module.error = True actr.call_command("set-buffer-failure","retrieval") module.lock.release() actr.add_command('retrieval-failure',retrieval_failure,'Python declarative module unsuccessful retrieval event.') actr.add_command('start-retrieval',None,'Signal for the start of a retrieval request') # Module interface functions def create (name): global declarative_modules declarative_modules[name.lower()] = declarative_module() return name actr.add_command('create-pDM',create,'Creation function for Python declarative module.') def delete (name): global declarative_modules del declarative_modules[name.lower()] actr.add_command('delete-pDM',delete,'Deletion function for Python declarative module.') def reset (name): current_module(name).reset() actr.add_command('reset-pDM',reset,'Reset function for Python declarative module') def query(name,buffer,slot,value): module = current_module(name) s = slot.lower() if hasattr(value,'lower'): v = value.lower() else: v = value module.lock.acquire() pending = module.pending error = module.error module.lock.release() if s == 'state': if v == 'free': return not(pending) elif v == 'busy': return pending elif v == 'error': return error else: actr.print_warning('Unknown state query %s to declarative module' % v) return False else: actr.print_warning('Unknown query %s %s to declarative module' % (s,v)) return False actr.add_command('query-pDM',query,'Query function for Python declarative module') def request (name,buffer,spec): module = current_module(name) module.lock.acquire() module.error = False if module.pending : actr.call_command("model_warning","A retrieval event has been aborted by a new request") actr.call_command("delete-event",module.pending) module.pending = False actr.schedule_event_now("start-retrieval",None,"declarative",output="medium") # Let ACT-R find the match(es) from all the DM chunks match = actr.call_command("find-matching-chunks",spec,module.chunks) # if :esc is t then :lf controls the timing if module.esc : time = module.lf else: time = 0 if match : module.pending = actr.schedule_event_relative(time,"retrieved-chunk",[match[0]],"declarative",destination="declarative",output="medium") else: module.pending = actr.schedule_event_relative(time,"retrieval-failure",None,"declarative",destination="declarative",output="medium") # should always free the chunk-spec resources when no longer needed actr.release_chunk_spec(spec) module.lock.release() actr.add_command('request-pDM',request,'Request function for Python declarative module') def params (name,param): module = current_module(name) module.lock.acquire() r = None if len(param) == 2: # a new value for a parameter if param[0].lower() == ":lf" : module.lf = param[1] r = param[1] elif param[0].lower() == ":esc" : module.esc = param[1] else: if param[0].lower() == ":lf" : r = module.lf module.lock.release() return r actr.add_command('params-pDM',params,'Parameter function for Python declarative module') def buffer_cleared(name,buffer,chunk): module = current_module(name) module.lock.acquire() # create a chunk-spec that describes the chunk and use ACT-R's matching # to search the list of chunks for a match spec = actr.define_chunk_spec(chunk) match = actr.call_command("find-matching-chunks",spec,module.chunks) actr.release_chunk_spec(spec) if match : # merge it with the first one found actr.call_command("merge-chunks",match[0],chunk) else: # otherwise check if we can store it if actr.call_command("chunk-not-storable",chunk) : # can't store it so store a copy copy = actr.copy_chunk(chunk) add_chunk_to_dm(module,copy) else : # safe to store it directly add_chunk_to_dm(chunk) module.lock.release() actr.add_command('cleared-pDM',buffer_cleared,'Chunk cleared from a buffer function for Python declarative module') # Define the module with a buffer called retrieval, add the :lf parameter, monitor the :esc parameter, # and get notified when a buffer is cleared. actr.define_module('declarative', [['retrieval']], [[':lf', [['owner',True],['valid-test','nonneg'], # use an internal ACT-R function to test it ['default-value',1.0],['warning','non-negative number'], ['documentation','Latency Factor (from Python)']]], [':esc',[['owner',False]]]], [['version','1.1P'], ['documentation','Simple (limited functionality) test of remote Python version of declarative module.'], ['creation','create-pDM'],['delete','delete-pDM'],['query','query-pDM'],['request','request-pDM'], ['notify-on-clear','cleared-pDM'],['reset','reset-pDM'], ['params','params-pDM']]) # When a chunk enters DM make it immutable, set its initial parameters for creation time # and reference count, and add it to the list of chunks. # This assumes the module's lock is already held. def add_chunk_to_dm (module,chunk): actr.call_command("make-chunk-immutable",chunk) actr.call_command("set-chunk-ct",chunk,actr.get_time()) actr.call_command("set-chunk-count",chunk,1) module.chunks.append(chunk) # Function to update the reference count automatically when chunks are merged. def merge_chunk_counts(c1,c2): return(c1 + 1) actr.add_command('merge-py-chunks',merge_chunk_counts,'Increment the reference count for merged chunks.') # Create the new chunk parameters for creation time and reference count actr.call_command("extend-chunks","ct") actr.call_command("extend-chunks","count",[["merge-value-function","'merge-py-chunks'"]]) # This function is going to be callable from within productions just # like the original ACT-R add-dm command. # # If there is a current model, pass the parameters off to define-chunks # to create them and then add all of the created chunks into DM and # return the names of those chunks. def add_dm(*chunk_defs): model = actr.current_model() if not(model): actr.print_warning('Add-dm called with no current model.') return(False) else: chunks=actr.define_chunks(*chunk_defs) module = current_module(model) module.lock.acquire() for c in chunks: add_chunk_to_dm(module,c) module.lock.release() return (chunks) actr.add_command('add-dm',add_dm,'Define chunks and add them to the Python declarative memory.',True,"add-dm",True) # This replaces the original ACT-R dm command which can be used # to print out all the chunks in DM or a specified subset of them. def dm(*chunks): model = actr.current_model() if not(model): actr.print_warning('Dm called with no current model.') return(False) else: module = current_module(model) module.lock.acquire() current_chunks=module.chunks module.lock.release() if chunks == (): actr.pprint_chunks(*current_chunks) return(current_chunks) else: r = [] for c in chunks: if c in current_chunks: actr.pprint_chunks(c) r.append(c) return (r) actr.add_command('dm',dm,'Print chunks from Python declarative memory.',True,"dm") # Replace the original ACT-R sdp command with this simplified version # which only serves to print the parameters for the indicated DM chunks. def sdp(*chunks): model = actr.current_model() if not(model): actr.print_warning('Sdp called with no current model.') return(False) else: module = current_module(model) module.lock.acquire() current_chunks=module.chunks module.lock.release() r = [] if chunks == (): for c in current_chunks: ct = actr.call_command("chunk-ct",c) count = actr.call_command("chunk-count",c) actr.command_output("Paramters for chunk %s created: %d current count: %d" % (c,ct,count)) r.append([c,ct,count]) else: for c in chunks: if c in current_chunks: ct = actr.call_command("chunk-ct",c) count = actr.call_command("chunk-count",c) actr.command_output("Paramters for chunk %s created: %d current count: %d" % (c,ct,count)) r.append([c,ct,count]) return (r) actr.add_command('sdp',sdp,'Print chunk parameters for chunks in Python declarative memory.',True,"sdp")
11,598
Common Lisp
.cl
247
37.700405
145
0.645565
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
1b333bc61899b08ff94f3487258cb2b3d675813f8f453f554381c6832a547e0c
14,374
[ -1 ]
14,375
simple.tcl
asmaloney_ACT-R/examples/connections/tcltk/simple.tcl
package require json # Save the end of message marker in a variable set end_of_cmd [format "%c" 4] # Procedure to send the string to ACT-R with the end of message character. proc send_string {s string} { global end_of_cmd puts $s "$string$end_of_cmd" } # Procedure to read a message from the socket and return the parsed JSON result # (which will be a dictionary for the object). proc read_string {s} { global end_of_cmd set d [read $s 1] set m "" set end [string first $end_of_cmd $d] while { $d != $end_of_cmd } { set m "$m$d" set d [read $s 1] } return [::json::json2dict $m] } # Read the ACT-R address and port from the default configuration files. if {[file readable "~/act-r-address.txt"]} { set fileid [open "~/act-r-address.txt" "r"] set address [read $fileid] close $fileid } if {[file readable "~/act-r-port-num.txt"]} { set fileid [open "~/act-r-port-num.txt" "r"] set port [read $fileid] close $fileid } # Open the socket. set actr_socket [socket $address $port] fconfigure $actr_socket -blocking no -buffering none # Send the command to set the name for this connection. send_string $actr_socket "{\"method\":\"set-name\",\"params\":\[\"Simple Tcl/Tk Example\"\],\"id\":null}" # Evaluate the ACT-R "act-r-version" command. send_string $actr_socket "{\"method\":\"evaluate\",\"params\":\[\"act-r-version\"\],\"id\":1}" # Read the response and parse the result out of it. set m [read_string $actr_socket] if {[dict exists $m "result"] && [dict exists $m "id"] && [dict exists $m "error"]} { set id [dict get $m "id"] set error [dict get $m "error"] set result [dict get $m "result"] if {$id == 1} { if {$error == "null"} { puts "ACT-R version: $result" set response "ACT-R version: $result" } else { puts "Error returned: $error" } } else { puts "Id $id is not expected value 1" } } else { puts "Unexpected message $m" } flush stdout # Using puts and flush aren't actually showing in the console # when sourced on my machine, so using a dialog box as well. # The error and unexpected messages above won't happen so just # show the valid case. tk_messageBox -message $response -type ok # Add a command called "tcl-add" which will be referenced by "add" locally. send_string $actr_socket "{\"method\":\"add\",\"params\":\[\"tcl-add\",\"add\",\"Add the two numbers provided. Params: num1 num2\"\],\"id\":null}" # Loop forever reading messages and responding to the # evaluate requests for "add". while 1 { set m [read_string $actr_socket] if {[dict exists $m "method"] && [dict exists $m "params"] && [dict exists $m "id"]} { set params [dict get $m "params"] if {[dict get $m "method"] == "evaluate" && [lindex $params 0] == "add"} { set err "" if { [llength $params] == 4 } { if [catch {set sum [expr [lindex $params 2] + [lindex $params 3]]}] { set err "Error when trying to add [lindex $params 2] and [lindex $params 3]" } } else { set err "Did not provide exactly 2 values to add" } # Generally would need additional parsing to convert id back to json but # for simplicity just using it directly because ACT-R currently sends numeric ids set id [dict get $m "id"] if { $id != "null"} { if {$err != ""} { send_string $actr_socket "{\"result\":null,\"error\":{\"message\": \"$err\"},\"id\":$id}" } else { send_string $actr_socket "{\"result\":$sum,\"error\":null,\"id\":$id}" } } } else { puts "Got invalid request $m which wasn't evaluate add" } } else { puts "Got invalid request $m" } }
3,853
Common Lisp
.cl
98
33.714286
147
0.619907
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
f25848d98d2a08028d024fdb1cb79593bd8d5abe1e741dfefe487e7b7b71f521
14,375
[ -1 ]
14,413
24-ctrl-panel-stop-button.tcx
asmaloney_ACT-R/environment/GUI/dialogs/24-ctrl-panel-stop-button.tcx
proc stop_model {} { call_act_r_command "schedule-break-relative" "nil" [list 0] # my json parser along with call_act_r_command can't create the options list... [list [list "details" "Environment Stop Button pressed"]]] } button [control_panel_name].stop_button \ -command {stop_model} -text "Stop" -font button_font pack [control_panel_name].stop_button
372
Common Lisp
.l
7
49.714286
140
0.724234
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
04045fbf526038e36d74f3b20a19cd65835b66c57d7e8b18bd6dae5594f5d85e
14,413
[ -1 ]
14,460
multi_model_talking.py
asmaloney_ACT-R/examples/multiple-models/multi_model_talking.py
# This file allows models that are running together to hear each # other talking by monitoring the output-speech command from the # microphone device of the speech module. # # To run models using this code just call the test_it function. # That will install a microphone device for all the models, # create a new command, set that command to monitor for speech # output, and run the models. # # There are example models in the multi-model-talking-model file, # and running those models is shown in the comments below. # import actr # This is the key to them hearing each other. # When any model speaks into a microphone device all other models # will hear that with the location being the name of the model # which spoke. # The audio & speech modules take care of a model hearing # itself automatically so don't want to double that up. def relay_speech_output (model, string): for m in actr.mp_models(): if not (m.lower() == model.lower()): # all other models will hear this actr.set_current_model(m) # Create the originating model's name as a simple chunk if # it isn't one already to avoid a warning of it being # created by default when the sound is generated. if not(actr.chunk_p(model)): actr.define_chunks(model) # Create the sound as a word with location indicating # the speaker. actr.new_word_sound(string, actr.mp_time(), model) def test_it (): actr.reset() actr.add_command("relay-speech-output", relay_speech_output, "Handle player speak actions") actr.monitor_command("output-speech","relay-speech-output") for m in actr.mp_models(): actr.set_current_model(m) actr.install_device(["speech","microphone"]) actr.run(10) actr.remove_command_monitor("output-speech", "relay-speech-output") actr.remove_command("relay-speech-output") """ >>> import multi_model_talking >>> actr.load_act_r_model("ACT-R:examples;multiple-models;multi-model-talking-models.lisp") True >>> multi_model_talking.test_it() 0.000 M1 PROCEDURAL CONFLICT-RESOLUTION 0.000 M2 PROCEDURAL CONFLICT-RESOLUTION 0.000 M3 PROCEDURAL CONFLICT-RESOLUTION 0.050 M2 PROCEDURAL PRODUCTION-FIRED SPEAK 0.050 M2 PROCEDURAL CLEAR-BUFFER GOAL 0.050 M2 PROCEDURAL CLEAR-BUFFER VOCAL 0.050 M2 SPEECH SPEAK TEXT Hello 0.050 M2 GOAL SET-BUFFER-CHUNK GOAL CHUNK0 0.050 M2 PROCEDURAL CONFLICT-RESOLUTION 0.200 M2 PROCEDURAL CONFLICT-RESOLUTION 0.250 M2 AUDIO new-sound 0.250 M1 AUDIO new-sound 0.250 M3 AUDIO new-sound 0.250 M2 PROCEDURAL CONFLICT-RESOLUTION 0.250 M1 PROCEDURAL CONFLICT-RESOLUTION 0.250 M3 PROCEDURAL CONFLICT-RESOLUTION 0.500 M2 PROCEDURAL CONFLICT-RESOLUTION 0.550 M1 AUDIO SET-BUFFER-CHUNK AURAL-LOCATION AUDIO-EVENT0 NIL 0.550 M3 AUDIO SET-BUFFER-CHUNK AURAL-LOCATION AUDIO-EVENT0 NIL 0.550 M2 AUDIO find-sound-failure 0.550 M1 PROCEDURAL CONFLICT-RESOLUTION 0.550 M3 PROCEDURAL CONFLICT-RESOLUTION 0.550 M2 PROCEDURAL CONFLICT-RESOLUTION 0.600 M1 PROCEDURAL PRODUCTION-FIRED DETECTED-SOUND 0.600 M1 PROCEDURAL CLEAR-BUFFER AURAL-LOCATION 0.600 M1 PROCEDURAL CLEAR-BUFFER GOAL 0.600 M1 PROCEDURAL CLEAR-BUFFER AURAL 0.600 M3 PROCEDURAL PRODUCTION-FIRED DETECTED-SOUND 0.600 M3 PROCEDURAL CLEAR-BUFFER AURAL-LOCATION 0.600 M3 PROCEDURAL CLEAR-BUFFER GOAL 0.600 M3 PROCEDURAL CLEAR-BUFFER AURAL 0.600 M1 AUDIO ATTEND-SOUND AUDIO-EVENT0-0 0.600 M3 AUDIO ATTEND-SOUND AUDIO-EVENT0-0 0.600 M1 GOAL SET-BUFFER-CHUNK GOAL CHUNK0 0.600 M3 GOAL SET-BUFFER-CHUNK GOAL CHUNK0 0.600 M1 PROCEDURAL CONFLICT-RESOLUTION 0.600 M3 PROCEDURAL CONFLICT-RESOLUTION 0.725 M1 AUDIO SET-BUFFER-CHUNK AURAL WORD0 0.725 M3 AUDIO SET-BUFFER-CHUNK AURAL WORD0 0.725 M1 PROCEDURAL CONFLICT-RESOLUTION 0.725 M3 PROCEDURAL CONFLICT-RESOLUTION 0.775 M1 PROCEDURAL PRODUCTION-FIRED HEAR I HEARD M2 SAY "Hello" 0.775 M1 PROCEDURAL CLEAR-BUFFER AURAL 0.775 M1 PROCEDURAL CLEAR-BUFFER VOCAL 0.775 M3 PROCEDURAL PRODUCTION-FIRED HEAR I HEARD M2 SAY "Hello" 0.775 M3 PROCEDURAL CLEAR-BUFFER AURAL 0.775 M1 SPEECH SPEAK TEXT Back at you 0.775 M1 PROCEDURAL CONFLICT-RESOLUTION 0.775 M3 PROCEDURAL CONFLICT-RESOLUTION 0.925 M1 PROCEDURAL CONFLICT-RESOLUTION 0.975 M1 AUDIO new-sound 0.975 M2 AUDIO new-sound 0.975 M3 AUDIO new-sound 0.975 M1 PROCEDURAL CONFLICT-RESOLUTION 0.975 M2 PROCEDURAL CONFLICT-RESOLUTION 0.975 M3 PROCEDURAL CONFLICT-RESOLUTION 1.275 M2 AUDIO SET-BUFFER-CHUNK AURAL-LOCATION AUDIO-EVENT1 NIL 1.275 M3 AUDIO SET-BUFFER-CHUNK AURAL-LOCATION AUDIO-EVENT1 NIL 1.275 M1 AUDIO find-sound-failure 1.275 M1 PROCEDURAL CONFLICT-RESOLUTION 1.275 M2 PROCEDURAL CONFLICT-RESOLUTION 1.275 M3 PROCEDURAL CONFLICT-RESOLUTION 1.325 M2 PROCEDURAL PRODUCTION-FIRED DETECTED-SOUND 1.325 M2 PROCEDURAL CLEAR-BUFFER AURAL-LOCATION 1.325 M2 PROCEDURAL CLEAR-BUFFER GOAL 1.325 M2 PROCEDURAL CLEAR-BUFFER AURAL 1.325 M3 PROCEDURAL PRODUCTION-FIRED DETECTED-SOUND 1.325 M3 PROCEDURAL CLEAR-BUFFER AURAL-LOCATION 1.325 M3 PROCEDURAL CLEAR-BUFFER GOAL 1.325 M3 PROCEDURAL CLEAR-BUFFER AURAL 1.325 M2 AUDIO ATTEND-SOUND AUDIO-EVENT1-0 1.325 M3 AUDIO ATTEND-SOUND AUDIO-EVENT1-0 1.325 M2 GOAL SET-BUFFER-CHUNK GOAL CHUNK1 1.325 M3 GOAL SET-BUFFER-CHUNK GOAL CHUNK1 1.325 M2 PROCEDURAL CONFLICT-RESOLUTION 1.325 M3 PROCEDURAL CONFLICT-RESOLUTION 1.525 M1 PROCEDURAL CONFLICT-RESOLUTION 1.725 M2 AUDIO SET-BUFFER-CHUNK AURAL WORD1 1.725 M3 AUDIO SET-BUFFER-CHUNK AURAL WORD1 1.725 M2 PROCEDURAL CONFLICT-RESOLUTION 1.725 M3 PROCEDURAL CONFLICT-RESOLUTION 1.775 M2 PROCEDURAL PRODUCTION-FIRED HEAR I HEARD M1 SAY "Back at you" 1.775 M2 PROCEDURAL CLEAR-BUFFER AURAL 1.775 M3 PROCEDURAL PRODUCTION-FIRED HEAR I HEARD M1 SAY "Back at you" 1.775 M3 PROCEDURAL CLEAR-BUFFER AURAL 1.775 M2 PROCEDURAL CONFLICT-RESOLUTION 1.775 M3 PROCEDURAL CONFLICT-RESOLUTION 1.775 - ------ Stopped because no events left to process """
7,937
Common Lisp
.l
139
50.201439
96
0.582719
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
ba976051fb843bd6fa1703b6ae5ae86746123de92ae72d39ed6ea09a6f922075
14,460
[ -1 ]
14,472
multi_window.py
asmaloney_ACT-R/examples/vision-module/multi_window.py
# This example shows that multiple devices can be installed to # the vision interface at the same time. It also shows that the # visicon features created by each exp-window installed are # available simultaneously as well as those from the mouse # cursor. Finally, it shows that the coordinates for all of # the features of the exp-window device and the mouse cursor # are represented in a global coordinate system and not in # the local coordinates of the windows themselves. # It depends upon the actr module from the ACT-R tutorial to provide # the connection to ACT-R and functions to access the ACT-R commands. import actr def example (): actr.reset() # The first window is located at x=0 and y=0 which # is fine for virtual windows, but if it were a real # window that window would be behind the menu bar # at the top of the display under OS X which makes # it difficult to interact with. The second window # is located at x=200, y=200. The default mouse # position is x=0, y=0. w1 = actr.open_exp_window("W1", visible=False, width=100, height=100, x=0, y=0) w2 = actr.open_exp_window("W2", visible=False, width=100, height=100, x=200, y=200) # add text to the same local position in each window. actr.add_text_to_exp_window(w1, "a", x=10, y=10, color='red') actr.add_text_to_exp_window(w2, "a", x=10, y=10, color='blue') # Install both windows and the mouse cursor actr.install_device(w1) actr.install_device(w2) actr.install_device(["vision", "cursor", "mouse"]) # Just run the model to have vision module process # things and print the visicon. # The model doesn't do anything. actr.run(1) actr.print_visicon() # Load a model which doesn't do anything. actr.load_act_r_model("ACT-R:examples;vision-module;multi-window-model.lisp")
1,923
Common Lisp
.l
36
47.444444
88
0.708833
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
fe9845bd06e19e6ea89286c3c253923cb9bd78f05d0ad9d0380235a764e5bf93
14,472
[ -1 ]
14,502
goal.py
asmaloney_ACT-R/examples/creating-modules/external/goal.py
import actr import threading actr.undefine_module('goal') actr.remove_command('goal-focus') actr.remove_command('mod-focus') goal_modules = {} class goal_module(): def __init__(self): self.lock = threading.Lock() self.delayed = None def reset(self): self.lock.acquire() self.delayed = None actr.set_parameter_value(':do-not-harvest','goal') self.lock.release() def create (name): global goal_modules goal_modules[name.lower()] = goal_module() return name actr.add_command('create-pgoal',create,'Creation function for Python goal module.') def delete (name): global goal_modules del goal_modules[name.lower()] actr.add_command('delete-pgoal',delete,'Deletion function for Python goal module.') def reset (name): goal_modules[name.lower()].reset() actr.add_command('reset-pgoal',reset,'Reset function for Python goal module') def query(name,buffer,slot,value): s = slot.lower() if hasattr(value,'lower'): v = value.lower() else: v = value if s == 'state': if v == 'free': return True elif v == 'busy': return False elif v == 'error': return False else: actr.print_warning('Unknown state query %s to goal module' % v) return False else: actr.print_warning('Unknown query %s %s to goal module' % (s,v)) return False actr.add_command('query-pgoal',query,'Query function for Python goal module') def request (name,buffer,spec): chunk_desc = actr.chunk_spec_to_chunk_def(spec) if chunk_desc: actr.schedule_set_buffer_chunk('goal',spec,0,module='goal',priority= -1000) actr.schedule_event_now('release-chunk-spec-id',params=[spec],module='goal',priority= -1001,output=False) else: actr.print_warning('Invalid request made to the goal buffer.') actr.add_command('request-pgoal',request,'Request function for Python goal module') def buffer_mod(name,buffer,spec): actr.schedule_mod_buffer_chunk(buffer,spec,0,module='goal',priority=20) actr.schedule_event_now('release-chunk-spec-id',params=[spec],module='goal',priority=19,maintenance=True) actr.add_command('bmod-pgoal',buffer_mod,'Buffer modification request function for Python goal module') actr.define_module('goal',[['goal',[':ga',0]]],None,[['version','1.1P'],['documentation','Replaced normal goal module with a remote Python version.'], ['creation','create-pgoal'],['delete','delete-pgoal'],['query','query-pgoal'],['request','request-pgoal'], ['buffer-mod','bmod-pgoal'],['reset',[None,'reset-pgoal']]]) def goal_focus (name=None): model = actr.current_model() if not(model): actr.print_warning('Goal-focus called with no current model.') else: module = goal_modules[model.lower()] if not(module): actr.print_warning('No goal module found for model %s when trying to use goal-focus.'%model) elif name: if actr.chunk_p(name): actr.schedule_set_buffer_chunk('goal',name,0,module='goal',priority=':max',requested=False) actr.schedule_event_after_module('goal','clear-delayed-goal',params=[model],module='goal',maintenance=True,output=False) module.lock.acquire() module.delayed = name module.lock.release() return name else: actr.print_warning('%s is not the name of a chunk in the current model - goal-focus failed' % name) else: chunk = actr.buffer_read('goal') module.lock.acquire() delayed = module.delayed module.lock.release() if not(chunk) and not(delayed): actr.command_output('Goal buffer is empty') return None elif not(chunk): actr.command_output('Will be a copy of %s when the model runs' % delayed) actr.pprint_chunks(delayed) return delayed elif not(delayed): actr.pprint_chunks(chunk) return chunk else: copy = actr.chunk_copied_from(chunk) if copy and (copy.lower() == delayed.lower()): actr.pprint_chunks(chunk) return chunk else: actr.command_output('Will be a copy of %s when the model runs' % delayed) actr.command_output('Currently holds:') actr.pprint_chunks(chunk) return delayed actr.add_command('goal-focus',goal_focus,'Python version which schedule a chunk to enter the goal buffer at the current time or print the current goal buffer chunk. Params: {chunk-name}.',None,'goal-focus') def clear_delayed_goal (model): module = goal_modules[model.lower()] if not(module): actr.print_warning('No goal module found for model %s when trying to clear delayed goal.'%model) else: module.lock.acquire() module.delayed = None module.lock.release() actr.add_command('clear-delayed-goal',clear_delayed_goal,'Event for letting the goal module know a goal-focus has completed. Do not call directly.') def mod_focus (*modifications): model = actr.current_model() if not(model): actr.print_warning('Mod-focus called with no current model.') else: module = goal_modules[model.lower()] if not(module): actr.print_warning('No goal module found for model %s when trying to use mod-focus.'%model) else: chunk = actr.buffer_read('goal') module.lock.acquire() delayed = module.delayed module.lock.release() if chunk or delayed: actr.schedule_mod_buffer_chunk('goal',modifications,0,module='goal',priority=':max') if delayed: return delayed else: return chunk else: actr.print_warning('No chunk currently in the goal buffer and no pending goal-focus chunk to be modified.') actr.add_command('mod-focus',mod_focus,'Modify the chunk in the goal buffer using the slots and values provided. Params: {<slot-name> <new-slot-value>}*',None,'mod-focus') # One minor note on this is that since the commands are on the Python side # the current model needs to be explicitly set with actr.set_current_model # to be able to use the actr.goal_focus & actr.mod_focus commands since the # dispatcher doesn't fill in a current model when a remote system sends the # command to someone other than the internal code.
7,015
Common Lisp
.l
142
38.077465
207
0.618934
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
407c8fa3df67574c78ea9a35148a8fdc841bc45a023ac184bf23d9d9ee94e785
14,502
[ -1 ]
14,504
goal_complete.py
asmaloney_ACT-R/examples/creating-modules/external/goal_complete.py
import json import threading import socket import time import os current_connection = None class evaluator(): def __init__(self,id): self.id = id self.lock = threading.Lock() self.cv = threading.Condition(self.lock) self.complete = False def notify_result(self): self.cv.acquire() self.complete = True self.cv.notify() self.cv.release() class actr(): def __init__(self,host="127.0.0.1",port=2650): self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.sock.connect((host, port)) self.connected = True self.cmd_id = 1 self.actions = {} self.stream_lock = threading.Lock() self.buffer = [] self.commands = {} self.data_collector = threading.Thread(target=self.collect_data) self.data_collector.daemon = True self.data_collector.start() self.id_lock = threading.Lock() self.echo_count = 0 self.echo = False self.show_output = True def send(self,method,*params): d = {} r = evaluator(self.cmd_id) self.actions[self.cmd_id] = r d['method'] = method self.id_lock.acquire() d['id'] = self.cmd_id self.cmd_id += 1 self.id_lock.release() d['params'] = params message = json.dumps(d) + chr(4) r.lock.acquire() self.stream_lock.acquire() self.sock.sendall(message.encode('utf-8')) self.stream_lock.release() while not r.complete: r.cv.wait() return [r.success] + r.results def collect_data(self): buffer= '' c = True while c: try: data = self.sock.recv(4096) buffer += data.decode('utf-8') while not chr(4) in buffer: data = self.sock.recv(4096) buffer += data.decode('utf-8') while chr(4) in buffer: pos = buffer.find(chr(4)) message = buffer[0:pos] pos += 1 buffer = buffer[pos:] self.process_message(json.loads(message)) except: if self.connected: print("ACT-R connection error connection no longer available.") c = False def process_message (self,d): if 'result' in d.keys(): id =d['id'] r = self.actions[id] if d['error'] is None: r.success = True r.results = d['result'] else: r.success = False errors=d['error'] r.results = [errors['message']] self.actions.pop(id,None) r.notify_result() else: if d['method'] == "evaluate": thread = threading.Thread(target=self.run_command,args=[d['params'][0],d['id'],d['params'][1:]]) thread.daemon = True thread.start() else: f={} f['id'] = d['id'] f['result'] = None e={} e['message'] = "Invalid method name" + d['params'][0] f['error'] = e message = json.dumps(f) + chr(4) self.stream_lock.acquire() self.sock.sendall(message.encode('utf-8')) self.stream_lock.release() def run_command (self,command,id,params): if command in self.commands.keys(): try: c = self.commands[command] result = c(*params) except: error = True else: error = None else: print("Evaluate received for %s which isn't a currently added command"%command) error = True f={} f['id'] = id if error: f['result'] = None f['error'] = {'message': "Error during run_command for %s which maps to %s with %s"%(command,self.commands[command],params)} elif result: f['result']= result f['error']= None else: f['result']= [None] f['error']= None message = json.dumps(f) + chr(4) self.stream_lock.acquire() self.sock.sendall(message.encode('utf-8')) self.stream_lock.release() def evaluate (self, *params): r = self.send ("evaluate", *params) if r[0] == False: for e in r[1:]: print (e) return False else: return r[1] def add_command(self,name,function,documentation="No documentation provided.",single=True,actr_name=None): if name not in self.commands.keys(): self.commands[name] = function elif self.commands[name] == function: print("Command ",name," already exists for function ",function) else: print("Command ",name," already exists and is now being replaced by ",function) self.commands[name] = function existing = self.send("check",name) if existing[0] == True: if existing[1] == None: result = self.send("add",name,name,documentation,single,actr_name) if result[0]: return result[1] else: return False elif existing[2] == None: print("Cannot add command ",name, " because it has already been added by a different owner.") return False else: return True else: print("Invalid command name ",name," cannot be added.") return False def remove_command(self,name): if name in self.commands.keys(): del self.commands[name] r = self.send('remove',name) if r[0] == False: for e in r[1:]: print (e) return False else: return True def start (host="127.0.0.1",port=2650): global current_connection if current_connection == None: current_connection = actr(host, port) return current_connection else: print("ACT-R is already connected.") return current_connection def connection (): port = None host = None connect = None if current_connection == None: if os.path.isfile(os.path.expanduser("~/act-r-port-num.txt")): with open(os.path.expanduser("~/act-r-port-num.txt"), 'r') as f: try: port = int(f.readline()) except: print("Problem reading ACT-R port number from ~s. Using default or 2650."%os.path.expanduser("~/act-r-port-num.txt")) port = 2650 else: port = 2650 if os.path.isfile(os.path.expanduser("~/act-r-address.txt")): with open(os.path.expanduser("~/act-r-address.txt"), 'r') as f: try: host = f.readline() except: print("Problem reading ACT-R host from ~s. Using default of 127.0.0.1."%os.path.expanduser("~/act-r-address.txt")) host = "127.0.0.1" else: host = "127.0.0.1" try: connect = start(host,port) except: print("Problem connecting to ACT-R at ~s:~s."%(host,port)) return None else: return connect else: return current_connection def stop(): global current_connection if current_connection == None: print("No current ACT-R connection to stop.") else: print("Closing down ACT-R connection.") current_connection.connected = False current_connection.sock.close() current_connection = None actr = connection() actr.evaluate('undefine-module',None,'goal') actr.remove_command('goal-focus') actr.remove_command('mod-focus') goal_modules = {} class goal_module(): def __init__(self): self.lock = threading.Lock() self.delayed = None def reset(self,model): self.lock.acquire() self.delayed = None actr.evaluate('set-parameter-value',model,':do-not-harvest','goal') self.lock.release() def create (model,name): global goal_modules goal_modules[name.lower()] = goal_module() return name actr.add_command('create_pgoal',create,'Creation function for Python goal module.') def delete (model,name): global goal_modules del goal_modules[name.lower()] actr.add_command('delete_pgoal',delete,'Deletion function for Python goal module.') def reset (model,name): goal_modules[name.lower()].reset(model) actr.add_command('reset_pgoal',reset,'Reset function for Python goal module') def query (model,name,buffer,slot,value): s = slot.lower() if hasattr(value,'lower'): v = value.lower() else: v = value if s == 'state': if v == 'free': return True elif v == 'busy': return False elif v == 'error': return False else: actr.evaluate('print-warning',model,'Unknown state query %s to goal module' % v) return False else: actr.evaluate('print-warning',model,'Unknown query %s %s to goal module' % (s,v)) return False actr.add_command('query_pgoal',query,'Query function for Python goal module') def request (model,name,buffer,spec): chunk_desc = actr.evaluate('chunk-spec-to-chunk-def',model,spec) if chunk_desc: actr.evaluate('schedule-set-buffer-chunk',model,'goal',spec,0,[['module','goal'],['priority',-1000]]) actr.evaluate('schedule-event-now',model,'release-chunk-spec-id',[['params',[spec]],['module','goal'],['priority',-1001],['output',False]]) else: actr.evaluate('print-warning',model,'Invalid request made to the goal buffer.') actr.add_command('request_pgoal',request,'Request function for Python goal module') def buffer_mod(model,name,buffer,spec): actr.evaluate('schedule-mod-buffer-chunk',model,buffer,spec,0,[['module','goal'],['priority',20]]) actr.evaluate('schedule-event-now',model,'release-chunk-spec-id',[['params',[spec]],['module','goal'],['priority',19],['maintenance',True]]) actr.add_command('buffer_mod_pgoal',buffer_mod,'Buffer modification request function for Python goal module') actr.evaluate('define-module',None,'goal',[['goal',[':ga',0]]],None,[['version','1.1P'],['documentation','Replaced normal goal module with a remote Python version.'], ['creation','create_pgoal'],['delete','delete_pgoal'],['query','query_pgoal'],['request','request_pgoal'], ['buffer-mod','buffer_mod_pgoal'],['reset',[None,'reset_pgoal']]]) def goal_focus (model,name=None): if not(model): actr.evaluate('print-warning',model,'Goal-focus called with no current model.') else: module = goal_modules[model.lower()] if not(module): actr.evaluate('print-warning',model,'No goal module found for model %s when trying to use goal-focus.'%model) elif name: if actr.evaluate('chunk-p',model,name): actr.evaluate('schedule-set-buffer-chunk',model,'goal',name,0,[['module','goal'],['priority',':max'],['requested',False]]) actr.evaluate('schedule-event-after-module',model,'goal','clear_delayed_goal',[['module','goal'],['output',False],['maintenance',True]]) module.lock.acquire() module.delayed = name module.lock.release() return name else: actr.evaluate('print-warning',model,'%s is not the name of a chunk in the current model - goal-focus failed' % name) else: chunk = actr.evaluate('buffer-read',model,'goal') module.lock.acquire() delayed = module.delayed module.lock.release() if not(chunk) and not(delayed): actr.evaluate('command-output',model,'Goal buffer is empty') return None elif not(chunk): actr.evaluate('command-output',model,'Will be a copy of %s when the model runs' % delayed) actr.evaluate('pprint-chunks',model,delayed) return delayed elif not(delayed): actr.evaluate('pprint-chunks',model,chunk) return chunk else: copy = actr.evaluate('chunk-copied-from',model,chunk) if copy and (copy.lower() == delayed.lower()): actr.evaluate('pprint-chunks',model,chunk) return chunk else: actr.evaluate('command-output',model,'Will be a copy of %s when the model runs' % delayed) actr.evaluate('command-output',model,'Currently holds:') actr.evaluate('pprint-chunks',model,chunk) return delayed actr.add_command('goal-focus',goal_focus,'Python version which schedule a chunk to enter the goal buffer at the current time or print the current goal buffer chunk. Params: {chunk-name}.',None,'goal-focus') def clear_delayed_goal (model): module = goal_modules[model.lower()] if not(module): actr.evaluate('print-warning',model,'No goal module found for model %s when trying to clear delayed goal.'%model) else: module.lock.acquire() module.delayed = None module.lock.release() actr.add_command('clear_delayed_goal',clear_delayed_goal,'Event for letting the goal module know a goal-focus has completed. Do not call directly.') def mod_focus (model,*modifications): if not(model): actr.evaluate('print-warning',model,'Mod-focus called with no current model.') else: module = goal_modules[model.lower()] if not(module): actr.evaluate('print-warning',model,'No goal module found for model %s when trying to use mod-focus.'%model) else: chunk = actr.evaluate('buffer-read',model,'goal') module.lock.acquire() delayed = module.delayed module.lock.release() if chunk or delayed: actr.evaluate('schedule-mod-buffer-chunk',model,'goal',modifications,0,[['module','goal'],['priority',':max']]) if delayed: return delayed else: return chunk else: actr.evaluate('print-warning',model,'No chunk currently in the goal buffer and no pending goal-focus chunk to be modified.') actr.add_command('mod-focus',mod_focus,'Modify the chunk in the goal buffer using the slots and values provided. Params: {<slot-name> <new-slot-value>}*',None,'mod-focus')
15,563
Common Lisp
.l
353
31.416431
207
0.557244
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
49506e38395d18a925e3f03190b6b3237640b8cca45600b8ad418285528f1888
14,504
[ -1 ]
14,506
simple.m
asmaloney_ACT-R/examples/connections/matlab/simple.m
% Read the ACT-R address and port config files fid = fopen('~/act-r-address.txt','r'); address = fscanf(fid,'%s'); fclose(fid); fid = fopen('~/act-r-port-num.txt','r'); port = fscanf(fid,'%d'); fclose(fid); % Open a socket to connect to ACT-R socket = tcpip(address,port,'NetworkRole','client','Timeout',Inf); fopen(socket); % Set the name for this ACT-R connection fwrite(socket,'{"method":"set-name","params":["Simple MATLAB"],"id":null}'); fwrite(socket,char(4)); % Evaluate the "act-r-version" command fwrite(socket,'{"method":"evaluate","params":["act-r-version"],"id":1}'); fwrite(socket,char(4)); % Read characters from the stream until the % end of message character is found. result = ''; c = fread(socket,1); while (c ~= char(4)) result = strcat(result,c); c = fread(socket,1); end % Decode the JSON data from that string response = jsondecode(result); % Check to make sure there is a result matching the % id provided (will always be the case here since % that's all the dispatcher will send) if ~isempty(response.id) if response.id == 1 if ~isempty(response.result) disp(strcat('ACT-R version is: ',response.result{1})); elseif ~isempty(response.error) disp('Error: '); disp(response.error.message); else disp('No result or error'); end else disp('Invalid response id'); end else disp('No id value on result'); end % Add a command called "matlab-add" which is referred to as "add" in the evaluate request fwrite(socket,'{"method":"add","params":["matlab-add","add","Add the 2 values provided. Params: num1 num2"],"id":null}'); fwrite(socket,char(4)); % Loop forever reading messages from ACT-R % and responding to the evaluate messages which % require a result. while 1 result = ''; c = fread(socket,1); while (c ~= char(4)) result = strcat(result,c); c = fread(socket,1); end response = jsondecode(result); if ~isempty(response.method) if strcmp(response.method,'evaluate') if (~isempty(response.params) && length(response.params) == 4 && strcmp(response.params{1},'add')) % should also verify that they're numbers and protect the % addition for errors if ~isempty(response.id) fwrite(socket,strcat('{"result":[',num2str(response.params{3}+response.params{4}),'],"error":null,"id":',jsonencode(response.id),'}',char(4))); end else disp('Invalid evaluate request'); end else disp('Received method other than evaluate'); end else disp('No method in message.'); end end
2,699
Common Lisp
.l
77
29.909091
163
0.650212
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
84ef8e881eb0c4a118721389bd9f1c90be5d643c3a1667517cb4632eba765239
14,506
[ -1 ]
14,507
simple_actr.py
asmaloney_ACT-R/examples/connections/python/simple_actr.py
import json import socket import os # function to send a string to ACT-R with the end of message character def send(socket,message): m = message + chr(4) socket.sendall(m.encode('utf-8')) # Read from the stream until the end of message character and then return # the value decoded from the JSON string def receive(socket): buffer= '' while not chr(4) in buffer: data = socket.recv(1) buffer += data.decode('utf-8') return json.loads(buffer[0:-1]) # Read the configuration files for the connection details with open(os.path.expanduser("~/act-r-port-num.txt"), 'r') as f: port = int(f.readline()) with open(os.path.expanduser("~/act-r-address.txt"), 'r') as f: host = f.readline() # Open the socket sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect((host, port)) # Set the name for this ACT-R connection send(sock,'{"method":"set-name","params":["Simple Python Example"],"id":null}') # Evaluate the "act-r-version" command send(sock,'{"method":"evaluate","params":["act-r-version"],"id":1}') # Get the response and parse it make sure it # is a valid response. The JSON object decodes # into a dictionary. message = receive(sock) if 'id' in message.keys(): if message['id'] == 1 : if 'result' in message.keys(): if message['result']: print("ACT-R Version is") print(message['result'][0]) elif 'error' in message.keys(): e = message['error'] print("error result: "+e['message']) else: print("Invalid result") else: print("Invalid result") else: print("Result with wrong id:") print(message['id']) # Add the command "python-sum" to ACT-R using "sum" as the name provided. send(sock,'{"method":"add","params":["python-sum","sum","Sum the values in the provided list. Params: list"],"id":null}') # Loop forever reading messages from ACT-R and returning # the sum of items when asked to evaluate the "sum" # command. while True : message = receive(sock) if 'method' in message.keys() and 'params' in message.keys() and 'id' in message.keys() : if message['method'] == 'evaluate': if len(message['params']) == 3 and message['params'][0] == "sum": result = None error = None try: result = sum(message['params'][2]) except: error = "Error trying to sum values." if message['id'] : if result: send(sock,'{"result":[%d],"error":null,"id":%s}'%(result,json.dumps(message['id']))) else: send(sock,'{"result":null,"error":{"message": "%s"},"id":%s}'%(error,json.dumps(message['id']))) else : print ("Unexpected message from ACT-R")
2,826
Common Lisp
.l
70
33.842857
122
0.627043
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
107891cfe19f7a4c973aabd65776e4ef32ad3c07da02222eba74031d48a7949f
14,507
[ -1 ]
14,508
simple.c
asmaloney_ACT-R/examples/connections/c/simple.c
#include <stdio.h> #include <string.h> #include <jansson.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/tcp.h> #include <netinet/in.h> #include <netdb.h> #include <stdlib.h> #include <pwd.h> // Read characters from a socket into a string until // the ACT-R end of message character is found. void read_message(int sockfd,char* buffer) { int index; int last; for(index = 0,last=0;last != 4;index++) { read(sockfd,&(buffer[index]),1); last = buffer[index]; } buffer[index-1] = 0; } void main (){ // Get the user's home directory. const char *homedir; if ((homedir = getenv("HOME")) == NULL) { homedir = getpwuid(getuid())->pw_dir; } // Create the directories for the ACT-R // config files and read in the results. char addr_file[128]; char port_file[128]; strcpy(addr_file,homedir); strcat(addr_file,"/act-r-address.txt"); strcpy(port_file,homedir); strcat(port_file,"/act-r-port-num.txt"); FILE *fp; fp = fopen(addr_file,"r"); char addr[128]; fscanf(fp,"%s",addr); fclose (fp); fp = fopen(port_file,"r"); int port_num; fscanf(fp,"%d",&port_num); fclose (fp); // Create and connect the socket to ACT-R. int sockfd; sockfd = socket(AF_INET,SOCK_STREAM,0); int flag = 1; setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, (void *) &flag, sizeof(int)); struct sockaddr_in dest; bzero(&dest, sizeof(dest)); dest.sin_family = AF_INET; dest.sin_port = htons(port_num); inet_aton(addr, &dest.sin_addr.s_addr); connect(sockfd,(struct sockaddr*)&dest, sizeof(dest)); // Send the messages to set the name for the connection and // evaluate the "act-r-version" command. char set_name[] ="{\"method\":\"set-name\",\"params\":[\"Simple c Example\"],\"id\":null}\04"; char evaluate[] ="{\"method\":\"evaluate\",\"params\":[\"act-r-version\"],\"id\":1}\04"; write(sockfd,set_name,strlen(set_name)); write(sockfd,evaluate,strlen(evaluate)); // Read the response from the socket, parse the JSON // code to get the result (with some unnecessary tests // tests for example purposes since ACT-R will always // respond correctly), and then print out the result returned. char buffer[256]; read_message(sockfd,buffer); json_t *root; json_error_t error; root = json_loads(buffer,0,&error); if(!root) { printf("error: on line %d: %s\n", error.line, error.text); exit(0); } if (!json_is_object(root)) { printf("Not an object\n"); exit(0); } json_t *r; json_t *e; json_t *id; r = json_object_get(root,"result"); e = json_object_get(root,"error"); id = json_object_get(root,"id"); // Check that it matches the id sent. if (json_is_integer(id) && json_integer_value(id) == 1) { // has an array result if (json_is_array(r)) { json_t *v; v = json_array_get(r,0); // and the first result is a string. if (json_is_string(v)) { printf("ACT-R version: %s\n",json_string_value(v)); json_decref(v); } // Otherwise there should be an error message. } else if (json_is_object(e)) { json_t *em; em = json_object_get(e,"message"); if (json_is_string(em)) { printf("ACT-R returned error result: %s\n",json_string_value(em)); json_decref(em); } } else { printf("Invalid response\n"); exit(0); } } else { printf("Got wrong id in response\n"); exit(0); } // Release the JSON objects. json_decref(id); json_decref(e); json_decref(r); json_decref(root); // Send the command to add our "c-add" command which will just // be called "add" when an evaluate request is made. char add[] ="{\"method\":\"add\",\"params\":[\"c-add\",\"add\",\"Command to add two numbers. Params: num1 num2\"],\"id\":null}\04"; write(sockfd,add,strlen(add)); json_t *m; json_t *p; json_t *c; json_t *n1; json_t *n2; json_t *o; double answer; char out[256]; // Loop forever responding to the message sent // (which will only be evaluate for the add command // but parse the result to verify for example purposes). for (;;) { read_message(sockfd,buffer); root = json_loads(buffer,0,&error); if(!root) { printf("error: on line %d: %s\n", error.line, error.text); exit(0); } if (!json_is_object(root)) { printf("Not an object\n"); exit(0); } m = json_object_get(root,"method"); p = json_object_get(root,"params"); id = json_object_get(root,"id"); // Check that it's an evaluate method. if (json_is_string(m) && strcmp(json_string_value(m),"evaluate") == 0) { // make sure there are 4 parameters. if (json_is_array(p) && json_array_size(p) == 4) { c = json_array_get(p,0); n1 = json_array_get(p,2); n2 = json_array_get(p,3); // If the first is "add" then add the third and fourth values. if (json_is_string(c) && strcmp(json_string_value(c),"add") == 0) { answer = json_number_value(n1) + json_number_value(n2); // If there was an id return the result. if(!json_is_null(id)) { sprintf(out,"{\"result\":[%f],\"error\":null,\"id\":%s}\04",answer,json_dumps(id,JSON_ENCODE_ANY)); write(sockfd,out,strlen(out)); } // Free all the JSON objects. json_decref(m); json_decref(p); json_decref(id); json_decref(c); json_decref(n1); json_decref(n2); json_decref(root); } else { printf("Request to evaluate something other than add\n"); exit(0); } } else { printf("Invalid parameters for add\n"); // Respond with an error message if(!json_is_null(id)) { sprintf(out,"{\"result\":null,\"error\":{\"message\":\"Bad parameters\"},\"id\":%s}\04",json_dumps(id,JSON_ENCODE_ANY)); write(sockfd,out,strlen(out)); } json_decref(m); json_decref(p); json_decref(id); json_decref(c); json_decref(n1); json_decref(n2); json_decref(root); } } else { printf("Something other than evaluate received\n"); exit(0); } } }
6,114
Common Lisp
.l
194
27
134
0.63382
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
8cc8c2a53cd699ff0bc59ef969721a5d594827cf770e794e1fbc4b4bfd57ab5e
14,508
[ -1 ]
14,509
actr-plotter.R
asmaloney_ACT-R/examples/connections/R/actr-plotter.R
# load the rjson library to parse the incoming data library(rjson) # create a function to read from the socket until the # ACT-R end of message character \004 is read. Return # the parsed data from that message. read_actr_message <- function(socket) { incoming <- "" repeat { c <- read.socket(socket,1,TRUE) if (c == "\004") break incoming <- paste(incoming,c, sep = "") } fromJSON(incoming) } # Read the ACT-R configuration files to determine the # address and port for the connection. Do a special # check for Windows because most Lisps consider ~ # to be /Users/<name> but R uses /Users/<name>/Documents. if (.Platform[["OS.type"]] == "windows") { a <- (scan("~/../act-r-address.txt","character")) p <- (scan("~/../act-r-port-num.txt")) } else { a <- (scan("~/act-r-address.txt","character")) p <- (scan("~/act-r-port-num.txt")) } # Open a socket connection to that location s <- make.socket(a,p) # Give ACT-R a name for the connection write.socket(s,"{\"method\":\"set-name\",\"params\":[\"R grapher\"],\"id\":null}\004") # Evaluate the ACT-R act-r-version command write.socket(s,"{\"method\":\"evaluate\",\"params\":[\"act-r-version\"],\"id\":1}\004") # Read the response m <- read_actr_message(s) # Check the response to make sure it is a # response to the evaluate request which # completed successfully. if (is.null(m[["result"]])) { print("Unexpected message from ACT-R") print(m) } else if (is.null(m[["result"]])) { print("Error returned from ACT-R") print(m[["error"]]) } else if (m[["id"]][[c(1)]] != 1) { print("Unexpected id on the result.") print(m[["id"]][[c(1)]]) } else { print("ACT-R version is") print(m[["result"]][[c(1)]]) } # force the output for the R GUI applications flush.console() # Add the "plot-with-r" command to ACT-R, using the name "graph" # for the evaluate calls it receives. write.socket(s,"{\"method\":\"add\",\"params\":[\"plot-with-r\",\"graph\",\"Draw a scatter plot in a pdf. Params: file-name title x-label y-label min-x max-x min-y max-y list-of-x-values list-of-y-values\"],\"id\":null}\004") # Loop forever reading messages from ACT-R and # responding to the requests as appropriate (they # should all be evaluate requests for "graph" but # check for completeness). repeat { j <- read_actr_message(s) message <- "" if (j[["method"]] != "evaluate") { message <- "Not an evaluate method." } else if (length(j[["params"]]) != 12) { message <- "Not enough parameters" } else if (j[["params"]][[c(1)]] != "graph") { message <- "Only evaluates graph" } else { params <- j[["params"]] model <- params[[c(2)]] # don't need the model name file <- params[[c(3)]] title <- params[[c(4)]] xaxis <- params[[c(5)]] yaxis <- params[[c(6)]] xmin <- params[[c(7)]] xmax <- params[[c(8)]] ymin <- params[[c(9)]] ymax <- params[[c(10)]] xvals <- params[[c(11)]] yvals <- params[[c(12)]] # Try to open the pdf indicated and draw a graph using plot. tryCatch({ pdf(file) plot(x=xvals,y=yvals,main=title,xlab=xaxis,ylab=yaxis,xlim=c(xmin,xmax),ylim=c(ymin,ymax)) dev.off() }, warning = function(w) { message <- paste("WARNING: ",w) }, error = function(e) { message <- paste("ERROR: ",e) }) } # If there was an id in the evaluate request indicating # a response was required send a true result if there # was no error otherwise send an error response with # the details of the errror. if (!is.null(j[["id"]][[c(1)]])) { if (message == "") { write.socket(s,paste("{\"result\":[true],\"error\":null,\"id\":",toJSON(j[["id"]][[c(1)]]),"}\004")) } else { write.socket(s,paste("{\"result\":null,\"error\":{\"message\": \"",message,"\"},\"id\":",toJSON(j[["id"]][[c(1)]]),"}\004")) } } }
3,984
Common Lisp
.l
104
33.692308
226
0.607499
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
8deaa57ce513ee2a3c313a9ab946ab1f7a2773162cd66ff115f2fe135839d8b3
14,509
[ -1 ]
14,510
environment.html
asmaloney_ACT-R/examples/connections/nodejs/environment.html
<html> <body> <script src="/socket.io/socket.io.js"></script> <!-- For the mybinder and jupyter versions use this instead: src="socket.io/socket.io.js" --> <script> // General communication with the node.js interface to ACT-R var which_interface = 1; // 1 is normal, 2 is mybinder, 3 is jupyter, 4 is play-with-docker if (which_interface == 1 || which_interface == 4) { var socket = io('/environment'); } else if (which_interface == 2) { var address = document.baseURI ; var socket = io('/environment', { path: address.slice(address.indexOf('/user'))+"socket.io" }); } else { var address = document.baseURI ; var socket = io('/environment', { path: "/proxy/4000/socket.io" }); } var name_string = ""; var cmdMap = new Map; var cmd_id = 0; var resultMap = new Map; socket.on('evaluate',function(params_list,id){ var cmd = params_list.shift(); if (cmdMap.get(cmd)) { socket.emit('result',cmdMap.get(cmd)(params_list),id); } else { socket.emit('result',null,id); } }); function record_error(msg) { console.log(msg); } function callback_handler(fn,success,data) { if (success) { fn(data); } else { record_error(data); fn(null); } } function evaluate_cmd(cmd,model,params,fn) { if(!params) { params = []; } params.unshift(model); params.unshift(cmd); if (fn) { socket.emit('evaluate',params,function(success,data) { callback_handler(fn,success,data); }); } else { socket.emit('evaluate',params,null); } } function add_cmd(cmd,docs,fn,name_fn) { cmdMap.set(cmd,fn); if (name_fn) { socket.emit('add',cmd,docs,function(success,data) { callback_handler(name_fn,success,data); }); } else { socket.emit('add',cmd,docs,null); } } function monitor_cmd(cmd,mon) { socket.emit('monitor',cmd,mon); } function stop_monitor(cmd,mon) { socket.emit('remove-monitor',cmd,mon); } function get_connections(fn) { if (fn) { socket.emit('connections',function(success,data) { callback_handler(fn,success,data); }); } else { socket.emit('connections',null); } } function get_cmds(fn) { if (fn) { socket.emit('cmds',function(success,data) { callback_handler(fn,success,data); }); } else { socket.emit('cmds',null); } } function check_cmd(cmd,fn) { if (fn) { socket.emit('check',cmd,function(success,data) { callback_handler(fn,success,data); }); } else { socket.emit('check',cmd,null); } } </script> <script> // Functions for common interface creation and display purposes function create_title_bar(name,with_model){ var title_bar = document.createElement('div'); title_bar.setAttribute("class","title-bar"); var title_div = document.createElement('div'); title_div.setAttribute("class","title-name"); var h3 = document.createElement('b'); if (with_model) { h3.innerHTML = name + " ("+ current_model + ")"; } else { h3.innerHTML = name; } title_div.appendChild(h3); title_bar.appendChild(title_div); var close_div = document.createElement('div'); close_div.setAttribute("class","close-box"); close = document.createElement('button'); close.innerHTML = "X"; close_div.appendChild(close); title_bar.appendChild(close_div); return([title_bar,title_div,close]); } function scrub_text(txt) { return(txt.replace(/</g, "&lt;").replace(/>/g, "&gt;")); } function create_list_view () { var display = document.createElement('div'); display.setAttribute("class","select-display"); var c_list = document.createElement('div'); c_list.setAttribute("class","select-display-list"); var c_display = document.createElement('div'); c_display.setAttribute("class","select-display-output"); var text_box = document.createElement('div'); text_box.setAttribute("class","output-display"); var text = document.createElement('pre'); var list = document.createElement('ul'); c_list.appendChild(list); c_display.appendChild(text_box); text_box.appendChild(text); display.appendChild(c_list); display.appendChild(c_display); return([display,text,list]); } var div_views = new Map; </script> <style> .title-bar { display: flex; height: 40px; width: 100%; flex-direction: row; overflow: hidden; } .title-name { display: flex; width: 100%; overflow: hidden; } .close-box { display: flex; width: 40px; } .select-display { display: flex; flex-direction: row; height: 100%; width: 100%; overflow: hidden; } .select-display-list { display: flex; height: 100%; width: 35%; overflow: auto; ul { display: flex; overflow: auto; padding: 0; } } .select-li { display: flex; white-space: nowrap; } .select-display-output { display: flex; height: 100%; width: 65%; overflow: hidden; } .output-display { display: flex; overflow: auto; width: 100%; height: 100%; } ul { list-style-type: none; padding: 0; } </style> <script> // Implement the current model notification and selection var current_model = null; var all_models = null; function update_model(){ var cm = document.getElementById("current_model"); while (cm.firstChild) { cm.removeChild(cm.firstChild); } if (all_models.length == 0) { current_model = null; } else { all_models.forEach(function(m){ var s = document.createElement("option"); s.setAttribute("value",m); s.innerHTML= m; cm.appendChild(s); }); if (all_models.length == 1 || current_model == null) { current_model = all_models[0]; cm.setAttribute("value",all_models[0]); } else { if (all_models.indexOf(current_model) == -1) { current_model = all_models[0]; cm.setAttribute("value",all_models[0]); } else { cm.setAttribute("value",current_model); } } } } evaluate_cmd("mp-models",null,null,function(names) { var n = names[0]; if (!n) { all_models = []; } else { all_models = n; } update_model(); }); function add_model(name) { var n = name[0]; all_models.push(n); update_model(); } function delete_model(name) { var n = name[0]; var i = all_models.indexOf(n); all_models.splice(i,1); update_model(); } function change_model() { var cm = document.getElementById("current_model"); if (cm.options.selectedIndex != -1) { current_model = cm.childNodes[cm.options.selectedIndex].getAttribute("value"); cm.setAttribute("value",current_model); } else { current_model = null; cm.setAttribute("value",null); } } add_cmd("add_model","environment creating-model monitoring cmd. do not call",add_model,null); monitor_cmd("creating-model","add_model"); add_cmd("delete_model","environment deleting-model monitoring cmd. do not call",delete_model,null); monitor_cmd("deleting-model","delete_model"); </script> <script> // handle the selection of files and assume the location based on provided unit # var load_results = ""; function collect_load_results(text) { load_results = load_results + text[1]; } add_cmd("monitor_loading","environment cmd to monitor output while loading. do not call",collect_load_results,null); function report_load_results(results) { stop_monitor("model-trace","monitor_loading"); stop_monitor("command-trace","monitor_loading"); stop_monitor("warning-trace","monitor_loading"); stop_monitor("general-trace","monitor_loading"); if (!results) { alert("Failure loading model\n"+load_results); } else { alert("Successful load\n"+load_results); } load_results = ""; } function load_model(unit) { if (socket.io.opts.hostname == "127.0.0.1" || socket.io.opts.hostname == "localhost") { var input = document.createElement('input'); input.type = 'file'; load_results = ""; monitor_cmd("model-trace","monitor_loading"); monitor_cmd("command-trace","monitor_loading"); monitor_cmd("warning-trace","monitor_loading"); monitor_cmd("general-trace","monitor_loading"); input.onchange = e => { var file = e.target.files[0]; if (unit) { var num = [document.getElementById('load_unit').valueAsNumber]; evaluate_cmd("load-act-r-code",null,["ACT-R:tutorial;unit"+num+";"+file.name],report_load_results); } else { evaluate_cmd("load-act-r-code",null,["ACT-R:tutorial;lisp;"+file.name],report_load_results); } } input.click(); } else { alert("Only local connections may load files."); } } function load_python_module() { if (socket.io.opts.hostname == "127.0.0.1" || socket.io.opts.hostname == "localhost") { var input = document.createElement('input'); input.type = 'file'; load_results = ""; monitor_cmd("model-trace","monitor_loading"); monitor_cmd("command-trace","monitor_loading"); monitor_cmd("warning-trace","monitor_loading"); monitor_cmd("general-trace","monitor_loading"); input.onchange = e => { var file = e.target.files[0]; evaluate_cmd("load-python-module-html",null,[file.name],report_load_results); } input.click(); } else { alert("Only local connections may import modules."); } } // For container versions only allow picking a unit 1 model by name from a list function load_unit1_model() { var model = document.getElementById("unit_1_model"); load_results = ""; monitor_cmd("model-trace","monitor_loading"); monitor_cmd("command-trace","monitor_loading"); monitor_cmd("warning-trace","monitor_loading"); monitor_cmd("general-trace","monitor_loading"); if (model.selectedIndex != 0) { selected = model.options[model.selectedIndex]; evaluate_cmd("load-act-r-code",null,["ACT-R:tutorial;unit1;"+selected.value],report_load_results); } } </script> <script> // The reset, reload, and run actions function reset_actr(){ evaluate_cmd("reset",null,null,null); } function reload_actr(){ evaluate_cmd("reload",null,null,null); } function run_actr(){ evaluate_cmd("run",null,[document.getElementById('run_time').valueAsNumber],null); } </script> <script> // The event queue display function show_event_queue(){ evaluate_cmd("mp-queue-text",null,[true],display_event_queue); } function display_event_queue(text) { var txt = text[0]; var evt_queue = div_views.get("evt_queue"); if (evt_queue) { if (evt_queue.getAttribute("open") != "yes") { evt_queue.setAttribute("open","yes"); document.getElementById('controls').appendChild(evt_queue); } document.getElementById("evt-text").innerHTML = scrub_text(txt); } else { var controls = document.getElementById('controls'); var div = document.createElement('div'); div.setAttribute("class","evt-queue-box"); div.setAttribute("open","yes"); var title_bar = create_title_bar("Event Queue",false); div.appendChild(title_bar[0]); title_bar[1].onclick = show_event_queue; title_bar[2].onclick = function(){ div.setAttribute("open","no"); controls.removeChild(div); }; var text_box = document.createElement('div'); text_box.setAttribute("class","output-display"); text = document.createElement('pre'); text.setAttribute("id","evt-text"); text.innerHTML = scrub_text(txt); div_views.set("evt_queue",div); text_box.appendChild(text); div.appendChild(text_box); controls.appendChild(div); } } </script> <style> .evt-queue-box { display: flex; width: 300px; border: double; height: 400px; flex-direction: column; overflow: hidden; resize: both; } </style> <script> // provide the running indicator function update_running() { if (document.getElementById("show_running").checked) { monitor_cmd("run-stop","stopped_monitor"); monitor_cmd("run-start","running_monitor"); } else { document.getElementById('running-indicator').innerHTML="-------"; stop_monitor("run-stop","stopped_monitor"); stop_monitor("run-start","running_monitor"); } } function running_now(ignore) { document.getElementById('running-indicator').innerHTML="<div style=\"color: green\">RUNNING</div>"; } function stopped_now(ignore) { document.getElementById('running-indicator').innerHTML="<div style=\"color: red\">STOPPED</div>"; } add_cmd("running_monitor","environment cmd to monitor run-start. do not call",running_now,null); add_cmd("stopped_monitor","environment cmd to monitor run-stop. do not call",stopped_now,null); </script> <script> // the declarative memory viewer function dm_filter_changed(view) { var items = div_views.get(view); items.current_filter = items.filter.childNodes[items.filter.options.selectedIndex].value; update_dm_chunk_list(view); } function update_dm_chunk_list(view) { var items = div_views.get(view); evaluate_cmd("filter-dm-chunks",items.model,[items.current_filter],function(data){ var chunks = data[0]; while(items.list.firstChild) { items.list.removeChild(items.list.firstChild); } var notdisplayed = true; if (chunks != null) { chunks.forEach(function(c){ var li = document.createElement('li'); li.setAttribute("class","select-li"); li.innerHTML=c; li.onclick = function() { li.style.backgroundColor= "gray"; items.chunk = c; if (items.selected) { items.selected.style.backgroundColor = null; } items.selected = li; update_chunk_view(view); }; if (c == items.chunk) { li.style.backgroundColor= "gray"; items.selected = li; update_chunk_view(view); notdisplayed = false; } items.list.appendChild(li); }); } if (notdisplayed) { items.chunk = null; update_chunk_view(view); } }); } function why_not_dm(view) { var items = div_views.get(view); if (items.chunk != null) { evaluate_cmd("dm-whynot-text",items.model,[items.chunk],function(data){ show_whynot_dm(items.model,items.chunk,data[0]); }); } } function show_whynot_dm(model,chunk,txt) { var controls = document.getElementById('controls'); var div = document.createElement('div'); div.setAttribute("class","why-not-box"); var title_bar = create_title_bar("Whynot "+chunk+" ("+model+")",false); div.appendChild(title_bar[0]); title_bar[2].onclick = function(){ controls.removeChild(div); }; var text_box = document.createElement('div'); text_box.setAttribute("class","output-display"); var text = document.createElement('pre'); text.innerHTML = scrub_text(txt); text_box.appendChild(text); div.appendChild(text_box); controls.appendChild(div); } function update_chunk_view(view) { var items = div_views.get(view); if (items.chunk == null) { items.text.innerHTML = ""; } else { evaluate_cmd("dm-chunk-details",items.model,[items.chunk],function(data) { items.text.innerHTML = scrub_text(data[0]); }); } } function update_dm_viewer(dm) { var items = div_views.get(dm); evaluate_cmd("dm-slot-filters",items.model,null,function(data){ var filters = data[0]; while (items.filter.firstChild) { items.filter.removeChild(items.filter.firstChild); } var count = 0; var unset = true; filters.forEach(function(m){ var s = document.createElement("option"); if (m == null) { m = "null"; } s.value = m; s.value = s.value.replace(/,/g, " ") s.innerHTML= m; items.filter.appendChild(s); if (items.current_filter == s.value) { items.filter.options.selectedIndex = count; unset = false; } count++; }); if (unset) { items.filter.options.selectedIndex = 0; items.current_filter = filters[0]; } update_dm_chunk_list(dm); }); } function dm_viewer() { if (current_model == null) { alert("Declarative Memory viewer requires a current model."); } else { var controls = document.getElementById('controls'); var div = document.createElement('div'); div.setAttribute("class","dm-box"); var title_bar = create_title_bar("Declarative Memory",true); div.appendChild(title_bar[0]); title_bar[1].onclick = function(){ update_dm_viewer(div); }; title_bar[2].onclick = function(){ controls.removeChild(div); div_views.delete(div); }; var filter_div = document.createElement('div'); filter_div.setAttribute("class","dm-filter-bar"); var but = document.createElement('button'); but.innerHTML="Why not?"; but.onclick = function(){ why_not_dm(div); }; filter_div.appendChild(but); var f_div = document.createElement('div'); var filter = document.createElement('pre'); filter.innerHTML = " Filter: "; f_div.appendChild(filter); filter_div.appendChild(f_div); var filter_select = document.createElement('select'); filter_select.onchange = function(){ dm_filter_changed(div); }; filter_div.appendChild(filter_select); div.appendChild(filter_div); var view = create_list_view(); div.appendChild(view[0]); div_views.set(div,{"list": view[2], "text": view[1], "filter": filter_select, "current_filter": null, "model": current_model, "chunk": null}); update_dm_viewer(div); controls.appendChild(div); } } </script> <style> .dm-box { display: flex; width: 400px; border: double; height: 400px; flex-direction: column; overflow: hidden; resize: both; } .dm-filter-bar { display: flex; height: 35px; width: 100%; flex-direction: row; } .why-not-box { display: flex; width: 300px; border: double; height: 400px; flex-direction: column; overflow: hidden; resize: both; } </style> <script> // procedural viewer function update_p_viewer(view) { var items = div_views.get(view); evaluate_cmd("all-productions",items.model,null,function(data){ var productions = data[0]; while(items.list.firstChild) { items.list.removeChild(items.list.firstChild); } var notdisplayed = true; if (productions != null) { productions.forEach(function(p){ var li = document.createElement('li'); li.setAttribute("class","select-li"); li.innerHTML=p; li.onclick = function() { li.style.backgroundColor= "gray"; items.p = p; if (items.selected) { items.selected.style.backgroundColor = null; } items.selected = li; update_p_view(view); }; if (p == items.p) { li.style.backgroundColor= "gray"; items.selected = li; update_p_view(view); notdisplayed = false; } items.list.appendChild(li); }); } if (notdisplayed) { items.p = null; update_p_view(view); } }); } function why_not_p(view) { var items = div_views.get(view); if (items.p != null) { evaluate_cmd("whynot-text",items.model,[items.p],function(data){ show_whynot_p(items.model,items.p,data[0]); }); } } function show_whynot_p(model,p,txt) { var controls = document.getElementById('controls'); var div = document.createElement('div'); div.setAttribute("class","why-not-box"); var title_bar = create_title_bar("Whynot "+p+" ("+model+")",false); div.appendChild(title_bar[0]); title_bar[2].onclick = function(){ controls.removeChild(div); }; var text_box = document.createElement('div'); text_box.setAttribute("class","output-display"); text = document.createElement('pre'); text.innerHTML = scrub_text(txt); text_box.appendChild(text); div.appendChild(text_box); controls.appendChild(div); } function update_p_view(view) { var items = div_views.get(view); if (items.p == null) { items.text.innerHTML = ""; } else { evaluate_cmd("production-details",items.model,[items.p],function(data) { items.text.innerHTML = scrub_text(data[0]); }); } } function procedural_viewer() { if (current_model == null) { alert("Procedural Memory viewer requires a current model."); } else { var controls = document.getElementById('controls'); var div = document.createElement('div'); div.setAttribute("class","procedural-box"); var title_bar = create_title_bar("Procedural Memory",true); div.appendChild(title_bar[0]); title_bar[1].onclick = function(){ update_p_viewer(div); }; title_bar[2].onclick = function(){ controls.removeChild(div); div_views.delete(div); }; var but = document.createElement('button'); but.innerHTML="Why not?"; but.onclick = function(){ why_not_p(div); }; div.appendChild(but); var view = create_list_view(); div.appendChild(view[0]); div_views.set(div,{"list": view[2], "text": view[1], "model": current_model, "p": null}); update_p_viewer(div); controls.appendChild(div); } } </script> <style> .procedural-box { display: flex; width: 400px; border: double; height: 400px; flex-direction: column; overflow: hidden; resize: both; } </style> <script> // Buffer viewer function update_buffer_viewer(view) { var items = div_views.get(view); evaluate_cmd("model-buffers",items.model,null,function(data){ var buffers = data[0]; while(items.list.firstChild) { items.list.removeChild(items.list.firstChild); } var notdisplayed = true; if (buffers != null) { buffers.forEach(function(b){ var li = document.createElement('li'); li.setAttribute("class","select-li"); li.innerHTML=b; li.onclick = function() { li.style.backgroundColor= "gray"; items.buffer = b; if (items.selected) { items.selected.style.backgroundColor = null; } items.selected = li; update_buffer_view(view); }; if (b == items.buffer) { li.style.backgroundColor= "gray"; items.selected = li; update_buffer_view(view); notdisplayed = false; } items.list.appendChild(li); }); } if (notdisplayed) { items.buffer = null; update_buffer_view(view); } }); } function update_buffer_view(view) { var items = div_views.get(view); if (items.buffer == null) { items.text.innerHTML = ""; } else { if (items.display == "contents") { evaluate_cmd("buffer-read",items.model,[items.buffer],function(data) { if (data[0]) { evaluate_cmd("printed-buffer-chunk",items.model,[items.buffer],function(data) { items.text.innerHTML = scrub_text(data[0]); }); } else { evaluate_cmd("multi-buffer-p",items.model,[items.buffer],function(data) { if (data[0]) { evaluate_cmd("get-m-buffer-chunks",items.model,[items.buffer],function(data) { items.text.innerHTML = "Empty multi-buffer\nPossible chunks are:\n"; if (data[0]) { data[0].forEach(function(c) { evaluate_cmd("printed-chunk",items.model,[c],function(data) { items.text.innerHTML = items.text.innerHTML + scrub_text(data[0]) + "\n"; }); }); } }); } else { items.text.innerHTML = "Buffer is empty"; } }); } }); } else { evaluate_cmd("printed-buffer-status",items.model,[items.buffer],function(data) { items.text.innerHTML = scrub_text(data[0]); }); } } } var buffer_count = 0; // to provide unique names for the radio button groups function buffer_viewer() { if (current_model == null) { alert("Buffer viewer requires a current model."); } else { var controls = document.getElementById('controls'); var div = document.createElement('div'); div.setAttribute("class","buffer-box"); var title_bar = create_title_bar("Buffers",true); div.appendChild(title_bar[0]); title_bar[1].onclick = function(){ update_buffer_viewer(div); }; title_bar[2].onclick = function(){ controls.removeChild(div); div_views.delete(div); }; var select = document.createElement('div'); select.setAttribute("class","buffer-bar"); var content_div = document.createElement('div'); var content_label = document.createElement('label'); content_label.setAttribute("for","buffer-content"+buffer_count); content_label.innerHTML="Contents"; var content = document.createElement('input'); content.type = "radio"; content.checked = true; content.name = "buffer"+buffer_count; content.id = "buffer-content"+buffer_count; content.onclick = function(){ var items = div_views.get(div); items.display = "contents"; update_buffer_viewer(div); }; var status_div = document.createElement('div'); var status_label = document.createElement('label'); status_label.setAttribute("for","buffer-status"+buffer_count); status_label.innerHTML="Status"; var status = document.createElement('input'); status.type = "radio"; status.name = "buffer"+buffer_count; status.id = "buffer-status"+buffer_count; status.onclick = function(){ var items = div_views.get(div); items.display = "status"; update_buffer_viewer(div); }; buffer_count++; content_div.appendChild(content_label); content_label.appendChild(content); status_div.appendChild(status_label); status_label.appendChild(status); select.appendChild(content_div); select.appendChild(status_div); div.appendChild(select); var view = create_list_view(); div.appendChild(view[0]); div_views.set(div,{"list": view[2], "text": view[1], "model": current_model, "buffer": null, "display": "contents"}); update_buffer_viewer(div); controls.appendChild(div); } } </script> <style> .buffer-box { display: flex; width: 450px; border: double; height: 400px; flex-direction: column; overflow: hidden; resize: both; } .buffer-bar { display: flex; height: 30px; width: 100%; flex-direction: row; overflow: hidden; justify-content: right; } </style> <script> // visicon display function update_visicon_viewer(view) { var items = div_views.get(view); evaluate_cmd("printed-visicon",items.model,null,function(data){ items.text.innerHTML = scrub_text(data[0]); }); } function visicon_viewer() { if (current_model == null) { alert("Visicon viewer requires a current model."); } else { var controls = document.getElementById('controls'); var div = document.createElement('div'); div.setAttribute("class","visicon-box"); var title_bar = create_title_bar("Visicon",true); div.appendChild(title_bar[0]); title_bar[1].onclick = function(){ update_visicon_viewer(div); }; title_bar[2].onclick = function(){ controls.removeChild(div); div_views.delete(div); }; var text_box = document.createElement('div'); text_box.setAttribute("class","output-display"); var text = document.createElement('pre'); text_box.appendChild(text); div.appendChild(text_box); div_views.set(div,{"text": text, "model": current_model}); update_visicon_viewer(div); controls.appendChild(div); } } </script> <style> .visicon-box { display: flex; width: 450px; border: double; height: 400px; flex-direction: column; overflow: hidden; resize: both; } </style> <script> // audicon viewer function update_audicon_viewer(view) { var items = div_views.get(view); evaluate_cmd("printed-audicon",items.model,null,function(data){ items.text.innerHTML = scrub_text(data[0]); }); } function audicon_viewer() { if (current_model == null) { alert("Audicon viewer requires a current model."); } else { var controls = document.getElementById('controls'); var div = document.createElement('div'); div.setAttribute("class","audicon-box"); var title_bar = create_title_bar("Audicon",true); div.appendChild(title_bar[0]); title_bar[1].onclick = function(){ update_audicon_viewer(div); }; title_bar[2].onclick = function(){ controls.removeChild(div); div_views.delete(div); }; var text_box = document.createElement('div'); text_box.setAttribute("class","output-display"); var text = document.createElement('pre'); text_box.appendChild(text); div.appendChild(text_box); div_views.set(div,{"text": text, "model": current_model}); update_audicon_viewer(div); controls.appendChild(div); } } </script> <style> .audicon-box { display: flex; width: 450px; border: double; height: 400px; flex-direction: column; overflow: hidden; resize: both; } </style> <script> // the commands and connections tool function update_cmd_viewer() { get_connections(function(data){ div_views.get("connections").data = data; show_connections(); }); } function update_cmd_documentation(cmd,doc){ check_cmd(cmd,function(d) { if (d[0]) { doc.innerHTML=d[2]; } }); } function show_connections(){ var connections = div_views.get("connections"); while(connections.con_list.firstChild) { connections.con_list.removeChild(connections.con_list.firstChild); } while(connections.cmd_list.firstChild) { connections.cmd_list.removeChild(connections.cmd_list.firstChild); } connections.addr.innerHTML=""; connections.sent.innerHTML=""; connections.rec.innerHTML=""; connections.docs.innerHTML=""; connections.con_selected = null; connections.cmd_selected = null; connections.data[0].forEach(function(c){ var li = document.createElement('li'); li.setAttribute("class","select-li"); li.innerHTML=c[0]; li.onclick = function() { li.style.backgroundColor= "gray"; if (connections.con_selected) { connections.con_selected.style.backgroundColor = null; } connections.con_selected = li; connections.addr.innerHTML=c[1]; connections.sent.innerHTML=c[2]; connections.rec.innerHTML=c[3]; while(connections.cmd_list.firstChild) { connections.cmd_list.removeChild(connections.cmd_list.firstChild); } connections.docs.innerHTML=""; if (c[4]) { c[4].forEach(function(cmd){ var cli = document.createElement('li'); cli.setAttribute("class","select-li"); cli.innerHTML=cmd; cli.onclick = function() { cli.style.backgroundColor= "gray"; if (connections.cmd_selected) { connections.cmd_selected.style.backgroundColor = null; } connections.cmd_selected = cli; update_cmd_documentation(cmd,connections.docs); }; connections.cmd_list.appendChild(cli); }); } }; connections.con_list.appendChild(li); }); } function cmd_viewer() { var connections = div_views.get("connections"); if (connections) { if (!connections.open) { connections.open = true; document.getElementById('controls').appendChild(connections.div); } } else { var controls = document.getElementById('controls'); var div = document.createElement('div'); div.setAttribute("class","connections-box"); var title_bar = create_title_bar("Connections & Commands",false); div.appendChild(title_bar[0]); title_bar[1].onclick = update_cmd_viewer; title_bar[2].onclick = function(){ var c = div_views.get("connections"); c.open = false; controls.removeChild(c.div); }; var titles = document.createElement('div'); titles.setAttribute("class","connections-titles"); var con_title = document.createElement('div'); con_title.setAttribute("class","connections-title"); con_title.innerHTML="Connections"; var cmd_title = document.createElement('div'); cmd_title.setAttribute("class","connections-title"); cmd_title.innerHTML="Commands"; titles.appendChild(con_title); titles.appendChild(cmd_title); div.appendChild(titles); var display = document.createElement('div'); display.setAttribute("class","connections-display"); var con_list = document.createElement('div'); con_list.setAttribute("class","connections-display-list"); var c_display = document.createElement('div'); c_display.setAttribute("class","connections-display-list"); display.appendChild(con_list); display.appendChild(c_display); div.appendChild(display); var list1 = document.createElement('ul'); con_list.appendChild(list1); var list2 = document.createElement('ul'); c_display.appendChild(list2); var details = document.createElement('div'); details.setAttribute("class","connections-details"); var con_details = document.createElement('div'); con_details.setAttribute("class","connections-details-box"); var cmd_details = document.createElement('div'); cmd_details.setAttribute("class","connections-details-box"); details.appendChild(con_details); details.appendChild(cmd_details); div.appendChild(details); var address = document.createElement('div'); address.innerHTML = "Address"; con_details.appendChild(address); var com_address = document.createElement('div'); com_address.setAttribute("class","connections-detail"); var addr = document.createElement('pre'); com_address.appendChild(addr); con_details.appendChild(com_address); var sent = document.createElement('div'); sent.innerHTML = "Sent"; con_details.appendChild(sent); var com_sent = document.createElement('div'); com_sent.setAttribute("class","connections-detail"); var sent = document.createElement('pre'); com_sent.appendChild(sent); con_details.appendChild(com_sent); var rec = document.createElement('div'); rec.innerHTML = "Received"; con_details.appendChild(rec); var com_rec = document.createElement('div'); com_rec.setAttribute("class","connections-detail"); var rec = document.createElement('pre'); com_rec.appendChild(rec); con_details.appendChild(com_rec); var docs = document.createElement('div'); docs.innerHTML = "Documentation"; cmd_details.appendChild(docs); var doc_box = document.createElement('div'); doc_box.setAttribute("class","connections-docs"); var docs = document.createElement('pre'); docs.setAttribute("class","doc-text"); doc_box.appendChild(docs); cmd_details.appendChild(doc_box); div_views.set("connections",{"div": div,"data": null, "con_selected": null,"cmd_selected": null, "open": true,"con_list": list1,"cmd_list": list2, "addr": addr, "sent": sent, "rec": rec, "docs": docs}); controls.appendChild(div); } update_cmd_viewer(); } </script> <style> .connections-box { display: flex; width: 450px; border: double; height: 400px; flex-direction: column; overflow: hidden; resize: both; } .connections-display { display: flex; flex-direction: row; height: 55%; width: 100%; overflow: hidden; } .connections-details { display: flex; flex-direction: row; height: 45%; width: 100%; overflow: hidden; } .connections-details-box { display: flex; flex-direction: column; height: 100%; width: 100%; overflow: hidden; } .connections-display-list { display: flex; height: 100%; width: 50%; overflow: auto; margin: 4px; ul { display: flex; overflow: auto; padding: 0; } } .connections-titles { display: flex; height: 20px; width: 100%; flex-direction: row; overflow: hidden; } .connections-title { display: flex; width: 50%; } .connections-detail { display: flex; width: 100%; height: 30px; } .connections-docs { display: flex; height: 100%; width: 100%; overflow-y: scroll; } .doc-text { white-space: normal; } </style> <script> // stepper tool -- uses the environment\stepper-control.lisp functionality var tutor_count = null; var stepper = null; var step_all_forced = false; var tutor_values = null; var tutor_data = null; var tutor_event = null; var tutor_items = null; function stepper_event(text) { document.getElementById("next-stepper-event").innerHTML=text[1]; var x = document.getElementsByClassName("title-name"); var i; for (i = 0; i < x.length; i++) { if (x[i].onclick) {x[i].onclick();} } enable_stepper_buttons(); } function update_stepper_views(){ var l = document.getElementById("stepper-item-list"); var item = null; if (l && l.selected) { item = l.selected.innerHTML; } if (item) { evaluate_cmd("update-stepper",null,[item],function(data){ l = document.getElementById("stepper-d2"); l.innerHTML=data[0]; if (current_tutor_mode() && tutor_event && (tutor_event.toUpperCase() == "PRODUCTION-SELECTED")) { tutor_data = new Map; l = document.getElementById("stepper-d3"); var txt =""; if (data[3]) { data[3].forEach(function (x) { txt = txt + x[0] + ":\n"; tutor_data.set(x[0],{answer: ( (x[1].startsWith && x[1].startsWith("'") && x[1].endsWith("'")) ? "\""+x[1].slice(1,-1)+"\"" : x[1]), buffer: x[2]}); }); } l.innerHTML=txt; var index = 0; l = document.getElementById("stepper-d4"); var separator = data[2].search(/==>/gm); tutor_values = []; tutor_answers = 0; var last_buffer = null; l.innerHTML=data[2].replace(/=[^&>=)\s]+/gim,function(m,o,s){ var txt = "<mark style=\"background: lightblue\" onclick=\"tutor_entry("+index+")\">"+m+"</mark>"; index++; var details = tutor_data.get(m); if (o < separator) { if (details.buffer) { last_buffer = m; } else { details.in_buffer = last_buffer.slice(1); } tutor_values.push([m,(o < separator)]); } else { if (s[o+m.length] == ">") { txt = m; index--; } else { tutor_values.push([m,(o < separator)]); } } return(txt); }); tutor_items = index; tutor_count = 0; } else { tutor_items = null; l = document.getElementById("stepper-d3"); l.innerHTML=data[1]; l = document.getElementById("stepper-d4"); l.innerHTML=data[2]; if (tutor_event && (tutor_event.toUpperCase() == "PRODUCTION-SELECTED")) { remove_instan_tutor(); } } }); } else { if (current_tutor_mode() && tutor_event) { evaluate_cmd("update-stepper",null,[false],function(data){ if (tutor_event.toUpperCase() == "CONFLICT-RESOLUTION") { tutor_items = 1; tutor_count = 0; show_cr_tutor(data[0]); } if (tutor_event.toUpperCase() == "START-RETRIEVAL") { tutor_items = 1; tutor_count = 0; show_r_tutor(data[0]); } }); } else if (tutor_event) { if (tutor_event.toUpperCase() == "CONFLICT-RESOLUTION") { remove_cr_tutor(); } if (tutor_event.toUpperCase() == "START-RETRIEVAL") { remove_r_tutor(); } } } } function stepper_update(vals) { document.getElementById("next-stepper-event").innerHTML=""; document.getElementById("last-stepper-event").innerHTML=vals[1]; tutor_event = vals[3]; document.getElementById("stepper-l1").innerHTML=vals[4]; document.getElementById("stepper-l2").innerHTML=vals[5]; document.getElementById("stepper-l3").innerHTML=vals[6]; document.getElementById("stepper-l4").innerHTML=vals[7]; document.getElementById("stepper-d2").innerHTML=""; document.getElementById("stepper-d3").innerHTML=""; document.getElementById("stepper-d4").innerHTML=""; var l = document.getElementById("stepper-item-list"); while(l.firstChild) { l.removeChild(l.firstChild); } var first = null; var items = vals[2]; if (items != null) { if (tutor_event && current_tutor_mode()) { items = items.slice(0,1); } items.forEach(function(i){ var li = document.createElement('li'); li.setAttribute("class","select-li"); li.innerHTML=i; if (first == null) { first = i; li.style.backgroundColor= "gray"; l.selected = li; } li.onclick = function() { if (l.selected != li) { li.style.backgroundColor= "gray"; if (l.selected) { l.selected.style.backgroundColor = null; } l.selected = li; update_stepper_views(); }}; l.appendChild(li); }); } else { l.selected = null; } update_stepper_views(); } var stepper_event_cmd = null; var stepper_update_cmd = null; add_cmd("stepper-event","environment stepper next event command. do not call",stepper_event,function(name){ stepper_event_cmd = name[0];}); add_cmd("stepper-update","environment stepper event update command. do not call",stepper_update,function(name){ stepper_update_cmd = name[0];}); function change_stepper_mode () { evaluate_cmd("set-stepper-tutoring",null,[current_stepper_id,current_tutor_mode()],function(x){ update_stepper_views(); }); } function current_tutor_mode(){ if (document.getElementById('stepper_tutor')) { return(document.getElementById('stepper_tutor').checked); } else { return (false); } } function disable_stepper_buttons() { b = document.getElementById('stepper-stop-button'); b.disabled = true; b = document.getElementById('stepper-step-button'); b.disabled = true; b = document.getElementById('stepper-until-button'); b.disabled = true; } function enable_stepper_buttons() { b = document.getElementById('stepper-stop-button'); b.disabled = false; b = document.getElementById('stepper-step-button'); b.disabled = false; b = document.getElementById('stepper-until-button'); b.disabled = false; } function show_stepper(force) { var step_all = document.getElementById("step_all"); var starting_step_all = step_all.checked; if (force && !starting_step_all) { step_all.checked = true; step_all_forced = true; } else { step_all_forced = false; } evaluate_cmd("start-stepper",null,[step_all.checked,current_tutor_mode(),stepper_event_cmd,stepper_update_cmd], function(result){ if (result[0]) { display_stepper(result[1]); } else { alert(result[1]); } }); } var current_stepper_id = null; function display_stepper(id) { current_stepper_id = id; if (stepper) { if (stepper.getAttribute("open") != "yes") { monitor_cmd("reset-step1","reset-stepper"); monitor_cmd("clear-all-start","clear-all-stepper"); var body = document.getElementById('controls'); stepper.setAttribute("open","yes"); body.appendChild(stepper); } } else { var controls = document.getElementById('controls'); var div = document.createElement('div'); div.setAttribute("class","stepper-box"); div.setAttribute("open","yes"); var title_bar = create_title_bar("Stepper",false); div.appendChild(title_bar[0]); title_bar[2].onclick = function(){ stepper.setAttribute("open","no"); stop_monitor("reset-step1","reset-stepper"); stop_monitor("clear-all-start","clear-all-stepper"); if (step_all_forced) { step_all.checked = false; } evaluate_cmd("stop-stepper",null,[current_stepper_id],null); tutor = div_views.get("tutor-entry"); if (tutor && tutor.open) { tutor.open = false; controls.removeChild(tutor.div); } remove_cr_tutor(); remove_r_tutor(); controls.removeChild(div); }; var but_div = document.createElement('div'); but_div.setAttribute("class","stepper-buttons"); var step = document.createElement('button'); step.setAttribute("id","stepper-step-button"); step.innerHTML="Step"; step.disabled = true; step.onclick = function(){ if (tutor_event && current_tutor_mode() && (tutor_items != tutor_count)) { alert("Cannot step until current tutor task is complete."); } else { evaluate_cmd("step-stepper",null,[current_stepper_id], function(result){ if (result[0]) { disable_stepper_buttons(); } else { alert("Stepping failed because: "+result[1]); } }); } }; but_div.appendChild(step); var stop = document.createElement('button'); stop.setAttribute("id","stepper-stop-button"); stop.innerHTML="Stop"; stop.disabled = true; stop.onclick = function(){ evaluate_cmd("step-stepper",null,[current_stepper_id,true], function(result){ if (result[0]) { disable_stepper_buttons(); } else { alert("Stepping failed because: "+result[1]); } }); }; but_div.appendChild(stop); var until_type = document.createElement('select'); var s = document.createElement("option"); s.value = "time"; s.innerHTML = "time"; until_type.appendChild(s); s = document.createElement("option"); s.value = "production"; s.innerHTML = "production"; until_type.appendChild(s); s = document.createElement("option"); s.value = "module"; s.innerHTML = "module"; until_type.appendChild(s); until_type.options.selectedIndex = 0; var until = document.createElement('button'); var until_value = document.createElement('input'); but_div.appendChild(until); until.setAttribute("id","stepper-until-button"); until.innerHTML="Run Until:"; until.disabled = true; until.onclick = function(){ if (current_tutor_mode()) { alert("Cannot use run until while in tutor mode."); } else { evaluate_cmd("step-stepper",null,[current_stepper_id,false,until_type.childNodes[until_type.options.selectedIndex].value,until_value.value], function(result){ if (result[0]) { disable_stepper_buttons(); } else { alert("Run Until failed because: "+result[1]); } }); } }; but_div.appendChild(until); but_div.appendChild(until_type); but_div.appendChild(until_value); var tutor = document.createElement('div'); var tutor_box = document.createElement('input'); tutor_box.setAttribute('type',"checkbox"); tutor_box.setAttribute('id',"stepper_tutor"); tutor.innerHTML="Tutor mode"; tutor_box.onclick=change_stepper_mode; tutor.appendChild(tutor_box); but_div.appendChild(tutor); div.appendChild(but_div); var next_div = document.createElement('div'); next_div.setAttribute("class","stepper-events"); next = document.createElement('div'); next.setAttribute("class","stepper-event-label"); next.innerHTML = "Next:"; next_div.appendChild(next); next_event = document.createElement('div'); next_event.setAttribute("class","stepper-event"); next_event_text = document.createElement('pre'); next_event_text.setAttribute("id","next-stepper-event"); next_event.appendChild(next_event_text); next_div.appendChild(next_event); div.appendChild(next_div); var last_div = document.createElement('div'); last_div.setAttribute("class","stepper-events"); last = document.createElement('div'); last.setAttribute("class","stepper-event-label"); last.innerHTML = "Last:"; last_div.appendChild(last); last_event = document.createElement('div'); last_event.setAttribute("class","stepper-event"); last_event_text = document.createElement('pre'); last_event_text.setAttribute("id","last-stepper-event"); last_event.appendChild(last_event_text); last_div.appendChild(last_event); div.appendChild(last_div); var display = document.createElement('div'); display.setAttribute("class","stepper-display"); var pane = document.createElement('div'); pane.setAttribute("class","stepper-display-panel"); display.appendChild(pane); var pane2 = document.createElement('div'); pane2.setAttribute("class","stepper-display-panel"); display.appendChild(pane2); div.appendChild(display); var heading = document.createElement('div'); heading.setAttribute("class","stepper-display-label"); heading.setAttribute("id","stepper-l1"); pane.appendChild(heading); var c_list = document.createElement('div'); c_list.setAttribute("class","stepper-display-list"); var list = document.createElement('ul'); list.setAttribute("id","stepper-item-list"); c_list.appendChild(list); pane.appendChild(c_list); heading = document.createElement('div'); heading.setAttribute("class","stepper-display-label"); heading.setAttribute("id","stepper-l2"); pane.appendChild(heading); var c_display = document.createElement('div'); c_display.setAttribute("class","stepper-display-text"); var text_box = document.createElement('div'); text_box.setAttribute("class","stepper-output-display"); var text = document.createElement('pre'); text.setAttribute("id","stepper-d2"); c_display.appendChild(text_box); text_box.appendChild(text); pane.appendChild(c_display); var heading = document.createElement('div'); heading.setAttribute("class","stepper-display-label"); heading.setAttribute("id","stepper-l3"); pane2.appendChild(heading); c_display = document.createElement('div'); c_display.setAttribute("class","stepper-display-text"); text_box = document.createElement('div'); text_box.setAttribute("class","stepper-output-display"); text = document.createElement('pre'); text.setAttribute("id","stepper-d3"); c_display.appendChild(text_box); text_box.appendChild(text); pane2.appendChild(c_display); heading = document.createElement('div'); heading.setAttribute("class","stepper-display-label"); heading.setAttribute("id","stepper-l4"); pane2.appendChild(heading); c_display = document.createElement('div'); c_display.setAttribute("class","stepper-display-text"); text_box = document.createElement('div'); text_box.setAttribute("class","stepper-output-display"); text = document.createElement('pre'); text.setAttribute("id","stepper-d4"); c_display.appendChild(text_box); text_box.appendChild(text); pane2.appendChild(c_display); monitor_cmd("reset-step1","reset-stepper"); monitor_cmd("clear-all-start","clear-all-stepper"); stepper = div; controls.appendChild(div); } reset_stepper(); evaluate_cmd("set-stepper-ready",null,[current_stepper_id],null); } function clear_all_stepper() { if(stepper) { if (stepper.getAttribute("open") == "yes") { stepper.setAttribute("open","no"); stop_monitor("reset-step1","reset-stepper"); stop_monitor("clear-all-start","clear-all-stepper"); if (step_all_forced) { step_all.checked = false; } document.getElementById('stepper_tutor').checked = false; var controls = document.getElementById('controls'); controls.removeChild(stepper); } } } function reset_stepper() { if (stepper) { if (stepper.getAttribute("open") == "yes") { stepper.item = null; tutor_event = null; tutor_data = null; tutor_items = null; document.getElementById('stepper_tutor').checked = false; var i = document.getElementById("stepper-l1"); i.innerHTML=""; i = document.getElementById("stepper-l2"); i.innerHTML=""; i = document.getElementById("stepper-l3"); i.innerHTML=""; i = document.getElementById("stepper-l4"); i.innerHTML=""; i = document.getElementById("stepper-d2"); i.innerHTML=""; i = document.getElementById("stepper-d3"); i.innerHTML=""; i = document.getElementById("stepper-d4"); i.innerHTML=""; i = document.getElementById("next-stepper-event"); i.innerHTML=""; i = document.getElementById("last-stepper-event"); i.innerHTML=""; i = document.getElementById("stepper-item-list"); while(i.firstChild) { i.removeChild(i.firstChild); } } remove_instan_tutor(); remove_cr_tutor(); remove_r_tutor(); } } function update_step_all() { if (stepper) { var step_all = document.getElementById("step_all"); evaluate_cmd("set-stepper-step-all",null,[current_stepper_id,step_all.checked],null); } } add_cmd("reset-stepper","environment stepper reset monitor. do not call",reset_stepper,null); add_cmd("clear-all-stepper","environment stepper clear-all monitor. do not call",clear_all_stepper,null); </script> <style> .stepper-box { display: flex; width: 575px; border: double; height: 400px; flex-direction: column; overflow: hidden; resize: both; } .stepper-buttons { display: flex; height: 35px; width: 100%; flex-direction: row; } .stepper-events { display: flex; height: 75px; width: 100%; flex-direction: row; overflow: hidden; } .stepper-event-label { display: flex; height: 100%; width: 20%; overflow: hidden; } .stepper-event { display: flex; height: 100%; width: 80%; overflow-x: scroll; } .stepper-display { display: flex; flex-direction: row; height: 100%; width: 100%; overflow: hidden; } .stepper-display-panel { display: flex; flex-direction: column; height: 100%; width: 50%; overflow: hidden; margin: 3px; } .stepper-display-label { display: flex; height: 25px; width: 100%; } .stepper-display-list { display: flex; height: 50%; width: 100%; overflow: auto; ul { display: flex; overflow: auto; padding: 0; } } .stepper-display-text { display: flex; height: 50%; width: 100%; overflow: hidden; } .stepper-output-display { display: flex; overflow: auto; width: 100%; height: 100%; } </style> <script> // the prompt to get variable bindings in the stepper's tutor mode function tutor_entry(index) { tutor_entry_window = div_views.get("tutor-entry"); var controls = document.getElementById('controls'); if (tutor_entry_window) { if (!tutor_entry_window.open) { tutor_entry_window.open = true; controls.appendChild(tutor_entry_window.div); } } else { var div = document.createElement('div'); div.setAttribute("class","tutor-answer-box"); var title_bar = create_title_bar("Tutor Mode Entry",false); div.appendChild(title_bar[0]); title_bar[2].onclick = function(){ tutor_entry_window.open = false; controls.removeChild(div); }; var prompt = document.createElement('div'); prompt.setAttribute("class","tutor-info"); div.appendChild(prompt); var entry = document.createElement('div'); entry.setAttribute("class","tutor-info"); var entry_box = document.createElement('input'); entry.appendChild(entry_box); div.appendChild(entry); var info = document.createElement('div'); info.setAttribute("class","tutor-info"); div.appendChild(info); var but_div = document.createElement('div'); but_div.setAttribute("class","tutor-info"); var hint = document.createElement('button'); hint.innerHTML="Hint"; but_div.appendChild(hint); var help = document.createElement('button'); help.innerHTML="Help"; but_div.appendChild(help); div.appendChild(but_div); tutor_entry_window = {"div": div, "open": true, "prompt": prompt, "info": info, "entry_value": entry_box, "hint": hint, "help": help}; div_views.set("tutor-entry",tutor_entry_window); controls.appendChild(div); } var variable = tutor_values[index][0]; var lhs = tutor_values[index][1]; var details = tutor_data.get(variable); tutor_entry_window.prompt.innerHTML = "What is the binding for " + variable + "?"; tutor_entry_window.info.innerHTML = ""; tutor_entry_window.entry_value.onchange = function() { if ((details.answer.toUpperCase() && tutor_entry_window.entry_value.value.toUpperCase() && (details.answer.toUpperCase() == tutor_entry_window.entry_value.value.toUpperCase())) || (details.answer == tutor_entry_window.entry_value.value)) { var bindings_text = document.getElementById("stepper-d3").innerHTML; var production_text = document.getElementById("stepper-d4").innerHTML; var bind_exp = new RegExp("^"+variable+":$","m"); document.getElementById("stepper-d3").innerHTML=bindings_text.replace(bind_exp,variable+": "+details.answer); var matching_string = "<mark style=\"background: lightblue\" onclick=\"tutor_entry("+index+")\">"+variable+"</mark>"; document.getElementById("stepper-d4").innerHTML=production_text.replace(matching_string,details.answer); details.answered = true; tutor_entry_window.open = false; controls.removeChild(tutor_entry_window.div); tutor_count++; } else { tutor_entry_window.info.innerHTML=tutor_entry_window.entry_value.value + " is not the binding for "+ variable; } }; tutor_entry_window.entry_value.value=""; tutor_entry_window.hint.onclick = function() { if (details.answered) { tutor_entry_window.info.innerHTML="Look in the bindings section of the stepper window for the current binding of " + variable; } else if (!lhs) { tutor_entry_window.info.innerHTML="You should find the binding for " + variable + " on the left hand side of the production first"; } else if (details.buffer) { tutor_entry_window.info.innerHTML="Use the buffers tool to determine the chunk in the " + variable.slice(1) + " buffer."; } else if (lhs && !details.buffer) { tutor_entry_window.info.innerHTML=variable + " is in a slot of the " + details.in_buffer + " buffer. You can find its value using the buffers tool."; } else { tutor_entry_window.info.innerHTML="No hint is available for this variable. If it is in a !bind! or !mv-bind! you will need to use the help button to get the answer."; } } tutor_entry_window.help.onclick = function() { tutor_entry_window.info.innerHTML="The current binding of " + variable + " is " + details.answer; } tutor_entry_window.entry_value.focus(); } </script> <script> // the display for selecting matching productions function show_cr_tutor(data) { var tutor_entry_window = div_views.get("tutor-cr-entry"); var controls = document.getElementById('controls'); var div = null if (tutor_entry_window) { if (!tutor_entry_window.open) { tutor_entry_window.open = true; tutor_entry_window.choices.forEach(function (x) { try { tutor_entry_window.div.removeChild(x); } catch (err) {}; }); try { tutor_entry_window.div.removeChild(tutor_entry_window.np); } catch (err) {}; } div = tutor_entry_window.div; } else { div = document.createElement('div'); div.setAttribute("class","tutor-pick-items"); var title_bar = create_title_bar("Choose Matching Productions",false); div.appendChild(title_bar[0]); title_bar[2].onclick = function(){ tutor_items = 0; tutor_entry_window.open = false; try { tutor_entry_window.div.removeChild(tutor_entry_window.np); } catch (err) {}; controls.removeChild(div); }; var prompt = document.createElement('div'); prompt.setAttribute("class","tutor-picker-info"); var text_box = document.createElement('div'); text_box.setAttribute("class","tutor-prompt-box"); var text = document.createElement('pre'); prompt.appendChild(text_box); text_box.appendChild(text); div.appendChild(prompt); var check = document.createElement('button'); check.innerHTML="Check"; div.appendChild(check); var none_prompt = document.createElement('div'); none_prompt.setAttribute("class","tutor-picker-item"); var none_text = document.createElement('pre'); var none_box = document.createElement('input'); none_box.setAttribute('type',"checkbox"); none_text.innerHTML=" None match"; none_box.onclick=no_cr_selected; none_prompt.appendChild(none_box); none_prompt.appendChild(none_text); tutor_entry_window = {"div": div, "open": true, "prompt": text, "check": check, "none": none_box,"np": none_prompt}; div_views.set("tutor-cr-entry",tutor_entry_window); controls.appendChild(div); } tutor_entry_window.none.checked = false ; div.appendChild(tutor_entry_window.np); tutor_entry_window.boxes = []; tutor_entry_window.answers = []; tutor_entry_window.choices = []; tutor_entry_window.texts = []; var pnum=0; if (data) { data.forEach(function(x) { prompt = document.createElement('div'); prompt.setAttribute("class","tutor-picker-item"); box = document.createElement('input'); box.setAttribute('type',"checkbox"); box.onclick=unselect_none; text_box = document.createElement('div'); text_box.setAttribute("class","tutor-item-box"); var text = document.createElement('pre'); text_box.appendChild(text); prompt.appendChild(box); prompt.appendChild(text_box); div.appendChild(prompt); text.innerHTML = "(production"+pnum+"\n"+x[0]+" ==>"; tutor_entry_window.boxes.push(box); tutor_entry_window.answers.push(x[1]); tutor_entry_window.choices.push(prompt); tutor_entry_window.texts.push(text); pnum++; }); } tutor_entry_window.prompt.innerHTML = "Using the information in the buffers,\nclick the box next to each of the\nproductions which have conditions\nthat match the current state, or check\nthe box labeled 'None match' if none\nof them match.\nThen press the Check button when done."; tutor_entry_window.check.innerHTML="Check"; tutor_entry_window.check.onclick = function() { if (no_cr_selections(tutor_entry_window)) { alert("You must select at least one production or the None match option."); } else if (all_cr_correct(tutor_entry_window)) { tutor_entry_window.div.removeChild(tutor_entry_window.np); remove_cr_tutor(); } else { tutor_entry_window.prompt.innerHTML = "These selections were incorrect.\nPress Ok after reviewing the reasons."; tutor_entry_window.div.removeChild(tutor_entry_window.np); tutor_entry_window.check.innerHTML="OK"; tutor_entry_window.check.onclick = function () { tutor_items = 0; tutor_entry_window.open = false; controls.removeChild(tutor_entry_window.div); }; } }; controls.appendChild(tutor_entry_window.div); } function no_cr_selected() { var tutor_entry_window = div_views.get("tutor-cr-entry"); var box = tutor_entry_window.none; if (box.checked) { tutor_entry_window.boxes.forEach(function(x){ x.checked = false; }); } } function unselect_none(){ var tutor_entry_window = div_views.get("tutor-cr-entry"); var box = tutor_entry_window.none; box.checked = false; } function all_cr_correct(tutor_entry_window) { var result = true; var boxes = tutor_entry_window.boxes; var answers = tutor_entry_window.answers; var choices = tutor_entry_window.choices; var texts = tutor_entry_window.texts; for (var i = 0; i < boxes.length; i++) { if (boxes[i].checked) { if (answers[i] == "") { tutor_entry_window.div.removeChild(choices[i]); } else { result = false; boxes[i].disabled = true; texts[i].innerHTML = texts[i].innerHTML + "\n<b>"+answers[i]+"</b>"; } } else { if (answers[i] != "") { tutor_entry_window.div.removeChild(choices[i]); } else { result = false; boxes[i].disabled = true; texts[i].innerHTML = texts[i].innerHTML + "\n<b>Does Match current state</b>"; } } } return result; } function no_cr_selections(tutor_entry_window) { var box = tutor_entry_window.none; if (box.checked) { return false; } else { var result = true; tutor_entry_window.boxes.forEach(function(x){ if (x.checked) { result = false; } }); return result; } } function remove_cr_tutor() { var tutor_entry_window = div_views.get("tutor-cr-entry"); var controls = document.getElementById('controls'); tutor_items = 0; if (tutor_entry_window) { if (tutor_entry_window.open) { tutor_entry_window.open = false; controls.removeChild(tutor_entry_window.div); } } } function remove_r_tutor() { var tutor_entry_window = div_views.get("tutor-r-entry"); var controls = document.getElementById('controls'); tutor_items = 0; if (tutor_entry_window) { if (tutor_entry_window.open) { tutor_entry_window.open = false; controls.removeChild(tutor_entry_window.div); } } } function remove_instan_tutor() { tutor_entry_window = div_views.get("tutor-entry"); var controls = document.getElementById('controls'); if (tutor_entry_window) { if (tutor_entry_window.open) { tutor_entry_window.open = false; controls.removeChild(tutor_entry_window.div); } } } // the display for selecting matching chunks function show_r_tutor(data) { var tutor_entry_window = div_views.get("tutor-r-entry"); var controls = document.getElementById('controls'); var div = null if (tutor_entry_window) { if (!tutor_entry_window.open) { tutor_entry_window.open = true; tutor_entry_window.choices.forEach(function (x) { try { tutor_entry_window.div.removeChild(x); } catch (err) {}; }); try { tutor_entry_window.div.removeChild(tutor_entry_window.np); } catch (err) {}; } div = tutor_entry_window.div; } else { div = document.createElement('div'); div.setAttribute("class","tutor-pick-items"); var title_bar = create_title_bar("Choose Matching Chunks",false); div.appendChild(title_bar[0]); title_bar[2].onclick = function(){ tutor_items = 0; tutor_entry_window.open = false; try { tutor_entry_window.div.removeChild(tutor_entry_window.np); } catch(err) {}; controls.removeChild(div); }; var prompt = document.createElement('div'); prompt.setAttribute("class","tutor-picker-info"); var text_box = document.createElement('div'); text_box.setAttribute("class","tutor-prompt-box"); var text = document.createElement('pre'); prompt.appendChild(text_box); text_box.appendChild(text); div.appendChild(prompt); var check = document.createElement('button'); check.innerHTML="Check"; div.appendChild(check); var none_prompt = document.createElement('div'); none_prompt.setAttribute("class","tutor-picker-item"); var none_text = document.createElement('pre'); var none_box = document.createElement('input'); none_box.setAttribute('type',"checkbox"); none_text.innerHTML=" None match"; none_box.onclick=no_r_selected; none_prompt.appendChild(none_box); none_prompt.appendChild(none_text); tutor_entry_window = {"div": div, "open": true, "prompt": text, "check": check, "none": none_box,"np": none_prompt}; div_views.set("tutor-r-entry",tutor_entry_window); controls.appendChild(div); } tutor_entry_window.none.checked = false ; div.appendChild(tutor_entry_window.np); tutor_entry_window.boxes = []; tutor_entry_window.answers = []; tutor_entry_window.choices = []; tutor_entry_window.texts = []; var pnum=0; if (data[1]) { data[1].forEach(function(x) { prompt = document.createElement('div'); prompt.setAttribute("class","tutor-picker-item"); box = document.createElement('input'); box.setAttribute('type',"checkbox"); box.onclick=unselect_none_r; text_box = document.createElement('div'); text_box.setAttribute("class","tutor-item-box"); var text = document.createElement('pre'); text_box.appendChild(text); prompt.appendChild(box); prompt.appendChild(text_box); div.appendChild(prompt); text.innerHTML = x[0]; tutor_entry_window.boxes.push(box); tutor_entry_window.answers.push(x[1]); tutor_entry_window.choices.push(prompt); tutor_entry_window.texts.push(text); pnum++; }); } tutor_entry_window.prompt.innerHTML = "Click the box next to each chunk from\nthe model's declarative memory which\nmatches the retrieval request from\nthe production that fired (shown below)\nor check the 'None match' box if\nnone of them match.\nThen press the Check button when done.\n<b>"+data[0]+"</b>"; tutor_entry_window.check.innerHTML="Check"; tutor_entry_window.check.onclick = function() { if (no_r_selections(tutor_entry_window)) { alert("You must select at least one chunk or the None match option."); } else if (all_r_correct(tutor_entry_window)) { tutor_entry_window.div.removeChild(tutor_entry_window.np); remove_r_tutor(); } else { tutor_entry_window.prompt.innerHTML = "These selections were incorrect.\nFor this request\n<b>"+data[0]+"</b>\n\nPress Ok after reviewing the items."; tutor_entry_window.div.removeChild(tutor_entry_window.np); tutor_entry_window.check.innerHTML="OK"; tutor_entry_window.check.onclick = function () { tutor_items = 0; tutor_entry_window.open = false; controls.removeChild(tutor_entry_window.div); }; } }; controls.appendChild(tutor_entry_window.div); } function no_r_selected() { var tutor_entry_window = div_views.get("tutor-r-entry"); var box = tutor_entry_window.none; if (box.checked) { tutor_entry_window.boxes.forEach(function(x){ x.checked = false; }); } } function unselect_none_r(){ var tutor_entry_window = div_views.get("tutor-r-entry"); var box = tutor_entry_window.none; box.checked = false; } function all_r_correct(tutor_entry_window) { var result = true; var boxes = tutor_entry_window.boxes; var answers = tutor_entry_window.answers; var choices = tutor_entry_window.choices; var texts = tutor_entry_window.texts; for (var i = 0; i < boxes.length; i++) { if (boxes[i].checked) { if (answers[i]) { tutor_entry_window.div.removeChild(choices[i]); } else { result = false; boxes[i].disabled = true; texts[i].innerHTML = texts[i].innerHTML + "\n<b>Does not match the request</b>"; } } else { if (answers[i]) { result = false; boxes[i].disabled = true; texts[i].innerHTML = texts[i].innerHTML + "\n<b>Does Match the request</b>"; } else { tutor_entry_window.div.removeChild(choices[i]); } } } return result; } function no_r_selections(tutor_entry_window) { var box = tutor_entry_window.none; if (box.checked) { return false; } else { var result = true; tutor_entry_window.boxes.forEach(function(x){ if (x.checked) { result = false; } }); return result; } } </script> <script> // Open the experiment window tool in another window/tab function open_exp_view() { open(document.baseURI+"expwindow.html"); } </script> <style> .tutor-answer-box { display: flex; width: 350px; border: double; height: 200px; flex-direction: column; overflow: hidden; resize: both; } .tutor-info { display: flex; height: 40px; width: 100%; flex-direction: row; } .tutor-pick-items { display: flex; width: 350px; border: double; height: 630px; flex-direction: column; overflow: auto; resize: both; } .tutor-picker-info { display: flex; height: auto; width: 100%; flex-direction: row; } .tutor-picker-item { display: flex; height: auto; border: single; width: 100%; flex-direction: row; } .tutor-prompt-box { display: flex; overflow: auto; width: 100%; height: auto; } .tutor-item-box { display: flex; overflow: auto; width: 100%; height: auto; } </style> <!-- The button display on the Left is just HTML --> <style> .flex-container { display: flex; flex-direction: row; height: 100%; } .button-panel { display: flex; flex-direction: column; align-items: center; width: 300px; height: 100%; } .button-section { display: flex; flex-direction: column; align-items: center; margin: 10px; } .controls { display: flex; flex-direction: row; flex-wrap: wrap; width: 100%; height: 100%; } </style> <div class="flex-container"> <div class="button-panel"> <div class="button-section"> <div>Current Model</div> <select id="current_model" onchange="change_model()" > </select> </div> <div class="button-section"> <!-- start-normal --> <div>Files</div> <button type="button" onclick="load_model(true)">Load ACT-R Tutorial Model</button> <div> Unit <input type="number" class="enter" value="1" id="load_unit" min="1" max="8"></div> <button type="button" onclick="load_model(false)">Load ACT-R Tutorial Experiment Code</button> <button type="button" onclick="load_python_module()">Import Python Module</button> <!-- end-normal --> <!-- start-container <div>Unit 1 Models</div> <button type="button" onclick="load_unit1_model()">Load Tutorial Model</button> <select id="unit_1_model"> <option value="">-Select Unit 1 model-</option> <option value="count.lisp">Count</option> <option value="addition.lisp">Addition</option> <option value="semantic.lisp">Semantic</option> <option value="tutor-model.lisp">Tutor Model</option> </select> end-container --> </div> <div class="button-section"> <div>Control</div> <div> <button type="button" onclick="show_stepper(false)">Stepper</button> <input type="checkbox" id="step_all" onchange="update_step_all()">Step All</input> </div> <button type="button" onclick="show_stepper(true)">Pause</button> <button type="button" onclick="show_event_queue()">Event Queue</button> <div> <button type="button" onclick="reset_actr()">Reset</button> <button type="button" onclick="reload_actr()">Reload</button> </div> <div> <button type="button" onclick="run_actr()">Run</button> <input type="number" name="" class="enter" value="10" id="run_time" min="0" width=100> </div> <div><input type="checkbox" id="show_running" onchange="update_running()">Show Running</input></div> <div id="running-indicator">-------</div> </div> <div class="button-section"> <div>Current Data</div> <button type="button" onclick="dm_viewer()">Declarative</button> <button type="button" onclick="procedural_viewer()">Procedural</button> <button type="button" onclick="buffer_viewer()">Buffers</button> <button type="button" onclick="visicon_viewer()">Visicon</button> <button type="button" onclick="audicon_viewer()">Audicon</button> </div> <div class="button-section"> <div>Miscellaneous</div> <button type="button" onclick="cmd_viewer()">Connections &amp; Commands</button> <button type="button" onclick="open_exp_view()">Open Experiment Window</button> </div> </div> <div class="controls" id="controls"> </div> </div> <script type=text/javascript> document.getElementById("show_running").checked = false; document.getElementById("step_all").checked = false; </script> </body> </html>
91,765
Common Lisp
.l
2,320
27.752586
314
0.552505
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
58dd6c831fe3dcbb9b7a5d6d45664760f9ac52f79e2482488c45d368878be0ea
14,510
[ -1 ]
14,511
simple.js
asmaloney_ACT-R/examples/connections/nodejs/simple.js
var net = require('net') var fs = require('fs') // Get the user's home directory which hopefully is in one of these // and matches the one ACT-R uses. var home = process.env.HOME || process.env.USERPROFILE || process.env.HOMEPATH var address = fs.readFileSync(home + "/act-r-address.txt",'utf8') var port = fs.readFileSync(home + "/act-r-port-num.txt",'utf8') var client = new net.Socket() client.connect(port,address) // Handle all the received communication in the data // function. Probably not the best way. Also, I'm sure // there's some simple object based way to create the // return results to write, but I don't really know // javascript. Since it works and this is only for // example purposes I'm calling it good enough. :) client.on('data',function(data) { let end = -1; let start = 0; // Assume we get whole messages for the example, but // something with large data values may be split and // need some way to handle that. while ((end = data.indexOf("\u0004", start)) != -1) { let m = JSON.parse(data.slice(start,end)); if (m.result) { // When there's a result it must be in response to an evaluate request if (m.id == 1) { // Does it have the id we sent? console.log('ACT-R version: ' + m.result[0]); } else { console.log('Result for wrong id returned'); } } if (m.error) { // If it has an error that was in response to an evaluate request console.log('Error reported in message: ' + data.slice(start,end)); } if (m.method && m.params) { // The only messages clients get with a method and params if (m.method == "evaluate") { // are to evaluate but check to be sure. let e = ""; let r = ""; if (m.params[0] == "add") { // is it the add command we created? if (m.params.length == 4) { // should be some error handling around this... r = m.params[2] + m.params[3]; } else { e = "Wrong number of parameters"; } } else { e = "Wrong method to evaluate"; } if (m.id) { // if there was an id return the result if (e == "") { // no error means send the result client.write("{\"result\":" + JSON.stringify(r) + ",\"error\":null,\"id\":" + JSON.stringify(m.id) + "}\u0004"); } else { // send the error client.write("{\result\":null,\"error\":" + e + ",\"id\":" + JSON.stringify(m.id) + "}\u0004"); } } } else { // shouldn't happen console.log('Invalid message: ' + data.slice(start,end)); } } start = end + 1; } }); // Set the name for this client client.write("{\"method\":\"set-name\",\"params\":[\"Node.js simple connect\"],\"id\":null}\u0004") // Evaluate the ACT-R "act-r-version" command, the result will be printed by the function above. client.write("{\"method\":\"evaluate\",\"params\":[\"act-r-version\"],\"id\":1}\u0004") // Add a new command called "node-js-add" which will be referred to as "add" locally. client.write("{\"method\":\"add\",\"params\":\[\"node-js-add\",\"add\",\"Add the two numbers provided. Params: num1 num2\"\],\"id\":null}\u0004")
3,298
Common Lisp
.l
67
41.880597
146
0.595906
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
0615ebc66cd454fd237cd653a33a2d46cbd9362892bead826526ddccbc7a83a1
14,511
[ -1 ]
14,512
goal.html
asmaloney_ACT-R/examples/connections/nodejs/goal.html
<html> <body> <script src="/socket.io/socket.io.js"></script> <script> var socket = io(); function update() { socket.emit('getgoal'); }; socket.on('updategoal',function(msg){ document.getElementById("goal").innerHTML = msg; }); </script> <pre id="goal"></pre> <button type="button" onclick="update()">Update</button> </body> </html>
403
Common Lisp
.l
16
19.8125
59
0.601078
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
92111d97fb668fd9f73fc8fbd07e5ea537ba85993d437ab191f324806bd2d747
14,512
[ -1 ]
14,513
expwindow.html
asmaloney_ACT-R/examples/connections/nodejs/expwindow.html
<html> <head> <style type="text/css"> body, html { margin:0; padding:0; background:white; color:#000; } #canvas { border: 1px solid DarkGray; } </style> </head> <body> <div id="canvascontainer"> <canvas id="canvas" width="1024" height="768"></canvas> </div> <script src="/socket.io/socket.io.js"></script> <!-- For the mybinder and jupyter versions use this instead: src="socket.io/socket.io.js" --> <script> // set this so the right path info is used later var which_interface = 1; // 1 is normal, 2 is mybinder, 3 is jupyter, 4 is play-with-docker </script> <script> var c = document.getElementById("canvas"); var canvas = c.getContext("2d"); function addtext(text,x,y,size,color){ canvas.font = size+"px sans-serif"; canvas.fillStyle = color; canvas.globalAlpha = 1.0; canvas.textAlign = "start"; canvas.textBaseline = "hanging"; canvas.fillText(text,x,y); } function addbutton(x1,y1,w,h,text,color) { canvas.fillStyle = color; canvas.globalAlpha = 1.0; canvas.fillRect(x1,y1,w,h); canvas.font = "14px sans-serif"; canvas.strokeStyle = "black"; canvas.lineWidth = 1; canvas.strokeRect(x1,y1,w,h); canvas.textBaseline = "middle"; canvas.textAlign = "center"; canvas.fillStyle = "black"; canvas.fillText(text,x1 + w/2,y1 + h/2); } function addline(x1,y1,x2,y2,color) { canvas.strokeStyle = color; canvas.globalAlpha = 1.0; canvas.lineWidth=2; canvas.beginPath(); canvas.moveTo(x1,y1); canvas.lineTo(x2,y2); canvas.stroke(); } function attentionring(x,y,color){ canvas.fillStyle = color; canvas.globalAlpha = .3; canvas.beginPath(); canvas.arc(x, y, 15, 0, Math.PI*2, true); canvas.closePath(); canvas.fill(); } function drawcursor(x,y,color) { cursor = new Path2D(); cursor.moveTo(x,y); cursor.lineTo(x,y+15); cursor.lineTo(x+4,y+13); cursor.lineTo(x+7,y+19); cursor.lineTo(x+9,y+19); cursor.lineTo(x+7,y+12); cursor.lineTo(x+12,y+12); cursor.closePath(); canvas.fillStyle = "white"; canvas.globalAlpha = 1.0; canvas.fill(cursor); canvas.strokeStyle = color; canvas.lineWidth = 2; canvas.stroke(cursor); } if (which_interface == 1 || which_interface == 4) { var socket = io('/expwindow'); } else if (which_interface == 2) { var address = document.baseURI ; var socket = io('/expwindow', { path: address.slice(address.indexOf('/user'),address.indexOf('expwindow'))+"socket.io" }); } else { var address = document.baseURI ; var socket = io('/expwindow', { path: "/proxy/4000/socket.io" }); } var items = {}; var attn = {}; function redisplay () { canvas.fillStyle = "white"; canvas.clearRect(0,0,1024,768); for (var i in items) { item = items[i]; switch(item[1]) { case "text" : addtext(item[4],item[2],item[3],item[6],item[5]); break; case "line" : addline(item[2],item[3],item[4],item[5],item[6]); break; case "button" : addbutton(item[2],item[3],item[4],item[5],item[6],item[7]); break; } } for (var a in attn) { item = attn[a]; switch(item[1]) { case "attend" : attentionring(item[2],item[3],item[4]); break; case "cursor" : drawcursor(item[2],item[3],item[4]); break; } } } socket.on('attend',function(msg){ attn[msg[0]] = msg; redisplay(); }); socket.on('add',function(msg){ items[msg[0]] = msg; redisplay(); }); socket.on('remove',function(msg){ delete items[msg]; delete attn[msg]; redisplay(); }); socket.on('clear',function(msg){ items = {}; attn = {}; redisplay() }); document.onmousedown = function(evt) { socket.emit('mouse',[evt.clientX,evt.clientY]); }; document.onkeypress = function(evt) { socket.emit('down',evt.key); }; </script> </body> </html>
4,332
Common Lisp
.l
150
22.1
97
0.578652
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
54bc9077325c85897eb1aef9186cdfd79255032236a3f34d7dcfce0fd85a931d
14,513
[ -1 ]
14,514
relay-virtual-view.js
asmaloney_ACT-R/examples/connections/nodejs/relay-virtual-view.js
// Create a webserver on port 3000 of the machine // and provide two pages as examples using websockets // provided by socket.io to update the information. // The default page is a viewer for the visible virtual // windows and this code will relay the info to that // window to display on a canvas item. // The page /goal.html will display the contents // of the chunk in the goal buffer everytime the // update button is pressed. // For simplicity, this sends all the updates to // every connected window regardless of what it // is displaying. var app = require('express')(); var http = require('http').Server(app); var io = require('socket.io')(http); // the visible virtual viewer app.get('/', function(req, res) { res.sendFile(__dirname + '/index.html'); }); // the goal buffer viewer app.get('/goal.html', function(req,res) { res.sendFile(__dirname + '/goal.html'); }); // Start the http server on port 3000. http.listen(3000); // Connect to ACT-R var net = require('net') var fs = require('fs') // Get the user's home directory which hopefully is in one of these // and matches the one ACT-R uses. var home = process.env.HOME || process.env.USERPROFILE || process.env.HOMEPATH var address = fs.readFileSync(home + "/act-r-address.txt",'utf8') var port = fs.readFileSync(home + "/act-r-port-num.txt",'utf8') var client = new net.Socket() client.connect(port,address) // Record of the window information for the visible virtual windows windows = {} // Just handle all the received communication in the data // function. Probably not the best way... client.on('data',function(data) { let end = -1; let start = 0; // Assume we get whole messages. while ((end = data.indexOf("\u0004", start)) != -1) { let m = JSON.parse(data.slice(start,end)); if (m.result) { // Only response we get is to our printed-buffer-chunk request not bothering to check the id // send the result to all connected clients io.emit("updategoal",m.result[0]); } if (m.error) { // shouldn't get any errors, but just incase // send the error message as the result to all connected clients io.emit("updategoal",m.error.message); } if (m.method && m.params) { // A request to evaluate our command if (m.method == "evaluate") { // to be safe check and make sure if (m.params[0] == "vv") { // it's the vv command we created // ignore the model parameter which would be params[1] // and just use the list of virtual-view info which is // the only other parameter. p = m.params[2]; // Virtual view data not actually documented yet other than // in the comments of the tools/visible-virtual.lisp file. // So you'll need to check there to know what these are. switch (p[0]) { case "open" : // just record the details, will need the main position // to add to the item coords since they're window local // and the other corner for determining if a mouse click // is within the window. windows[p[1]] = {"x1" : p[2], "x2" : p[2] + p[4], "y1" : p[3], "y2" : p[3] + p[5], "items": {}}; break; case "text": w = windows[p[1]]; if (w != undefined) { // safety check because we might have missed // the open if we connected after the window was opened // create a name for the item which is a combo of the window and the item name = p[1] + "_name_" + p[2]; // record the name for use when the window is closed w["items"][name] = true; // send the details to all the connected pages io.emit("add",[name,"text",p[3]+w["x1"],p[4]+w["y1"],p[5],p[6],p[7]]); } break; case "line": w = windows[p[1]]; if (w != undefined) { name = p[1] + "_name_" + p[2]; w["items"][name] = true; io.emit("add",[name,"line",p[3]+w["x1"],p[4]+w["y1"],p[5]+w["x1"],p[6]+w["y1"],p[7]]); } break; case "button": w = windows[p[1]]; if (w != undefined) { name = p[1] + "_name_" + p[2]; w["items"][name] = true; io.emit("add",[name,"button",p[3]+w["x1"],p[4]+w["y1"],p[5],p[6],p[7],p[8]]); } break; case "attention": w = windows[p[1]]; if (w != undefined) { name = p[1] + "_attn_" + p[2]; w["items"][name] = true; // attention and cursor use a different notification // from the normal items so that they can be drawn // last and overlap the normal items io.emit("attend",[name,"attend",p[3],p[4],p[5]]); } break; case "cursor": w = windows[p[1]]; if (w != undefined) { name = p[1] + "_cursor_" + p[2]; w["items"][name] = true; io.emit("attend",[name,"cursor",p[3]+w["x1"],p[4]+w["y1"],p[5]]); } break; case "remove" : w = windows[p[1]]; if (w != undefined) { name = p[1] + "_name_" + p[2]; delete w["items"][name]; io.emit("remove",name); } break; case "clearcursor": w = windows[p[1]]; if (w != undefined) { name = p[1] + "_cursor_" + p[2]; delete w["items"][name]; io.emit("remove",name); } break; case "clearattention": w = windows[p[1]]; if (w != undefined) { name = p[1] + "_attn_" + p[2]; delete w["items"][name]; io.emit("remove",name); } break; case "close" : w = windows[p[1]]; if (w != undefined) { // send the remove for everything for (var i in w["items"]) { io.emit("remove",i); } w["items"] = {}; } // get rid of the window delete windows[p[1]] break; } } if (m.id) { // if there was an id just return a true result client.write("{\"result\": true,\"error\":null,\"id\":" + JSON.stringify(m.id) + "}\u0004"); } } else { // shouldn't happen console.log('Invalid message: ' + data.slice(start,end)); } } start = end + 1; } }); // Set the name for this client client.write("{\"method\":\"set-name\",\"params\":[\"Node.js AGI virtual viewer and goal chunk server\"],\"id\":null}\u0004") // Add a new command called "node-js-vv-relay" which will be referred to as "vv" locally. client.write("{\"method\":\"add\",\"params\":\[\"node-js-vv-relay\",\"vv\",\"Virtual window handler for browser based display. Do not call.\"\],\"id\":null}\u0004") // Evaluate the ACT-R "add-virtual-window-handler" command so that node-js-vv-relay gets called to display visible virtual window items. client.write("{\"method\":\"evaluate\",\"params\":[\"add-virtual-window-handler\",false,\"node-js-vv-relay\"],\"id\":null}\u0004") // When something connects create two handlers that will // relay the keypresses and mouse clicks back. // The mouse click is interpreted assuming the windows do // not overlap to pick which one and translate the global to local // coordinates. io.on('connection',function(socket){ console.log('connected: ' + socket.conn["remoteAddress"]); socket.emit('clear',""); // when we get a down event that is a keypress // and we just create the output-key event with // the given key name and a false (nil) model name. // Should verify that it's a valid key name for ACT-R, // but not for a simple demo. socket.on('down',function(msg){ client.write("{\"method\":\"evaluate\",\"params\":[\"output-key\",false,false,\""+msg+"\"],\"id\":null}\u0004") }); // when we get a mouse event that's a record of // a button click with an x and y position. // Loop through the windows that have been opened to // find which one it's in (if any) and then send // that to the virtual mouse handler function so it // can perform any necessary actions (button clicks, etc) // keeping in mind that (at least currently) that handler // requirs a window relative position. socket.on('mouse',function(msg){ x = msg[0]; y = msg[1]; w = -1; for (var win in windows) { if ( x >= windows[win].x1 && x <= windows[win].x2 && y >= windows[win].y1 && y <= windows[win].y2 ) { w = win; } } if (w != -1) { x = x - windows[w].x1; y = y - windows[w].y1; client.write("{\"method\":\"evaluate\",\"params\":[\"visible-virtual-window-mouse-click\",false,\""+win+"\","+x+","+y+"],\"id\":null}\u0004") } }); // When we get a getgoal event that means we need to // request the goal buffer's chunk to send back. // Assumes there's only one model defined because it // provides a false (nil) current model value. socket.on('getgoal',function(){ client.write("{\"method\":\"evaluate\",\"params\":[\"printed-buffer-chunk\",false,\"goal\"],\"id\":1}\u0004") }); });
10,015
Common Lisp
.l
219
34.894977
165
0.542339
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
4c432f1bae45c46c3d13b0a48aff6daec1d9e098735e9dd855d5ea6224d30ecb
14,514
[ -1 ]
14,515
index.html
asmaloney_ACT-R/examples/connections/nodejs/index.html
<html> <head> <style type="text/css"> body, html { margin:0; padding:0; background:white; color:#000; } #canvas { border: 1px solid DarkGray; } </style> </head> <body> <div id="canvascontainer"> <canvas id="canvas" width="1024" height="768"></canvas> </div> <script src="/socket.io/socket.io.js"></script> <script> var c = document.getElementById("canvas"); var canvas = c.getContext("2d"); function addtext(text,x,y,size,color){ canvas.font = size+"px sans-serif"; canvas.fillStyle = color; canvas.globalAlpha = 1.0; canvas.textAlign = "start"; canvas.textBaseline = "hanging"; canvas.fillText(text,x,y); } function addbutton(x1,y1,w,h,text,color) { canvas.fillStyle = color; canvas.globalAlpha = 1.0; canvas.fillRect(x1,y1,w,h); canvas.font = "14px sans-serif"; canvas.strokeStyle = "black"; canvas.lineWidth = 1; canvas.strokeRect(x1,y1,w,h); canvas.textBaseline = "middle"; canvas.textAlign = "center"; canvas.fillStyle = "black"; canvas.fillText(text,x1 + w/2,y1 + h/2); } function addline(x1,y1,x2,y2,color) { canvas.strokeStyle = color; canvas.globalAlpha = 1.0; canvas.lineWidth=2; canvas.beginPath(); canvas.moveTo(x1,y1); canvas.lineTo(x2,y2); canvas.stroke(); } function attentionring(x,y,color){ canvas.fillStyle = color; canvas.globalAlpha = .3; canvas.beginPath(); canvas.arc(x, y, 15, 0, Math.PI*2, true); canvas.closePath(); canvas.fill(); } function drawcursor(x,y,color) { cursor = new Path2D(); cursor.moveTo(x,y); cursor.lineTo(x,y+15); cursor.lineTo(x+4,y+13); cursor.lineTo(x+7,y+19); cursor.lineTo(x+9,y+19); cursor.lineTo(x+7,y+12); cursor.lineTo(x+12,y+12); cursor.closePath(); canvas.fillStyle = "white"; canvas.globalAlpha = 1.0; canvas.fill(cursor); canvas.strokeStyle = color; canvas.lineWidth = 2; canvas.stroke(cursor); } var socket = io(); var items = {}; var attn = {}; function redisplay () { canvas.fillStyle = "white"; canvas.clearRect(0,0,1024,768); for (var i in items) { item = items[i]; switch(item[1]) { case "text" : addtext(item[4],item[2],item[3],item[6],item[5]); break; case "line" : addline(item[2],item[3],item[4],item[5],item[6]); break; case "button" : addbutton(item[2],item[3],item[4],item[5],item[6],item[7]); break; } } for (var a in attn) { item = attn[a]; switch(item[1]) { case "attend" : attentionring(item[2],item[3],item[4]); break; case "cursor" : drawcursor(item[2],item[3],item[4]); break; } } } socket.on('attend',function(msg){ attn[msg[0]] = msg; redisplay(); }); socket.on('add',function(msg){ items[msg[0]] = msg; redisplay(); }); socket.on('remove',function(msg){ delete items[msg]; delete attn[msg]; redisplay(); }); socket.on('clear',function(msg){ items = {}; attn = {}; redisplay() }); document.onmousedown = function(evt) { socket.emit('mouse',[evt.clientX,evt.clientY]); }; document.onkeypress = function(evt) { socket.emit('down',evt.key); }; </script> </body> </html>
3,599
Common Lisp
.l
134
20.231343
70
0.571471
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
1a0dd65be4c169f829c7da879f67cdfb48cd28e4b7f1f0152d835d46b7e5cb46
14,515
[ -1 ]
14,517
simpleACTRtest.java
asmaloney_ACT-R/examples/connections/Java/simpleACTRtest.java
import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.net.InetAddress; import java.net.Socket; import java.net.UnknownHostException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.io.BufferedReader; import java.io.FileReader; import java.io.PrintWriter; import java.io.InputStream; import org.json.*; public class simpleACTRtest { private static char eom = 4; // End of message character. private static PrintWriter out; private static InputStream in; // Send a string down the socket stream followed by the // end of message character. private static void print (String s) { out.print(s); out.print(eom); out.flush(); } // Read and collect characters from the socket until the // end of message character is received and return the // String that was collected. private static String receive() throws IOException { StringBuffer buff = new StringBuffer(); for(int c = in.read(); (c != -1) && (c != eom) ;c = in.read()) { buff.append((char)c); } return(buff.toString()); } public static void main(String[] args) throws UnknownHostException, IOException, ClassNotFoundException, InterruptedException{ // Read the address and port from the ACT-R files in the // user's home directory. Path addressPath = Paths.get(System.getProperty("user.home"),"act-r-address.txt"); Path portPath = Paths.get(System.getProperty("user.home"),"act-r-port-num.txt"); BufferedReader ar = Files.newBufferedReader(addressPath); String address = ar.readLine(); ar.close(); BufferedReader pr = Files.newBufferedReader(portPath); String portString = pr.readLine(); pr.close(); // Connect to ACT-R. Socket socket = new Socket(address,Integer.parseInt(portString)); // Save the streams used for writing and reading // from the socket. out = new PrintWriter(socket.getOutputStream()); in = socket.getInputStream(); // Send the message to indicate a name for this connection. print("{\"method\":\"set-name\",\"params\":[\"Simple Java Example\"],\"id\":null}"); // Evaluate the ACT-R "act-r-version" command. print("{\"method\":\"evaluate\",\"params\":[\"act-r-version\"],\"id\":1}"); // Read the result and parse it to get the returned value. // Has more error checking that really necessary given we // know there are no other results that could be received. String result = receive(); JSONObject obj = new JSONObject(result); if (obj.has("result") && obj.has("error") && obj.has("id")) { if (obj.getInt("id") == 1) { // matches id sent if (obj.isNull("error")) { // no error reported JSONArray arr = obj.getJSONArray("result"); System.out.println("ACT-R Version: "+arr.getString(0)); } else { // Print the error returned. JSONObject e = obj.getJSONObject("error"); System.out.println("Error: "+e.getString("message")); } } else { System.out.println("Wrong id received."); } } else { System.out.println("Invalid message received."); } // Send the method to add a new command called "java-add" and have // it referred to as "add" in the evaluate requests that are sent. print("{\"method\":\"add\",\"params\":[\"java-add\",\"add\",\"Add the two values provided. Params: a1 a2\"],\"id\":null}"); // Loop forever reading messages and responding to requests // to evaluate "add". for(;;) { result = receive(); obj = new JSONObject(result); // Parse the object to make sure it is a valid request // to evaluate the add command with two numbers. if (obj.has("method") && obj.has("params") && obj.has("id")) { if (!obj.isNull("id")) { // Null id means no return should be sent if (obj.getString("method").equals("evaluate")) { JSONArray arr = obj.getJSONArray("params"); if (arr.length() == 4 && arr.getString(0).equals("add")) { long sum = arr.getLong(2) + arr.getLong(3); print("{\"result\":["+sum+"],\"error\":null,\"id\":"+obj.valueToString(obj.get("id"))+"}"); } else { print("{\"result\":null,\"error\":{\"message\": \"Bad parameters\"},\"id\":"+obj.valueToString(obj.get("id"))+"}"); } } else { System.out.println("Not an evaluate method."); } } else { System.out.println("Without id no return needed so do nothing."); } } else { System.out.println("Invalid message received."); } } } }
5,387
Common Lisp
.l
108
37.509259
144
0.56567
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
38185ee14aaea474287eafa4b38aa31ee868c033212248260ea4813b892e31d0
14,517
[ -1 ]
14,548
siegler.py
asmaloney_ACT-R/tutorial/python/siegler.py
# ACT-R tutorial unit 5 siegler task. # This experiment presents a model with a pair of numbers aurally # and the model must respond vocally with the sum of those numbers. # The task and data to which the model is fit are in the paper: # # Siegler, R. S., & Shrager, J. (1984). Strategy choices in addition # and subtraction: How do children know what to do? In C. Sophian (Ed.), # Origins of cognitive skills (pp. 229-293). Hillsdale, NJ: Erlbaum. # # The original experiment was performed with 4 year-olds who made # many errors in their responses. # Import the actr module for tutorial tasks import actr # Load the corresponding model for the task. actr.load_act_r_model("ACT-R:tutorial;unit5;siegler-model.lisp") # Create variables for the response, to record whether the # monitoring function is currently available, and a subset of # the original data for comparison. response = False monitor_installed = False siegler_data = [[0, .05, .86, 0, .02, 0, .02, 0, 0, .06], [0, .04, .07, .75, .04, 0, .02, 0, 0, .09], [0, .02, 0, .10, .75, .05, .01, .03, 0, .06], [.02, 0, .04, .05, .80, .04, 0, .05, 0, 0], [0, 0, .07, .09, .25, .45, .08, .01, .01, .06], [.04, 0, 0, .05, .21, .09, .48, 0, .02, .11]] # record_model_speech will be monitoring the output-speech # command called by the microphone device so that it can # record the model's speech output. def record_model_speech (model,string): global response response = string.lower() # Because the task can be run as a single trial, or over # larger blocks it's more efficient to only install and # remove the monitor once for the run instead of on each # trial as has been done in other tasks. These functions # are used to do that when necessary. def add_speech_monitor(): global monitor_installed if monitor_installed == False: actr.add_command("siegler-response",record_model_speech,"Siegler task model response") actr.monitor_command("output-speech","siegler-response") monitor_installed = True return True else: return False def remove_speech_monitor(): actr.remove_command_monitor("output-speech","siegler-response") actr.remove_command("siegler-response") global monitor_installed monitor_installed = False # trial takes two parameters which must be numbers. # It resets the model and adds a microphone device to record # the models speech output. Then, the numbers are presented # aurally to the model using new-digit-sound, and after # running the model it returns any vocal response that it made. def trial(arg1,arg2): actr.reset() actr.install_device(["speech","microphone"]) need_to_remove = add_speech_monitor() actr.new_digit_sound(arg1) actr.new_digit_sound(arg2,.75) global response response = False actr.run(30) if need_to_remove: remove_speech_monitor() return response # set runs one trial for each of the addition problems # in the data set and returns the results of those trials. def set (): need_to_remove = add_speech_monitor() data = [trial(1,1),trial(1,2),trial(1,3), trial(2,2),trial(2,3),trial(3,3)] if need_to_remove: remove_speech_monitor() return data # experiment requires one parameter which is how many sets # of trials to run. It runs that many trials collecting the # responses and then passes those to analyze to compute the # response percentages, compare the data to the experimental # data, and display the results. def experiment(n): add_speech_monitor() data = [] for i in range(n): data.append(set()) remove_speech_monitor() analyze(data) def analyze(responses): results = [[0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0]] positions = {'zero':0,'one':1,'two':2,'three':3,'four':4,'five':5, 'six':6,'seven':7,'eight':8} for r in responses: for i in range(6): if r[i] in positions: results[i][positions[r[i]]] += 1 else: results[i][9] += 1 n = len(responses) for i in range(6): for j in range(10): results[i][j] /= n display_results(results) def display_results(results): questions = ["1+1","1+2","1+3","2+2","2+3","3+3"] actr.correlation(results,siegler_data) actr.mean_deviation(results,siegler_data) print(" 0 1 2 3 4 5 6 7 8 Other") for i in range(6): print(questions[i],end="") for j in range(10): print("%6.2f" % results[i][j],end="") print()
5,039
Common Lisp
.l
119
34.966387
95
0.625286
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
7b77f17dfae4f6949f989d15fe88ee42b30ec5f34429bd537fc6cc7fbcd1b5c4
14,548
[ -1 ]
14,549
ul_issues.py
asmaloney_ACT-R/tutorial/python/ul_issues.py
# ACT-R tutorial unit7 task for investigating utility # learning modeling issues. import actr def present_choose(): actr.goal_focus('initial-goal') if actr.random(1.0) < .6: answer = 'a' elif actr.random(1.0) > .5: answer = 'b' else: answer = None actr.schedule_event_relative(5,'utility-learning-issues-show-result',params=[answer],output='medium') def show_result (choice): actr.mod_chunk('response','answer',choice) actr.set_buffer_chunk('imaginal','response') actr.schedule_event_relative(2,'utility-learning-issues-choose',output='medium') actr.add_command('utility-learning-issues-choose',present_choose,"Function to change model's goal for utility learning issues model") actr.add_command('utility-learning-issues-show-result',show_result,"Function to set the model's imaginal buffer for utility learning issues model") def finished (): actr.remove_command('utility-learning-issues-choose') actr.remove_command('utility-learning-issues-show-result') actr.load_act_r_model("ACT-R:tutorial;unit7;utility-learning-issues-model.lisp")
1,151
Common Lisp
.l
22
46.181818
148
0.728015
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
116b4ab4e757ce029c0dc845c9230a5c050d4217183aa10db0d69399b1d7fa4d
14,549
[ -1 ]
14,550
sperling.py
asmaloney_ACT-R/tutorial/python/sperling.py
# ACT-R tutorial unit 3 demonstration task. # The sperling experiment displays a block of 12 # letters in the window, with 3 lines of 4 letters # per line for a brief time. After the display has # been presented a tone sound is generated to indicate # which row of letters must be reported (the timing of # the tone relative to the initial display of the # letters is variable). After the letters go away # the participant must press the keys to indicate which # letters were in the target row, and press the spacebar # to indicate completion. # Import the actr module for tutorial tasks import actr # Load the corresponding tutorial model actr.load_act_r_model("ACT-R:tutorial;unit3;sperling-model.lisp") # Define some global variables: responses holds the list of # keys pressed by the participant, show_responses indicates # whether or not to print out the responses provided after a # trial is run, and exp_data holds the results of the # original experiment (number of correct responses from # the target row based on the delay of the tone) for # comparison to the model's performance. responses = [] show_responses = True exp_data = [3.03,2.4,2.03,1.5] # The trial function runs a single trial of the task # and returns the number of correct responses. It requires one # parameter which is the time in seconds to delay the tone # after the items have been presented. def trial(onset_time): # Reset ACT-R and all models to initial state actr.reset() # create some local variables to perform the trial: # letters: is a randomized list of letter strings # answers: will be the list of letters in the target row # row: a random number from 0-2 indicating which row will # be the target # window: an experiment window created to display the task letters = actr.permute_list(["B","C","D","F","G","H","J", "K","L","M","N","P","Q","R", "S","T","V","W","X","Y","Z"]) answers = [] row = actr.random(3) window = actr.open_exp_window("Sperling Experiment", visible=True) # Show the first 12 letters from the list in the window in # three rows of four and record which ones are in the target # row in the answers variable. for i in range(3): for j in range(4): txt = letters[j + (i * 4)] if i == row: answers.append(txt) actr.add_text_to_exp_window(window, txt, x=(75 + (j * 50)), y=(100 + (i * 50))) # Tell the model to interact with that window actr.install_device(window) # Set the freq variable based on which row is the target if row == 0: freq = 2000 elif row == 1: freq = 1000 else: freq = 500 # Create a tone with frequency freq for .5 seconds # starting at the indicated onset_time actr.new_tone_sound(freq,.5,onset_time) # To simulate the persistent visual memory for the model # we will not clear the display until after a randomly # chosen time between .9 and 1.1 seconds has passed. # This is done by scheduling the clear-exp-window command # to be called after that amount of time has passed. actr.schedule_event_relative(900 + actr.random(200), "clear-exp-window", params=[window],time_in_ms=True) # clear the response variable global responses responses = [] # Add a command for our respond_to_key_press function so that # ACT-R can call it. actr.add_command("sperling-response",respond_to_key_press, "Sperling task key press response monitor") # Monitor the output-key action so that our respond_to_key_press # function is called when a key is pressed. actr.monitor_command("output-key","sperling-response") # Run the model for up to 30 seconds in real time mode. actr.run(30,True) # Stop monitoring the output-key action and remove our command. actr.remove_command_monitor("output-key","sperling-response") actr.remove_command("sperling-response") # If the show_responses variable is True then print out # the correct answers and the responses that were provided if show_responses: print("answers: %s"%answers) print("responses: %s"%responses) # Call the compute_score function to determine the number of # correct responses and return the result. return(compute_score(answers)) # The compute_score function counts how many of the correct answers # were provided by the participant and returns that number. def compute_score(answers): score = 0 for s in responses: if s.upper() in answers: score += 1 return(score) # This function is the one that will be called when the participant # presses a key, and it just records the result in the responses # list unless it is the space bar. def respond_to_key_press (model,key): global responses if not(key.lower() == "space"): responses.append(key) # The report_data function takes a list of the average number of items # reported in the target row ordered by onset delay. It compares those # to the original experiment's data based on correlation and mean deviation # then calls print_results to display the data. def report_data(data): actr.correlation(data,exp_data) actr.mean_deviation(data,exp_data) print_results (data) # The print_results function takes a list of the average target row data # and prints that in a table along with the original experiment's data. def print_results(data): print("Condition Current Participant Original Experiment") for (c,d,o) in zip([0.0,0.15,0.3,1.0],data,exp_data): print(" %4.2f sec. %6.2f %6.2f"%(c,d,o)) # The one_block function runs a trial of the experiment at each # of the experiment's tone onset conditions in a random order. # It returns a list of the correct answer counts in the order # of onset duration (lowest first). def one_block(): result = [] for t in actr.permute_list([0.0,.15,.3,1.0]): result.append((t,trial(t))) result.sort() return (list(map(lambda x: x[1],result))) # The experiment function takes one required parameter which is # the number of blocks to run in the experiment (where each block # is one trial at each of the 4 possible onset times). It collects # the data over blocks, averages the results, and passes that to the # report_data function for display. def experiment(n): results=[0,0,0,0] for i in range(n): results=list(map(lambda x,y: x + y,results,one_block())) report_data(list(map(lambda x: x/n,results)))
6,970
Common Lisp
.l
145
41.013793
92
0.675833
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
31a0bae4d033c9bd6642bb116edb942d87a031859fd90faf308a8aca83e05b59
14,550
[ -1 ]
14,581
WNLexical-readme.txt
asmaloney_ACT-R/extras/WNLexicalModule/WNLexical-readme.txt
#| ACT-R/WN-LEXICAL :: WNLexical module This directory contains the module file "WNLexical_3-0-2.lisp", which can be loaded using the require-extra command in a model file (the recommended method): (require-extra "WNLexicalModule") or it can be placed into the user-loads directory of ACT-R to be loaded automatically. A models folder also contains act-r model examples. In addition, the most recent package "WNLexicalData" must be downloaded and installed by following the instructions in the "WNLexicalData-readme" file. Before loading the module, you must have the following files present: actr7.x/WNLexicalData/WNChunks.data actr7.x/WNLexicalData/WNChunksIndexes.data |# :eof
692
Common Lisp
.l
14
47.571429
93
0.815868
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
f58928880ea711261eefd43e382ca41827471bf3080d91b05d9a875b85d5dc6f
14,581
[ -1 ]
14,583
WNLexicalData-readme.txt
asmaloney_ACT-R/extras/WNLexicalModule/WNLexicalData-readme.txt
#| ACT-R/WN-LEXICAL :: WNLexicalData The folder "WNLexicalData" contains the files that are used by the ACT-R WN-Lexical module. The whole folder and its content must be copied to the "actr7.x/" folder. The files, "WNChunks.data" and "WNChunksIndexes.data" were generated from the Prolog version of WordNet 3.0 ( http://wordnet.princeton.edu/obtain ). The WNLexical data files can be obtained from http://sourceforge.net/projects/actr-wn-lexical/ Before loading the WNLexical module you must have the following files present: actr7.x/WNLexicalData/WNChunks.data actr7.x/WNLexicalData/WNChunksIndexes.data |# :eof
622
Common Lisp
.l
13
46.153846
94
0.806988
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
5adea6f7feddcf1bf6af94ea0be3d267a74177fd616133be54cf5f9d52fcd43a
14,583
[ -1 ]
14,594
blending-read-me.txt
asmaloney_ACT-R/extras/blending/blending-read-me.txt
This document describes a module for ACT-R 7 which implements the blended retrieval mechanism described in: Lebiere, C. (1999). The dynamics of cognitive arithmetic. Kognitionswissenschaft [Journal of the German Cognitive Science Society] Special issue on cognitive modelling and cognitive architectures, D.Wallach & H. A. Simon (eds.)., 8 (1), 5-19. The slides in the included blending.pdf file describe the original ACT-R 4 version of the mechanism. The theory of this module is basically same, but the implementation is different in ACT-R 7. This document and the example blending-test models show the details of the ACT-R 7 implementation. To use the module the easiest thing to do is call (require-extra "blending"), and placing that into any model which needs blending will ensure it's loaded as needed. one can also move the blending.lisp file into the user-loads directory of the ACT-R source file distribution before loading the main ACT-R load file or load the blending.lisp file explicitly after loading the main ACT-R loader (there must not be a model currently defined at the time the file is loaded). Once the module is added to the system it will add another buffer called blending for a model to use. There is no switch needed to activate blending once the module is loaded. There is also a history tool for use with the ACT-R Environment. If the blending module is defined when the Environment starts there will be an additional button in the General Recordable Data section labeled "Blending History". The blending history tool works basically the same as the retrieval history tool which is described in the Environment's manual. The blending module assumes that the default declarative module is also loaded. If that module has been modified or removed from the system then the blending module may not work correctly. ---------------------------------------------------------------- The blending module has several parameters: :blt - the blending trace. If this parameter is set to t then a detailed trace of the blending process will be output in the model's trace. :sblt - save blending trace If this parameter is set to t then the details of the blending trace will be saved while the model runs and can be displayed after by calling print-blending-trace with the time of the blended request for which the trace is desired. [This is now depricated and the history stream described at the end should be used instead to achieve the same results.] :tmp - the temperature. If set to a number this value will be used as the temperature in the chunk probability equation. If it is set to nil then the temperature will be the model's :ans value times the square root of 2. :min-bl - mimimum base-level The minimum base-level activation a chunk in DM must have to be considered in the matching-set. Note that because it is only a test of base-level activation it does not take into account any context effects. It doesn't have any theoretical basis, but may be useful for performance purposes if a model generates a lot of chunks over time and only the recent and/or very strong ones are necessary for blending purposes. :value->mag - a mapping function. If :value->mag is set to a function, then that function will be used to convert all blending slot values into a magnitude to use for blending (see details below). :mag->value - a mapping function. If :mag->value is set to a function, then that function will be used to convert magnitudes back into values when the :value-mag function has returned magnitude values or to adjust the result if the :value-mag function is identity (see details below). :blend-all-slots If :blend-all-slots is nil, which is the default, then the fixed values specified in the request will occur explicitly in the corresponding slots of the resulting chunk. If :blend- all-slots is set to t then all of the slots of the resulting chunk will be determined through the blending process. For this parameter to be useful the declarative partial matching must also be turned on (:mp set to non-nil) otherwise only chunks which match the request explicitly will be considered and there will be nothing to blend for those slots. :blending-request-hook Can be specified as a function to call when there is a blending request. That function should take one parameter which will be the id of a chunk-spec for the request. The return value of the function is ignored. Each setting adds a new function and the "current value" of the parameter is a list of all functions that are set. Setting a value of nil clears all the functions from the hook. :blending-result-hook Can be specified as a function to call when a blending request completes. That function should take one parameter which will be either the chunk saved in the buffer or nil if the request failed or was terminated by a new request. The return value of the function is ignored. Note that since the chunk may not be put into the buffer until some later time this function may not be called at the same time as the request hook function. Each setting adds a new function and the "current value" of the parameter is a list of all functions that are set. Setting a value of nil clears all the functions from the hook. :blending-set-hook Can be specified as a function to call when there is a blending request. That function should take one parameter which will be the list of chunks matched to be blended. The return value of the function is ignored. Each setting adds a new function and the "current value" of the parameter is a list of all functions that are set. Setting a value of nil clears all the functions from the hook. ---------------------------------------------------------------- The blending module only responds to the default queries for state {free, busy, and error}. The module will be busy between the time a request is received and the time that a chunk is placed into the buffer in response to the request or until it signals an error due to failure. If an error is set it will remain set until the next request is received by the module. ---------------------------------------------------------------- The blending buffer takes requests the same way the retrieval buffer does and it will attempt to find a chunk that matches the request among the chunks in the model's declarative memory. It differs in that the chunk returned may have "blended" values in some of its slots. How those blended values are computed is described below. The module can only handle one request at a time. If a new request is received while the module is busy it will cancel the previous request, process the new request and print a warning in the trace. There are two request parameters allowed in a request :ignore-slots and :do-not-generalize. If :ignore-slots is provided it must specify a list of slot names. Those slots will not receive a blended value in the result chunk. This parameter is primarily for efficiency purposes because creating a blended value for a slot can be a costly operation. Thus, if there are slots in the target chunks for which the model will not need a value in the resulting chunk then ignoring those slots may provide a noticable improvement in the time it takes to run the model. If :do-not-generalize is provided it must specify a list of slot names. Any of those slots which will receive a blended value in the resulting chunk will be computed without using blending method b described below. Instead it will use method c for those slots. This may be necessary when one wants to use chunks for the slot contents and doesn't want blending to potentially consider all other chunks as values. ---------------------------------------------------------------- Here is the description of how the resulting chunk to a blending request is created. The request provided is used to find the set of chunks which match the request in the same way that a retrieval request does given the declarative module's current parameter values. That set of chunks does not take into account the activation of those chunks i.e. chunks in that set may have activations below the retrieval threshold. We will call that set of chunks the matching set and use MS to refer to it in the description below. For each chunk i in MS its activation is computed based on the current settings of the declarative module (including noise), which will be called A(i). If the :min-bl parameter is specified for the model then any chunks which have a base-level activation below that value are removed from MS. The activations and the temperature value for the blending module are then used to compute the probability of recall for the chunks in MS using the Boltzmann equation (shown in blending.pdf). The probability of retrieving chunk i from MS will be called p(i). [An important thing to note is that the p(i) values are computed up front based on all the chunks in MS. There is a potential issue with that when the chunks in MS do not all have the same set of slots, which is noted below.] We will determine which slots that chunk will have based on all of the chunks in MS. Every slot which holds a value in some chunk of MS may occur in the resulting chunk. If the :blend-all-slots parameter is nil and the slot has an explicit value in the request then that explicit value will occur in that slot of the resulting chunk. An explicit value is a value requested with an equality test. If a slot is requested with both equality and non-equal tests the explicit value from the equality test will be used. If the :ignore-slots request parameter is provided any slots in that list which do not have an explicit value in the request will not occur in the result. A slot which is in the :ignore-slots list and also has an explicit value in the request will have that explicit value if :blend-all-slots is nil, but will be skippped if :blend-all-slots is t. For all other slots (including those with an explicit value if the :blend-all-slots parameter is t) the following process is performed to determine the value for that slot (referenced by the index k below) in the resulting chunk: A list of potential values is created by taking the value from slot k for each of the chunks in MS which has slot k. Those values will be referred to as: v(k,i) - the value of the slot k in chunk i from MS. For each v(k,i) it calls the value->mag function of the module with v(k,i) as the only parameter. The return value of that function is the magnitude to use for blending and will be referred to as: m(k,i). The default value->mag function is identity and thus v(k,i) = m(k,i) by default. An m(k,i) value of nil is ignored. If all v(k,i) values result in nil magnitudes then the slot k will not occur in the resulting chunk. Based on the set of m(k,i) values one of the following methods is used to create the blended result for slot k, called R(k): a) all the m(k,i) values are numbers: Then R(k) is the sum over all chunks i in MS which have slot k of p(i)*m(k,i). Note that if not all chunks in MS contain slot k that the sum of the p(i) values used to compute this quantity will not be 1.0. This differs from the ACT-R 6.0 version which would have treated those missing slots as a value of "nil" and not averaged them. It would have instead used method c (below) to compute the value. b) all the m(k,i) values are chunks and the slot k is not in the :do-not-generalize list specified with the request It determines a set of potential value chunks based on the slots which the m(k,i) chunks have. That set will be called PV(k). To construct PV(k) consider the set of slots for each chunk i, called s(i). i) If the intersection of all the sets s(i) is non-null then PV(k) is the set of all of the chunks in the model's DM which contain that intersection of slots. ii) If the intersection of all the sets s(i) is null then PV(k) is the set of all the chunks in the model's DM. For each chunk j in PV(k) a value B(j) is computed as the sum over the chunks i in MS of p(i) times the square of the similarity between chunk j and m(k,i). R(k) is then the chunk j for which the B(j) value is minimum. c) the m(k,i) values are neither all numbers nor all chunks, or the slot k is in the :do-not-generalize list specified in the request A set of potential values, PV(k), is created which contains all of the unique (tested with equalp) m(k,i) values. If there is only one unique item in PV(k) then that value is R(k) with no further computation. Otherwise, for each item j in PV(k) a value B(j) is computed as the sum over the chunks i in MS of p(i) times the square of the similarity between j and m(k,i). Note: Since the items in PV(k) may not be chunks this assumes that there is a similarity function set for the declarative module which will compute similarities between non-chunk items otherwise all non-equal non-chunk items will have the maximum dissimilarity value. R(k) is then the value j for which the B(j) value is minimum. If there is no mag->value function specified or the value->mag function returned values such that m(k,i) = v(k,i) for all i then the value for the slot k will be the value R(k). If there is a mag->value function and either there exists an i such that m(k,i) != v(k,i) or the value->mag function is the default function identity then the value for the slot k will be the result of calling the mag->value function with two parameters. The first will be the value R(k). The second value will be the chunk-spec of the request which was made to the module. ---------------------------------------------------------------- After all slots of the resulting chunk have been computed the module determines whether or not the chunk can be successfully created by blending. To determine that, a match score, M, is computed as the log of the sum over the chunks i in MS of e to the power A(i). If M is greater than or equal to the retrieval threshold of the declarative module then the created chunk is placed into the blending buffer with a latency computed in the same way the declarative module computes retrieval latency using M as the activation of the chunk. If M is below the retrieval threshold then the module will fail to produce the chunk and an error will be signaled after a latency based on the retrieval threshold passes. ------------------------------------------------------------------ The blending module has a history stream named blending-trace which can be recorded to save all of the details of the blending requests which are made. If that stream is recorded then the print-blending- trace command can be called with the time of a request (in seconds unless the optional second parameter is true in which case it should be in milliseconds) to print the blending trace of the request at that time to the command trace. One can also use that history information directly if desired. It's format is a list of key value pairs which are sufficient to rebuild the trace output (while the details of that data are not provided here the keys should be fairly descriptive enough to figure it out). There are also two history processors for that history stream called blending-times, which returns only the list of times at which a blending request was made, and blending-environment-history, which includes a string containing the blended trace and strings of the chunks which were blended.
15,611
Common Lisp
.l
269
56.122677
85
0.770878
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
7c60bf2342d6a4faab7457dd7a7fe260cd51ffe379745ab74d6393dd072461f5
14,594
[ -1 ]
14,605
default-activation.txt
asmaloney_ACT-R/extras/adaptive-noise/example-data/default-activation.txt
-2.3861763 -1.8998168 -1.6305171 -1.45761 -1.3135244 -1.2095046 -1.1057488 -1.024914 -0.9488659 -0.8817001 -0.83555585 -0.7928741 -0.72860175 -0.7057436 -0.6628125 -0.63401324 -0.5960824 -0.5609349 -0.5287495 -0.48974237 -0.4769877 -0.44040513 -0.42719898 -0.39772093 -0.37000063 -0.35363412 -0.33690968 -0.31837842 -0.29178917 -0.2785998 -0.25538635 -0.2398887 -0.22089231 -0.2110636 -0.18959059 -0.17702658 -0.15725009 -0.15181588 -0.13195577 -0.11416793 -0.09887758 -0.08538564 -0.079657026 -0.075296134 -0.04747063 -0.04477336 -0.040929448 -0.023238953 3.6430164e-4 -0.0041929763 0.0038185741 0.017654726 0.040224824 0.050828032 0.056542072 0.06742722 0.072670706 0.082207724 0.09143316 0.10454984 0.11493955 0.11610774 0.12400988 0.12389053 0.14378878 0.14011677 0.1463419 0.15691714 0.170557 0.18797114 0.19246204 0.19669172 0.2030041 0.202904 0.22186276 0.22503455 0.22864802 0.23115554 0.24683776 0.25226486 0.26033533 0.26452845 0.27014005 0.28018615 0.28171098 0.2981468 0.28882694 0.30701888 0.30676824 0.3114463 0.3202014 0.32421473 0.33135828 0.33859313 0.34170282 0.34798542 0.34780657 0.36821234 0.36946377 0.3660754 0.37684444 0.38305727 0.38291165 0.38789675 0.39048097 0.40505475 0.40403754 0.40994102 0.41980729 0.41469467 0.43232846 0.4305377 0.4340877 0.43380752 0.4528401 0.4450687 0.44817743 0.4555385 0.45857173 0.46105078 0.47491318 0.4686211 0.48208302 0.492181 0.48955807 0.48003846 0.50505793 0.4954895 0.5016919 0.5079565 0.510425 0.5080039 0.5227546 0.52523196 0.5282529 0.53096336 0.52672386 0.5397137 0.5418678 0.54046595 0.5432125 0.5471551 0.55389756 0.55780995 0.55532974 0.55786765 0.5689361 0.5818221 0.573637 0.58194757 0.57778585 0.5914501 0.5813797 0.59918 0.60172296 0.59483284 0.604513 0.59531873 0.60307163 0.6183808 0.61254835 0.61973876 0.61653435 0.62814313 0.6326055 0.6367635 0.63261163 0.641923 0.65052634 0.64507085 0.6498854 0.6525686 0.65203863 0.65090144 0.6573867 0.6601013 0.6683811 0.6702444 0.6653151 0.66972 0.67209834 0.68440306 0.6764487 0.68827623 0.70155245 0.6891114 0.6928011 0.6964728 0.7059491 0.7030888 0.6969934 0.70976985 0.71503294 0.72096676 0.7207662 0.71660984 0.725148 0.720956 0.7318715 0.7270545 0.73192966 0.7297152 0.7414668 0.73956996 0.7439978 0.74719155 0.74618536 0.7554284 0.7497786 0.75873333 0.7657843 0.7730594 0.7670996 0.7552844 0.7669886 0.7679439 0.76842785 0.77127224 0.78233 0.7749797 0.7843 0.7773629 0.78430897 0.79253036 0.79326993 0.78465515 0.78694344 0.80578613 0.79893637 0.8008308 0.808098 0.8039239 0.80747336 0.8107358 0.81370443 0.8117094 0.81783175 0.8217449 0.8248109 0.8255907 0.8263586 0.81728286 0.8310972 0.83387136 0.83789676 0.84075755 0.84284335 0.8404627 0.85152596 0.837783 0.842287 0.8557876 0.84334385 0.8528042 0.8586836 0.8586305 0.85939324 0.86382246 0.8604121 0.8637746 0.86073506 0.8644085 0.8771069 0.87987256 0.87797207 0.87583655 0.88017225 0.8860561 0.8907625 0.87930214 0.873926 0.89109075 0.88048464 0.898035 0.88759923 0.89619356 0.8941126 0.89251053 0.9024671 0.9142511 0.90233254 0.9029293 0.9132342 0.9222796 0.90611476 0.91426903 0.9210072 0.9253034 0.9259758 0.9167579 0.91742444 0.92251503 0.92006844 0.9356743 0.931039 0.9341388 0.9423539 0.94123787 0.93380517 0.9403191
3,205
Common Lisp
.l
300
9.686667
13
0.87956
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
da220534262bdf9336b20e6732d3d6f2d5a85a7b19faf471c12894d930bf5253
14,605
[ -1 ]
14,606
default-latency.txt
asmaloney_ACT-R/extras/adaptive-noise/example-data/default-latency.txt
0.0,3,,0.0,1 0.41457593,2,,0.012278588,2 0.82915187,1,,0.024557175,1 1.2437278,7,,0.036835764,3 1.6583037,11,,0.04911435,2 2.0728798,18,,0.061392937,5 2.4874556,35,,0.07367153,9 2.9020314,24,,0.085950114,22 3.3166075,48,,0.0982287,19 3.7311835,49,,0.11050729,34 4.1457596,67,,0.12278587,34 4.560335,81,,0.13506447,50 4.974911,98,,0.14734305,54 5.3894873,93,,0.15962164,65 5.804063,129,,0.17190023,88 6.218639,159,,0.18417881,82 6.633215,175,,0.1964574,98 7.047791,170,,0.20873599,128 7.462367,194,,0.22101457,139 7.8769426,234,,0.23329316,138 8.291519,214,,0.24557175,131 8.706095,202,,0.25785035,144 9.12067,213,,0.27012894,160 9.535247,226,,0.28240752,162 9.949822,217,,0.2946861,185 10.364398,201,,0.3069647,174 10.778975,189,,0.31924328,181 11.19355,189,,0.33152187,148 11.608126,175,,0.34380046,179 12.022702,172,,0.35607904,166 12.437278,146,,0.36835763,168 12.851854,121,,0.38063622,156 13.26643,139,,0.3929148,177 13.6810055,116,,0.4051934,143 14.095582,99,,0.41747198,133 14.510158,98,,0.42975056,142 14.924734,82,,0.44202915,137 15.33931,67,,0.45430773,119 15.753885,56,,0.46658632,122 16.16846,56,,0.4788649,103 16.583038,46,,0.4911435,100 16.997614,49,,0.5034221,85 17.41219,39,,0.5157007,90 17.826765,35,,0.52797925,71 18.24134,38,,0.5402579,66 18.655916,33,,0.5525364,66 19.070494,21,,0.56481504,77 19.48507,21,,0.5770936,41 19.899645,12,,0.5893722,42 20.31422,14,,0.6016508,30 20.728796,16,,0.6139294,35 21.143373,6,,0.62620795,20 21.55795,11,,0.63848656,35 21.972525,10,,0.6507651,22 22.3871,12,,0.66304374,18 22.801676,5,,0.6753223,19 23.216251,5,,0.6876009,9 23.630829,2,,0.69987947,16 24.045404,4,,0.7121581,18 24.45998,6,,0.72443664,11 24.874556,4,,0.73671526,11 25.289131,5,,0.7489938,13 25.703709,5,,0.76127243,13 26.118284,3,,0.773551,11 26.53286,0,,0.7858296,9 26.947435,5,,0.7981082,9 27.362011,3,,0.8103868,5 27.776588,4,,0.8226654,3 28.191164,1,,0.83494395,6 28.60574,3,,0.84722257,5 29.020315,0,,0.8595011,6 29.43489,0,,0.87177974,2 29.849468,0,,0.8840583,5 30.264044,0,,0.8963369,2 30.67862,0,,0.90861547,2 31.093195,0,,0.9208941,2 31.50777,0,,0.93317264,2 31.922346,0,,0.94545126,3 32.33692,0,,0.9577298,1 32.7515,1,,0.97000843,3 33.166077,1,,0.982287,1 33.58065,0,,0.9945656,0 33.995228,0,,1.0068442,0 34.4098,1,,1.0191227,1 34.82438,0,,1.0314014,1 35.238953,0,,1.04368,2 35.65353,0,,1.0559585,1 36.068108,0,,1.0682371,1 36.48268,0,,1.0805157,0 36.89726,1,,1.0927943,1 37.311832,0,,1.1050729,1 37.72641,0,,1.1173514,1 38.140987,0,,1.1296301,0 38.55556,0,,1.1419086,0 38.97014,0,,1.1541872,0 39.384712,0,,1.1664658,0 39.79929,0,,1.1787444,0 40.213867,1,,1.191023,0 40.62844,0,,1.2033015,0 41.04302,0,,1.2155802,1 41.457592,1,,1.2278588,1
2,668
Common Lisp
.l
101
25.415842
29
0.763927
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
b3c29bf3ce9193acfd9ffc7996acf3bb0a94f699155459a73263fd854da5012f
14,606
[ -1 ]
14,607
reinforce-uan-latency.txt
asmaloney_ACT-R/extras/adaptive-noise/example-data/reinforce-uan-latency.txt
0.0,2,,0.0,2 0.026696568,2,,0.0020919263,0 0.053393137,3,,0.0041838526,2 0.0800897,6,,0.0062757786,0 0.10678627,6,,0.008367705,0 0.13348284,9,,0.010459632,0 0.1601794,22,,0.012551557,0 0.18687598,19,,0.014643484,1 0.21357255,26,,0.01673541,0 0.24026911,32,,0.018827336,1 0.2669657,42,,0.020919263,2 0.29366225,52,,0.023011189,4 0.3203588,58,,0.025103115,6 0.34705538,83,,0.027195042,5 0.37375197,85,,0.029286968,1 0.40044853,109,,0.031378895,4 0.4271451,114,,0.03347082,6 0.45384166,138,,0.035562746,2 0.48053822,150,,0.03765467,1 0.5072348,166,,0.0397466,4 0.5339314,196,,0.041838527,5 0.56062794,183,,0.043930452,8 0.5873245,193,,0.046022378,5 0.61402106,192,,0.048114303,2 0.6407176,234,,0.05020623,6 0.6674142,209,,0.05229816,7 0.69411075,200,,0.054390084,4 0.7208074,188,,0.05648201,9 0.74750394,188,,0.058573935,11 0.7742005,181,,0.06066586,7 0.80089706,193,,0.06275779,13 0.8275936,161,,0.06484971,9 0.8542902,155,,0.06694164,8 0.88098675,154,,0.06903357,16 0.9076833,146,,0.07112549,11 0.9343799,118,,0.07321742,18 0.96107644,121,,0.07530934,15 0.987773,86,,0.07740127,16 1.0144696,93,,0.0794932,14 1.0411662,97,,0.081585124,14 1.0678627,75,,0.08367705,15 1.0945593,73,,0.085768975,25 1.1212559,61,,0.087860905,29 1.1479524,41,,0.089952834,24 1.174649,45,,0.092044756,21 1.2013456,44,,0.094136685,39 1.2280421,31,,0.09622861,39 1.2547387,25,,0.09832054,49 1.2814353,25,,0.10041246,44 1.3081318,16,,0.10250439,47 1.3348284,20,,0.10459632,64 1.3615249,16,,0.10668824,75 1.3882215,18,,0.10878017,68 1.4149181,12,,0.11087209,77 1.4416147,7,,0.11296402,78 1.4683113,8,,0.11505595,98 1.4950079,9,,0.11714787,87 1.5217044,9,,0.1192398,100 1.548401,10,,0.12133172,125 1.5750976,3,,0.12342365,123 1.6017941,6,,0.12551558,126 1.6284907,4,,0.12760751,148 1.6551872,3,,0.12969942,125 1.6818838,3,,0.13179135,163 1.7085804,0,,0.13388328,164 1.7352769,6,,0.13597521,176 1.7619735,2,,0.13806714,180 1.7886701,2,,0.14015906,168 1.8153666,1,,0.14225098,184 1.8420632,1,,0.14434291,163 1.8687598,2,,0.14643484,156 1.8954563,1,,0.14852677,162 1.9221529,2,,0.15061869,159 1.9488494,1,,0.15271062,166 1.975546,1,,0.15480255,154 2.0022426,0,,0.15689448,144 2.0289392,0,,0.1589864,132 2.0556357,2,,0.16107832,127 2.0823324,0,,0.16317025,110 2.1090288,0,,0.16526218,86 2.1357255,0,,0.1673541,78 2.162422,0,,0.16944604,75 2.1891186,0,,0.17153795,77 2.215815,1,,0.17362988,60 2.2425117,0,,0.17572181,46 2.2692082,0,,0.17781374,33 2.2959049,0,,0.17990567,36 2.3226016,0,,0.18199758,32 2.349298,0,,0.18408951,22 2.3759947,1,,0.18618144,23 2.4026911,0,,0.18827337,16 2.4293878,0,,0.1903653,10 2.4560843,0,,0.19245721,7 2.482781,0,,0.19454914,9 2.5094774,0,,0.19664107,7 2.536174,0,,0.198733,4 2.5628705,0,,0.20082492,1 2.5895672,0,,0.20291685,0 2.6162636,0,,0.20500877,3 2.6429603,0,,0.2071007,1 2.6696568,1,,0.20919263,1
2,801
Common Lisp
.l
101
26.732673
30
0.775556
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
cf0e8cef75a9bf5bfd694f35e8cb8cdf9552cd2bba9155b92dd9ceb695f6fccf
14,607
[ -1 ]
14,608
uan-latency.txt
asmaloney_ACT-R/extras/adaptive-noise/example-data/uan-latency.txt
0.0,1,,0.0,1 0.02850886,5,,0.003426439,0 0.05701772,2,,0.006852878,0 0.085526586,10,,0.010279316,0 0.11403544,7,,0.013705756,2 0.1425443,9,,0.017132195,0 0.17105317,18,,0.020558633,0 0.19956203,27,,0.023985073,1 0.22807088,41,,0.027411511,0 0.25657976,43,,0.03083795,1 0.2850886,44,,0.03426439,0 0.31359747,81,,0.03769083,0 0.34210634,92,,0.041117266,2 0.37061518,104,,0.044543706,1 0.39912406,118,,0.047970146,0 0.4276329,127,,0.051396582,0 0.45614177,163,,0.054823022,2 0.48465064,141,,0.058249462,2 0.5131595,174,,0.0616759,0 0.54166836,166,,0.06510234,1 0.5701772,214,,0.06852878,1 0.5986861,199,,0.07195522,3 0.62719494,227,,0.07538166,2 0.6557038,209,,0.07880809,3 0.6842127,228,,0.08223453,3 0.7127215,219,,0.08566097,4 0.74123037,180,,0.08908741,5 0.7697392,198,,0.09251385,3 0.7982481,225,,0.09594029,10 0.82675695,179,,0.099366724,9 0.8552658,150,,0.102793165,3 0.8837747,168,,0.106219605,3 0.91228354,132,,0.109646045,7 0.9407924,131,,0.113072485,13 0.9693013,108,,0.116498925,12 0.9978101,117,,0.119925365,15 1.026319,99,,0.1233518,18 1.0548278,81,,0.12677824,14 1.0833367,86,,0.13020468,23 1.1118456,58,,0.13363111,13 1.1403544,53,,0.13705756,24 1.1688633,52,,0.14048399,24 1.1973722,45,,0.14391044,33 1.225881,33,,0.14733687,41 1.2543899,30,,0.15076332,42 1.2828988,37,,0.15418975,28 1.3114076,26,,0.15761618,46 1.3399165,31,,0.16104263,40 1.3684254,12,,0.16446906,43 1.3969342,4,,0.16789551,50 1.425443,16,,0.17132194,55 1.4539518,11,,0.17474839,54 1.4824607,11,,0.17817482,74 1.5109696,8,,0.18160126,66 1.5394784,6,,0.1850277,69 1.5679873,5,,0.18845414,87 1.5964962,6,,0.19188058,92 1.625005,4,,0.19530702,106 1.6535139,5,,0.19873345,123 1.6820228,3,,0.2021599,132 1.7105316,3,,0.20558633,118 1.7390405,1,,0.20901278,124 1.7675494,2,,0.21243921,166 1.7960582,5,,0.21586566,170 1.8245671,0,,0.21929209,175 1.853076,2,,0.22271852,160 1.8815848,2,,0.22614497,146 1.9100937,1,,0.2295714,154 1.9386026,1,,0.23299785,147 1.9671113,0,,0.23642428,181 1.9956203,1,,0.23985073,183 2.0241292,1,,0.24327716,185 2.052638,0,,0.2467036,177 2.0811467,0,,0.25013003,169 2.1096556,0,,0.2535565,159 2.1381645,0,,0.25698292,159 2.1666734,0,,0.26040936,135 2.1951823,1,,0.2638358,129 2.2236912,0,,0.26726222,111 2.2522,0,,0.27068868,86 2.2807088,0,,0.27411512,96 2.3092177,0,,0.27754155,64 2.3377266,0,,0.28096798,59 2.3662355,0,,0.28439444,67 2.3947444,0,,0.28782088,52 2.423253,0,,0.2912473,53 2.451762,0,,0.29467374,32 2.4802709,0,,0.29810017,33 2.5087798,0,,0.30152664,23 2.5372887,0,,0.30495307,19 2.5657976,0,,0.3083795,20 2.5943062,0,,0.31180593,12 2.6228151,0,,0.31523237,4 2.651324,0,,0.31865883,8 2.679833,0,,0.32208526,7 2.7083418,0,,0.3255117,2 2.7368507,0,,0.32893813,4 2.7653594,0,,0.33236456,2 2.7938683,0,,0.33579102,0 2.8223772,0,,0.33921745,1 2.850886,1,,0.3426439,2
2,780
Common Lisp
.l
101
26.524752
29
0.773796
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
98e6347bbe8f3b9cf1404bfe8fe953a76abebbd2117fdcacc8734fe1a14a255b
14,608
[ -1 ]
14,609
reinforce-latency.txt
asmaloney_ACT-R/extras/adaptive-noise/example-data/reinforce-latency.txt
0.0,2,,0.0,4 0.4188886,2,,0.016614527,6 0.8377772,5,,0.033229053,4 1.2566658,8,,0.04984358,25 1.6755544,11,,0.066458106,49 2.094443,19,,0.08307263,62 2.5133317,33,,0.09968716,81 2.9322202,39,,0.116301686,111 3.3511088,55,,0.13291621,155 3.7699974,54,,0.14953074,207 4.188886,67,,0.16614527,215 4.6077747,91,,0.18275979,235 5.0266633,112,,0.19937432,288 5.445552,137,,0.21598884,286 5.8644404,134,,0.23260337,292 6.283329,140,,0.2492179,318 6.7022176,173,,0.26583242,311 7.121106,185,,0.28244695,305 7.5399947,210,,0.29906148,271 7.9588833,211,,0.315676,239 8.377772,216,,0.33229053,212 8.79666,216,,0.34890506,196 9.215549,206,,0.36551958,154 9.634438,212,,0.3821341,160 10.053327,209,,0.39874864,147 10.472215,207,,0.41536316,111 10.891104,227,,0.4319777,87 11.309992,213,,0.44859222,81 11.728881,174,,0.46520674,58 12.147769,138,,0.48182127,52 12.566658,138,,0.4984358,51 12.985546,156,,0.5150503,46 13.404435,108,,0.53166485,26 13.823324,94,,0.5482794,21 14.242212,107,,0.5648939,20 14.661101,79,,0.5815084,15 15.079989,82,,0.59812295,12 15.4988785,72,,0.6147375,11 15.917767,58,,0.631352,17 16.336655,47,,0.6479665,8 16.755545,38,,0.66458106,7 17.174433,44,,0.6811956,11 17.59332,42,,0.6978101,4 18.012209,30,,0.7144246,3 18.431099,29,,0.73103917,6 18.849987,23,,0.7476537,4 19.268875,23,,0.7642682,1 19.687763,12,,0.7808827,3 20.106653,15,,0.7974973,2 20.525541,17,,0.8141118,1 20.94443,10,,0.8307263,0 21.36332,9,,0.8473408,2 21.782207,7,,0.8639554,0 22.201096,0,,0.88056993,1 22.619984,8,,0.89718443,2 23.038874,3,,0.9137989,1 23.457762,5,,0.9304135,0 23.87665,6,,0.94702804,0 24.295538,7,,0.96364254,0 24.714428,1,,0.98025703,0 25.133316,2,,0.9968716,0 25.552204,4,,1.0134861,1 25.971092,3,,1.0301006,0 26.389982,1,,1.0467151,0 26.80887,1,,1.0633297,0 27.227758,0,,1.0799443,0 27.646648,0,,1.0965588,0 28.065536,0,,1.1131732,0 28.484425,0,,1.1297878,1 28.903313,1,,1.1464024,0 29.322203,0,,1.1630168,0 29.74109,2,,1.1796314,0 30.159979,0,,1.1962459,0 30.578867,0,,1.2128605,0 30.997757,1,,1.229475,0 31.416645,1,,1.2460895,0 31.835533,1,,1.262704,0 32.25442,1,,1.2793186,0 32.67331,1,,1.295933,0 33.092197,0,,1.3125476,0 33.51109,1,,1.3291621,0 33.929977,0,,1.3457767,0 34.348866,0,,1.3623912,0 34.767754,0,,1.3790057,0 35.18664,1,,1.3956202,0 35.60553,2,,1.4122348,0 36.024418,0,,1.4288492,0 36.44331,0,,1.4454638,0 36.862198,0,,1.4620783,0 37.281086,0,,1.4786929,0 37.699974,0,,1.4953074,0 38.118862,0,,1.5119219,0 38.53775,0,,1.5285364,0 38.95664,0,,1.545151,0 39.375526,0,,1.5617654,0 39.79442,0,,1.57838,0 40.213306,0,,1.5949945,0 40.632195,0,,1.6116091,0 41.051083,0,,1.6282237,0 41.46997,0,,1.6448381,0 41.88886,1,,1.6614527,1
2,642
Common Lisp
.l
101
25.158416
29
0.761511
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
c3ccb10d56e4f3a02a612bbdee38825364ac9a673d8c1a2057f71adcd76407b6
14,609
[ -1 ]
14,610
default-choice.txt
asmaloney_ACT-R/extras/adaptive-noise/example-data/default-choice.txt
0.5984 0.5946 0.5874 0.6004 0.5938 0.5848 0.586 0.5976 0.5912 0.5888 0.5962 0.5938 0.5948 0.59 0.585 0.5924 0.593 0.595 0.589 0.5934 0.599 0.5926 0.5942 0.596 0.608 0.5926 0.5982 0.6 0.5946 0.5874 0.5958 0.606 0.5936 0.584 0.5994 0.607 0.592 0.5856 0.5936 0.5942 0.601 0.5912 0.586 0.5892 0.5844 0.6034 0.6062 0.5844 0.5896 0.5854 0.5956 0.5988 0.5854 0.5858 0.5836 0.5954 0.5822 0.5866 0.5858 0.6044 0.5966 0.5836 0.588 0.5838 0.5916 0.5954 0.5884 0.5946 0.5974 0.5924 0.5922 0.6002 0.5836 0.5912 0.5912 0.5984 0.5946 0.5902 0.5936 0.598 0.5974 0.5804 0.5888 0.591 0.6012 0.6064 0.5926 0.5974 0.5998 0.592 0.5992 0.6002 0.6054 0.5964 0.5858 0.587 0.591 0.5966 0.5848 0.5904 0.6066 0.6 0.6032 0.5892 0.5976 0.5954 0.6084 0.5878 0.6004 0.6106 0.602 0.5926 0.598 0.6046 0.5988 0.59 0.6002 0.5962 0.5928 0.5994 0.5972 0.6014 0.5946 0.589 0.5832 0.5898 0.605 0.6028 0.5916 0.5954 0.6018 0.5862 0.5916 0.5892 0.5938 0.5982 0.5936 0.5962 0.5798 0.5812 0.592 0.597 0.582 0.5958 0.6034 0.5874 0.5916 0.5922 0.6002 0.5926 0.5968 0.5938 0.588 0.5938 0.5888 0.597 0.593 0.5972 0.5992 0.5924 0.596 0.593 0.601 0.5964 0.6026 0.598 0.5894 0.602 0.6064 0.5902 0.5942 0.5952 0.5962 0.598 0.602 0.5902 0.59 0.5852 0.5968 0.5972 0.592 0.599 0.5998 0.585 0.596 0.601 0.5956 0.5932 0.5966 0.5956 0.5884 0.5924 0.5904 0.592 0.6016 0.5962 0.6012 0.5988 0.5978 0.5866 0.606 0.5964 0.5762 0.6006 0.5978 0.5926 0.5916 0.604 0.5796 0.6108 0.597 0.5954 0.5862 0.587 0.5856 0.6016 0.5938 0.5928 0.5996 0.6 0.5926 0.5946 0.5934 0.6042 0.5892 0.592 0.5848 0.6004 0.6028 0.5964 0.5872 0.5972 0.5908 0.5954 0.5858 0.5882 0.6004 0.5992 0.604 0.606 0.5898 0.594 0.593 0.6032 0.5892 0.5874 0.5974 0.5916 0.5926 0.606 0.5956 0.5944 0.588 0.5908 0.5974 0.5888 0.5966 0.5856 0.5916 0.6036 0.5968 0.5882 0.5996 0.6 0.609 0.598 0.5872 0.5936 0.5882 0.5928 0.593 0.584 0.607 0.5874 0.5946 0.5932 0.5944 0.577 0.5846 0.6012 0.5876 0.5854 0.5872 0.596 0.577 0.6036 0.6006 0.587 0.5954 0.581 0.5976 0.5902 0.584 0.6058 0.5992 0.6126 0.5932 0.593 0.595 0.5962
2,014
Common Lisp
.l
300
5.716667
6
0.825073
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
c115afe4fd748d0d8c42d3ed358bdb6b30bdf4c685adbe884a197dd0050592ab
14,610
[ -1 ]
14,620
release.yaml
asmaloney_ACT-R/.github/workflows/release.yaml
name: Release ACT-R Slim on: release: types: [created, edited] jobs: slim: name: Release ACT-R Slim runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Slim Archive # "slim" removes examples, tutorials, and extras run: zip -r actr-slim-${{ github.event.release.tag_name }}.zip . -x \*.git\* \*.DS_Store \*.zip examples/\* extras/\* other-files/\* tutorial/\* - name: Slim (no env) Archive # "super slim" also removes the docs and (most of) the environment run: zip -r actr-super-slim-${{ github.event.release.tag_name }}.zip . -x \*.git\* \*.DS_Store \*.zip docs/\* environment/\*.exe environment/GUI/\* environment/alternate-\* environment/run-\* environment/start\* examples/\* extras/\* other-files/\* tutorial/\* - name: Release uses: softprops/action-gh-release@v1 if: startsWith(github.ref, 'refs/tags/') with: files: | actr-slim-${{ github.event.release.tag_name }}.zip actr-super-slim-${{ github.event.release.tag_name }}.zip
1,083
Common Lisp
.l
23
40.217391
268
0.623229
asmaloney/ACT-R
6
0
0
LGPL-2.1
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
3f834cf425c9078db8bf5acf599f8e902388284537b3d3ec5b89872b10e8778c
14,620
[ -1 ]
14,663
boot.lisp
rudolfochrist_cl-manager/templates/boot.lisp
;;; boot.lisp ;;; This Source Code Form is subject to the terms of the Mozilla Public ;;; License, v. 2.0. If a copy of the MPL was not distributed with this ;;; file, You can obtain one at http://mozilla.org/MPL/2.0/. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; !!! WARNING !!! ;;; ;;; ;;; ;;; Don't touch anything below unless you know what you're doing. ;;; ;;; ;;; ;;; Load this file to load dependencies installed with cl-manager without ;;; ;;; loading cl-manager itself. ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (require 'asdf) #+sbcl (require 'sb-aclrepl) (defun current-directory-search (name) "Search the current directory for system NAME." (probe-file (make-pathname :defaults (uiop:getcwd) :name (asdf:primary-system-name name) :type "asd"))) (defun dot-clm-directory-search (name) "Search .clm directory for system NAME." (find-if (lambda (p) (and (string= (asdf:primary-system-name name) (pathname-name p)) (string= "asd" (pathname-type p)))) (uiop:directory-files (merge-pathnames ".clm/" (uiop:getcwd)) "**/*.asd"))) (setf asdf:*system-definition-search-functions* (nconc asdf:*system-definition-search-functions* (list 'current-directory-search 'dot-clm-directory-search)))
1,746
Common Lisp
.lisp
29
54.551724
86
0.457578
rudolfochrist/cl-manager
6
0
4
MPL-2.0
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
6da5fed968b1271a72bcc2882e1f63e904a3ff5e1685fc295c01c1b1cab9ffb1
14,663
[ -1 ]
14,664
cl-manager.asd
rudolfochrist_cl-manager/cl-manager.asd
;;; cl-manager.asd ;;; This Source Code Form is subject to the terms of the Mozilla Public ;;; License, v. 2.0. If a copy of the MPL was not distributed with this ;;; file, You can obtain one at http://mozilla.org/MPL/2.0/. (defsystem "cl-manager" :author "Sebastian Christ <[email protected]>" :maintainer "Sebastian Christ <[email protected]>" :mailto "[email protected]" :license "MPL-2.0" :homepage "https://github.com/rudolfochrist/cl-manager" :bug-tracker "https://github.com/rudolfochrist/cl-manager/issues" :source-control (:git "https://github.com/rudolfochrist/cl-manager.git") :version (:read-file-line "version") :depends-on ((:require "asdf") (:require "uiop")) :components ((:file "manager") (:static-file "templates/boot.lisp")) :description "A Common Lisp Package/System/Project/Library Manager" :long-description #.(uiop:read-file-string (uiop:subpathname *load-pathname* "README.txt")) :perform (load-op :before (c o) (when (= 0 (length (uiop:run-program "command -v git" :output '(:string :stripped t) :ignore-error-status t))) (error "Please install `git'. Refer to https://git-scm.com/ for details.")) (when (= 0 (length (uiop:run-program "command -v curl" :output '(:string :stripped t) :ignore-error-status t))) (error "Please install `curl'. Refer to your system's package manager."))) :perform (load-op :after (c o) (uiop:symbol-call :cl-manager :update-index) (uiop:symbol-call :cl-manager :register-search-functions) (pushnew :clm *features*) (pushnew :cl-manager *features*)))
1,974
Common Lisp
.asd
35
42.257143
97
0.563533
rudolfochrist/cl-manager
6
0
4
MPL-2.0
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
8c3c9f40d04841643bc3fe9e2497f3186db39bacdc4d8ea526a98f1684486783
14,664
[ -1 ]
14,668
org-export.el
rudolfochrist_cl-manager/doc/org-export.el
;;; org-export.el --- Org texinfo customizations ;;; Commentary: ;; Stuff to make org and texinfo work better together. ;; This Source Code Form is subject to the terms of the Mozilla Public ;; License, v. 2.0. If a copy of the MPL was not distributed with this ;; file, You can obtain one at http://mozilla.org/MPL/2.0/. ;;; Code: (require 'cl-lib) (require 'ox) (require 'ox-md) (require 'ox-texinfo) (require 'ox-latex) (require 'ox-koma-letter nil t) (setq org-export-allow-bind-keywords t ; allows the use og #+BIND in org files org-export-date-timestamp-format "%Y-%m-%d" org-footnote-auto-label t ; generate numbered footnotes like [fn:1] ) ;;;; TEXINFO ;;; ;;; use strike-through to markup vars in texinfo (add-to-list 'org-texinfo-text-markup-alist '(strike-through . "@var{%s}")) (defun org-texinfo-ref-open (path) "Open the reference. PATH is the reference headline." (let ((headline (org-find-exact-headline-in-buffer path (current-buffer) t))) (if headline (goto-char headline) ;; try to find anchor (let ((anchor (save-excursion (save-restriction (widen) (goto-char (point-min)) (search-forward (format "@anchor{%s}" path) nil t) (when (match-string 0) (point)))))) (when anchor (goto-char anchor)))))) (defun org-texinfo-reference-export (ref-type path description backend) "Format the texinfo reference. Argument REF-TYPE The reference type. Argument PATH Path to reference. Argument DESCRIPTION Reference Description. Argument BACKEND Org export backend." (when (eql backend 'texinfo) (format "@%s{%s}" ref-type (if description (format "%s,,%s" path description) path)))) (defun org-texinfo-xref-export (path desc backend) "Export xref with PATH DESC for BACKEND." (org-texinfo-reference-export "xref" path desc backend)) (org-link-set-parameters "texixref" :follow 'org-texinfo-ref-open :export 'org-texinfo-xref-export) (defun org-texinfo-ref-export (path desc backend) "Export ref with PATH DESC for BACKEND." (org-texinfo-reference-export "ref" path desc backend)) (org-link-set-parameters "texiref" :follow 'org-texinfo-ref-open :export 'org-texinfo-ref-export) (defun org-texinfo-pxref-export (path desc backend) "Export pxref with PATH DESC for BACKEND." (org-texinfo-reference-export "pxref" path desc backend)) (org-link-set-parameters "texipxref" :follow 'org-texinfo-ref-open :export 'org-texinfo-pxref-export) ;;;; LATEX ;;; ;;; extend latex "log" files (setq org-latex-logfiles-extensions '("aux" "bcf" "blg" "fdb_latexmk" "fls" "figlist" "glg" "glo" "gls" "idx" "ist" "log" "nav" "out" "ptc" "run.xml" "snm" "toc" "vrb" "xdv" "bbl" "ilg" "ind" "lof" "lot" "lol" "xwm")) ;;; misc. (defun toggle-org-latex-hyperref-colorlinks (&optional force-colorlinks) "Toggel colorlinks=true in LaTeX hyperref setup. This is great for printing the document in grayscale. With prefix argumnet or if FORCE-COLORLINKS is non-nil set hypersetup to include colorlinks=true." (interactive "P") (let ((prefix "\\hypersetup{\n pdftitle={%t},\n pdfcreator={%c}, \n pdflang={%L},\n colorlinks=") (suffix "}\n") (colorlinksp (string-match "colorlinks=true" org-latex-hyperref-template))) (setq org-latex-hyperref-template (concat prefix (if (or force-colorlinks (not colorlinksp)) "true" "false") suffix)))) ;;; latex settings (setq org-latex-prefer-user-labels t org-latex-hyperref-template (toggle-org-latex-hyperref-colorlinks t) org-latex-compiler "xelatex" org-latex-pdf-process '("%latex -interaction nonstopmode %f" "%bib %b" "makeindex %b" "PATH=\"/usr/bin:$PATH\" makeglossaries %b" ; use system perl for makeglossaries "%latex -interaction nonstopmode %f" "%latex -interaction nonstopmode %f")) ;;; org export filters (defvar org-export-latex-add-link-footnotes nil "If non-nil links will be added as footnotes if exported to latex.") (defun org-export-latex-link-footnote (text backend info) "Create a footnote in latex for each link. So when printed the information isn't lost. Argument TEXT is the link's text. Argument BACKEND is the use export backend. Argument INFO - I have no idea what this does." (when (and org-export-latex-add-link-footnotes (org-export-derived-backend-p backend 'latex) (string-match "\\\\href{\\(.*\\)}{\\(.*\\)}" text)) (when (cl-some (lambda (type) (string-prefix-p type (match-string 1 text))) '("http" "https" "ftp" "mailto" "doi")) (format "%s \\footnote{\\url{%s}} " text (match-string 1 text))))) (add-to-list 'org-export-filter-link-functions #'org-export-latex-link-footnote) ;;; org-babel (org-babel-do-load-languages 'org-babel-load-languages '((emacs-lisp .t) (shell . t))) (provide 'org-export) ;;; org-export.el ends here
5,468
Common Lisp
.l
125
35.696
111
0.624953
rudolfochrist/cl-manager
6
0
4
MPL-2.0
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
bbdcbb86c49682c78bbe804685d95d1d97aaa0ed0d15664f2df9eba9196b26e4
14,668
[ -1 ]
14,683
vgmplay.asd
bohonghuang_vgmplay/vgmplay.asd
#+sb-core-compression (defmethod asdf:perform ((o asdf:image-op) (c asdf:system)) (uiop:dump-image (asdf:output-file o c) :executable t :compression t)) (defsystem vgmplay :defsystem-depends-on (:deploy) :version "1.1.0" :author "Bohong Huang <[email protected]>" :maintainer "Bohong Huang <[email protected]>" :license "gpl3" :description "An Video Game Music player written in Common Lisp" :homepage "https://github.com/bohonghuang/cl-agbplay" :bug-tracker "https://github.com/bohonghuang/cl-agbplay/issues" :source-control (:git "https://github.com/bohonghuang/cl-agbplay.git") :serial t :build-operation "deploy-op" :build-pathname "vgmplay" :entry-point "vgmplay:main" :components ((:file "vgmplay")) :depends-on (#:asdf #:alexandria #:cl-agbplay #:cl-agbplay.cffi #:claw-raylib #:cl-wave-file-writer))
842
Common Lisp
.asd
19
41.526316
104
0.729927
bohonghuang/vgmplay
6
0
0
GPL-3.0
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
021c4f35f87cb1172e5ec18ec6bad55a548f49742a34d4cbbf5b68c34f8f88fc
14,683
[ -1 ]
14,700
setup.lisp
enzuru_home/quicklisp/setup.lisp
(defpackage #:ql-setup (:use #:cl) (:export #:*quicklisp-home* #:qmerge #:qenough)) (in-package #:ql-setup) (unless *load-truename* (error "This file must be LOADed to set up quicklisp.")) (defvar *quicklisp-home* (make-pathname :name nil :type nil :defaults *load-truename*)) (defun qmerge (pathname) "Return PATHNAME merged with the base Quicklisp directory." (merge-pathnames pathname *quicklisp-home*)) (defun qenough (pathname) (enough-namestring pathname *quicklisp-home*)) ;;; ASDF is a hard requirement of quicklisp. Make sure it's either ;;; already loaded or load it from quicklisp's bundled version. (defvar *required-asdf-version* "3.0") ;;; Put ASDF's fasls in a separate directory (defun implementation-signature () "Return a string suitable for discriminating different implementations, or similar implementations with possibly-incompatible FASLs." ;; XXX Will this have problems with stuff like threads vs ;; non-threads fasls? (let ((*print-pretty* nil)) (format nil "lisp-implementation-type: ~A~%~ lisp-implementation-version: ~A~%~ machine-type: ~A~%~ machine-version: ~A~%" (lisp-implementation-type) (lisp-implementation-version) (machine-type) (machine-version)))) (defun dumb-string-hash (string) "Produce a six-character hash of STRING." (let ((hash #xD13CCD13)) (loop for char across string for value = (char-code char) do (setf hash (logand #xFFFFFFFF (logxor (ash hash 5) (ash hash -27) value)))) (subseq (format nil "~(~36,6,'0R~)" (mod hash 88888901)) 0 6))) (defun asdf-fasl-pathname () "Return a pathname suitable for storing the ASDF FASL, separated from ASDF FASLs from incompatible implementations. Also, save a file in the directory with the implementation signature, if it doesn't already exist." (let* ((implementation-signature (implementation-signature)) (original-fasl (compile-file-pathname (qmerge "asdf.lisp"))) (fasl (qmerge (make-pathname :defaults original-fasl :directory (list :relative "cache" "asdf-fasls" (dumb-string-hash implementation-signature))))) (signature-file (merge-pathnames "signature.txt" fasl))) (ensure-directories-exist fasl) (unless (probe-file signature-file) (with-open-file (stream signature-file :direction :output) (write-string implementation-signature stream))) fasl)) (defun ensure-asdf-loaded () "Try several methods to make sure that a sufficiently-new ASDF is loaded: first try (require \"asdf\"), then loading the ASDF FASL, then compiling asdf.lisp to a FASL and then loading it." (let ((source (qmerge "asdf.lisp"))) (labels ((asdf-symbol (name) (let ((asdf-package (find-package '#:asdf))) (when asdf-package (find-symbol (string name) asdf-package)))) (version-satisfies (version) (let ((vs-fun (asdf-symbol '#:version-satisfies)) (vfun (asdf-symbol '#:asdf-version))) (when (and vs-fun vfun (fboundp vs-fun) (fboundp vfun)) (funcall vs-fun (funcall vfun) version))))) (block nil (macrolet ((try (&body asdf-loading-forms) `(progn (handler-bind ((warning #'muffle-warning)) (ignore-errors ,@asdf-loading-forms)) (when (version-satisfies *required-asdf-version*) (return t))))) (try) (try (require "asdf")) (let ((fasl (asdf-fasl-pathname))) (try (load fasl :verbose nil)) (try (load (compile-file source :verbose nil :output-file fasl)))) (error "Could not load ASDF ~S or newer" *required-asdf-version*)))))) (ensure-asdf-loaded) ;;; ;;; Quicklisp sometimes must upgrade ASDF. Ugrading ASDF will blow ;;; away existing ASDF methods, so e.g. FASL recompilation :around ;;; methods would be lost. This config file will make it possible to ;;; ensure ASDF can be configured before loading Quicklisp itself via ;;; ASDF. Thanks to Nikodemus Siivola for pointing out this issue. ;;; (let ((asdf-init (probe-file (qmerge "asdf-config/init.lisp")))) (when asdf-init (with-simple-restart (skip "Skip loading ~S" asdf-init) (load asdf-init :verbose nil :print nil)))) (push (qmerge "quicklisp/") asdf:*central-registry*) (let ((*compile-print* nil) (*compile-verbose* nil) (*load-verbose* nil) (*load-print* nil)) (asdf:oos 'asdf:load-op "quicklisp" :verbose nil)) (quicklisp:setup)
5,057
Common Lisp
.lisp
117
33.700855
80
0.605851
enzuru/home
6
0
1
GPL-3.0
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
6db1228dd118df9f948bede12d0156d45a8063b89f4d67c07bd75b9a0e71bebc
14,700
[ 128673 ]
14,701
impl-util.lisp
enzuru_home/quicklisp/quicklisp/impl-util.lisp
;;;; impl-util.lisp (in-package #:ql-impl-util) (definterface call-with-quiet-compilation (fun) (:documentation "Call FUN with warnings, style-warnings, and other verbose messages suppressed.") (:implementation t (let ((*load-verbose* nil) (*compile-verbose* nil) (*load-print* nil) (*compile-print* nil)) (handler-bind ((warning #'muffle-warning)) (funcall fun))))) (defimplementation (call-with-quiet-compilation :for sbcl :qualifier :around) (fun) (declare (ignore fun)) (handler-bind ((ql-sbcl:compiler-note #'muffle-warning)) (call-next-method))) (defimplementation (call-with-quiet-compilation :for cmucl :qualifier :around) (fun) (declare (ignore fun)) (let ((ql-cmucl:*gc-verbose* nil)) (call-next-method))) (definterface rename-directory (from to) (:implementation t (rename-file from to) (truename to)) (:implementation cmucl (rename-file from (string-right-trim "/" (namestring to))) (truename to)) (:implementation clisp (ql-clisp:rename-directory from to) (truename to))) (definterface probe-directory (pathname) (:documentation "Return the truename of PATHNAME, if it exists and is a directory, or NIL otherwise.") (:implementation t (let ((directory (probe-file pathname))) (when directory ;; probe-file is specified to return the truename of the path, ;; but Allegro does not return the truename; truenamize it. (truename directory)))) (:implementation clisp (let ((directory (ql-clisp:probe-pathname pathname))) (when (and directory (ql-clisp:probe-directory directory)) directory)))) (definterface init-file-name () (:documentation "Return the init file name for the current implementation.") (:implementation allegro ".clinit.cl") (:implementation abcl ".abclrc") (:implementation ccl #+windows "ccl-init.lisp" #-windows ".ccl-init.lisp") (:implementation clasp ".clasprc") (:implementation clisp ".clisprc.lisp") (:implementation ecl ".eclrc") (:implementation mezzano "init.lisp") (:implementation mkcl ".mkclrc") (:implementation lispworks ".lispworks") (:implementation sbcl ".sbclrc") (:implementation cmucl ".cmucl-init.lisp") (:implementation scl ".scl-init.lisp") ) (defun init-file-name-for (&optional implementation-designator) (let* ((class-name (find-symbol (string-upcase implementation-designator) 'ql-impl)) (class (find-class class-name nil))) (when class (let ((*implementation* (make-instance class))) (init-file-name))))) (defun quicklisp-init-file-form () "Return a form suitable for describing the location of the quicklisp init file. If the file is available relative to the home directory, returns a form that merges with the home directory instead of specifying an absolute file." (let* ((init-file (ql-setup:qmerge "setup.lisp")) (enough (enough-namestring init-file (user-homedir-pathname)))) (cond ((equal (pathname enough) (pathname init-file)) ;; The init-file is somewhere outside of the home directory (pathname enough)) (t `(merge-pathnames ,enough (user-homedir-pathname)))))) (defun write-init-forms (stream &key (indentation 0)) (format stream "~%~v@T;;; The following lines added by ql:add-to-init-file:~%" indentation) (format stream "~v@T#-quicklisp~%" indentation) (let ((*print-case* :downcase)) (format stream "~v@T(let ((quicklisp-init ~S))~%" indentation (quicklisp-init-file-form))) (format stream "~v@T (when (probe-file quicklisp-init)~%" indentation) (format stream "~v@T (load quicklisp-init)))~%~%" indentation)) (defun suitable-lisp-init-file (implementation) "Return the name of IMPLEMENTATION's init file. If IMPLEMENTAION is a string or pathname, return its merged pathname instead." (typecase implementation ((or string pathname) (merge-pathnames implementation)) ((or null (eql t)) (init-file-name)) (t (init-file-name-for implementation)))) (defun add-to-init-file (&optional implementation-or-file) "Add forms to the Lisp implementation's init file that will load quicklisp at CL startup." (let ((init-file (suitable-lisp-init-file implementation-or-file))) (unless init-file (error "Don't know how to add to init file for your implementation.")) (setf init-file (merge-pathnames init-file (user-homedir-pathname))) (format *query-io* "~&I will append the following lines to ~S:~%" init-file) (write-init-forms *query-io* :indentation 2) (when (ql-util:press-enter-to-continue) (with-open-file (stream init-file :direction :output :if-does-not-exist :create :if-exists :append) (write-init-forms stream))) init-file)) ;;; ;;; Native namestrings. ;;; (definterface native-namestring (pathname) (:documentation "In Clozure CL, #\\.s in pathname-names are escaped in namestrings with #\\> on Windows and #\\\\ elsewhere. This can cause a problem when using CL:NAMESTRING to store pathname data that might be used by other implementations. NATIVE-NAMESTRING is intended to provide a namestring that can be parsed as a same-enough object on multiple implementations.") (:implementation t (namestring pathname)) (:implementation ccl (ql-ccl:native-translated-namestring pathname)) (:implementation sbcl (ql-sbcl:native-namestring pathname))) ;;; ;;; Directory write date ;;; (definterface directory-write-date (pathname) (:documentation "Return the write-date of the directory designated by PATHNAME as a universal time, like file-write-date.") (:implementation t (file-write-date pathname)) (:implementation clisp (nth-value 2 (ql-clisp:probe-pathname pathname)))) ;;; ;;; Deleting a directory tree ;;; (defvar *wild-entry* (make-pathname :name :wild :type :wild :version :wild)) (defvar *wild-relative* (make-pathname :directory '(:relative :wild))) (definterface directoryp (entry) (:documentation "Return true if ENTRY refers to a directory.") (:implementation t (not (or (pathname-name entry) (pathname-type entry)))) (:implementation allegro (ql-allegro:file-directory-p entry :follow-symbolic-links nil)) (:implementation lispworks (ql-lispworks:file-directory-p entry))) (definterface directory-entries (directory) (:documentation "Return all directory entries of DIRECTORY as a list, or NIL if there are no directory entries. Excludes the \".\" and \"..\" entries.") (:implementation allegro (directory directory #+allegro :directories-are-files #+allegro nil #+allegro :follow-symbolic-links #+allegro nil)) (:implementation abcl (directory (merge-pathnames *wild-entry* directory) #+abcl :resolve-symlinks #+abcl nil)) (:implementation ccl (directory (merge-pathnames *wild-entry* directory) #+ccl :directories #+ccl t #+ccl :follow-links #+ccl nil)) (:implementation clasp (nconc (directory (merge-pathnames *wild-entry* directory) #+clasp :resolve-symlinks #+clasp nil) (directory (merge-pathnames *wild-relative* directory) #+clasp :resolve-symlinks #+clasp nil))) (:implementation clisp ;; :full gives pathnames as well as truenames, BUT: it returns a ;; singleton pathname, not a list, on dead symlinks. (remove nil (mapcar (lambda (entry) (and (listp entry) (first entry))) (nconc (directory (merge-pathnames *wild-entry* directory) #+clisp :full #+clisp t #+clisp :if-does-not-exist #+clisp :keep) (directory (merge-pathnames *wild-relative* directory) #+clisp :full #+clisp t #+clisp :if-does-not-exist #+clisp :keep))))) (:implementation cmucl (directory (merge-pathnames *wild-entry* directory) #+cmucl :truenamep #+cmucl nil)) (:implementation scl (directory (merge-pathnames *wild-entry* directory) #+scl :truenamep #+scl nil)) (:implementation lispworks (directory (merge-pathnames *wild-entry* directory) #+lispworks :directories #+lispworks t #+lispworks :link-transparency #+lispworks nil)) (:implementation ecl (nconc (directory (merge-pathnames *wild-entry* directory) #+ecl :resolve-symlinks #+ecl nil) (directory (merge-pathnames *wild-relative* directory) #+ecl :resolve-symlinks #+ecl nil))) (:implementation mezzano (directory (merge-pathnames *wild-entry* directory))) (:implementation mkcl (setf directory (truename directory)) (nconc (directory (merge-pathnames *wild-entry* directory)) (directory (merge-pathnames *wild-relative* directory)))) (:implementation sbcl (directory (merge-pathnames *wild-entry* directory) #+sbcl :resolve-symlinks #+sbcl nil))) (defimplementation (directory-entries :qualifier :around) (directory) ;; Don't return any entries when called with a non-directory ;; argument (if (directoryp directory) (call-next-method) (warn "directory-entries - not a directory -- ~S" directory))) (definterface delete-directory (entry) (:documentation "Delete the directory ENTRY. Might signal an error if it is not an empty directory.") (:implementation t (delete-file entry)) (:implementation allegro (ql-allegro:delete-directory entry)) (:implementation ccl (ql-ccl:delete-directory entry)) (:implementation clasp (ql-clasp:rmdir entry)) (:implementation clisp (ql-clisp:delete-directory entry)) (:implementation cmucl (ql-cmucl:unix-rmdir (namestring entry))) (:implementation scl (ql-scl:unix-rmdir (ql-scl:unix-namestring entry))) (:implementation ecl (ql-ecl:rmdir entry)) (:implementation mkcl (ql-mkcl:rmdir entry)) (:implementation lispworks (ql-lispworks:delete-directory entry)) (:implementation sbcl (ql-sbcl:rmdir entry))) (defimplementation (delete-directory :qualifier :around) (directory) ;; Don't delete non-directories with delete-directory (if (directoryp directory) (call-next-method) (error "delete-directory - not a directory -- ~A" directory))) (definterface delete-directory-tree (pathname) (:documentation "Delete the directory tree rooted at PATHNAME.") (:implementation t (let ((directories-to-process (list (truename pathname))) (directories-to-delete '())) (loop (unless directories-to-process (return)) (let* ((current (pop directories-to-process)) (entries (directory-entries current))) (push current directories-to-delete) (dolist (entry entries) (if (directoryp entry) (push entry directories-to-process) (delete-file entry))))) (map nil 'delete-directory directories-to-delete))) (:implementation allegro (ql-allegro:delete-directory-and-files pathname)) (:implementation ccl (ql-ccl:delete-directory pathname))) (defimplementation (delete-directory-tree :qualifier :around) (pathname) (if (directoryp pathname) (call-next-method) (progn (warn "delete-directory-tree - not a directory, ~ deleting anyway -- ~s" pathname) (delete-file pathname)))) (defun map-directory-tree (directory fun) "Call FUN for every file in directory and all its subdirectories, recursively. Uses the truename of directory as a starting point. Does not follow symlinks, but, on some implementations, DOES include potentially dead symlinks." (let ((directories-to-process (list (truename directory)))) (loop (unless directories-to-process (return)) (let* ((current (pop directories-to-process)) (entries (directory-entries current))) (dolist (entry entries) (if (directoryp entry) (push entry directories-to-process) (funcall fun entry)))))))
12,468
Common Lisp
.lisp
312
33.541667
83
0.669169
enzuru/home
6
0
1
GPL-3.0
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
2c3a2094f14b31fd0bd3c0faab108f4a21133d8314cd6d8eb4350fe974cb0822
14,701
[ 161736 ]
14,702
package.lisp
enzuru_home/quicklisp/quicklisp/package.lisp
;;;; package.lisp (defpackage #:ql-util (:documentation "Utility functions used in various places.") (:use #:cl) (:export #:write-line-to-file #:without-prompting #:press-enter-to-continue #:replace-file #:copy-file #:delete-file-if-exists #:ensure-file-exists #:split-spaces #:first-line #:file-size #:safely-read #:safely-read-file #:make-versions-url #:with-temporary-file)) (defpackage #:ql-setup (:documentation "Functions and variables initialized early in the Quicklisp client configuration.") (:use #:cl) (:export #:qmerge #:qenough #:*quicklisp-home*)) (defpackage #:ql-config (:documentation "Getting and setting persistent configuration values.") (:use #:cl #:ql-util #:ql-setup) (:export #:config-value)) (defpackage #:ql-impl (:documentation "Configuration of implementation-specific packages and interfaces.") (:use #:cl) (:export #:*implementation*) (:export #:definterface #:defimplementation #:show-interfaces) (:export #:lisp #:abcl #:allegro #:ccl #:clasp #:clisp #:cmucl #:cormanlisp #:ecl #:gcl #:lispworks #:mezzano #:mkcl #:scl #:sbcl)) (defpackage #:ql-impl-util (:documentation "Utility functions that require implementation-specific functionality.") (:use #:cl #:ql-impl) (:export #:call-with-quiet-compilation #:add-to-init-file #:rename-directory #:delete-directory #:probe-directory #:directory-entries #:delete-directory-tree #:map-directory-tree #:native-namestring #:directory-write-date)) (defpackage #:ql-network (:documentation "Simple, low-level network access.") (:use #:cl #:ql-impl) (:export #:open-connection #:write-octets #:read-octets #:close-connection #:with-connection)) (defpackage #:ql-progress (:documentation "Displaying a progress bar.") (:use #:cl) (:export #:make-progress-bar #:start-display #:update-progress #:finish-display)) (defpackage #:ql-http (:documentation "A simple HTTP client.") (:use #:cl #:ql-network #:ql-progress #:ql-config) (:export #:*proxy-url* #:fetch #:http-fetch #:*fetch-scheme-functions* #:scheme #:hostname #:port #:path #:url #:*maximum-redirects* #:*default-url-defaults*) (:export #:fetch-error #:unexpected-http-status #:unexpected-http-status-code #:unexpected-http-status-url #:too-many-redirects #:too-many-redirects-url #:too-many-redirects-count)) (defpackage #:ql-minitar (:documentation "A simple implementation of unpacking the 'tar' file format.") (:use #:cl) (:export #:unpack-tarball)) (defpackage #:ql-gunzipper (:documentation "An implementation of gunzip.") (:use #:cl) (:export #:gunzip)) (defpackage #:ql-cdb (:documentation "Read and write CDB files; code adapted from ZCDB.") (:use #:cl) (:export #:lookup #:map-cdb #:convert-index-file)) (defpackage #:ql-dist (:documentation "Generic functions, variables, and classes for interacting with the dist system. Documented, exported symbols are intended for public use.") (:use #:cl #:ql-util #:ql-http #:ql-setup #:ql-gunzipper #:ql-minitar) (:intern #:dist-version #:dist-url) (:import-from #:ql-impl-util #:delete-directory-tree #:directory-entries #:probe-directory) ;; Install/enable protocol (:export #:installedp #:install #:uninstall #:ensure-installed #:enabledp #:enable #:disable) ;; Preference protocol (:export #:preference #:preference-file #:preference-parent #:forget-preference) ;; Generic (:export #:all-dists #:canonical-distinfo-url #:enabled-dists #:find-dist #:find-dist-or-lose #:find-system #:find-release #:dist #:system #:release #:base-directory #:relative-to #:metadata-name #:install-metadata-file #:short-description #:provided-releases #:provided-systems #:installed-releases #:installed-systems #:name) ;; Dists (:export #:dist #:dist-merge #:find-system-in-dist #:find-release-in-dist #:system-index-url #:release-index-url #:available-versions-url #:available-versions #:version #:subscription-url #:new-version-available-p #:dist-difference #:fetch-dist #:initialize-release-index #:initialize-system-index #:with-consistent-dists) ;; Dist updates (:export #:available-update #:update-release-differences #:show-update-report #:update-in-place #:install-dist #:subscription-inhibition-file #:inhibit-subscription #:uninhibit-subscription #:subscription-inhibited-p #:subscription-unavailable #:subscribedp #:subscribe #:unsubscribe) ;; Releases (:export #:release #:project-name #:system-files #:archive-url #:archive-size #:ensure-archive-file #:archive-content-sha1 #:archive-md5 #:prefix #:local-archive-file #:ensure-local-archive-file #:check-local-archive-file #:invalid-local-archive #:invalid-local-archive-file #:invalid-local-archive-release #:missing-local-archive #:badly-sized-local-archive #:delete-and-retry) ;; Systems (:export #:dist #:release #:preference #:system-file-name #:required-systems) ;; Misc (:export #:standard-dist-enumeration-function #:*dist-enumeration-functions* #:find-asdf-system-file #:system-definition-searcher #:system-apropos #:system-apropos-list #:dependency-tree #:clean #:unknown-dist)) (defpackage #:ql-dist-user (:documentation "A package that uses QL-DIST; useful for playing around in without clobbering any QL-DIST internals.") (:use #:cl #:ql-dist)) (defpackage #:ql-bundle (:documentation "A package for supporting the QL:BUNDLE-SYSTEMS function.") (:use #:cl #:ql-dist #:ql-impl-util) (:shadow #:find-system #:find-release) (:export #:bundle #:requested-systems #:ensure-system #:ensure-release #:write-bundle #:add-systems-recursively #:object-not-found #:system-not-found #:system-not-found-system #:release-not-found #:bundle-directory-exists #:bundle-directory-exists-directory)) (defpackage #:quicklisp-client (:documentation "The Quicklisp client package, intended for end-user Quicklisp commands and configuration parameters.") (:nicknames #:quicklisp #:ql) (:use #:cl #:ql-util #:ql-impl-util #:ql-dist #:ql-http #:ql-setup #:ql-config #:ql-minitar #:ql-gunzipper) (:shadow #:uninstall) (:shadowing-import-from #:ql-dist #:dist-version #:dist-url) (:export #:dist-version #:dist-url) (:export #:quickload #:*quickload-prompt* #:*quickload-verbose* #:*quickload-explain* #:system-not-found #:system-not-found-name #:uninstall #:uninstall-dist #:qmerge #:*quicklisp-home* #:*initial-dist-url* #:*proxy-url* #:config-value #:setup #:provided-systems #:system-apropos #:system-apropos-list #:system-list #:client-version #:client-url #:available-client-versions #:install-client #:update-client #:update-dist #:update-all-dists #:available-dist-versions #:add-to-init-file #:use-only-quicklisp-systems #:write-asdf-manifest-file #:where-is-system #:help #:register-local-projects #:local-projects-searcher #:*local-project-directories* #:list-local-projects #:list-local-systems #:who-depends-on #:bundle-systems)) (in-package #:quicklisp-client)
9,318
Common Lisp
.lisp
326
19.518405
71
0.549911
enzuru/home
6
0
1
GPL-3.0
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
d78120dd5762d98be77509ea7c4d2f75cf0e10b24b448f378b692ce9a4674d52
14,702
[ 374779 ]
14,703
http.lisp
enzuru_home/quicklisp/quicklisp/http.lisp
;;; ;;; A simple HTTP client ;;; (in-package #:ql-http) ;;; Octet data (deftype octet () '(unsigned-byte 8)) (defun make-octet-vector (size) (make-array size :element-type 'octet :initial-element 0)) (defun octet-vector (&rest octets) (make-array (length octets) :element-type 'octet :initial-contents octets)) ;;; ASCII characters as integers (defun acode (char) (cond ((eql char :cr) 13) ((eql char :lf) 10) (t (let ((code (char-code char))) (if (<= 0 code 127) code (error "Character ~S is not in the ASCII character set" char)))))) (defvar *whitespace* (list (acode #\Space) (acode #\Tab) (acode :cr) (acode :lf))) (defun whitep (code) (member code *whitespace*)) (defun ascii-vector (string) (let ((vector (make-octet-vector (length string)))) (loop for char across string for code = (char-code char) for i from 0 if (< 127 code) do (error "Invalid character for ASCII -- ~A" char) else do (setf (aref vector i) code)) vector)) (defun ascii-subseq (vector start end) "Return a subseq of octet-specialized VECTOR as a string." (let ((string (make-string (- end start)))) (loop for i from 0 for j from start below end do (setf (char string i) (code-char (aref vector j)))) string)) (defun ascii-downcase (code) (if (<= 65 code 90) (+ code 32) code)) (defun ascii-equal (a b) (eql (ascii-downcase a) (ascii-downcase b))) (defmacro acase (value &body cases) (flet ((convert-case-keys (keys) (mapcar (lambda (key) (etypecase key (integer key) (character (char-code key)) (symbol (ecase key (:cr 13) (:lf 10) ((t) t))))) (if (consp keys) keys (list keys))))) `(case ,value ,@(mapcar (lambda (case) (destructuring-bind (keys &rest body) case `(,(if (eql keys t) t (convert-case-keys keys)) ,@body))) cases)))) ;;; Pattern matching (for finding headers) (defclass matcher () ((pattern :initarg :pattern :reader pattern) (pos :initform 0 :accessor match-pos) (matchedp :initform nil :accessor matchedp))) (defun reset-match (matcher) (setf (match-pos matcher) 0 (matchedp matcher) nil)) (define-condition match-failure (error) ()) (defun match (matcher input &key (start 0) end error) (let ((i start) (end (or end (length input))) (match-end (length (pattern matcher)))) (with-slots (pattern pos) matcher (loop (cond ((= pos match-end) (let ((match-start (- i pos))) (setf pos 0) (setf (matchedp matcher) t) (return (values match-start (+ match-start match-end))))) ((= i end) (return nil)) ((= (aref pattern pos) (aref input i)) (incf i) (incf pos)) (t (if error (error 'match-failure) (if (zerop pos) (incf i) (setf pos 0))))))))) (defun ascii-matcher (string) (make-instance 'matcher :pattern (ascii-vector string))) (defun octet-matcher (&rest octets) (make-instance 'matcher :pattern (apply 'octet-vector octets))) (defun acode-matcher (&rest codes) (make-instance 'matcher :pattern (make-array (length codes) :element-type 'octet :initial-contents (mapcar 'acode codes)))) ;;; "Connection Buffers" are a kind of callback-driven, ;;; pattern-matching chunky stream. Callbacks can be called for a ;;; certain number of octets or until one or more patterns are seen in ;;; the input. cbufs automatically refill themselves from a ;;; connection as needed. (defvar *cbuf-buffer-size* 8192) (define-condition end-of-data (error) ()) (defclass cbuf () ((data :initarg :data :accessor data) (connection :initarg :connection :accessor connection) (start :initarg :start :accessor start) (end :initarg :end :accessor end) (eofp :initarg :eofp :accessor eofp)) (:default-initargs :data (make-octet-vector *cbuf-buffer-size*) :connection nil :start 0 :end 0 :eofp nil) (:documentation "A CBUF is a connection buffer that keeps track of incoming data from a connection. Several functions make it easy to treat a CBUF as a kind of chunky, callback-driven stream.")) (define-condition cbuf-progress () ((size :initarg :size :accessor cbuf-progress-size :initform 0))) (defun call-processor (fun cbuf start end) (signal 'cbuf-progress :size (- end start)) (funcall fun (data cbuf) start end)) (defun make-cbuf (connection) (make-instance 'cbuf :connection connection)) (defun make-stream-writer (stream) "Create a callback for writing data to STREAM." (lambda (data start end) (write-sequence data stream :start start :end end))) (defgeneric size (cbuf) (:method ((cbuf cbuf)) (- (end cbuf) (start cbuf)))) (defgeneric emptyp (cbuf) (:method ((cbuf cbuf)) (zerop (size cbuf)))) (defgeneric refill (cbuf) (:method ((cbuf cbuf)) (when (eofp cbuf) (error 'end-of-data)) (setf (start cbuf) 0) (setf (end cbuf) (read-octets (data cbuf) (connection cbuf))) (cond ((emptyp cbuf) (setf (eofp cbuf) t) (error 'end-of-data)) (t (size cbuf))))) (defun process-all (fun cbuf) (unless (emptyp cbuf) (call-processor fun cbuf (start cbuf) (end cbuf)))) (defun multi-cmatch (matchers cbuf) (let (start end) (dolist (matcher matchers (values start end)) (multiple-value-bind (s e) (match matcher (data cbuf) :start (start cbuf) :end (end cbuf)) (when (and s (or (null start) (< s start))) (setf start s end e)))))) (defun cmatch (matcher cbuf) (if (consp matcher) (multi-cmatch matcher cbuf) (match matcher (data cbuf) :start (start cbuf) :end (end cbuf)))) (defun call-until-end (fun cbuf) (handler-case (loop (process-all fun cbuf) (refill cbuf)) (end-of-data () (return-from call-until-end)))) (defun show-cbuf (context cbuf) (format t "cbuf: ~A ~D - ~D~%" context (start cbuf) (end cbuf))) (defun call-for-n-octets (n fun cbuf) (let ((remaining n)) (loop (when (<= remaining (size cbuf)) (let ((end (+ (start cbuf) remaining))) (call-processor fun cbuf (start cbuf) end) (setf (start cbuf) end) (return))) (process-all fun cbuf) (decf remaining (size cbuf)) (refill cbuf)))) (defun call-until-matching (matcher fun cbuf) (loop (multiple-value-bind (start end) (cmatch matcher cbuf) (when start (call-processor fun cbuf (start cbuf) end) (setf (start cbuf) end) (return))) (process-all fun cbuf) (refill cbuf))) (defun ignore-data (data start end) (declare (ignore data start end))) (defun skip-until-matching (matcher cbuf) (call-until-matching matcher 'ignore-data cbuf)) ;;; Creating HTTP requests as octet buffers (defclass octet-sink () ((storage :initarg :storage :accessor storage)) (:default-initargs :storage (make-array 1024 :element-type 'octet :fill-pointer 0 :adjustable t)) (:documentation "A simple stream-like target for collecting octets.")) (defun add-octet (octet sink) (vector-push-extend octet (storage sink))) (defun add-octets (octets sink &key (start 0) end) (setf end (or end (length octets))) (loop for i from start below end do (add-octet (aref octets i) sink))) (defun add-string (string sink) (loop for char across string for code = (char-code char) do (add-octet code sink))) (defun add-strings (sink &rest strings) (mapc (lambda (string) (add-string string sink)) strings)) (defun add-newline (sink) (add-octet 13 sink) (add-octet 10 sink)) (defun sink-buffer (sink) (subseq (storage sink) 0)) (defvar *proxy-url* (config-value "proxy-url")) (defun full-proxy-path (host port path) (format nil "~:[http~;https~]://~A~:[:~D~;~*~]~A" (eql port 443) host (or (null port) (eql port 80) (eql port 443)) port path)) (defun user-agent-string () "Return a string suitable for using as the User-Agent value in HTTP requests. Includes Quicklisp version and CL implementation and version information." (labels ((requires-encoding (char) (not (or (alphanumericp char) (member char '(#\. #\- #\_))))) (encode (string) (substitute-if #\_ #'requires-encoding string)) (version-string (string) (if (string-equal string nil) "unknown" (let* ((length (length string)) (start (or (position-if #'digit-char-p string) 0)) (space (or (position #\Space string :start start) length)) (limit (min space length (+ start 24)))) (encode (subseq string start limit)))))) ;; FIXME: Be more configurable, and take/set the version from ;; somewhere else. (format nil "quicklisp-client/~A ~A/~A" ql-info:*version* (encode (lisp-implementation-type)) (version-string (lisp-implementation-version))))) (defun make-request-buffer (host port path &key (method "GET")) "Return an octet vector suitable for sending as an HTTP 1.1 request." (setf method (string method)) (when *proxy-url* (setf path (full-proxy-path host port path))) (let ((sink (make-instance 'octet-sink))) (flet ((add-line (&rest strings) (apply #'add-strings sink strings) (add-newline sink))) (add-line method " " path " HTTP/1.1") (add-line "Host: " host (if (integerp port) (format nil ":~D" port) "")) (add-line "Connection: close") (add-line "User-Agent: " (user-agent-string)) (add-newline sink) (sink-buffer sink)))) (defun sink-until-matching (matcher cbuf) (let ((sink (make-instance 'octet-sink))) (call-until-matching matcher (lambda (buffer start end) (add-octets buffer sink :start start :end end)) cbuf) (sink-buffer sink))) ;;; HTTP headers (defclass header () ((data :initarg :data :accessor data) (status :initarg :status :accessor status) (name-starts :initarg :name-starts :accessor name-starts) (name-ends :initarg :name-ends :accessor name-ends) (value-starts :initarg :value-starts :accessor value-starts) (value-ends :initarg :value-ends :accessor value-ends))) (defmethod print-object ((header header) stream) (print-unreadable-object (header stream :type t) (prin1 (status header) stream))) (defun matches-at (pattern target pos) (= (mismatch pattern target :start2 pos) (length pattern))) (defun header-value-indexes (field-name header) (loop with data = (data header) with pattern = (ascii-vector (string-downcase field-name)) for start across (name-starts header) for i from 0 when (matches-at pattern data start) return (values (aref (value-starts header) i) (aref (value-ends header) i)))) (defun ascii-header-value (field-name header) (multiple-value-bind (start end) (header-value-indexes field-name header) (when start (ascii-subseq (data header) start end)))) (defun all-field-names (header) (map 'list (lambda (start end) (ascii-subseq (data header) start end)) (name-starts header) (name-ends header))) (defun headers-alist (header) (mapcar (lambda (name) (cons name (ascii-header-value name header))) (all-field-names header))) (defmethod describe-object :after ((header header) stream) (format stream "~&Decoded headers:~% ~S~%" (headers-alist header))) (defun content-length (header) (let ((field-value (ascii-header-value "content-length" header))) (when field-value (let ((value (ignore-errors (parse-integer field-value)))) (or value (error "Content-Length header field value is not a number -- ~A" field-value)))))) (defun chunkedp (header) (string= (ascii-header-value "transfer-encoding" header) "chunked")) (defun location (header) (ascii-header-value "location" header)) (defun status-code (vector) (let* ((space (position (acode #\Space) vector)) (c1 (- (aref vector (incf space)) 48)) (c2 (- (aref vector (incf space)) 48)) (c3 (- (aref vector (incf space)) 48))) (+ (* c1 100) (* c2 10) (* c3 1)))) (defun force-downcase-field-names (header) (loop with data = (data header) for start across (name-starts header) for end across (name-ends header) do (loop for i from start below end for code = (aref data i) do (setf (aref data i) (ascii-downcase code))))) (defun skip-white-forward (pos vector) (position-if-not 'whitep vector :start pos)) (defun skip-white-backward (pos vector) (let ((nonwhite (position-if-not 'whitep vector :end pos :from-end t))) (if nonwhite (1+ nonwhite) pos))) (defun contract-field-value-indexes (header) "Header field values exclude leading and trailing whitespace; adjust the indexes in the header accordingly." (loop with starts = (value-starts header) with ends = (value-ends header) with data = (data header) for i from 0 for start across starts for end across ends do (setf (aref starts i) (skip-white-forward start data)) (setf (aref ends i) (skip-white-backward end data)))) (defun next-line-pos (vector) (let ((pos 0)) (labels ((finish (&optional (i pos)) (return-from next-line-pos i)) (after-cr (code) (acase code (:lf (finish pos)) (t (finish (1- pos))))) (pending (code) (acase code (:cr #'after-cr) (:lf (finish pos)) (t #'pending)))) (let ((state #'pending)) (loop (setf state (funcall state (aref vector pos))) (incf pos)))))) (defun make-hvector () (make-array 16 :fill-pointer 0 :adjustable t)) (defun process-header (vector) "Create a HEADER instance from the octet data in VECTOR." (let* ((name-starts (make-hvector)) (name-ends (make-hvector)) (value-starts (make-hvector)) (value-ends (make-hvector)) (header (make-instance 'header :data vector :status 999 :name-starts name-starts :name-ends name-ends :value-starts value-starts :value-ends value-ends)) (mark nil) (pos (next-line-pos vector))) (unless pos (error "Unable to process HTTP header")) (setf (status header) (status-code vector)) (labels ((save (value vector) (vector-push-extend value vector)) (mark () (setf mark pos)) (clear-mark () (setf mark nil)) (finish () (if mark (save mark value-ends) (save pos value-ends)) (force-downcase-field-names header) (contract-field-value-indexes header) (return-from process-header header)) (in-new-line (code) (acase code ((#\Tab #\Space) (setf mark nil) #'in-value) (t (when mark (save mark value-ends)) (clear-mark) (save pos name-starts) (in-name code)))) (after-cr (code) (acase code (:lf #'in-new-line) (t (in-new-line code)))) (in-name (code) (acase code (#\: (save pos name-ends) (save (1+ pos) value-starts) #'in-value) ((:cr :lf) (finish)) ((#\Tab #\Space) (error "Unexpected whitespace in header field name")) (t (unless (<= 0 code 127) (error "Unexpected non-ASCII header field name")) #'in-name))) (in-value (code) (acase code (:lf (mark) #'in-new-line) (:cr (mark) #'after-cr) (t #'in-value)))) (let ((state #'in-new-line)) (loop (incf pos) (when (<= (length vector) pos) (error "No header found in response")) (setf state (funcall state (aref vector pos)))))))) ;;; HTTP URL parsing (defclass url () ((scheme :initarg :scheme :accessor scheme :initform nil) (hostname :initarg :hostname :accessor hostname :initform nil) (port :initarg :port :accessor port :initform nil) (path :initarg :path :accessor path :initform "/"))) (defun parse-urlstring (urlstring) (setf urlstring (string-trim " " urlstring)) (let* ((pos (position #\: urlstring)) (scheme (or (and pos (subseq urlstring 0 pos)) "http")) (pos (mismatch urlstring "://" :test 'char-equal :start1 pos)) (mark pos) (url (make-instance 'url))) (setf (scheme url) scheme) (labels ((save () (subseq urlstring mark pos)) (mark () (setf mark pos)) (finish () (return-from parse-urlstring url)) (hostname-char-p (char) (position char "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_." :test 'char-equal)) (at-start (char) (case char (#\/ (setf (port url) nil) (mark) #'in-path) (t #'in-host))) (in-host (char) (case char ((#\/ :end) (setf (hostname url) (save)) (mark) #'in-path) (#\: (setf (hostname url) (save)) (mark) #'in-port) (t (unless (hostname-char-p char) (error "~S is not a valid URL" urlstring)) #'in-host))) (in-port (char) (case char ((#\/ :end) (setf (port url) (parse-integer urlstring :start (1+ mark) :end pos)) (mark) #'in-path) (t (unless (digit-char-p char) (error "Bad port in URL ~S" urlstring)) #'in-port))) (in-path (char) (case char ((#\# :end) (setf (path url) (save)) (finish))) #'in-path)) (let ((state #'at-start)) (loop (when (<= (length urlstring) pos) (funcall state :end) (finish)) (setf state (funcall state (aref urlstring pos))) (incf pos)))))) (defun url (thing) (if (stringp thing) (parse-urlstring thing) thing)) (defgeneric request-buffer (method url) (:method (method url) (setf url (url url)) (make-request-buffer (hostname url) (or (port url) 80) (path url) :method method))) (defun urlstring (url) (format nil "~@[~A://~]~@[~A~]~@[:~D~]~A" (and (hostname url) (scheme url)) (hostname url) (port url) (path url))) (defmethod print-object ((url url) stream) (print-unreadable-object (url stream :type t) (prin1 (urlstring url) stream))) (defun merge-urls (url1 url2) (setf url1 (url url1)) (setf url2 (url url2)) (make-instance 'url :scheme (or (scheme url1) (scheme url2)) :hostname (or (hostname url1) (hostname url2)) :port (or (port url1) (port url2)) :path (or (path url1) (path url2)))) ;;; Requesting an URL and saving it to a file (defparameter *maximum-redirects* 10) (defvar *default-url-defaults* (url "http://src.quicklisp.org/")) (defun read-http-header (cbuf) (let ((header-data (sink-until-matching (list (acode-matcher :lf :lf) (acode-matcher :cr :cr) (acode-matcher :cr :lf :cr :lf)) cbuf))) (process-header header-data))) (defun read-chunk-header (cbuf) (let* ((header-data (sink-until-matching (acode-matcher :cr :lf) cbuf)) (end (or (position (acode :cr) header-data) (position (acode #\;) header-data)))) (values (parse-integer (ascii-subseq header-data 0 end) :radix 16)))) (defun save-chunk-response (stream cbuf) "For a chunked response, read all chunks and write them to STREAM." (let ((fun (make-stream-writer stream)) (matcher (acode-matcher :cr :lf))) (loop (let ((chunk-size (read-chunk-header cbuf))) (when (zerop chunk-size) (return)) (call-for-n-octets chunk-size fun cbuf) (skip-until-matching matcher cbuf))))) (defun save-response (file header cbuf &key (if-exists :rename-and-delete)) (with-open-file (stream file :direction :output :if-exists if-exists :element-type 'octet) (let ((content-length (content-length header))) (cond ((chunkedp header) (save-chunk-response stream cbuf)) (content-length (call-for-n-octets content-length (make-stream-writer stream) cbuf)) (t (call-until-end (make-stream-writer stream) cbuf)))))) (defun call-with-progress-bar (size fun) (let ((progress-bar (make-progress-bar size))) (start-display progress-bar) (flet ((update (condition) (update-progress progress-bar (cbuf-progress-size condition)))) (handler-bind ((cbuf-progress #'update)) (funcall fun))) (finish-display progress-bar))) (define-condition fetch-error (error) ()) (define-condition unexpected-http-status (fetch-error) ((status-code :initarg :status-code :reader unexpected-http-status-code) (url :initarg :url :reader unexpected-http-status-url)) (:report (lambda (condition stream) (format stream "Unexpected HTTP status for ~A: ~A" (unexpected-http-status-url condition) (unexpected-http-status-code condition))))) (define-condition too-many-redirects (fetch-error) ((url :initarg :url :reader too-many-redirects-url) (redirect-count :initarg :redirect-count :reader too-many-redirects-count)) (:report (lambda (condition stream) (format stream "Too many redirects (~:D) for ~A" (too-many-redirects-count condition) (too-many-redirects-url condition))))) (defvar *fetch-scheme-functions* '(("http" . http-fetch)) "assoc list to decide which scheme-function are called by FETCH function.") (defun fetch (url file &rest rest) "Request URL and write the body of the response to FILE." (let* ((url (merge-urls url *default-url-defaults*)) (call (cdr (assoc (scheme url) *fetch-scheme-functions* :test 'equal)))) (if call (apply call (urlstring url) file rest) (error "Unknown scheme ~S" url)))) (defun http-fetch (url file &key (follow-redirects t) quietly (if-exists :rename-and-delete) (maximum-redirects *maximum-redirects*)) "default scheme-function for http protocol." (setf url (merge-urls url *default-url-defaults*)) (setf file (merge-pathnames file)) (let ((redirect-count 0) (original-url url) (connect-url (or (url *proxy-url*) url)) (stream (if quietly (make-broadcast-stream) *trace-output*))) (loop (when (<= maximum-redirects redirect-count) (error 'too-many-redirects :url original-url :redirect-count redirect-count)) (with-connection (connection (hostname connect-url) (or (port connect-url) 80)) (let ((cbuf (make-instance 'cbuf :connection connection)) (request (request-buffer "GET" url))) (write-octets request connection) (let ((header (read-http-header cbuf))) (loop while (= (status header) 100) do (setf header (read-http-header cbuf))) (cond ((= (status header) 200) (let ((size (content-length header))) (format stream "~&; Fetching ~A~%" url) (if (and (numberp size) (plusp size)) (format stream "; ~$KB~%" (/ size 1024)) (format stream "; Unknown size~%")) (if quietly (save-response file header cbuf :if-exists if-exists) (call-with-progress-bar (content-length header) (lambda () (save-response file header cbuf :if-exists if-exists)))))) ((not (<= 300 (status header) 399)) (error 'unexpected-http-status :url url :status-code (status header)))) (if (and follow-redirects (<= 300 (status header) 399)) (let ((new-urlstring (ascii-header-value "location" header))) (when (not new-urlstring) (error "Redirect code ~D received, but no Location: header" (status header))) (incf redirect-count) (setf url (merge-urls new-urlstring url)) (format stream "~&; Redirecting to ~A~%" url)) (return (values header (and file (probe-file file)))))))))))
27,724
Common Lisp
.lisp
758
26.377309
84
0.543644
enzuru/home
6
0
1
GPL-3.0
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
900b19acc7447cde3fda42aef408257602408816a0f8179842a3e226d68535c1
14,703
[ 29254, 404582 ]
14,704
setup.lisp
enzuru_home/quicklisp/quicklisp/setup.lisp
(in-package #:quicklisp) (defun show-wrapped-list (words &key (indent 4) (margin 60)) (let ((*print-right-margin* margin) (*print-pretty* t) (*print-escape* nil) (prefix (make-string indent :initial-element #\Space))) (pprint-logical-block (nil words :per-line-prefix prefix) (pprint-fill *standard-output* (sort (copy-seq words) #'string<) nil)) (fresh-line) (finish-output))) (defun recursively-install (name) (labels ((recurse (name) (let ((system (find-system name))) (unless system (error "Unknown system ~S" name)) (ensure-installed system) (mapcar #'recurse (required-systems system)) name))) (with-consistent-dists (recurse name)))) (defclass load-strategy () ((name :initarg :name :accessor name) (asdf-systems :initarg :asdf-systems :accessor asdf-systems) (quicklisp-systems :initarg :quicklisp-systems :accessor quicklisp-systems))) (defmethod print-object ((strategy load-strategy) stream) (print-unreadable-object (strategy stream :type t) (format stream "~S (~D asdf, ~D quicklisp)" (name strategy) (length (asdf-systems strategy)) (length (quicklisp-systems strategy))))) (defgeneric quicklisp-releases (strategy) (:method (strategy) (remove-duplicates (mapcar 'release (quicklisp-systems strategy))))) (defgeneric quicklisp-release-table (strategy) (:method ((strategy load-strategy)) (let ((table (make-hash-table))) (dolist (system (quicklisp-systems strategy)) (push system (gethash (release system) table nil))) table))) (define-condition system-not-found (error) ((name :initarg :name :reader system-not-found-name)) (:report (lambda (condition stream) (format stream "System ~S not found" (system-not-found-name condition)))) (:documentation "This condition is signaled by QUICKLOAD when a system given to load is not available via ASDF or a Quicklisp dist.")) (defun compute-load-strategy (name) (setf name (string-downcase name)) (let ((asdf-systems '()) (quicklisp-systems '())) (labels ((recurse (name) (let ((asdf-system (asdf:find-system name nil)) (quicklisp-system (find-system name))) (cond (asdf-system (push asdf-system asdf-systems)) (quicklisp-system (push quicklisp-system quicklisp-systems) (dolist (subname (required-systems quicklisp-system)) (recurse subname))) (t (cerror "Try again" 'system-not-found :name name) (recurse name)))))) (with-consistent-dists (recurse name))) (make-instance 'load-strategy :name name :asdf-systems (remove-duplicates asdf-systems) :quicklisp-systems (remove-duplicates quicklisp-systems)))) (defun show-load-strategy (strategy) (format t "To load ~S:~%" (name strategy)) (let ((asdf-systems (asdf-systems strategy)) (releases (quicklisp-releases strategy))) (when asdf-systems (format t " Load ~D ASDF system~:P:~%" (length asdf-systems)) (show-wrapped-list (mapcar 'asdf:component-name asdf-systems))) (when releases (format t " Install ~D Quicklisp release~:P:~%" (length releases)) (show-wrapped-list (mapcar 'name releases))))) (defvar *macroexpand-progress-in-progress* nil) (defun macroexpand-progress-fun (old-hook &key (char #\.) (chars-per-line 50) (forms-per-char 250)) (let ((output-so-far 0) (seen-so-far 0)) (labels ((finish-line () (when (plusp output-so-far) (dotimes (i (- chars-per-line output-so-far)) (write-char char)) (terpri) (setf output-so-far 0))) (show-string (string) (let* ((length (length string)) (new-output (+ length output-so-far))) (cond ((< chars-per-line new-output) (finish-line) (write-string string) (setf output-so-far length)) (t (write-string string) (setf output-so-far new-output)))) (finish-output)) (show-package (name) ;; Only show package markers when compiling. Showing ;; them when loading shows a bunch of ASDF system ;; package noise. (when *compile-file-pathname* (finish-line) (show-string (format nil "[package ~(~A~)]" name))))) (lambda (fun form env) (when (and (consp form) (eq (first form) 'cl:defpackage) (ignore-errors (string (second form)))) (show-package (second form))) (incf seen-so-far) (when (<= forms-per-char seen-so-far) (setf seen-so-far 0) (write-char char) (finish-output) (incf output-so-far) (when (<= chars-per-line output-so-far) (setf output-so-far 0) (terpri) (finish-output))) (funcall old-hook fun form env))))) (defun call-with-macroexpand-progress (fun) (let ((*macroexpand-hook* (if *macroexpand-progress-in-progress* *macroexpand-hook* (macroexpand-progress-fun *macroexpand-hook*))) (*macroexpand-progress-in-progress* t)) (funcall fun) (terpri))) (defun apply-load-strategy (strategy) (map nil 'ensure-installed (quicklisp-releases strategy)) (call-with-macroexpand-progress (lambda () (format t "~&; Loading ~S~%" (name strategy)) (asdf:load-system (name strategy) :verbose nil)))) (defun autoload-system-and-dependencies (name &key prompt) "Try to load the system named by NAME, automatically loading any Quicklisp-provided systems first, and catching ASDF missing dependencies too if possible." (setf name (string-downcase name)) (with-simple-restart (abort "Give up on ~S" name) (let ((tried-so-far (make-hash-table :test 'equalp))) (tagbody retry (handler-case (let ((strategy (compute-load-strategy name))) (show-load-strategy strategy) (when (or (not prompt) (press-enter-to-continue)) (apply-load-strategy strategy))) (asdf:missing-dependency-of-version (c) ;; Nothing Quicklisp can do to recover from this, so just ;; resignal (error c)) (asdf:missing-dependency (c) (let ((parent (asdf::missing-required-by c)) (missing (asdf::missing-requires c))) (typecase parent ((or null asdf:system) ;; NIL parent comes from :defsystem-depends-on failures (if (gethash missing tried-so-far) (error "Dependency looping -- already tried to load ~ ~A" missing) (setf (gethash missing tried-so-far) missing)) (autoload-system-and-dependencies missing :prompt prompt) (go retry)) (t ;; Error isn't from a system dependency, so there's ;; nothing to autoload (error c)))))))) name)) (defvar *initial-dist-url* "http://beta.quicklisp.org/dist/quicklisp.txt") (defun dists-initialized-p () (not (not (ignore-errors (truename (qmerge "dists/")))))) (defun quickstart-parameter (name &optional default) (let* ((package (find-package '#:quicklisp-quickstart)) (symbol (and package (find-symbol (string '#:*quickstart-parameters*) package))) (plist (and symbol (symbol-value symbol))) (parameter (and plist (getf plist name)))) (or parameter default))) (defun maybe-initial-setup () "Run the steps needed when Quicklisp setup is run for the first time after the quickstart installation." (let ((quickstart-proxy-url (quickstart-parameter :proxy-url)) (quickstart-initial-dist-url (quickstart-parameter :initial-dist-url))) (when (and quickstart-proxy-url (not *proxy-url*)) (setf *proxy-url* quickstart-proxy-url) (setf (config-value "proxy-url") quickstart-proxy-url)) (unless (dists-initialized-p) (let ((target (qmerge "dists/quicklisp/distinfo.txt")) (url (or quickstart-initial-dist-url *initial-dist-url*))) (ensure-directories-exist target) (install-dist url :prompt nil))))) (defun setup () (unless (member 'system-definition-searcher asdf:*system-definition-search-functions*) (setf asdf:*system-definition-search-functions* (append asdf:*system-definition-search-functions* (list 'local-projects-searcher 'system-definition-searcher)))) (let ((files (nconc (directory (qmerge "local-init/*.lisp")) (directory (qmerge "local-init/*.cl"))))) (with-simple-restart (abort "Stop loading local setup files") (dolist (file (sort files #'string< :key #'pathname-name)) (with-simple-restart (skip "Skip local setup file ~S" file) ;; Don't try to load Emacs lock files, other hidden files (unless (char= (char (pathname-name file) 0) #\.) (load file)))))) (maybe-initial-setup) (ensure-directories-exist (qmerge "local-projects/")) (pushnew :quicklisp *features*) t)
10,112
Common Lisp
.lisp
230
32.552174
79
0.572848
enzuru/home
6
0
1
GPL-3.0
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
194ec9b55ed46a523cddf51dc5bc472528fb1312a6bafc3849068174175d3508
14,704
[ 363587 ]
14,705
cdb.lisp
enzuru_home/quicklisp/quicklisp/cdb.lisp
;;;; cdb.lisp (in-package #:ql-cdb) (defconstant +initial-hash-value+ 5381) (defun cdb-hash (octets) "http://cr.yp.to/cdb/cdb.txt" (declare (type (simple-array (unsigned-byte 8) (*)) octets) (optimize speed)) (let ((h +initial-hash-value+)) (declare (type (unsigned-byte 32) h)) (dotimes (i (length octets) h) (let ((c (aref octets i))) (setf h (logand #xFFFFFFFF (+ h (ash h 5)))) (setf h (logxor h c)))))) (defun make-growable-vector (&key (size 10) (element-type t)) (make-array size :fill-pointer 0 :adjustable t :element-type element-type)) (defun make-octet-vector (size) (make-array size :element-type '(unsigned-byte 8))) (defun encode-string (string) "Do a bare-bones ASCII encoding of STRING." (map-into (make-octet-vector (length string)) 'char-code string)) (defun decode-octets (octets) "Do a bare-bones ASCII decoding of OCTETS." (map-into (make-string (length octets)) 'code-char octets)) (defun read-cdb-u32 (stream) (logand #xFFFFFFFF (logior (ash (read-byte stream) 0) (ash (read-byte stream) 8) (ash (read-byte stream) 16) (ash (read-byte stream) 24)))) (defun lookup-record-at (position key stream) (file-position stream position) (let ((key-size (read-cdb-u32 stream)) (value-size (read-cdb-u32 stream))) (when (= key-size (length key)) (let ((test-key (make-octet-vector key-size))) (when (/= key-size (read-sequence test-key stream)) (error "Could not read record key of size ~D from cdb stream" key-size)) (unless (mismatch test-key key :test #'=) (let ((value (make-octet-vector value-size))) (if (= value-size (read-sequence value stream)) value (error "Could not read record value of size ~D from cdb stream" value-size)))))))) (defun table-slot-lookup (key hash table-position initial-slot slot-count stream) (let ((slot initial-slot)) (loop (file-position stream (+ table-position (* slot 8))) (let ((test-hash (read-cdb-u32 stream)) (record-position (read-cdb-u32 stream))) (when (zerop record-position) (return)) (when (= hash test-hash) (let ((value (lookup-record-at record-position key stream))) (when value (return value))))) (setf slot (mod (1+ slot) slot-count))))) (defun stream-lookup (key stream) (let* ((hash (cdb-hash key)) (pointer-index (logand #xFF hash))) (file-position stream (* pointer-index 8)) (let ((table-position (read-cdb-u32 stream)) (slot-count (read-cdb-u32 stream))) (when (plusp slot-count) (let ((initial-slot (mod (ash hash -8) slot-count))) (table-slot-lookup key hash table-position initial-slot slot-count stream)))))) (defun %lookup (key cdb) "Return the value for KEY in CDB, or NIL if no matching key is found. CDB should be a pathname or an open octet stream. The key should be a vector of octets. The returned value will be a vector of octets." (if (streamp cdb) (stream-lookup key cdb) (with-open-file (stream cdb :element-type '(unsigned-byte 8)) (stream-lookup key stream)))) (defun lookup (key cdb) "Return the value for KEY in CDB, or NIL if no matching key is found. CDB should be a pathname or an open octet stream. The key should be an ASCII-encodable string. The returned value will be a string." (let ((value (%lookup (encode-string key) cdb))) (when value (decode-octets value)))) (defun stream-map-cdb (function stream) (labels ((map-one-slot (i) (file-position stream (* i 8)) (let ((table-position (read-cdb-u32 stream)) (slot-count (read-cdb-u32 stream))) (when (plusp slot-count) (map-one-table table-position slot-count)))) (map-one-table (position count) (dotimes (i count) (file-position stream (+ position (* i 8))) (let ((hash (read-cdb-u32 stream)) (position (read-cdb-u32 stream))) (declare (ignore hash)) (when (plusp position) (map-record position))))) (map-record (position) (file-position stream position) (let* ((key-size (read-cdb-u32 stream)) (value-size (read-cdb-u32 stream)) (key (make-octet-vector key-size)) (value (make-octet-vector value-size))) (read-sequence key stream) (read-sequence value stream) (funcall function key value)))) (dotimes (i 256) (map-one-slot i)))) (defun %map-cdb (function cdb) "Call FUNCTION once with each key and value in CDB." (if (streamp cdb) (stream-map-cdb function cdb) (with-open-file (stream cdb :element-type '(unsigned-byte 8)) (stream-map-cdb function stream)))) (defun map-cdb (function cdb) (%map-cdb (lambda (key value) (funcall function (decode-octets key) (decode-octets value))) cdb)) ;;; Writing CDB files (defun write-cdb-u32 (u32 stream) "Write an (unsigned-byte 32) value to STREAM in little-endian order." (write-byte (ldb (byte 8 0) u32) stream) (write-byte (ldb (byte 8 8) u32) stream) (write-byte (ldb (byte 8 16) u32) stream) (write-byte (ldb (byte 8 24) u32) stream)) (defclass record-pointer () ((hash-value :initarg :hash-value :accessor hash-value :documentation "The hash value of the record key.") (record-position :initarg :record-position :accessor record-position :documentation "The file position at which the record is stored.")) (:default-initargs :hash-value 0 :record-position 0) (:documentation "Every key/value record written to a CDB has a corresponding record pointer, which tracks the key's hash value and the record's position in the data file. When all records have been written to the file, these record pointers are organized into hash tables at the end of the cdb file.")) (defmethod print-object ((record-pointer record-pointer) stream) (print-unreadable-object (record-pointer stream :type t) (format stream "~8,'0X@~:D" (hash-value record-pointer) (record-position record-pointer)))) (defvar *empty-record-pointer* (make-instance 'record-pointer)) (defclass hash-table-bucket () ((table-position :initarg :table-position :accessor table-position :documentation "The file position at which this table is (eventually) slotted.") (entries :initarg :entries :accessor entries :documentation "A vector of record-pointers.")) (:default-initargs :table-position 0 :entries (make-growable-vector)) (:documentation "During construction of the CDB, record pointers are accumulated into one of 256 hash table buckets, depending on the low 8 bits of the hash value of the key. At the end of record writing, these buckets are used to write out hash table vectors at the end of the file, and write pointers to the hash table vectors at the start of the file.")) (defgeneric entry-count (object) (:method ((object hash-table-bucket)) (length (entries object)))) (defgeneric slot-count (object) (:method ((object hash-table-bucket)) (* (entry-count object) 2))) (defun bucket-hash-vector (bucket) "Create a hash vector for a bucket. A hash vector has 2x the entries of the bucket, and is initialized to an empty record pointer. The high 24 bits of the hash value of a record pointer, mod the size of the vector, is used as a starting slot, and the vector is walked (wrapping at the end) to find the first free slot for positioning each record pointer entry." (let* ((size (slot-count bucket)) (vector (make-array size :initial-element nil))) (flet ((slot (record) (let ((index (mod (ash (hash-value record) -8) size))) (loop (unless (aref vector index) (return (setf (aref vector index) record))) (setf index (mod (1+ index) size)))))) (map nil #'slot (entries bucket))) (nsubstitute *empty-record-pointer* nil vector))) (defmethod print-object ((bucket hash-table-bucket) stream) (print-unreadable-object (bucket stream :type t) (format stream "~D entr~:@P" (entry-count bucket)))) (defclass cdb-writer () ((buckets :initarg :buckets :accessor buckets) (end-of-records-position :initarg :end-of-records-position :accessor end-of-records-position) (output :initarg :output :accessor output)) (:default-initargs :end-of-records-position 2048 :buckets (map-into (make-array 256) (lambda () (make-instance 'hash-table-bucket))))) (defun add-record (key value cdb-writer) "Add KEY and VALUE to a cdb file. KEY and VALUE should both be (unsigned-byte 8) vectors." (let* ((output (output cdb-writer)) (hash-value (cdb-hash key)) (bucket-index (logand #xFF hash-value)) (bucket (aref (buckets cdb-writer) bucket-index)) (record-position (file-position output)) (record-pointer (make-instance 'record-pointer :record-position record-position :hash-value hash-value))) (vector-push-extend record-pointer (entries bucket)) (write-cdb-u32 (length key) output) (write-cdb-u32 (length value) output) (write-sequence key output) (write-sequence value output) (force-output output) (incf (end-of-records-position cdb-writer) (+ 8 (length key) (length value))))) (defun write-bucket-hash-table (bucket stream) "Write BUCKET's hash table vector to STREAM." (map nil (lambda (pointer) (write-cdb-u32 (hash-value pointer) stream) (write-cdb-u32 (record-position pointer) stream)) (bucket-hash-vector bucket))) (defun write-hash-tables (cdb-writer) "Write the traililng hash tables to the end of the cdb file. Initializes the position of the buckets in the process." (let ((stream (output cdb-writer))) (map nil (lambda (bucket) (setf (table-position bucket) (file-position stream)) (write-bucket-hash-table bucket stream)) (buckets cdb-writer)))) (defun write-pointers (cdb-writer) "Write the leading hash table pointers to the beginning of the cdb file. Must be called after WRITE-HASH-TABLES, or the positions won't be available." (let ((stream (output cdb-writer))) (file-position stream :start) (map nil (lambda (bucket) (let ((position (table-position bucket)) (count (slot-count bucket))) (when (zerop position) (error "Table positions not initialized correctly")) (write-cdb-u32 position stream) (write-cdb-u32 count stream))) (buckets cdb-writer)))) (defun finish-cdb-writer (cdb-writer) "Write the trailing hash tables and leading table pointers to the cdb file." (write-hash-tables cdb-writer) (write-pointers cdb-writer) (force-output (output cdb-writer))) (defvar *pointer-padding* (make-array 2048 :element-type '( unsigned-byte 8))) (defun call-with-output-to-cdb (cdb-pathname temp-pathname fun) "Call FUN with one argument, a CDB-WRITER instance to which records can be added with ADD-RECORD." (with-open-file (stream temp-pathname :direction :output :element-type '(unsigned-byte 8) :if-exists :supersede) (let ((cdb (make-instance 'cdb-writer :output stream))) (write-sequence *pointer-padding* stream) (funcall fun cdb) (finish-cdb-writer cdb))) (values (rename-file temp-pathname cdb-pathname))) (defmacro with-output-to-cdb ((cdb file temp-file) &body body) "Evaluate BODY with CDB bound to a CDB-WRITER object. The CDB in progress is written to TEMP-FILE, and then when the CDB is successfully written, TEMP-FILE is renamed to FILE. For atomic operation, FILE and TEMP-FILE must be on the same filesystem." `(call-with-output-to-cdb ,file ,temp-file (lambda (,cdb) ,@body))) ;;; Index file (systems.txt, releases.txt) conversion (defun convert-index-file (index-file &key (cdb-file (make-pathname :type "cdb" :defaults index-file)) (index 0)) (with-open-file (stream index-file) (let ((header (read-line stream))) (unless (and (plusp (length header)) (char= (char header 0) #\#)) (error "Bad header line in ~A -- ~S" index-file header))) (with-output-to-cdb (cdb cdb-file (make-pathname :type "cdb-tmp" :defaults cdb-file)) (loop for line = (read-line stream nil) for words = (and line (ql-util:split-spaces line)) while line do (add-record (encode-string (elt words index)) (encode-string line) cdb)))))
13,548
Common Lisp
.lisp
313
35.035144
80
0.625834
enzuru/home
6
0
1
GPL-3.0
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
2da9d65a341190ad89db1019d18d62983595709c6c2b784cd9dd33e1ffa56004
14,705
[ 336637, 354884 ]
14,706
utils.lisp
enzuru_home/quicklisp/quicklisp/utils.lisp
;;;; utils.lisp (in-package #:ql-util) (defun write-line-to-file (string file) (with-open-file (stream file :direction :output :if-exists :supersede) (write-line string stream))) (defvar *do-not-prompt* nil "When *DO-NOT-PROMPT* is true, PRESS-ENTER-TO-CONTINUE returns true without user interaction.") (defmacro without-prompting (&body body) "Evaluate BODY in an environment where PRESS-ENTER-TO-CONTINUE always returns true without prompting for the user to press enter." `(let ((*do-not-prompt* t)) ,@body)) (defun press-enter-to-continue () (when *do-not-prompt* (return-from press-enter-to-continue t)) (format *query-io* "~&Press Enter to continue.~%") (let ((result (read-line *query-io*))) (zerop (length result)))) (defun replace-file (from to) "Like RENAME-FILE, but deletes TO if it exists, first." (when (probe-file to) (delete-file to)) (rename-file from to)) (defun copy-file (from to &key (if-exists :rename-and-delete)) "Copy the file FROM to TO." (let* ((buffer-size 8192) (buffer (make-array buffer-size :element-type '(unsigned-byte 8)))) (with-open-file (from-stream from :element-type '(unsigned-byte 8)) (with-open-file (to-stream to :element-type '(unsigned-byte 8) :direction :output :if-exists if-exists) (let ((length (file-length from-stream))) (multiple-value-bind (full leftover) (floor length buffer-size) (dotimes (i full) (read-sequence buffer from-stream) (write-sequence buffer to-stream)) (read-sequence buffer from-stream) (write-sequence buffer to-stream :end leftover))))) (probe-file to))) (defun ensure-file-exists (pathname) (open pathname :direction :probe :if-does-not-exist :create)) (defun delete-file-if-exists (pathname) (when (probe-file pathname) (delete-file pathname))) (defun split-spaces (line) (let ((words '()) (mark 0) (pos 0)) (labels ((finish () (setf pos (length line)) (save) (return-from split-spaces (nreverse words))) (save () (when (< mark pos) (push (subseq line mark pos) words))) (mark () (setf mark pos)) (in-word (char) (case char (#\Space (save) #'in-space) (t #'in-word))) (in-space (char) (case char (#\Space #'in-space) (t (mark) #'in-word)))) (let ((state #'in-word)) (dotimes (i (length line) (finish)) (setf pos i) (setf state (funcall state (char line i)))))))) (defun first-line (file) (with-open-file (stream file) (values (read-line stream)))) (defun (setf first-line) (line file) (with-open-file (stream file :direction :output :if-exists :rename-and-delete) (write-line line stream))) (defun file-size (file) (with-open-file (stream file :element-type '(unsigned-byte 8)) (file-length stream))) (defun safely-read (stream) "Read one form from STREAM with *READ-EVAL* bound to NIL." (let ((*read-eval* nil)) (read stream))) (defun safely-read-file (file) "Read the first form from FILE with SAFELY-READ." (with-open-file (stream file) (safely-read stream))) (defun make-versions-url (url) "Given an URL that looks like http://foo/bar.ext, return http://foo/bar-versions.txt." (let ((suffix-pos (position #\. url :from-end t))) (unless suffix-pos (error "Can't make a versions URL from ~A" url)) (let ((extension (subseq url suffix-pos))) (concatenate 'string (subseq url 0 suffix-pos) "-versions" extension)))) (defun call-with-temporary-file (fun template-pathname) (assert (null (pathname-directory template-pathname))) (let* ((relative-file (merge-pathnames template-pathname #p"tmp/")) (absolute-file (ql-setup:qmerge relative-file)) (randomized-file (make-pathname :name (format nil "~A-~36,5,'0R" (pathname-name template-pathname) (random #xFFFFFF)) :defaults absolute-file))) (unwind-protect (funcall fun randomized-file) (delete-file-if-exists randomized-file)))) ;;; TODO: Use this where (qmerge "tmp/...") is used, when possible (defmacro with-temporary-file ((var template) &body body) "Evaluate BODY with VAR bound to a temporary pathname created by adding random data to the pathname-name of TEMPLATE, which should be a pathname without a directory component. After evaluation, the temporary pathname is deleted if it exists." `(call-with-temporary-file (lambda (,var) ,@body) ,template))
5,189
Common Lisp
.lisp
127
31.15748
88
0.581086
enzuru/home
6
0
1
GPL-3.0
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
a030ee175e7f893a25dbab4740f40265dd396a0fb507241f970014ab0d1ac102
14,706
[ 359110 ]
14,707
deflate.lisp
enzuru_home/quicklisp/quicklisp/deflate.lisp
;;;; Deflate --- RFC 1951 Deflate Decompression ;;;; ;;;; Copyright (C) 2000-2009 PMSF IT Consulting Pierre R. Mai. ;;;; ;;;; Permission is hereby granted, free of charge, to any person obtaining ;;;; a copy of this software and associated documentation files (the ;;;; "Software"), to deal in the Software without restriction, including ;;;; without limitation the rights to use, copy, modify, merge, publish, ;;;; distribute, sublicense, and/or sell copies of the Software, and to ;;;; permit persons to whom the Software is furnished to do so, subject to ;;;; the following conditions: ;;;; ;;;; The above copyright notice and this permission notice shall be ;;;; included in all copies or substantial portions of the Software. ;;;; ;;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ;;;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ;;;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. ;;;; IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR ;;;; OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ;;;; ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR ;;;; OTHER DEALINGS IN THE SOFTWARE. ;;;; ;;;; Except as contained in this notice, the name of the author shall ;;;; not be used in advertising or otherwise to promote the sale, use or ;;;; other dealings in this Software without prior written authorization ;;;; from the author. ;;;; ;;;; $Id: 377d3a33e9db5a3b54c850619183ee555a41b894 $ (cl:in-package #:ql-gunzipper) ;;;; %File Description: ;;;; ;;;; This file contains routines implementing the RFC 1951 Deflate ;;;; Compression and/or Decompression method, as used by e.g. gzip and ;;;; other compression and archiving tools and protocols. It also ;;;; implements handling routines for zlib-style (RFC 1950) and ;;;; gzip-style (RFC 1952) wrappers around raw Deflate streams. ;;;; ;;;; The main entry points are the functions inflate-stream, and its ;;;; cousins inflate-zlib-stream and inflate-gzip-stream, which take ;;;; an input-stream and an output-stream as their arguments, and ;;;; inflate the RFC 1951, RFC 1950 or RFC 1952-style deflate formats ;;;; from the input-stream to the output-stream. ;;;; ;;; ;;; Conditions ;;; (define-condition decompression-error (simple-error) ()) (define-condition deflate-decompression-error (decompression-error) () (:report (lambda (c s) (with-standard-io-syntax (let ((*print-readably* nil)) (format s "Error detected during deflate decompression: ~?" (simple-condition-format-control c) (simple-condition-format-arguments c))))))) (define-condition zlib-decompression-error (decompression-error) () (:report (lambda (c s) (with-standard-io-syntax (let ((*print-readably* nil)) (format s "Error detected during zlib decompression: ~?" (simple-condition-format-control c) (simple-condition-format-arguments c))))))) (define-condition gzip-decompression-error (decompression-error) () (:report (lambda (c s) (with-standard-io-syntax (let ((*print-readably* nil)) (format s "Error detected during zlib decompression: ~?" (simple-condition-format-control c) (simple-condition-format-arguments c))))))) ;;; ;;; Adler-32 Checksums ;;; (defconstant +adler-32-start-value+ 1 "Start value for Adler-32 checksums as per RFC 1950.") (defconstant +adler-32-base+ 65521 "Base value for Adler-32 checksums as per RFC 1950.") (declaim (ftype (function ((unsigned-byte 32) (simple-array (unsigned-byte 8) (*)) fixnum) (unsigned-byte 32)) update-adler32-checksum)) (defun update-adler32-checksum (crc buffer end) (declare (type (unsigned-byte 32) crc) (type (simple-array (unsigned-byte 8) (*)) buffer) (type fixnum end) (optimize (speed 3) (debug 0) (space 0) (safety 0)) #+sbcl (sb-ext:muffle-conditions sb-ext:compiler-note)) (let ((s1 (ldb (byte 16 0) crc)) (s2 (ldb (byte 16 16) crc))) (declare (type (unsigned-byte 32) s1 s2)) (dotimes (i end) (declare (type fixnum i)) (setq s1 (mod (+ s1 (aref buffer i)) +adler-32-base+) s2 (mod (+ s2 s1) +adler-32-base+))) (dpb s2 (byte 16 16) s1))) ;;; ;;; CRC-32 Checksums ;;; (defconstant +crc-32-start-value+ 0 "Start value for CRC-32 checksums as per RFC 1952.") (defconstant +crc-32-polynomial+ #xedb88320 "CRC-32 Polynomial as per RFC 1952.") (declaim (ftype #-lispworks (function () (simple-array (unsigned-byte 32) (256))) #+lispworks (function () (sys:simple-int32-vector 256)) generate-crc32-table)) (defun generate-crc32-table () (let ((result #-lispworks (make-array 256 :element-type '(unsigned-byte 32)) #+lispworks (sys:make-simple-int32-vector 256))) (dotimes (i #-lispworks (length result) #+lispworks 256 result) (let ((cur i)) (dotimes (k 8) (setq cur (if (= 1 (logand cur 1)) (logxor (ash cur -1) +crc-32-polynomial+) (ash cur -1)))) #-lispworks (setf (aref result i) cur) #+lispworks (setf (sys:int32-aref result i) (sys:integer-to-int32 (dpb (ldb (byte 32 0) cur) (byte 32 0) (if (logbitp 31 cur) -1 0)))))))) (declaim (ftype (function ((unsigned-byte 32) (simple-array (unsigned-byte 8) (*)) fixnum) (unsigned-byte 32)) update-crc32-checksum)) #-lispworks (defun update-crc32-checksum (crc buffer end) (declare (type (unsigned-byte 32) crc) (type (simple-array (unsigned-byte 8) (*)) buffer) (type fixnum end) (optimize (speed 3) (debug 0) (space 0) (safety 0)) #+sbcl (sb-ext:muffle-conditions sb-ext:compiler-note)) (let ((table (load-time-value (generate-crc32-table))) (cur (logxor crc #xffffffff))) (declare (type (simple-array (unsigned-byte 32) (256)) table) (type (unsigned-byte 32) cur)) (dotimes (i end) (declare (type fixnum i)) (let ((index (logand #xff (logxor cur (aref buffer i))))) (declare (type (unsigned-byte 8) index)) (setq cur (logxor (aref table index) (ash cur -8))))) (logxor cur #xffffffff))) #+lispworks (defun update-crc32-checksum (crc buffer end) (declare (type (unsigned-byte 32) crc) (type (simple-array (unsigned-byte 8) (*)) buffer) (type fixnum end) (optimize (speed 3) (debug 0) (space 0) (safety 0) (float 0))) (let ((table (load-time-value (generate-crc32-table))) (cur (sys:int32-lognot (sys:integer-to-int32 (dpb (ldb (byte 32 0) crc) (byte 32 0) (if (logbitp 31 crc) -1 0)))))) (declare (type (sys:simple-int32-vector 256) table) (type sys:int32 cur)) (dotimes (i end) (declare (type fixnum i)) (let ((index (sys:int32-to-integer (sys:int32-logand #xff (sys:int32-logxor cur (aref buffer i)))))) (declare (type fixnum index)) (setq cur (sys:int32-logxor (sys:int32-aref table index) (sys:int32-logand #x00ffffff (sys:int32>> cur 8)))))) (ldb (byte 32 0) (sys:int32-to-integer (sys:int32-lognot cur))))) ;;; ;;; Helper Data Structures: Sliding Window Stream ;;; (eval-when (:compile-toplevel :load-toplevel :execute) (defconstant +sliding-window-size+ 32768 "Size of sliding window for RFC 1951 Deflate compression scheme.")) (defstruct sliding-window-stream (stream nil :type stream :read-only t) (buffer (make-array +sliding-window-size+ :element-type '(unsigned-byte 8)) :type (simple-array (unsigned-byte 8) (#.+sliding-window-size+)) :read-only t) (buffer-end 0 :type fixnum) (checksum nil :type symbol :read-only t) (checksum-value 0 :type (unsigned-byte 32))) (declaim (inline sliding-window-stream-write-byte)) (defun sliding-window-stream-write-byte (stream byte) (declare (type sliding-window-stream stream) (type (unsigned-byte 8) byte) #+sbcl (sb-ext:muffle-conditions sb-ext:compiler-note)) "Write a single byte to the sliding-window-stream." (let ((end (sliding-window-stream-buffer-end stream))) (declare (type fixnum end)) (unless (< end +sliding-window-size+) (write-sequence (sliding-window-stream-buffer stream) (sliding-window-stream-stream stream)) (case (sliding-window-stream-checksum stream) (:adler-32 (setf (sliding-window-stream-checksum-value stream) (update-adler32-checksum (sliding-window-stream-checksum-value stream) (sliding-window-stream-buffer stream) +sliding-window-size+))) (:crc-32 (setf (sliding-window-stream-checksum-value stream) (update-crc32-checksum (sliding-window-stream-checksum-value stream) (sliding-window-stream-buffer stream) +sliding-window-size+)))) (setq end 0)) (setf (aref (sliding-window-stream-buffer stream) end) byte (sliding-window-stream-buffer-end stream) (1+ end)))) (defun sliding-window-stream-flush (stream) (declare (type sliding-window-stream stream)) "Flush any remaining buffered bytes from the stream." (let ((end (sliding-window-stream-buffer-end stream))) (declare (type fixnum end)) (unless (zerop end) (case (sliding-window-stream-checksum stream) (:adler-32 (setf (sliding-window-stream-checksum-value stream) (update-adler32-checksum (sliding-window-stream-checksum-value stream) (sliding-window-stream-buffer stream) end))) (:crc-32 (setf (sliding-window-stream-checksum-value stream) (update-crc32-checksum (sliding-window-stream-checksum-value stream) (sliding-window-stream-buffer stream) end)))) (write-sequence (sliding-window-stream-buffer stream) (sliding-window-stream-stream stream) :end end)))) (defun sliding-window-stream-copy-bytes (stream distance length) (declare (type sliding-window-stream stream) (type fixnum distance length)) "Copy a number of bytes from the current sliding window." (let* ((end (sliding-window-stream-buffer-end stream)) (start (mod (- end distance) +sliding-window-size+)) (buffer (sliding-window-stream-buffer stream))) (declare (type fixnum end start) (type (simple-array (unsigned-byte 8) (#.+sliding-window-size+)) buffer)) (dotimes (i length) (sliding-window-stream-write-byte stream (aref buffer (mod (+ start i) +sliding-window-size+)))))) ;;; ;;; Helper Data Structures: Bit-wise Input Stream ;;; (defstruct bit-stream (stream nil :type stream :read-only t) (next-byte 0 :type fixnum) (bits 0 :type (unsigned-byte 29)) (bit-count 0 :type (unsigned-byte 8))) (declaim (inline bit-stream-get-byte)) (defun bit-stream-get-byte (stream) (declare (type bit-stream stream)) "Read another byte from the underlying stream." (the (unsigned-byte 8) (read-byte (bit-stream-stream stream)))) (declaim (inline bit-stream-read-bits)) (defun bit-stream-read-bits (stream bits) (declare (type bit-stream stream) ;; [quicklisp-added] ;; FIXME: This might be fixed soon in ECL. ;; http://article.gmane.org/gmane.lisp.ecl.general/7659 #-ecl (type (unsigned-byte 8) bits)) "Read single or multiple bits from the given bit-stream." (loop while (< (bit-stream-bit-count stream) bits) do ;; Fill bits (setf (bit-stream-bits stream) (logior (bit-stream-bits stream) (the (unsigned-byte 29) (ash (bit-stream-get-byte stream) (bit-stream-bit-count stream)))) (bit-stream-bit-count stream) (+ (bit-stream-bit-count stream) 8))) ;; Return properly masked bits (if (= (bit-stream-bit-count stream) bits) (prog1 (bit-stream-bits stream) (setf (bit-stream-bits stream) 0 (bit-stream-bit-count stream) 0)) (prog1 (ldb (byte bits 0) (bit-stream-bits stream)) (setf (bit-stream-bits stream) (ash (bit-stream-bits stream) (- bits)) (bit-stream-bit-count stream) (- (bit-stream-bit-count stream) bits))))) (declaim (inline bit-stream-copy-block)) (defun bit-stream-copy-block (stream out-stream) (declare (type bit-stream stream) (type sliding-window-stream out-stream) (optimize (speed 3) (safety 0) (space 0) (debug 0))) "Copy a given block of bytes directly from the underlying stream." ;; Skip any remaining unprocessed bits (setf (bit-stream-bits stream) 0 (bit-stream-bit-count stream) 0) ;; Get LEN/NLEN and copy bytes (let* ((len (logior (bit-stream-get-byte stream) (ash (bit-stream-get-byte stream) 8))) (nlen (ldb (byte 16 0) (lognot (logior (bit-stream-get-byte stream) (ash (bit-stream-get-byte stream) 8)))))) (unless (= len nlen) (error 'deflate-decompression-error :format-control "Block length mismatch for stored block: LEN(~D) vs. NLEN(~D)!" :format-arguments (list len nlen))) (dotimes (i len) (sliding-window-stream-write-byte out-stream (bit-stream-get-byte stream))))) ;;; ;;; Huffman Coding ;;; ;;; A decode-tree struct contains all information necessary to decode ;;; the given canonical huffman code. Note that length-count contains ;;; the number of codes with a given length for each length, whereas ;;; the code-symbols array contains the symbols corresponding to the ;;; codes in canoical order of the codes. ;;; ;;; Decoding then uses this information and the principles underlying ;;; canonical huffman codes to determine whether the currently ;;; collected word falls between the first code and the last code for ;;; the current length, and if so, uses the offset to determine the ;;; code's symbol. Otherwise more bits are needed. (defstruct decode-tree (length-count (make-array 16 :element-type 'fixnum :initial-element 0) :type (simple-array fixnum (*)) :read-only t) (code-symbols (make-array 16 :element-type 'fixnum :initial-element 0) :type (simple-array fixnum (*)))) (defun make-huffman-decode-tree (code-lengths) "Construct a huffman decode-tree for the canonical huffman code with the code lengths of each symbol given in the input array." (let* ((max-length (reduce #'max code-lengths :initial-value 0)) (next-code (make-array (1+ max-length) :element-type 'fixnum :initial-element 0)) (code-symbols (make-array (length code-lengths) :element-type 'fixnum :initial-element 0)) (length-count (make-array (1+ max-length) :element-type 'fixnum :initial-element 0))) ;; Count length occurences and calculate offsets of smallest codes (loop for index from 1 to max-length for code = 0 then (+ code (aref length-count (1- index))) do (setf (aref next-code index) code) initially ;; Count length occurences (loop for length across code-lengths do (incf (aref length-count length)) finally (setf (aref length-count 0) 0))) ;; Construct code symbols mapping (loop for length across code-lengths for index upfrom 0 unless (zerop length) do (setf (aref code-symbols (aref next-code length)) index) (incf (aref next-code length))) ;; Return result (make-decode-tree :length-count length-count :code-symbols code-symbols))) (declaim (inline read-huffman-code)) (defun read-huffman-code (bit-stream decode-tree) (declare (type bit-stream bit-stream) (type decode-tree decode-tree) (optimize (speed 3) (safety 0) (space 0) (debug 0))) "Read the next huffman code word from the given bit-stream and return its decoded symbol, for the huffman code given by decode-tree." (loop with length-count of-type (simple-array fixnum (*)) = (decode-tree-length-count decode-tree) with code-symbols of-type (simple-array fixnum (*)) = (decode-tree-code-symbols decode-tree) for code of-type fixnum = (bit-stream-read-bits bit-stream 1) then (+ (* code 2) (bit-stream-read-bits bit-stream 1)) for index of-type fixnum = 0 then (+ index count) for first of-type fixnum = 0 then (* (+ first count) 2) for length of-type fixnum upfrom 1 below (length length-count) for count = (aref length-count length) thereis (when (< code (the fixnum (+ first count))) (aref code-symbols (+ index (- code first)))) finally (error 'deflate-decompression-error :format-control "Corrupted Data detected during decompression: ~ Incorrect huffman code (~X) in huffman decode!" :format-arguments (list code)))) ;;; ;;; Standard Huffman Tables ;;; (defparameter *std-lit-decode-tree* (make-huffman-decode-tree (concatenate 'vector (make-sequence 'vector 144 :initial-element 8) (make-sequence 'vector 112 :initial-element 9) (make-sequence 'vector 24 :initial-element 7) (make-sequence 'vector 8 :initial-element 8)))) (defparameter *std-dist-decode-tree* (make-huffman-decode-tree (make-sequence 'vector 32 :initial-element 5))) ;;; ;;; Dynamic Huffman Table Handling ;;; (defparameter *code-length-entry-order* #(16 17 18 0 8 7 9 6 10 5 11 4 12 3 13 2 14 1 15) "Order of Code Length Tree Code Lengths.") (defun decode-code-length-entries (bit-stream count decode-tree) "Decode the given number of code length entries from the bit-stream using the given decode-tree, and return a corresponding array of code lengths for further processing." (do ((result (make-array count :element-type 'fixnum :initial-element 0)) (index 0)) ((>= index count) result) (let ((code (read-huffman-code bit-stream decode-tree))) (ecase code ((0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) (setf (aref result index) code) (incf index)) (16 (let ((length (+ 3 (bit-stream-read-bits bit-stream 2)))) (dotimes (i length) (setf (aref result (+ index i)) (aref result (1- index)))) (incf index length))) (17 (let ((length (+ 3 (bit-stream-read-bits bit-stream 3)))) (dotimes (i length) (setf (aref result (+ index i)) 0)) (incf index length))) (18 (let ((length (+ 11 (bit-stream-read-bits bit-stream 7)))) (dotimes (i length) (setf (aref result (+ index i)) 0)) (incf index length))))))) (defun decode-huffman-tables (bit-stream) "Decode the stored huffman tables from the given bit-stream, returning the corresponding decode-trees for literals/length and distance codes." (let* ((hlit (bit-stream-read-bits bit-stream 5)) (hdist (bit-stream-read-bits bit-stream 5)) (hclen (bit-stream-read-bits bit-stream 4))) ;; Construct Code Length Decode Tree (let ((cl-decode-tree (loop with code-lengths = (make-array 19 :element-type '(unsigned-byte 8) :initial-element 0) for index from 0 below (+ hclen 4) for code-length = (bit-stream-read-bits bit-stream 3) for code-index = (aref *code-length-entry-order* index) do (setf (aref code-lengths code-index) code-length) finally (return (make-huffman-decode-tree code-lengths))))) ;; Decode Code Length Table and generate separate huffman trees (let ((entries (decode-code-length-entries bit-stream (+ hlit 257 hdist 1) cl-decode-tree))) (values (make-huffman-decode-tree (subseq entries 0 (+ hlit 257))) (make-huffman-decode-tree (subseq entries (+ hlit 257)))))))) ;;; ;;; Compressed Block Handling ;;; (declaim (inline decode-length-entry)) (defun decode-length-entry (symbol bit-stream) "Decode the given length symbol into a proper length specification." (cond ((<= symbol 264) (- symbol 254)) ((<= symbol 268) (+ 11 (* (- symbol 265) 2) (bit-stream-read-bits bit-stream 1))) ((<= symbol 272) (+ 19 (* (- symbol 269) 4) (bit-stream-read-bits bit-stream 2))) ((<= symbol 276) (+ 35 (* (- symbol 273) 8) (bit-stream-read-bits bit-stream 3))) ((<= symbol 280) (+ 67 (* (- symbol 277) 16) (bit-stream-read-bits bit-stream 4))) ((<= symbol 284) (+ 131 (* (- symbol 281) 32) (bit-stream-read-bits bit-stream 5))) ((= symbol 285) 258) (t (error 'deflate-decompression-error :format-control "Strange Length Code in bitstream: ~D" :format-arguments (list symbol))))) (declaim (inline decode-distance-entry)) (defun decode-distance-entry (symbol bit-stream) "Decode the given distance symbol into a proper distance specification." (cond ((<= symbol 3) (1+ symbol)) (t (multiple-value-bind (order offset) (truncate symbol 2) (let* ((extra-bits (1- order)) (factor (ash 1 extra-bits))) (+ (1+ (ash 1 order)) (* offset factor) (bit-stream-read-bits bit-stream extra-bits))))))) (defun decode-huffman-block (bit-stream window-stream lit-decode-tree dist-decode-tree) "Decode the huffman code block using the huffman codes given by lit-decode-tree and dist-decode-tree." (do ((symbol (read-huffman-code bit-stream lit-decode-tree) (read-huffman-code bit-stream lit-decode-tree))) ((= symbol 256)) (cond ((<= symbol 255) (sliding-window-stream-write-byte window-stream symbol)) (t (let ((length (decode-length-entry symbol bit-stream)) (distance (decode-distance-entry (read-huffman-code bit-stream dist-decode-tree) bit-stream))) (sliding-window-stream-copy-bytes window-stream distance length)))))) ;;; ;;; Block Handling Code ;;; (defun decode-block (bit-stream window-stream) "Decompress a block read from bit-stream into window-stream." (let* ((finalp (not (zerop (bit-stream-read-bits bit-stream 1)))) (type (bit-stream-read-bits bit-stream 2))) (ecase type (#b00 (bit-stream-copy-block bit-stream window-stream)) (#b01 (decode-huffman-block bit-stream window-stream *std-lit-decode-tree* *std-dist-decode-tree*)) (#b10 (multiple-value-bind (lit-decode-tree dist-decode-tree) (decode-huffman-tables bit-stream) (decode-huffman-block bit-stream window-stream lit-decode-tree dist-decode-tree))) (#b11 (error 'deflate-decompression-error :format-control "Encountered Reserved Block Type ~D!" :format-arguments (list type)))) (not finalp))) ;;; ;;; ZLIB - RFC 1950 handling ;;; (defun parse-zlib-header (input-stream) "Parse a ZLIB-style header as per RFC 1950 from the input-stream and return the compression-method, compression-level dictionary-id and flags fields of the header as return values. Checks the header for corruption and signals a zlib-decompression-error in case of corruption." (let ((compression-method (read-byte input-stream)) (flags (read-byte input-stream))) (unless (zerop (mod (+ (* compression-method 256) flags) 31)) (error 'zlib-decompression-error :format-control "Corrupted Header ~2,'0X,~2,'0X!" :format-arguments (list compression-method flags))) (let ((dict (unless (zerop (ldb (byte 1 5) flags)) (parse-zlib-checksum input-stream)))) (values (ldb (byte 4 0) compression-method) (ldb (byte 4 4) compression-method) dict (ldb (byte 2 6) flags))))) (defun parse-zlib-checksum (input-stream) (+ (* (read-byte input-stream) 256 256 256) (* (read-byte input-stream) 256 256) (* (read-byte input-stream) 256) (read-byte input-stream))) (defun parse-zlib-footer (input-stream) "Parse the ZLIB-style footer as per RFC 1950 from the input-stream and return the Adler-32 checksum contained in the footer as its return value." (parse-zlib-checksum input-stream)) ;;; ;;; GZIP - RFC 1952 handling ;;; (defconstant +gzip-header-id1+ 31 "GZIP Header Magic Value ID1 as per RFC 1952.") (defconstant +gzip-header-id2+ 139 "GZIP Header Magic Value ID2 as per RFC 1952.") (defun parse-gzip-header (input-stream) "Parse a GZIP-style header as per RFC 1952 from the input-stream and return the compression-method, text-flag, modification time, XFLAGS, OS, FEXTRA flags, filename, comment and CRC16 fields of the header as return values (or nil if any given field is not present). Checks the header for magic values and correct flags settings and signals a gzip-decompression-error in case of incorrect or unsupported magic values or flags." (let ((id1 (read-byte input-stream)) (id2 (read-byte input-stream)) (compression-method (read-byte input-stream)) (flags (read-byte input-stream))) (unless (and (= id1 +gzip-header-id1+) (= id2 +gzip-header-id2+)) (error 'gzip-decompression-error :format-control "Header missing magic values ~2,'0X,~2,'0X (got ~2,'0X,~2,'0X instead)!" :format-arguments (list +gzip-header-id1+ +gzip-header-id2+ id1 id2))) (unless (= compression-method 8) (error 'gzip-decompression-error :format-control "Unknown compression-method in Header ~2,'0X!" :format-arguments (list compression-method))) (unless (zerop (ldb (byte 3 5) flags)) (error 'gzip-decompression-error :format-control "Unknown flags in Header ~2,'0X!" :format-arguments (list flags))) (values compression-method ;; FTEXT (= 1 (ldb (byte 1 0) flags)) ;; MTIME (parse-gzip-mtime input-stream) ;; XFLAGS (read-byte input-stream) ;; OS (read-byte input-stream) ;; FEXTRA (unless (zerop (ldb (byte 1 2) flags)) (parse-gzip-extra input-stream)) ;; FNAME (unless (zerop (ldb (byte 1 3) flags)) (parse-gzip-string input-stream)) ;; FCOMMENT (unless (zerop (ldb (byte 1 4) flags)) (parse-gzip-string input-stream)) ;; CRC16 (unless (zerop (ldb (byte 1 1) flags)) (+ (read-byte input-stream) (* (read-byte input-stream 256))))))) (defun parse-gzip-mtime (input-stream) (let ((time (+ (read-byte input-stream) (* (read-byte input-stream) 256) (* (read-byte input-stream) 256 256) (* (read-byte input-stream) 256 256 256)))) (if (zerop time) nil (+ time 2208988800)))) (defun parse-gzip-extra (input-stream) (let* ((length (+ (read-byte input-stream) (* (read-byte input-stream) 256))) (result (make-array length :element-type '(unsigned-byte 8)))) (read-sequence result input-stream) result)) (defun parse-gzip-string (input-stream) (with-output-to-string (string) (loop for value = (read-byte input-stream) until (zerop value) do (write-char (code-char value) string)))) (defun parse-gzip-checksum (input-stream) (+ (read-byte input-stream) (* (read-byte input-stream) 256) (* (read-byte input-stream) 256 256) (* (read-byte input-stream) 256 256 256))) (defun parse-gzip-footer (input-stream) "Parse the GZIP-style footer as per RFC 1952 from the input-stream and return the CRC-32 checksum and ISIZE fields contained in the footer as its return values." (values (parse-gzip-checksum input-stream) ;; ISIZE (+ (read-byte input-stream) (* (read-byte input-stream) 256) (* (read-byte input-stream) 256 256) (* (read-byte input-stream) 256 256 256)))) ;;; ;;; Main Entry Points ;;; (defun inflate-stream (input-stream output-stream &key checksum) "Inflate the RFC 1951 data from the given input stream into the given output stream, which are required to have an element-type of (unsigned-byte 8). If checksum is given, it indicates the checksumming algorithm to employ in calculating a checksum of the expanded content, which is then returned from this function. Valid values are :adler-32 for Adler-32 checksum (see RFC 1950), or :crc-32 for CRC-32 as per ISO 3309 (see RFC 1952, ZIP)." (loop with window-stream = (make-sliding-window-stream :stream output-stream :checksum checksum :checksum-value (ecase checksum ((nil) 0) (:crc-32 +crc-32-start-value+) (:adler-32 +adler-32-start-value+))) with bit-stream = (make-bit-stream :stream input-stream) while (decode-block bit-stream window-stream) finally (sliding-window-stream-flush window-stream) (when checksum (return (sliding-window-stream-checksum-value window-stream))))) (defun inflate-zlib-stream (input-stream output-stream &key check-checksum) "Inflate the RFC 1950 zlib data from the given input stream into the given output stream, which are required to have an element-type of (unsigned-byte 8). This returns the Adler-32 checksum of the file as its first return value, with the compression level as its second return value. Note that it is the responsibility of the caller to check whether the expanded data matches the Adler-32 checksum, unless the check-checksum keyword argument is set to true, in which case the checksum is checked internally and a zlib-decompression-error is signalled if they don't match." (multiple-value-bind (cm cinfo dictid flevel) (parse-zlib-header input-stream) (unless (= cm 8) (error 'zlib-decompression-error :format-control "Unknown compression method ~D!" :format-arguments (list cm))) (unless (<= cinfo 7) (error 'zlib-decompression-error :format-control "Unsupported sliding window size 2^~D = ~D!" :format-arguments (list (+ 8 cinfo) (expt 2 (+ 8 cinfo))))) (unless (null dictid) (error 'zlib-decompression-error :format-control "Unknown preset dictionary id ~8,'0X!" :format-arguments (list dictid))) (let ((checksum-new (inflate-stream input-stream output-stream :checksum (when check-checksum :adler-32))) (checksum-old (parse-zlib-footer input-stream))) (when (and check-checksum (not (= checksum-old checksum-new))) (error 'zlib-decompression-error :format-control "Checksum mismatch for decompressed stream: ~8,'0X != ~8,'0X!" :format-arguments (list checksum-old checksum-new))) (values checksum-old flevel)))) (defun inflate-gzip-stream (input-stream output-stream &key check-checksum) "Inflate the RFC 1952 gzip data from the given input stream into the given output stream, which are required to have an element-type of (unsigned-byte 8). This returns the CRC-32 checksum of the file as its first return value, with any filename, modification time, and comment fields as further return values or nil if not present. Note that it is the responsibility of the caller to check whether the expanded data matches the CRC-32 checksum, unless the check-checksum keyword argument is set to true, in which case the checksum is checked internally and a gzip-decompression-error is signalled if they don't match." (multiple-value-bind (cm ftext mtime xfl os fextra fname fcomment) (parse-gzip-header input-stream) (declare (ignore ftext xfl os fextra)) (unless (= cm 8) (error 'gzip-decompression-error :format-control "Unknown compression method ~D!" :format-arguments (list cm))) (let ((checksum-new (inflate-stream input-stream output-stream :checksum (when check-checksum :crc-32))) (checksum-old (parse-gzip-footer input-stream))) ;; Handle Checksums (when (and check-checksum (not (= checksum-old checksum-new))) (error 'gzip-decompression-error :format-control "Checksum mismatch for decompressed stream: ~8,'0X != ~8,'0X!" :format-arguments (list checksum-old checksum-new))) (values checksum-old fname mtime fcomment)))) (defun gunzip (input-file output-file) (with-open-file (input input-file :element-type '(unsigned-byte 8)) (with-open-file (output output-file :direction :output :if-exists :supersede :element-type '(unsigned-byte 8)) (inflate-gzip-stream input output))) (probe-file output-file))
34,317
Common Lisp
.lisp
720
39.097222
86
0.630663
enzuru/home
6
0
1
GPL-3.0
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
0a1539373c136cb5c8ebeab159ba1a06a85cd2a53fb82ac8990294b3f2c7bf90
14,707
[ 166042, 351806 ]
14,708
dist.lisp
enzuru_home/quicklisp/quicklisp/dist.lisp
;;;; dist.lisp (in-package #:ql-dist) ;;; Generic functions (defgeneric dist (object) (:documentation "Return the dist of OBJECT.")) (defgeneric available-versions (object) (:documentation "Return a list of version information for OBJECT.")) (defgeneric system-index-url (object) (:documentation "Return the URL for the system index of OBJECT.")) (defgeneric release-index-url (object) (:documentation "Return the URL for the release index of OBJECT.")) (defgeneric available-versions-url (object) (:documentation "Return the URL for the available versions data file of OBJECT.")) (defgeneric release (object) (:documentation "Return the release of OBJECT.")) (defgeneric system (object) (:documentation "Return the system of OBJECT.")) (defgeneric name (object) (:documentation "Return the name of OBJECT.")) (defgeneric find-system (name) (:documentation "Return a system with the given NAME, or NIL if no system is found. If multiple systems have the same name, the one with the highest preference is returned.")) (defgeneric find-release (name) (:documentation "Return a release with the given NAME, or NIL if no system is found. If multiple releases have the same name, the one with the highest preference is returned.")) (defgeneric find-systems-named (name) (:documentation "Return a list of all systems in all enabled dists with the given NAME, sorted by preference.")) (defgeneric find-releases-named (name) (:documentation "Return a list of all releases in all enabled dists with the given NAME, sorted by preference.")) (defgeneric base-directory (object) (:documentation "Return the base directory pathname of OBJECT.") (:method ((object pathname)) (merge-pathnames object))) (defgeneric relative-to (object pathname) (:documentation "Merge PATHNAME with the base-directory of OBJECT.") (:method (object pathname) (merge-pathnames pathname (base-directory object)))) (defgeneric enabledp (object) (:documentation "Return true if OBJECT is enabled.")) (defgeneric enable (object) (:documentation "Enable OBJECT.")) (defgeneric disable (object) (:documentation "Disable OBJECT.")) (defgeneric installedp (object) (:documentation "Return true if OBJECT is installed.")) (defgeneric install (object) (:documentation "Install OBJECT.")) (defgeneric ensure-installed (object) (:documentation "Ensure that OBJECT is installed.") (:method (object) (unless (installedp object) (install object)) object)) (defgeneric uninstall (object) (:documentation "Uninstall OBJECT.")) (defgeneric metadata-name (object) (:documentation "The metadata-name of an object is used to form the pathname for a few different object metadata files.")) (defgeneric install-metadata-file (object) (:documentation "The pathname to a file describing the installation status of OBJECT.")) (defgeneric subscription-inhibition-file (object) (:documentation "The file whose presence indicates the inhibited subscription status of OBJECT.") (:method (object) (relative-to object "subscription-inhibited.txt"))) (defgeneric inhibit-subscription (object) (:documentation "Inhibit subscription for OBJECT.") (:method (object) (ensure-file-exists (subscription-inhibition-file object)))) (defgeneric uninhibit-subscription (object) (:documentation "Remove inhibition of subscription for OBJECT.") (:method (object) (delete-file-if-exists (subscription-inhibition-file object)))) (defgeneric subscription-inhibited-p (object) (:documentation "Return T if subscription to OBJECT is inhibited.") (:method (object) (not (not (probe-file (subscription-inhibition-file object)))))) (define-condition subscription-unavailable (error) ((object :initarg :object :reader subscription-unavailable-object))) (defgeneric subscribedp (object) (:documentation "Return true if OBJECT is subscribed to updates.")) (defgeneric subscribe (object) (:documentation "Subscribe to updates of OBJECT, if possible. If no updates are available, a condition of type SUBSCRIPTION-UNAVAILABLE is raised.") (:method (object) (uninhibit-subscription object) (unless (subscribedp object) (error 'subscription-unavailable :object object)) t)) (defgeneric unsubscribe (object) (:documentation "Unsubscribe from updates to OBJECT.") (:method (object) (inhibit-subscription object))) (defgeneric preference-parent (object) (:documentation "Return a value suitable for checking if OBJECT has no specific preference set.") (:method (object) (declare (ignore object)) nil)) (defgeneric preference-file (object) (:documentation "Return the file from which preference information is loaded for OBJECT.") (:method (object) (relative-to object "preference.txt"))) (defgeneric preference (object) (:documentation "Returns a value used when comparing multiple systems or releases with the same name. Objects with higher preference are returned by FIND-SYSTEM and FIND-RELEASE.") (:method ((object null)) 0) (:method (object) (with-open-file (stream (preference-file object) :if-does-not-exist nil) (if stream (values (parse-integer (read-line stream))) (preference (preference-parent object)))))) (defgeneric (setf preference) (preference object) (:documentation "Set the preference for OBJECT. Objects with higher preference are returned by FIND-SYSTEM and FIND-RELEASE.") (:method (preference object) (check-type preference integer) (let ((preference-file (preference-file object))) (ensure-directories-exist preference-file) (with-open-file (stream (preference-file object) :direction :output :if-exists :supersede) (format stream "~D" preference))) preference)) (defgeneric forget-preference (object) (:documentation "Remove specific preference information for OBJECT.") (:method (object) (delete-file-if-exists (preference-file object)))) (defgeneric short-description (object) (:documentation "Return a short string describing OBJECT.")) (defgeneric provided-releases (object) (:documentation "Return a list of releases provided by OBJECT.")) (defgeneric provided-systems (object) (:documentation "Return a list of systems provided by OBJECT.")) (defgeneric installed-releases (dist) (:documentation "Return a list of all releases installed for DIST.") (:method (dist) (remove-if-not #'installedp (provided-releases dist)))) (defgeneric installed-systems (dist) (:documentation "Return a list of all systems installed for DIST.") (:method (dist) (remove-if-not #'installedp (provided-systems dist)))) (defgeneric new-version-available-p (dist) (:documentation "Return true if a new version of DIST is available.")) (defgeneric find-system-in-dist (system-name dist) (:documentation "Return a system with the given NAME in DIST, or NIL if no system is found.")) (defgeneric find-release-in-dist (release-name dist) (:documentation "Return a release with the given NAME in DIST, or NIL if no release is found.")) (defgeneric ensure-system-index-file (dist) (:documentation "Return the pathname for the system index file of DIST, fetching it from a remote source first if necessary.")) (defgeneric ensure-system-cdb-file (dist) (:documentation "Return the pathname for the system cdb file of DIST, creating it if necessary.")) (defgeneric ensure-release-index-file (dist) (:documentation "Return the pathname for the release index file of DIST, fetching it from a remote source first if necessary.")) (defgeneric ensure-release-cdb-file (dist) (:documentation "Return the pathname for the release cdb file of DIST, creating it if necessary.")) (defgeneric initialize-release-index (dist) (:documentation "Initialize the release index of DIST.")) (defgeneric initialize-system-index (dist) (:documentation "Initialize the system index of DIST.")) (defgeneric local-archive-file (release) (:documentation "Return the pathname to where the archive file of RELEASE should be stored.")) (defgeneric ensure-local-archive-file (release) (:documentation "If the archive file for RELEASE is not available locally, fetch it and return the pathname to it.")) (defgeneric check-local-archive-file (release) (:documentation "Check the local archive file of RELEASE for validity, including size and signature checks. Signals errors in the case of invalid files.")) (defgeneric archive-url (release) (:documentation "Return the full URL for fetching the archive file of RELEASE.")) (defgeneric installed-asdf-system-file (object) (:documentation "Return the path to the installed ASDF system file for OBJECT, or NIL if there is no installed system file.")) (eval-when (:compile-toplevel :load-toplevel :execute) (defmacro destructure-line (lambda-list line &body body) `(destructuring-bind ,lambda-list (split-spaces ,line) ,@body)) (defun call-for-each-line (fun file) (with-open-file (stream file) (loop for line = (read-line stream nil) while line do (funcall fun line)))) (defmacro for-each-line ((line file) &body body) `(call-for-each-line (lambda (,line) ,@body) ,file))) (defun make-line-instance (line class &rest initargs) "Create an instance from words in an index file line. The last initarg collects all the trailing arguments, if any." (let* ((words (split-spaces line)) (args (mapcan #'list (butlast initargs) words)) (trailing (subseq words (1- (length initargs))))) (apply #'make-instance class (first (last initargs)) trailing args))) (defun ignorable-line (line) (labels ((blank-char-p (char) (member char '(#\Space #\Tab))) (blankp (line) (every #'blank-char-p line)) (ignorable (line) (or (zerop (length line)) (blankp line) (eql (char line 0) #\#)))) (ignorable line))) (defvar *initarg-case-converter* (cond ((string= :string "string") #'string-downcase) ((string= :string "STRING") #'string-upcase))) (defun config-file-initargs (file) (flet ((initarg-keyword (string) ;; A concession to mlisp (intern (funcall *initarg-case-converter* string) 'keyword))) (let ((initargs '())) (for-each-line (line file) (unless (ignorable-line line) (destructure-line (initarg value) line (let ((keyword (initarg-keyword (string-right-trim ":" initarg)))) (push value initargs) (push keyword initargs))))) initargs))) ;;; ;;; A few generic things ;;; (defmethod dist ((name symbol)) (dist (string name))) (defmethod dist ((name string)) (find-dist (string-downcase name))) (defmethod release ((name symbol)) (release (string name))) (defmethod release ((name string)) (find-release (string-downcase name))) (defmethod system ((name symbol)) (system (string name))) (defmethod system ((name string)) (find-system (string-downcase name))) ;;; ;;; Dists ;;; ;;; A dist is a set of releases. ;;; (defclass dist () ((base-directory :initarg :base-directory :accessor base-directory) (name :initarg :name :accessor name) (version :initarg :version :accessor version) (system-index-url :initarg :system-index-url :accessor system-index-url) (release-index-url :initarg :release-index-url :accessor release-index-url) (available-versions-url :initarg :available-versions-url :accessor available-versions-url) (archive-base-url :initarg :archive-base-url :accessor archive-base-url) (canonical-distinfo-url :initarg :canonical-distinfo-url :accessor canonical-distinfo-url) (distinfo-subscription-url :initarg :distinfo-subscription-url :accessor distinfo-subscription-url) (system-index :initarg :system-index :accessor system-index) (release-index :initarg :release-index :accessor release-index) (provided-systems :initarg :provided-systems :accessor provided-systems) (provided-releases :initarg :provided-releases :accessor provided-releases) (local-distinfo-file :initarg :local-distinfo-file :accessor local-distinfo-file)) (:default-initargs :name "unnamed" :version "unknown" :distinfo-subscription-url nil)) (defmethod short-description ((dist dist)) (format nil "~A ~A" (name dist) (version dist))) (defmethod print-object ((dist dist) stream) (print-unreadable-object (dist stream :type t) (write-string (short-description dist) stream))) (defun cdb-lookup (dist key cdb) (ql-cdb:lookup key (relative-to dist cdb))) (defmethod slot-unbound (class (dist dist) (slot (eql 'available-versions-url))) (declare (ignore class)) (setf (available-versions-url dist) (make-versions-url (distinfo-subscription-url dist)))) (defmethod ensure-system-index-file ((dist dist)) (let ((pathname (relative-to dist "systems.txt"))) (or (probe-file pathname) (nth-value 1 (fetch (system-index-url dist) pathname))))) (defmethod ensure-system-cdb-file ((dist dist)) (let* ((system-file (ensure-system-index-file dist)) (cdb-file (make-pathname :type "cdb" :defaults system-file))) (or (probe-file cdb-file) (ql-cdb:convert-index-file system-file :cdb-file cdb-file :index 2)))) (defmethod ensure-release-index-file ((dist dist)) (let ((pathname (relative-to dist "releases.txt"))) (or (probe-file pathname) (nth-value 1 (fetch (release-index-url dist) pathname))))) (defmethod ensure-release-cdb-file ((dist dist)) (let* ((release-file (ensure-release-index-file dist)) (cdb-file (make-pathname :type "cdb" :defaults release-file))) (or (probe-file cdb-file) (ql-cdb:convert-index-file release-file :cdb-file cdb-file :index 0)))) (defmethod slot-unbound (class (dist dist) (slot (eql 'provided-systems))) (declare (ignore class)) (initialize-system-index dist) (setf (slot-value dist 'provided-systems) (loop for system being each hash-value of (system-index dist) collect system))) (defmethod slot-unbound (class (dist dist) (slot (eql 'provided-releases))) (declare (ignore class)) (initialize-release-index dist) (setf (slot-value dist 'provided-releases) (loop for system being each hash-value of (release-index dist) collect system))) (defun dist-name-pathname (name) "Return the pathname that would be used for an installed dist with the given NAME." (qmerge (make-pathname :directory (list :relative "dists" name)))) (defmethod slot-unbound (class (dist dist) (slot (eql 'base-directory))) (declare (ignore class)) (setf (base-directory dist) (dist-name-pathname (name dist)))) (defun make-dist-from-file (file &key (class 'dist)) "Load dist info from FILE and use it to create a dist instance." (let ((initargs (config-file-initargs file))) (apply #'make-instance class :local-distinfo-file file :allow-other-keys t initargs))) (defmethod install-metadata-file ((dist dist)) (relative-to dist "distinfo.txt")) (defun find-dist (name) (find name (all-dists) :key #'name :test #'string=)) (defmethod enabledp ((dist dist)) (not (not (probe-file (relative-to dist "enabled.txt"))))) (defmethod enable ((dist dist)) (ensure-file-exists (relative-to dist "enabled.txt")) t) (defmethod disable ((dist dist)) (delete-file-if-exists (relative-to dist "enabled.txt")) t) (defmethod installedp ((dist dist)) (let ((installed (find-dist (name dist)))) (equalp (version installed) (version dist)))) (defmethod uninstall ((dist dist)) (when (installedp dist) (dolist (system (provided-systems dist)) (asdf:clear-system (name system))) (ql-impl-util:delete-directory-tree (base-directory dist)) t)) (defun make-release-from-line (line dist) (let ((release (make-line-instance line 'release :project-name :archive-url :archive-size :archive-md5 :archive-content-sha1 :prefix :system-files))) (setf (dist release) dist) (setf (archive-size release) (parse-integer (archive-size release))) release)) (defmethod find-release-in-dist (release-name (dist dist)) (let* ((index (release-index dist)) (release (gethash release-name index))) (or release (let ((line (cdb-lookup dist release-name (ensure-release-cdb-file dist)))) (when line (setf (gethash release-name index) (make-release-from-line line dist))))))) (defparameter *dist-enumeration-functions* '(standard-dist-enumeration-function) "ALL-DISTS calls each function in this list with no arguments, and appends the results into a list of dist objects, removing duplicates. Functions might be called just once for a batch of related operations; see WITH-CONSISTENT-DISTS.") (defun standard-dist-enumeration-function () "The default function used for producing a list of dist objects." (loop for file in (directory (qmerge "dists/*/distinfo.txt")) collect (make-dist-from-file file))) (defun all-dists () "Return a list of all known dists." (remove-duplicates (apply 'append (mapcar 'funcall *dist-enumeration-functions*)))) (defun enabled-dists () "Return a list of all known dists for which ENABLEDP returns true." (remove-if-not #'enabledp (all-dists))) (defmethod install-metadata-file (object) (relative-to (dist object) (make-pathname :directory (list :relative "installed" (metadata-name object)) :name (name object) :type "txt"))) (defclass preference-mixin () () (:documentation "Instances of this class have a special location for their preference files.")) (defgeneric filesystem-name (object) (:method (object) ;; This is to work around system names like "foo/bar". (let* ((name (name object)) (slash (position #\/ name))) (if slash (subseq name 0 slash) name)))) (defmethod preference-file ((object preference-mixin)) (relative-to (dist object) (make-pathname :directory (list :relative "preferences" (metadata-name object)) :name (filesystem-name object) :type "txt"))) (defmethod distinfo-subscription-url :around ((dist dist)) (unless (subscription-inhibited-p dist) (call-next-method))) (defmethod subscribedp ((dist dist)) (distinfo-subscription-url dist)) ;;; ;;; Releases ;;; (defclass release (preference-mixin) ((project-name :initarg :project-name :accessor name :accessor project-name) (dist :initarg :dist :accessor dist :reader preference-parent) (provided-systems :initarg :provided-systems :accessor provided-systems) (archive-url :initarg :archive-url :accessor archive-url) (archive-size :initarg :archive-size :accessor archive-size) (archive-md5 :initarg :archive-md5 :accessor archive-md5) (archive-content-sha1 :initarg :archive-content-sha1 :accessor archive-content-sha1) (prefix :initarg :prefix :accessor prefix :reader short-description) (system-files :initarg :system-files :accessor system-files) (metadata-name :initarg :metadata-name :accessor metadata-name)) (:default-initargs :metadata-name "releases") (:documentation "Instances of this class represent a snapshot of a project at some point in time, which might be from version control, or from an official release, or from some other source.")) (defmethod print-object ((release release) stream) (print-unreadable-object (release stream :type t) (format stream "~A / ~A" (short-description release) (short-description (dist release))))) (define-condition invalid-local-archive (error) ((release :initarg :release :reader invalid-local-archive-release) (file :initarg :file :reader invalid-local-archive-file)) (:report (lambda (condition stream) (format stream "The archive file ~S for release ~S is invalid" (file-namestring (invalid-local-archive-file condition)) (name (invalid-local-archive-release condition)))))) (define-condition missing-local-archive (invalid-local-archive) () (:report (lambda (condition stream) (format stream "The archive file ~S for release ~S is missing" (file-namestring (invalid-local-archive-file condition)) (name (invalid-local-archive-release condition)))))) (define-condition badly-sized-local-archive (invalid-local-archive) ((expected-size :initarg :expected-size :reader badly-sized-local-archive-expected-size) (actual-size :initarg :actual-size :reader badly-sized-local-archive-actual-size)) (:report (lambda (condition stream) (format stream "The archive file ~S for ~S is the wrong size: ~ expected ~:D, got ~:D" (file-namestring (invalid-local-archive-file condition)) (name (invalid-local-archive-release condition)) (badly-sized-local-archive-expected-size condition) (badly-sized-local-archive-actual-size condition))))) (defmethod check-local-archive-file ((release release)) (let ((file (local-archive-file release))) (unless (probe-file file) (error 'missing-local-archive :file file :release release)) (let ((actual-size (file-size file)) (expected-size (archive-size release))) (unless (= actual-size expected-size) (error 'badly-sized-local-archive :file file :release release :actual-size actual-size :expected-size expected-size))))) (defmethod local-archive-file ((release release)) (relative-to (dist release) (make-pathname :directory '(:relative "archives") :defaults (file-namestring (path (url (archive-url release))))))) (defmethod ensure-local-archive-file ((release release)) (let ((pathname (local-archive-file release))) (tagbody :retry (or (probe-file pathname) (progn (ensure-directories-exist pathname) (fetch (archive-url release) pathname))) (restart-case (check-local-archive-file release) (delete-and-retry (&optional v) :report "Delete the archive file and fetch it again" (declare (ignore v)) (delete-file pathname) (go :retry)))) pathname)) (defmethod base-directory ((release release)) (relative-to (dist release) (make-pathname :directory (list :relative "software" (prefix release))))) (defmethod installedp ((release release)) (and (probe-file (install-metadata-file release)) (every #'installedp (provided-systems release)))) (defmethod install ((release release)) (let ((archive (ensure-local-archive-file release)) (output (relative-to (dist release) (make-pathname :directory (list :relative "software")))) (tracking (install-metadata-file release))) (with-temporary-file (tar "release-install.tar") (ensure-directories-exist tar) (ensure-directories-exist output) (ensure-directories-exist tracking) (gunzip archive tar) (unpack-tarball tar :directory output)) (ensure-directories-exist tracking) (with-open-file (stream tracking :direction :output :if-exists :supersede) (write-line (qenough (base-directory release)) stream)) (let ((provided (provided-systems release)) (dist (dist release))) (dolist (file (system-files release)) (let ((system (find-system-in-dist (pathname-name file) dist))) (unless (member system provided) (error "FIND-SYSTEM-IN-DIST returned ~A but I expected one of ~A" system provided)) (let ((system-tracking (install-metadata-file system)) (system-file (merge-pathnames file (base-directory release)))) (ensure-directories-exist system-tracking) (unless (probe-file system-file) (error "Release claims to have ~A, but I can't find it" system-file)) (with-open-file (stream system-tracking :direction :output :if-exists :supersede) (write-line (qenough system-file) stream)))))) release)) (defmethod uninstall ((release release)) (when (installedp release) (dolist (system (installed-systems release)) (asdf:clear-system (name system)) (delete-file (install-metadata-file system))) (delete-file (install-metadata-file release)) (delete-file (local-archive-file release)) (ql-impl-util:delete-directory-tree (base-directory release)) t)) (defun call-for-each-index-entry (file fun) (labels ((blank-char-p (char) (member char '(#\Space #\Tab))) (blankp (line) (every #'blank-char-p line)) (ignorable (line) (or (zerop (length line)) (blankp line) (eql (char line 0) #\#)))) (with-open-file (stream file) (loop for line = (read-line stream nil) while line do (unless (ignorable line) (funcall fun line)))))) (defmethod slot-unbound (class (dist dist) (slot (eql 'release-index))) (declare (ignore class)) (setf (slot-value dist 'release-index) (make-hash-table :test 'equal))) ;;; ;;; Systems ;;; ;;; A "system" in the defsystem sense. ;;; (defclass system (preference-mixin) ((name :initarg :name :accessor name :reader short-description) (system-file-name :initarg :system-file-name :accessor system-file-name) (release :initarg :release :accessor release :reader preference-parent) (dist :initarg :dist :accessor dist) (required-systems :initarg :required-systems :accessor required-systems) (metadata-name :initarg :metadata-name :accessor metadata-name)) (:default-initargs :metadata-name "systems")) (defmethod print-object ((system system) stream) (print-unreadable-object (system stream :type t) (format stream "~A / ~A / ~A" (short-description system) (short-description (release system)) (short-description (dist system))))) (defmethod provided-systems ((system system)) (list system)) (defmethod initialize-release-index ((dist dist)) (let ((releases (ensure-release-index-file dist)) (index (release-index dist))) (call-for-each-index-entry releases (lambda (line) (let ((instance (make-line-instance line 'release :project-name :archive-url :archive-size :archive-md5 :archive-content-sha1 :prefix :system-files))) ;; Don't clobber anything previously loaded via CDB (unless (gethash (project-name instance) index) (setf (dist instance) dist) (setf (archive-size instance) (parse-integer (archive-size instance))) (setf (gethash (project-name instance) index) instance))))) (setf (release-index dist) index))) (defmethod initialize-system-index ((dist dist)) (initialize-release-index dist) (let ((systems (ensure-system-index-file dist)) (index (system-index dist))) (call-for-each-index-entry systems (lambda (line) (let ((instance (make-line-instance line 'system :release :system-file-name :name :required-systems))) ;; Don't clobber anything previously loaded via CDB (unless (gethash (name instance) index) (let ((release (find-release-in-dist (release instance) dist))) (setf (release instance) release) (if (slot-boundp release 'provided-systems) (pushnew instance (provided-systems release)) (setf (provided-systems release) (list instance)))) (setf (dist instance) dist) (setf (gethash (name instance) index) instance))))) (setf (system-index dist) index))) (defmethod slot-unbound (class (release release) (slot (eql 'provided-systems))) (declare (ignore class)) ;; FIXME: This isn't right, since the system index has systems that ;; don't match the defining system file name. (setf (slot-value release 'provided-systems) (mapcar (lambda (system-file) (find-system-in-dist (pathname-name system-file) (dist release))) (system-files release)))) (defmethod slot-unbound (class (dist dist) (slot (eql 'system-index))) (declare (ignore class)) (setf (slot-value dist 'system-index) (make-hash-table :test 'equal))) (defun make-system-from-line (line dist) (let ((system (make-line-instance line 'system :release :system-file-name :name :required-systems))) (setf (dist system) dist) (setf (release system) (find-release-in-dist (release system) dist)) system)) (defmethod find-system-in-dist (system-name (dist dist)) (let* ((index (system-index dist)) (system (gethash system-name index))) (or system (let ((line (cdb-lookup dist system-name (ensure-system-cdb-file dist)))) (when line (setf (gethash system-name index) (make-system-from-line line dist))))))) (defmethod preference ((system system)) (if (probe-file (preference-file system)) (call-next-method) (preference (release system)))) (defun thing-name-designator (designator) "Convert DESIGNATOR to a string naming a thing. Strings are used as-is, symbols are converted to their downcased symbol-name." (typecase designator (string designator) (symbol (string-downcase designator)) (t (error "~S is not a valid designator for a system or release" designator)))) (defun find-thing-named (find-fun name) (setf name (thing-name-designator name)) (let ((result '())) (dolist (dist (enabled-dists) (sort result #'> :key #'preference)) (let ((thing (funcall find-fun name dist))) (when thing (push thing result)))))) (defmethod find-systems-named (name) (find-thing-named #'find-system-in-dist name)) (defmethod find-releases-named (name) (find-thing-named #'find-release-in-dist name)) (defmethod find-system (name) (first (find-systems-named name))) (defmethod find-release (name) (first (find-releases-named name))) (defmethod install ((system system)) (ensure-installed (release system))) (defmethod install-metadata-file ((system system)) (relative-to (dist system) (make-pathname :name (system-file-name system) :type "txt" :directory '(:relative "installed" "systems")))) (defmethod installed-asdf-system-file ((system system)) (let ((metadata-file (install-metadata-file system))) (when (probe-file metadata-file) (with-open-file (stream metadata-file) (let* ((relative (read-line stream)) (full (qmerge relative))) (when (probe-file full) full)))))) (defmethod installedp ((system system)) (installed-asdf-system-file system)) (defmethod uninstall ((system system)) (uninstall (release system))) (defun find-asdf-system-file (name) "Return the ASDF system file in which the system named NAME is defined." (let ((system (find-system name))) (when system (installed-asdf-system-file system)))) (defun system-definition-searcher (name) "Like FIND-ASDF-SYSTEM-FILE, but this function can be used in ASDF:*SYSTEM-DEFINITION-SEARCH-FUNCTIONS*; it will only return system file names if they match NAME." (let ((system-file (find-asdf-system-file name))) (when (and system-file (string= (pathname-name system-file) name)) system-file))) (defun call-with-consistent-dists (fun) "Take a snapshot of the available dists and return the same list consistently each time ALL-DISTS is called in the dynamic scope of FUN." (let* ((all-dists (all-dists)) (*dist-enumeration-functions* (list (constantly all-dists)))) (funcall fun))) (defmacro with-consistent-dists (&body body) "See CALL-WITH-CONSISTENT-DISTS." `(call-with-consistent-dists (lambda () ,@body))) (defgeneric dependency-tree (system) (:method ((symbol symbol)) (dependency-tree (string-downcase symbol))) (:method ((string string)) (let ((system (find-system string))) (when system (dependency-tree system)))) (:method ((system system)) (with-consistent-dists (list* system (remove nil (mapcar 'dependency-tree (required-systems system))))))) (defmethod provided-systems ((object (eql t))) (let ((systems (loop for dist in (enabled-dists) appending (provided-systems dist)))) (sort systems #'string< :key #'name))) (defmethod provided-releases ((object (eql t))) (let ((releases (loop for dist in (enabled-dists) appending (provided-releases dist)))) (sort releases #'string< :key #'name))) (defgeneric system-apropos-list (term) (:method ((term symbol)) (system-apropos-list (symbol-name term))) (:method ((term string)) (setf term (string-downcase term)) (let ((result '())) (dolist (system (provided-systems t) (nreverse result)) (when (or (search term (name system)) (search term (name (release system)))) (push system result)))))) (defgeneric system-apropos (term) (:method (term) (map nil (lambda (system) (format t "~A~%" system)) (system-apropos-list term)) (values))) ;;; ;;; Clean up things ;;; (defgeneric clean (object) (:documentation "Remove any unneeded files or directories related to OBJECT.")) (defmethod clean ((dist dist)) (let* ((releases (provided-releases dist)) (known-archives (mapcar 'local-archive-file releases)) (known-directories (mapcar 'base-directory releases)) (present-archives (mapcar 'truename (directory-entries (relative-to dist "archives/")))) (present-directories (mapcar 'truename (directory-entries (relative-to dist "software/")))) (garbage-archives (set-difference present-archives known-archives :test 'equalp)) (garbage-directories ;; Use the namestring here on the theory that pathnames with ;; equalp namestrings are sufficiently the same. On ;; LispWorks, for example, identical namestrings can still ;; differ in :name, :type, and more. (set-difference present-directories known-directories :test 'equalp :key 'namestring))) (map nil 'delete-file garbage-archives) (map nil 'delete-directory-tree garbage-directories))) ;;; ;;; Available versions ;;; (defmethod available-versions ((dist dist)) (let ((temp (qmerge "tmp/dist-versions.txt")) (versions '()) (url (available-versions-url dist))) (when url (ensure-directories-exist temp) (delete-file-if-exists temp) (handler-case (fetch url temp) (unexpected-http-status () (return-from available-versions nil))) (with-open-file (stream temp) (loop for line = (read-line stream nil) while line do (destructuring-bind (version url) (split-spaces line) (setf versions (acons version url versions))))) versions))) ;;; ;;; User interface bits to re-export from QL ;;; (define-condition unknown-dist (error) ((name :initarg :name :reader unknown-dist-name)) (:report (lambda (condition stream) (format stream "No dist known by that name -- ~S" (unknown-dist-name condition))))) (defun find-dist-or-lose (name) (let ((dist (find-dist name))) (or dist (error 'unknown-dist :name name)))) (defun dist-url (name) (canonical-distinfo-url (find-dist-or-lose name))) (defun dist-version (name) (version (find-dist-or-lose name)))
38,423
Common Lisp
.lisp
980
31.865306
118
0.648718
enzuru/home
6
0
1
GPL-3.0
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
bfaaf06e56b97d4f8aee214438532ac15b7eeb67282a330b2700add333253aee
14,708
[ 13654 ]
14,709
progress.lisp
enzuru_home/quicklisp/quicklisp/progress.lisp
;;; ;;; A text progress bar ;;; (in-package #:ql-progress) (defclass progress-bar () ((start-time :initarg :start-time :accessor start-time) (end-time :initarg :end-time :accessor end-time) (progress-character :initarg :progress-character :accessor progress-character) (character-count :initarg :character-count :accessor character-count :documentation "How many characters wide is the progress bar?") (characters-so-far :initarg :characters-so-far :accessor characters-so-far) (update-interval :initarg :update-interval :accessor update-interval :documentation "Update the progress bar display after this many internal-time units.") (last-update-time :initarg :last-update-time :accessor last-update-time :documentation "The display was last updated at this time.") (total :initarg :total :accessor total :documentation "The total number of units tracked by this progress bar.") (progress :initarg :progress :accessor progress :documentation "How far in the progress are we?") (pending :initarg :pending :accessor pending :documentation "How many raw units should be tracked in the next display update?")) (:default-initargs :progress-character #\= :character-count 50 :characters-so-far 0 :update-interval (floor internal-time-units-per-second 4) :last-update-time 0 :total 0 :progress 0 :pending 0)) (defgeneric start-display (progress-bar)) (defgeneric update-progress (progress-bar unit-count)) (defgeneric update-display (progress-bar)) (defgeneric finish-display (progress-bar)) (defgeneric elapsed-time (progress-bar)) (defgeneric units-per-second (progress-bar)) (defmethod start-display (progress-bar) (setf (last-update-time progress-bar) (get-internal-real-time)) (setf (start-time progress-bar) (get-internal-real-time)) (fresh-line) (finish-output)) (defmethod update-display (progress-bar) (incf (progress progress-bar) (pending progress-bar)) (setf (pending progress-bar) 0) (setf (last-update-time progress-bar) (get-internal-real-time)) (let* ((showable (floor (character-count progress-bar) (/ (total progress-bar) (progress progress-bar)))) (needed (- showable (characters-so-far progress-bar)))) (setf (characters-so-far progress-bar) showable) (dotimes (i needed) (write-char (progress-character progress-bar))) (finish-output))) (defmethod update-progress (progress-bar unit-count) (incf (pending progress-bar) unit-count) (let ((now (get-internal-real-time))) (when (< (update-interval progress-bar) (- now (last-update-time progress-bar))) (update-display progress-bar)))) (defmethod finish-display (progress-bar) (update-display progress-bar) (setf (end-time progress-bar) (get-internal-real-time)) (terpri) (format t "~:D bytes in ~$ seconds (~$KB/sec)~%" (total progress-bar) (elapsed-time progress-bar) (/ (units-per-second progress-bar) 1024)) (finish-output)) (defmethod elapsed-time (progress-bar) (/ (- (end-time progress-bar) (start-time progress-bar)) internal-time-units-per-second)) (defmethod units-per-second (progress-bar) (if (plusp (elapsed-time progress-bar)) (/ (total progress-bar) (elapsed-time progress-bar)) 0)) (defun kb/sec (progress-bar) (/ (units-per-second progress-bar) 1024)) (defparameter *uncertain-progress-chars* "?") (defclass uncertain-size-progress-bar (progress-bar) ((progress-char-index :initarg :progress-char-index :accessor progress-char-index) (units-per-char :initarg :units-per-char :accessor units-per-char)) (:default-initargs :total 0 :progress-char-index 0 :units-per-char (floor (expt 1024 2) 50))) (defmethod update-progress :after ((progress-bar uncertain-size-progress-bar) unit-count) (incf (total progress-bar) unit-count)) (defmethod progress-character ((progress-bar uncertain-size-progress-bar)) (let ((index (progress-char-index progress-bar))) (prog1 (char *uncertain-progress-chars* index) (setf (progress-char-index progress-bar) (mod (1+ index) (length *uncertain-progress-chars*)))))) (defmethod update-display ((progress-bar uncertain-size-progress-bar)) (setf (last-update-time progress-bar) (get-internal-real-time)) (multiple-value-bind (chars pend) (floor (pending progress-bar) (units-per-char progress-bar)) (setf (pending progress-bar) pend) (dotimes (i chars) (write-char (progress-character progress-bar)) (incf (characters-so-far progress-bar)) (when (<= (character-count progress-bar) (characters-so-far progress-bar)) (terpri) (setf (characters-so-far progress-bar) 0) (finish-output))) (finish-output))) (defun make-progress-bar (total) (if (or (not total) (zerop total)) (make-instance 'uncertain-size-progress-bar) (make-instance 'progress-bar :total total)))
5,100
Common Lisp
.lisp
137
32.335766
77
0.6964
enzuru/home
6
0
1
GPL-3.0
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
49fd6aabfcf1cdddf7b523fb610952c5378e9bdc2e2fa30fb52c6a6517e64040
14,709
[ 363047, 366153 ]
14,710
bundle-template.lisp
enzuru_home/quicklisp/quicklisp/bundle-template.lisp
(cl:in-package #:cl-user) (eval-when (:compile-toplevel :load-toplevel :execute) (require "asdf") (unless (find-package '#:asdf) (error "ASDF could not be required"))) (let ((indicator '#:ql-bundle-v1) (searcher-name '#:ql-bundle-searcher) (base (make-pathname :name nil :type nil :defaults #. (or *compile-file-truename* *load-truename*)))) (labels ((file-lines (file) (with-open-file (stream file) (loop for line = (read-line stream nil) while line collect line))) (relative (pathname) (merge-pathnames pathname base)) (pathname-timestamp (pathname) #+clisp (nth-value 2 (ext:probe-pathname pathname)) #-clisp (file-write-date pathname)) (system-table (table pathnames) (dolist (pathname pathnames table) (setf (gethash (pathname-name pathname) table) (relative pathname)))) (initialize-bundled-systems-table (table data-source) (system-table table (mapcar (lambda (line) (merge-pathnames line data-source)) (file-lines data-source)))) (local-projects-system-pathnames (data-source) (let ((files (directory (merge-pathnames "**/*.asd" data-source)))) (stable-sort (sort files #'string< :key #'namestring) #'< :key (lambda (file) (length (namestring file)))))) (initialize-local-projects-table (table data-source) (system-table table (local-projects-system-pathnames data-source))) (make-table (&key data-source init-function) (let ((table (make-hash-table :test 'equalp))) (setf (gethash "/data-source" table) data-source (gethash "/timestamp" table) (pathname-timestamp data-source) (gethash "/init" table) init-function) table)) (tcall (table key &rest args) (let ((fun (gethash key table))) (unless (and fun (functionp fun)) (error "Unknown function key ~S" key)) (apply fun args))) (created-timestamp (table) (gethash "/timestamp" table)) (data-source-timestamp (table) (pathname-timestamp (data-source table))) (data-source (table) (gethash "/data-source" table)) (stalep (table) ;; FIXME: Handle newly missing data sources? (< (created-timestamp table) (data-source-timestamp table))) (meta-key-p (key) (and (stringp key) (< 0 (length key)) (char= (char key 0) #\/))) (clear (table) ;; Don't clear "/foo" keys (maphash (lambda (key value) (declare (ignore value)) (unless (meta-key-p key) (remhash key table))) table)) (initialize (table) (tcall table "/init" table (data-source table)) (setf (gethash "/timestamp" table) (pathname-timestamp (data-source table))) table) (update (table) (clear table) (initialize table)) (lookup (system-name table) (when (stalep table) (update table)) (values (gethash system-name table))) (search-function (system-name) (let ((tables (get searcher-name indicator))) (dolist (table tables) (let* ((result (lookup system-name table)) (probed (and result (probe-file result)))) (when probed (return probed)))))) (make-bundled-systems-table () (initialize (make-table :data-source (relative "system-index.txt") :init-function #'initialize-bundled-systems-table))) (make-bundled-local-projects-systems-table () (let ((data-source (relative "bundled-local-projects/system-index.txt"))) (when (probe-file data-source) (initialize (make-table :data-source data-source :init-function #'initialize-bundled-systems-table))))) (make-local-projects-table () (initialize (make-table :data-source (relative "local-projects/") :init-function #'initialize-local-projects-table))) (=matching-data-sources (tables) (let ((data-sources (mapcar #'data-source tables))) (lambda (table) (member (data-source table) data-sources :test #'equalp)))) (check-for-existing-searcher (searchers) (block done (dolist (searcher searchers) (when (symbolp searcher) (let ((plist (symbol-plist searcher))) (loop for key in plist by #'cddr when (and (symbolp key) (string= key indicator)) do (setf indicator key) (setf searcher-name searcher) (return-from done t))))))) (clear-asdf (table) (maphash (lambda (system-name pathname) (declare (ignore pathname)) (asdf:clear-system system-name)) table))) (let ((existing (check-for-existing-searcher asdf:*system-definition-search-functions*))) (let* ((local (make-local-projects-table)) (bundled-local-projects (make-bundled-local-projects-systems-table)) (bundled (make-bundled-systems-table)) (new-tables (remove nil (list local bundled-local-projects bundled))) (existing-tables (get searcher-name indicator)) (filter (=matching-data-sources new-tables))) (setf (get searcher-name indicator) (append new-tables (delete-if filter existing-tables))) (map nil #'clear-asdf new-tables)) (unless existing (setf (symbol-function searcher-name) #'search-function) (push searcher-name asdf:*system-definition-search-functions*))) t))
6,978
Common Lisp
.lisp
148
29.952703
86
0.491272
enzuru/home
6
0
1
GPL-3.0
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
a522c1a02471a532ddfeca50e9f156b37080e87e2686f5a4daa4ae873de176e9
14,710
[ 116942, 144791 ]
14,711
client.lisp
enzuru_home/quicklisp/quicklisp/client.lisp
;;;; client.lisp (in-package #:quicklisp-client) (defvar *quickload-verbose* nil "When NIL, show terse output when quickloading a system. Otherwise, show normal compile and load output.") (defvar *quickload-prompt* nil "When NIL, quickload systems without prompting for enter to continue, otherwise proceed directly without user intervention.") (defvar *quickload-explain* t) (define-condition system-not-quickloadable (error) ((system :initarg :system :reader not-quickloadable-system))) (defun maybe-silence (silent stream) (or (and silent (make-broadcast-stream)) stream)) (defgeneric quickload (systems &key verbose silent prompt explain &allow-other-keys) (:documentation "Load SYSTEMS the quicklisp way. SYSTEMS is a designator for a list of things to be loaded.") (:method (systems &key (prompt *quickload-prompt*) (silent nil) (verbose *quickload-verbose*) &allow-other-keys) (let ((*standard-output* (maybe-silence silent *standard-output*)) (*trace-output* (maybe-silence silent *trace-output*))) (unless (listp systems) (setf systems (list systems))) (dolist (thing systems systems) (flet ((ql () (autoload-system-and-dependencies thing :prompt prompt))) (tagbody :start (restart-case (if verbose (ql) (call-with-quiet-compilation #'ql)) (register-local-projects () :report "Register local projects and try again." (register-local-projects) (go :start))))))))) (defmethod quickload :around (systems &key verbose prompt explain &allow-other-keys) (declare (ignorable systems verbose prompt explain)) (with-consistent-dists (call-next-method))) (defun system-list () (provided-systems t)) (defun update-dist (dist &key (prompt t)) (when (stringp dist) (setf dist (find-dist dist))) (let ((new (available-update dist))) (cond (new (show-update-report dist new) (when (or (not prompt) (press-enter-to-continue)) (update-in-place dist new))) ((not (subscribedp dist)) (format t "~&You are not subscribed to ~S." (name dist))) (t (format t "~&You already have the latest version of ~S: ~A.~%" (name dist) (version dist)))))) (defun update-all-dists (&key (prompt t)) (let ((dists (remove-if-not 'subscribedp (all-dists)))) (format t "~&~D dist~:P to check.~%" (length dists)) (dolist (old dists) (with-simple-restart (skip "Skip update of dist ~S" (name old)) (update-dist old :prompt prompt))))) (defun available-dist-versions (name) (available-versions (find-dist-or-lose name))) (defun help () "For help with Quicklisp, see http://www.quicklisp.org/beta/") (defun uninstall (system-name) (let ((system (find-system system-name))) (cond (system (ql-dist:uninstall system)) (t (warn "Unknown system ~S" system-name) nil)))) (defun uninstall-dist (name) (let ((dist (find-dist name))) (when dist (ql-dist:uninstall dist)))) (defun write-asdf-manifest-file (output-file &key (if-exists :rename-and-delete) exclude-local-projects) "Write a list of system file pathnames to OUTPUT-FILE, one per line, in order of descending QL-DIST:PREFERENCE." (when (or (eql output-file nil) (eql output-file t)) (setf output-file (qmerge "manifest.txt"))) (with-open-file (stream output-file :direction :output :if-exists if-exists) (unless exclude-local-projects (register-local-projects) (dolist (system-file (list-local-projects)) (let* ((enough (enough-namestring system-file output-file)) (native (native-namestring enough))) (write-line native stream)))) (with-consistent-dists (let ((systems (provided-systems t)) (already-seen (make-hash-table :test 'equal))) (dolist (system (sort systems #'> :key #'preference)) ;; FIXME: find-asdf-system-file does another find-system ;; behind the scenes. Bogus. Should be a better way to go ;; from system object to system file. (let* ((system-file (find-asdf-system-file (name system))) (enough (and system-file (enough-namestring system-file output-file))) (native (and enough (native-namestring enough)))) (when (and native (not (gethash native already-seen))) (setf (gethash native already-seen) native) (format stream "~A~%" native))))))) (probe-file output-file)) (defun where-is-system (name) "Return the pathname to the source directory of ASDF system with the given NAME, or NIL if no system by that name can be found known." (let ((system (asdf:find-system name nil))) (when system (asdf:system-source-directory system))))
5,267
Common Lisp
.lisp
119
34.882353
84
0.610018
enzuru/home
6
0
1
GPL-3.0
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
f3b6ab6d1641566e10fa7dbbf22a204cca311573313e84f40b7d701a13bfcf8d
14,711
[ 101606 ]
14,712
impl.lisp
enzuru_home/quicklisp/quicklisp/impl.lisp
(in-package #:ql-impl) (eval-when (:compile-toplevel :load-toplevel :execute) (defun error-unimplemented (&rest args) (declare (ignore args)) (error "Not implemented"))) (defvar *interfaces* (make-hash-table) "A table of defined interfaces and their documentation.") (defun show-interfaces () "Display information about what interfaces are defined." (maphash (lambda (interface info) (destructuring-bind (arguments docstring) info (let ((*package* (find-package :keyword))) (format t "(~S ~:[()~;~:*~A~]~@[~% ~S~])~%" interface arguments docstring)))) *interfaces*)) (defmacro neuter-package (name) `(eval-when (:compile-toplevel :load-toplevel :execute) (let ((definition (fdefinition 'error-unimplemented))) (do-external-symbols (symbol ,(string name)) (unless (fboundp symbol) (setf (fdefinition symbol) definition)))))) (eval-when (:compile-toplevel :load-toplevel :execute) (defun feature-expression-passes-p (expression) (cond ((keywordp expression) (member expression *features*)) ((consp expression) (case (first expression) (or (some 'feature-expression-passes-p (rest expression))) (and (every 'feature-expression-passes-p (rest expression))))) (t (error "Unrecognized feature expression -- ~S" expression))))) (defmacro define-implementation-package (feature package-name &rest options) (let* ((output-options '((:use) (:export #:lisp))) (prep (cdr (assoc :prep options))) (class-option (cdr (assoc :class options))) (class (first class-option)) (superclasses (rest class-option)) (import-options '()) (effectivep (feature-expression-passes-p feature))) (dolist (option options) (ecase (first option) ((:prep :class)) ((:import-from :import) (push option import-options)) ((:export :shadow :intern :documentation) (push option output-options)) ((:reexport-from) (push (cons :export (cddr option)) output-options) (push (cons :import-from (cdr option)) import-options)))) `(progn ,@(when effectivep `((eval-when (:compile-toplevel :load-toplevel :execute) ,@prep))) (defclass ,class ,superclasses ()) (defpackage ,package-name ,@output-options ,@(when effectivep import-options)) ,@(when effectivep `((setf *implementation* (make-instance ',class)))) ,@(unless effectivep `((neuter-package ,package-name)))))) (defmacro definterface (name lambda-list &body options) (let* ((doc-option (find :documentation options :key #'first)) (doc (second doc-option))) (setf (gethash name *interfaces*) (list lambda-list doc))) (let* ((forbidden (intersection lambda-list lambda-list-keywords)) (gf-options (remove :implementation options :key #'first)) (implementations (set-difference options gf-options)) (implementation-arg (copy-symbol '%implementation))) (when forbidden (error "~S not allowed in definterface lambda list" forbidden)) (flet ((method-option (class body) `(:method ((,implementation-arg ,class) ,@lambda-list) ,@body))) (let ((generic-name (intern (format nil "%~A" name)))) `(progn (defgeneric ,generic-name (lisp ,@lambda-list) ,@gf-options ,@(mapcan (lambda (implementation) (destructuring-bind (class &rest body) (rest implementation) (mapcar (lambda (class) (method-option class body)) (if (consp class) class (list class))))) implementations)) (defun ,name ,lambda-list (,generic-name *implementation* ,@lambda-list))))))) (defmacro defimplementation (name-and-options lambda-list &body body) (destructuring-bind (name &key (for t) qualifier) (if (consp name-and-options) name-and-options (list name-and-options)) (unless for (error "You must specify an implementation name.")) (let ((generic-name (find-symbol (format nil "%~A" name))) (implementation-arg (copy-symbol '%implementation))) (unless generic-name (error "~S does not name an implementation function" name)) `(defmethod ,generic-name ,@(when qualifier (list qualifier)) ,(list* `(,implementation-arg ,for) lambda-list) ,@body)))) ;;; Bootstrap implementations (defvar *implementation* nil) (defclass lisp () ()) ;;; Allegro Common Lisp (define-implementation-package :allegro #:ql-allegro (:documentation "Allegro Common Lisp - http://www.franz.com/products/allegrocl/") (:class allegro) (:reexport-from #:socket #:make-socket) (:reexport-from #:excl #:file-directory-p #:delete-directory #:delete-directory-and-files #:read-vector)) ;;; Armed Bear Common Lisp (define-implementation-package :abcl #:ql-abcl (:documentation "Armed Bear Common Lisp - http://common-lisp.net/project/armedbear/") (:class abcl) (:reexport-from #:ext #:make-socket #:get-socket-stream)) ;;; Clozure CL (define-implementation-package :ccl #:ql-ccl (:documentation "Clozure Common Lisp - http://www.clozure.com/clozurecl.html") (:class ccl) (:reexport-from #:ccl #:delete-directory #:make-socket #:native-translated-namestring)) ;;; CLASP (define-implementation-package :clasp #:ql-clasp (:documentation "CLASP - http://github.com/drmeister/clasp") (:class clasp) (:prep (require 'sockets)) (:intern #:host-network-address) (:reexport-from #:si #:rmdir #:file-kind) (:reexport-from #:sb-bsd-sockets #:get-host-by-name #:host-ent-address #:inet-socket #:socket-connect #:socket-make-stream)) ;;; GNU CLISP (define-implementation-package :clisp #:ql-clisp (:documentation "GNU CLISP - http://clisp.cons.org/") (:class clisp) (:reexport-from #:socket #:socket-connect) (:reexport-from #:ext #:delete-directory #:rename-directory #:probe-directory #:probe-pathname #:read-byte-sequence)) ;;; CMUCL (define-implementation-package :cmu #:ql-cmucl (:documentation "CMU Common Lisp - http://www.cons.org/cmucl/") (:class cmucl) (:reexport-from #:system #:make-fd-stream) (:reexport-from #:unix #:unix-rmdir) (:reexport-from #:extensions #:connect-to-inet-socket #:*gc-verbose*)) (defvar ql-cmucl:*gc-verbose*) ;;; Scieneer CL (define-implementation-package :scl #:ql-scl (:documentation "Scieneer Common Lisp - http://www.scieneer.com/scl/") (:class scl) (:reexport-from #:system #:make-fd-stream) (:reexport-from #:unix #:unix-rmdir) (:reexport-from #:extensions #:connect-to-inet-socket #:unix-namestring)) ;;; LispWorks (define-implementation-package :lispworks #:ql-lispworks (:documentation "LispWorks - http://www.lispworks.com/") (:class lispworks) (:prep (require "comm")) (:reexport-from #:lw #:file-directory-p #:delete-directory) (:reexport-from #:comm #:open-tcp-stream #:get-host-entry)) ;;; ECL (define-implementation-package :ecl #:ql-ecl (:documentation "ECL - http://ecls.sourceforge.net/") (:class ecl) (:prep (require 'sockets)) (:intern #:host-network-address) (:reexport-from #:si #:rmdir #:file-kind) (:reexport-from #:sb-bsd-sockets #:get-host-by-name #:host-ent-address #:inet-socket #:socket-connect #:socket-make-stream)) ;;; Mezzano (define-implementation-package :mezzano #:ql-mezzano (:documentation "Mezzano Lisp Operating System - https://github.com/froggey/Mezzano") (:class mezzano) (:reexport-from #:mezzano.network.tcp #:tcp-stream-connect)) ;;; MKCL (define-implementation-package :mkcl #:ql-mkcl (:documentation "ManKai Common Lisp - http://common-lisp.net/project/mkcl/") (:class mkcl) (:prep (require 'sockets)) (:intern #:host-network-address) (:reexport-from #:si #:rmdir #:file-kind) (:reexport-from #:sb-bsd-sockets #:get-host-by-name #:host-ent-address #:inet-socket #:socket-connect #:socket-make-stream)) ;;; SBCL (define-implementation-package :sbcl #:ql-sbcl (:class sbcl) (:documentation "Steel Bank Common Lisp - http://www.sbcl.org/") (:prep (require 'sb-posix) (require 'sb-bsd-sockets)) (:intern #:host-network-address) (:reexport-from #:sb-posix #:rmdir) (:reexport-from #:sb-ext #:compiler-note #:native-namestring) (:reexport-from #:sb-bsd-sockets #:get-host-by-name #:inet-socket #:host-ent-address #:socket-connect #:socket-make-stream))
10,024
Common Lisp
.lisp
264
27.984848
87
0.570664
enzuru/home
6
0
1
GPL-3.0
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
dfb3b46eba9b58e59581ad8850971638447372d7ae9827b2e36d1bb19b54dda0
14,712
[ 285227 ]
14,713
config.lisp
enzuru_home/quicklisp/quicklisp/config.lisp
;;;; config.lisp (in-package #:ql-config) (defun config-value-file-pathname (path) (let ((bad-position (position #\Space path))) (when bad-position (error "Space not allowed at position ~D in ~S" bad-position path))) (let* ((space-path (substitute #\Space #\/ path)) (split (split-spaces space-path)) (directory-parts (butlast split)) (name (first (last split))) (base (qmerge "config/"))) (merge-pathnames (make-pathname :name name :type "txt" :directory (list* :relative directory-parts)) base))) (defun config-value (path) (let ((file (config-value-file-pathname path))) (with-open-file (stream file :if-does-not-exist nil) (when stream (values (read-line stream nil)))))) (defun (setf config-value) (new-value path) (let ((file (config-value-file-pathname path))) (typecase new-value (null (delete-file-if-exists file)) (string (ensure-directories-exist file) (with-open-file (stream file :direction :output :if-does-not-exist :create :if-exists :rename-and-delete) (write-line new-value stream))) (t (error "Bad config value ~S; must be a string or NIL" new-value)))))
1,356
Common Lisp
.lisp
36
28.833333
75
0.582067
enzuru/home
6
0
1
GPL-3.0
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
6e11df8585ae1dca0bb88d78f748ba63b5026d22ee740618b59db78ea24278d7
14,713
[ 246628, 269494 ]
14,714
minitar.lisp
enzuru_home/quicklisp/quicklisp/minitar.lisp
(in-package #:ql-minitar) (defconstant +block-size+ 512) (defconstant +space-code+ 32) (defconstant +newline-code+ 10) (defconstant +equals-code+ 61) (defun make-block-buffer () (make-array +block-size+ :element-type '(unsigned-byte 8) :initial-element 0)) (defun skip-n-blocks (n stream) (let ((block (make-block-buffer))) (dotimes (i n) (read-sequence block stream)))) (defun read-octet-vector (length stream) (let ((block (make-block-buffer)) (vector (make-array length :element-type '(unsigned-byte 8))) (offset 0) (block-count (ceiling length +block-size+))) (dotimes (i block-count) (read-sequence block stream) (replace vector block :start1 offset) (incf offset +block-size+)) vector)) (defun decode-pax-header-record (vector offset) "Decode VECTOR as pax extended header data. Returns the keyword and value it specifies as multiple values." ;; Vector format is: "%d %s=%s\n", <length>, <keyword>, <value> ;; See http://pubs.opengroup.org/onlinepubs/009695399/utilities/pax.html (let* ((length-start offset) (length-end (position +space-code+ vector :start length-start)) (length-string (ascii-subseq vector length-start length-end)) (length (parse-integer length-string)) (keyword-start (1+ length-end)) (keyword-end (position +equals-code+ vector :start keyword-start)) (keyword (ascii-subseq vector keyword-start keyword-end)) (value-start (1+ keyword-end)) (value-end (1- (+ offset length))) (value (ascii-subseq vector value-start value-end))) (values keyword value (+ offset length)))) (defun decode-pax-header (vector) "Decode VECTOR as a pax header and return it as an alist." (let ((header nil) (offset 0) (length (length vector))) (loop (when (<= length offset) (return header)) (multiple-value-bind (keyword value new-offset) (decode-pax-header-record vector offset) (setf header (acons keyword value header)) (setf offset new-offset))))) (defun pax-header-path (vector) "Decode VECTOR as a pax header and return its 'path' value, if any." (let ((header-alist (decode-pax-header vector))) (cdr (assoc "path" header-alist :test 'equal)))) (defun ascii-subseq (vector start end) (let ((string (make-string (- end start)))) (loop for i from 0 for j from start below end do (setf (char string i) (code-char (aref vector j)))) string)) (defun block-asciiz-string (block start length) (let* ((end (+ start length)) (eos (or (position 0 block :start start :end end) end))) (ascii-subseq block start eos))) (defun prefix (header) (when (plusp (aref header 345)) (block-asciiz-string header 345 155))) (defun name (header) (block-asciiz-string header 0 100)) (defun payload-size (header) (values (parse-integer (block-asciiz-string header 124 12) :radix 8))) (defun nth-block (n file) (with-open-file (stream file :element-type '(unsigned-byte 8)) (let ((block (make-block-buffer))) (skip-n-blocks (1- n) stream) (read-sequence block stream) block))) (defun payload-type (code) (case code (0 :file) (48 :file) (50 :symlink) (76 :long-name) (53 :directory) (103 :global-header) (120 :pax-extended-header) (t :unsupported))) (defun full-path (header) (let ((prefix (prefix header)) (name (name header))) (if prefix (format nil "~A/~A" prefix name) name))) (defun save-file (file size stream) (multiple-value-bind (full-blocks partial) (truncate size +block-size+) (ensure-directories-exist file) (with-open-file (outstream file :direction :output :if-exists :supersede :element-type '(unsigned-byte 8)) (let ((block (make-block-buffer))) (dotimes (i full-blocks) (read-sequence block stream) (write-sequence block outstream)) (when (plusp partial) (read-sequence block stream) (write-sequence block outstream :end partial)))))) (defun gnu-long-name (size stream) ;; GNU long names are simply the filename (null terminated) packed into the ;; payload. (let ((payload (read-octet-vector size stream))) (ascii-subseq payload 0 (1- size)))) (defun unpack-tarball (tarfile &key (directory *default-pathname-defaults*)) (let ((block (make-block-buffer)) (extended-path nil)) (with-open-file (stream tarfile :element-type '(unsigned-byte 8)) (loop (let ((size (read-sequence block stream))) (when (zerop size) (return)) (unless (= size +block-size+) (error "Bad size on tarfile")) (when (every #'zerop block) (return)) (let* ((payload-code (aref block 156)) (payload-type (payload-type payload-code)) (tar-path (or (shiftf extended-path nil) (full-path block))) (full-path (merge-pathnames tar-path directory)) (payload-size (payload-size block)) (block-count (ceiling (payload-size block) +block-size+))) (case payload-type (:file (save-file full-path payload-size stream)) (:directory (ensure-directories-exist full-path)) ((:symlink :global-header) ;; These block types aren't required for Quicklisp archives (skip-n-blocks block-count stream)) (:long-name (setf extended-path (gnu-long-name payload-size stream))) (:pax-extended-header (let* ((pax-header-data (read-octet-vector payload-size stream)) (path (pax-header-path pax-header-data))) (when path (setf extended-path path)))) (t (warn "Unknown tar block payload code -- ~D" payload-code) (skip-n-blocks block-count stream))))))))) (defun contents (tarfile) (let ((block (make-block-buffer)) (result '())) (with-open-file (stream tarfile :element-type '(unsigned-byte 8)) (loop (let ((size (read-sequence block stream))) (when (zerop size) (return (nreverse result))) (unless (= size +block-size+) (error "Bad size on tarfile")) (when (every #'zerop block) (return (nreverse result))) (let* ((payload-type (payload-type (aref block 156))) (tar-path (full-path block)) (payload-size (payload-size block))) (skip-n-blocks (ceiling payload-size +block-size+) stream) (case payload-type (:file (push tar-path result)) (:directory (push tar-path result)))))))))
6,950
Common Lisp
.lisp
172
32.238372
80
0.609056
enzuru/home
6
0
1
GPL-3.0
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
0783c1bc21c26d0974d1656046051810611a9fae8cc098bcaf1e8d1fafe1d663
14,714
[ 15486, 109489 ]
14,715
client-update.lisp
enzuru_home/quicklisp/quicklisp/client-update.lisp
;;;; client-update.lisp (in-package #:quicklisp-client) (defun fetch-client-file-info (client-file-info output-file) (maybe-fetch-gzipped (file-url client-file-info) output-file) (check-client-file output-file client-file-info) (probe-file output-file)) (defun retirement-directory (base) (let ((suffix 0)) (loop (incf suffix) (let* ((try (format nil "~A-~D" base suffix)) (dir (qmerge (make-pathname :directory (list :relative "retired" try))))) (unless (probe-directory dir) (return dir)))))) (defun retire (directory base) (let ((retirement-home (qmerge "retired/")) (from (truename directory))) (ensure-directories-exist retirement-home) (let* ((*default-pathname-defaults* retirement-home) (to (retirement-directory base))) (rename-directory from to) to))) (defun client-update-scratch-directory (client-info) (qmerge (make-pathname :directory (list :relative "tmp" "client-update" (version client-info))))) (defun %install-client (new-info local-info) (let* ((work-directory (client-update-scratch-directory new-info)) (current-quicklisp-directory (qmerge "quicklisp/")) (new-quicklisp-directory (merge-pathnames "quicklisp/" work-directory)) (local-temp-tar (merge-pathnames "quicklisp.tar" work-directory)) (local-setup (merge-pathnames "setup.lisp" work-directory)) (local-asdf (merge-pathnames "asdf.lisp" work-directory)) (new-client-tar-p (not (info-equal (client-tar-info new-info) (client-tar-info local-info)))) (new-setup-p (not (info-equal (setup-info new-info) (setup-info local-info)))) (new-asdf-p (not (info-equal (asdf-info new-info) (asdf-info local-info))))) (ensure-directories-exist work-directory) ;; Fetch and unpack quicklisp.tar if needed (when new-client-tar-p (fetch-client-file-info (client-tar-info new-info) local-temp-tar) (unpack-tarball local-temp-tar :directory work-directory)) ;; Fetch setup.lisp if needed (when new-setup-p (fetch-client-file-info (setup-info new-info) local-setup)) ;; Fetch asdf.lisp if needed (when new-asdf-p (fetch-client-file-info (asdf-info new-info) local-asdf)) ;; Everything fetched, so move the old stuff away and move the new ;; stuff in (when new-client-tar-p (retire (qmerge "quicklisp/") (format nil "quicklisp-~A" (version local-info))) (rename-directory new-quicklisp-directory current-quicklisp-directory)) (when new-setup-p (replace-file local-setup (qmerge "setup.lisp"))) (when new-asdf-p (replace-file local-asdf (qmerge "asdf.lisp"))) ;; But unconditionally move the new client-info into place (replace-file (source-file new-info) (qmerge "client-info.sexp")) new-info)) (defun update-client (&key (prompt t)) (let* ((local-info (local-client-info)) (newest-info (newest-client-info local-info))) (cond ((null newest-info) (format t "No client update available.~%")) ((client-version-lessp local-info newest-info) (format t "Updating client from version ~A to version ~A.~%" (version local-info) (version newest-info)) (when (or (not prompt) (press-enter-to-continue)) (%install-client newest-info local-info) (format t "~&New Quicklisp client installed. ~ It will take effect on restart.~%"))) (t (format t "The most up-to-date client, version ~A, ~ is already installed.~%" (version local-info))))) t) (defun install-client (&key url version) (unless (or url version) (error "One of ~S or ~S is required" :url :version)) (when (and url version) (error "Only one of ~S or ~S is allowed" :url :version)) (when version (setf url (client-info-url-from-version version))) (let ((local-info (local-client-info)) (new-info (fetch-client-info url))) (%install-client new-info local-info)))
4,446
Common Lisp
.lisp
97
35.762887
77
0.601613
enzuru/home
6
0
1
GPL-3.0
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
9837840018b960c05f0bb724541d366cbc07887954c6adc000184d2e4412b46b
14,715
[ 39214, 189150 ]
14,716
bundle.lisp
enzuru_home/quicklisp/quicklisp/bundle.lisp
;;;; bundle.lisp (in-package #:ql-bundle) ;;; Bundling is taking a set of Quicklisp-provided systems and ;;; creating a directory structure and metadata in which those systems ;;; can be loaded without involving Quicklisp. ;;; ;;; This works for systems provided directly Quicklisp, or systems in ;;; the Quicklisp local-projects directories (if ;;; :include-local-projects is specified). (defgeneric find-system (system bundle)) (defgeneric add-system (system bundle)) (defgeneric ensure-system (system bundle)) (defgeneric find-release (relase bundle)) (defgeneric add-release (release bundle)) (defgeneric ensure-release (release bundle)) (defgeneric write-loader-script (bundle stream)) (defgeneric write-system-index (bundle stream)) (defgeneric unpack-release (release target)) (defgeneric unpack-releases (bundle target)) (defgeneric write-bundle (bundle target)) (defvar *ignored-systems* (list "asdf") "Systems that might appear in depends-on lists in Quicklisp, but which can't be bundled.") (defvar *bundle-progress-output* (make-synonym-stream '*trace-output*) "Informative output related to creating the bundle is sent to this stream.") ;;; Implementation ;;; Conditions (define-condition bundle-error (error) ()) (define-condition object-not-found (bundle-error) ((name :initarg :name :reader object-not-found-name) (type :initarg :type :reader object-not-found-type)) (:report (lambda (condition stream) (format stream "~A ~S not found" (object-not-found-type condition) (object-not-found-name condition)))) (:default-initargs :type "Object")) (define-condition system-not-found (object-not-found) ((name :reader system-not-found-system)) (:default-initargs :type "System")) (define-condition release-not-found (object-not-found) () (:default-initargs :type "Release")) (define-condition bundle-directory-exists (bundle-error) ((directory :initarg :directory :reader bundle-directory-exists-directory)) (:report (lambda (condition stream) (format stream "Bundle directory ~A already exists" (bundle-directory-exists-directory condition))))) (defun iso8601-time-stamp (&optional (time (get-universal-time))) (multiple-value-bind (second minute hour day month year) (decode-universal-time time 0) (format nil "~4,'0D-~2,'0D-~2,'0DT~ ~2,'0D:~2,'0D:~2,'0DZ" year month day hour minute second))) (defclass bundle () ((requested-systems :initarg :requested-systems :reader requested-systems :documentation "Names of the systems requested directly for bundling.") (creation-time :initarg :creation-time :reader creation-time) (release-table :initarg :release-table :reader release-table) (system-table :initarg :system-table :reader system-table)) (:default-initargs :requested-systems nil :creation-time (iso8601-time-stamp) :release-table (make-hash-table :test 'equalp) :system-table (make-hash-table :test 'equalp))) (defmethod print-object ((bundle bundle) stream) (print-unreadable-object (bundle stream :type t) (format stream "~D release~:P, ~D system~:P" (hash-table-count (release-table bundle)) (hash-table-count (system-table bundle))))) (defmethod provided-releases ((bundle bundle)) (let ((releases '())) (maphash (lambda (name release) (declare (ignore name)) (push release releases)) (release-table bundle)) (sort releases 'string< :key 'name))) (defmethod provided-systems ((bundle bundle)) (sort (mapcan #'provided-systems (provided-releases bundle)) 'string< :key 'name)) (defmethod find-system (name (bundle bundle)) (values (gethash name (system-table bundle)))) (defmethod add-system (name (bundle bundle)) (let ((system (ql-dist:find-system name))) (unless system (error 'system-not-found :name name)) (ensure-release (name (release system)) bundle) system)) (defmethod ensure-system (name (bundle bundle)) (or (find-system name bundle) (add-system name bundle))) (defmethod find-release (name (bundle bundle)) (values (gethash name (release-table bundle)))) (defmethod add-release (name (bundle bundle)) (let ((release (ql-dist:find-release name))) (unless release (error 'release-not-found :name name)) (setf (gethash (name release) (release-table bundle)) release) (let ((system-table (system-table bundle))) (dolist (system (provided-systems release)) (setf (gethash (name system) system-table) system))) release)) (defmethod ensure-release (name (bundle bundle)) (or (find-release name bundle) (add-release name bundle))) (defun add-systems-recursively (names bundle) (with-consistent-dists (labels ((add-one (name) (unless (member name *ignored-systems* :test 'equalp) (let ((system (restart-case (ensure-system name bundle) (omit () :report "Ignore this system and omit it from the bundle.")))) (when system (dolist (required-system-name (required-systems system)) (add-one required-system-name))))))) (map nil #'add-one names))) bundle) (defmethod unpack-release (release target) (let ((*default-pathname-defaults* (truename (ensure-directories-exist target))) (archive (ensure-local-archive-file release)) (temp-tar (ensure-directories-exist (ql-setup:qmerge "tmp/bundle.tar")))) (ql-gunzipper:gunzip archive temp-tar) (ql-minitar:unpack-tarball temp-tar :directory "software/") (delete-file temp-tar) release)) (defmethod unpack-releases ((bundle bundle) target) (dolist (release (provided-releases bundle)) (unpack-release release target)) bundle) (defmethod write-system-index ((bundle bundle) stream) (dolist (release (provided-releases bundle)) ;; Working with strings, here, intentionally not with pathnames (let ((prefix (concatenate 'string "software/" (prefix release)))) (dolist (system-file (system-files release)) (format stream "~A/~A~%" prefix system-file))))) (defmethod write-loader-script ((bundle bundle) stream) (let ((template-lines (load-time-value (with-open-file (stream #. (merge-pathnames "bundle-template" (or *compile-file-truename* *load-truename*))) (loop for line = (read-line stream nil) while line collect line))))) (dolist (line template-lines) (write-line line stream)))) (defun coerce-to-directory (pathname) ;; Cribbed from quicklisp-bootstrap/quicklisp.lisp (let ((name (file-namestring pathname))) (if (or (null name) (equal name "")) pathname (make-pathname :defaults pathname :name nil :type nil :directory (append (pathname-directory pathname) (list name)))))) (defun bundle-metadata-plist (bundle) (list :creation-time (creation-time bundle) :requested-systems (requested-systems bundle) :lisp-info (list :machine-instance (machine-instance) :machine-type (machine-type) :machine-version (machine-version) :lisp-implementation-type (lisp-implementation-type) :lisp-implementation-version (lisp-implementation-version)) :quicklisp-info (list :home (namestring ql:*quicklisp-home*) :local-project-directories (mapcar 'namestring ql:*local-project-directories*) :dists (loop for dist in (enabled-dists) collect (list :name (name dist) :dist-url (canonical-distinfo-url dist) :version (version dist)))))) (defmethod write-bundle ((bundle bundle) target) (unpack-releases bundle target) (let ((index-file (merge-pathnames "system-index.txt" target)) (loader-file (merge-pathnames "bundle.lisp" target)) (local-projects (merge-pathnames "local-projects/" target)) (metadata-file (merge-pathnames "bundle-info.sexp" target))) (ensure-directories-exist local-projects) (with-open-file (stream index-file :direction :output :if-exists :supersede) (write-system-index bundle stream)) (with-open-file (stream loader-file :direction :output :if-exists :supersede) (write-loader-script bundle stream)) (with-open-file (stream metadata-file :direction :output :if-exists :supersede) (with-standard-io-syntax (let ((*print-pretty* t)) (prin1 (bundle-metadata-plist bundle) stream) (terpri stream)))) (probe-file loader-file))) (defun copy-file (from-file to-file) (with-open-file (from-stream from-file :element-type '(unsigned-byte 8) :if-does-not-exist nil) (when from-stream (let ((buffer (make-array 10000 :element-type '(unsigned-byte 8)))) (with-open-file (to-stream to-file :direction :output :if-exists :supersede :element-type '(unsigned-byte 8)) (loop (let ((end-index (read-sequence buffer from-stream))) (when (zerop end-index) (return to-file)) (write-sequence buffer to-stream :end end-index)))))))) (defun copy-directory-tree (from-directory to-directory) ;; Use the truename here to ensure that relative pathnames match up ;; properly. For example, on SBCL, "~/foo/bar/" entries are not ;; relative to "/home/baz/foo/bar/" entries. (setf from-directory (truename from-directory)) (map-directory-tree from-directory (lambda (from-pathname) (when (probe-file from-pathname) (let* ((relative (enough-namestring from-pathname from-directory)) (relative-directory (pathname-directory relative)) (to-pathname (merge-pathnames relative to-directory))) (unless (or (null relative-directory) (eql (first relative-directory) :relative)) (error "Expected relative pathname to copy from ~A ~ - bad symlink? - ~S" from-pathname relative)) (ensure-directories-exist to-pathname) (copy-file from-pathname to-pathname)))))) (defun copy-local-projects-directories (local-projects-directories to-directory) "Copy the local-projects directories to TO-DIRECTORY. Each one gets a distinct subdirectory." (loop for prefix from 0 for prefix-directory = (make-pathname :directory (list :relative (format nil "~4,'0X" prefix))) for from-directory in local-projects-directories for real-to-directory = (merge-pathnames prefix-directory to-directory) do (format *bundle-progress-output* "~&; Copying ~A to bundle..." from-directory ) (force-output *bundle-progress-output*) (ensure-directories-exist real-to-directory) (copy-directory-tree from-directory real-to-directory) (format *bundle-progress-output* "done.~%") (force-output *bundle-progress-output*))) (defun ql:bundle-systems (system-names &key include-local-projects to (overwrite t)) "In the directory TO, construct a self-contained bundle of libraries based on SYSTEM-NAMES. For each system named, and its recursive required systems, unpack its release archive in TO/software/, and write a system index, compatible with the output of QL:WRITE-ASDF-MANIFEST-FILE, to TO/system-index.txt. Write a loader script to TO/bundle.lisp that, when loaded via CL:LOAD, configures ASDF to load systems from the bundle before any other system. SYSTEM-NAMES must name systems provided directly by Quicklisp. If INCLUDE-LOCAL-PROJECTS is true, each directory in QL:*LOCAL-PROJECT-DIRECTORIES* is copied into the bundle and loaded before any of the other bundled systems." (unless to (error "TO argument must be provided")) (let* ((bundle (make-instance 'bundle :requested-systems system-names)) (to (coerce-to-directory to)) (software (merge-pathnames "software/" to))) (when (and (probe-directory to) (not overwrite)) (cerror "Overwrite it" 'bundle-directory-exists :directory to)) (when (probe-directory software) (delete-directory-tree software)) (add-systems-recursively system-names bundle) (let ((bundled-local-projects (merge-pathnames "bundled-local-projects/" to))) (when include-local-projects (when (probe-directory bundled-local-projects) (delete-directory-tree bundled-local-projects)) (copy-local-projects-directories ql:*local-project-directories* bundled-local-projects) (ensure-directories-exist bundled-local-projects) (ql::make-system-index bundled-local-projects))) (values (write-bundle bundle to) bundle)))
14,070
Common Lisp
.lisp
315
34.974603
89
0.62686
enzuru/home
6
0
1
GPL-3.0
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
45e4844452b88a4e5c421711384bbe72c97b41d2b46de683fbae6610e5308031
14,716
[ 174445, 481830 ]
14,717
fetch-gzipped.lisp
enzuru_home/quicklisp/quicklisp/fetch-gzipped.lisp
;;;; fetch-gzipped.lisp (in-package #:quicklisp-client) (defun gzipped-url (url) (check-type url string) (concatenate 'string url ".gz")) (defun fetch-gzipped-version (url file &key quietly) (let ((gzipped (gzipped-url url)) (gzipped-temp (merge-pathnames "gzipped.tmp" file))) (fetch gzipped gzipped-temp :quietly quietly) (gunzip gzipped-temp file) (delete-file-if-exists gzipped-temp) (probe-file file))) (defun url-not-suitable-error-p (condition) (<= 400 (unexpected-http-status-code condition) 499)) (defun maybe-fetch-gzipped (url file &key quietly) (handler-case (fetch-gzipped-version url file :quietly quietly) (unexpected-http-status (condition) (cond ((url-not-suitable-error-p condition) (fetch url file :quietly quietly) (probe-file file)) (t (error condition))))))
887
Common Lisp
.lisp
23
32.913043
60
0.675991
enzuru/home
6
0
1
GPL-3.0
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
89db16c8a218c3219a4b956f44b367c4f4849aa08cde0c9ebaa2fce76423bbc5
14,717
[ 259400, 372524 ]
14,718
misc.lisp
enzuru_home/quicklisp/quicklisp/misc.lisp
;;;; misc.lisp (in-package #:quicklisp-client) ;;; ;;; This stuff will probably end up somewhere else. ;;; (defun use-only-quicklisp-systems () (asdf:initialize-source-registry '(:source-registry :ignore-inherited-configuration)) (asdf:map-systems 'asdf:clear-system) t) (defun who-depends-on (system-name) "Return a list of names of systems that depend on SYSTEM-NAME." (setf system-name (string-downcase system-name)) (loop for system in (provided-systems t) when (member system-name (required-systems system) :test 'string=) collect (name system)))
587
Common Lisp
.lisp
16
33.5
74
0.726631
enzuru/home
6
0
1
GPL-3.0
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
3990cf410ff4cdd4f1b8c18c32e9576a83fdcbd28330cb702c68e337b856269a
14,718
[ 64313 ]
14,719
network.lisp
enzuru_home/quicklisp/quicklisp/network.lisp
;;; ;;; Low-level networking implementations ;;; (in-package #:ql-network) (definterface host-address (host) (:implementation t host) (:implementation sbcl (ql-sbcl:host-ent-address (ql-sbcl:get-host-by-name host)))) (definterface open-connection (host port) (:documentation "Open and return a network connection to HOST on the given PORT.") (:implementation t (declare (ignore host port)) (error "Sorry, quicklisp in implementation ~S is not supported yet." (lisp-implementation-type))) (:implementation allegro (ql-allegro:make-socket :remote-host host :remote-port port)) (:implementation abcl (let ((socket (ql-abcl:make-socket host port))) (ql-abcl:get-socket-stream socket :element-type '(unsigned-byte 8)))) (:implementation ccl (ql-ccl:make-socket :remote-host host :remote-port port)) (:implementation clasp (let* ((endpoint (ql-clasp:host-ent-address (ql-clasp:get-host-by-name host))) (socket (make-instance 'ql-clasp:inet-socket :protocol :tcp :type :stream))) (ql-clasp:socket-connect socket endpoint port) (ql-clasp:socket-make-stream socket :element-type '(unsigned-byte 8) :input t :output t :buffering :full))) (:implementation clisp (ql-clisp:socket-connect port host :element-type '(unsigned-byte 8))) (:implementation cmucl (let ((fd (ql-cmucl:connect-to-inet-socket host port))) (ql-cmucl:make-fd-stream fd :element-type '(unsigned-byte 8) :binary-stream-p t :input t :output t))) (:implementation scl (let ((fd (ql-scl:connect-to-inet-socket host port))) (ql-scl:make-fd-stream fd :element-type '(unsigned-byte 8) :input t :output t))) (:implementation ecl (let* ((endpoint (ql-ecl:host-ent-address (ql-ecl:get-host-by-name host))) (socket (make-instance 'ql-ecl:inet-socket :protocol :tcp :type :stream))) (ql-ecl:socket-connect socket endpoint port) (ql-ecl:socket-make-stream socket :element-type '(unsigned-byte 8) :input t :output t :buffering :full))) (:implementation mezzano (ql-mezzano:tcp-stream-connect host port :element-type '(unsigned-byte 8))) (:implementation mkcl (let* ((endpoint (ql-mkcl:host-ent-address (ql-mkcl:get-host-by-name host))) (socket (make-instance 'ql-mkcl:inet-socket :protocol :tcp :type :stream))) (ql-mkcl:socket-connect socket endpoint port) (ql-mkcl:socket-make-stream socket :element-type '(unsigned-byte 8) :input t :output t :buffering :full))) (:implementation lispworks (ql-lispworks:open-tcp-stream host port :direction :io :errorp t :read-timeout nil :element-type '(unsigned-byte 8) :timeout 5)) (:implementation sbcl (let* ((endpoint (ql-sbcl:host-ent-address (ql-sbcl:get-host-by-name host))) (socket (make-instance 'ql-sbcl:inet-socket :protocol :tcp :type :stream))) (ql-sbcl:socket-connect socket endpoint port) (ql-sbcl:socket-make-stream socket :element-type '(unsigned-byte 8) :input t :output t :buffering :full)))) (definterface read-octets (buffer connection) (:documentation "Read from CONNECTION into BUFFER. Returns the number of octets read.") (:implementation t (read-sequence buffer connection)) (:implementation allegro (ql-allegro:read-vector buffer connection)) (:implementation clisp (ql-clisp:read-byte-sequence buffer connection :no-hang nil :interactive t))) (definterface write-octets (buffer connection) (:documentation "Write the contents of BUFFER to CONNECTION.") (:implementation t (write-sequence buffer connection) (finish-output connection))) (definterface close-connection (connection) (:implementation t (ignore-errors (close connection)))) (definterface call-with-connection (host port fun) (:documentation "Establish a network connection to HOST on PORT and call FUN with that connection as the only argument. Unconditionally closes the connection afterwareds via CLOSE-CONNECTION in an unwind-protect. See also WITH-CONNECTION.") (:implementation t (let (connection) (unwind-protect (progn (setf connection (open-connection host port)) (funcall fun connection)) (when connection (close-connection connection)))))) (defmacro with-connection ((connection host port) &body body) `(call-with-connection ,host ,port (lambda (,connection) ,@body)))
5,767
Common Lisp
.lisp
132
29.681818
75
0.544695
enzuru/home
6
0
1
GPL-3.0
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
f5f88071c009593c286143e30341a1e8b27f0d20b499731017cce8248f8d476c
14,719
[ 458697 ]
14,720
local-projects.lisp
enzuru_home/quicklisp/quicklisp/local-projects.lisp
;;;; local-projects.lisp ;;; ;;; Local project support. ;;; ;;; Local projects can be placed in <quicklisp>/local-projects/. New ;;; entries in that directory are automatically scanned for system ;;; files for use with QL:QUICKLOAD. ;;; ;;; This works by keeping a cache of system file pathnames in ;;; <quicklisp>/local-projects/system-index.txt. Whenever the ;;; timestamp on the local projects directory is newer than the ;;; timestamp on the system index file, the entire tree is re-scanned ;;; and cached. ;;; ;;; This will pick up system files that are created as a result of ;;; creating new project directory in <quicklisp>/local-projects/, ;;; e.g. unpacking a tarball or zip file, checking out a project from ;;; version control, etc. It will NOT pick up a system file that is ;;; added sometime later in a subdirectory; for that, the ;;; REGISTER-LOCAL-PROJECTS function is needed to rebuild the system ;;; file index. ;;; ;;; In the event there are multiple systems of the same name in the ;;; directory tree, the one with the shortest pathname namestring is ;;; used. This is intended to ignore stuff like _darcs pristine ;;; directories. ;;; ;;; Work in progress! ;;; (in-package #:quicklisp-client) (defparameter *local-project-directories* (list (qmerge "local-projects/")) "The default local projects directory.") (defun system-index-file (pathname) "Return the system index file for the directory PATHNAME." (merge-pathnames "system-index.txt" pathname)) (defun matching-directory-files (directory fun) (let ((result '())) (map-directory-tree directory (lambda (file) (when (funcall fun file) (push file result)))) result)) (defun local-project-system-files (pathname) "Return a list of system files under PATHNAME." (let* ((files (matching-directory-files pathname (lambda (file) (equalp (pathname-type file) "asd"))))) (setf files (sort files #'string< :key #'namestring)) (stable-sort files #'< :key (lambda (file) (length (namestring file)))))) (defun make-system-index (pathname) "Create a system index file for all system files under PATHNAME. Current format is one native namestring per line." (setf pathname (truename pathname)) (with-open-file (stream (system-index-file pathname) :direction :output :if-exists :rename-and-delete) (dolist (system-file (local-project-system-files pathname)) (let ((system-path (enough-namestring system-file pathname))) (write-line (native-namestring system-path) stream))) (probe-file stream))) (defun find-valid-system-index (pathname) "Find a valid system index file for PATHNAME; one that both exists and has a newer timestamp than PATHNAME." (let* ((file (system-index-file pathname)) (probed (probe-file file))) (when (and probed (<= (directory-write-date pathname) (file-write-date probed))) probed))) (defun ensure-system-index (pathname) "Find or create a system index file for PATHNAME." (or (find-valid-system-index pathname) (make-system-index pathname))) (defun find-system-in-index (system index-file) "If any system pathname in INDEX-FILE has a pathname-name matching SYSTEM, return its full pathname." (with-open-file (stream index-file) (loop for namestring = (read-line stream nil) while namestring when (string= system (pathname-name namestring)) return (or (probe-file (merge-pathnames namestring index-file)) ;; If the indexed .asd file doesn't exist anymore ;; then regenerate the index and restart the search. (find-system-in-index system (make-system-index (directory-namestring index-file))))))) (defun local-projects-searcher (system-name) "This function is added to ASDF:*SYSTEM-DEFINITION-SEARCH-FUNCTIONS* to use the local project directory and cache to find systems." (dolist (directory *local-project-directories*) (when (probe-directory directory) (let ((system-index (ensure-system-index directory))) (when system-index (let ((system (find-system-in-index system-name system-index))) (when system (return system)))))))) (defun list-local-projects () "Return a list of pathnames to local project system files." (let ((result (make-array 16 :fill-pointer 0 :adjustable t)) (seen (make-hash-table :test 'equal))) (dolist (directory *local-project-directories* (coerce result 'list)) (let ((index (ensure-system-index directory))) (when index (with-open-file (stream index) (loop for line = (read-line stream nil) while line do (let ((pathname (merge-pathnames line index))) (unless (gethash (pathname-name pathname) seen) (setf (gethash (pathname-name pathname) seen) t) (vector-push-extend (merge-pathnames line index) result)))))))))) (defun register-local-projects () "Force a scan of the local projects directory to create the system file index." (map nil 'make-system-index *local-project-directories*)) (defun list-local-systems () "Return a list of local project system names." (mapcar #'pathname-name (list-local-projects)))
5,706
Common Lisp
.lisp
124
37.895161
108
0.646372
enzuru/home
6
0
1
GPL-3.0
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
c01a049f03b266c6de4a642d8e14802b84baf04a93c0822b781e4e5e648c35aa
14,720
[ 169198, 378721 ]
14,721
quicklisp.asd
enzuru_home/quicklisp/quicklisp/quicklisp.asd
;;;; quicklisp.asd (defpackage #:ql-info (:export #:*version*)) (defvar ql-info:*version* (with-open-file (stream (merge-pathnames "version.txt" *load-truename*)) (read-line stream))) (asdf:defsystem #:quicklisp :description "The Quicklisp client application." :author "Zach Beane <[email protected]>" :license "BSD-style" :serial t :version #.(remove-if-not #'digit-char-p ql-info:*version*) :components ((:file "package") (:file "utils") (:file "config") (:file "impl") (:file "impl-util") (:file "network") (:file "progress") (:file "http") (:file "deflate") (:file "minitar") (:file "cdb") (:file "dist") (:file "setup") (:file "client") (:file "fetch-gzipped") (:file "client-info") (:file "client-update") (:file "dist-update") (:file "misc") (:file "local-projects") (:file "bundle")))
1,117
Common Lisp
.lisp
33
23.060606
74
0.486586
enzuru/home
6
0
1
GPL-3.0
9/19/2024, 11:27:13 AM (Europe/Amsterdam)
c3c6c709bd09c6e5d0b8bf7ac64489a718b30d1d050147a608d6a0e8b8bca94b
14,721
[ 5838, 455302 ]