hping wiki

Differences for page Alist for Tcl

Current version compared with version Tue Nov 16 09:11:34 GMT 2004

...
  The key a is associated with the value 1, b with value 2, and so on.
  (Note: alists are very used in Lisp dialects, but the format is a bit
  different. Every alist element is a two element list, so the format
- is like {[list [list a 1] [list b 2] [list c 3]]}. In Tcl the flat
+ is like {\[list \[list a 1\] \[list b 2\] \[list c 3\]\]}. In Tcl the flat
  list format is more convenient).
  
  Alists are very powerful, because they have many advantages of
...
  
  Alists can be viewed as a mapping from keys to data that can
  be extended, reduced or non-destructively altered at runtime,
- and at the same time be a valid list. [[[CMCc] - incidentally,
- mappings from keys to data can also be fruitfully looked at as partial 
- functions]][[[DKF] - Actually, the alist value is not updatable; it is the variable containing the alist that is updatable; model the variable as a higher-order function from "abstract time" (i.e. generation sequence number) to the relation representing the current alist.]]
+ and at the same time be a valid list.
  
  Alists are very generic, but the first goal of this library
  is provide a way to encapsulate an object representation
...
  in a simple but powerful data structure.
  
- '''RATIONALE''' (skip it if you want just the tutorial)
+ ===RATIONALE=== (skip it if you want just the tutorial)
  
- The alist representation has the benefit to be a valid [[dict]]
+ The alist representation has the benefit to be a valid {\[dict\]}
  representation, but the usage and design is a bit different.
- Basically they are very similar but the API is different: [[dict]]s
+ Basically they are very similar but the API is different: {\[dict\]}s
  are designed to be generic, while this implementation of alists
  is designed to make it easy to be used as powerful structures
  (in the sense of C "struct").
...
  data structure, so to set an unknown key can't just create a new
  key/value pair: it's not defensive programming).
  
