File: record.tst

package info (click to toggle)
gap-utils 0.93-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 1,504 kB
  • sloc: xml: 2,167; javascript: 155; makefile: 105
file content (65 lines) | stat: -rw-r--r-- 2,401 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#@local  r, defaults, PrintDimensions, mydim

##############################################################################
##
#W  record.tst                  Utils Package                    
##
#Y  Copyright (C) 2015-2022, The GAP Group 
##  

gap> ReadPackage( "utils", "tst/loadall.g" );;
gap> UtilsLoadingComplete;
true

## SubSection 8.1.1 
gap> r := rec( a := 1, b := 2, c := 3 );;                                      
gap> AssignGlobals( r );
The following global variables have been assigned:
[ "a", "b", "c" ]
gap> [ a, b, c ];
[ 1, 2, 3 ]

## SubSection 8.2.1 
gap> defaults := rec( a := 1, b := 2, c := 3 );;
gap> OptionRecordWithDefaults( defaults, rec( a := 6) );
rec( a := 6, b := 2, c := 3 )
gap> OptionRecordWithDefaults( defaults, rec( b := 7, c := 8 ) );
rec( a := 1, b := 7, c := 8 )
gap> OptionRecordWithDefaults( defaults, [ ] );
rec( a := 1, b := 2, c := 3 )
gap> OptionRecordWithDefaults( defaults, [ rec( c := 8 ) ] );
rec( a := 1, b := 2, c := 8 )
gap> OptionRecordWithDefaults( defaults, rec( d := 9 ) );
Error, Unknown option: d
gap> OptionRecordWithDefaults( defaults, [ rec( b := 7 ), rec( c := 8 ) ] );
Error, Too many arguments for function
gap> OptionRecordWithDefaults( defaults, 5 );
Error, Options should be a record
gap> OptionRecordWithDefaults( defaults, [6,7,8] );
Error, Too many arguments for function

gap> PrintDimensions := function( arg ) 
>        local nargs, dim, order, V, L, len, K, i; 
>        nargs := Length( arg ); 
>        dim := [ arg[1]!.height, arg[1]!.width, arg[1]!.depth ]; 
>        order := rec( h := 1, w := 2, d := 3 ); 
>        V := [ "height", "width", "depth" ]; 
>        if ( nargs > 1 ) and IsRecord( arg[2] ) then 
>            order := OptionRecordWithDefaults( order, arg[2] ); 
>        fi; 
>        L := [ order!.h, order!.w, order!.d ]; 
>        len := Length( L );
>        K := [ 1..len ]; 
>        SortParallel( L, K ); 
>        Print( "dimensions: " ); 
>        Print( V[K[1]], " = ", dim[K[1]], ", " );
>        Print( V[K[2]], " = ", dim[K[2]], ", " );
>        Print( V[K[3]], " = ", dim[K[3]], "\n" );
>    end;;

gap> mydim := rec( height := 45, width := 31, depth := 17 ); 
rec( depth := 17, height := 45, width := 31 )
gap> PrintDimensions( mydim );
dimensions: height = 45, width = 31, depth = 17
gap> PrintDimensions( mydim, rec( h:=3, w:=1, d:=2 ) );
dimensions: width = 31, depth = 17, height = 45