Next: , Previous: , Up: Top  


11 Additional Functions

11.1 cond ⇒ $[x;y;z]

If x then y else z.

 $[3>2;`a;`b]
`a
 $[2>3;`a;`b]
`b

11.2 amend ⇒ @[x;i;f[;y]]

Replace the values in list x at indices i with f or f[y].

@[x;i;f] examples

 x:(`x00`x01;`x10`x11`x12;`x20;`x30`x31`x32);x
x00 x01    
x10 x11 x12
x20        
x30 x31 x32

 @[x;,1;`newValue]
x00 x01    
newValue   
x20        
x30 x31 x32

 @[x;1 2;`newValue]
x00 x01    
newValue   
newValue   
x30 x31 x32

@[x;i;f;y] examples

 x:(0 1;10 11 12;20;30 31 32);x
0 1     
10 11 12
20      
30 31 32

 @[x;,1;*;100]
0 1           
1000 1100 1200
20            
30 31 32      

 @[x;1 2;*;100]
0 1           
1000 1100 1200
2000          
30 31 32      

11.3 dmend ⇒ .[x;i;f[;y]]

.[x;i;f] examples

 x:(`x00`x01;`x10`x11`x12;`x20;`x30`x31`x32);x
x00 x01    
x10 x11 x12
x20        
x30 x31 x32

 .[x;1 2;`newValue]
x00 x01         
x10 x11 newValue
x20             
x30 x31 x32     

.[x;i;f;y] examples

 x:(`x00`x01;`x10`x11`x12;`x20;`x30`x31`x32);x
x00 x01    
x10 x11 x12
x20        
x30 x31 x32

 i:(1 3; 0 1);i
1 3
0 1

 y:(`a`b;`c`d);y
a b
c d

 .[x;i;:;y]
x00 x01
a b x12
x20    
c d x32

 x:(0 1;10 11 12;20;30 31 32);x
0 1     
10 11 12
20      
30 31 32

 .[x;i;*;-1]
0 1       
-10 -11 12
20        
-30 -31 32