- Alists can be implemented very well using [[dict]], but since
- [[dict]] is still only available in Tcl >= 8.5 this implementation
- uses only commands available in Tcl 8.4 (notably [[lset]]).
- Btw note that alists implemented with [[dict]] lost some interesting
+ Alists can be implemented very well using {\[dict\]}, but since
+ {\[dict\]} is still only available in Tcl >= 8.5 this implementation
+ uses only commands available in Tcl 8.4 (notably {\[lset\]}).
+ Btw note that alists implemented with {\[dict\]} lost some interesting
  priprietis (because the lookup is no longer from "left" to "right",
  and also can't hold multiple identical keys).
  
...
- '''BASIC USAGE'''
+ ===BASIC USAGE===
  
- To define a new alist, the [[alist]] command is used:
+ To define a new alist, the {\[alist\]} command is used:
  
      alist flower petals color type
  
...
- The call to the [[alist]] command with this arguments creates
- a command named [[make-flower]] that returns a list representing
+ The call to the {\[alist\]} command with this arguments creates
+ a command named {\[make-flower\]} that returns a list representing
  an alist with the specified keys/values pairs.
  
- To access fields we use the [[alget]] and [[alset]] commands.
+ To access fields we use the {\[alget\]} and {\[alset\]} commands.
  
  For example, to create a flower that's a red rose with 5 petals
  we may write:
...
      alset rose color red
      alset rose type rose
  
- [[alset]] has the following signature:
+ {\[alset\]} has the following signature:
  
      alest alistVar keyPath keyValue ?keyPath keyValue ...?
  
...
- The [[alset]] command takes as arguments the name of a variable that
+ The {\[alset\]} command takes as arguments the name of a variable that
  holds a valid alist, the name of the key to set, and the new value.
  It's possible to specify more than just one key/value pair, so
  the previous last three lines of code are equivalent to:
...
  
      alset rose petals 5 color red type rose
  
- To access the value associated with a given key we use [[alget]], that
+ To access the value associated with a given key we use {\[alget\]}, that
  has the following signature:
  
      alget alistValue keypath
...
  
  Will print: "This flower is a rose with 5 red petals".
  
- Both [[alget]] and [[alset]] will raise an error if the specified
+ Both {\[alget\]} and {\[alset\]} will raise an error if the specified
  key does not exists.
  
- '''DEFAULT VALUES AND INITIALIZATION'''
+ ===DEFAULT VALUES AND INITIALIZATION===
  
  When alists are declared, we can specify the default value for
- every key. This way, the [[make-<alistname>]] command will create
+ every key. This way, the {\[make-<alistname>\]} command will create
  alists with every value initialized to the default value specified
  in the declaration.
  
...
  
     alist flower {petals 0} {color none} {type unknow}
  
- Now every new flower alist created using [[make-flower]] will be
+ Now every new flower alist created using {\[make-flower\]} will be
  initialized with the default values we provided. As you can see
  to specify a default value, instead to use the key name, we use
  a two-element list with the key name and the default value.
...
  Will output: "This flower is a unknown with 0 none petals".
  
  Another way to initialize fields at creation time is to pass
- arguments to the [[make-flower]] function. For example to
+ arguments to the {\[make-flower\]} function. For example to
  create a flower with the default values but with 3 white petals
  we can write:
  
...
     set someflower [make-flower petals 3 color white]
  
  It should be noted that if no default value is specified in the
- alist declaration, nor arguments are passed to the [[make-...]] command,
+ alist declaration, nor arguments are passed to the {\[make-...\]} command,
  all the fields are initialized to a null string.
  
- '''NESTING'''
+ ===NESTING===
  
- alists (like [[dict]]s) are able to nest. Let's see why and how
+ alists (like {\[dict\]}s) are able to nest. Let's see why and how
  to use this feature.
  
  Suppose you are creating a program for a florist that ships
...
  
     alist box color [list content [make-flower]] [list shipaddr [make-address]]
  
- This way all the box created using [[make-box]] will contain nested
+ This way all the box created using {\[make-box\]} will contain nested
  flower and address alists.
  
  Now to create the previous box we can write:
...
  values (so, just strings), so you can pass and return they with
  normal procedures.
  
- '''LISTS OF ALISTS'''
+ ===LISTS OF ALISTS===
  
  Our florist wants to expand it's product line, so it plans to
  ship boxes with more than one flower. The florist's software
...
     alset box content $content
  
  In order to make it more simple, the alist library provides
- the [[allappend]] command that works like [[lappend]] but against
+ the {\[allappend\]} command that works like {\[lappend\]} but against
  alist fields. So we can rewrite the above three lines of code into:
  
     allappend box content [make-flower color blue type tulipan]
...
  
  '''ALISTS TYPE SYSTEM'''
  
- Every time an alist is created by the [[make-<name>]] command,
+ Every time an alist is created by the {\[make-<name>\]} command,
  the generated alist contains all the keys the user specified
  in the alist definition of that name, plus an additional
  key __alisttype__ that has as default value the name of the
...
     alget $p __alisttype__
  
  Instead to directly get the __alisttype__ key, there is the
- command [[altype]] that does just this. So the above code is
+ command {\[altype\]} that does just this. So the above code is
  equivalent to:
  
     altype $p
...
  
  The output will be 1020, 10 20 and 30
  
- '''OTHER UTILITIES'''
+ ===OTHER UTILITIES===
  
- [[alincr]] increments the integer at the specified alist's key.
+ {\[alincr\]} increments the integer at the specified alist's key.
  Example:
  
     alincr alistVarName x.y -3
...
  
  The last argument (the increment) can be omitted and defaults to 1.
  
- [[alsappend]] is like [[allappend]] but append strings to the specified
+ {\[alsappend\]} is like {\[allappend\]} but append strings to the specified
  string instead to elements to the specified list.
  
- it's called 'sappend' because append strings. Since [[allappend]] is
- similar to [[lappend]], and [[alsappend]] is similar to [[append]] you may
- wonder why the name of this command is not just [[alappend]]. That's because
+ it's called 'sappend' because append strings. Since {\[allappend\]} is
+ similar to {\[lappend\]}, and {\[alsappend\]} is similar to {\[append\]} you may
+ wonder why the name of this command is not just {\[alappend\]}. That's because
  it's too simple to write "alappend" instead of "allappend".
  
  Happy nesting.
...
- }
  
   # Alists - Lisp-like alist data structures.
   # Copyright (C) 2004 Salvatore Sanfilippo <antirez@invece.org>.
...

The following is the old page content