Forum .LRN Q&A: Re: Strange Code in LORS

Collapse
6: Re: Strange Code in LORS (response to 1)
Posted by Dave Bauer on
Nima,

This code is mostly experimental. Basically if its installed it will allow you to create a couse by hand and add objects from assessment of xowiki into the course.

I can't imagine why that code uses append instead of lappend :) lappend is definitely correct. Each element, as_sections, Questions needs to be a seperate list element too.

Collapse
8: Re: Strange Code in LORS (response to 6)
Posted by Gustaf Neumann on
just to be on the safe side, avoid a stupid thread ala "lappend does not work either". string map uses a flat list for the map. The complete code is:
set pretty_types_map [list]
if { [apm_package_installed_p assessment] } {
  lappend pretty_types_map as_sections Questions
}
if { [apm_package_installed_p xowiki] } {
  lappend pretty_types_map ::xowiki::Page Content
}
In case people ask: why [list] instead of {}?

In byte-code compiled cases, [list] is directly compiled into a Tcl_Obj of type list. If {} is used instead if [list], the Tcl_Obj will be of type string and will be converted into a list by the first lappend operation. In the concrete example, the difference is not important, aside from a documentation point of view. In Tcl it is regarded as a good practice to use [list] where appropriate.

Btw, the code above is not very general, since xowiki supports different types of acs-objects, which are not handled by the snippet above. To label these object_types with "Content", one can query the available object_types by :xowiki::Page object_types and provide for these an entry in the map.

if { [apm_package_installed_p xowiki] } {
  foreach object_type [:xowiki::Page object_types] {
     lappend pretty_types_map $object_type Content
  }
}

The code is untested, i have never used LORS.

Collapse
Posted by Silvia Margarita Baldiris Navarro on
Thanks Gustaf, my lors works very good now!