List Manipulation

I use AS on Mac OS 8.6 and my script contains 2 lists of names.
They are availablep {} & usedp {}
When the script locates the name that I desire I need to add it to usedp and remove it from availablep
The first is easy


set usedp to usedp & the name

My question is “What is the code to delete the name from availablep” ?

All suggestions greatfully appreciated
:cry:

Paul,

Here are two ways of doing it. If you have the Akua List Suite scripting addition you can get it done in a few less lines. Or you can use the completely vanilla system solution employing a repeat.

property usedp : {"Taken Name 1"}
property availablep : {"Unused Name 1", "Unused Name 2", "Unused Name 3"}

set thisName to display dialog "8^)" default answer ""--smile
set thisName to the text returned of the result

--using Akua List Suite 106 (returns only items of availablep that do not match the user entry)
(*if availablep contains thisName then
	set usedp to usedp & thisName--add the name to the used list if found in available
--if the name is found we just added it to the used list, next remove it from available's	
set availablep to collect items of availablep that match thisName with negation and just contents
end if*)

--100% vanilla solution ( a little longer )-not much though
if availablep contains thisName then
	set usedp to usedp & thisName--same as before, add to the used list
	set quasiAvailable to {} --set up a temp container list
	repeat with thisItem in availablep--repeat with every item in the available list
		if thisItem as text = thisName then--does the item on this pass  from the available's match the user entry? 
			--do nothing, we only want to copy names the user didn't enter
		else
			copy thisItem as text to the end of quasiAvailable--copy items from the old list if the user did not enter it
		end if
	end repeat
	--now that you've looped thru the available's set your availablep variable to the quasi list we built (minus the name that was entered)
	set availablep to quasiAvailable
end if

Run this script 3 times in your editor, typing 1 of each of the names on each pass and you should see the list of 3 availables dwindle to 0 and the list of used climb to 3.

Tested on Mac OS 8.6

Good luck Paul!

Thank God of Akua List Scripting Addition and Mytzlscript

Your few less lines worked just fine and seems faster than the “plain vanilla”.
:smiley:

On the reasonable assumption that the names in the lists are all strings, another vanilla approach would be:

set availablep to {"Bill", "Fred", "Arthur", "Sid", "Charlie"}
set usedp to {}

set desiredName to "Fred"
if availablep contains desiredName then
  set end of usedp to desiredName
  set i to 1
  repeat until item i of availablep is desiredName
    set i to i + 1
  end repeat
  -- Replace the name in availablep with a non-string
  set item i of availablep to missing value
  -- Reset availablep to the remaining strings
  set availablep to availablep's strings
end if