Page 1 of 1

Here's how to add an item to the end of a list

Posted: Wed Oct 09, 2019 1:31 pm
by MichaelBluejay
I'm replacing my original post with this one, because the way I thought I came up with for easily adding an item to the end of a list without manually inserting commas, well, I can't get it to work now. I'd delete this thread except I don't have that ability.

So, the most compact way to add an item to the end of a list is put "",newItem after theList.

Re: Here's how to add an item to the end of a list

Posted: Wed Oct 09, 2019 2:53 pm
by dunbarx
Michael.

Your snippet will not compile, you need to:

Code: Select all

put "figs" into item (num(items of tList )+1) of tList
Now then:

Code: Select all

on mouseUp
   put "apples,berries,cherries" into tList
   put "figs" into item last+1 of tList
end mouseUp
yields ""figs,berries,cherries", LC is ignoring the "last+" portion, as it often does with spurious words. This "feature" of LC can throw you. It does me. I wish the parser was more strict.

Keep having fun playing around. Discovering that LC will create the correct number of chunks when asked is cool, eh?. Try this;

Code: Select all

 put "apples,berries,cherries" into tList
   put "figs" into item 10 of tList
Write back any time with all you discover, as well as complaints. :wink:

Craig

Re: Here's how to add an item to the end of a list

Posted: Wed Oct 09, 2019 3:53 pm
by MichaelBluejay
Well, I was sure it worked for me, but now I can't get it to. I'm wondering if there's maybe some small syntax thing I'm missing.

Guess I'm back to manually inserting commas.

I'd delete this thread except there's no way to do that as a basic user.

Re: Here's how to add an item to the end of a list

Posted: Wed Oct 09, 2019 6:36 pm
by [-hh]
You write "newItem & comma". Write "comma & newItem".

A bit more compact:

Code: Select all

put "",newItem after theList -- use value of variable newItem
put ",abcd" after theList -- use value

Re: Here's how to add an item to the end of a list

Posted: Wed Oct 09, 2019 9:32 pm
by MichaelBluejay
Thank you. I do like "",newitem more than comma & newItem. It's easier to tell at a glance that we're appending an item to the list.