box
TOC »
- box
- Documentation
- Box Core
- Usage
- Box syntax
- make-box
- make-box-mutable
- make-box-immutable
- make-box-variable
- make-box-location
- box?
- box-mutable?
- box-immutable?
- box-variable?
- box-location?
- box-set!
- box-ref
- box-location
- box-swap!
- make-box-variable-closure
- make-box-location-closure
- Box Core Literals
- Box Values
- Box Values Literals
- SRFI-111
- Examples
- Requirements
- Bugs and Limitations
- Author
- Repository
- Version history
- License
Documentation
Implements the box data type, both single and multiple valued. A single valued, or core, box is a cell containing a mutable or immutable field. A multiple valued. or values, box is a cell containing a mutable tuple of, 0 or more, values.
The core boxed value maybe any Scheme type, including a variable or a location. The values box will only box Scheme data objects, not a variable or a location.
Box Core
Usage
(import box-core)
Box syntax
The lexical syntax of a box containing the scheme-object S* is #&S*.
Only mutable boxes can be recovered. An immutable, variable, or location box will lose identity when printed.
make-box
- (make-box [INITIAL [IMMUTABLE? #f]]) -> boxprocedure
Returns a BOX with, optional, initial value INITIAL.
The BOX is mutable unless the IMMUTABLE? argument is #t.
An attempt to mutate an immutable box will signal an exception.
make-box-mutable
- make-box-mutable #!optional INITIALprocedure
Returns a BOX with, optional, initial value INITIAL.
make-box-immutable
- make-box-immutable INITIALprocedure
Returns a BOX with an initial value INITIAL.
An attempt to mutate an immutable box will signal an exception.
make-box-variable
- (make-box-variable VARIABLE [IMMUTABLE? #f]) -> boxsyntax
Returns a boxed reference to the VARIABLE, which must be in lexical-scope.
The BOX is mutable unless the IMMUTABLE? argument is #t.
An attempt to mutate an immutable box will signal an exception.
make-box-location
- (make-box-location TYPE INITIAL-VALUE [IMMUTABLE? #f]) -> boxsyntax
Returns a boxed reference to a location of TYPE and INITIAL-VALUE.
The BOX is mutable unless the IMMUTABLE? argument is #t.
An attempt to mutate an immutable box will signal an exception.
Unavailable in EVALuated source.
box?
- box? OBJECTprocedure
Is OBJECT a BOX?
box-mutable?
- box-mutable? OBJECTprocedure
Is OBJECT a mutable BOX?
box-immutable?
- box-immutable? OBJECTprocedure
Is OBJECT an immutable BOX?
box-variable?
- box-variable? OBJECTprocedure
Is OBJECT a boxed variable?
box-location?
- box-location? OBJECTprocedure
Is OBJECT a boxed location?
box-set!
- box-set! BOX OBJECTprocedure
Changes the boxed value of BOX to OBJECT. Will signal an exception for an immutable {{BOX}.
box-ref
- box-ref BOXprocedure
Returns the boxed value of BOX.
box-location
- (box-location BOX [WEAK? #f]) -> locationprocedure
Returns a LOCATION object for a boxed variable, location or locatable box. Signals an exception otherwise.
The locative is "strong" unless the WEAK? argument is #t. The WEAK? argument is ignored for boxed variables and locations.
The location of a boxed value or boxed location is the box. The location of a boxed variable is the same as (location (box-ref BOX)); currently the location of a symbol may not be taken.
See Locations.
box-swap!
- box-swap! BOX FUNC #!optional OBJECT...procedure
Changes the boxed value of BOX to (FUNC <BOX-VALUE> OBJECT...). Will signal an exception for an immutable BOX. Returns the new value of BOX.
make-box-variable-closure
- make-box-variable-closure IMMUTABLE? REF SETprocedure
- IMMUTABLE?
- boolean
- REF
- (-> *)
- SET
- (* -> void)
make-box-location-closure
- make-box-location-closure IMMUTABLE? REF SET REFLOCprocedure
- IMMUTABLE?
- boolean
- REF
- (-> *)
- SET
- (* -> void)
- REFLOC
- (-> location)
Box Core Literals
Usage
(import (box-core literals))
Box syntax
An (import (box-core literals)) registers the read-print syntax of a box containing the scheme-object S* as #&S*.
Only mutable boxes can be recovered. An immutable, variable, or location box will lose identity when printed.
Box Values
Usage
(import (box values))
make-box
- (: make-box (#!rest -> boxv))procedure
Collect 0 or more values in a box.
box?
- (: box? (* -> boolean : boxv))procedure
A box?
box-ref
- (: box-ref (boxv -> . *))procedure
Returns 0 or more values from the box.
box-set!
- (: box-set! (boxv #!rest -> void))procedure
Replaces the boxed values with a new tuple of 0 or more values.
box-arity
- (: box-arity (boxv -> fixnum))procedure
Returns the count of boxed values.
box-value-ref
- (: box-value-ref (boxv fixnum -> *))procedure
Returns the boxed value in the tuple at position fixnum.
box-value-set!
- (: box-value-set! (boxv fixnum * -> void))procedure
Replaces the boxed value in the tuple at position fixnum with the object *.
Box Values Literals
Usage
(import (box values literals))
Box syntax
An (import (box values literals)) registers the read-print syntax of boxed values as #N&* where N is a length marker and * is either a single value with 0 length or multiple values with a positive length.
SRFI-111
This API is deprecated & will be removed in favor of the srfi-111 egg.
Usage
(import box)
Examples
#;1> (import box-core (box-core literals)) #;2> (define b (make-box 0)) #;3> b #&0 #;4> (define (inc-box! bx) (set! (box-ref bx) (add1 (box-ref bx)))) #;5> (inc-box! b) #;6> (box-re b) 1 #;7> (box-swap! b add1) 2 #;8> (box-swap! b * 3) 6f #;9> (box-ref b) 6
Requirements
Bugs and Limitations
- The location of a boxed variable is rather useless.
Author
Repository
This egg is hosted on the CHICKEN Subversion repository:
https://anonymous@code.call-cc.org/svn/chicken-eggs/release/5/box
If you want to check out the source code repository of this egg and you are not familiar with Subversion, see this page.
Version history
- 3.8.0
- Add module (box values).
- 3.7.0
- .
- 3.6.0
- Remove check-errors dependency.
- 3.5.0
- Use less of check-errors.
- 3.4.0
- Remove srfi-111 feature & test.
- 3.3.0
- Remove srfi-111 module.
- 3.2.4
- srfi-111 bindings are procedure.
- 3.2.3
- Fix type predicates.
- 3.2.2
- srfi-111 provides box?.
- 3.2.1
- Provide box-core module, box w/o srfi-111 bindings.
- 3.2.0
- Provide srfi-111 module. Add make-box-mutable & make-box-immutable.
- 3.1.0
- Add immutable-box.
- 3.0.0
- CHICKEN 5 release.
License
Copyright (C) 2009-2024 Kon Lovett. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the Software), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED ASIS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.