modify()

Read(4843) Label: modify,

Here’s how to use modify() function.

r.modify( x i : F i ,… )

Description:

Modify the field values of a record.

Syntax:

r.modify(xi:Fi,)

Note:

The function modifies the field values in record r.

Parameter:

r

The record to be modified

xi

Modification expression

Fi

Name of the field to be modified. The ith field in r will be modified if Fi isn’t supplied

r'

The new record that will replace record r

Option:

@r(r')

Replace record r with record r' according to the former’s order

@f(r')

Modify a certain field value of record r with record r'

Return value:

Record

Example:

 

A

 

1

=[[1,"Lucy",29]].new(~(1):ID,~(2):Name,~(3):Age)

2

=A1(1).modify(2,"Petter")

Modify the first and the second field.

3

=A2.modify(30:Age)

Modify Age field.

4

=A3.modify(3,33:Age)

Modify the first field and Age field.

5

=[[4,"Lily",23]].new(~(1):SID,~(2):SName,~(3):SAge)

6

=A4.modify@r(A5(1))

Fill members of A5(1) in A4 according to A4’s order.

7

=A6.modify@f(([["ella"]].new(~(1):Name))(1))

Modify only the value of Name field in A6.

Related function:

T.modify()

T.insert()

T.delete()

T. modify()

Description:

Modify field values in a table sequence.

Syntax:

T.modify(k,xi:Fi,…)

Modify the kth record, which is equal to T(k).modify(xi:Fi,…)

T.modify(k:A,xi:Fi,…)

Modify the records from the kth record to the (k+|A|-1)th record

Note:

The function modifies one or more records at the specified position(s). Automatically update the index, if any, and check distinctness.

Parameter:

k

The position at which the record will be modified. If k exceeds the limit, then append a new record in the end

xi

The value of Fi field to be modified

Fi

Name of the field of the record which will be modified. If Fi is omitted, then modify the ith field of T

T

A table sequence

A

A sequence or an integer; If A is an integer, then it is equal to to(A)

Option:

@n

Return the newly-modified record or sequence

@r(k:A)

Modify table sequence T using sequence A from the kth record according to the order of the fields

@f(k:A)

Modify table sequence T using sequence A from the kth record; only the common fields are modified.

Return value:

Return the updated record or sequence

Example:

 

A

 

1

=demo.query("select * from DEPARTMENT")

2

=A1.modify(1,"Sales",5)

Modify the first and the second fields of the first record.

3

=A1.modify(2,6:MANAGER)

Modify the MANAGER field of the second record.

4

=A1.modify@n(2:1,"AAA":DEPT,76:MANAGER)

Return the modified second record.

5

=create(DeptName,ManagerID)

 

 

 

6

=A5.modify(1:A1,DEPT:DeptName,MANAGER:ManagerID)

Append a new record in the end because 1 exceeds the limit.

7

=A1.delete(A1.select(MANAGER>5))

 

8

=A5.modify@r(1:A7)

Modify A5 using A7 from the first record.

9

=create(DeptName,MANAGER)

 

10

=A9.modify@f(1:A7)

Modify MANAGER field only.

Related function:

r.modify()

T.insert()

T.delete()

A.modify()

A.modify ()

Description:

Assign value(s) to one or more members of a sequence according to the specified position(s).

Syntax:

A.modify(k,x)

Assign x to the kth member of sequence A

A.modify(k,X)

Assign members of X to members of A in order from the kth position to the (k+|X|-1)th position; do the assignment backward from the end when k<0

Note:

The function assigns x to the kth member of sequence A or members of X to the members of A from the kth position to the number (k+|X|-1)th position in order.

Parameter:

A

A sequence

k

A member position; If k is greater than the length of sequence A, then append the member in the end

x

A member value

X

A sequence

Option:

@n

Return the modified record or a record sequence of modified records

Return value:

A sequence

Example:

 

A

 

1

=["a","c","d","e","f"]

 

2

=A1.modify(2,"g")

[a,g,d,e,f].

3

=A1.modify(6,[2,4,5])

[a,g,d,e,f,2,4,5]; append the values at the end as the specified position exceeds the limit.

4

=demo.query("select * from STUDENTS")

 

5

=A4.modify@n(2:3,ID+10:ID)

Return a record sequence of modified records.

6

=A1. modify(-2,"h")

Assign values backward and return [a,g,d,e,f,2,4,h,5] as parameter k<0.

Related function:

A.delete()

A.insert()

T.modify()