798 | | ==== gensym |
| 798 | ==== Symbol utilities |
| 799 | |
| 800 | ===== symbol-append |
| 801 | |
| 802 | <procedure>(symbol-append SYMBOL1 ...)</procedure> |
| 803 | |
| 804 | Creates a new symbol from the concatenated names of the argument symbols |
| 805 | {{(SYMBOL1 ...)}}. |
| 806 | |
| 807 | ==== Uninterned symbols ("gensyms") |
| 808 | |
| 809 | Symbols may be "interned" or "uninterned". Interned symbols are |
| 810 | registered in a global table, and when read back from a port are |
| 811 | identical to a symbol written before: |
| 812 | |
| 813 | <enscript highlight=scheme> |
| 814 | (define sym 'foo) |
| 815 | |
| 816 | (eq? sym (with-input-from-string |
| 817 | (with-output-to-string |
| 818 | (lambda () (write sym))) |
| 819 | read)) |
| 820 | |
| 821 | => #t |
| 822 | </enscript> |
| 823 | |
| 824 | Uninterned symbols on the other hand are not globally registered and so |
| 825 | mulitple symbols with the same name may coexist: |
| 826 | |
| 827 | <enscript highlight=scheme> |
| 828 | (define sym (gensym 'foo)) ; sym is a uninterned symbol like "foo42" |
| 829 | |
| 830 | (eq? sym (with-input-from-string ; the symbol read will be an interned symbol |
| 831 | (with-output-to-string |
| 832 | (lambda () (write sym))) |
| 833 | read)) |
| 834 | |
| 835 | => #f |
| 836 | |
| 837 | (eq? (string->uninterned-symbol "foo") (string->uninterned-symbol "foo")) |
| 838 | |
| 839 | => #f |
| 840 | </enscript> |
| 841 | |
| 842 | Use uninterned symbols if you need to generate unique values that |
| 843 | can be compared quickly, for example as keys into a hash-table |
| 844 | or association list. Note that uninterned symbols loose their |
| 845 | uniqueness property when written to a file and read back in, as |
| 846 | in the example above. |
| 847 | |
| 848 | |
| 849 | ===== gensym |
817 | | Creates a new interned symbol from the concatenated names of the argument symbols |
818 | | {{(SYMBOL1 ...)}}. |
| 870 | ===== get |
| 871 | |
| 872 | <procedure>(get SYMBOL PROPERTY [DEFAULT])</procedure> |
| 873 | |
| 874 | Returns the value stored under the key {{PROPERTY}} in the property |
| 875 | list of {{SYMBOL}}. If no such property is stored, returns |
| 876 | {{DEFAULT}}. The {{DEFAULT}} is optional and defaults to {{#f}}. |
| 877 | |
| 878 | ===== put! |
| 879 | |
| 880 | <procedure>(put! SYMBOL PROPERTY VALUE)</procedure> |
| 881 | setter: (set! (get SYMBOL PROPERTY) VALUE) |
| 882 | |
| 883 | Stores {{VALUE}} under the key {{PROPERTY}} in the property list of |
| 884 | {{SYMBOL}} replacing any previously stored value. |
| 885 | |
| 886 | ===== remprop! |
| 887 | |
| 888 | <procedure>(remprop! SYMBOL PROPERTY)</procedure> |
| 889 | |
| 890 | Deletes the first property matching the key {{PROPERTY}} in the property list |
| 891 | of {{SYMBOL}}. Returns {{#t}} when a deletion performed, and {{#f}} otherwise. |
| 892 | |
| 893 | ===== symbol-plist |
| 894 | |
| 895 | <procedure>(symbol-plist SYMBOL)</procedure> |
| 896 | setter: (set! (symbol-plist SYMBOL) LST) |
| 897 | |
| 898 | Returns the property list of {{SYMBOL}} or sets it. |
| 899 | |
| 900 | ===== get-properties |
| 901 | |
| 902 | <procedure>(get-properties SYMBOL PROPERTIES)</procedure> |
| 903 | |
| 904 | Searches the property list of {{SYMBOL}} for the first property with a key in |
| 905 | the list {{PROPERTIES}}. Returns 3 values: the matching property key, value, |
| 906 | and the tail of property list after the matching property. When no match found |
| 907 | all values are {{#f}}. |
| 908 | |
| 909 | {{PROPERTIES}} may also be an atom, in which case it is treated as a list of |
| 910 | one element. |
1155 | | === Property lists |
1156 | | |
1157 | | As in other Lisp dialects, CHICKEN supports "property lists" associated with symbols. |
1158 | | Properties are accessible via a key that can be any kind of value but which will |
1159 | | be compared using {{eq?}}. |
1160 | | |
1161 | | ==== get |
1162 | | |
1163 | | <procedure>(get SYMBOL PROPERTY [DEFAULT])</procedure> |
1164 | | |
1165 | | Returns the value stored under the key {{PROPERTY}} in the property |
1166 | | list of {{SYMBOL}}. If no such property is stored, returns |
1167 | | {{DEFAULT}}. The {{DEFAULT}} is optional and defaults to {{#f}}. |
1168 | | |
1169 | | ==== put! |
1170 | | |
1171 | | <procedure>(put! SYMBOL PROPERTY VALUE)</procedure> |
1172 | | setter: (set! (get SYMBOL PROPERTY) VALUE) |
1173 | | |
1174 | | Stores {{VALUE}} under the key {{PROPERTY}} in the property list of |
1175 | | {{SYMBOL}} replacing any previously stored value. |
1176 | | |
1177 | | ==== remprop! |
1178 | | |
1179 | | <procedure>(remprop! SYMBOL PROPERTY)</procedure> |
1180 | | |
1181 | | Deletes the first property matching the key {{PROPERTY}} in the property list |
1182 | | of {{SYMBOL}}. Returns {{#t}} when a deletion performed, and {{#f}} otherwise. |
1183 | | |
1184 | | ==== symbol-plist |
1185 | | |
1186 | | <procedure>(symbol-plist SYMBOL)</procedure> |
1187 | | setter: (set! (symbol-plist SYMBOL) LST) |
1188 | | |
1189 | | Returns the property list of {{SYMBOL}} or sets it. |
1190 | | |
1191 | | ==== get-properties |
1192 | | |
1193 | | <procedure>(get-properties SYMBOL PROPERTIES)</procedure> |
1194 | | |
1195 | | Searches the property list of {{SYMBOL}} for the first property with a key in |
1196 | | the list {{PROPERTIES}}. Returns 3 values: the matching property key, value, |
1197 | | and the tail of property list after the matching property. When no match found |
1198 | | all values are {{#f}}. |
1199 | | |
1200 | | {{PROPERTIES}} may also be an atom, in which case it is treated as a list of |
1201 | | one element. |