Re: Using insert()

new topic     » goto parent     » topic index » view thread      » older message » newer message

Append | Concatenate

An append "introduces one new item to the end of a sequence list." An append increases the length of a sequence by one.

s = { ■ , ■ , ■ , ■ } 
 
            -- introducing action 
s = append(s, □ } 
? s 
-->   { ■ , ■ , ■ , ■ , □ } 
sequence s  
 
s = {1,2,3,4} 
s = append(s, 99 ) 
? s 
 --> {1,2,3,4, 99 }   -- one item introduced 
 
s = {1,2,3,4} 
s = append(s, {99} ) 
? s 
 --> {1,2,3,4, {99} }  -- one item introduced 

A prepend "introduces one new item to the start of a sequence list." A prepend works at the start of the sequence list (it is like an append).

A concatenation "joins two objects together." After joining, the final length is equal to the sum of the two original lengths.

s1 = { ■ , ■ , ■ , ■ } 
s2 = { □ , □  } 
 
 
            -- joining action 
? s1 & s2 
--> { ■ , ■ , ■ , ■ ,  □ , □  } 
sequence s1, s2 
 
s1 = {1,2,3,4} 
s2 = {50,60} 
? s1 & s2 
--> {1,2,3,4,50,60} 

Insert | Splice

An insert "introduces one item into a sequence." You can introduce an item at the head of a sequence (use insert or prepend), within a sequence (insert), or at the tail of a sequence (insert or append). The prepend|append actions are very common so they get their own functions. The length of a sequence after an insert increases by one.

s = { ■ , ■ , ■ , ■ } 
s = insert(s, □ , 2 ) 
? s 
  --> { ■ , □ , ■ , ■ , ■ } 
 
 
s = { ■ , ■ , ■ , ■ } 
s = insert(s, 5 ) 
? s 
    --> { ■ , ■ , ■ , ■ , □ } 
 
 
 
    -- an append is the same as an insert to length+1 
s = { ■ , ■ , ■ , ■ } 
s = append(s, □ ) 
? s 
    --> { ■ , ■ , ■ , ■ , □ } 
sequence s 
 
s = {1,2,3,4} 
s = insert(s, 999, 2 ) 
? s 
    --> {1, 999, 2,3,4} 
 
s = {1,2,3,4} 
s = insert(s, 999, 5 ) 
? s 
    --> {1,2,3,4, 999 } 
     
s = {1,2,3,4} 
s = insert(s, 999, 1 ) 
? s 
    --> { 999, 1,2,3,4} 

A splice "joins the ends of objects together." Sum the lengths of the spliced objects to get the length of the new sequence.

s = { ■ , ■ , ■ , ■ } 
s = splice(s, { □ , ▧  }, 2 ) 
? s 
    --> { ■ , □ , ▧ , ■ , ■ , ■ } 
 
 
s = { ■ , ■ , ■ , ■ } 
s = splice(s, { □ , ▧  }, 4 ) 
? s 
    --> { ■ , ■ , ■ , ■ , □ , ▧  } 
     
 
-- a splice at the tail is the same as concatenation & 
 
s = { ■ , ■ , ■ , ■ } 
s = { ■ , ■ , ■ , ■ } & { □ , ▧  } 
? s 
    --> { ■ , ■ , ■ , ■ , □ , ▧  } 
sequence s 
 
s = {1,2,3,4} 
s = splice(s, {66,99}, 2 ) 
? s 
    --> {1,  66,99,  2,3,4 } 
 
s = {1,2,3,4} 
s = splice(s, {66,99}, 5 ) 
? s 
    --> {1,2,3,4, 66,99 } 
 
s = {1,2,3,4} 
s = s & {66,99} 
? s 
    --> {1,2,3,4, 66,99 } 

string | sequence

A string is "a flat sequence of atoms." Each atom being an integer code for plain text or UTF encoding.

If you insert something other than an atom (as a valid code) into a string-- you no longer have a valid string.

str = "●●●●●●●●" 
    -- a string 
 
str = insert(str, {"bad"}, 3 ) 
? str 
    --> { ● , ● , {"bad"}, ● , ● , ● , ● , ● , ● } 
    -- no longer a string 
new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu