Lists

Each card shows a command to explain. A missed card returns later in the round and starts the schedule over. A card answered correctly moves up the schedule and next appears after 1, 3, 7, then 21 days. Keys 1 to 4 choose an option, h shows a hint, and Enter moves on. A hint keeps the card where it is on the schedule. An ordering card is answered by clicking its items in order, and one wrong click ends it. Time values are in nanoseconds. Progress is stored in this browser.

SourceTCL (Tool Command Language) is the scripting language every place-and-route and timing tool embeds, so the same skills carry between them. These cards follow the official Tcl manual pages, and each answer links to the page for that command. The examples are in the style the OpenROAD-flow-scripts scripts use, since that is Tcl written for a real flow. Reference: the Tcl manual (Tcl on GitHub).
All 8 cards in this section, with answers
  • set cells {} foreach c [get_cells *] { lappend cells [get_name $c] }
    Appends each name as one element, keeping the list structure intact.

    Hint: Ask what lappend does that set with a concatenation would not.

    A list is not just text with spaces: lappend quotes an element that contains spaces or brackets so it stays a single element. Building a list by string concatenation breaks as soon as a name contains a bracket, which hierarchical names often do. Tcl reference

  • set corners {slow typical fast} set first [lindex $corners 0] set last [lindex $corners end]
    Indexes from 0, and `end` names the last element.

    Hint: Note where counting starts, and the word used for the other end.

    end and arithmetic on it, such as end-1, work in every list command that takes an index. llength gives the count, and lrange takes a span, so lrange $corners 1 end drops the first element. Tcl reference

  • lsort -real -decreasing $slacks
    Sorts numerically and largest first, rather than as text ascending.

    Hint: Ask what the default comparison would do to numbers.

    Sorting defaults to text order, where 10 comes before 9. -real and -integer compare numerically, -unique removes duplicates, and -command sorts with your own procedure, which is how a list of objects is sorted by a property. Tcl reference

  • lassign [split $line ":"] rule value set parts [split "metal1 metal2 metal3"]
    Assigns list elements to named variables, and splits text into a list.

    Hint: One takes a list apart into variables; the other makes a list from text.

    split cuts text at every character of the separator set, defaulting to whitespace; join is its inverse. lassign unpacks a list positionally, which is the readable way to take apart a line already parsed into fields. Tcl reference

  • set corners {slow typical fast} lsearch $corners typical lsearch -exact -not -inline -all $corners typical
    The position of a match, or minus one.

    Hint: The plain form answers where, not whether.

    The plain call returns an index, so a test reads if {[lsearch $l $x] >= 0}. Options change both the matching and the result: -exact, -glob, and -regexp choose how to match, -all returns every index, and -inline returns the elements instead. Tcl reference

  • set corners {slow typical fast} lreplace $corners 1 1 nominal puts $corners
    The original is unchanged, since the command returns a new list.

    Hint: Ask what the last line prints.

    Every list command except lappend and lset returns a value and leaves its argument alone, so the result has to be assigned. Forgetting this is why a filtered list comes out identical to the one it was built from. Tcl reference

  • join {metal1 metal2 metal3} ", " concat {a b} {c d}
    The first makes one string with a separator; the second merges lists.

    Hint: One produces a string, the other a list.

    Joining is how a report line or a comma-separated argument is built, and split is its inverse. Merging produces a flat list, which is the difference from lappend, since appending a list adds it as one element. Tcl reference

  • set pin {dpath/a_reg[9]/D} report_slack $pin eval "report_slack $pin"
    The second substitutes the name a second time, so the brackets run as a command.

    Hint: One of the two lines lets the brackets be seen by the interpreter again.

    Substitution happens once per evaluation, so passing a variable directly is safe however strange the name is. Building a command as a string and evaluating it exposes every special character again. Where a command must be built, list quotes each part correctly. Tcl reference