3 |
@chapter Simple Generic Data Types |
@chapter Simple Generic Data Types |
4 |
|
|
5 |
This chapter describes those of Guile's simple data types which are |
This chapter describes those of Guile's simple data types which are |
6 |
primarily are used for their role as items of generic data. By |
primarily used for their role as items of generic data. By |
7 |
@dfn{simple} we mean data types that are not primarily used as |
@dfn{simple} we mean data types that are not primarily used as |
8 |
containers to hold other data --- i.e. pairs, lists, vectors and so on. |
containers to hold other data --- i.e. pairs, lists, vectors and so on. |
9 |
For the documentation of such @dfn{compound} data types, see |
For the documentation of such @dfn{compound} data types, see |
193 |
|
|
194 |
@deffn {Scheme Procedure} number? obj |
@deffn {Scheme Procedure} number? obj |
195 |
@deffnx {C Function} scm_number_p (obj) |
@deffnx {C Function} scm_number_p (obj) |
196 |
Return @code{#t} if @var{obj} is any kind of number, @code{#f} else. |
Return @code{#t} if @var{obj} is any kind of number, else @code{#f}. |
|
@findex number? |
|
197 |
@end deffn |
@end deffn |
198 |
|
|
199 |
For example: |
For example: |
264 |
|
|
265 |
@deffn {Scheme Procedure} integer? x |
@deffn {Scheme Procedure} integer? x |
266 |
@deffnx {C Function} scm_integer_p (x) |
@deffnx {C Function} scm_integer_p (x) |
267 |
Return @code{#t} if @var{x} is an integer number, @code{#f} else. |
Return @code{#t} if @var{x} is an integer number, else @code{#f}. |
268 |
|
|
269 |
@lisp |
@lisp |
270 |
(integer? 487) |
(integer? 487) |
328 |
|
|
329 |
@deffn {Scheme Procedure} real? obj |
@deffn {Scheme Procedure} real? obj |
330 |
@deffnx {C Function} scm_real_p (obj) |
@deffnx {C Function} scm_real_p (obj) |
331 |
Return @code{#t} if @var{obj} is a real number, @code{#f} else. |
Return @code{#t} if @var{obj} is a real number, else @code{#f}. |
332 |
Note that the sets of integer and rational values form subsets |
Note that the sets of integer and rational values form subsets |
333 |
of the set of real numbers, so the predicate will also be fulfilled |
of the set of real numbers, so the predicate will also be fulfilled |
334 |
if @var{obj} is an integer number or a rational number. |
if @var{obj} is an integer number or a rational number. |
|
@findex real? |
|
335 |
@end deffn |
@end deffn |
336 |
|
|
337 |
@deffn {Scheme Procedure} rational? x |
@deffn {Scheme Procedure} rational? x |
1462 |
* String Searching:: Searching in strings. |
* String Searching:: Searching in strings. |
1463 |
* Alphabetic Case Mapping:: Convert the alphabetic case of strings. |
* Alphabetic Case Mapping:: Convert the alphabetic case of strings. |
1464 |
* Appending Strings:: Appending strings to form a new string. |
* Appending Strings:: Appending strings to form a new string. |
1465 |
|
* String Miscellanea:: Miscellaneous string procedures. |
1466 |
@end menu |
@end menu |
1467 |
|
|
1468 |
@node String Syntax |
@node String Syntax |
1858 |
@end deffn |
@end deffn |
1859 |
|
|
1860 |
|
|
1861 |
|
@node String Miscellanea |
1862 |
|
@subsection String Miscellanea |
1863 |
|
|
1864 |
|
This section contains all remaining string procedures. |
1865 |
|
|
1866 |
|
@deffn {Scheme Procedure} string-ci->symbol str |
1867 |
|
@deffnx {C Function} scm_string_ci_to_symbol (str) |
1868 |
|
Return the symbol whose name is @var{str}. @var{str} is |
1869 |
|
converted to lowercase before the conversion is done, if Guile |
1870 |
|
is currently reading symbols case-insensitively. |
1871 |
|
@end deffn |
1872 |
|
|
1873 |
|
|
1874 |
@node Regular Expressions |
@node Regular Expressions |
1875 |
@section Regular Expressions |
@section Regular Expressions |
1876 |
@tpindex Regular expressions |
@tpindex Regular expressions |
2274 |
@menu |
@menu |
2275 |
* Symbol Read Syntax:: Extended read syntax for symbols. |
* Symbol Read Syntax:: Extended read syntax for symbols. |
2276 |
* Symbol Primitives:: Operations related to symbols. |
* Symbol Primitives:: Operations related to symbols. |
2277 |
|
* Symbol Tables:: Collecting symbols into obarrays. |
2278 |
* Symbol Discrete:: Using symbols as discrete values. |
* Symbol Discrete:: Using symbols as discrete values. |
2279 |
* Symbol Props:: Function slots and property lists. |
* Symbol Props:: Function slots and property lists. |
2280 |
* Symbol Uninterned:: Uninterned symbols. |
* Symbol Uninterned:: Uninterned symbols. |
2284 |
@node Symbol Read Syntax |
@node Symbol Read Syntax |
2285 |
@subsection Extended Read Syntax for Symbols |
@subsection Extended Read Syntax for Symbols |
2286 |
|
|
2287 |
The read syntax for symbols is a sequence of letters, digits, and |
The read syntax for a symbol is a sequence of letters, digits, and |
2288 |
@dfn{extended alphabetic characters}, beginning with a character that |
@dfn{extended alphabetic characters}, beginning with a character that |
2289 |
cannot begin a number. In addition, the special cases of @code{+}, |
cannot begin a number. In addition, the special cases of @code{+}, |
2290 |
@code{-}, and @code{...} are read as symbols even though numbers can |
@code{-}, and @code{...} are read as symbols even though numbers can |
2294 |
they were letters. The set of extended alphabetic characters is: |
they were letters. The set of extended alphabetic characters is: |
2295 |
|
|
2296 |
@example |
@example |
2297 |
! $ % & * + - . / : < = > ? @@ ^ _ ~ |
! $ % & * + - . / : < = > ? @@ ^ _ ~ |
2298 |
@end example |
@end example |
2299 |
|
|
2300 |
In addition to the standard read syntax defined above (which is taken |
In addition to the standard read syntax defined above (which is taken |
2361 |
(eq? 'mISSISSIppi 'mississippi) @result{} #t |
(eq? 'mISSISSIppi 'mississippi) @result{} #t |
2362 |
(string->symbol "mISSISSIppi") @result{} @r{the symbol with name "mISSISSIppi"} |
(string->symbol "mISSISSIppi") @result{} @r{the symbol with name "mISSISSIppi"} |
2363 |
(eq? 'bitBlt (string->symbol "bitBlt")) @result{} #f |
(eq? 'bitBlt (string->symbol "bitBlt")) @result{} #f |
2364 |
(eq? 'JollyWog |
(eq? 'LolliPop |
2365 |
(string->symbol (symbol->string 'JollyWog))) @result{} #t |
(string->symbol (symbol->string 'LolliPop))) @result{} #t |
2366 |
(string=? "K. Harper, M.D." |
(string=? "K. Harper, M.D." |
2367 |
(symbol->string |
(symbol->string |
2368 |
(string->symbol "K. Harper, M.D."))) @result{}#t |
(string->symbol "K. Harper, M.D."))) @result{}#t |
2404 |
@end lisp |
@end lisp |
2405 |
@end deffn |
@end deffn |
2406 |
|
|
2407 |
@deffn {Scheme Procedure} symbol-hash symbol |
@node Symbol Tables |
2408 |
@deffnx {C Function} scm_symbol_hash (symbol) |
@subsection Symbol Tables |
2409 |
Return a hash value for @var{symbol}. |
|
2410 |
@end deffn |
@c FIXME::martin: Are all these procedures still relevant? |
2411 |
|
|
2412 |
|
Guile symbol tables are hash tables. Each hash table, also called an |
2413 |
|
@dfn{obarray} (for `object array'), is a vector of association lists. |
2414 |
|
Each entry in the alists is a pair (@var{SYMBOL} . @var{VALUE}). To |
2415 |
|
@dfn{intern} a symbol in a symbol table means to return its |
2416 |
|
(@var{SYMBOL} . @var{VALUE}) pair, adding a new entry to the symbol |
2417 |
|
table (with an undefined value) if none is yet present. |
2418 |
|
|
2419 |
@deffn {Scheme Procedure} gensym [prefix] |
@deffn {Scheme Procedure} gensym [prefix] |
2420 |
@deffnx {C Function} scm_gensym (prefix) |
@deffnx {C Function} scm_gensym (prefix) |
2425 |
resetting the counter. |
resetting the counter. |
2426 |
@end deffn |
@end deffn |
2427 |
|
|
2428 |
|
@vgone{gentemp,1.6} |
2429 |
|
@vgone{intern-symbol,1.6} |
2430 |
|
@vgone{string->obarray-symbol,1.6} |
2431 |
|
@vgone{symbol-binding,1.6} |
2432 |
|
@vgone{symbol-bound?,1.6} |
2433 |
|
|
2434 |
|
|
2435 |
@node Symbol Discrete |
@node Symbol Discrete |
2436 |
@subsection Using Symbols as Discrete Values |
@subsection Using Symbols as Discrete Values |
2460 |
Change the binding of @var{symbol}'s function slot. |
Change the binding of @var{symbol}'s function slot. |
2461 |
@end deffn |
@end deffn |
2462 |
|
|
2463 |
|
@deffn {Scheme Procedure} symbol-hash symbol |
2464 |
|
@deffnx {C Function} scm_symbol_hash (symbol) |
2465 |
|
Return a hash value for @var{symbol}. |
2466 |
|
@end deffn |
2467 |
|
|
2468 |
|
@deffn {Scheme Procedure} symbol-interned? obarray string |
2469 |
|
@deffnx {C Function} scm_symbol_interned_p (obarray, string) |
2470 |
|
Return @code{#t} if @var{obarray} contains a symbol with name |
2471 |
|
@var{string}, and @code{#f} otherwise. |
2472 |
|
@end deffn |
2473 |
|
|
2474 |
@deffn {Scheme Procedure} symbol-pref symbol |
@deffn {Scheme Procedure} symbol-pref symbol |
2475 |
@deffnx {C Function} scm_symbol_pref (symbol) |
@deffnx {C Function} scm_symbol_pref (symbol) |
2476 |
Return the @dfn{property list} currently associated with @var{symbol}. |
Return the @dfn{property list} currently associated with @var{symbol}. |
2481 |
Change the binding of @var{symbol}'s property slot. |
Change the binding of @var{symbol}'s property slot. |
2482 |
@end deffn |
@end deffn |
2483 |
|
|
2484 |
|
@vgone{symbol-set!,1.6} |
2485 |
|
@vgone{unintern-symbol,1.6} |
2486 |
|
|
2487 |
|
|
2488 |
@node Symbol Uninterned |
@node Symbol Uninterned |
2489 |
@subsection Uninterned Symbols |
@subsection Uninterned Symbols |
2490 |
|
|
2506 |
created and entered into the table so that it can be found later. |
created and entered into the table so that it can be found later. |
2507 |
|
|
2508 |
Sometimes you might want to create a symbol that is guaranteed `fresh', |
Sometimes you might want to create a symbol that is guaranteed `fresh', |
2509 |
i.e., a symbol that did not exist previously. You might also want to |
i.e. a symbol that did not exist previously. You might also want to |
2510 |
somehow guarantee that no one else will ever unintentionally stumble |
somehow guarantee that no one else will ever unintentionally stumble |
2511 |
across your symbol in the future. These properties of a symbol are |
across your symbol in the future. These properties of a symbol are |
2512 |
often needed when generating code during macro expansion. When |
often needed when generating code during macro expansion. When |
2513 |
introducing new temporary variables, you want to guarantee that they |
introducing new temporary variables, you want to guarantee that they |
2514 |
don't conflict with variables in other peoples code. |
don't conflict with variables in other people's code. |
2515 |
|
|
2516 |
The simplest way to arrange for this is to create a new symbol and to |
The simplest way to arrange for this is to create a new symbol but |
2517 |
not enter it into the global table of all symbols. That way, no one |
not enter it into the global table of all symbols. That way, no one |
2518 |
will ever get access to your symbol by chance. Symbols that are not in |
will ever get access to your symbol by chance. Symbols that are not in |
2519 |
the table are called @dfn{uninterned}. Of course, symbols that |
the table are called @dfn{uninterned}. Of course, symbols that |
2572 |
|
|
2573 |
@end lisp |
@end lisp |
2574 |
|
|
2575 |
|
|
2576 |
@node Keywords |
@node Keywords |
2577 |
@section Keywords |
@section Keywords |
2578 |
@tpindex Keywords |
@tpindex Keywords |
2759 |
@node Keyword Procedures |
@node Keyword Procedures |
2760 |
@subsection Keyword Procedures |
@subsection Keyword Procedures |
2761 |
|
|
|
@c FIXME::martin: Review me! |
|
|
|
|
2762 |
The following procedures can be used for converting symbols to keywords |
The following procedures can be used for converting symbols to keywords |
2763 |
and back. |
and back. |
2764 |
|
|